~ubuntu-branches/ubuntu/raring/libjboss-remoting-java/raring

« back to all changes in this revision

Viewing changes to src/tests/org/jboss/test/remoting/configuration/ServerBindingTestCase.java

  • Committer: Package Import Robot
  • Author(s): Torsten Werner
  • Date: 2011-09-09 14:01:03 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: package-import@ubuntu.com-20110909140103-hqokx61534tas9rg
Tags: 2.5.3.SP1-1
* Newer but not newest upstream release. Do not build samples.
* Change debian/watch to upstream's svn repo.
* Add patch to fix compile error caused by tomcat update.
  (Closes: #628303)
* Switch to source format 3.0.
* Switch to debhelper level 7.
* Remove useless Depends.
* Update Standards-Version: 3.9.2.
* Update README.source.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
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.
 
6
*
 
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.
 
11
*
 
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.
 
16
*
 
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.
 
21
*/
 
22
 
 
23
/*
 
24
 * Created on Jan 3, 2006
 
25
 */
 
26
package org.jboss.test.remoting.configuration;
 
27
 
 
28
import java.net.InetAddress;
 
29
 
 
30
import junit.framework.TestCase;
 
31
 
 
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;
 
37
 
 
38
 
 
39
/**
 
40
 * A ServerBindTest.
 
41
 
 
42
 * @author <a href="mailto:r.sigal@computer.org">Ron Sigal</a>
 
43
 * @version $Revision: 593 $
 
44
 * <p>
 
45
 * Copyright (c) 2005
 
46
 * </p>
 
47
 */
 
48
 
 
49
public class ServerBindingTestCase extends TestCase
 
50
{
 
51
   protected static final Logger log = Logger.getLogger(ServerBindingTestCase.class);
 
52
   private Connector connector;
 
53
   
 
54
   public void setUp() throws Exception
 
55
   {
 
56
      connector = new Connector();
 
57
   }
 
58
   
 
59
 
 
60
   public void tearDown() throws Exception
 
61
   {
 
62
      if(connector != null)
 
63
      {
 
64
         connector.stop();
 
65
         connector.destroy();
 
66
      }
 
67
   }
 
68
 
 
69
   
 
70
   public void testBindAddress()
 
71
   {
 
72
      String uri = "socket://192.0.0.1:8081/?serverBindAddress=localhost";
 
73
      assertTrue(doOneBindingTest(uri, "localhost", 8081));
 
74
   }
 
75
   
 
76
   
 
77
   public void testConnectAddress()
 
78
   {
 
79
      try
 
80
      {
 
81
         String uri = "socket://0.1.2.3:8082/?clientConnectAddress=1.2.3.4";
 
82
         assertTrue(doOneBindingTest(uri, InetAddress.getLocalHost().getHostAddress(), 8082));
 
83
      }
 
84
      catch (Exception e)
 
85
      {
 
86
         e.printStackTrace();
 
87
         log.error(e);
 
88
         fail();
 
89
      }
 
90
   }
 
91
   
 
92
   
 
93
   public void testBindAndConnectAddress()
 
94
   {
 
95
      try
 
96
      {
 
97
         String uri = "socket://0.1.2.3:8083/?serverBindAddress=localhost&clientConnectAddress=1.2.3.4";
 
98
         assertTrue(doOneBindingTest(uri, "localhost", 8083));
 
99
      }
 
100
      catch (Exception e)
 
101
      {
 
102
         e.printStackTrace();
 
103
         log.error(e);
 
104
         fail();
 
105
      }
 
106
   }
 
107
   
 
108
   
 
109
   public void testLocatorAddress()
 
110
   {
 
111
      try
 
112
      {
 
113
         String uri = "socket://localhost:8084";
 
114
         assertTrue(doOneBindingTest(uri, "127.0.0.1", 8084));
 
115
      }
 
116
      catch (Exception e)
 
117
      {
 
118
         e.printStackTrace();
 
119
         log.error(e);
 
120
         fail();
 
121
      }
 
122
   }
 
123
   
 
124
   
 
125
   public void testNullLocatorAddress()
 
126
   {
 
127
      try
 
128
      {
 
129
         String uri = "socket://:8085";
 
130
         assertTrue(doOneBindingTest(uri, "127.0.0.1", 8085));
 
131
      }
 
132
      catch (Exception e)
 
133
      {
 
134
         e.printStackTrace();
 
135
         log.error(e);
 
136
         fail();
 
137
      }
 
138
   }
 
139
   
 
140
   
 
141
   public void testBindPort()
 
142
   {
 
143
      String uri = "socket://localhost:1111/?serverBindPort=8086";
 
144
      assertTrue(doOneBindingTest(uri, "127.0.0.1", 8086));
 
145
   }
 
146
 
 
147
   
 
148
   public void testZeroBindPort()
 
149
   {
 
150
      String uri = "socket://localhost/?serverBindPort=0";
 
151
      assertTrue(doOneAnonymousBindingTest(uri));
 
152
   }
 
153
 
 
154
   
 
155
   public void testNegativeBindPort()
 
156
   {
 
157
      String uri = "socket://localhost/?serverBindPort=-1";
 
158
      assertTrue(doOneAnonymousBindingTest(uri));
 
159
   }
 
160
   
 
161
   
 
162
   public void testZeroConnectPort()
 
163
   {
 
164
      String uri = "socket://localhost/?clientConnectPort=0";
 
165
      assertTrue(doOneAnonymousBindingTest(uri));
 
166
   }
 
167
 
 
168
   
 
169
   public void testNegativeConnectPort()
 
170
   {
 
171
      String uri = "socket://localhost/?serverBindPort=-1";
 
172
      assertTrue(doOneAnonymousBindingTest(uri));
 
173
   }
 
174
   
 
175
   public void testZeroBindandConnectPort()
 
176
   {
 
177
      String uri = "socket://localhost/?serverBindPort=0&clientConnectPort=0";
 
178
      assertTrue(doOneAnonymousBindingTest(uri));
 
179
   }
 
180
 
 
181
   
 
182
   public void testNegativeBindandConnectPort()
 
183
   {
 
184
      String uri = "socket://localhost/?serverBindPort=-1&clientConnectPort=-1";
 
185
      assertTrue(doOneAnonymousBindingTest(uri));
 
186
   }  
 
187
   
 
188
   
 
189
   public void testZeroLocatorPort()
 
190
   {
 
191
      String uri = "socket://localhost:0";
 
192
      assertTrue(doOneAnonymousBindingTest(uri));
 
193
   }
 
194
 
 
195
   
 
196
   public void testNegativeLocatorPort()
 
197
   {
 
198
      String uri = "socket://localhost:-1";
 
199
      assertTrue(doOneAnonymousBindingTest(uri));
 
200
   }
 
201
   
 
202
   
 
203
   protected boolean doOneBindingTest(String uri, String expectedHost, int expectedPort)
 
204
   {
 
205
      boolean success = true;
 
206
      
 
207
      try
 
208
      {
 
209
         connector.setInvokerLocator(uri);
 
210
         connector.create();
 
211
         connector.start();
 
212
         
 
213
         ServerInvoker[] serverInvokers = InvokerRegistry.getServerInvokers();
 
214
         
 
215
         if (serverInvokers == null || serverInvokers.length == 0)
 
216
         {
 
217
            log.error("no invoker created: " + uri);
 
218
            success = false;
 
219
         }
 
220
         
 
221
         ServerInvoker serverInvoker = serverInvokers[0];
 
222
         String bindHost = serverInvoker.getServerBindAddress();
 
223
         int bindPort = serverInvoker.getServerBindPort();
 
224
         
 
225
         if (!expectedHost.equals(bindHost))
 
226
         {
 
227
            log.error("host (" + bindHost + ") != expected host (" + expectedHost);
 
228
            success = false;
 
229
         }
 
230
         
 
231
         if (expectedPort != bindPort)
 
232
         {
 
233
            log.error("port (" + bindPort + ") != expected port (" + expectedPort);
 
234
            success = false;
 
235
         }
 
236
 
 
237
         return success;
 
238
      }
 
239
      catch (Exception e)
 
240
      {
 
241
         e.printStackTrace();
 
242
         log.error(e);
 
243
         return false;
 
244
      }
 
245
   }
 
246
 
 
247
   
 
248
   protected boolean doOneAnonymousBindingTest(String uri)
 
249
   {
 
250
      boolean success = true;
 
251
      
 
252
      try
 
253
      {
 
254
         connector.setInvokerLocator(uri);
 
255
         connector.create();
 
256
         connector.start();
 
257
         InvokerLocator locator = new InvokerLocator(connector.getInvokerLocator());
 
258
         
 
259
         if (locator.getPort() <= 0)
 
260
         {
 
261
            log.error("port should be > 0: " + locator.getPort());
 
262
            success = false;
 
263
         }
 
264
 
 
265
         return success;
 
266
      }
 
267
      catch (Exception e)
 
268
      {
 
269
         e.printStackTrace();
 
270
         log.error(e);
 
271
         return false;
 
272
      }
 
273
   }
 
274
}
 
275