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

« back to all changes in this revision

Viewing changes to src/tests/org/jboss/test/remoting/transport/rmi/RMIInvokerDecoratorTestCase.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
package org.jboss.test.remoting.transport.rmi;
 
23
 
 
24
import java.net.InetAddress;
 
25
import java.util.HashMap;
 
26
import java.util.Map;
 
27
 
 
28
import javax.management.MBeanServer;
 
29
 
 
30
import junit.framework.TestCase;
 
31
 
 
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.logging.XLevel;
 
37
import org.jboss.remoting.Client;
 
38
import org.jboss.remoting.InvocationRequest;
 
39
import org.jboss.remoting.InvokerLocator;
 
40
import org.jboss.remoting.ServerInvocationHandler;
 
41
import org.jboss.remoting.ServerInvoker;
 
42
import org.jboss.remoting.callback.Callback;
 
43
import org.jboss.remoting.callback.HandleCallbackException;
 
44
import org.jboss.remoting.callback.InvokerCallbackHandler;
 
45
import org.jboss.remoting.marshal.MarshalFactory;
 
46
import org.jboss.remoting.transport.Connector;
 
47
import org.jboss.remoting.transport.PortUtil;
 
48
 
 
49
 
 
50
/**
 
51
 * Unit test for JBREM-167.
 
52
 * 
 
53
 * @author <a href="ron.sigal@jboss.com">Ron Sigal</a>
 
54
 * @version $Revision: 1.1 $
 
55
 * <p>
 
56
 * Copyright Mar 12, 2008
 
57
 * </p>
 
58
 */
 
59
public class RMIInvokerDecoratorTestCase extends TestCase
 
60
{
 
61
   private static Logger log = Logger.getLogger(RMIInvokerDecoratorTestCase.class);
 
62
   
 
63
   private static boolean firstTime = true;
 
64
   
 
65
   protected String host;
 
66
   protected int port;
 
67
   protected String locatorURI;
 
68
   protected InvokerLocator serverLocator;
 
69
   protected Connector connector;
 
70
   protected TestInvocationHandler invocationHandler;
 
71
 
 
72
   
 
73
   public void setUp() throws Exception
 
74
   {
 
75
      if (firstTime)
 
76
      {
 
77
         firstTime = false;
 
78
         Logger.getLogger("org.jboss.remoting").setLevel(XLevel.INFO);
 
79
         Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
 
80
         String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
 
81
         PatternLayout layout = new PatternLayout(pattern);
 
82
         ConsoleAppender consoleAppender = new ConsoleAppender(layout);
 
83
         Logger.getRootLogger().addAppender(consoleAppender);  
 
84
         MarshalFactory.addMarshaller("decorated", new TestDecorator(), new TestUnDecorator());
 
85
      }
 
86
   }
 
87
 
 
88
   
 
89
   public void tearDown()
 
90
   {
 
91
   }
 
92
   
 
93
   
 
94
   public void testDecoration() throws Throwable
 
95
   {
 
96
      log.info("entering " + getName());
 
97
      
 
98
      // Start server.
 
99
      setupServer();
 
100
      
 
101
      // Create client.
 
102
      InvokerLocator clientLocator = new InvokerLocator(locatorURI);
 
103
      HashMap clientConfig = new HashMap();
 
104
      clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
 
105
      addExtraClientConfig(clientConfig);
 
106
      Client client = new Client(clientLocator, clientConfig);
 
107
      client.connect();
 
108
      log.info("client is connected");
 
109
      
 
110
      // Test connections.
 
111
      assertEquals(new Integer(17), client.invoke(new Integer(17)));
 
112
      
 
113
      client.disconnect();
 
114
      shutdownServer();
 
115
      log.info(getName() + " PASSES");
 
116
   }
 
117
   
 
118
   
 
119
   protected String getTransport()
 
120
   {
 
121
      return "rmi";
 
122
   }
 
123
   
 
124
   
 
125
   protected void addExtraClientConfig(Map config) {}
 
126
   protected void addExtraServerConfig(Map config) {}
 
127
   
 
128
 
 
129
   protected void setupServer() throws Exception
 
130
   {
 
131
      host = InetAddress.getLocalHost().getHostAddress();
 
132
      port = PortUtil.findFreePort(host);
 
133
      locatorURI = getTransport() + "://" + host + ":" + port;
 
134
      locatorURI += "/?" + InvokerLocator.DATATYPE + "=decorated";
 
135
      serverLocator = new InvokerLocator(locatorURI);
 
136
      log.info("Starting remoting server with locator uri of: " + locatorURI);
 
137
      HashMap config = new HashMap();
 
138
      config.put(InvokerLocator.FORCE_REMOTE, "true");
 
139
      addExtraServerConfig(config);
 
140
      connector = new Connector(serverLocator, config);
 
141
      connector.create();
 
142
      invocationHandler = new TestInvocationHandler();
 
143
      connector.addInvocationHandler("test", invocationHandler);
 
144
      connector.start();
 
145
   }
 
146
   
 
147
   
 
148
   protected void shutdownServer() throws Exception
 
149
   {
 
150
      if (connector != null)
 
151
         connector.stop();
 
152
   }
 
153
   
 
154
   
 
155
   static class TestInvocationHandler implements ServerInvocationHandler
 
156
   {
 
157
      public void addListener(InvokerCallbackHandler callbackHandler) {}
 
158
      public Object invoke(final InvocationRequest invocation) throws Throwable
 
159
      {
 
160
         return invocation.getParameter();
 
161
      }
 
162
      public void removeListener(InvokerCallbackHandler callbackHandler) {}
 
163
      public void setMBeanServer(MBeanServer server) {}
 
164
      public void setInvoker(ServerInvoker invoker) {}
 
165
   }
 
166
}
 
 
b'\\ No newline at end of file'