001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.cxf.systest.jaxws;
019:
020: import java.lang.reflect.UndeclaredThrowableException;
021: import java.net.URL;
022: import java.util.ArrayList;
023: import java.util.Arrays;
024: import java.util.Collections;
025: import java.util.List;
026:
027: import javax.xml.namespace.QName;
028: import javax.xml.ws.Holder;
029: import javax.xml.ws.Service;
030: import javax.xml.ws.soap.SOAPBinding;
031: import javax.xml.ws.soap.SOAPFaultException;
032:
033: import org.apache.cxf.anonymous_complex_type.AnonymousComplexType;
034: import org.apache.cxf.anonymous_complex_type.AnonymousComplexTypeService;
035: import org.apache.cxf.anonymous_complex_type.RefSplitName;
036: import org.apache.cxf.anonymous_complex_type.RefSplitNameResponse;
037: import org.apache.cxf.anonymous_complex_type.SplitName;
038: import org.apache.cxf.anonymous_complex_type.SplitNameResponse.Names;
039: import org.apache.cxf.jaxb_element_test.JaxbElementTest;
040: import org.apache.cxf.jaxb_element_test.JaxbElementTest_Service;
041: import org.apache.cxf.ordered_param_holder.ComplexStruct;
042: import org.apache.cxf.ordered_param_holder.OrderedParamHolder;
043: import org.apache.cxf.ordered_param_holder.OrderedParamHolder_Service;
044: import org.apache.cxf.systest.jaxws.DocLitWrappedCodeFirstService.Foo;
045: import org.apache.cxf.tests.inherit.Inherit;
046: import org.apache.cxf.tests.inherit.InheritService;
047: import org.apache.cxf.tests.inherit.objects.SubTypeA;
048: import org.apache.cxf.tests.inherit.objects.SubTypeB;
049: import org.apache.cxf.tests.inherit.types.ObjectInfo;
050: import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
051: import org.junit.BeforeClass;
052: import org.junit.Test;
053:
054: public class ClientServerMiscTest extends
055: AbstractBusClientServerTestBase {
056:
057: @BeforeClass
058: public static void startServers() throws Exception {
059: assertTrue("server did not launch correctly",
060: launchServer(ServerMisc.class));
061: }
062:
063: @Test
064: public void testAnonymousComplexType() throws Exception {
065:
066: AnonymousComplexTypeService actService = new AnonymousComplexTypeService();
067: assertNotNull(actService);
068: QName portName = new QName(
069: "http://cxf.apache.org/anonymous_complex_type/",
070: "anonymous_complex_typeSOAP");
071: AnonymousComplexType act = actService.getPort(portName,
072: AnonymousComplexType.class);
073:
074: try {
075: Names reply = act.splitName("Tom Li");
076: assertNotNull("no response received from service", reply);
077: assertEquals("Tom", reply.getFirst());
078: assertEquals("Li", reply.getSecond());
079: } catch (UndeclaredThrowableException ex) {
080: throw (Exception) ex.getCause();
081: }
082: }
083:
084: @Test
085: public void testRefAnonymousComplexType() throws Exception {
086:
087: AnonymousComplexTypeService actService = new AnonymousComplexTypeService();
088: assertNotNull(actService);
089: QName portName = new QName(
090: "http://cxf.apache.org/anonymous_complex_type/",
091: "anonymous_complex_typeSOAP");
092: AnonymousComplexType act = actService.getPort(portName,
093: AnonymousComplexType.class);
094:
095: try {
096: SplitName name = new SplitName();
097: name.setName("Tom Li");
098: RefSplitName refName = new RefSplitName();
099: refName.setSplitName(name);
100: RefSplitNameResponse reply = act.refSplitName(refName);
101: assertNotNull("no response received from service", reply);
102: assertEquals("Tom", reply.getSplitNameResponse().getNames()
103: .getFirst());
104: assertEquals("Li", reply.getSplitNameResponse().getNames()
105: .getSecond());
106: } catch (UndeclaredThrowableException ex) {
107: throw (Exception) ex.getCause();
108: }
109: }
110:
111: @Test
112: public void testMinOccursAndNillableJAXBElement() throws Exception {
113:
114: JaxbElementTest_Service service = new JaxbElementTest_Service();
115: assertNotNull(service);
116: JaxbElementTest port = service.getPort(JaxbElementTest.class);
117:
118: try {
119:
120: String response = port.newOperation("hello");
121: assertNotNull(response);
122: assertEquals("in=hello", response);
123:
124: response = port.newOperation(null);
125: assertNotNull(response);
126: assertEquals("in=null", response);
127:
128: } catch (UndeclaredThrowableException ex) {
129: throw (Exception) ex.getCause();
130: }
131: }
132:
133: @Test
134: public void testOrderedParamHolder() throws Exception {
135: OrderedParamHolder_Service service = new OrderedParamHolder_Service();
136: OrderedParamHolder port = service.getOrderedParamHolderSOAP();
137:
138: try {
139: Holder<ComplexStruct> part3 = new Holder<ComplexStruct>();
140: part3.value = new ComplexStruct();
141: part3.value.setElem1("elem1");
142: part3.value.setElem2("elem2");
143: part3.value.setElem3(0);
144: Holder<Integer> part2 = new Holder<Integer>();
145: part2.value = 0;
146: Holder<String> part1 = new Holder<String>();
147: part1.value = "part1";
148:
149: port.orderedParamHolder(part3, part2, part1);
150:
151: assertNotNull(part3.value);
152: assertEquals("check value", "return elem1", part3.value
153: .getElem1());
154: assertEquals("check value", "return elem2", part3.value
155: .getElem2());
156: assertEquals("check value", 1, part3.value.getElem3());
157: assertNotNull(part2.value);
158: assertEquals("check value", 1, part2.value.intValue());
159: assertNotNull(part1.value);
160: assertEquals("check value", "return part1", part1.value);
161:
162: } catch (UndeclaredThrowableException ex) {
163: throw (Exception) ex.getCause();
164: }
165: }
166:
167: @Test
168: public void testStringListOutDocLitNoWsdl() throws Exception {
169: QName portName = new QName(
170: "http://cxf.apache.org/systest/jaxws/DocLitWrappedCodeFirstService",
171: "DocLitWrappedCodeFirstServicePort");
172: QName servName = new QName(
173: "http://cxf.apache.org/systest/jaxws/DocLitWrappedCodeFirstService",
174: "DocLitWrappedCodeFirstService");
175:
176: Service service = Service.create(servName);
177: service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING,
178: ServerMisc.DOCLIT_CODEFIRST_URL);
179: DocLitWrappedCodeFirstService port = service.getPort(portName,
180: DocLitWrappedCodeFirstService.class);
181: runDocLitTest(port);
182: }
183:
184: @Test
185: public void testStringListOutDocLitWsdl() throws Exception {
186: QName portName = new QName(
187: "http://cxf.apache.org/systest/jaxws/DocLitWrappedCodeFirstService",
188: "DocLitWrappedCodeFirstServicePort");
189: QName servName = new QName(
190: "http://cxf.apache.org/systest/jaxws/DocLitWrappedCodeFirstService",
191: "DocLitWrappedCodeFirstService");
192:
193: Service service = Service.create(new URL(
194: ServerMisc.DOCLIT_CODEFIRST_URL + "?wsdl"), servName);
195: DocLitWrappedCodeFirstService port = service.getPort(portName,
196: DocLitWrappedCodeFirstService.class);
197: runDocLitTest(port);
198: }
199:
200: private void runDocLitTest(DocLitWrappedCodeFirstService port)
201: throws Exception {
202: List<String> rev = new ArrayList<String>(Arrays
203: .asList(DocLitWrappedCodeFirstServiceImpl.DATA));
204: Collections.reverse(rev);
205:
206: String s;
207:
208: String arrayOut[] = port.arrayOutput();
209: assertNotNull(arrayOut);
210: assertEquals(3, arrayOut.length);
211: for (int x = 0; x < 3; x++) {
212: assertEquals(DocLitWrappedCodeFirstServiceImpl.DATA[x],
213: arrayOut[x]);
214: }
215:
216: List<String> listOut = port.listOutput();
217: assertNotNull(listOut);
218: assertEquals(3, listOut.size());
219: for (int x = 0; x < 3; x++) {
220: assertEquals(DocLitWrappedCodeFirstServiceImpl.DATA[x],
221: listOut.get(x));
222: }
223:
224: s = port.arrayInput(DocLitWrappedCodeFirstServiceImpl.DATA);
225: assertEquals("string1string2string3", s);
226: s = port.listInput(java.util.Arrays
227: .asList(DocLitWrappedCodeFirstServiceImpl.DATA));
228: assertEquals("string1string2string3", s);
229:
230: s = port.multiListInput(Arrays
231: .asList(DocLitWrappedCodeFirstServiceImpl.DATA), rev,
232: "Hello", 24);
233: assertEquals(
234: "string1string2string3string3string2string1Hello24", s);
235:
236: s = port.listInput(new ArrayList<String>());
237: assertEquals("", s);
238:
239: s = port.listInput(null);
240: assertEquals("", s);
241:
242: s = port.multiListInput(Arrays
243: .asList(DocLitWrappedCodeFirstServiceImpl.DATA), rev,
244: null, 24);
245: assertEquals(
246: "string1string2string3string3string2string1<null>24", s);
247:
248: Holder<String> a = new Holder<String>();
249: Holder<String> b = new Holder<String>("Hello");
250: Holder<String> c = new Holder<String>();
251: Holder<String> d = new Holder<String>(" ");
252: Holder<String> e = new Holder<String>("world!");
253: Holder<String> f = new Holder<String>();
254: Holder<String> g = new Holder<String>();
255: s = port.multiInOut(a, b, c, d, e, f, g);
256: assertEquals("Hello world!", s);
257: assertEquals("a", a.value);
258: assertEquals("b", b.value);
259: assertEquals("c", c.value);
260: assertEquals("d", d.value);
261: assertEquals("e", e.value);
262: assertEquals("f", f.value);
263: assertEquals("g", g.value);
264:
265: List<Foo> foos = port.listObjectOutput();
266: assertEquals(2, foos.size());
267: assertEquals("a", foos.get(0).getName());
268: assertEquals("b", foos.get(1).getName());
269:
270: List<Foo[]> foos2 = port.listObjectArrayOutput();
271: assertNotNull(foos2);
272: assertEquals(2, foos2.size());
273: assertEquals(2, foos2.get(0).length);
274: assertEquals(2, foos2.get(1).length);
275: }
276:
277: @Test
278: public void testRpcLitNoWsdl() throws Exception {
279: QName portName = new QName(
280: "http://cxf.apache.org/systest/jaxws/RpcLitCodeFirstService",
281: "RpcLitCodeFirstServicePort");
282: QName servName = new QName(
283: "http://cxf.apache.org/systest/jaxws/RpcLitCodeFirstService",
284: "RpcLitCodeFirstService");
285:
286: Service service = Service.create(servName);
287: service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING,
288: ServerMisc.RPCLIT_CODEFIRST_URL);
289: RpcLitCodeFirstService port = service.getPort(portName,
290: RpcLitCodeFirstService.class);
291: runRpcLitTest(port);
292: }
293:
294: @Test
295: public void testRpcLitWsdl() throws Exception {
296: QName portName = new QName(
297: "http://cxf.apache.org/systest/jaxws/RpcLitCodeFirstService",
298: "RpcLitCodeFirstServicePort");
299: QName servName = new QName(
300: "http://cxf.apache.org/systest/jaxws/RpcLitCodeFirstService",
301: "RpcLitCodeFirstService");
302:
303: Service service = Service.create(new URL(
304: ServerMisc.RPCLIT_CODEFIRST_URL + "?wsdl"), servName);
305: RpcLitCodeFirstService port = service.getPort(portName,
306: RpcLitCodeFirstService.class);
307: runRpcLitTest(port);
308: }
309:
310: private void runRpcLitTest(RpcLitCodeFirstService port)
311: throws Exception {
312: List<String> rev = new ArrayList<String>(Arrays
313: .asList(RpcLitCodeFirstServiceImpl.DATA));
314: Collections.reverse(rev);
315:
316: String s;
317:
318: String arrayOut[] = port.arrayOutput();
319: assertNotNull(arrayOut);
320: assertEquals(3, arrayOut.length);
321: for (int x = 0; x < 3; x++) {
322: assertEquals(RpcLitCodeFirstServiceImpl.DATA[x],
323: arrayOut[x]);
324: }
325:
326: List<String> listOut = port.listOutput();
327: assertNotNull(listOut);
328: assertEquals(3, listOut.size());
329: for (int x = 0; x < 3; x++) {
330: assertEquals(RpcLitCodeFirstServiceImpl.DATA[x], listOut
331: .get(x));
332: }
333:
334: s = port.arrayInput(RpcLitCodeFirstServiceImpl.DATA);
335: assertEquals("string1string2string3", s);
336: s = port.listInput(java.util.Arrays
337: .asList(RpcLitCodeFirstServiceImpl.DATA));
338: assertEquals("string1string2string3", s);
339:
340: s = port.multiListInput(Arrays
341: .asList(RpcLitCodeFirstServiceImpl.DATA), rev, "Hello",
342: 24);
343: assertEquals(
344: "string1string2string3string3string2string1Hello24", s);
345:
346: s = port.listInput(new ArrayList<String>());
347: assertEquals("", s);
348:
349: try {
350: s = port.listInput(null);
351: fail("RPC/Lit parts cannot be null");
352: } catch (SOAPFaultException ex) {
353: //ignore, expected
354: }
355:
356: try {
357: s = port.multiListInput(Arrays
358: .asList(RpcLitCodeFirstServiceImpl.DATA), rev,
359: null, 24);
360: fail("RPC/Lit parts cannot be null");
361: } catch (SOAPFaultException ex) {
362: //ignore, expected
363: }
364:
365: Holder<String> a = new Holder<String>();
366: Holder<String> b = new Holder<String>("Hello");
367: Holder<String> c = new Holder<String>();
368: Holder<String> d = new Holder<String>(" ");
369: Holder<String> e = new Holder<String>("world!");
370: Holder<String> f = new Holder<String>();
371: Holder<String> g = new Holder<String>();
372: s = port.multiInOut(a, b, c, d, e, f, g);
373: assertEquals("Hello world!", s);
374: assertEquals("a", a.value);
375: assertEquals("b", b.value);
376: assertEquals("c", c.value);
377: assertEquals("d", d.value);
378: assertEquals("e", e.value);
379: assertEquals("f", f.value);
380: assertEquals("g", g.value);
381:
382: a = new Holder<String>();
383: b = new Holder<String>("Hello");
384: c = new Holder<String>();
385: d = new Holder<String>(" ");
386: e = new Holder<String>("world!");
387: f = new Holder<String>();
388: g = new Holder<String>();
389: s = port.multiHeaderInOut(a, b, c, d, e, f, g);
390: assertEquals("Hello world!", s);
391: assertEquals("a", a.value);
392: assertEquals("b", b.value);
393: assertEquals("c", c.value);
394: assertEquals("d", d.value);
395: assertEquals("e", e.value);
396: assertEquals("f", f.value);
397: assertEquals("g", g.value);
398:
399: List<org.apache.cxf.systest.jaxws.RpcLitCodeFirstService.Foo> foos = port
400: .listObjectOutput();
401: assertEquals(2, foos.size());
402: assertEquals("a", foos.get(0).getName());
403: assertEquals("b", foos.get(1).getName());
404:
405: List<org.apache.cxf.systest.jaxws.RpcLitCodeFirstService.Foo[]> foos2 = port
406: .listObjectArrayOutput();
407: assertNotNull(foos2);
408: assertEquals(2, foos2.size());
409: assertEquals(2, foos2.get(0).length);
410: assertEquals(2, foos2.get(1).length);
411: }
412:
413: @Test
414: public void testInheritedTypesInOtherPackage() throws Exception {
415: InheritService serv = new InheritService();
416: Inherit port = serv.getInheritPort();
417: ObjectInfo obj = port.getObject(0);
418: assertNotNull(obj);
419: assertNotNull(obj.getBaseObject());
420: assertEquals("A", obj.getBaseObject().getName());
421: assertTrue(obj.getBaseObject() instanceof SubTypeA);
422:
423: obj = port.getObject(1);
424: assertNotNull(obj);
425: assertNotNull(obj.getBaseObject());
426: assertEquals("B", obj.getBaseObject().getName());
427: assertTrue(obj.getBaseObject() instanceof SubTypeB);
428:
429: }
430: }
|