1
2
3
4
5 package test.crispy.impl;
6
7 import java.util.ArrayList;
8 import java.util.Date;
9 import java.util.Hashtable;
10 import java.util.List;
11 import java.util.Map;
12 import java.util.Properties;
13 import java.util.Vector;
14
15 import junit.framework.TestCase;
16 import net.sf.crispy.ExceptionWrapper;
17 import net.sf.crispy.InterceptorContext;
18 import net.sf.crispy.InterceptorHandler;
19 import net.sf.crispy.Modifier;
20 import net.sf.crispy.Property;
21 import net.sf.crispy.impl.ServiceManager;
22 import net.sf.crispy.impl.XmlRpcExecutor;
23 import net.sf.crispy.impl.xmlrpc.MiniXmlRpcServer;
24 import net.sf.crispy.impl.xmlrpc.XmlRpcAdminService;
25 import net.sf.crispy.impl.xmlrpc.XmlRpcConvertHandler;
26 import net.sf.crispy.interceptor.LogInterceptor;
27 import net.sf.crispy.interceptor.StopWatchInterceptor;
28 import net.sf.crispy.server.InterceptorHandlerCreator;
29 import net.sf.crispy.server.ServiceEndpoint;
30 import net.sf.crispy.server.ServiceEndpointImpl;
31 import test.crispy.JUnitTestException;
32 import test.crispy.JUnitTestException2;
33 import test.crispy.compatibility.CompatibilityKit;
34 import test.crispy.concurrent.AsynchronousCallbackForTests;
35 import test.crispy.example.model.Adresse;
36 import test.crispy.example.model.Kunde;
37 import test.crispy.example.model.Primitive;
38 import test.crispy.example.model.SubSubProblemNode;
39 import test.crispy.example.model.ValidationError;
40 import test.crispy.example.service.Calculator;
41 import test.crispy.example.service.CalculatorImpl;
42 import test.crispy.example.service.Echo;
43 import test.crispy.example.service.EchoImpl;
44 import test.crispy.example.service.MyService;
45 import test.crispy.example.service.MyServiceImpl;
46 import test.crispy.example.service.RemoteCalculator;
47 import test.crispy.example.service.RemoteCalculatorImpl;
48
49 /**
50 * @author Linke
51 *
52 */
53 public class XmlRpcServiceTest extends TestCase {
54
55
56 private static MiniXmlRpcServer miniXmlRpcServer = null;
57 private CompatibilityKit compatibilityKit = new CompatibilityKit();
58 private String nullValue = "!---Null-Value---!";
59
60 /**
61 * Init <code>static</code> MiniXmlRpcServer for all tests.
62 */
63 public XmlRpcServiceTest() {
64 if (miniXmlRpcServer == null) {
65 miniXmlRpcServer = new MiniXmlRpcServer(nullValue);
66
67 miniXmlRpcServer.addService(Echo.class.getName(), EchoImpl.class.getName());
68 miniXmlRpcServer.addService(Calculator.class.getName(), CalculatorImpl.class.getName());
69 miniXmlRpcServer.addService(MyService.class.getName(), MyServiceImpl.class.getName());
70
71 miniXmlRpcServer.start();
72 }
73 compatibilityKit.addProperty(Property.EXECUTOR_CLASS, XmlRpcExecutor.class.getName());
74 }
75
76 /**
77 * Started MiniXmlRpcServer.
78 *
79 * @see junit.framework.TestCase#setUp()
80 */
81 protected void setUp() throws Exception {
82 super.setUp();
83 compatibilityKit.removeProperty(Property.DYNAMIC_PROXY_CLASS);
84 compatibilityKit.removeProperty(Property.NULL_VALUE);
85 }
86
87
88 private Properties getProperties() {
89 Properties prop = new Properties();
90 prop.put(Property.EXECUTOR_CLASS, XmlRpcExecutor.class.getName());
91 prop.put(Property.REMOTE_URL_AND_PORT, "http://localhost:9090");
92
93 prop.put(Property.SECURITY_USER, "user");
94 prop.put(Property.SECURITY_PASSWD, "passwd");
95
96
97 return prop;
98 }
99
100 public void testEchoPrimitive() throws Exception {
101 Properties prop = new Properties();
102 prop.put(Property.EXECUTOR_CLASS, XmlRpcExecutor.class.getName());
103
104 ServiceManager lvServiceManager = new ServiceManager(prop);
105 Echo lvEcho = (Echo) lvServiceManager.createService(Echo.class);
106 Primitive lvPrimitive = Primitive.createPrimitiveExample();
107
108 Primitive lvPrimitiveAfter = lvEcho.echoPrimitive(lvPrimitive);
109 assertEquals(lvPrimitive, lvPrimitiveAfter);
110 assertNotSame(lvPrimitive, lvPrimitiveAfter);
111 }
112
113 public void testSimpleRemoteInvocation() throws Exception {
114 compatibilityKit.makeSimpleEchoTest(compatibilityKit.createServiceManager());
115 }
116
117
118 public void testSimpleRemoteInvocationWithDynamicCglibProxy() throws Exception {
119 compatibilityKit.addProperty(Property.DYNAMIC_PROXY_CLASS, Property.VALUE_FOR_CGLIB_DYNAMIC_PROXY);
120 compatibilityKit.makeSimpleEchoTest(compatibilityKit.createServiceManager());
121 }
122
123
124 public void testSimpleRemoteInvocationWithDynamicJdkProxy() throws Exception {
125 compatibilityKit.addProperty(Property.DYNAMIC_PROXY_CLASS, Property.VALUE_FOR_JDK_DYNAMIC_PROXY);
126 compatibilityKit.makeSimpleEchoTest(compatibilityKit.createServiceManager());
127 }
128
129 public void testSimpleDoubleRemoteInvocation() throws Exception {
130 compatibilityKit.makeMultipleServiceTest();
131 }
132
133 public void testComplexRemoteInvocation() throws Exception {
134 compatibilityKit.makeComplexEchoTest(compatibilityKit.createServiceManager());
135 }
136
137 public void testCycleDetectionTest() throws Exception {
138 compatibilityKit.makeCycleDetectionTest(compatibilityKit.createServiceManager());
139 }
140
141 public void testAddNode() throws Exception {
142 compatibilityKit.makeAddNodeTest(compatibilityKit.createServiceManager());
143 }
144
145 public void testXmlRpcAdminService() {
146 ServiceManager lvServiceManager = new ServiceManager(getProperties());
147 XmlRpcAdminService lvAdminService = (XmlRpcAdminService) lvServiceManager.createService(XmlRpcAdminService.class);
148 assertNotNull("Es konnte kein XmlRpcAdminService geladen werden: " + lvAdminService, lvAdminService);
149
150 String lvRemoveService = lvAdminService.removeService(Echo.class.getName());
151 assertEquals(lvRemoveService, Echo.class.getName());
152 String lvAddService = lvAdminService.addService(Echo.class.getName(), EchoImpl.class.getName());
153 assertEquals(lvAddService, Echo.class.getName());
154
155 Boolean lvExistService = lvAdminService.existService(Echo.class.getName());
156 assertTrue(lvExistService.booleanValue());
157
158 List lvAllService = lvAdminService.getAllService();
159 int lvSizeService = lvAllService.size();
160 assertTrue(lvSizeService > 2);
161 }
162
163 public void testProxyInterceptor() throws Exception {
164 Properties prop = getProperties();
165 prop.put(Property.INTERCEPTOR_CLASS, StopWatchInterceptor.class.getName());
166
167 ServiceManager lvServiceManager = new ServiceManager(prop);
168
169 Calculator lvCalculator = (Calculator) lvServiceManager.createService(Calculator.class);
170 assertNotNull(lvCalculator);
171 int lvResult = lvCalculator.add(2, 3);
172 assertEquals(lvResult, 5);
173 lvResult = lvCalculator.subtract(8, 2);
174 assertEquals(lvResult, 6);
175
176
177 Echo lvEcho = (Echo) lvServiceManager.createService(Echo.class);
178 assertNotNull(lvEcho);
179 String lvEchoStr = "Hallo Echo";
180 assertEquals(lvEcho.echo(lvEchoStr), lvEchoStr);
181
182
183
184
185 }
186
187 public void testModifyService() throws Exception {
188 compatibilityKit.makeModifyServiceTest(compatibilityKit.createServiceManager());
189 }
190
191 public void testMiniXmlRpcServerAddService() throws Exception {
192 miniXmlRpcServer.addService(RemoteCalculator.class.getName(), new RemoteCalculatorImpl());
193
194 Properties prop = new Properties();
195 prop.put(Property.REMOTE_URL_AND_PORT, "http://localhost:9090");
196 prop.put(Property.INTERCEPTOR_CLASS, LogInterceptor.class.getName());
197 prop.put(Property.EXECUTOR_CLASS, XmlRpcExecutor.class.getName());
198
199 ServiceManager manager = new ServiceManager(prop);
200
201 RemoteCalculator remoteCalculator = (RemoteCalculator) manager.createService(RemoteCalculator.class);
202 assertEquals(remoteCalculator.add(1,2 ), 3);
203
204 }
205
206 public void testAddLongs() throws Exception {
207 Properties prop = getProperties();
208
209 ServiceManager manager = new ServiceManager(prop);
210 Calculator calc = (Calculator) manager.createService(Calculator.class);
211 assertEquals(calc.addLong(new Long(123l), new Long(124l)), new Long(247));
212 }
213
214 public void testOverloading() throws Exception {
215 Properties prop = new Properties();
216 prop.put(Property.REMOTE_URL_AND_PORT, "http://localhost:9090");
217 prop.put(Property.EXECUTOR_CLASS, XmlRpcExecutor.class.getName());
218
219 ServiceManager manager = new ServiceManager(prop);
220 Calculator lvCalculator = (Calculator) manager.createService(Calculator.class);
221 int lvIntResult = lvCalculator.add(2, 3);
222 assertEquals(lvIntResult, 5);
223 long lvLongResult = lvCalculator.add(21, 32);
224 assertEquals(lvLongResult, 53);
225 double lvDoubleResult = lvCalculator.add(2.3, 3.2);
226 assertEquals(lvDoubleResult, 5.5, 0);
227 }
228
229 public void testOverloadingInteger() throws Exception {
230 Properties prop = new Properties();
231 prop.put(Property.REMOTE_URL_AND_PORT, "http://localhost:9090");
232 prop.put(Property.EXECUTOR_CLASS, XmlRpcExecutor.class.getName());
233
234 ServiceManager manager = new ServiceManager(prop);
235 Echo echo = (Echo) manager.createService(Echo.class);
236 Integer i[] = echo.echoArray(new Integer[] {new Integer(1), new Integer(3), new Integer(5)});
237 assertTrue(i.length == 3);
238 assertEquals(i[0], new Integer(1));
239 assertEquals(i[1], new Integer(3));
240 assertEquals(i[2], new Integer(5));
241 }
242
243 public void testOverloadingLong() throws Exception {
244 Properties prop = new Properties();
245 prop.put(Property.REMOTE_URL_AND_PORT, "http://localhost:9090");
246 prop.put(Property.EXECUTOR_CLASS, XmlRpcExecutor.class.getName());
247
248 ServiceManager manager = new ServiceManager(prop);
249 Echo echo = (Echo) manager.createService(Echo.class);
250 Long l[] = echo.echoArray(new Long[] {new Long(1), new Long(5)});
251 assertTrue(l.length == 2);
252 assertEquals(l[0], new Long(1));
253 assertEquals(l[1], new Long(5));
254 }
255
256 public void testOverloadingObject() throws Exception {
257 Properties prop = new Properties();
258 prop.put(Property.REMOTE_URL_AND_PORT, "http://localhost:9090");
259 prop.put(Property.EXECUTOR_CLASS, XmlRpcExecutor.class.getName());
260
261 ServiceManager manager = new ServiceManager(prop);
262 Echo echo = (Echo) manager.createService(Echo.class);
263 Object o[] = echo.echoArray(new Object[] {"a", new Integer(3), new Long(5)});
264 assertTrue(o.length == 3);
265 assertEquals(o[0], "a");
266 assertEquals(o[1], new Integer(3));
267
268 }
269
270 public void testCreateService() throws Exception {
271 Properties prop = new Properties();
272 prop.put(Property.REMOTE_URL_AND_PORT, "http://localhost:9090");
273 prop.put(Property.EXECUTOR_CLASS, XmlRpcExecutor.class.getName());
274
275 ServiceManager lvManager = new ServiceManager(prop);
276 Calculator lvCalculator1 = (Calculator) lvManager.createService(Calculator.class);
277 Calculator lvCalculator2 = (Calculator) lvManager.createService(Calculator.class);
278
279 assertNotNull(lvCalculator1);
280 assertNotNull(lvCalculator2);
281 assertNotSame(lvCalculator1, lvCalculator2);
282 }
283
284 public void testThrowException() throws Exception {
285 Properties prop = new Properties();
286 prop.put(Property.REMOTE_URL_AND_PORT, "http://localhost:9090");
287 prop.put(Property.EXECUTOR_CLASS, XmlRpcExecutor.class.getName());
288
289 ServiceManager lvManager = new ServiceManager(prop);
290
291 Echo lvEcho = (Echo) lvManager.createService(Echo.class);
292 boolean throwException = false;
293 try {
294 lvEcho.throwException("A Test-Excption.");
295 } catch (JUnitTestException e) {
296 throwException = true;
297 }
298 assertTrue("No Exception thrown: " + throwException, throwException);
299 }
300
301 public void testNullValueParamsWithException() throws Exception {
302 Properties prop = new Properties();
303 prop.put(Property.EXECUTOR_CLASS, XmlRpcExecutor.class.getName());
304
305 ServiceManager lvManager = new ServiceManager(prop);
306
307 Echo lvEcho = (Echo) lvManager.createService(Echo.class);
308 try {
309 lvEcho.echo(null);
310 fail("Null Value are not supported");
311 } catch (Exception e) {
312 assertTrue(true);
313 }
314 }
315
316 public void testNullStringValueParams() throws Exception {
317 Properties prop = new Properties();
318 prop.put(Property.NULL_VALUE, nullValue);
319 prop.put(Property.EXECUTOR_CLASS, XmlRpcExecutor.class.getName());
320
321 ServiceManager lvManager = new ServiceManager(prop);
322
323 Echo lvEcho = (Echo) lvManager.createService(Echo.class);
324 String s = lvEcho.echo(null);
325 assertNull(s);
326 }
327
328 public void testNullLongValueParams() throws Exception {
329 Properties prop = new Properties();
330 prop.put(Property.NULL_VALUE, nullValue);
331 prop.put(Property.EXECUTOR_CLASS, XmlRpcExecutor.class.getName());
332
333 ServiceManager lvManager = new ServiceManager(prop);
334
335 Calculator lvCalculator = (Calculator) lvManager.createService(Calculator.class);
336 Long lvLong = lvCalculator.addLong(null, null);
337 assertNull(lvLong);
338 }
339
340 public void testNullComplexValueParams() throws Exception {
341 Properties prop = new Properties();
342 prop.put(Property.NULL_VALUE, nullValue);
343 prop.put(Property.EXECUTOR_CLASS, XmlRpcExecutor.class.getName());
344
345 ServiceManager lvManager = new ServiceManager(prop);
346
347 Echo lvEcho = (Echo) lvManager.createService(Echo.class);
348 Kunde k = lvEcho.renameKunde(null, null);
349 assertNull(k);
350 }
351
352 public void testSimpleRemotePing() throws Exception {
353 Properties prop = new Properties();
354 prop.put(Property.EXECUTOR_CLASS, XmlRpcExecutor.class.getName());
355
356 ServiceManager manager = new ServiceManager(prop);
357 Echo echo = (Echo) manager.createService(Echo.class);
358 String lvPing = echo.ping();
359 assertEquals(lvPing, Echo.PING_STRING);
360 }
361
362 public void testTransferDate() throws Exception {
363 Properties prop = new Properties();
364 prop.put(Property.EXECUTOR_CLASS, XmlRpcExecutor.class.getName());
365
366 ServiceManager manager = new ServiceManager(prop);
367 MyService lvMyService = (MyService) manager.createService(MyService.class);
368
369 SubSubProblemNode lvNode = new SubSubProblemNode();
370 Date d = new Date();
371 lvNode.setDate(d);
372 SubSubProblemNode lvNodeAfter = lvMyService.transferSubSubProblemNode(lvNode);
373 assertNotNull(lvNodeAfter.getDate());
374
375
376 String s1 = Long.toString(lvNode.getDate().getTime());
377 s1 = s1.substring(0, (s1.length() - 3)) + "000";
378 String s2 = Long.toString(lvNodeAfter.getDate().getTime());
379 assertEquals(s1, s2);
380 }
381
382
383
384
385 public void testAsynchronousInvocation() throws Exception {
386 Properties prop = new Properties();
387 prop.put(Property.EXECUTOR_CLASS, XmlRpcExecutor.class.getName());
388 prop.put(Property.ASYNCHRONOUS_CALLBACK_CLASS, AsynchronousCallbackForTests.class.getName());
389
390 ServiceManager manager = new ServiceManager(prop);
391 Echo echo = (Echo) manager.createService(Echo.class);
392 String lvPing = echo.ping();
393 assertNull(lvPing);
394
395 assertTrue(manager.isInvocationAsynchronous(Echo.class));
396
397 Thread.sleep(300);
398 AsynchronousCallbackForTests lvAsynchronousCallbackForTests = (AsynchronousCallbackForTests) manager.getAsynchronousCallback(Echo.class);
399 assertNotNull(lvAsynchronousCallbackForTests);
400
401 assertEquals("ping", lvAsynchronousCallbackForTests.getMethodName());
402 assertEquals(Echo.PING_STRING, lvAsynchronousCallbackForTests.getResult());
403 assertNull(lvAsynchronousCallbackForTests.getThrowable());
404 }
405
406 public void testAsynchronousInvocationWithMultyThreaded() throws Exception {
407 Properties prop = new Properties();
408 prop.put(Property.EXECUTOR_CLASS, XmlRpcExecutor.class.getName());
409 prop.put(Property.ASYNCHRONOUS_CALLBACK_CLASS, AsynchronousCallbackForTests.class.getName());
410 prop.put(Property.ASYNCHRONOUS_MAX_SIZE_OF_THREADS, "3");
411
412 ServiceManager manager = new ServiceManager(prop);
413 Echo echo = (Echo) manager.createService(Echo.class);
414 String lvPing = echo.ping();
415 assertNull(lvPing);
416
417 assertTrue(manager.isInvocationAsynchronous(Echo.class));
418
419 Thread.sleep(300);
420 AsynchronousCallbackForTests lvAsynchronousCallbackForTests = (AsynchronousCallbackForTests) manager.getAsynchronousCallback(Echo.class);
421 assertNotNull(lvAsynchronousCallbackForTests);
422
423 assertEquals("ping", lvAsynchronousCallbackForTests.getMethodName());
424 assertEquals(Echo.PING_STRING, lvAsynchronousCallbackForTests.getResult());
425 assertNull(lvAsynchronousCallbackForTests.getThrowable());
426 }
427
428 public void testIndivualAsynchronousInvocationWithMultyThreaded() throws Exception {
429 Properties prop = new Properties();
430 prop.put(Property.EXECUTOR_CLASS, XmlRpcExecutor.class.getName());
431
432 ServiceManager manager = new ServiceManager(prop);
433 AsynchronousCallbackForTests lvCallback = new AsynchronousCallbackForTests();
434 Echo e = (Echo) manager.createService(Echo.class, lvCallback, null, 8);
435
436 String lvEchoStr = null;
437 String lvLongExecution = null;
438 for (int i=0;i<3;i++) {
439 lvLongExecution = e.doLongExecution("Hello");
440 assertNull(lvLongExecution);
441 lvEchoStr = e.echo("Hello");
442 assertNull(lvEchoStr);
443 }
444 }
445
446 public void testIndivualAsynchronousInvocationWithMultyThreadedWith2Services() throws Exception {
447 Properties prop = new Properties();
448 prop.put(Property.EXECUTOR_CLASS, XmlRpcExecutor.class.getName());
449
450 ServiceManager manager = new ServiceManager(prop);
451 AsynchronousCallbackForTests lvCallback = new AsynchronousCallbackForTests();
452 Echo e = (Echo) manager.createService(Echo.class, lvCallback, null, 8);
453 Calculator c = (Calculator) manager.createService(Calculator.class, lvCallback, null, 8);
454
455 String lvLongExecution = null;
456 Long lvAddResult = null;
457 for (int i=0;i<3;i++) {
458 lvLongExecution = e.doLongExecution("Hello");
459 assertNull(lvLongExecution);
460 lvAddResult = c.addLong(new Long(123), new Long(456));
461 assertNull(lvAddResult);
462 int lvIntValue = c.add(1, 1);
463 assertEquals(0, lvIntValue);
464 }
465 }
466
467 public void testIndivualAsynchronousInvocationWithMethodFilter() throws Exception {
468 Properties prop = new Properties();
469 prop.put(Property.EXECUTOR_CLASS, XmlRpcExecutor.class.getName());
470
471 ServiceManager manager = new ServiceManager(prop);
472 AsynchronousCallbackForTests lvCallback = new AsynchronousCallbackForTests();
473 Echo e = (Echo) manager.createService(Echo.class, lvCallback, new String[] { "doLongExecution" }, 4);
474
475 String lvEchoStr = null;
476 String lvLongExecution = null;
477 for (int i=0;i<3;i++) {
478 lvLongExecution = e.doLongExecution("Hello");
479 assertNotNull(lvLongExecution);
480 assertEquals("Hello", lvLongExecution);
481 lvEchoStr = e.echo("Hello");
482 assertNull(lvEchoStr);
483 }
484 }
485
486 public void testRemoveAsynchronousCallback() throws Exception {
487 Properties prop = new Properties();
488 prop.put(Property.EXECUTOR_CLASS, XmlRpcExecutor.class.getName());
489
490 ServiceManager manager = new ServiceManager(prop);
491 AsynchronousCallbackForTests lvCallback = new AsynchronousCallbackForTests();
492 Echo e = (Echo) manager.createService(Echo.class, lvCallback, new String[] { "doLongExecution" }, 4);
493
494 String lvEchoStr = e.echo("Hello");
495 assertNull(lvEchoStr);
496
497 manager.removeAsynchronousCallback(Echo.class);
498
499 lvEchoStr = e.echo("Hello");
500 assertNotNull(lvEchoStr);
501 assertEquals("Hello", lvEchoStr);
502 }
503
504 public void testAddAndRemoveAsynchronousCallback() throws Exception {
505 Properties prop = new Properties();
506 prop.put(Property.EXECUTOR_CLASS, XmlRpcExecutor.class.getName());
507
508 ServiceManager manager = new ServiceManager(prop);
509 AsynchronousCallbackForTests lvCallback = new AsynchronousCallbackForTests();
510 Echo e = (Echo) manager.createService(Echo.class, lvCallback, new String[] { "doLongExecution" }, 4);
511 Calculator c = (Calculator) manager.createService(Calculator.class, lvCallback, null, 4);
512
513 String lvEchoStr = e.echo("Hello");
514 assertNull(lvEchoStr);
515
516 Long lvAddResult = c.addLong(new Long(1), new Long(3));
517 assertNull(lvAddResult);
518
519 assertTrue(manager.isInvocationAsynchronous(Calculator.class));
520 manager.removeAsynchronousCallback(Calculator.class);
521 assertFalse(manager.isInvocationAsynchronous(Calculator.class));
522
523 lvEchoStr = e.echo("Hello2");
524 assertNull(lvEchoStr);
525
526 lvAddResult = c.addLong(new Long(2), new Long(3));
527 assertNotNull(lvAddResult);
528 assertEquals(new Long(5), lvAddResult);
529
530
531 manager.removeAsynchronousCallback(Echo.class);
532
533 lvEchoStr = e.echo("Hello3");
534 assertNotNull(lvEchoStr);
535 assertEquals("Hello3", lvEchoStr);
536 }
537
538
539
540 public void testNotRemoteMethod() throws Exception {
541 Properties prop = getProperties();
542
543 ServiceManager manager = new ServiceManager(prop);
544 Calculator calc1 = (Calculator) manager.createService(Calculator.class);
545 Calculator calc2 = (Calculator) manager.createService(Calculator.class);
546
547 assertFalse(calc1.equals( calc2));
548 assertFalse(calc1 == calc2);
549
550 assertEquals(calc1.hashCode(), 0);
551 assertEquals(calc2.hashCode(), 0);
552
553 try {
554 calc1.notify();
555 fail("Notify is not supported");
556 } catch (Exception e) {
557 assertTrue(true);
558 }
559
560 try {
561 calc1.notifyAll();
562 fail("NotifyAll is not supported");
563 } catch (Exception e) {
564 assertTrue(true);
565 }
566
567 try {
568 calc1.wait();
569 fail("Wait is not supported");
570 } catch (Exception e) {
571 assertTrue(true);
572 }
573
574 }
575
576 public void testXmlRpcConvertHandler() throws Exception {
577 XmlRpcConvertHandler lvXmlRpcConvertHandler = new XmlRpcConvertHandler(new EchoImpl(), null);
578 String lvEchoString = "Hello Crispy";
579 Vector lvParams = new Vector();
580 lvParams.add(lvEchoString);
581 Object lvResult = lvXmlRpcConvertHandler.execute("echo", lvParams);
582 assertEquals(lvEchoString, lvResult);
583 }
584
585 public void testXmlRpcConvertHandlerWithInterceptorHandler() throws Exception {
586 ServiceEndpoint lvServiceEndpoint = new ServiceEndpointImpl();
587 lvServiceEndpoint.setInterceptorHandlerCreator(
588 new InterceptorHandlerCreator() {
589
590 public InterceptorHandler createNewInterceptorHandlerInstance() {
591 InterceptorHandler lvHandler = new InterceptorHandler();
592 lvHandler.setModifier(new Modifier() {
593
594 public InterceptorContext modifyBeforeInvocation(InterceptorContext pvInterceptorContext) {
595 Object lvArgs[] = new Object[1];
596 lvArgs[0] = pvInterceptorContext.getArgs()[0];
597 pvInterceptorContext.setArgs(lvArgs);
598 return pvInterceptorContext;
599 }
600
601 public InterceptorContext modifyAfterInvocation(InterceptorContext pvInterceptorContext) {
602 return pvInterceptorContext;
603 }
604
605 });
606 return lvHandler;
607 }
608
609 }
610 );
611
612 XmlRpcConvertHandler lvXmlRpcConvertHandler = new XmlRpcConvertHandler(new EchoImpl(), null, lvServiceEndpoint);
613 String lvEchoString = "Hello Crispy";
614 Vector lvParams = new Vector();
615 lvParams.add(lvEchoString);
616 lvParams.add(new Kunde("I'm to much"));
617 lvParams.add(new Long(-1));
618 Object lvResult = lvXmlRpcConvertHandler.execute("echo", lvParams);
619 assertEquals(lvEchoString, lvResult);
620 }
621
622 public void testXmlRpcConvertHandlerWithException() throws Exception {
623 XmlRpcConvertHandler lvXmlRpcConvertHandler = new XmlRpcConvertHandler(new EchoImpl(), null);
624 String lvEchoString = "Hello Crispy";
625 Vector lvParams = new Vector();
626 lvParams.add(lvEchoString);
627 lvParams.add("I'm to much");
628 try {
629 Object lvReturn = lvXmlRpcConvertHandler.execute("echo", lvParams);
630 ExceptionWrapper.isResultExceptionThanThrowIt(lvReturn);
631 fail("The echo Mthod must throw a Exception (to much args).");
632 } catch (Exception e) {
633 assertTrue(true);
634 }
635 }
636
637 public void testRemoteMethodWithThrownExceptionWithValidationErrors() throws Exception {
638 Properties prop = getProperties();
639
640 ServiceManager manager = new ServiceManager(prop);
641 Echo lvEcho = (Echo) manager.createService(Echo.class);
642
643 List lvValidationErrors = new ArrayList();
644 ValidationError lvError1 = new ValidationError(1, "Error 1");
645 ValidationError lvError2 = new ValidationError(2, "Error 2");
646 lvValidationErrors.add(lvError1);
647 lvValidationErrors.add(lvError2);
648 try {
649 lvEcho.throwComplexException("JUnit-Test", lvValidationErrors);
650 fail("The method throwComplexEception must be thrown a Exception");
651 } catch (Exception e) {
652 assertTrue(e instanceof JUnitTestException2);
653 assertEquals(lvValidationErrors.size(), ((JUnitTestException2) e).getValidationErrors().size());
654 }
655 }
656
657 public void testEchoObjectWithComplexMap() throws Exception {
658 Properties prop = getProperties();
659 ServiceManager manager = new ServiceManager(prop);
660
661 Kunde k = new Kunde("Test-Kunde");
662 Adresse a = new Adresse();
663 a.setOrt("Hier");
664 k.getAdressen().add(a);
665 Map lvMap = new Hashtable();
666 lvMap.put("ADRESSE_KEY", a);
667 lvMap.put("KUNDE_KEY", k);
668
669 Echo lvEcho = (Echo) manager.createService(Echo.class);
670
671 assertNotNull(lvEcho.echo("Test"));
672
673 Object lvResult = lvEcho.echoObject(lvMap);
674 assertNotNull(lvResult);
675 assertTrue(lvResult instanceof Map);
676 Map lvMapAfter = (Map) lvResult;
677 Adresse a2 = (Adresse) lvMapAfter.get("ADRESSE_KEY");
678 assertEquals(a.getOrt(), a2.getOrt());
679 Kunde k2 = (Kunde) lvMapAfter.get("KUNDE_KEY");
680 assertEquals(k.getName(), k2.getName());
681 assertEquals(k.getAdressen().size(), k2.getAdressen().size());
682 assertEquals(a2, k2.getAdressen().get(0));
683 }
684 }