KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > remoting > transport > socket > InvokerServerTest


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.test.remoting.transport.socket;
8
9 import java.util.Iterator JavaDoc;
10 import java.util.Map JavaDoc;
11 import java.util.Set JavaDoc;
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 /**
21  * This is the concrete test for invoker server.
22  *
23  * @author <a HREF="mailto:telrod@e2technologies.net">Tom Elrod</a>
24  */

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 JavaDoc metatdata) throws Exception JavaDoc
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 JavaDoc buildLocatorURI(Map JavaDoc metadata)
49    {
50       if(metadata == null || metadata.size() == 0)
51       {
52          return transport + "://localhost:" + serverPort;
53       }
54       else
55       {
56          StringBuffer JavaDoc uriBuffer = new StringBuffer JavaDoc(transport + "://localhost:" + serverPort);
57
58          Set JavaDoc keys = metadata.keySet();
59          Iterator JavaDoc itr = keys.iterator();
60          while(itr.hasNext())
61          {
62             String JavaDoc key = (String JavaDoc) itr.next();
63             String JavaDoc value = (String JavaDoc) metadata.get(key);
64             uriBuffer.append(key + "=" + value + ",");
65          }
66          return uriBuffer.substring(0, uriBuffer.length() - 1);
67       }
68    }
69
70    protected String JavaDoc getSubsystem()
71    {
72       return "mock";
73    }
74
75    protected ServerInvocationHandler getServerInvocationHandler()
76    {
77       return new MockServerInvocationHandler();
78    }
79
80    protected void setUp() throws Exception JavaDoc
81    {
82       init(null);
83    }
84
85    protected void tearDown() throws Exception JavaDoc
86    {
87       if(connector != null)
88       {
89          connector.stop();
90          connector.destroy();
91       }
92    }
93
94    public static void main(String JavaDoc[] args)
95    {
96       InvokerServerTest server = new InvokerServerTest();
97       try
98       {
99          server.setUp();
100       }
101       catch(Exception JavaDoc e)
102       {
103          e.printStackTrace();
104       }
105    }
106 }
107
Popular Tags