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" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
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:
<mailto:cactus-user-unsubscribe@;jakarta.apache.org>
> For additional commands, e-mail:
<mailto:cactus-user-help@;jakarta.apache.org>


--
To unsubscribe, e-mail:   <mailto:cactus-user-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:cactus-user-help@;jakarta.apache.org>

Reply via email to