View Javadoc

1   package test.crispy.server;
2   
3   import junit.framework.TestCase;
4   import net.sf.crispy.ExceptionWrapper;
5   import net.sf.crispy.InterceptorHandler;
6   import net.sf.crispy.interceptor.StopWatchInterceptor;
7   import net.sf.crispy.server.ServiceEndpoint;
8   import net.sf.crispy.server.ServiceEndpointImpl;
9   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(), EchoImpl.class.getMethod("ping", null), null, null);
19  		assertEquals(EchoImpl.PING_STRING, lvResult);
20  	}
21  	
22  	public void testDoInvoke_2() throws Exception {
23  		ServiceEndpoint lvEndpoint = new ServiceEndpointImpl();
24  		Object lvResult = lvEndpoint.doInvoke(new EchoImpl(), 
25  										EchoImpl.class.getMethod("echo", new Class[] {String.class}), 
26  										new Object [] {"My Echo"}, null);
27  		assertEquals("My Echo", lvResult);
28  	}
29  
30  
31  	public void testInterceptorHandler() throws Exception {
32  		ServiceEndpoint lvEndpoint = new ServiceEndpointImpl();
33  		assertNotNull(lvEndpoint.createNewInterceptorHandlerInstance());
34  	}
35  
36  	public void testInterceptorHandler_2() throws Exception {
37  		SubServiceEndpoint lvEndpoint = new SubServiceEndpoint();
38  		assertNotNull(lvEndpoint.createNewInterceptorHandlerInstance());
39  
40  		StopWatchInterceptor lvStopWatchInterceptor = lvEndpoint.getStopWatchInterceptor();
41  		assertTrue(lvStopWatchInterceptor.getStopTimeInvokeMethod() < 0);
42  		
43  		lvEndpoint.doInvoke(new EchoImpl(), EchoImpl.class.getMethod("echo", new Class[] {String.class}), new Object [] {"My Echo"}, null);
44  		assertTrue(lvStopWatchInterceptor.getStopTimeInvokeMethod() > 20);
45  		assertEquals(2, lvEndpoint.createNewInterceptorHandlerInstance().getInterceptorSize());
46  	}
47  	
48  	public void testInterceptorHandler_3() throws Exception {
49  		ServiceEndpoint lvEndpoint = new ServiceEndpointImpl();
50  		assertNotNull(lvEndpoint.createNewInterceptorHandlerInstance());
51  		
52  		StopWatchInterceptor lvStopWatch = new StopWatchInterceptor();
53  		InterceptorHandler lvHandler = new InterceptorHandler();
54  		lvHandler.addInterceptor(new WaitInterceptor());
55  		lvHandler.addInterceptor(lvStopWatch);
56  
57  		Object lvResult = lvEndpoint.doInvoke(new EchoImpl(), EchoImpl.class.getMethod("ping", null), null, lvHandler);
58  		assertEquals(EchoImpl.PING_STRING, lvResult);
59  		assertTrue(lvStopWatch.getStopTimeInvokeMethod() > 20);
60  	}
61  
62  
63  	public void testException() throws Exception {
64  		ServiceEndpoint lvEndpoint = new ServiceEndpointImpl();
65  		
66  		String lvMessage = "Test-Message";
67  		Object lvResult = lvEndpoint.doInvoke(new EchoImpl(), EchoImpl.class.getMethod("throwException", new Class [] { String.class } ), new String[] {lvMessage}, null);
68  		assertNotNull(lvResult);
69  		assertTrue(lvResult instanceof ExceptionWrapper);
70  		ExceptionWrapper lvExceptionWrapper = (ExceptionWrapper) lvResult;
71  		assertEquals(JUnitTestException.class.getName(), lvExceptionWrapper.getExceptionClassName());
72  		assertEquals("Test Exception: " + lvMessage, lvExceptionWrapper.getMessage());
73  		
74  		assertTrue(lvExceptionWrapper.getStackTraceByteArray().length > 0);
75  		assertTrue(lvExceptionWrapper.getStackTraceElementWrapperList().size() > 0);
76  	}
77  }