1 22 package org.jboss.ejb3.test.initial; 23 24 import java.util.Map ; 25 import javax.naming.InitialContext ; 26 27 33 public class Tester implements TesterMBean 34 { 35 public void testSLSBCollocation() throws Exception 36 { 37 InitialContext ctx = new InitialContext (); 38 TestLocal local = (TestLocal) ctx.lookup("TestBean/local"); 39 TestRemote remote = (TestRemote) ctx.lookup("TestBean/remote"); 40 41 if (local.getObject() != TestBean.obj) throw new RuntimeException ("Local call not equal"); 42 if (local.getObject() == remote.getObject()) throw new RuntimeException ("Remote should not be equal"); 43 Map map = remote.getObject(); 44 map.put("hello", "world"); 45 46 Object obj = local.echo(map); 47 if (obj != map) throw new RuntimeException ("argument and return should be the same"); 48 49 map = (Map )obj; 50 if (!map.containsKey("hello")) throw new RuntimeException ("not good return"); 51 52 obj = remote.echo(map); 53 if (obj == map) throw new RuntimeException ("argument and return should not be the same"); 54 55 map = (Map )obj; 56 if (!map.containsKey("hello")) throw new RuntimeException ("not good return"); 57 58 } 59 60 public void testSFSBCollocation() throws Exception 61 { 62 InitialContext ctx = new InitialContext (); 63 StatefulTestLocal local = (StatefulTestLocal) ctx.lookup("StatefulTestBean/local"); 64 StatefulTestRemote remote = (StatefulTestRemote) ctx.lookup("StatefulTestBean/remote"); 65 66 if (local.getObject() != StatefulTestBean.obj) throw new RuntimeException ("Local call not equal"); 67 if (local.getObject() == remote.getObject()) throw new RuntimeException ("Remote should not be equal"); 68 Map map = remote.getObject(); 69 map.put("hello", "world"); 70 71 Object obj = local.echo(map); 72 if (obj != map) throw new RuntimeException ("argument and return should be the same"); 73 map = (Map )obj; 74 if (!map.containsKey("hello")) throw new RuntimeException ("not good return"); 75 76 obj = remote.echo(map); 77 if (obj == map) throw new RuntimeException ("argument and return should not be the same"); 78 79 map = (Map )obj; 80 if (!map.containsKey("hello")) throw new RuntimeException ("not good return"); 81 } 82 83 84 public void test() throws Exception 85 { 86 InitialContext ctx = new InitialContext (); 87 Test test = (Test) ctx.lookup("TestBean/local"); 88 String echo = test.testMe("echo"); 89 if (!"echo".equals(echo)) throw new RuntimeException ("ECHO FAILED!"); 90 } 91 92 public void statefulTest() throws Exception 93 { 94 InitialContext ctx = new InitialContext (); 95 StatefulTestLocal test = (StatefulTestLocal) ctx.lookup("StatefulTestBean/local"); 96 test.setState("hello world"); 97 if (!test.getState().equals("hello world")) throw new Exception ("state was not retained"); 98 } 99 100 public void testInterceptors() throws Exception 101 { 102 InitialContext ctx = new InitialContext (); 103 InterceptedSLTest test = (InterceptedSLTest) ctx.lookup("InterceptedSLTestBean/local"); 104 int ret = test.testMethod(5); 105 int expected = 3010; 106 107 if (ret != expected) throw new Exception ("return value was not " + expected + ", it was: " + ret); 108 109 boolean exception = false; 110 try 111 { 112 test.throwsThrowable(1); 113 } 114 catch (Throwable e) 115 { 116 exception = true; 117 } 118 if (!exception) throw new Exception ("Exception was not thrown"); 119 } 120 121 public void testCallbacks() throws Exception 122 { 123 InitialContext ctx = new InitialContext (); 125 TestStatus status = (TestStatus) ctx.lookup("TestStatusBean/remote"); 126 status.clear(); 127 InterceptedSLTest test = (InterceptedSLTest) ctx.lookup("InterceptedSLTestBean/local"); 128 test.testMethod(5); 129 if (!status.postConstruct()) throw new Exception ("PostConstruct should be called for SLSB"); 130 if (status.prePassivate()) throw new Exception ("PrePassivate should not be called for SLSB"); 131 if (status.postActivate()) throw new Exception ("PostActivate should not be called for SLSB"); 132 133 } 136 } 137 138 139 140 | Popular Tags |