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