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.
24
* Created on Jan 3, 2006
26
package org.jboss.test.remoting.configuration;
28
import java.net.InetAddress;
30
import junit.framework.TestCase;
32
import org.jboss.logging.Logger;
33
import org.jboss.remoting.InvokerLocator;
34
import org.jboss.remoting.InvokerRegistry;
35
import org.jboss.remoting.ServerInvoker;
36
import org.jboss.remoting.transport.Connector;
42
* @author <a href="mailto:r.sigal@computer.org">Ron Sigal</a>
43
* @version $Revision: 593 $
49
public class ServerBindingTestCase extends TestCase
51
protected static final Logger log = Logger.getLogger(ServerBindingTestCase.class);
52
private Connector connector;
54
public void setUp() throws Exception
56
connector = new Connector();
60
public void tearDown() throws Exception
70
public void testBindAddress()
72
String uri = "socket://192.0.0.1:8081/?serverBindAddress=localhost";
73
assertTrue(doOneBindingTest(uri, "localhost", 8081));
77
public void testConnectAddress()
81
String uri = "socket://0.1.2.3:8082/?clientConnectAddress=1.2.3.4";
82
assertTrue(doOneBindingTest(uri, InetAddress.getLocalHost().getHostAddress(), 8082));
93
public void testBindAndConnectAddress()
97
String uri = "socket://0.1.2.3:8083/?serverBindAddress=localhost&clientConnectAddress=1.2.3.4";
98
assertTrue(doOneBindingTest(uri, "localhost", 8083));
109
public void testLocatorAddress()
113
String uri = "socket://localhost:8084";
114
assertTrue(doOneBindingTest(uri, "127.0.0.1", 8084));
125
public void testNullLocatorAddress()
129
String uri = "socket://:8085";
130
assertTrue(doOneBindingTest(uri, "127.0.0.1", 8085));
141
public void testBindPort()
143
String uri = "socket://localhost:1111/?serverBindPort=8086";
144
assertTrue(doOneBindingTest(uri, "127.0.0.1", 8086));
148
public void testZeroBindPort()
150
String uri = "socket://localhost/?serverBindPort=0";
151
assertTrue(doOneAnonymousBindingTest(uri));
155
public void testNegativeBindPort()
157
String uri = "socket://localhost/?serverBindPort=-1";
158
assertTrue(doOneAnonymousBindingTest(uri));
162
public void testZeroConnectPort()
164
String uri = "socket://localhost/?clientConnectPort=0";
165
assertTrue(doOneAnonymousBindingTest(uri));
169
public void testNegativeConnectPort()
171
String uri = "socket://localhost/?serverBindPort=-1";
172
assertTrue(doOneAnonymousBindingTest(uri));
175
public void testZeroBindandConnectPort()
177
String uri = "socket://localhost/?serverBindPort=0&clientConnectPort=0";
178
assertTrue(doOneAnonymousBindingTest(uri));
182
public void testNegativeBindandConnectPort()
184
String uri = "socket://localhost/?serverBindPort=-1&clientConnectPort=-1";
185
assertTrue(doOneAnonymousBindingTest(uri));
189
public void testZeroLocatorPort()
191
String uri = "socket://localhost:0";
192
assertTrue(doOneAnonymousBindingTest(uri));
196
public void testNegativeLocatorPort()
198
String uri = "socket://localhost:-1";
199
assertTrue(doOneAnonymousBindingTest(uri));
203
protected boolean doOneBindingTest(String uri, String expectedHost, int expectedPort)
205
boolean success = true;
209
connector.setInvokerLocator(uri);
213
ServerInvoker[] serverInvokers = InvokerRegistry.getServerInvokers();
215
if (serverInvokers == null || serverInvokers.length == 0)
217
log.error("no invoker created: " + uri);
221
ServerInvoker serverInvoker = serverInvokers[0];
222
String bindHost = serverInvoker.getServerBindAddress();
223
int bindPort = serverInvoker.getServerBindPort();
225
if (!expectedHost.equals(bindHost))
227
log.error("host (" + bindHost + ") != expected host (" + expectedHost);
231
if (expectedPort != bindPort)
233
log.error("port (" + bindPort + ") != expected port (" + expectedPort);
248
protected boolean doOneAnonymousBindingTest(String uri)
250
boolean success = true;
254
connector.setInvokerLocator(uri);
257
InvokerLocator locator = new InvokerLocator(connector.getInvokerLocator());
259
if (locator.getPort() <= 0)
261
log.error("port should be > 0: " + locator.getPort());