1 7 package org.jboss.test.remoting.transport.rmi; 8 9 import java.util.HashMap ; 10 import java.util.Iterator ; 11 import java.util.Map ; 12 import java.util.Set ; 13 import org.jboss.jrunit.extensions.ServerTestCase; 14 import org.jboss.logging.Logger; 15 import org.jboss.remoting.InvokerLocator; 16 import org.jboss.remoting.ServerInvocationHandler; 17 import org.jboss.remoting.transport.Connector; 18 import org.jboss.remoting.transport.rmi.RMIServerInvoker; 19 import org.jboss.test.remoting.TestUtil; 20 import org.jboss.test.remoting.transport.mock.MockServerInvocationHandler; 21 22 23 28 public class RMIInvokerServerTest extends ServerTestCase 29 { 30 private int port = RMIServerInvoker.DEFAULT_REGISTRY_PORT - 1; 31 private String transport = "rmi"; 32 private Connector connector; 33 34 private static final Logger log = Logger.getLogger(RMIInvokerServerTest.class); 35 36 public void init(Map metatdata) throws Exception 37 { 38 if(port < 0) 39 { 40 port = TestUtil.getRandomPort(); 41 } 42 log.debug("port = " + port); 43 44 connector = new Connector(); 45 InvokerLocator locator = new InvokerLocator(buildLocatorURI(metatdata)); 46 connector.setInvokerLocator(locator.getLocatorURI()); 47 connector.start(); 48 connector.addInvocationHandler(getSubsystem(), getServerInvocationHandler()); 49 } 50 51 private String buildLocatorURI(Map metadata) 52 { 53 if(metadata == null || metadata.size() == 0) 54 { 55 return transport + "://localhost:" + port; 56 } 57 else 58 { 59 StringBuffer uriBuffer = new StringBuffer (transport + "://localhost:" + port + "/?"); 60 61 Set keys = metadata.keySet(); 62 Iterator itr = keys.iterator(); 63 while(itr.hasNext()) 64 { 65 String key = (String ) itr.next(); 66 String value = (String ) metadata.get(key); 67 uriBuffer.append(key + "=" + value + ","); 68 } 69 return uriBuffer.substring(0, uriBuffer.length() - 1); 70 } 71 } 72 73 protected String getSubsystem() 74 { 75 return "mock"; 76 } 77 78 protected ServerInvocationHandler getServerInvocationHandler() 79 { 80 return new MockServerInvocationHandler(); 81 } 82 83 public void setUp() throws Exception 84 { 85 Map metadata = new HashMap (); 86 metadata.put(RMIServerInvoker.REGISTRY_PORT_KEY, String.valueOf(port + 1)); 87 init(metadata); 88 } 89 90 public void tearDown() throws Exception 91 { 92 if(connector != null) 93 { 94 connector.stop(); 95 connector.destroy(); 96 } 97 } 98 99 100 } 101 | Popular Tags |