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

« back to all changes in this revision

Viewing changes to tests/org/jboss/test/remoting/marshall/config/ConfigurationMapTestParent.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 2009, Red Hat Middleware LLC, and individual contributors
4
 
 * as indicated by the @author tags. See the copyright.txt file in the
5
 
 * distribution for a 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
 
package org.jboss.test.remoting.marshall.config;
24
 
 
25
 
import java.net.InetAddress;
26
 
import java.util.HashMap;
27
 
import java.util.Map;
28
 
 
29
 
import junit.framework.TestCase;
30
 
 
31
 
import org.apache.log4j.ConsoleAppender;
32
 
import org.apache.log4j.Level;
33
 
import org.apache.log4j.Logger;
34
 
import org.apache.log4j.PatternLayout;
35
 
import org.jboss.logging.XLevel;
36
 
import org.jboss.remoting.Client;
37
 
import org.jboss.remoting.InvokerLocator;
38
 
import org.jboss.remoting.Remoting;
39
 
import org.jboss.remoting.marshal.MarshalFactory;
40
 
import org.jboss.remoting.transport.Connector;
41
 
import org.jboss.remoting.transport.PortUtil;
42
 
 
43
 
 
44
 
/**
45
 
 * Unit test for JBREM-1102.
46
 
 * 
47
 
 * @author <a href="ron.sigal@jboss.com">Ron Sigal</a>
48
 
 * @version 
49
 
 * <p>
50
 
 * Copyright Mar 20, 2009
51
 
 * </p>
52
 
 */
53
 
public abstract class ConfigurationMapTestParent extends TestCase
54
 
{
55
 
   private static Logger log = Logger.getLogger(ConfigurationMapTestParent.class);
56
 
   
57
 
   private static boolean firstTime = true;
58
 
   
59
 
   protected String host;
60
 
   protected int port;
61
 
   protected String locatorURI;
62
 
   protected InvokerLocator serverLocator;
63
 
   protected Connector connector;
64
 
   protected TestInvocationHandler invocationHandler;
65
 
 
66
 
   
67
 
   public void setUp() throws Exception
68
 
   {
69
 
      if (firstTime)
70
 
      {
71
 
         firstTime = false;
72
 
         Logger.getLogger("org.jboss.remoting").setLevel(XLevel.TRACE);
73
 
         Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
74
 
         String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
75
 
         PatternLayout layout = new PatternLayout(pattern);
76
 
         ConsoleAppender consoleAppender = new ConsoleAppender(layout);
77
 
         Logger.getRootLogger().addAppender(consoleAppender);  
78
 
      }
79
 
      
80
 
      ConfigTestMarshaller.reset();
81
 
      ConfigTestUnmarshaller.reset();
82
 
      LocatorTestMarshaller.reset();
83
 
      LocatorTestUnmarshaller.reset();
84
 
   }
85
 
 
86
 
   
87
 
   public void tearDown()
88
 
   {
89
 
   }
90
 
   
91
 
   
92
 
   public void testDatatypeConfigDefault() throws Throwable
93
 
   {
94
 
      log.info("entering " + getName());
95
 
      
96
 
      // Cache marshaller/unmarshaller.
97
 
      MarshalFactory.addMarshaller("config", new ConfigTestMarshaller(), new ConfigTestUnmarshaller());
98
 
      
99
 
      // Start server.
100
 
      HashMap serverConfig = new HashMap();
101
 
      serverConfig.put(InvokerLocator.DATATYPE, "config");
102
 
      setupServer("x=y", serverConfig);
103
 
      
104
 
      // Create client.
105
 
      InvokerLocator clientLocator = new InvokerLocator(locatorURI);
106
 
      HashMap clientConfig = new HashMap();
107
 
      clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
108
 
      clientConfig.put(InvokerLocator.DATATYPE, "config");
109
 
      addExtraClientConfig(clientConfig);
110
 
      Client client = new Client(clientLocator, clientConfig);
111
 
      client.connect();
112
 
      log.info("client is connected");
113
 
      
114
 
      // Test connections.
115
 
      assertEquals("abc", client.invoke("abc"));
116
 
      log.info("connection is good");
117
 
      
118
 
      // Do tests.
119
 
      assertTrue(ConfigTestMarshaller.ok(false, marshallerDatatypeUnused()));
120
 
      assertTrue(ConfigTestUnmarshaller.ok(false, 0));
121
 
      assertTrue(LocatorTestMarshaller.ok());
122
 
      assertTrue(LocatorTestUnmarshaller.ok());
123
 
      
124
 
      client.disconnect();
125
 
      shutdownServer();
126
 
      log.info(getName() + " PASSES");
127
 
   }
128
 
   
129
 
   
130
 
   public void testDatatypePassConfigMapFalse() throws Throwable
131
 
   {
132
 
      log.info("entering " + getName());
133
 
      
134
 
      // Cache marshaller/unmarshaller.
135
 
      MarshalFactory.addMarshaller("config", new ConfigTestMarshaller(), new ConfigTestUnmarshaller());
136
 
      
137
 
      // Start server.
138
 
      HashMap serverConfig = new HashMap();
139
 
      serverConfig.put(InvokerLocator.DATATYPE, "config");
140
 
      serverConfig.put(Remoting.PASS_CONFIG_MAP_TO_MARSHAL_FACTORY, "false");
141
 
      setupServer("x=y", serverConfig);
142
 
      
143
 
      // Create client.
144
 
      InvokerLocator clientLocator = new InvokerLocator(locatorURI);
145
 
      HashMap clientConfig = new HashMap();
146
 
      clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
147
 
      clientConfig.put(InvokerLocator.DATATYPE, "config");
148
 
      clientConfig.put(Remoting.PASS_CONFIG_MAP_TO_MARSHAL_FACTORY, "false");
149
 
      addExtraClientConfig(clientConfig);
150
 
      Client client = new Client(clientLocator, clientConfig);
151
 
      client.connect();
152
 
      log.info("client is connected");
153
 
      
154
 
      // Test connections.
155
 
      assertEquals("abc", client.invoke("abc"));
156
 
      log.info("connection is good");
157
 
      
158
 
      // Do tests.
159
 
      assertTrue(ConfigTestMarshaller.ok(false, marshallerDatatypeUnused()));
160
 
      assertTrue(ConfigTestUnmarshaller.ok(false, 0));
161
 
      assertTrue(LocatorTestMarshaller.ok());
162
 
      assertTrue(LocatorTestUnmarshaller.ok());
163
 
      
164
 
      client.disconnect();
165
 
      shutdownServer();
166
 
      log.info(getName() + " PASSES");
167
 
   }
168
 
   
169
 
   
170
 
   public void testDatatypePassConfigMapTrue() throws Throwable
171
 
   {
172
 
      log.info("entering " + getName());
173
 
      
174
 
      // Cache marshaller/unmarshaller.
175
 
      MarshalFactory.addMarshaller("config", new ConfigTestMarshaller(), new ConfigTestUnmarshaller());
176
 
      
177
 
      // Start server.
178
 
      HashMap serverConfig = new HashMap();
179
 
      serverConfig.put(InvokerLocator.DATATYPE, "config");
180
 
      serverConfig.put(Remoting.PASS_CONFIG_MAP_TO_MARSHAL_FACTORY, "true");
181
 
      setupServer("x=y", serverConfig);
182
 
      
183
 
      // Create client.
184
 
      InvokerLocator clientLocator = new InvokerLocator(locatorURI);
185
 
      HashMap clientConfig = new HashMap();
186
 
      clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
187
 
      clientConfig.put(InvokerLocator.DATATYPE, "config");
188
 
      clientConfig.put(Remoting.PASS_CONFIG_MAP_TO_MARSHAL_FACTORY, "true");
189
 
      addExtraClientConfig(clientConfig);
190
 
      Client client = new Client(clientLocator, clientConfig);
191
 
      client.connect();
192
 
      log.info("client is connected");
193
 
      
194
 
      // Test connections.
195
 
      assertEquals("abc", client.invoke("abc"));
196
 
      log.info("connection is good");
197
 
      
198
 
      // Do tests.
199
 
      assertTrue(ConfigTestMarshaller.ok(true, marshallerCountDatatype()));
200
 
      assertTrue(ConfigTestUnmarshaller.ok(true, unmarshallerCountDatatype()));
201
 
      assertTrue(LocatorTestMarshaller.ok());
202
 
      assertTrue(LocatorTestUnmarshaller.ok());
203
 
      
204
 
      client.disconnect();
205
 
      shutdownServer();
206
 
      log.info(getName() + " PASSES");
207
 
   }
208
 
   
209
 
   
210
 
   public void testFQNConfigDefault() throws Throwable
211
 
   {
212
 
      log.info("entering " + getName());
213
 
      
214
 
      // Start server.
215
 
      HashMap serverConfig = new HashMap();
216
 
      serverConfig.put(InvokerLocator.MARSHALLER, ConfigTestMarshaller.class.getName());
217
 
      serverConfig.put(InvokerLocator.UNMARSHALLER, ConfigTestUnmarshaller.class.getName());
218
 
      setupServer("x=y", serverConfig);
219
 
      
220
 
      // Create client.
221
 
      InvokerLocator clientLocator = new InvokerLocator(locatorURI);
222
 
      HashMap clientConfig = new HashMap();
223
 
      clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
224
 
      clientConfig.put(InvokerLocator.MARSHALLER, ConfigTestMarshaller.class.getName());
225
 
      clientConfig.put(InvokerLocator.UNMARSHALLER, ConfigTestUnmarshaller.class.getName());
226
 
      addExtraClientConfig(clientConfig);
227
 
      Client client = new Client(clientLocator, clientConfig);
228
 
      client.connect();
229
 
      log.info("client is connected");
230
 
      
231
 
      // Test connections.
232
 
      assertEquals("abc", client.invoke("abc"));
233
 
      log.info("connection is good");
234
 
      
235
 
      // Do tests.
236
 
      assertTrue(ConfigTestMarshaller.ok(false,marshallerFQNUnused()));
237
 
      assertTrue(ConfigTestUnmarshaller.ok(false, 0));
238
 
      assertTrue(LocatorTestMarshaller.ok());
239
 
      assertTrue(LocatorTestUnmarshaller.ok());
240
 
      
241
 
      client.disconnect();
242
 
      shutdownServer();
243
 
      log.info(getName() + " PASSES");
244
 
   }
245
 
   
246
 
   
247
 
   
248
 
   
249
 
   public void testFQNPassConfigMapFalse() throws Throwable
250
 
   {
251
 
      log.info("entering " + getName());
252
 
      
253
 
      // Start server.
254
 
      HashMap serverConfig = new HashMap();
255
 
      serverConfig.put(InvokerLocator.MARSHALLER, ConfigTestMarshaller.class.getName());
256
 
      serverConfig.put(InvokerLocator.UNMARSHALLER, ConfigTestUnmarshaller.class.getName());
257
 
      serverConfig.put(Remoting.PASS_CONFIG_MAP_TO_MARSHAL_FACTORY, "false");
258
 
      setupServer("x=y", serverConfig);
259
 
      
260
 
      // Create client.
261
 
      InvokerLocator clientLocator = new InvokerLocator(locatorURI);
262
 
      HashMap clientConfig = new HashMap();
263
 
      clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
264
 
      clientConfig.put(InvokerLocator.MARSHALLER, ConfigTestMarshaller.class.getName());
265
 
      clientConfig.put(InvokerLocator.UNMARSHALLER, ConfigTestUnmarshaller.class.getName());
266
 
      clientConfig.put(Remoting.PASS_CONFIG_MAP_TO_MARSHAL_FACTORY, "false");
267
 
      addExtraClientConfig(clientConfig);
268
 
      Client client = new Client(clientLocator, clientConfig);
269
 
      client.connect();
270
 
      log.info("client is connected");
271
 
      
272
 
      // Test connections.
273
 
      assertEquals("abc", client.invoke("abc"));
274
 
      log.info("connection is good");
275
 
      
276
 
      // Do tests.
277
 
      assertTrue(ConfigTestMarshaller.ok(false, marshallerFQNUnused()));
278
 
      assertTrue(ConfigTestUnmarshaller.ok(false, 0));
279
 
      assertTrue(LocatorTestMarshaller.ok());
280
 
      assertTrue(LocatorTestUnmarshaller.ok());
281
 
      
282
 
      client.disconnect();
283
 
      shutdownServer();
284
 
      log.info(getName() + " PASSES");
285
 
   }
286
 
   
287
 
   
288
 
   public void testFQNConfigPassConfigMapTrue() throws Throwable
289
 
   {
290
 
      log.info("entering " + getName());
291
 
      
292
 
      // Start server.
293
 
      HashMap serverConfig = new HashMap();
294
 
      serverConfig.put(InvokerLocator.MARSHALLER, ConfigTestMarshaller.class.getName());
295
 
      serverConfig.put(InvokerLocator.UNMARSHALLER, ConfigTestUnmarshaller.class.getName());
296
 
      serverConfig.put(Remoting.PASS_CONFIG_MAP_TO_MARSHAL_FACTORY, "true");
297
 
      setupServer("x=y", serverConfig);
298
 
      
299
 
      // Create client.
300
 
      InvokerLocator clientLocator = new InvokerLocator(locatorURI);
301
 
      HashMap clientConfig = new HashMap();
302
 
      clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
303
 
      clientConfig.put(InvokerLocator.MARSHALLER, ConfigTestMarshaller.class.getName());
304
 
      clientConfig.put(InvokerLocator.UNMARSHALLER, ConfigTestUnmarshaller.class.getName());
305
 
      clientConfig.put(Remoting.PASS_CONFIG_MAP_TO_MARSHAL_FACTORY, "true");
306
 
      addExtraClientConfig(clientConfig);
307
 
      Client client = new Client(clientLocator, clientConfig);
308
 
      client.connect();
309
 
      log.info("client is connected");
310
 
      
311
 
      // Test connections.
312
 
      assertEquals("abc", client.invoke("abc"));
313
 
      log.info("connection is good");
314
 
      
315
 
      // Do tests.
316
 
      assertTrue(ConfigTestMarshaller.ok(true, marshallerCountFQN()));
317
 
      assertTrue(ConfigTestUnmarshaller.ok(true, unmarshallerCountFQN()));
318
 
      assertTrue(LocatorTestMarshaller.ok());
319
 
      assertTrue(LocatorTestUnmarshaller.ok());
320
 
      
321
 
      client.disconnect();
322
 
      shutdownServer();
323
 
      log.info(getName() + " PASSES");
324
 
   }
325
 
   
326
 
 
327
 
   protected int marshallerCountDatatype()
328
 
   {
329
 
      return 6;
330
 
   }
331
 
   
332
 
   protected int unmarshallerCountDatatype()
333
 
   {
334
 
      return 4;
335
 
   }
336
 
   
337
 
   protected int marshallerCountFQN()
338
 
   {
339
 
      return 3;
340
 
   }
341
 
   
342
 
   protected int unmarshallerCountFQN()
343
 
   {
344
 
      return 2;
345
 
   }
346
 
   
347
 
   protected int marshallerDatatypeUnused()
348
 
   {
349
 
      return 2;
350
 
   }
351
 
 
352
 
   protected int marshallerFQNUnused()
353
 
   {
354
 
      return 1;
355
 
   }
356
 
   
357
 
   protected abstract String getTransport();
358
 
   
359
 
   
360
 
   protected void addExtraClientConfig(Map config) {}
361
 
   protected void addExtraServerConfig(Map config) {}
362
 
   
363
 
 
364
 
   protected void setupServer(String parameter, Map extraConfig) throws Exception
365
 
   {
366
 
      log.info("parameter: " + parameter);
367
 
      log.info("extraConfig: " + extraConfig);
368
 
      host = InetAddress.getLocalHost().getHostAddress();
369
 
      port = PortUtil.findFreePort(host);
370
 
      locatorURI = getTransport() + "://" + host + ":" + port + "/?" + parameter;
371
 
//      locatorURI += "&serializationtype=jboss";
372
 
      String metadata = System.getProperty("remoting.metadata");
373
 
      if (metadata != null)
374
 
      {
375
 
         locatorURI += "&" + metadata;
376
 
      }
377
 
      serverLocator = new InvokerLocator(locatorURI);
378
 
      log.info("Starting remoting server with locator uri of: " + locatorURI);
379
 
      HashMap config = new HashMap();
380
 
      config.put(InvokerLocator.FORCE_REMOTE, "true");
381
 
      addExtraServerConfig(config);
382
 
      if (extraConfig != null)
383
 
      {
384
 
         config.putAll(extraConfig);
385
 
      }
386
 
      connector = new Connector(serverLocator, config);
387
 
      connector.create();
388
 
      invocationHandler = getInvocationHandler();
389
 
      connector.addInvocationHandler("test", invocationHandler);
390
 
      connector.start();
391
 
   }
392
 
   
393
 
   
394
 
   protected void shutdownServer() throws Exception
395
 
   {
396
 
      if (connector != null)
397
 
         connector.stop();
398
 
   }
399
 
   
400
 
   
401
 
   protected TestInvocationHandler getInvocationHandler()
402
 
   {
403
 
      return new TestInvocationHandler();
404
 
   }
405
 
}
 
 
b'\\ No newline at end of file'