1 15 package hivemind.test.lib; 16 17 import hivemind.test.lib.impl.FakeContext; 18 import hivemind.test.lib.impl.NameLookupHack; 19 import hivemind.test.lib.impl.SimpleHomeImpl; 20 21 import java.rmi.RemoteException ; 22 import java.util.Map ; 23 24 import javax.naming.Context ; 25 26 import org.apache.hivemind.ApplicationRuntimeException; 27 import org.apache.hivemind.Registry; 28 import org.apache.hivemind.xml.XmlTestCase; 29 30 35 36 public class TestEJBProxyFactory extends XmlTestCase 37 { 38 protected void tearDown() throws Exception 39 { 40 super.tearDown(); 41 42 NameLookupHack._context = null; 43 NameLookupHack._properties = null; 44 } 45 46 public void testEJBProxy() throws Exception 47 { 48 Registry r = buildFrameworkRegistry("EJBProxy.xml"); 49 50 SimpleHomeImpl home = new SimpleHomeImpl(); 51 FakeContext context = new FakeContext(); 52 context.bind("hivemind.test.lib.Simple", home); 53 NameLookupHack._context = context; 54 55 SimpleRemote object = (SimpleRemote) r.getService( 56 "hivemind.test.lib.SimpleRemote", 57 SimpleRemote.class); 58 59 assertEquals(7, object.add(4, 3)); 60 assertEquals(201, object.add(1, 200)); 62 63 66 Map p = NameLookupHack._properties; 67 68 assertEquals("fred", p.get(Context.INITIAL_CONTEXT_FACTORY)); 69 assertEquals("barney", p.get(Context.URL_PKG_PREFIXES)); 70 assertEquals("wilma", p.get(Context.PROVIDER_URL)); 71 } 72 73 public void testEJBProxyNameFailure() throws Exception 74 { 75 Registry r = buildFrameworkRegistry("EJBProxy.xml"); 76 77 FakeContext context = new FakeContext(); 78 context.setForceError(true); 79 80 NameLookupHack._context = context; 81 82 SimpleRemote object = (SimpleRemote) r.getService( 83 "hivemind.test.lib.SimpleRemote", 84 SimpleRemote.class); 85 86 try 87 { 88 89 object.add(4, 3); 90 unreachable(); 91 } 92 catch (ApplicationRuntimeException ex) 93 { 94 assertExceptionSubstring( 95 ex, 96 "Unable to lookup 'hivemind.test.lib.Simple' in JNDI context"); 97 98 Throwable t = findNestedException(ex); 99 100 assertExceptionSubstring(t, "Forced error: hivemind.test.lib.Simple"); 101 } 102 } 103 104 public void testEJBProxyRemoteFailure() throws Exception 105 { 106 Registry r = buildFrameworkRegistry("EJBProxy.xml"); 107 108 SimpleHomeImpl home = new SimpleHomeImpl(); 109 home.setForceError(true); 110 111 FakeContext context = new FakeContext(); 112 context.bind("hivemind.test.lib.Simple", home); 113 NameLookupHack._context = context; 114 115 NameLookupHack._context = context; 116 117 SimpleRemote object = (SimpleRemote) r.getService( 118 "hivemind.test.lib.SimpleRemote", 119 SimpleRemote.class); 120 121 try 122 { 123 124 object.add(4, 3); 125 unreachable(); 126 } 127 catch (RemoteException ex) 128 { 129 assertExceptionSubstring(ex, "Forced error."); 130 } 131 } 132 133 } | Popular Tags |