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

« back to all changes in this revision

Viewing changes to src/tests/org/jboss/test/remoting/configuration/RMIConfigurationTestCase.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
 
 
23
package org.jboss.test.remoting.configuration;
 
24
 
 
25
import junit.framework.TestCase;
 
26
import org.jboss.remoting.Client;
 
27
import org.jboss.remoting.InvokerLocator;
 
28
import org.jboss.remoting.InvokerRegistry;
 
29
import org.jboss.remoting.ServerInvoker;
 
30
import org.jboss.remoting.transport.Connector;
 
31
import org.jboss.remoting.transport.PortUtil;
 
32
import org.jboss.test.remoting.transport.mock.MockServerInvocationHandler;
 
33
import org.w3c.dom.Document;
 
34
 
 
35
import javax.xml.parsers.DocumentBuilderFactory;
 
36
import java.io.ByteArrayInputStream;
 
37
import java.net.InetAddress;
 
38
 
 
39
 
 
40
/**
 
41
 * @author <a href="mailto:tom.elrod@jboss.com">Tom Elrod</a>
 
42
 */
 
43
public class RMIConfigurationTestCase extends TestCase
 
44
{
 
45
   private String transport = "rmi";
 
46
   private int serverPort = 6666;
 
47
   private int clientPort = 7777;
 
48
   private int registryPort = 8888;
 
49
   private String hostName = null;
 
50
   private String hostIP = null;
 
51
   private Connector connector = null;
 
52
 
 
53
   public void setUp() throws Exception
 
54
   {
 
55
      hostName = InetAddress.getLocalHost().getHostName();
 
56
      hostIP = InetAddress.getLocalHost().getHostAddress();
 
57
 
 
58
      connector = new Connector();
 
59
      StringBuffer buf = new StringBuffer();
 
60
      buf.append("<?xml version=\"1.0\"?>\n");
 
61
      buf.append("<config>");
 
62
      buf.append("<invoker transport=\"" + transport + "\">");
 
63
      buf.append("<attribute name=\"registryPort\" isParam=\"true\">" + registryPort + "</attribute>");
 
64
      buf.append("<attribute name=\"serverBindAddress\">" + hostName + "</attribute>");
 
65
      buf.append("<attribute name=\"serverBindPort\">" + serverPort + "</attribute>");
 
66
      buf.append("<attribute name=\"clientConnectAddress\">" + hostIP + "</attribute>");
 
67
      buf.append("<attribute name=\"clientConnectPort\">" + clientPort + "</attribute>");
 
68
      buf.append("</invoker>");
 
69
      buf.append("<handlers>");
 
70
      buf.append("  <handler subsystem=\"mock\">" + MockServerInvocationHandler.class.getName() + "</handler>\n");
 
71
      buf.append("</handlers>");
 
72
      buf.append("</config>");
 
73
      Document xml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream(buf.toString().getBytes()));
 
74
      connector.setConfiguration(xml.getDocumentElement());
 
75
      connector.create();
 
76
      connector.start();
 
77
 
 
78
   }
 
79
 
 
80
   public void testClientConfiguration() throws Exception
 
81
   {
 
82
 
 
83
      // make sure the client's view of the locator will be as configured
 
84
      ServerInvoker[] serverInvokers = InvokerRegistry.getServerInvokers();
 
85
 
 
86
      if(serverInvokers != null && serverInvokers.length > 0)
 
87
      {
 
88
         InvokerLocator locator = serverInvokers[0].getLocator();
 
89
         String locatorHost = locator.getHost();
 
90
         int locatorPort = locator.getPort();
 
91
 
 
92
         System.out.println("locator host = " + locatorHost);
 
93
         System.out.println("locator port = " + locatorPort);
 
94
         assertEquals(hostIP, locatorHost);
 
95
         assertEquals(clientPort, locatorPort);
 
96
      }
 
97
 
 
98
      // check for server bind port (assume is the server since no exception thrown before)
 
99
      boolean portAvailable = PortUtil.checkPort(serverPort, hostName);
 
100
      assertTrue(!portAvailable);
 
101
      portAvailable = PortUtil.checkPort(registryPort, hostName);
 
102
      assertTrue(!portAvailable);
 
103
 
 
104
      // make sure can call ont
 
105
      Client client = new Client(new InvokerLocator(transport + "://" + hostName + ":" + serverPort + "/?registryPort=" + registryPort));
 
106
      client.connect();
 
107
      String param = "foobar";
 
108
      Object ret = null;
 
109
      try
 
110
      {
 
111
         ret = client.invoke(param);
 
112
      }
 
113
      catch(Throwable throwable)
 
114
      {
 
115
         throw new Exception("Call on server failed.", throwable);
 
116
      }
 
117
      assertEquals(param, ret);
 
118
 
 
119
   }
 
120
 
 
121
   public void tearDown() throws Exception
 
122
   {
 
123
      if(connector != null)
 
124
      {
 
125
         connector.stop();
 
126
         connector.destroy();
 
127
      }
 
128
   }
 
129
 
 
130
   public static void main(String[] args)
 
131
   {
 
132
      RMIConfigurationTestCase testCase = new RMIConfigurationTestCase();
 
133
      try
 
134
      {
 
135
         testCase.setUp();
 
136
         testCase.testClientConfiguration();
 
137
         testCase.tearDown();
 
138
      }
 
139
      catch(Exception e)
 
140
      {
 
141
         e.printStackTrace();
 
142
      }
 
143
   }
 
144
}
 
 
b'\\ No newline at end of file'