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.
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.marshall.config;
25
import java.net.InetAddress;
26
import java.util.HashMap;
29
import junit.framework.TestCase;
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;
45
* Unit test for JBREM-1102.
47
* @author <a href="ron.sigal@jboss.com">Ron Sigal</a>
50
* Copyright Mar 20, 2009
53
public abstract class ConfigurationMapTestParent extends TestCase
55
private static Logger log = Logger.getLogger(ConfigurationMapTestParent.class);
57
private static boolean firstTime = true;
59
protected String host;
61
protected String locatorURI;
62
protected InvokerLocator serverLocator;
63
protected Connector connector;
64
protected TestInvocationHandler invocationHandler;
67
public void setUp() throws Exception
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);
80
ConfigTestMarshaller.reset();
81
ConfigTestUnmarshaller.reset();
82
LocatorTestMarshaller.reset();
83
LocatorTestUnmarshaller.reset();
87
public void tearDown()
92
public void testDatatypeConfigDefault() throws Throwable
94
log.info("entering " + getName());
96
// Cache marshaller/unmarshaller.
97
MarshalFactory.addMarshaller("config", new ConfigTestMarshaller(), new ConfigTestUnmarshaller());
100
HashMap serverConfig = new HashMap();
101
serverConfig.put(InvokerLocator.DATATYPE, "config");
102
setupServer("x=y", serverConfig);
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);
112
log.info("client is connected");
115
assertEquals("abc", client.invoke("abc"));
116
log.info("connection is good");
119
assertTrue(ConfigTestMarshaller.ok(false, marshallerDatatypeUnused()));
120
assertTrue(ConfigTestUnmarshaller.ok(false, 0));
121
assertTrue(LocatorTestMarshaller.ok());
122
assertTrue(LocatorTestUnmarshaller.ok());
126
log.info(getName() + " PASSES");
130
public void testDatatypePassConfigMapFalse() throws Throwable
132
log.info("entering " + getName());
134
// Cache marshaller/unmarshaller.
135
MarshalFactory.addMarshaller("config", new ConfigTestMarshaller(), new ConfigTestUnmarshaller());
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);
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);
152
log.info("client is connected");
155
assertEquals("abc", client.invoke("abc"));
156
log.info("connection is good");
159
assertTrue(ConfigTestMarshaller.ok(false, marshallerDatatypeUnused()));
160
assertTrue(ConfigTestUnmarshaller.ok(false, 0));
161
assertTrue(LocatorTestMarshaller.ok());
162
assertTrue(LocatorTestUnmarshaller.ok());
166
log.info(getName() + " PASSES");
170
public void testDatatypePassConfigMapTrue() throws Throwable
172
log.info("entering " + getName());
174
// Cache marshaller/unmarshaller.
175
MarshalFactory.addMarshaller("config", new ConfigTestMarshaller(), new ConfigTestUnmarshaller());
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);
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);
192
log.info("client is connected");
195
assertEquals("abc", client.invoke("abc"));
196
log.info("connection is good");
199
assertTrue(ConfigTestMarshaller.ok(true, marshallerCountDatatype()));
200
assertTrue(ConfigTestUnmarshaller.ok(true, unmarshallerCountDatatype()));
201
assertTrue(LocatorTestMarshaller.ok());
202
assertTrue(LocatorTestUnmarshaller.ok());
206
log.info(getName() + " PASSES");
210
public void testFQNConfigDefault() throws Throwable
212
log.info("entering " + getName());
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);
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);
229
log.info("client is connected");
232
assertEquals("abc", client.invoke("abc"));
233
log.info("connection is good");
236
assertTrue(ConfigTestMarshaller.ok(false,marshallerFQNUnused()));
237
assertTrue(ConfigTestUnmarshaller.ok(false, 0));
238
assertTrue(LocatorTestMarshaller.ok());
239
assertTrue(LocatorTestUnmarshaller.ok());
243
log.info(getName() + " PASSES");
249
public void testFQNPassConfigMapFalse() throws Throwable
251
log.info("entering " + getName());
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);
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);
270
log.info("client is connected");
273
assertEquals("abc", client.invoke("abc"));
274
log.info("connection is good");
277
assertTrue(ConfigTestMarshaller.ok(false, marshallerFQNUnused()));
278
assertTrue(ConfigTestUnmarshaller.ok(false, 0));
279
assertTrue(LocatorTestMarshaller.ok());
280
assertTrue(LocatorTestUnmarshaller.ok());
284
log.info(getName() + " PASSES");
288
public void testFQNConfigPassConfigMapTrue() throws Throwable
290
log.info("entering " + getName());
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);
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);
309
log.info("client is connected");
312
assertEquals("abc", client.invoke("abc"));
313
log.info("connection is good");
316
assertTrue(ConfigTestMarshaller.ok(true, marshallerCountFQN()));
317
assertTrue(ConfigTestUnmarshaller.ok(true, unmarshallerCountFQN()));
318
assertTrue(LocatorTestMarshaller.ok());
319
assertTrue(LocatorTestUnmarshaller.ok());
323
log.info(getName() + " PASSES");
327
protected int marshallerCountDatatype()
332
protected int unmarshallerCountDatatype()
337
protected int marshallerCountFQN()
342
protected int unmarshallerCountFQN()
347
protected int marshallerDatatypeUnused()
352
protected int marshallerFQNUnused()
357
protected abstract String getTransport();
360
protected void addExtraClientConfig(Map config) {}
361
protected void addExtraServerConfig(Map config) {}
364
protected void setupServer(String parameter, Map extraConfig) throws Exception
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)
375
locatorURI += "&" + metadata;
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)
384
config.putAll(extraConfig);
386
connector = new Connector(serverLocator, config);
388
invocationHandler = getInvocationHandler();
389
connector.addInvocationHandler("test", invocationHandler);
394
protected void shutdownServer() throws Exception
396
if (connector != null)
401
protected TestInvocationHandler getInvocationHandler()
403
return new TestInvocationHandler();
b'\\ No newline at end of file'