1 7 8 package org.jboss.ejb3.test.stateful.unit; 9 10 import org.jboss.test.JBossTestCase; 11 import org.jboss.ejb3.test.stateful.nested.ParentStatefulRemote; 12 13 import javax.naming.Context ; 14 import javax.naming.InitialContext ; 15 import java.util.Date ; 16 17 import junit.framework.Test; 18 19 25 public class NestedBeanUnitTestCase extends JBossTestCase 26 { 27 static boolean deployed = false; 28 public static int test = 0; 29 static Date startDate = new Date (); 30 31 protected final String namingFactory = 32 System.getProperty(Context.INITIAL_CONTEXT_FACTORY); 33 34 protected final String providerURL = 35 System.getProperty(Context.PROVIDER_URL); 36 37 public NestedBeanUnitTestCase (String name) 38 { 39 super(name); 40 } 41 42 public static Test suite() throws Exception 43 { 44 return getDeploySetup(NestedBeanUnitTestCase.class, "stateful-test.jar"); 45 } 46 47 public void testBasic() 48 throws Exception 49 { 50 getLog().debug(++NestedBeanUnitTestCase.test +"- " 51 +"Trying the context..."); 52 53 InitialContext ctx = getInitialContext(); 55 56 getLog().debug("Test Stateful Bean"); 57 getLog().debug("=================================="); 58 getLog().debug(++NestedBeanUnitTestCase.test +"- " 59 +"Looking up testBasic..."); 60 ParentStatefulRemote stateful = (ParentStatefulRemote) ctx.lookup("testParentStateful/remote"); 61 62 assertEquals("Counter: ", 1, stateful.increment()); 63 assertEquals("Counter: ", 2, stateful.increment()); 64 65 stateful.remove(); 66 getLog().debug("ok"); 67 } 68 69 public void testStatefulPassivation() 70 throws Exception 71 { 72 getLog().debug(++NestedBeanUnitTestCase.test +"- "+"Trying the context..."); 73 74 InitialContext ctx = getInitialContext(); 75 76 getLog().debug("Test Stateful Bean passivation"); 77 getLog().debug("=================================="); 78 getLog().debug(++NestedBeanUnitTestCase.test +"- " 79 +"Looking up testParentStateful..."); 80 ParentStatefulRemote stateful = (ParentStatefulRemote) ctx.lookup("testParentStateful/remote"); 81 82 assertEquals("Counter: ", 1, stateful.increment()); 83 assertEquals("Counter: ", 2, stateful.increment()); 84 _sleep(10000); 86 assertEquals("Counter: ", 3, stateful.increment()); 87 assertEquals("Counter: ", 4, stateful.increment()); 88 assertEquals(1, stateful.getPrePassivate()); 89 assertEquals(1, stateful.getPostActivate()); 90 91 stateful.remove(); 92 getLog().debug("ok"); 93 } 94 95 public void testStatefulRepeatedPassivation() 96 throws Exception 97 { 98 getLog().debug(++NestedBeanUnitTestCase.test +"- "+"Trying the context..."); 99 100 InitialContext ctx = getInitialContext(); 101 102 getLog().debug("Test Stateful Bean passivation"); 103 getLog().debug("=================================="); 104 getLog().debug(++NestedBeanUnitTestCase.test +"- " 105 +"Looking up testParentStateful..."); 106 ParentStatefulRemote stateful = (ParentStatefulRemote) ctx.lookup("testParentStateful/remote"); 107 stateful.reset(); 108 109 assertEquals("Counter: ", 1, stateful.increment()); 110 assertEquals("Counter: ", 2, stateful.increment()); 111 _sleep(10000); 113 assertEquals("Counter: ", 3, stateful.increment()); 114 assertEquals("Counter: ", 4, stateful.increment()); 115 assertEquals(1, stateful.getPrePassivate()); 116 assertEquals(1, stateful.getPostActivate()); 117 _sleep(10000); 119 assertEquals("Counter: ", 5, stateful.increment()); 120 assertEquals("Counter: ", 6, stateful.increment()); 121 assertEquals(2, stateful.getPrePassivate()); 122 assertEquals(2, stateful.getPostActivate()); 123 124 stateful.remove(); 125 getLog().debug("ok"); 126 } 127 128 protected void _sleep(long time) 129 { 130 try { 131 Thread.sleep(time); 132 } catch (InterruptedException e) { 133 e.printStackTrace(); 134 } 135 } 136 } 137 | Popular Tags |