1 22 23 package org.jboss.ejb3.test.localcall; 24 25 import javax.ejb.Remote ; 26 import javax.ejb.Local ; 27 import javax.naming.InitialContext ; 28 29 import org.jboss.annotation.ejb.Service; 30 31 36 @Service 37 @Remote (ServiceRemote.class) 38 @Local (ServiceLocal.class) 39 public class ServiceBean implements ServiceLocal, ServiceRemote 40 { 41 public void test() 42 { 43 44 } 45 46 public void testLocal()throws Exception 47 { 48 InitialContext ctx = new InitialContext (); 49 StatefulLocal stateful1 = (StatefulLocal)ctx.lookup("StatefulBean/local"); 50 StatefulLocal stateful2 = (StatefulLocal)ctx.lookup("StatefulBean/local"); 51 52 StatefulClustered statefulClustered1 = (StatefulClustered)ctx.lookup("StatefulClusteredBean/remote"); 53 StatefulClustered statefulClustered2 = (StatefulClustered)ctx.lookup("StatefulClusteredBean/remote"); 54 55 StatelessLocal stateless1 = (StatelessLocal)ctx.lookup("StatelessBean/local"); 56 StatelessLocal stateless2 = (StatelessLocal)ctx.lookup("StatelessBean/local"); 57 58 StatelessClustered statelessClustered1 = (StatelessClustered)ctx.lookup("StatelessClusteredBean/remote"); 59 StatelessClustered statelessClustered2 = (StatelessClustered)ctx.lookup("StatelessClusteredBean/remote"); 60 61 ServiceLocal service1 = (ServiceLocal)ctx.lookup("ServiceBean/local"); 62 ServiceLocal service2 = (ServiceLocal)ctx.lookup("ServiceBean/local"); 63 64 stateful1.test(); 65 stateful2.test(); 66 statefulClustered1.test(); 67 statefulClustered2.test(); 68 stateless1.test(); 69 stateless2.test(); 70 statelessClustered1.test(); 71 statelessClustered2.test(); 72 service1.test(); 73 service2.test(); 74 75 assertFalse(stateful1.hashCode() == stateful2.hashCode()); 76 assertFalse(statefulClustered1.hashCode() == statefulClustered2.hashCode()); 77 assertTrue(stateless1.hashCode() == stateless2.hashCode()); 78 assertTrue(statelessClustered1.hashCode() == statelessClustered2.hashCode()); 79 assertTrue(service1.hashCode() == service2.hashCode()); 80 81 assertFalse(stateful1.equals(stateful2)); 82 assertFalse(statefulClustered1.equals(statefulClustered2)); 83 assertTrue(stateless1.equals(stateless2)); 84 assertTrue(statelessClustered1.equals(statelessClustered2)); 85 assertTrue(service1.equals(service2)); 86 } 87 88 private void assertFalse(boolean b) 89 { 90 if (b) 91 { 92 throw new RuntimeException ("Assertion failed!"); 93 } 94 } 95 96 private void assertTrue(boolean b) 97 { 98 if (!b) 99 { 100 throw new RuntimeException ("Assertion failed!"); 101 } 102 } 103 104 } 105 | Popular Tags |