KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > wsdd > TestStructure


1 package test.wsdd;
2
3 import junit.framework.Test;
4 import junit.framework.TestCase;
5 import junit.framework.TestSuite;
6 import org.apache.axis.Chain;
7 import org.apache.axis.Handler;
8 import org.apache.axis.TargetedChain;
9 import org.apache.axis.configuration.FileProvider;
10 import org.apache.axis.handlers.soap.SOAPService;
11 import org.apache.axis.server.AxisServer;
12
13 import java.io.InputStream JavaDoc;
14
15 /**
16  * Positive test of basic structure of a WSDD document
17  */

18 public class TestStructure extends TestCase
19 {
20     static final String JavaDoc INPUT_FILE = "testStructure1.wsdd";
21     AxisServer server;
22
23     public TestStructure (String JavaDoc name)
24     {
25         super(name);
26     }
27
28     public static Test suite()
29     {
30         return new TestSuite(TestStructure.class);
31     }
32
33     protected void setUp()
34     {
35         InputStream JavaDoc is = getClass().getResourceAsStream(INPUT_FILE);
36         FileProvider provider = new FileProvider(is);
37         server = new AxisServer(provider);
38     }
39
40     public static void main(String JavaDoc[] args) throws Exception JavaDoc
41     {
42         TestStructure tester = new TestStructure("TestStructure");
43         tester.setUp();
44         tester.testServiceBackReference();
45     }
46     
47     public void testChainAnonymousHandler() throws Exception JavaDoc
48     {
49         Chain chainOne = (Chain) server.getHandler("chain.one");
50         assertNotNull("chain.one should be non-null!", chainOne);
51
52         Handler chainOne_handlers[] = chainOne.getHandlers();
53         assertNotNull("chain.one/handlers should be non-null!",
54                       chainOne_handlers);
55         assertTrue("chain.one should have exactly 1 handler!",
56                 (1 == chainOne_handlers.length));
57
58         Handler chainOne_handler = chainOne_handlers[0];
59         assertNotNull("chain.one's handler should be non-null!",
60                       chainOne_handler);
61         assertTrue("chain.one's handler should be a JWSHandler!",
62                 (chainOne_handler instanceof
63                  org.apache.axis.handlers.JWSHandler));
64     }
65
66     public void testServiceBackReference() throws Exception JavaDoc
67     {
68         SOAPService serviceOne = (SOAPService)server.getService("service.one");
69         assertNotNull("service.one should be non-null!", serviceOne);
70
71         Chain serviceOne_responseFlow = (Chain)serviceOne.getResponseHandler();
72         assertNotNull("service.two/responseFlow should be non-null!",
73                       serviceOne_responseFlow);
74
75         Handler serviceOne_responseFlow_handlers[] =
76                              serviceOne_responseFlow.getHandlers();
77         assertNotNull("service.one/responseFlow/handlers should be non-null!",
78                         serviceOne_responseFlow_handlers);
79         assertTrue("service.one should have exactly 1 handler!",
80                 (1 == serviceOne_responseFlow_handlers.length));
81
82         Handler serviceOne_responseFlow_handler =
83                         serviceOne_responseFlow_handlers[0];
84         assertNotNull("service.one's handler should be non-null!",
85                       serviceOne_responseFlow_handler);
86         assertTrue("service.one's handler should be a RPCProvider!",
87                     (serviceOne_responseFlow_handler instanceof
88                          org.apache.axis.providers.java.RPCProvider));
89
90         Handler serviceOne_handler_byName = server.getHandler("BackReference");
91         assertTrue("service.one's 'BackReference' should be same as directly accessed 'BR'!",
92                    (serviceOne_responseFlow_handler ==
93                             serviceOne_handler_byName));
94
95          /*******************************************************
96           <service name="service.two" provider="java:MSG">
97            <requestFlow>
98              <handler type="BackReference"/>
99            </requestFlow>
100           </service>
101          ******************************************************/

102         SOAPService serviceTwo = null;
103         serviceTwo = (SOAPService) server.getService("service.two");
104         assertTrue("service.two should be non-null!",
105                    (null != serviceTwo));
106
107         Chain serviceTwo_requestFlow = (Chain) serviceTwo.getRequestHandler();
108         assertTrue("service.two/requestFlow should be non-null!",
109                 (null != serviceTwo_requestFlow));
110
111         Handler serviceTwo_requestFlow_handlers[] =
112                                 serviceTwo_requestFlow.getHandlers();
113         assertTrue("service.two/requestFlow/handlers should be non-null!",
114                 (null != serviceTwo_requestFlow_handlers));
115         assertTrue("service.two should have exactly 1 handler!",
116                 (1 == serviceTwo_requestFlow_handlers.length));
117
118         Handler serviceTwo_requestFlow_handler =
119                                 serviceTwo_requestFlow_handlers[0];
120         assertTrue("service.two's handler should be non-null!",
121                 (null != serviceTwo_requestFlow_handler));
122         assertTrue("service.two's handler should be a RPCProvider!",
123                     (serviceTwo_requestFlow_handler instanceof
124                                 org.apache.axis.providers.java.RPCProvider));
125
126         assertTrue("service.two's 'BackReference' should be same as service.one's!",
127                    (serviceTwo_requestFlow_handler ==
128                             serviceOne_responseFlow_handler));
129     }
130
131     public void testTransportForwardReference()
132             throws Exception JavaDoc
133     {
134         TargetedChain transportOne =
135                         (TargetedChain)server.getTransport("transport.one");
136         assertNotNull("transport.one should be non-null!", transportOne);
137
138         Chain transportOne_responseFlow =
139                         (Chain)transportOne.getResponseHandler();
140         assertNotNull("transport.two/responseFlow should be non-null!",
141                       transportOne_responseFlow);
142
143         Handler transportOne_responseFlow_handlers[] =
144                         transportOne_responseFlow.getHandlers();
145         assertNotNull("transport.one/responseFlow/handlers should be non-null!",
146                       transportOne_responseFlow_handlers);
147         assertTrue("transport.one should have exactly 1 handler!",
148                 (1 == transportOne_responseFlow_handlers.length));
149
150         Handler transportOne_responseFlow_handler =
151                         transportOne_responseFlow_handlers[0];
152         assertNotNull("transport.one's handler should be non-null!",
153                       transportOne_responseFlow_handler);
154         assertTrue("transport.one's handler should be a URLMapper!",
155                     (transportOne_responseFlow_handler instanceof
156                                 org.apache.axis.handlers.http.URLMapper));
157
158         Handler transportOne_handler_byName =
159                 server.getHandler("ForwardReference");
160         assertTrue("transport.one's 'ForwardReference' should be same as directly accessed 'BR'!",
161                    (transportOne_responseFlow_handler ==
162                             transportOne_handler_byName));
163
164         TargetedChain transportTwo =
165                 (TargetedChain)server.getTransport("transport.two");
166         assertNotNull("transport.two should be non-null!", transportTwo);
167
168         Chain transportTwo_requestFlow = (Chain) transportTwo.getRequestHandler();
169         assertNotNull("transport.two/requestFlow should be non-null!",
170                       transportTwo_requestFlow);
171
172         Handler transportTwo_requestFlow_handlers[] =
173                 transportTwo_requestFlow.getHandlers();
174         assertNotNull("transport.two/requestFlow/handlers should be non-null!",
175                       transportTwo_requestFlow_handlers);
176         assertTrue("transport.two should have exactly 1 handler!",
177                 (1 == transportTwo_requestFlow_handlers.length));
178
179         Handler transportTwo_requestFlow_handler = transportTwo_requestFlow_handlers[0];
180         assertNotNull("transport.two's handler should be non-null!",
181                       transportTwo_requestFlow_handler);
182         assertTrue("transport.two's handler should be a URLMapper!",
183                     (transportTwo_requestFlow_handler instanceof
184                         org.apache.axis.handlers.http.URLMapper));
185
186         assertTrue("transport.two's 'ForwardReference' should be same as transport.one's!",
187                    (transportTwo_requestFlow_handler == transportOne_responseFlow_handler));
188     }
189 }
190
Popular Tags