1 22 package org.jboss.ejb3.test.ejbcontext.unit; 23 24 import org.jboss.ejb3.test.ejbcontext.Stateful; 25 import org.jboss.ejb3.test.ejbcontext.StatefulRemote; 26 import org.jboss.ejb3.test.ejbcontext.Stateless; 27 import org.jboss.logging.Logger; 28 import org.jboss.test.JBossTestCase; 29 import junit.framework.Test; 30 31 37 public class EjbContextUnitTestCase 38 extends JBossTestCase 39 { 40 private static final Logger log = Logger.getLogger(EjbContextUnitTestCase.class); 41 42 public EjbContextUnitTestCase(String name) 43 { 44 super(name); 45 } 46 47 public void testEjbContextJndi() throws Exception 48 { 49 Stateful stateful = (Stateful)getInitialContext().lookup("Stateful"); 50 stateful.testEjbContext(); 51 } 52 53 public void testEjbContextLookup() throws Exception 54 { 55 Stateless stateless = (Stateless)getInitialContext().lookup("Stateless"); 56 stateless.testEjbContextLookup(); 57 } 58 59 public void testStatelessInvokedBusinessInterface() throws Exception 60 { 61 Stateless stateless1 = (Stateless)getInitialContext().lookup("Stateless"); 62 Stateless stateless2 = (Stateless)getInitialContext().lookup("Stateless"); 63 64 Class interfc = stateless1.testInvokedBusinessInterface(); 65 assertEquals(interfc, Stateless.class); 66 67 interfc = stateless2.testInvokedBusinessInterface(); 68 assertEquals(interfc, Stateless.class); 69 70 Stateless stateless = (Stateless)stateless1.testBusinessObject(Stateless.class); 71 stateless.noop(); 72 73 assertEquals(interfc, Stateless.class); 74 75 try{ 76 stateless1.testBusinessObject(Stateful.class); 77 fail("IllegalStateException not thrown"); 78 } 79 catch (javax.ejb.EJBException e) 80 { 81 if (!(e.getCause() instanceof IllegalStateException )) throw e; 82 assertEquals(IllegalStateException .class, e.getCause().getClass()); 83 } 84 85 stateless1.testEjbObject(); 86 87 stateless1.testEjbLocalObject(); 88 } 89 90 public void testStatefulInvokedBusinessInterface() throws Exception 91 { 92 Stateful stateful1 = (Stateful)getInitialContext().lookup("Stateful"); 93 StatefulRemote stateful2 = (StatefulRemote)getInitialContext().lookup("StatefulRemote"); 94 95 Class interfc = stateful1.testInvokedBusinessInterface(); 96 assertEquals(interfc, Stateful.class); 97 98 interfc = stateful2.testInvokedBusinessInterface2(); 99 assertEquals(interfc, StatefulRemote.class); 100 101 interfc = stateful1.testLocalInvokedBusinessInterface(); 102 assertEquals(interfc, StatefulRemote.class); 103 104 stateful1.setState("same"); 105 Stateful stateful3 = (Stateful)stateful1.getBusinessObject(); 106 assertEquals("same", stateful3.getState()); 107 108 109 } 110 111 public static Test suite() throws Exception 112 { 113 return getDeploySetup(EjbContextUnitTestCase.class, "ejbcontext.jar"); 114 } 115 116 } 117 | Popular Tags |