KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > integration > EchoTest


1 /*
2  * Copyright 2004,2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.axis2.integration;
18
19 import junit.framework.TestCase;
20 import org.apache.axis2.om.OMAbstractFactory;
21 import org.apache.axis2.om.OMConstants;
22 import org.apache.axis2.om.OMNamespace;
23 import org.apache.axis2.soap.SOAPFactory;
24
25 import java.io.File JavaDoc;
26 import java.net.MalformedURLException JavaDoc;
27 import java.net.URL JavaDoc;
28 import java.net.URLClassLoader JavaDoc;
29
30 public class EchoTest extends TestCase {
31     private final SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
32     private final OMNamespace ns =
33         fac.createOMNamespace("http://apache.ws.apache.org/samples", "samples");
34     private final OMNamespace arrayNs =
35         fac.createOMNamespace(OMConstants.ARRAY_ITEM_NSURI, OMConstants.ARRAY_ITEM_NS_PREFIX);
36     private final OMNamespace targetNs = fac.createOMNamespace("http://axis.apache.org", "s");
37     private final URLClassLoader JavaDoc cl;
38
39     public EchoTest() throws MalformedURLException JavaDoc {
40         cl =
41             new URLClassLoader JavaDoc(
42                 new URL JavaDoc[] { new File JavaDoc("target/test-resources/samples/services/echo.jar").toURL()},
43                 EchoTest.class.getClassLoader());
44     }
45
46     public EchoTest(String JavaDoc arg0) throws MalformedURLException JavaDoc {
47         super(arg0);
48         cl =
49             new URLClassLoader JavaDoc(
50                 new URL JavaDoc[] { new File JavaDoc("target/test-resources/samples/services/echo.jar").toURL()},
51                 EchoTest.class.getClassLoader());
52
53     }
54
55 // private SOAPEnvelope createRawMessage(String method, OMElement parameters) {
56
// SOAPEnvelope envelope = fac.getDefaultEnvelope();
57
//
58
// OMElement responseMethodName = fac.createOMElement(method, ns);
59
// envelope.getBody().addChild(responseMethodName);
60
// responseMethodName.addChild(parameters);
61
// return envelope;
62
//
63
// }
64
//
65
// private XMLStreamReader invokeTheService(
66
// SOAPEnvelope envelope,
67
// EndpointReference targetEPR,
68
// QName opName)
69
// throws Exception {
70
//
71
// Call call = new Call();
72
// call.setTo(targetEPR);
73
// call.setTransportInfo(Constants.TRANSPORT_HTTP, Constants.TRANSPORT_HTTP, false);
74
// SOAPEnvelope responseEnv =
75
// (SOAPEnvelope) call.invokeBlocking(opName.getLocalPart(), envelope);
76
//
77
// SOAPBody body = responseEnv.getBody();
78
// if (body.hasFault()) {
79
// throw body.getFault().getException();
80
// }
81
// XMLStreamReader xpp = body.getXMLStreamReader();
82
//
83
// int event = xpp.next();
84
// while (event != XMLStreamConstants.START_ELEMENT) {
85
// event = xpp.next();
86
// }
87
// event = xpp.next();
88
// while (event != XMLStreamConstants.START_ELEMENT) {
89
// event = xpp.next();
90
// }
91
// event = xpp.next();
92
// while (event != XMLStreamConstants.START_ELEMENT) {
93
// event = xpp.next();
94
// }
95
// return xpp;
96
// }
97
//
98
// public void testEchoString() throws Exception {
99
// String message = "Hello testing";
100
// EndpointReference targetEPR =
101
// new EndpointReference(
102
// AddressingConstants.WSA_TO,
103
// "http://127.0.0.1:"
104
// + (org.apache.axis2.integration.Constants.TESTING_PORT)
105
// + "/axis/services/echo/echoString");
106
//
107
// OMElement returnelement = fac.createOMElement("param1", ns);
108
// returnelement.setBuilder(
109
// new ObjectToOMBuilder(returnelement, new SimpleTypeEncoder(message)));
110
// returnelement.declareNamespace(arrayNs);
111
// SOAPEnvelope envelope = createRawMessage("echoString", returnelement);
112
// XMLStreamReader xpp = invokeTheService(envelope, targetEPR, new QName("echoString"));
113
// String value = SimpleTypeEncodingUtils.deserializeString(xpp);
114
// assertEquals(value, message);
115
// }
116
//
117
// public void testEchoStringArray() throws Exception {
118
// String[] messages =
119
// new String[] {
120
// "Hello testing1",
121
// "Hello testing2",
122
// "Hello testing3",
123
// "Hello testing4",
124
// "Hello testing5" };
125
//
126
// EndpointReference targetEPR =
127
// new EndpointReference(
128
// AddressingConstants.WSA_TO,
129
// "http://127.0.0.1:"
130
// + (org.apache.axis2.integration.Constants.TESTING_PORT)
131
// + "/axis/services/echo/echoStringArray");
132
//
133
// OMElement returnelement = fac.createOMElement("param1", ns);
134
//
135
// ObjectToOMBuilder builder =
136
// new ObjectToOMBuilder(
137
// returnelement,
138
// new ArrayTypeEncoder(messages, new SimpleTypeEncoder(null)));
139
//
140
// returnelement.setBuilder(builder);
141
// returnelement.declareNamespace(arrayNs);
142
// SOAPEnvelope envelope = createRawMessage("echoStringArray", returnelement);
143
//
144
// XMLStreamReader xpp = invokeTheService(envelope, targetEPR, new QName("echoStringArray"));
145
// String[] values = SimpleTypeEncodingUtils.deserializeStringArray(xpp);
146
// for (int i = 0; i < values.length; i++) {
147
// assertEquals(values[i], messages[i]);
148
// }
149
// }
150

151     public void testEchoStruct() throws Exception JavaDoc {
152 // EndpointReference targetEPR =
153
// new EndpointReference(
154
// AddressingConstants.WSA_TO,
155
// "http://127.0.0.1:"
156
// + (org.apache.axis2.integration.Constants.TESTING_PORT)
157
// + "/axis/services/echo/echoEchoStruct");
158
//
159
// String[] messages =
160
// new String[] {
161
// "Hello testing1",
162
// "Hello testing2",
163
// "Hello testing3",
164
// "Hello testing4",
165
// "Hello testing5" };
166
// Class clasname = Class.forName("encoding.sample1.EchoStruct", true, cl);
167
// Object obj = clasname.newInstance();
168
//
169
// Method method1 = clasname.getMethod("setValue1", new Class[] { String.class });
170
// method1.invoke(obj, new Object[] { "Ruy Lopez" });
171
// Method method2 = clasname.getMethod("setValue2", new Class[] { String.class });
172
// method2.invoke(obj, new Object[] { "Kings Gambit" });
173
// Method method3 = clasname.getMethod("setValue3", new Class[] { int.class });
174
// method3.invoke(obj, new Object[] { new Integer(345)});
175
// Method method4 = clasname.getMethod("setValue4", new Class[] { String.class });
176
// method4.invoke(obj, new Object[] { "Kings Indian Defence" });
177
// Method method5 = clasname.getMethod("setValue5", new Class[] { String.class });
178
// method5.invoke(obj, new Object[] { "Musio Gambit" });
179
// Method method6 = clasname.getMethod("setValue6", new Class[] { String.class });
180
// method6.invoke(obj, new Object[] { "Benko Gambit" });
181
// Method method7 = clasname.getMethod("setValue7", new Class[] { String.class });
182
// method7.invoke(obj, new Object[] { "Secillian Defance" });
183
// Method method8 = clasname.getMethod("setValue8", new Class[] { String.class });
184
// method8.invoke(obj, new Object[] { "Queens Gambit" });
185
// Method method9 = clasname.getMethod("setValue9", new Class[] { String.class });
186
// method9.invoke(obj, new Object[] { "Queens Indian Defense" });
187
// Method method10 = clasname.getMethod("setValue10", new Class[] { String.class });
188
// method10.invoke(obj, new Object[] { "Alekine's Defense" });
189
// Method method11 = clasname.getMethod("setValue11", new Class[] { String.class });
190
// method11.invoke(obj, new Object[] { "Perc Defense" });
191
// Method method12 = clasname.getMethod("setValue12", new Class[] { String.class });
192
// method12.invoke(obj, new Object[] { "Scotch Gambit" });
193
// Method method13 = clasname.getMethod("setValue13", new Class[] { String.class });
194
// method13.invoke(obj, new Object[] { "English Opening" });
195
//
196
// OMElement returnelement = fac.createOMElement("param1", ns);
197
//
198
// Class encoderClass = Class.forName("encoding.sample1.EchoStructEncoder", true, cl);
199
// Constructor constCt = encoderClass.getConstructor(new Class[] { clasname });
200
// Object obj1 = constCt.newInstance(new Object[] { obj });
201
//
202
// ObjectToOMBuilder builder = new ObjectToOMBuilder(returnelement, (Encoder) obj1);
203
//
204
// returnelement.setBuilder(builder);
205
// returnelement.declareNamespace(
206
// OMConstants.ARRAY_ITEM_NSURI,
207
// OMConstants.ARRAY_ITEM_NS_PREFIX);
208
// returnelement.declareNamespace(targetNs);
209
//
210
// SOAPEnvelope envelope = createRawMessage("echoEchoStruct", returnelement);
211
//
212
// XMLStreamReader xpp = invokeTheService(envelope, targetEPR, new QName("echoEchoStruct"));
213
//
214
// Method deserializeMethod =
215
// encoderClass.getMethod("deSerialize", new Class[] { XMLStreamReader.class });
216
// Object result = deserializeMethod.invoke(obj1, new Object[] { xpp });
217
// assertTrue(result.equals(obj));
218
}
219
220 // public void testEchoStructArray() throws Exception {
221
// EndpointReference targetEPR =
222
// new EndpointReference(
223
// AddressingConstants.WSA_TO,
224
// "http://127.0.0.1:"
225
// + (org.apache.axis2.integration.Constants.TESTING_PORT)
226
// + "/axis/services/echo/echoEchoStructArray");
227
//
228
// Object[] objs = new Object[10];
229
// Class clasname = Class.forName("encoding.sample1.EchoStruct", true, cl);
230
//
231
// for (int i = 0; i < objs.length; i++) {
232
//
233
// objs[i] = clasname.newInstance();
234
// Method method1 = clasname.getMethod("setValue1", new Class[] { String.class });
235
// method1.invoke(objs[i], new Object[] { "Ruy Lopez" });
236
// Method method2 = clasname.getMethod("setValue2", new Class[] { String.class });
237
// method2.invoke(objs[i], new Object[] { "Kings Gambit" });
238
// Method method3 = clasname.getMethod("setValue3", new Class[] { int.class });
239
// method3.invoke(objs[i], new Object[] { new Integer(345)});
240
// Method method4 = clasname.getMethod("setValue4", new Class[] { String.class });
241
// method4.invoke(objs[i], new Object[] { "Kings Indian Defence" });
242
// Method method5 = clasname.getMethod("setValue5", new Class[] { String.class });
243
// method5.invoke(objs[i], new Object[] { "Musio Gambit" });
244
// Method method6 = clasname.getMethod("setValue6", new Class[] { String.class });
245
// method6.invoke(objs[i], new Object[] { "Benko Gambit" });
246
// Method method7 = clasname.getMethod("setValue7", new Class[] { String.class });
247
// method7.invoke(objs[i], new Object[] { "Secillian Defance" });
248
// Method method8 = clasname.getMethod("setValue8", new Class[] { String.class });
249
// method8.invoke(objs[i], new Object[] { "Queens Gambit" });
250
// Method method9 = clasname.getMethod("setValue9", new Class[] { String.class });
251
// method9.invoke(objs[i], new Object[] { "Queens Indian Defense" });
252
// Method method10 = clasname.getMethod("setValue10", new Class[] { String.class });
253
// method10.invoke(objs[i], new Object[] { "Alekine's Defense" });
254
// Method method11 = clasname.getMethod("setValue11", new Class[] { String.class });
255
// method11.invoke(objs[i], new Object[] { "Perc Defense" });
256
// Method method12 = clasname.getMethod("setValue12", new Class[] { String.class });
257
// method12.invoke(objs[i], new Object[] { "Scotch Gambit" });
258
// Method method13 = clasname.getMethod("setValue13", new Class[] { String.class });
259
// method13.invoke(objs[i], new Object[] { "English Opening" });
260
// }
261
//
262
// OMElement returnelement = fac.createOMElement("param1", ns);
263
//
264
// Class encoderClass = Class.forName("encoding.sample1.EchoStructEncoder", true, cl);
265
// Constructor constCt = encoderClass.getConstructor(new Class[] { clasname });
266
// Object obj1 = constCt.newInstance(new Object[] { null });
267
//
268
// ObjectToOMBuilder builder =
269
// new ObjectToOMBuilder(returnelement, new ArrayTypeEncoder(objs, (Encoder) obj1));
270
//
271
// returnelement.setBuilder(builder);
272
// returnelement.declareNamespace(arrayNs);
273
// returnelement.declareNamespace(targetNs);
274
//
275
// SOAPEnvelope envelope = createRawMessage("echoEchoStructArray", returnelement);
276
//
277
// XMLStreamReader xpp =
278
// invokeTheService(envelope, targetEPR, new QName("echoEchoStructArray"));
279
//
280
// Encoder enc = new ArrayTypeEncoder(objs, (Encoder) obj1);
281
//
282
// Method deserializeMethod =
283
// encoderClass.getMethod("deSerialize", new Class[] { XMLStreamReader.class });
284
// Object obj = enc.deSerialize(xpp);
285
// Object[] structs = (Object[]) obj;
286
//
287
// for (int i = 0; i < structs.length; i++) {
288
// assertTrue(structs[i].equals(objs[i]));
289
//
290
// }
291
//
292
// }
293
//
294
// protected void setUp() throws Exception {
295
// UtilServer.start();
296
// }
297
//
298
// protected void tearDown() throws Exception {
299
// UtilServer.stop();
300
// }
301
}
302
Popular Tags