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

« back to all changes in this revision

Viewing changes to src/tests/org/jboss/test/remoting/multihome/XmlMultihomeConfigTestCase.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 2006, 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.multihome;
 
24
 
 
25
import java.io.ByteArrayInputStream;
 
26
 
 
27
import javax.xml.parsers.DocumentBuilderFactory;
 
28
 
 
29
import junit.framework.TestCase;
 
30
 
 
31
import org.jboss.logging.Logger;
 
32
import org.jboss.remoting.transport.Connector;
 
33
import org.w3c.dom.Document;
 
34
 
 
35
/**
 
36
 * Unit tests for JBREM-983.
 
37
 * 
 
38
 * @author <a href="mailto:ron.sigal@jboss.com">Ron Sigal</a>
 
39
 * @version $Revision: 3873 $
 
40
 * <p>
 
41
 * Copyright (c) Jun 13, 2006
 
42
 * </p>
 
43
 */
 
44
public class XmlMultihomeConfigTestCase extends TestCase
 
45
{
 
46
   protected static Logger log = Logger.getLogger(XmlMultihomeConfigTestCase.class);
 
47
   protected static boolean firstTime = true;
 
48
   
 
49
   
 
50
   protected String getTransport()
 
51
   {
 
52
      return "socket";
 
53
   }
 
54
   
 
55
   
 
56
   public void setUp()
 
57
   {
 
58
   }
 
59
   
 
60
 
 
61
   public void testXmlConfigOneHome() throws Throwable
 
62
   {
 
63
      Connector connector = new Connector();
 
64
 
 
65
      // Create and set xml configuration document.
 
66
      StringBuffer buf = new StringBuffer();
 
67
      buf.append("<?xml version=\"1.0\"?>\n");
 
68
      buf.append("<config>");
 
69
      buf.append("   <invoker transport=\"socket\">");
 
70
      buf.append("      <attribute name=\"homes\">");
 
71
      buf.append("         <home>host2:2222</home>");
 
72
      buf.append("      </attribute>");
 
73
      buf.append("      <attribute name=\"path\">a/b</attribute>");
 
74
      buf.append("      <attribute name=\"timeout\" isParam=\"true\">1000</attribute>");
 
75
      buf.append("   </invoker>");
 
76
      buf.append("</config>");
 
77
      ByteArrayInputStream bais = new ByteArrayInputStream(buf.toString().getBytes());
 
78
      Document xml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(bais);
 
79
      connector.setConfiguration(xml.getDocumentElement());
 
80
      connector.create();
 
81
      
 
82
      String createdURI = connector.getInvokerLocator();
 
83
      log.info("created InvokerLocator:  " + createdURI);
 
84
      String expectedURI = "socket://multihome/a/b/?";
 
85
      expectedURI       += "homes=host2:2222&";
 
86
      expectedURI       += "timeout=1000";
 
87
      log.info("expected InvokerLocator: " + expectedURI);
 
88
      assertEquals(expectedURI, createdURI);
 
89
      
 
90
      log.info(getName() + " PASSES");
 
91
   }
 
92
   
 
93
   
 
94
   public void testXmlConfigThreeHomes() throws Throwable
 
95
   {
 
96
      Connector connector = new Connector();
 
97
 
 
98
      // Create and set xml configuration document.
 
99
      StringBuffer buf = new StringBuffer();
 
100
      buf.append("<?xml version=\"1.0\"?>\n");
 
101
      buf.append("<config>");
 
102
      buf.append("   <invoker transport=\"socket\">");
 
103
      buf.append("      <attribute name=\"homes\">");
 
104
      buf.append("         <home>host2:2222</home>");
 
105
      buf.append("         <home>host3:3333</home>");
 
106
      buf.append("         <home>host4:4444</home>");
 
107
      buf.append("      </attribute>");
 
108
      buf.append("      <attribute name=\"path\">a/b</attribute>");
 
109
      buf.append("      <attribute name=\"timeout\" isParam=\"true\">1000</attribute>");
 
110
      buf.append("   </invoker>");
 
111
      buf.append("</config>");
 
112
      ByteArrayInputStream bais = new ByteArrayInputStream(buf.toString().getBytes());
 
113
      Document xml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(bais);
 
114
      connector.setConfiguration(xml.getDocumentElement());
 
115
      connector.create();
 
116
      
 
117
      String createdURI = connector.getInvokerLocator();
 
118
      log.info("created InvokerLocator:  " + createdURI);
 
119
      String expectedURI = "socket://multihome/a/b/?";
 
120
      expectedURI       += "homes=host2:2222!host3:3333!host4:4444&";
 
121
      expectedURI       += "timeout=1000";
 
122
      log.info("expected InvokerLocator: " + expectedURI);
 
123
      assertEquals(expectedURI, createdURI);
 
124
      
 
125
      log.info(getName() + " PASSES");
 
126
   }
 
127
   
 
128
   
 
129
   public void testXmlConfigWithConnectHomes() throws Throwable
 
130
   {
 
131
      Connector connector = new Connector();
 
132
 
 
133
      // Create and set xml configuration document.
 
134
      StringBuffer buf = new StringBuffer();
 
135
      buf.append("<?xml version=\"1.0\"?>\n");
 
136
      buf.append("<config>");
 
137
      buf.append("   <invoker transport=\"socket\">");
 
138
      buf.append("      <attribute name=\"homes\">");
 
139
      buf.append("         <home>host2:2222</home>");
 
140
      buf.append("         <home>host3:3333</home>");
 
141
      buf.append("      </attribute>");
 
142
      buf.append("      <attribute name=\"connecthomes\">");
 
143
      buf.append("         <connecthome>host4:4444</connecthome>");
 
144
      buf.append("         <connecthome>host5:5555</connecthome>");
 
145
      buf.append("      </attribute>");
 
146
      buf.append("      <attribute name=\"path\">a/b</attribute>");
 
147
      buf.append("      <attribute name=\"timeout\" isParam=\"true\">1000</attribute>");
 
148
      buf.append("   </invoker>");
 
149
      buf.append("</config>");
 
150
      ByteArrayInputStream bais = new ByteArrayInputStream(buf.toString().getBytes());
 
151
      Document xml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(bais);
 
152
      connector.setConfiguration(xml.getDocumentElement());
 
153
      connector.create();
 
154
      
 
155
      String createdURI = connector.getInvokerLocator();
 
156
      log.info("created InvokerLocator:  " + createdURI);
 
157
      String expectedURI = "socket://multihome/a/b/?";
 
158
      expectedURI       += "connecthomes=host4:4444!host5:5555&";
 
159
      expectedURI       += "homes=host2:2222!host3:3333&";
 
160
      expectedURI       += "timeout=1000";
 
161
      log.info("expected InvokerLocator: " + expectedURI);
 
162
      assertEquals(expectedURI, createdURI);
 
163
      
 
164
      log.info(getName() + " PASSES");
 
165
   }
 
166
   
 
167
   
 
168
   public void testXmlConfigWithServerBindPort() throws Throwable
 
169
   {
 
170
      Connector connector = new Connector();
 
171
 
 
172
      // Create and set xml configuration document.
 
173
      StringBuffer buf = new StringBuffer();
 
174
      buf.append("<?xml version=\"1.0\"?>\n");
 
175
      buf.append("<config>");
 
176
      buf.append("   <invoker transport=\"socket\">");
 
177
      buf.append("      <attribute name=\"serverBindAddress\">host1</attribute>");
 
178
      buf.append("      <attribute name=\"serverBindPort\">1111</attribute>");
 
179
      buf.append("      <attribute name=\"homes\">");
 
180
      buf.append("         <home>host2:2222</home>");
 
181
      buf.append("         <home>host3</home>");
 
182
      buf.append("      </attribute>");
 
183
      buf.append("      <attribute name=\"connecthomes\">");
 
184
      buf.append("         <connecthome>host4</connecthome>");
 
185
      buf.append("         <connecthome>host5:5555</connecthome>");
 
186
      buf.append("      </attribute>");
 
187
      buf.append("      <attribute name=\"path\">a/b</attribute>");
 
188
      buf.append("      <attribute name=\"timeout\" isParam=\"true\">1000</attribute>");
 
189
      buf.append("   </invoker>");
 
190
      buf.append("</config>");
 
191
      ByteArrayInputStream bais = new ByteArrayInputStream(buf.toString().getBytes());
 
192
      Document xml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(bais);
 
193
      connector.setConfiguration(xml.getDocumentElement());
 
194
      connector.create();
 
195
      
 
196
      String createdURI = connector.getInvokerLocator();
 
197
      log.info("created InvokerLocator:  " + createdURI);
 
198
      String expectedURI = "socket://multihome:1111/a/b/?";
 
199
      expectedURI       += "connecthomes=host4:1111!host5:5555&";
 
200
      expectedURI       += "homes=host2:2222!host3:1111&";
 
201
      expectedURI       += "timeout=1000";
 
202
      log.info("expected InvokerLocator: " + expectedURI);
 
203
      assertEquals(expectedURI, createdURI);
 
204
      
 
205
      log.info(getName() + " PASSES");
 
206
   }
 
207
   
 
208
   
 
209
   public void testXmlConfigWithClientConnectPort() throws Throwable
 
210
   {
 
211
      Connector connector = new Connector();
 
212
 
 
213
      // Create and set xml configuration document.
 
214
      StringBuffer buf = new StringBuffer();
 
215
      buf.append("<?xml version=\"1.0\"?>\n");
 
216
      buf.append("<config>");
 
217
      buf.append("   <invoker transport=\"socket\">");
 
218
      buf.append("      <attribute name=\"serverBindAddress\">host1</attribute>");
 
219
      buf.append("      <attribute name=\"serverBindPort\">1111</attribute>");
 
220
      buf.append("      <attribute name=\"clientConnectAddress\">host2</attribute>");
 
221
      buf.append("      <attribute name=\"clientConnectPort\">2222</attribute>");
 
222
      buf.append("      <attribute name=\"homes\">");
 
223
      buf.append("         <home>host3:3333</home>");
 
224
      buf.append("         <home>host4</home>");
 
225
      buf.append("      </attribute>");
 
226
      buf.append("      <attribute name=\"connecthomes\">");
 
227
      buf.append("         <connecthome>host5</connecthome>");
 
228
      buf.append("         <connecthome>host6:6666</connecthome>");
 
229
      buf.append("      </attribute>");
 
230
      buf.append("      <attribute name=\"path\">a/b</attribute>");
 
231
      buf.append("      <attribute name=\"timeout\" isParam=\"true\">1000</attribute>");
 
232
      buf.append("   </invoker>");
 
233
      buf.append("</config>");
 
234
      ByteArrayInputStream bais = new ByteArrayInputStream(buf.toString().getBytes());
 
235
      Document xml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(bais);
 
236
      connector.setConfiguration(xml.getDocumentElement());
 
237
      connector.create();
 
238
      
 
239
      String createdURI = connector.getInvokerLocator();
 
240
      log.info("created InvokerLocator:  " + createdURI);
 
241
      String expectedURI = "socket://multihome:2222/a/b/?";
 
242
      expectedURI       += "connecthomes=host5:2222!host6:6666&";
 
243
      expectedURI       += "homes=host3:3333!host4:2222&";
 
244
      expectedURI       += "timeout=1000";
 
245
      log.info("expected InvokerLocator: " + expectedURI);
 
246
      assertEquals(expectedURI, createdURI);
 
247
      
 
248
      log.info(getName() + " PASSES");
 
249
   }
 
250
   
 
251
   
 
252
   public void testXmlConfigWithConnectHomesAndNoHomes() throws Throwable
 
253
   {
 
254
      Connector connector = new Connector();
 
255
 
 
256
      // Create and set xml configuration document.
 
257
      StringBuffer buf = new StringBuffer();
 
258
      buf.append("<?xml version=\"1.0\"?>\n");
 
259
      buf.append("<config>");
 
260
      buf.append("   <invoker transport=\"socket\">");
 
261
      buf.append("      <attribute name=\"connecthomes\">");
 
262
      buf.append("         <connecthome>host5</connecthome>");
 
263
      buf.append("         <connecthome>host6:6666</connecthome>");
 
264
      buf.append("      </attribute>");
 
265
      buf.append("      <attribute name=\"path\">a/b</attribute>");
 
266
      buf.append("      <attribute name=\"timeout\" isParam=\"true\">1000</attribute>");
 
267
      buf.append("   </invoker>");
 
268
      buf.append("</config>");
 
269
      ByteArrayInputStream bais = new ByteArrayInputStream(buf.toString().getBytes());
 
270
      Document xml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(bais);
 
271
      connector.setConfiguration(xml.getDocumentElement());
 
272
 
 
273
      try
 
274
      {
 
275
         log.info("=================  EXCEPTION EXPECTED ================");
 
276
         connector.create();
 
277
         fail("Should have gotten IllegalStateException");
 
278
      }
 
279
      catch (IllegalStateException e)
 
280
      {
 
281
         String msg = "Error configuring invoker for connector.  Can not continue without invoker.";
 
282
         assertEquals("unexpected message", msg, e.getMessage());
 
283
         log.info("got expected IllegalStateException");
 
284
         log.info("======================================================");
 
285
      }
 
286
      
 
287
      log.info(getName() + " PASSES");
 
288
   }
 
289
}
 
 
b'\\ No newline at end of file'