You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-user@jakarta.apache.org by Honghai Zhang <ho...@towers.com> on 2002/10/22 20:35:42 UTC

Test EJBs

I am using "ServletTestCase" to test EJBs deployed on Weblogic Server 6.1.

Here is the test scenario:
I have 2 EJBs I need to test.  I want to test one method for each EJB.
The method of 2nd EJB uses the return value of the method of 1st EJB.

Here is the code



////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public class CactusTest extends ServletTestCase {
...
    public void testPlus() throws Exception {
        sum = ejb.plus(2, 3);
        assertEquals(5, sum);
    }

    public void testMinus() throws Exception {
        int diff = ejb2.minus(sum, 3);
        assertEquals(2, diff);
    }

....
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


It is does not work because I think the instance variable "sum" was
initialized to 0 when the method "testMinus()" was executed.  Does anyone
know why this happens? (May be 2nd instance was created?)

What are the alternatives if this does not work?

Regards,

Honghai Zhang
TPAS, Towers Perrin



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Test EJBs

Posted by Mark Wehby <mw...@TRIPLEI.COM>.
 In order to use this value in the second method, create a static instance
varible and place the value in it.  The way in which Cactus works, the
CactusTest class is destroyed each time control is returned to the
client-side.  In order to keep the sum variable value, you would need to do
the following.




////////////////////////////////////////////////////////////////////////////
////////////////////////////////////
 public class CactusTest extends ServletTestCase {
       private static int sum = 0;

     public void testPlus() throws Exception {
         sum = ejb.plus(2, 3);
         assertEquals(5, sum);
     }

     public void testMinus() throws Exception {
         int diff = ejb2.minus(sum, 3);
         assertEquals(2, diff);
     }

 }



----- Original Message -----
From: "Honghai Zhang" <ho...@towers.com>
To: <ca...@jakarta.apache.org>
Sent: Tuesday, October 22, 2002 2:35 PM
Subject: Test EJBs


>
> I am using "ServletTestCase" to test EJBs deployed on Weblogic Server 6.1.
>
> Here is the test scenario:
> I have 2 EJBs I need to test.  I want to test one method for each EJB.
> The method of 2nd EJB uses the return value of the method of 1st EJB.
>
> Here is the code
>
>
>
>
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////
> public class CactusTest extends ServletTestCase {
> ...
>     public void testPlus() throws Exception {
>         sum = ejb.plus(2, 3);
>         assertEquals(5, sum);
>     }
>
>     public void testMinus() throws Exception {
>         int diff = ejb2.minus(sum, 3);
>         assertEquals(2, diff);
>     }
>
> ....
> }
>
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////
>
>
> It is does not work because I think the instance variable "sum" was
> initialized to 0 when the method "testMinus()" was executed.  Does anyone
> know why this happens? (May be 2nd instance was created?)
>
> What are the alternatives if this does not work?
>
> Regards,
>
> Honghai Zhang
> TPAS, Towers Perrin
>
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>