KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > jaxrpc > AJAXRPC


1 package test.jaxrpc;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.HashMap JavaDoc;
5 import java.util.List JavaDoc;
6 import java.util.Map JavaDoc;
7
8 import javax.xml.rpc.handler.HandlerChain JavaDoc;
9 import javax.xml.rpc.handler.HandlerInfo JavaDoc;
10
11 import junit.framework.TestCase;
12
13 import org.apache.axis.AxisFault;
14 import org.apache.axis.MessageContext;
15 import org.apache.axis.handlers.BasicHandler;
16 import org.apache.axis.handlers.HandlerInfoChainFactory;
17
18
19 /**
20  *
21  *
22  * @author Guillaume Sauthier
23  */

24 public abstract class AJAXRPC extends TestCase {
25
26     HandlerInfo JavaDoc handlerInfo0 = null;
27     HandlerInfo JavaDoc handlerInfo1 = null;
28     HandlerInfo JavaDoc handlerInfo2 = null;
29     Map JavaDoc handler0Config = null;
30     protected Map JavaDoc handler1Config = null;
31     protected Map JavaDoc handler2Config = null;
32
33     /**
34      * Sets up the handlerInfo and handlerConfigs for all tests.
35      * Each test has 3 JAX-RPC Handlers of the same type to keep things
36      * simple.
37      *
38      * @throws Exception
39      */

40     protected void setUp() throws Exception JavaDoc {
41         handlerInfo0 = new HandlerInfo JavaDoc();
42         handlerInfo0.setHandlerClass(AAAHandler.class);
43         handlerInfo1 = new HandlerInfo JavaDoc();
44         handlerInfo1.setHandlerClass(AAAHandler.class);
45         handlerInfo2 = new HandlerInfo JavaDoc();
46         handlerInfo2.setHandlerClass(AAAHandler.class);
47         handler0Config = new HashMap JavaDoc();
48         handler1Config = new HashMap JavaDoc();
49         handler2Config = new HashMap JavaDoc();
50         handlerInfo0.setHandlerConfig(handler0Config);
51         handlerInfo1.setHandlerConfig(handler1Config);
52         handlerInfo2.setHandlerConfig(handler2Config);
53     }
54
55     /**
56      * Convenience method to organize all test checking for a particular
57      * handler.
58      * <p/>
59      * Checks to see if the expected number of calls to handleRequest, handleResponse
60      * and handleFault reconciles with actuals
61      *
62      * @param message
63      * @param handler the target handler to reconcile
64      * @param numHandleRequest # of expected calls to handleRequest
65      * @param numHandleResponse # of expected calls to handleResponse
66      * @param numHandleFault # of expected call to handleFault
67      */

68     protected void assertHandlerRuntime(String JavaDoc message, AAAHandler handler, int numHandleRequest, int numHandleResponse, int numHandleFault) {
69         assertEquals(message + ": handleRequest", numHandleRequest,
70                 handler.getHandleRequestInvocations());
71         assertEquals(message + ": handleResponse", numHandleResponse,
72                 handler.getHandleResponseInvocations());
73         assertEquals(message + ": handleFault", numHandleFault,
74                 handler.getHandleFaultInvocations());
75     }
76
77     /**
78      * Convenience method to create a HandlerInfoChainFactory
79      *
80      * @return
81      */

82     protected TestHandlerInfoChainFactory buildInfoChainFactory() {
83         List JavaDoc handlerInfos = new ArrayList JavaDoc();
84         handlerInfos.add(handlerInfo0);
85         handlerInfos.add(handlerInfo1);
86         handlerInfos.add(handlerInfo2);
87         TestHandlerInfoChainFactory factory = new TestHandlerInfoChainFactory(
88                 handlerInfos);
89         return factory;
90     }
91     /**
92      * Mock Service Handler used to simulate a service object throwing
93      * an AxisFault.
94      */

95     protected class MockServiceHandler extends BasicHandler {
96         public void invoke(MessageContext msgContext) throws AxisFault {
97             throw new AxisFault();
98         }
99     }
100
101     /**
102      * Helper class for keeping references to the JAX-RPC Handlers
103      * that are created by the Factory.
104      * <p/>
105      * This class allows us to access the individual handlers after
106      * the test case has been executed in order to make sure that
107      * the expected methods of the handler instance have been invoked.
108      */

109     protected class TestHandlerInfoChainFactory extends HandlerInfoChainFactory {
110         AAAHandler[] handlers;
111
112         public TestHandlerInfoChainFactory(List JavaDoc handlerInfos) {
113             super(handlerInfos);
114         }
115
116         public HandlerChain JavaDoc createHandlerChain() {
117             HandlerChain JavaDoc chain = super.createHandlerChain();
118             handlers = new AAAHandler[chain.size()];
119             for (int i = 0; i < chain.size(); i++) {
120                 handlers[i] = (AAAHandler) chain.get(i);
121             }
122             return chain;
123         }
124
125         public AAAHandler[] getHandlers() {
126             return handlers;
127         }
128
129     }
130
131 }
132
Popular Tags