2
* JBoss, Home of Professional Open Source
3
* Copyright 2009, 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.
22
package org.jboss.test.remoting.template;
24
import java.net.InetAddress;
25
import java.util.HashMap;
28
import javax.management.MBeanServer;
30
import junit.framework.TestCase;
32
import org.apache.log4j.ConsoleAppender;
33
import org.apache.log4j.Level;
34
import org.apache.log4j.Logger;
35
import org.apache.log4j.PatternLayout;
36
import org.jboss.remoting.Client;
37
import org.jboss.remoting.InvocationRequest;
38
import org.jboss.remoting.InvokerLocator;
39
import org.jboss.remoting.ServerInvocationHandler;
40
import org.jboss.remoting.ServerInvoker;
41
import org.jboss.remoting.callback.Callback;
42
import org.jboss.remoting.callback.HandleCallbackException;
43
import org.jboss.remoting.callback.InvokerCallbackHandler;
44
import org.jboss.remoting.transport.Connector;
45
import org.jboss.remoting.transport.PortUtil;
48
public class TestCaseTemplate extends TestCase
50
private static Logger log = Logger.getLogger(TestCaseTemplate.class);
52
private static boolean firstTime = true;
54
protected String host;
56
protected String locatorURI;
57
protected InvokerLocator serverLocator;
58
protected Connector connector;
59
protected TestInvocationHandler invocationHandler;
62
public void setUp() throws Exception
67
Logger.getLogger("org.jboss.remoting").setLevel(Level.INFO);
68
Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
69
String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
70
PatternLayout layout = new PatternLayout(pattern);
71
ConsoleAppender consoleAppender = new ConsoleAppender(layout);
72
Logger.getRootLogger().addAppender(consoleAppender);
77
public void tearDown()
82
public void testMethod() throws Throwable
84
log.info("entering " + getName());
90
InvokerLocator clientLocator = new InvokerLocator(locatorURI);
91
HashMap clientConfig = new HashMap();
92
clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
93
addExtraClientConfig(clientConfig);
94
Client client = new Client(clientLocator, clientConfig);
96
log.info("client is connected");
99
assertEquals("abc", client.invoke("abc"));
100
log.info("connection is good");
104
log.info(getName() + " PASSES");
108
protected String getTransport()
114
protected void addExtraClientConfig(Map config) {}
115
protected void addExtraServerConfig(Map config) {}
118
protected void setupServer() throws Exception
120
host = InetAddress.getLocalHost().getHostAddress();
121
port = PortUtil.findFreePort(host);
122
locatorURI = getTransport() + "://" + host + ":" + port;
123
String metadata = System.getProperty("remoting.metadata");
124
if (metadata != null)
126
locatorURI += "/?" + metadata;
128
serverLocator = new InvokerLocator(locatorURI);
129
log.info("Starting remoting server with locator uri of: " + locatorURI);
130
HashMap config = new HashMap();
131
config.put(InvokerLocator.FORCE_REMOTE, "true");
132
addExtraServerConfig(config);
133
connector = new Connector(serverLocator, config);
135
invocationHandler = new TestInvocationHandler();
136
connector.addInvocationHandler("test", invocationHandler);
141
protected void shutdownServer() throws Exception
143
if (connector != null)
148
static class TestInvocationHandler implements ServerInvocationHandler
150
public void addListener(InvokerCallbackHandler callbackHandler) {}
151
public Object invoke(final InvocationRequest invocation) throws Throwable
153
return invocation.getParameter();
155
public void removeListener(InvokerCallbackHandler callbackHandler) {}
156
public void setMBeanServer(MBeanServer server) {}
157
public void setInvoker(ServerInvoker invoker) {}
161
static class TestCallbackHandler implements InvokerCallbackHandler
163
public void handleCallback(Callback callback) throws HandleCallbackException
165
log.info("received callback");
b'\\ No newline at end of file'