View Javadoc

1   /*
2    * Created on 29.04.2005 from Linke
3    *
4    */
5   package test.crispy.impl;
6   
7   import java.math.BigDecimal;
8   import java.util.ArrayList;
9   import java.util.Date;
10  import java.util.List;
11  import java.util.Properties;
12  
13  import junit.framework.TestCase;
14  import net.sf.crispy.InvocationException;
15  import net.sf.crispy.Property;
16  import net.sf.crispy.impl.ServiceManager;
17  import net.sf.crispy.impl.StaticLocalObjectProxy;
18  import net.sf.crispy.impl.local.MiniLocalObjectServer;
19  import net.sf.crispy.interceptor.StopWatchInterceptor;
20  
21  import org.apache.commons.logging.Log;
22  import org.apache.commons.logging.LogFactory;
23  
24  import test.crispy.JUnitTestException;
25  import test.crispy.JUnitTestException2;
26  import test.crispy.compatibility.CompatibilityKit;
27  import test.crispy.concurrent.AsynchronousCallbackForTests;
28  import test.crispy.example.interceptor.WaitInterceptor;
29  import test.crispy.example.model.Adresse;
30  import test.crispy.example.model.Kunde;
31  import test.crispy.example.model.Primitive;
32  import test.crispy.example.model.SubSubProblemNode;
33  import test.crispy.example.model.ValidationError;
34  import test.crispy.example.service.Calculator;
35  import test.crispy.example.service.CalculatorImpl;
36  import test.crispy.example.service.Echo;
37  import test.crispy.example.service.EchoImpl;
38  import test.crispy.example.service.MyService;
39  import test.crispy.example.service.MyServiceImpl;
40  
41  /**
42   * Simple local test from services.
43   * 
44   * @author Linke
45   *
46   */
47  public class SimpleServiceTest extends TestCase {
48  	
49  	private static Log log = LogFactory.getLog (SimpleServiceTest.class);
50  	
51  	protected void tearDown() throws Exception {
52  		super.tearDown();
53  		MiniLocalObjectServer.removeService(Calculator.class);
54  		MiniLocalObjectServer.removeService(Echo.class);
55  	}
56  	
57  	private void makeEchoTest (ServiceManager pvServiceManager) {
58  		Echo lvEcho = (Echo) pvServiceManager.createService(Echo.class);
59  		assertNotNull(lvEcho);
60  		String lvEchoStr = "Hallo Echo";
61  		assertEquals(lvEcho.echo(lvEchoStr), lvEchoStr);		
62  	}
63  
64  	private void makeCalculatorTest (ServiceManager pvServiceManager) {
65  		Calculator lvCalculator = (Calculator) pvServiceManager.createService(Calculator.class);
66  		assertNotNull(lvCalculator);
67  		int lvResult = lvCalculator.add(2, 3);
68  		assertEquals(lvResult, 5);
69  		lvResult = lvCalculator.subtract(8, 2);
70  		assertEquals(lvResult, 6);		
71  	}
72  	
73  	
74  	public void testSimpleRemotePing() throws Exception {
75  		Properties prop = new Properties();
76      	prop.put(Echo.class.getName(), EchoImpl.class.getName());
77      	
78  		ServiceManager manager = new ServiceManager(prop);
79  		Echo echo =  (Echo) manager.createService(Echo.class);
80  		String lvPing = echo.ping();
81  		assertEquals(lvPing, Echo.PING_STRING);
82  	}
83  	
84  	
85  	/** The simpelst call from service. */
86  	public void testSimpleService() {
87  		ServiceManager lvServiceManager = new ServiceManager(Echo.class, EchoImpl.class);
88  		makeEchoTest (lvServiceManager);
89  	}
90  	
91  	/** Test simple service with Properties. */
92  	public void testSimplePropertyService() {
93          Properties prop = new Properties();
94          prop.put(Echo.class.getName(), EchoImpl.class.getName());        
95  
96          ServiceManager lvServiceManager = new ServiceManager(prop);
97          makeEchoTest (lvServiceManager);
98  	}
99  
100 	/** Two ore more services are possible */
101 	public void testMultipleSimpleService() {
102 
103         Properties prop = new Properties();
104         prop.put(Echo.class.getName(), EchoImpl.class.getName());
105         prop.put(Calculator.class.getName(), CalculatorImpl.class.getName());
106      
107 		ServiceManager lvServiceManager = new ServiceManager(prop);		
108 		makeEchoTest (lvServiceManager);		
109 		makeCalculatorTest (lvServiceManager);
110 	}
111 	
112     /** Try to call a service Echo without a registration from Echo. */
113     public void testServiceNotRegist() throws Exception {
114         Properties prop = new Properties();
115         prop.put(Property.STATIC_PROXY_CLASS, StaticLocalObjectProxy.class.getName());
116         prop.put(Calculator.class.getName(), CalculatorImpl.class.getName());       
117         
118         ServiceManager lvServiceManager = new ServiceManager(prop);
119         makeCalculatorTest (lvServiceManager);
120         try {
121         	// muss Fehler auftreten, da KEIN Echo-Service registriert ist
122         	makeEchoTest (lvServiceManager);
123         	fail("The Echo Service is not registered. This must throw Exception.");
124         } catch (InvocationException e) { 
125         	if (log.isDebugEnabled()) { log.debug("NO Exception: " + e); }
126         }
127 	}
128     
129     /** This is not a correct case, but is not a problem */
130     public void testServiceWithInterface() {
131         Properties prop = new Properties();
132         prop.put(CalculatorImpl.class.getName(), CalculatorImpl.class.getName());       
133         
134         ServiceManager lvServiceManager = new ServiceManager(prop);
135         Calculator lvComputer = (Calculator) lvServiceManager.createService(CalculatorImpl.class);
136         assertEquals(lvComputer.add(1,1), 2);
137         assertEquals(lvComputer.subtract(1,1), 0);
138         
139         try {
140         	Calculator lvComputerError = (Calculator) lvServiceManager.createService(Calculator.class);
141         	lvComputerError.add(3, 4);
142         	fail("The ComputerImpl and not Computer-Interfaces is registered");
143         } catch (Exception e) { log.debug("No Error: ", e); }
144 
145 	}
146 
147     /** Call about the ProxyDelegate from Jdk-InvocationHandler. */
148     public void testJdkProxyDelegate() {
149         Properties prop = new Properties();
150         prop.put(Calculator.class.getName(), CalculatorImpl.class.getName());
151         prop.put(Property.STATIC_PROXY_CLASS, StaticLocalObjectProxy.class.getName());
152         prop.put(Property.DYNAMIC_PROXY_CLASS, Property.VALUE_FOR_JDK_DYNAMIC_PROXY);
153         prop.put(Property.SECURITY_USER, "user");
154         prop.put(Property.SECURITY_PASSWD, "passwd");
155         
156         ServiceManager lvServiceManager = new ServiceManager(prop);
157         makeCalculatorTest (lvServiceManager);		
158 	}
159     
160     /** Call about the ProxyDelegate from CGLIB-InvocationHandler. */
161     public void testCglibProxyDelegate() {
162         Properties prop = new Properties();
163         prop.put(Calculator.class.getName(), CalculatorImpl.class.getName());
164         prop.put(Property.STATIC_PROXY_CLASS, StaticLocalObjectProxy.class.getName());
165         prop.put(Property.DYNAMIC_PROXY_CLASS, Property.VALUE_FOR_CGLIB_DYNAMIC_PROXY);
166         
167         
168         ServiceManager lvServiceManager = new ServiceManager(prop);
169 //        Calculator lvComputer = (Calculator) lvServiceManager.createService(Calculator.class);
170         makeCalculatorTest (lvServiceManager);
171 		
172 	}
173     
174     public void testMultiProxyInterceptor() throws Exception {
175         Properties prop = new Properties();
176         prop.put(Calculator.class.getName(), CalculatorImpl.class.getName());
177         prop.put(Echo.class.getName(), EchoImpl.class.getName());
178         prop.put(Property.DYNAMIC_PROXY_CLASS, Property.VALUE_FOR_JDK_DYNAMIC_PROXY);
179         prop.put(Property.INTERCEPTOR_CLASS, WaitInterceptor.class.getName());
180         prop.put(Property.INTERCEPTOR_CLASS_2, StopWatchInterceptor.class.getName());
181         
182         ServiceManager lvServiceManager = new ServiceManager(prop);
183         makeCalculatorTest (lvServiceManager);
184         
185         assertTrue(lvServiceManager.getInterceptorSize() == 2);
186         
187         WaitInterceptor lvWaitInterceptor = (WaitInterceptor) lvServiceManager.getInterceptorByPos(0);
188     	StopWatchInterceptor lvProxyInterceptor = (StopWatchInterceptor) lvServiceManager.getInterceptorByPos(1);
189     	
190     	assertTrue(lvProxyInterceptor.getStopTimeNewInstance() >= lvWaitInterceptor.getWaitTime());
191     	assertTrue(lvProxyInterceptor.getStopTimeInvokeMethod() >= lvWaitInterceptor.getWaitTime());
192     	
193         makeEchoTest(lvServiceManager);
194     	assertTrue(lvProxyInterceptor.getStopTimeNewInstance() >= lvWaitInterceptor.getWaitTime());
195     	assertTrue(lvProxyInterceptor.getStopTimeInvokeMethod() >= lvWaitInterceptor.getWaitTime());
196         
197 	}
198 
199     public void testSimpleRemoteInvocationWithOutDynamicJdkProxy() throws Exception {
200         Properties prop = new Properties();
201         prop.put(Calculator.class.getName(), CalculatorImpl.class.getName());
202         prop.put(Property.INTERCEPTOR_CLASS, WaitInterceptor.class.getName());
203         prop.put(Property.INTERCEPTOR_CLASS_2, StopWatchInterceptor.class.getName());		
204 		
205 		ServiceManager lvManager = new ServiceManager(prop);
206 		makeCalculatorTest(lvManager);
207 		StopWatchInterceptor lvStopWatchInterceptor = (StopWatchInterceptor) lvManager.getInterceptorByPos(1);
208 		long lvStopTime = lvStopWatchInterceptor.getStopTimeInvokeMethod();
209 		assertTrue("StopTime is: " + lvStopTime, lvStopTime > 10);
210 		
211 		lvManager.removeInterceptorByPos(0);
212 		lvManager.removeInterceptorByPos(0);
213 		makeCalculatorTest(lvManager);
214 		assertEquals(lvStopTime, lvStopWatchInterceptor.getStopTimeInvokeMethod());
215 		
216 		lvStopWatchInterceptor.clearStopTimeInvokeMethod();
217 		lvStopWatchInterceptor.clearStopTimeNewInstance();
218 		makeCalculatorTest(lvManager);
219 		lvStopTime = lvStopWatchInterceptor.getStopTimeInvokeMethod();
220 		assertEquals(lvStopTime, 0);
221     }
222 
223     public void testModifyService() throws Exception {
224     	CompatibilityKit compatibilityKit = new CompatibilityKit();
225     	compatibilityKit.addProperty(Property.DYNAMIC_PROXY_CLASS, Property.VALUE_FOR_JDK_DYNAMIC_PROXY);
226 		compatibilityKit.makeModifyServiceTest(compatibilityKit.createServiceManager());
227 	}
228    
229     public void testCycleDetectionTest() throws Exception {
230         Properties prop = new Properties();
231         prop.put(Echo.class.getName(), EchoImpl.class.getName());
232         prop.put(Property.DYNAMIC_PROXY_CLASS, Property.VALUE_FOR_JDK_DYNAMIC_PROXY);
233         
234         ServiceManager lvServiceManager = new ServiceManager(prop);
235 		Echo lvEcho = (Echo) lvServiceManager.createService(Echo.class);
236 		
237 		Kunde k = new Kunde("Mario");
238 		k.setGehalt(new BigDecimal(12.34));
239 		Adresse a = new Adresse();
240 		a.setOrt("Magdebrug");
241 		a.setPlz("39104");
242 		k.getAdressen().add(a);
243 		a.setKunde(k);
244 		
245 		String lvRenameName = "Nadine";
246 		Kunde kAfter = lvEcho.renameKunde(k, lvRenameName);
247 		assertEquals(kAfter.getName(), lvRenameName);
248 		
249 		Kunde kTemp = ((Adresse) kAfter.getAdressen().get(0)).getKunde();
250 		assertEquals(kAfter, kTemp);
251 	}
252     
253     public void testAddNode() throws Exception {
254     	CompatibilityKit compatibilityKit = new CompatibilityKit();    	
255     	compatibilityKit.makeAddNodeTest(compatibilityKit.createServiceManager());
256 	}
257     
258     public void testEchoPrimitive() throws Exception {
259     	MiniLocalObjectServer server = new MiniLocalObjectServer();  	
260     	server.addService(Echo.class, new EchoImpl());
261     	server.start();
262     	
263     	Properties prop = new Properties();
264     	prop.put(Property.STATIC_PROXY_CLASS, StaticLocalObjectProxy.class.getName());
265         
266         ServiceManager lvServiceManager = new ServiceManager(prop);
267         Echo lvEcho = (Echo) lvServiceManager.createService(Echo.class);
268         Primitive lvPrimitive = Primitive.createPrimitiveExample();
269         
270         Primitive lvPrimitiveAfter = lvEcho.echoPrimitive(lvPrimitive);
271         assertEquals(lvPrimitive, lvPrimitiveAfter);
272         assertSame(lvPrimitive, lvPrimitiveAfter);
273 	}
274 
275 	public void testInnerClassServiceImpl() throws Exception {
276     	MiniLocalObjectServer server = new MiniLocalObjectServer();  	
277     	server.addService(MyService.class, new MyService() {
278     		MyServiceImpl myServiceImpl = new MyServiceImpl();
279 			public SubSubProblemNode transferSubSubProblemNode(SubSubProblemNode pvNode) {
280 				return myServiceImpl.transferSubSubProblemNode(pvNode);
281 			}
282     		
283     		}
284     			
285     	);
286     	server.start();
287     	
288     	Properties prop = new Properties();
289     	prop.put(Property.STATIC_PROXY_CLASS, StaticLocalObjectProxy.class.getName());
290         
291         ServiceManager lvServiceManager = new ServiceManager(prop);
292 		MyService lvService =  (MyService) lvServiceManager.createService(MyService.class);
293 		
294 		SubSubProblemNode lvNode = new SubSubProblemNode();
295 		Date d = new Date();
296 		lvNode.setDate(d);
297 		
298 		SubSubProblemNode lvNodeAfter = lvService.transferSubSubProblemNode(lvNode);
299 		assertEquals(lvNodeAfter.getDate(), lvNode.getDate());        
300 	}
301 
302     public void testMiniLocalObjectServer() throws Exception {
303     	MiniLocalObjectServer server = new MiniLocalObjectServer();  	
304     	server.addService(Echo.class, new EchoImpl());
305     	server.start();
306     	
307     	Properties prop = new Properties();
308     	prop.put(Property.STATIC_PROXY_CLASS, StaticLocalObjectProxy.class.getName());
309         
310         ServiceManager lvServiceManager = new ServiceManager(prop);
311     	makeEchoTest(lvServiceManager);
312     	
313     	server.addService(Calculator.class, new CalculatorImpl());
314     	makeCalculatorTest(lvServiceManager);
315 	}
316 
317     public void testOverloading() throws Exception {
318     	MiniLocalObjectServer server = new MiniLocalObjectServer();
319     	server.start();
320     	
321     	server.addService(Calculator.class, new CalculatorImpl());
322 
323 		Properties prop = new Properties();
324     	prop.put(Property.STATIC_PROXY_CLASS, StaticLocalObjectProxy.class.getName());		
325 		
326 		ServiceManager manager = new ServiceManager(prop);
327 		Calculator lvCalculator = (Calculator) manager.createService(Calculator.class);
328 		int lvIntResult = lvCalculator.add(2, 3);
329 		assertEquals(lvIntResult, 5);
330 		long lvLongResult = lvCalculator.add(21, 32);
331 		assertEquals(lvLongResult, 53);
332 		double lvDoubleResult = lvCalculator.add(2.3, 3.2);
333 		assertEquals(lvDoubleResult, 5.5, 0);
334     }
335     
336     public void testOverloadingInteger() throws Exception {
337     	MiniLocalObjectServer server = new MiniLocalObjectServer();
338     	server.start();
339     	
340     	server.addService(Echo.class, new EchoImpl());
341     	
342     	Properties prop = new Properties();
343     	prop.put(Property.STATIC_PROXY_CLASS, StaticLocalObjectProxy.class.getName());
344 		
345 		ServiceManager manager = new ServiceManager(prop);
346 		Echo echo =  (Echo) manager.createService(Echo.class);
347 		Integer i[] = echo.echoArray(new Integer[] {new Integer(1), new Integer(3), new Integer(5)});
348 		assertTrue(i.length == 3);
349 		assertEquals(i[0], new Integer(1));
350 		assertEquals(i[1], new Integer(3));
351 		assertEquals(i[2], new Integer(5));
352 	}
353     
354     public void testOverloadingLong() throws Exception {
355     	MiniLocalObjectServer server = new MiniLocalObjectServer();
356     	server.start();
357     	
358     	server.addService(Echo.class, new EchoImpl());
359     	
360     	Properties prop = new Properties();
361     	prop.put(Property.STATIC_PROXY_CLASS, StaticLocalObjectProxy.class.getName());
362 		
363 		ServiceManager manager = new ServiceManager(prop);
364 		Echo echo =  (Echo) manager.createService(Echo.class);
365 		Long l[] = echo.echoArray(new Long[] {new Long(1), new Long(5)});
366 		assertTrue(l.length == 2);
367 		assertEquals(l[0], new Long(1));
368 		assertEquals(l[1], new Long(5));
369 	}
370 
371     public void testOverloadingObject() throws Exception {
372     	MiniLocalObjectServer server = new MiniLocalObjectServer();
373     	server.start();
374     	
375     	server.addService(Echo.class, new EchoImpl());
376     	
377     	Properties prop = new Properties();
378     	prop.put(Property.STATIC_PROXY_CLASS, StaticLocalObjectProxy.class.getName());
379 		
380 		ServiceManager manager = new ServiceManager(prop);
381 		Echo echo =  (Echo) manager.createService(Echo.class);
382 		Object o[] = echo.echoArray(new Object[] {"a", new Integer(3), new Long(5)});
383 		assertTrue(o.length == 3);
384 		assertEquals(o[0], "a");
385 		assertEquals(o[1], new Integer(3));
386 //		assertEquals(o[2], new Long(5)); is Integer
387 	}
388     
389     public void testCreateService() throws Exception {
390         Properties prop = new Properties();
391     	prop.put(Property.STATIC_PROXY_CLASS, StaticLocalObjectProxy.class.getName());        
392     	prop.put(Calculator.class.getName(), CalculatorImpl.class.getName());
393     	
394     	ServiceManager lvManager = new ServiceManager(prop);
395         Calculator lvCalculator1 = (Calculator) lvManager.createService(Calculator.class);
396         Calculator lvCalculator2 = (Calculator) lvManager.createService(Calculator.class);
397         
398         assertNotNull(lvCalculator1);
399         assertNotNull(lvCalculator2);
400         assertNotSame(lvCalculator1, lvCalculator2);
401 	}
402     
403     public void testThrowException() throws Exception {
404         Properties prop = new Properties();
405     	prop.put(Property.STATIC_PROXY_CLASS, StaticLocalObjectProxy.class.getName());        
406     	prop.put(Echo.class.getName(), EchoImpl.class.getName());
407         
408 		ServiceManager lvManager = new ServiceManager(prop);
409 
410 		Echo lvEcho = (Echo) lvManager.createService(Echo.class);
411 		boolean throwException = false;
412 		try {
413 			lvEcho.throwException("A Test-Excption.");
414 		} catch (JUnitTestException e) {
415 			throwException = true;
416 		}
417 		assertTrue("No Exception thrown: " + throwException, throwException);
418 	}    
419 
420     public void testNullValueParamsWithException() throws Exception {
421         Properties prop = new Properties();
422     	prop.put(Property.STATIC_PROXY_CLASS, StaticLocalObjectProxy.class.getName());        
423     	prop.put(Echo.class.getName(), EchoImpl.class.getName());
424 		
425 		ServiceManager lvManager = new ServiceManager(prop);
426 
427 		Echo lvEcho = (Echo) lvManager.createService(Echo.class);
428 		String s = lvEcho.echo(null);
429 		assertNull(s);
430 	}
431 
432     public void testNullLongValueParams() throws Exception {
433         Properties prop = new Properties();
434     	prop.put(Property.STATIC_PROXY_CLASS, StaticLocalObjectProxy.class.getName());        
435     	prop.put(Calculator.class.getName(), CalculatorImpl.class.getName());
436 		
437 		ServiceManager lvManager = new ServiceManager(prop);
438 
439 		Calculator lvCalculator = (Calculator) lvManager.createService(Calculator.class);
440 		Long lvLong = lvCalculator.addLong(null, null);
441 		assertNull(lvLong);
442 	}
443 
444     public void testNullComplexValueParams() throws Exception {
445         Properties prop = new Properties();
446     	prop.put(Property.STATIC_PROXY_CLASS, StaticLocalObjectProxy.class.getName());        
447     	prop.put(Echo.class.getName(), EchoImpl.class.getName());
448 		
449 		ServiceManager lvManager = new ServiceManager(prop);
450 
451 		Echo lvEcho = (Echo) lvManager.createService(Echo.class);
452 		Kunde k = lvEcho.renameKunde(null, null);
453 		assertNull(k);
454 	}
455 
456 	public void testTransferDate() throws Exception {
457 		Properties prop = new Properties();
458     	prop.put(Property.STATIC_PROXY_CLASS, StaticLocalObjectProxy.class.getName());        
459     	prop.put(Echo.class.getName(), EchoImpl.class.getName());
460 		
461 		ServiceManager manager = new ServiceManager(prop);
462 		Echo lvEcho =  (Echo) manager.createService(Echo.class);
463 		
464 		Kunde k = new Kunde("JUnit-Test-Name");
465 		Date d = new Date();
466 		k.setDate(d);
467 		Kunde k2 = lvEcho.renameKunde(k, "Rename-Test");
468 		assertNotNull(k2.getDate());
469 		assertEquals(k.getDate(), k2.getDate());
470 	}
471     
472     
473     
474 	public void testAsynchronousInvocation() throws Exception {
475 		Properties prop = new Properties();
476     	prop.put(Property.STATIC_PROXY_CLASS, StaticLocalObjectProxy.class.getName());
477     	prop.put(Property.DYNAMIC_PROXY_CLASS, Property.VALUE_FOR_JDK_DYNAMIC_PROXY);
478 		prop.put(Property.ASYNCHRONOUS_CALLBACK_CLASS, AsynchronousCallbackForTests.class.getName());
479 		prop.put(Echo.class.getName(), EchoImpl.class.getName());
480 		
481 		ServiceManager manager = new ServiceManager(prop);
482 		Echo echo =  (Echo) manager.createService(Echo.class);
483 		String lvPing = echo.ping();
484 		assertNull(lvPing);
485 		
486         assertTrue(manager.isInvocationAsynchronous(Echo.class));
487         
488         Thread.sleep(300);
489         AsynchronousCallbackForTests lvAsynchronousCallbackForTests = (AsynchronousCallbackForTests) manager.getAsynchronousCallback(Echo.class);
490         assertNotNull(lvAsynchronousCallbackForTests);
491         
492         assertEquals("ping", lvAsynchronousCallbackForTests.getMethodName());
493         assertEquals(Echo.PING_STRING, lvAsynchronousCallbackForTests.getResult());
494         assertNull(lvAsynchronousCallbackForTests.getThrowable());
495 	}
496 	
497 	public void testAsynchronousInvocationWithMultyThreaded() throws Exception {
498 		Properties prop = new Properties();
499     	prop.put(Property.STATIC_PROXY_CLASS, StaticLocalObjectProxy.class.getName());
500     	prop.put(Property.DYNAMIC_PROXY_CLASS, Property.VALUE_FOR_JDK_DYNAMIC_PROXY);
501 		prop.put(Property.ASYNCHRONOUS_CALLBACK_CLASS, AsynchronousCallbackForTests.class.getName());
502 		prop.put(Property.ASYNCHRONOUS_MAX_SIZE_OF_THREADS, "3");
503 		prop.put(Echo.class.getName(), EchoImpl.class.getName());
504 		
505 		ServiceManager manager = new ServiceManager(prop);
506 		Echo echo =  (Echo) manager.createService(Echo.class);
507 		String lvPing = echo.ping();
508 		assertNull(lvPing);
509 		
510         assertTrue(manager.isInvocationAsynchronous(Echo.class));
511         
512         Thread.sleep(300);
513         AsynchronousCallbackForTests lvAsynchronousCallbackForTests = (AsynchronousCallbackForTests) manager.getAsynchronousCallback(Echo.class);
514         assertNotNull(lvAsynchronousCallbackForTests);
515         
516         assertEquals("ping", lvAsynchronousCallbackForTests.getMethodName());
517         assertEquals(Echo.PING_STRING, lvAsynchronousCallbackForTests.getResult());
518         assertNull(lvAsynchronousCallbackForTests.getThrowable());
519 	}
520 
521 	public void testIndivualAsynchronousInvocationWithMultyThreaded() throws Exception {
522 		Properties prop = new Properties();
523     	prop.put(Property.STATIC_PROXY_CLASS, StaticLocalObjectProxy.class.getName());
524     	prop.put(Property.DYNAMIC_PROXY_CLASS, Property.VALUE_FOR_JDK_DYNAMIC_PROXY);
525     	prop.put(Echo.class.getName(), EchoImpl.class.getName());
526 
527 		ServiceManager manager = new ServiceManager(prop);
528 		AsynchronousCallbackForTests lvCallback = new AsynchronousCallbackForTests();
529 		Echo e = (Echo) manager.createService(Echo.class, lvCallback, null, 8);
530 		
531 		String lvEchoStr = null;
532 		String lvLongExecution = null;
533 		for (int i=0;i<3;i++) {
534 			lvLongExecution = e.doLongExecution("Hello");
535 			assertNull(lvLongExecution);
536 			lvEchoStr = e.echo("Hello");
537 			assertNull(lvEchoStr);
538 		}
539 	}
540 	
541 	public void testIndivualAsynchronousInvocationWithMultyThreadedWith2Services() throws Exception {
542 		Properties prop = new Properties();
543     	prop.put(Property.STATIC_PROXY_CLASS, StaticLocalObjectProxy.class.getName());
544     	prop.put(Property.DYNAMIC_PROXY_CLASS, Property.VALUE_FOR_JDK_DYNAMIC_PROXY);
545     	prop.put(Echo.class.getName(), EchoImpl.class.getName());
546     	prop.put(Calculator.class.getName(), CalculatorImpl.class.getName());
547 
548 		ServiceManager manager = new ServiceManager(prop);
549 		AsynchronousCallbackForTests lvCallback = new AsynchronousCallbackForTests();
550 		Echo e = (Echo) manager.createService(Echo.class, lvCallback, null, 8);
551 		Calculator c =  (Calculator) manager.createService(Calculator.class, lvCallback, null, 8);
552 		
553 		String lvLongExecution = null;
554 		Long lvAddResult = null;
555 		for (int i=0;i<3;i++) {
556 			lvLongExecution = e.doLongExecution("Hello");
557 			assertNull(lvLongExecution);
558 			lvAddResult = c.addLong(new Long(123), new Long(456));
559 			assertNull(lvAddResult);
560 		}
561 	}
562 
563 	public void testIndivualAsynchronousInvocationWithMethodFilter() throws Exception {
564 		Properties prop = new Properties();
565     	prop.put(Property.STATIC_PROXY_CLASS, StaticLocalObjectProxy.class.getName());
566     	prop.put(Property.DYNAMIC_PROXY_CLASS, Property.VALUE_FOR_JDK_DYNAMIC_PROXY);
567     	prop.put(Echo.class.getName(), EchoImpl.class.getName());
568 
569 		ServiceManager manager = new ServiceManager(prop);
570 		AsynchronousCallbackForTests lvCallback = new AsynchronousCallbackForTests();
571 		Echo e = (Echo) manager.createService(Echo.class, lvCallback, new String[] { "doLongExecution" }, 4);
572 		
573 		String lvEchoStr = null;
574 		String lvLongExecution = null;
575 		for (int i=0;i<3;i++) {
576 			lvLongExecution = e.doLongExecution("Hello");
577 			assertNotNull(lvLongExecution);
578 			assertEquals("Hello", lvLongExecution);
579 			lvEchoStr = e.echo("Hello");
580 			assertNull(lvEchoStr);
581 		}
582 	}
583 
584 	public void testAddAndRemoveAsynchronousCallback() throws Exception {
585 		Properties prop = new Properties();
586     	prop.put(Property.STATIC_PROXY_CLASS, StaticLocalObjectProxy.class.getName());
587     	prop.put(Property.DYNAMIC_PROXY_CLASS, Property.VALUE_FOR_JDK_DYNAMIC_PROXY);
588     	prop.put(Echo.class.getName(), EchoImpl.class.getName());
589     	prop.put(Calculator.class.getName(), CalculatorImpl.class.getName());
590 
591 		ServiceManager manager = new ServiceManager(prop);
592 		AsynchronousCallbackForTests lvCallback = new AsynchronousCallbackForTests();
593 		Echo e = (Echo) manager.createService(Echo.class, lvCallback, new String[] { "doLongExecution" }, 4);
594 		Calculator c =  (Calculator) manager.createService(Calculator.class, lvCallback, null, 4);
595 				
596 		String lvEchoStr = e.echo("Hello");
597 		assertNull(lvEchoStr);
598 		
599 		Long lvAddResult = c.addLong(new Long(1), new Long(3));
600 		assertNull(lvAddResult);
601 		
602 		assertTrue(manager.isInvocationAsynchronous(Calculator.class));
603 		manager.removeAsynchronousCallback(Calculator.class);
604 		assertFalse(manager.isInvocationAsynchronous(Calculator.class));
605 		
606 		lvEchoStr = e.echo("Hello2");
607 		assertNull(lvEchoStr);
608 		
609 		lvAddResult = c.addLong(new Long(2), new Long(3));
610 		assertNotNull(lvAddResult);
611 		assertEquals(new Long(5), lvAddResult);
612 		
613 		
614 		manager.removeAsynchronousCallback(Echo.class);
615 		
616 		lvEchoStr = e.echo("Hello3");
617 		assertNotNull(lvEchoStr);
618 		assertEquals("Hello3", lvEchoStr);
619 	}
620 
621 	public void testRemoteMethodWithThrownExceptionWithValidationErrors() throws Exception {
622 		Properties prop = new Properties();
623     	prop.put(Property.STATIC_PROXY_CLASS, StaticLocalObjectProxy.class.getName());
624     	prop.put(Echo.class.getName(), EchoImpl.class.getName());
625 
626     	
627 		ServiceManager manager = new ServiceManager(prop);
628 		Echo lvEcho = (Echo) manager.createService(Echo.class);
629 		
630 		List lvValidationErrors = new ArrayList();
631 		ValidationError lvError1 = new ValidationError(1, "Error 1");
632 		ValidationError lvError2 = new ValidationError(2, "Error 2");
633 		lvValidationErrors.add(lvError1);
634 		lvValidationErrors.add(lvError2);
635 		try {
636 			lvEcho.throwComplexException("JUnit-Test", lvValidationErrors);
637 			fail("The method throwComplexEception must be thrown a Exception");
638 		} catch (Exception e) {
639 			assertTrue(e instanceof JUnitTestException2);
640 			assertEquals(lvValidationErrors.size(), ((JUnitTestException2) e).getValidationErrors().size());
641 		}
642 	}
643 
644 }