File: AJAXRPC.java

package info (click to toggle)
axis 1.4-29
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 52,100 kB
  • sloc: java: 129,124; xml: 10,602; jsp: 983; sh: 84; cs: 36; makefile: 18
file content (131 lines) | stat: -rw-r--r-- 4,403 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package test.jaxrpc;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.xml.rpc.handler.HandlerChain;
import javax.xml.rpc.handler.HandlerInfo;

import junit.framework.TestCase;

import org.apache.axis.AxisFault;
import org.apache.axis.MessageContext;
import org.apache.axis.handlers.BasicHandler;
import org.apache.axis.handlers.HandlerInfoChainFactory;


/**
 *
 *
 * @author Guillaume Sauthier
 */
public abstract class AJAXRPC extends TestCase {

    HandlerInfo handlerInfo0 = null;
    HandlerInfo handlerInfo1 = null;
    HandlerInfo handlerInfo2 = null;
    Map handler0Config = null;
    protected Map handler1Config = null;
    protected Map handler2Config = null;

    /**
     * Sets up the handlerInfo and handlerConfigs for all tests.
     * Each test has 3 JAX-RPC Handlers of the same type to keep things
     * simple.
     * 
     * @throws Exception 
     */
    protected void setUp() throws Exception {
        handlerInfo0 = new HandlerInfo();
        handlerInfo0.setHandlerClass(AAAHandler.class);
        handlerInfo1 = new HandlerInfo();
        handlerInfo1.setHandlerClass(AAAHandler.class);
        handlerInfo2 = new HandlerInfo();
        handlerInfo2.setHandlerClass(AAAHandler.class);
        handler0Config = new HashMap();
        handler1Config = new HashMap();
        handler2Config = new HashMap();
        handlerInfo0.setHandlerConfig(handler0Config);
        handlerInfo1.setHandlerConfig(handler1Config);
        handlerInfo2.setHandlerConfig(handler2Config);
    }

    /**
     * Convenience method to organize all test checking for a particular
     * handler.
     * <p/>
     * Checks to see if the expected number of calls to handleRequest, handleResponse
     * and handleFault reconciles with actuals
     * 
     * @param message           
     * @param handler           the target handler to reconcile
     * @param numHandleRequest  # of expected calls to handleRequest
     * @param numHandleResponse # of expected calls to handleResponse
     * @param numHandleFault    # of expected call to handleFault
     */
    protected void assertHandlerRuntime(String message, AAAHandler handler, int numHandleRequest, int numHandleResponse, int numHandleFault) {
        assertEquals(message + ": handleRequest", numHandleRequest,
                handler.getHandleRequestInvocations());
        assertEquals(message + ": handleResponse", numHandleResponse,
                handler.getHandleResponseInvocations());
        assertEquals(message + ": handleFault", numHandleFault,
                handler.getHandleFaultInvocations());
    }

    /**
     * Convenience method to create a HandlerInfoChainFactory
     * 
     * @return 
     */
    protected TestHandlerInfoChainFactory buildInfoChainFactory() {
        List handlerInfos = new ArrayList();
        handlerInfos.add(handlerInfo0);
        handlerInfos.add(handlerInfo1);
        handlerInfos.add(handlerInfo2);
        TestHandlerInfoChainFactory factory = new TestHandlerInfoChainFactory(
                handlerInfos);
        return factory;
    }
    /**
     * Mock Service Handler used to simulate a service object throwing
     * an AxisFault.
     */
    protected class MockServiceHandler extends BasicHandler {
        public void invoke(MessageContext msgContext) throws AxisFault {
            throw new AxisFault();
        }
    }

    /**
     * Helper class for keeping references to the JAX-RPC Handlers
     * that are created by the Factory.
     * <p/>
     * This class allows us to access the individual handlers after
     * the test case has been executed in order to make sure that
     * the expected methods of the handler instance have been invoked.
     */
    protected class TestHandlerInfoChainFactory extends HandlerInfoChainFactory {
        AAAHandler[] handlers;

        public TestHandlerInfoChainFactory(List handlerInfos) {
            super(handlerInfos);
        }

        public HandlerChain createHandlerChain() {
            HandlerChain chain = super.createHandlerChain();
            handlers = new AAAHandler[chain.size()];
            for (int i = 0; i < chain.size(); i++) {
                handlers[i] = (AAAHandler) chain.get(i);
            }
            return chain;
        }

        public AAAHandler[] getHandlers() {
            return handlers;
        }

    }

}