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.
22
package org.jboss.test.remoting.security;
24
import java.io.ByteArrayInputStream;
25
import java.net.InetAddress;
26
import java.util.HashMap;
29
import javax.management.MBeanServer;
30
import javax.management.MBeanServerFactory;
31
import javax.management.ObjectName;
32
import javax.xml.parsers.DocumentBuilderFactory;
34
import junit.framework.TestCase;
36
import org.apache.log4j.ConsoleAppender;
37
import org.apache.log4j.Level;
38
import org.apache.log4j.Logger;
39
import org.apache.log4j.PatternLayout;
40
import org.jboss.logging.XLevel;
41
import org.jboss.remoting.InvocationRequest;
42
import org.jboss.remoting.InvokerLocator;
43
import org.jboss.remoting.ServerInvocationHandler;
44
import org.jboss.remoting.ServerInvoker;
45
import org.jboss.remoting.callback.InvokerCallbackHandler;
46
import org.jboss.remoting.detection.multicast.MulticastDetector;
47
import org.jboss.remoting.transport.Connector;
48
import org.jboss.remoting.transport.PortUtil;
49
import org.w3c.dom.Document;
53
* Unit test for JBREM-977.
55
* @author <a href="ron.sigal@jboss.com">Ron Sigal</a>
56
* @version $Revision: 1.1 $
58
* Copyright May 4, 2008
61
public class NetworkRegistryProxyTestCase extends TestCase
63
private static Logger log = Logger.getLogger(NetworkRegistryProxyTestCase.class);
65
private static boolean firstTime = true;
66
protected String host;
68
protected String locatorURI;
69
protected InvokerLocator serverLocator;
70
protected Connector connector;
71
protected MBeanServer server;
72
protected int numAdded;
73
protected int numUpdated;
76
public void setUp() throws Exception
81
Logger.getLogger("org.jboss.remoting").setLevel(XLevel.INFO);
82
Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
83
String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
84
PatternLayout layout = new PatternLayout(pattern);
85
ConsoleAppender consoleAppender = new ConsoleAppender(layout);
86
Logger.getRootLogger().addAppender(consoleAppender);
91
public void tearDown()
96
public void testNetworkRegistryProxy() throws Throwable
98
log.info("entering " + getName());
104
MBeanServer server = MBeanServerFactory.createMBeanServer();
105
InvokerLocator locator = new InvokerLocator(locatorURI);
106
TestNetworkRegistry networkRegistry = new TestNetworkRegistry(locator);
107
ObjectName name = new ObjectName("test:type=TestNetworkRegistry");
108
server.registerMBean(networkRegistry, name);
110
// Create detector and tell it to register local Connectors.
111
MulticastDetector detector = new MulticastDetector();
112
StringBuffer buf = new StringBuffer();
113
buf.append("<?xml version=\"1.0\"?>\n");
114
buf.append("<local/>");
115
ByteArrayInputStream bais = new ByteArrayInputStream(buf.toString().getBytes());
116
Document xml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(bais);
117
detector.setConfiguration(xml.getDocumentElement());
118
server.registerMBean(detector, new ObjectName("test:type=MulticastDetector"));
121
// Verify that TestNetworkRegistry proxy gets used.
122
detector.forceDetection();
123
assertEquals(1, networkRegistry.counter);
124
int counter = ((Integer) server.getAttribute(name, "Counter")).intValue();
125
assertEquals(networkRegistry.counter, counter);
128
server.unregisterMBean(name);
130
log.info(getName() + " PASSES");
134
protected String getTransport()
140
protected void addExtraClientConfig(Map config) {}
141
protected void addExtraServerConfig(Map config) {}
144
protected void setupServer() throws Exception
146
host = InetAddress.getLocalHost().getHostAddress();
147
port = PortUtil.findFreePort(host);
148
locatorURI = getTransport() + "://" + host + ":" + port;
149
serverLocator = new InvokerLocator(locatorURI);
150
log.info("Starting remoting server with locator uri of: " + locatorURI);
151
HashMap config = new HashMap();
152
config.put(InvokerLocator.FORCE_REMOTE, "true");
153
addExtraServerConfig(config);
154
connector = new Connector(serverLocator, config);
156
connector.addInvocationHandler("test", new TestServerInvocationHandler());
161
protected void shutdownServer() throws Exception
163
if (connector != null)
168
public static class TestServerInvocationHandler implements ServerInvocationHandler
170
public void addListener(InvokerCallbackHandler callbackHandler) {}
172
public Object invoke(final InvocationRequest invocation) throws Throwable
174
return invocation.getParameter();
177
public void removeListener(InvokerCallbackHandler callbackHandler) {}
178
public void setMBeanServer(MBeanServer server) {}
179
public void setInvoker(ServerInvoker invoker) {}
b'\\ No newline at end of file'