KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > remoting > transport > rmi > RMIInvokerServerTest


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.rmi;
8
9 import java.util.HashMap JavaDoc;
10 import java.util.Iterator JavaDoc;
11 import java.util.Map JavaDoc;
12 import java.util.Set JavaDoc;
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 /**
24  * This is the concrete test for invoker server.
25  *
26  * @author <a HREF="mailto:telrod@e2technologies.net">Tom Elrod</a>
27  */

28 public class RMIInvokerServerTest extends ServerTestCase
29 {
30    private int port = RMIServerInvoker.DEFAULT_REGISTRY_PORT - 1;
31    private String JavaDoc transport = "rmi";
32    private Connector connector;
33
34    private static final Logger log = Logger.getLogger(RMIInvokerServerTest.class);
35
36    public void init(Map JavaDoc metatdata) throws Exception JavaDoc
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 JavaDoc buildLocatorURI(Map JavaDoc metadata)
52    {
53       if(metadata == null || metadata.size() == 0)
54       {
55          return transport + "://localhost:" + port;
56       }
57       else
58       {
59          StringBuffer JavaDoc uriBuffer = new StringBuffer JavaDoc(transport + "://localhost:" + port + "/?");
60
61          Set JavaDoc keys = metadata.keySet();
62          Iterator JavaDoc itr = keys.iterator();
63          while(itr.hasNext())
64          {
65             String JavaDoc key = (String JavaDoc) itr.next();
66             String JavaDoc value = (String JavaDoc) metadata.get(key);
67             uriBuffer.append(key + "=" + value + ",");
68          }
69          return uriBuffer.substring(0, uriBuffer.length() - 1);
70       }
71    }
72
73    protected String JavaDoc getSubsystem()
74    {
75       return "mock";
76    }
77
78    protected ServerInvocationHandler getServerInvocationHandler()
79    {
80       return new MockServerInvocationHandler();
81    }
82
83    public void setUp() throws Exception JavaDoc
84    {
85       Map JavaDoc metadata = new HashMap JavaDoc();
86       metadata.put(RMIServerInvoker.REGISTRY_PORT_KEY, String.valueOf(port + 1));
87       init(metadata);
88    }
89
90    public void tearDown() throws Exception JavaDoc
91    {
92       if(connector != null)
93       {
94          connector.stop();
95          connector.destroy();
96       }
97    }
98
99
100 }
101
Popular Tags