1 23 24 package com.rift.coad.util.connection; 26 27 import java.lang.reflect.Proxy ; 29 import java.lang.reflect.InvocationHandler ; 30 import java.lang.reflect.Method ; 31 32 import junit.framework.*; 34 35 import org.apache.log4j.Logger; 37 import org.apache.log4j.BasicConfigurator; 38 39 44 public class ConnectionHandlerTest extends TestCase { 45 46 49 public interface TestInter { 50 public String helloWorld(String msg) throws java.rmi.RemoteException ; 51 } 52 53 56 public class TestInterImpl implements TestInter { 57 58 61 public String helloWorld(String msg) throws java.rmi.RemoteException { 62 if (throwException) { 63 throw new java.rmi.RemoteException ("This is a test ex"); 64 } 65 System.out.println("Message is :" + msg); 66 called = true; 67 return "Bob is your uncle"; 68 } 69 } 70 71 public boolean called = false; 72 public boolean throwException = false; 73 74 public ConnectionHandlerTest(String testName) { 75 super(testName); 76 BasicConfigurator.configure(); 77 } 78 79 protected void setUp() throws Exception { 80 } 81 82 protected void tearDown() throws Exception { 83 } 84 85 88 public void testHandler() throws Exception { 89 System.out.println("Handler"); 90 91 TestInterImpl rmiRef = new TestInterImpl(); 92 RMIConnection rmiConnection = new RMIConnection(null,"test"); 93 ConnectionHandler handler = new ConnectionHandler(rmiConnection,rmiRef); 94 TestInter testInter = (TestInter)Proxy.newProxyInstance( 95 TestInter.class.getClassLoader(), 96 new Class [] {TestInter.class},handler); 97 98 String result = testInter.helloWorld("test message"); 99 System.out.println("Result message : " + result); 100 101 if (called == false) { 102 fail("Failed to make the call"); 103 } 104 105 called = false; 106 throwException = true; 107 108 try { 109 testInter.helloWorld("Test"); 110 fail("Failed to generate an exception"); 111 } catch (java.rmi.RemoteException ex) { 112 if (called) { 113 fail("The call landed"); 114 } 115 } 116 } 117 118 } 119 | Popular Tags |