01: package test.crispy.server;
02:
03: import junit.framework.TestCase;
04: import net.sf.crispy.ExceptionWrapper;
05: import net.sf.crispy.InterceptorHandler;
06: import net.sf.crispy.interceptor.StopWatchInterceptor;
07: import net.sf.crispy.server.ServiceEndpoint;
08: import net.sf.crispy.server.ServiceEndpointImpl;
09: import test.crispy.JUnitTestException;
10: import test.crispy.example.SubServiceEndpoint;
11: import test.crispy.example.interceptor.WaitInterceptor;
12: import test.crispy.example.service.EchoImpl;
13:
14: public class ServiceEndpointTest extends TestCase {
15:
16: public void testDoInvoke() throws Exception {
17: ServiceEndpoint lvEndpoint = new ServiceEndpointImpl();
18: Object lvResult = lvEndpoint.doInvoke(new EchoImpl(),
19: EchoImpl.class.getMethod("ping", null), null, null);
20: assertEquals(EchoImpl.PING_STRING, lvResult);
21: }
22:
23: public void testDoInvoke_2() throws Exception {
24: ServiceEndpoint lvEndpoint = new ServiceEndpointImpl();
25: Object lvResult = lvEndpoint.doInvoke(new EchoImpl(),
26: EchoImpl.class.getMethod("echo",
27: new Class[] { String.class }),
28: new Object[] { "My Echo" }, null);
29: assertEquals("My Echo", lvResult);
30: }
31:
32: public void testInterceptorHandler() throws Exception {
33: ServiceEndpoint lvEndpoint = new ServiceEndpointImpl();
34: assertNotNull(lvEndpoint.createNewInterceptorHandlerInstance());
35: }
36:
37: public void testInterceptorHandler_2() throws Exception {
38: SubServiceEndpoint lvEndpoint = new SubServiceEndpoint();
39: assertNotNull(lvEndpoint.createNewInterceptorHandlerInstance());
40:
41: StopWatchInterceptor lvStopWatchInterceptor = lvEndpoint
42: .getStopWatchInterceptor();
43: assertTrue(lvStopWatchInterceptor.getStopTimeInvokeMethod() < 0);
44:
45: lvEndpoint.doInvoke(new EchoImpl(), EchoImpl.class.getMethod(
46: "echo", new Class[] { String.class }),
47: new Object[] { "My Echo" }, null);
48: assertTrue(lvStopWatchInterceptor.getStopTimeInvokeMethod() > 20);
49: assertEquals(2, lvEndpoint
50: .createNewInterceptorHandlerInstance()
51: .getInterceptorSize());
52: }
53:
54: public void testInterceptorHandler_3() throws Exception {
55: ServiceEndpoint lvEndpoint = new ServiceEndpointImpl();
56: assertNotNull(lvEndpoint.createNewInterceptorHandlerInstance());
57:
58: StopWatchInterceptor lvStopWatch = new StopWatchInterceptor();
59: InterceptorHandler lvHandler = new InterceptorHandler();
60: lvHandler.addInterceptor(new WaitInterceptor());
61: lvHandler.addInterceptor(lvStopWatch);
62:
63: Object lvResult = lvEndpoint
64: .doInvoke(new EchoImpl(), EchoImpl.class.getMethod(
65: "ping", null), null, lvHandler);
66: assertEquals(EchoImpl.PING_STRING, lvResult);
67: assertTrue(lvStopWatch.getStopTimeInvokeMethod() > 20);
68: }
69:
70: public void testException() throws Exception {
71: ServiceEndpoint lvEndpoint = new ServiceEndpointImpl();
72:
73: String lvMessage = "Test-Message";
74: Object lvResult = lvEndpoint.doInvoke(new EchoImpl(),
75: EchoImpl.class.getMethod("throwException",
76: new Class[] { String.class }),
77: new String[] { lvMessage }, null);
78: assertNotNull(lvResult);
79: assertTrue(lvResult instanceof ExceptionWrapper);
80: ExceptionWrapper lvExceptionWrapper = (ExceptionWrapper) lvResult;
81: assertEquals(JUnitTestException.class.getName(),
82: lvExceptionWrapper.getExceptionClassName());
83: assertEquals("Test Exception: " + lvMessage, lvExceptionWrapper
84: .getMessage());
85:
86: assertTrue(lvExceptionWrapper.getStackTraceByteArray().length > 0);
87: assertTrue(lvExceptionWrapper.getStackTraceElementWrapperList()
88: .size() > 0);
89: }
90: }
|