View Javadoc

1   package test.crispy.impl;
2   
3   import java.io.ByteArrayOutputStream;
4   import java.io.PrintStream;
5   import java.util.HashMap;
6   import java.util.Map;
7   import java.util.Properties;
8   import java.util.Vector;
9   
10  import junit.framework.TestCase;
11  import net.sf.crispy.ExceptionWrapper;
12  import net.sf.crispy.IServiceManager;
13  import net.sf.crispy.InvocationException;
14  import net.sf.crispy.InvocationStrategy;
15  import net.sf.crispy.Property;
16  import net.sf.crispy.impl.MiniHttpServer;
17  import net.sf.crispy.impl.ModifierChain;
18  import net.sf.crispy.impl.RmiExecutor;
19  import net.sf.crispy.impl.ServiceManager;
20  import net.sf.crispy.impl.XmlRpcExecutor;
21  import net.sf.crispy.impl.caucho.CauchoServlet;
22  import net.sf.crispy.impl.caucho.MiniCauchoServer;
23  import net.sf.crispy.impl.jaxrpc.ArrayTypeMappingFactory;
24  import net.sf.crispy.impl.jaxrpc.BeanTypeMappingFactory;
25  import net.sf.crispy.impl.jaxrpc.MapTypeMappingFactory;
26  import net.sf.crispy.impl.jaxrpc.MiniAxisServer;
27  import net.sf.crispy.impl.jaxrpc.VectorTypeMappingFactory;
28  import net.sf.crispy.impl.jboss.JBossRemotingInvocationHandler;
29  import net.sf.crispy.impl.jboss.MiniJBossRemotingServer;
30  import net.sf.crispy.impl.local.MiniLocalObjectServer;
31  import net.sf.crispy.impl.rest.MiniRestServer;
32  import net.sf.crispy.impl.rest.Parser;
33  import net.sf.crispy.impl.rest.ResponseFail;
34  import net.sf.crispy.impl.rmi.MiniRmiServer;
35  import net.sf.crispy.impl.rmi.RmiInvocationHandler;
36  import net.sf.crispy.impl.rmi.RmiInvocationHandlerImpl;
37  import net.sf.crispy.impl.xmlrpc.MiniXmlRpcServer;
38  import net.sf.crispy.impl.xmlrpc.XmlRpcAdminServiceImpl;
39  import net.sf.crispy.impl.xmlrpc.XmlRpcConvertHandler;
40  import net.sf.crispy.impl.xmlrpc.XmlRpcHttpAdminServlet;
41  import net.sf.crispy.impl.xmlrpc.XmlRpcHttpServlet;
42  import net.sf.crispy.interceptor.LogInterceptor;
43  import net.sf.crispy.interceptor.StopWatchInterceptor;
44  import net.sf.crispy.strategy.ClassMethodMapInvocationStrategy;
45  import net.sf.crispy.strategy.UrlPlusClassNameInvocationStrategy;
46  
47  import org.apache.xmlrpc.XmlRpcServer;
48  
49  import test.crispy.JUnitTestException;
50  import test.crispy.example.InterceptorHandlerCreatorExample;
51  import test.crispy.example.model.Kunde;
52  import test.crispy.example.model.Primitive;
53  import test.crispy.example.modify.CalculatorModifierAfter;
54  import test.crispy.example.modify.CalculatorModifierBefore;
55  import test.crispy.example.service.Calculator;
56  import test.crispy.example.service.CalculatorImpl;
57  import test.crispy.example.service.Echo;
58  import test.crispy.example.service.EchoImpl;
59  import test.crispy.impl.rmi.RmiInvocationHandlerTestImpl;
60  import test.crispy.mock.MockServletConfig;
61  
62  public class AdditionalTest extends TestCase {
63  
64  	
65  	public void testArrayTypeMappingFactory() throws Exception {
66  		ArrayTypeMappingFactory lvArrayTypeMappingFactory = new ArrayTypeMappingFactory();
67  		try {
68  			lvArrayTypeMappingFactory.setParameter(null);
69  			fail("ArrayTypeMappingFactory.setParameter(null) must thrown a Exception");
70  		} catch (Exception e) {
71  			assertTrue(true);
72  		}
73  		
74  		String lvParams[] = new String [] { Kunde.class.getName(), Kunde.class.getName() };
75  		lvArrayTypeMappingFactory.setParameter(lvParams);
76  		assertNotNull(lvArrayTypeMappingFactory.toString());
77  		
78  		try {
79  			lvParams = new String [] { "is.not.a.valid.class", "is.not.a.valid.class" };
80  			lvArrayTypeMappingFactory.setParameter(lvParams);
81  			fail("ArrayTypeMappingFactory.setParameter(*is.not.a.valid.class') must thrown a Exception");
82  		} catch (Throwable t) {
83  			assertTrue(true);
84  		}
85  	}
86  	
87  	public void testBeanTypeMappingFactory() throws Exception {
88  		BeanTypeMappingFactory lvBeanTypeMappingFactory = new BeanTypeMappingFactory();
89  		try {
90  			lvBeanTypeMappingFactory.setParameter(null);
91  			fail("BeanTypeMappingFactory.setParameter(null) must thrown a Exception");
92  		} catch (Exception e) {
93  			assertTrue(true);
94  		}
95  
96  		try {
97  			String lvParams[] = new String [] { "is.not.a.valid.class", "is.not.a.valid.class" };
98  			lvBeanTypeMappingFactory.setParameter(lvParams);
99  			fail("BeanTypeMappingFactory.setParameter(*is.not.a.valid.class') must thrown a Exception");
100 		} catch (Throwable t) {
101 			assertTrue(true);
102 		}
103 	}
104 	
105 	public void testMapTypeMappingFactory() throws Exception {
106 		MapTypeMappingFactory lvMapTypeMappingFactory = new MapTypeMappingFactory();
107 		lvMapTypeMappingFactory.setParameter(null);
108 		assertNotNull(lvMapTypeMappingFactory.getDeserializerFactory());
109 		assertNotNull(lvMapTypeMappingFactory.getJavaType());
110 		assertNotNull(lvMapTypeMappingFactory.getSerializerFactory());
111 		assertNotNull(lvMapTypeMappingFactory.getXmlType());
112 	}
113 	
114 	public void testVectorTypeMappingFactory() throws Exception {
115 		VectorTypeMappingFactory lvVectorTypeMappingFactory = new VectorTypeMappingFactory();
116 		lvVectorTypeMappingFactory.setParameter(null);
117 		assertNotNull(lvVectorTypeMappingFactory.getDeserializerFactory());
118 		assertNotNull(lvVectorTypeMappingFactory.getJavaType());
119 		assertNotNull(lvVectorTypeMappingFactory.getSerializerFactory());
120 		assertNotNull(lvVectorTypeMappingFactory.getXmlType());
121 
122 	}
123 	
124 	public void testMiniAxisServer() throws Exception {
125 		MiniAxisServer server = new MiniAxisServer();
126 		server.addService("NoServiceInterface", "NoServiceObject");
127 		server.start();
128 		server.stop();
129 	}
130 	
131 	public void testMiniLocalObjectServer() throws Exception {
132 		MiniLocalObjectServer lvMiniLocalObjectServer = new MiniLocalObjectServer();
133 		lvMiniLocalObjectServer.addService(Calculator.class.getName(), CalculatorImpl.class.getName());
134 		lvMiniLocalObjectServer.addService("NoServiceInterface", "NoServiceObject");
135 		lvMiniLocalObjectServer.start();
136 		lvMiniLocalObjectServer.stop();
137 	}
138 	
139 	public void testMiniCauchoServer() throws Exception {
140 		MiniCauchoServer lvMiniCauchoServer = new MiniCauchoServer();
141 		lvMiniCauchoServer.addService(Echo.class.getName(), EchoImpl.class.getName());
142 		assertEquals(lvMiniCauchoServer.getServerType(), MiniCauchoServer.SERVER_TYPE_BOTH);
143 		
144 		lvMiniCauchoServer = new MiniCauchoServer(1234);
145 		assertEquals(lvMiniCauchoServer.getServerType(), MiniCauchoServer.SERVER_TYPE_BOTH);
146 		
147 		lvMiniCauchoServer = new MiniCauchoServer(MiniCauchoServer.SERVER_TYPE_BURLAP, MiniCauchoServer.DEFAULT_PORT);
148 		assertEquals(lvMiniCauchoServer.getServerType(), MiniCauchoServer.SERVER_TYPE_BURLAP);
149 		lvMiniCauchoServer.addService(Echo.class.getName(), EchoImpl.class.getName());
150 
151 		lvMiniCauchoServer = new MiniCauchoServer(MiniCauchoServer.SERVER_TYPE_HESSIAN, MiniCauchoServer.DEFAULT_PORT);
152 		assertEquals(lvMiniCauchoServer.getServerType(), MiniCauchoServer.SERVER_TYPE_HESSIAN);
153 		lvMiniCauchoServer.addService(Echo.class.getName(), EchoImpl.class.getName());
154 		
155 		lvMiniCauchoServer.start();
156 		lvMiniCauchoServer.stop();
157 	}
158 	
159 	public void testCauchoServletCache() throws Exception {
160 		CauchoServlet lvCauchoServlet = new CauchoServlet();
161 		Kunde lvKunde = new Kunde("TestKunde");
162 		lvCauchoServlet.addCache("kunde", lvKunde);
163 		Object lvObject = lvCauchoServlet.getFromCache("kunde");
164 		assertNotNull(lvObject);
165 		Kunde lvKunde2 = (Kunde) lvObject;
166 		assertEquals(lvKunde.getName(), lvKunde2.getName());
167 		assertEquals(lvCauchoServlet.getCacheSize(), 1);
168 		lvCauchoServlet.clearCahce();
169 		assertEquals(lvCauchoServlet.getCacheSize(), 0);
170 	}
171 
172 	public void testMiniJBossRemotingServer() throws Exception {
173 		MiniJBossRemotingServer lvMiniJBossRemotingServer = new MiniJBossRemotingServer("socket://localhost:5411/");
174 		lvMiniJBossRemotingServer.start();
175 		lvMiniJBossRemotingServer.stop();
176 		lvMiniJBossRemotingServer.addService(Echo.class.getName(), new EchoImpl());
177 	}
178 	
179 	public void testJBossRemotingInvocationHandler() throws Exception {
180 		JBossRemotingInvocationHandler lvHandler = new JBossRemotingInvocationHandler();
181 		lvHandler.addService(Calculator.class.getName(), new CalculatorImpl());
182 		assertEquals(lvHandler.serviceSize(), 1);
183 		lvHandler.removeService(Calculator.class.getName());
184 		assertEquals(lvHandler.serviceSize(), 0);
185 
186 		// are not implementended method
187 		lvHandler.addListener(null);
188 		lvHandler.removeListener(null);
189 	}
190 	
191 	public void testMiniRestServer() throws Exception {
192 		MiniRestServer lvMiniRestServer = new MiniRestServer();
193 		lvMiniRestServer.start();
194 		lvMiniRestServer.stop();
195 	}
196 	
197 	public void testInterceptor() throws Exception {
198 		LogInterceptor lvLogInterceptor = new LogInterceptor();
199 		lvLogInterceptor.onError(new Exception("Junit-Test-Exception"));
200 		
201 		StopWatchInterceptor lvStopWatchInterceptor = new StopWatchInterceptor();
202 		int lvOnErrorCounter = lvStopWatchInterceptor.getOnErrorCounter();
203 		lvStopWatchInterceptor.onError(new Exception("Junit-Test-Exception-2"));
204 		assertEquals((lvOnErrorCounter + 1), lvStopWatchInterceptor.getOnErrorCounter());
205 	}
206 	
207 	public void testRmiInvocationHandlerImpl() throws Exception {
208 		RmiInvocationHandlerImpl lvHandler = new RmiInvocationHandlerImpl();
209 		lvHandler.addService(Echo.class.getName(), new EchoImpl());
210 		lvHandler.addService(Calculator.class.getName(), new CalculatorImpl());
211 		assertEquals(lvHandler.getServiceSize(), 2);
212 		lvHandler.removeService(Echo.class.getName());
213 		assertEquals(lvHandler.getServiceSize(), 1);
214 		try {
215 			lvHandler.invoke(Echo.class.getName(), "echo", new Vector());
216 			fail("Can't invoke echo-Method");
217 		} catch(Exception e) {
218 			assertTrue(true);
219 		}
220 		Vector params = new Vector();
221 		params.add(new Integer(3));
222 		params.add(new Integer(5));
223 		Integer lvResult = (Integer) lvHandler.invoke(Calculator.class.getName(), "add", params);
224 		assertEquals(lvResult, new Integer(8));
225 	}
226 
227 	public void testRmiInvocationHandlerImplAddService() throws Exception {
228 		RmiInvocationHandlerImpl lvHandler = new RmiInvocationHandlerImpl();
229 		lvHandler.addService(Echo.class.getName(), new EchoImpl());
230 		lvHandler.addService(Calculator.class.getName(), CalculatorImpl.class.getName());
231 		assertEquals(lvHandler.getServiceSize(), 2);
232 		
233 		Object lvCalcImpl = lvHandler.getService(Calculator.class.getName());
234 		assertNotNull(lvCalcImpl);
235 		assertTrue(lvCalcImpl instanceof Calculator);
236 	}
237 
238 	public void testRmiInvocationHandlerThrowException() throws Exception {
239 		RmiInvocationHandlerImpl lvHandler = new RmiInvocationHandlerImpl();
240 		lvHandler.addService(Echo.class.getName(), new EchoImpl());
241 		assertEquals(lvHandler.getServiceSize(), 1);
242 		Vector lvParam = new Vector();
243 		lvParam.add("MyMessage");
244 		Object lvResult = lvHandler.invoke(Echo.class.getName(), "throwException", lvParam);
245 		assertNotNull(lvResult);
246 		assertTrue(lvResult instanceof Map);
247 		Map lvResultMap = (Map) lvResult;
248 		assertEquals(ExceptionWrapper.class.getName(), lvResultMap.get("class"));
249 	}
250 
251 	public void testRmiInvocationHandlerThrowException2() throws Exception {
252 		RmiInvocationHandlerImpl lvHandler = new RmiInvocationHandlerImpl();
253 		lvHandler.addService(Echo.class.getName(), new EchoImpl());
254 		lvHandler.addService(Calculator.class.getName(), new CalculatorImpl());
255 		assertEquals(lvHandler.getServiceSize(), 2);
256 		Vector lvParam = new Vector();
257 		lvParam.add("MyMessage");
258 		Object lvResult = lvHandler.invoke(Calculator.class.getName(), "throwException", lvParam);
259 		assertNotNull(lvResult);
260 		assertTrue(lvResult instanceof Map);
261 		Map lvResultMap = (Map) lvResult;
262 		assertEquals(ExceptionWrapper.class.getName(), lvResultMap.get("class"));
263 	}
264 
265 	public void testMiniRmiServerLastStartedRmiServer() throws Exception {
266 		assertNull(MiniRmiServer.getLastStartedRmiServer());
267 	}
268 	public void testMiniRmiServerUrlAndPort() throws Exception {
269 		MiniRmiServer lvServer = new MiniRmiServer();
270 		assertEquals(lvServer.getUrlAndPort(), RmiExecutor.DEFAULT_URL_AND_PORT);
271 		String lvTestUrlAndPort = "http://testServer:9080";
272 		lvServer.setUrlAndPort(lvTestUrlAndPort);
273 		assertEquals(lvServer.getUrlAndPort(), lvTestUrlAndPort);
274 		lvServer.addService(Echo.class.getName(), new EchoImpl());
275 	}
276 	public void testMiniRmiServerAndRmiInvocationHandler() throws Exception {
277 		RmiInvocationHandler lvHandler = new RmiInvocationHandlerImpl();
278 		MiniRmiServer lvServer = new MiniRmiServer(1089, lvHandler);
279 		assertEquals(1089, lvServer.getPort());
280 		assertEquals(lvHandler, lvServer.getRmiInvocationHandler());
281 		assertSame(lvHandler, lvServer.getRmiInvocationHandler());
282 	}
283 
284 	public void testMiniRmiServerAndRmiInvocationHandler2() throws Exception {
285 		RmiInvocationHandler lvHandler = new RmiInvocationHandlerTestImpl();
286 		MiniRmiServer lvServer = new MiniRmiServer(1089, lvHandler);
287 		InterceptorHandlerCreatorExample lvCreatorExample = new InterceptorHandlerCreatorExample();
288 		lvServer.setInterceptorHandlerCreator(lvCreatorExample);
289 		assertNull(lvServer.getInterceptorHandlerCreator());
290 		try {
291 			lvServer.addService(Echo.class.getName(), new EchoImpl());
292 			fail("Can't add Service. RmiInvocationHandlerTestImpl is not a ServiceEndpoint.");
293 		} catch (Exception e) {
294 			assertTrue(true);
295 		}
296 	}
297 
298 	public void testXmlRpcConvertHandler() throws Exception {
299 		XmlRpcConvertHandler lvHandler = new XmlRpcConvertHandler(new CalculatorImpl(), null);
300 		Vector params = new Vector();
301 		params.add(new Integer(3));
302 		params.add(new Integer(5));
303 		Integer lvResult = (Integer) lvHandler.execute("Calculator.add", params);
304 		assertEquals(lvResult, new Integer(8));
305 		lvHandler.execute("add", params);
306 		try {
307 			params.remove(0);
308 			lvHandler.execute("add_", params);
309 			fail("Can't invoke add-Method");
310 		} catch(Exception e) {
311 			assertTrue(true);
312 		}
313 		
314 	}
315 	
316 	public void testMiniHttpServer() throws Exception {
317 		MiniHttpServer lvHttpServer = new MiniHttpServer();
318 		lvHttpServer.addService(Echo.class.getName(), EchoImpl.class.getName());
319 		assertEquals(lvHttpServer.getContext(), "/");
320 		lvHttpServer.setContext(null);
321 		assertEquals(lvHttpServer.getContext(), "/");
322 		lvHttpServer.setContext("test-context");
323 		assertEquals(lvHttpServer.getContext(), "/test-context");
324 		lvHttpServer.addServlet("/servler", XmlRpcHttpAdminServlet.class.getName());
325 		lvHttpServer.start();
326 		lvHttpServer.start();
327 		lvHttpServer.stop();
328 	}
329 	
330 	public void testMiniHttpServerInHttpPackage() throws Exception {
331 		net.sf.crispy.impl.http.MiniHttpServer lvHttpServer = new net.sf.crispy.impl.http.MiniHttpServer();
332 		assertNotNull(lvHttpServer.getInternalHttpServer());
333 	}
334 	
335 	public void testMiniHttpServerInHttpPackageServletsProperties() throws Exception {
336 		net.sf.crispy.impl.http.MiniHttpServer lvHttpServer = new net.sf.crispy.impl.http.MiniHttpServer();
337 		String lvServletName = "MyTestServlet";
338 		lvHttpServer.setServletName(lvServletName);
339 		assertEquals(lvServletName, lvHttpServer.getServletName());
340 		
341 		String lvServletContext = "MyTestServletContext";
342 		lvHttpServer.setServletContext(lvServletContext);
343 		assertEquals(lvServletContext + "*", lvHttpServer.getServletContext());
344 	}
345 
346 	
347 	public void testModifierChain() throws Exception {
348 		ModifierChain lvModifierChain = new ModifierChain();
349 		lvModifierChain.addModifier(new CalculatorModifierAfter());
350 		assertEquals(lvModifierChain.size(), 1);
351 		
352 		Properties lvProperties = new Properties();
353 		lvProperties.put(Calculator.class.getName(), CalculatorImpl.class.getName());
354 		lvProperties.put(Property.DYNAMIC_PROXY_CLASS, Property.VALUE_FOR_JDK_DYNAMIC_PROXY);
355 		
356 		IServiceManager lvServiceManager = new ServiceManager(lvProperties);
357 		lvServiceManager.setModifier(lvModifierChain);
358 		
359 		Calculator lvCalculator = (Calculator) lvServiceManager.createService(Calculator.class);
360 		int lvResult = lvCalculator.add(1, 1);
361 		assertEquals(lvResult, CalculatorModifierAfter.NEW_ADD_VALUE.intValue());
362 		
363 		lvModifierChain.removeModifier(0);
364 		assertEquals(lvModifierChain.size(), 0);
365 		lvModifierChain.addModifier(new CalculatorModifierBefore());
366 		assertEquals(lvModifierChain.size(), 1);
367 		
368 		lvResult = lvCalculator.add(1, 1);
369 		assertEquals(lvResult, -2);
370 	}
371 	
372 	public void testXmlRpcHttpAdminServlet() throws Exception {
373 		XmlRpcHttpAdminServlet lvRpcHttpServlet = new XmlRpcHttpAdminServlet();
374 		lvRpcHttpServlet.init();
375 		lvRpcHttpServlet.init(null);
376 		lvRpcHttpServlet.addService(Echo.class.getName(), EchoImpl.class.getName());
377 		assertTrue(lvRpcHttpServlet.existService(Echo.class.getName()).booleanValue());
378 		assertEquals(lvRpcHttpServlet.getAllService().size(), 3);
379 		lvRpcHttpServlet.removeService(Echo.class.getName());
380 		assertEquals(lvRpcHttpServlet.getAllService().size(), 2);
381 
382 		lvRpcHttpServlet.addService(Echo.class.getName(), new EchoImpl());
383 		assertTrue(lvRpcHttpServlet.existService(Echo.class.getName()).booleanValue());
384 		assertEquals(lvRpcHttpServlet.getAllService().size(), 3);
385 	}
386 
387 	public void testXmlRpcHttpServletOnServer() throws Exception {
388 		MiniHttpServer lvHttpServer = new MiniHttpServer(9876);
389 		lvHttpServer.addService(Echo.class.getName(), EchoImpl.class.getName());
390 		lvHttpServer.setContext("/crispy");
391 		lvHttpServer.addServlet("xmlrpc-servlet", XmlRpcHttpAdminServlet.class.getName());
392 		
393 		lvHttpServer.start();
394 
395 		Properties prop = new Properties();
396 		prop.put(Property.EXECUTOR_CLASS, XmlRpcExecutor.class.getName());
397 		prop.put(Property.REMOTE_URL_AND_PORT, "http://localhost:9876/crispy/xmlrpc-servlet");
398 		ServiceManager lvServiceManager = new ServiceManager(prop);
399 		Echo lvEcho = (Echo) lvServiceManager.createService(Echo.class);
400 		String lvEchoStr = "Hello Crispy ...";
401 		assertEquals(lvEcho.echo(lvEchoStr), lvEchoStr);
402 		
403 		lvHttpServer.stop();
404 	}
405 	
406 	public void testXmlParser() throws Exception {
407 		Parser lvParser = new Parser();
408 		lvParser.parse("<test>Test</test>");
409 	}
410 	
411 	public void testResponseFail() throws Exception {
412 		ResponseFail lvResponseFail = new ResponseFail();
413 		assertEquals(lvResponseFail.getMethod(), "- NoMethod -");
414 		lvResponseFail.setMethod("Test");
415 		assertEquals(lvResponseFail.getMethod(), "Test");
416 		
417 		assertEquals(lvResponseFail.getService(), "- NoServiceClass -");
418 		lvResponseFail.setService("TestService");
419 		assertEquals(lvResponseFail.getService(), "TestService");
420 		
421 		assertNotNull(lvResponseFail.toString());
422 	}
423 	
424 	public void testClassMethodMapInvocationStrategy() throws Exception {
425 		ClassMethodMapInvocationStrategy lvStrategy = new ClassMethodMapInvocationStrategy();
426 		Map lvMap = new HashMap();
427 		try {
428 			lvStrategy.convert(lvMap);	
429 			fail();
430 		} catch (Exception e) {
431 			assertTrue(true);
432 		}
433 		
434 		lvMap.put(InvocationStrategy.CLASS_NAME, Calculator.class.getName());
435 		try {
436 			lvStrategy.convert(lvMap);	
437 			fail();
438 		} catch (Exception e) {
439 			assertTrue(true);
440 		}
441 	}
442 	
443 	public void testUrlPlusClassNameInvocationStrategy() throws Exception {
444 		UrlPlusClassNameInvocationStrategy lvStrategy = new UrlPlusClassNameInvocationStrategy();
445 		Map lvMap = new HashMap();
446 		lvMap.put(InvocationStrategy.CONST_NAMESPACE, "test");
447 		lvStrategy.convert(lvMap);
448 	}
449 	
450 	public void testMiniXmlRpcServer() throws Exception {
451 		MiniXmlRpcServer lvMiniXmlRpcServer = new MiniXmlRpcServer();
452 		lvMiniXmlRpcServer.start();
453 		lvMiniXmlRpcServer.start();
454 		lvMiniXmlRpcServer.addService("test.NotValideInterface", "test.NotValideImplementation");
455 		lvMiniXmlRpcServer.stop();
456 	}
457 	
458 	public void testMiniXmlRpcServer2() throws Exception {
459 		int lvPort = 1234;
460 		String lvNullValue = "MyTestNullValue";
461 		MiniXmlRpcServer lvMiniXmlRpcServer = new MiniXmlRpcServer(lvPort, lvNullValue);
462 		assertEquals(lvPort, lvMiniXmlRpcServer.getPort().intValue());
463 		assertEquals(lvNullValue, lvMiniXmlRpcServer.getNullValue());
464 	}
465 	
466 	public void testXmlRpcHttpServlet() throws Exception {
467 		MiniHttpServer server = new MiniHttpServer(8023);
468 		server.setContext("/crispy");
469 		server.addServlet("/xmlrpc-test/*", XmlRpcHttpServlet.class.getName(), Echo.class.getName(), EchoImpl.class.getName());
470 		server.start();
471 		
472 		Properties props = new Properties();
473 		props.put(Property.REMOTE_URL_AND_PORT, "http://localhost:8023/crispy/xmlrpc-test");
474 		props.put(Property.EXECUTOR_CLASS, XmlRpcExecutor.class.getName());
475 		ServiceManager lvManager = new ServiceManager(props);
476 		Echo lvEcho = (Echo) lvManager.createService(Echo.class);
477 		assertEquals(lvEcho.echo("ECHO"), "ECHO");
478 	}
479 
480 	public void testXmlRpcHttpServletInit() throws Exception {
481 		XmlRpcHttpServlet lvXmlRpcHttpServlet = new XmlRpcHttpServlet();
482 		MockServletConfig config = new MockServletConfig("XmlRpcHttpServlet");
483 		config.addInitParameter("test.service", "not.valid.Class");
484 		try {
485 			lvXmlRpcHttpServlet.init(config);
486 			fail("Exception with null parameter");
487 		} catch (Exception e) {
488 			assertTrue(true);
489 		}		
490 	}
491 	
492 	public void testXmlRpcHttpServletNullValue() throws Exception {
493 		XmlRpcHttpServlet lvXmlRpcHttpServlet = new XmlRpcHttpServlet();
494 		String lvNullValue = "MyTestNullValue";
495 		lvXmlRpcHttpServlet.setNullValue(lvNullValue);
496 		assertEquals(lvNullValue, lvXmlRpcHttpServlet.getNullValue());
497 	}
498 	
499 	public void testXmlRpcHttpServletServiceMethods() throws Exception {
500 		XmlRpcHttpServlet lvXmlRpcHttpServlet = new XmlRpcHttpServlet();
501 		assertEquals(0, lvXmlRpcHttpServlet.getServiceSize());
502 		
503 		lvXmlRpcHttpServlet.addService(Echo.class.getName(), EchoImpl.class.getName());
504 		assertEquals(1, lvXmlRpcHttpServlet.getServiceSize());
505 		
506 		lvXmlRpcHttpServlet.addService(Echo.class.getName(), new EchoImpl());
507 		assertEquals(1, lvXmlRpcHttpServlet.getServiceSize());
508 		
509 		lvXmlRpcHttpServlet.addService(Calculator.class.getName(), CalculatorImpl.class.getName());
510 		assertEquals(2, lvXmlRpcHttpServlet.getServiceSize());
511 
512 		lvXmlRpcHttpServlet.removeService(Echo.class.getName());
513 		assertEquals(1, lvXmlRpcHttpServlet.getServiceSize());
514 	}
515 
516 	public void testXmlRpcAdminServiceImpl() throws Exception {
517 		XmlRpcAdminServiceImpl lvAdminServiceImpl = new XmlRpcAdminServiceImpl(new XmlRpcServer(), null, null);
518 		assertEquals(lvAdminServiceImpl.getAllService().size(), 2);
519 		
520 		Map lvServiceMap = new HashMap();
521 		lvServiceMap.put(Echo.class.getName(), EchoImpl.class.getName());
522 		lvAdminServiceImpl = new XmlRpcAdminServiceImpl(new XmlRpcServer(), lvServiceMap, null);
523 		assertEquals(lvAdminServiceImpl.getAllService().size(), 3);
524 
525 	}
526 	
527 	public void testDebugModeOn() throws Exception {
528 		Properties props = new Properties();
529 		ServiceManager lvManager = new ServiceManager(props);
530 		assertFalse(ServiceManager.DEBUG_MODE_ON);
531 		assertNotNull(lvManager);
532 		
533 		props.put(Property.DEBUG_MODE_ON, "true");
534 		lvManager = new ServiceManager(props);
535 		assertTrue(ServiceManager.DEBUG_MODE_ON);
536 	}
537 	
538 	public void testDebugModeOnGloabal() throws Exception {
539 		ServiceManager.DEBUG_MODE_ON = true;
540 		Properties props = new Properties();
541 		props.put(Property.DEBUG_MODE_ON, "false");
542 		new ServiceManager(props);
543 		assertTrue(ServiceManager.DEBUG_MODE_ON);
544 		
545 		ServiceManager.DEBUG_MODE_ON = false;
546 		assertFalse(ServiceManager.DEBUG_MODE_ON);
547 	}
548 	
549 	public void testEqualsPrimitive() throws Exception {
550 		Primitive lvPrimitive = Primitive.createPrimitiveExample();
551 		
552 		assertFalse(lvPrimitive.equals(null));
553 		assertFalse(lvPrimitive.equals("TestString"));
554 		assertFalse(lvPrimitive.equals(new Primitive()));
555 		
556 		assertEquals(lvPrimitive, Primitive.createPrimitiveExample());
557 	}
558 	
559 	public void testInvocationException() throws Exception {
560 		PrintStream lvErr = System.err;
561 		// no error print
562 		System.setErr(new PrintStream(new ByteArrayOutputStream(0)));
563 
564 		String lvMessage = "JUnit-Test-Message";
565 		InvocationException lvException = new InvocationException(lvMessage);
566 		assertEquals(lvMessage, lvException.getMessage());
567 		
568 		lvException.printStackTrace();
569 		System.setErr(lvErr);
570 	}
571 	
572 	public void testInvocationException2() throws Exception {
573 		
574 
575 		String lvMessage = "JUnit-Test-Message";
576 		ExceptionWrapper lvExceptionWrapper = new ExceptionWrapper(new JUnitTestException(lvMessage));
577 		InvocationException lvException = new InvocationException(lvExceptionWrapper);
578 		assertEquals(lvMessage, lvExceptionWrapper.getMessage());
579 
580 		PrintStream lvOut = System.out;
581 		// no error print
582 		System.setOut(new PrintStream(new ByteArrayOutputStream(0)));
583 		
584 		lvException.printStackTrace();
585 		lvExceptionWrapper.printStackTrace(new ByteArrayOutputStream(0));
586 		lvExceptionWrapper.printStackTrace();
587 		lvExceptionWrapper.printStackTrace2();
588 
589 		System.setOut(lvOut);
590 	}
591 
592 }