2
* JBoss, Home of Professional Open Source
3
* Copyright 2005, JBoss Inc., and individual contributors as indicated
4
* by the @authors tag. See the copyright.txt in the distribution for a
5
* full listing of individual contributors.
7
* This is free software; you can redistribute it and/or modify it
8
* under the terms of the GNU Lesser General Public License as
9
* published by the Free Software Foundation; either version 2.1 of
10
* the License, or (at your option) any later version.
12
* This software is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Lesser General Public License for more details.
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with this software; if not, write to the Free
19
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
23
package org.jboss.test.remoting.configuration;
25
import junit.framework.TestCase;
26
import org.jboss.remoting.Client;
27
import org.jboss.remoting.InvokerLocator;
28
import org.jboss.remoting.InvokerRegistry;
29
import org.jboss.remoting.ServerInvoker;
30
import org.jboss.remoting.transport.Connector;
31
import org.jboss.remoting.transport.PortUtil;
32
import org.jboss.test.remoting.transport.mock.MockServerInvocationHandler;
33
import org.w3c.dom.Document;
35
import javax.xml.parsers.DocumentBuilderFactory;
36
import java.io.ByteArrayInputStream;
37
import java.net.InetAddress;
41
* @author <a href="mailto:tom.elrod@jboss.com">Tom Elrod</a>
43
public class RMIConfigurationTestCase extends TestCase
45
private String transport = "rmi";
46
private int serverPort = 6666;
47
private int clientPort = 7777;
48
private int registryPort = 8888;
49
private String hostName = null;
50
private String hostIP = null;
51
private Connector connector = null;
53
public void setUp() throws Exception
55
hostName = InetAddress.getLocalHost().getHostName();
56
hostIP = InetAddress.getLocalHost().getHostAddress();
58
connector = new Connector();
59
StringBuffer buf = new StringBuffer();
60
buf.append("<?xml version=\"1.0\"?>\n");
61
buf.append("<config>");
62
buf.append("<invoker transport=\"" + transport + "\">");
63
buf.append("<attribute name=\"registryPort\" isParam=\"true\">" + registryPort + "</attribute>");
64
buf.append("<attribute name=\"serverBindAddress\">" + hostName + "</attribute>");
65
buf.append("<attribute name=\"serverBindPort\">" + serverPort + "</attribute>");
66
buf.append("<attribute name=\"clientConnectAddress\">" + hostIP + "</attribute>");
67
buf.append("<attribute name=\"clientConnectPort\">" + clientPort + "</attribute>");
68
buf.append("</invoker>");
69
buf.append("<handlers>");
70
buf.append(" <handler subsystem=\"mock\">" + MockServerInvocationHandler.class.getName() + "</handler>\n");
71
buf.append("</handlers>");
72
buf.append("</config>");
73
Document xml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream(buf.toString().getBytes()));
74
connector.setConfiguration(xml.getDocumentElement());
80
public void testClientConfiguration() throws Exception
83
// make sure the client's view of the locator will be as configured
84
ServerInvoker[] serverInvokers = InvokerRegistry.getServerInvokers();
86
if(serverInvokers != null && serverInvokers.length > 0)
88
InvokerLocator locator = serverInvokers[0].getLocator();
89
String locatorHost = locator.getHost();
90
int locatorPort = locator.getPort();
92
System.out.println("locator host = " + locatorHost);
93
System.out.println("locator port = " + locatorPort);
94
assertEquals(hostIP, locatorHost);
95
assertEquals(clientPort, locatorPort);
98
// check for server bind port (assume is the server since no exception thrown before)
99
boolean portAvailable = PortUtil.checkPort(serverPort, hostName);
100
assertTrue(!portAvailable);
101
portAvailable = PortUtil.checkPort(registryPort, hostName);
102
assertTrue(!portAvailable);
104
// make sure can call ont
105
Client client = new Client(new InvokerLocator(transport + "://" + hostName + ":" + serverPort + "/?registryPort=" + registryPort));
107
String param = "foobar";
111
ret = client.invoke(param);
113
catch(Throwable throwable)
115
throw new Exception("Call on server failed.", throwable);
117
assertEquals(param, ret);
121
public void tearDown() throws Exception
123
if(connector != null)
130
public static void main(String[] args)
132
RMIConfigurationTestCase testCase = new RMIConfigurationTestCase();
136
testCase.testClientConfiguration();
b'\\ No newline at end of file'