001: /*
002: * The Apache Software License, Version 1.1
003: *
004: *
005: * Copyright (c) 2002 The Apache Software Foundation. All rights
006: * reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: *
012: * 1. Redistributions of source code must retain the above copyright
013: * notice, this list of conditions and the following disclaimer.
014: *
015: * 2. Redistributions in binary form must reproduce the above copyright
016: * notice, this list of conditions and the following disclaimer in
017: * the documentation and/or other materials provided with the
018: * distribution.
019: *
020: * 3. The end-user documentation included with the redistribution,
021: * if any, must include the following acknowledgment:
022: * "This product includes software developed by the
023: * Apache Software Foundation (http://www.apache.org/)."
024: * Alternately, this acknowledgment may appear in the software itself,
025: * if and wherever such third-party acknowledgments normally appear.
026: *
027: * 4. The names "WSIF" and "Apache Software Foundation" must
028: * not be used to endorse or promote products derived from this
029: * software without prior written permission. For written
030: * permission, please contact apache@apache.org.
031: *
032: * 5. Products derived from this software may not be called "Apache",
033: * nor may "Apache" appear in their name, without prior written
034: * permission of the Apache Software Foundation.
035: *
036: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
037: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
038: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
039: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
040: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
041: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
042: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
043: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
044: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
045: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
046: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
047: * SUCH DAMAGE.
048: * ====================================================================
049: *
050: * This software consists of voluntary contributions made by many
051: * individuals on behalf of the Apache Software Foundation and was
052: * originally based on software copyright (c) 2001, 2002, International
053: * Business Machines, Inc., http://www.apache.org. For more
054: * information on the Apache Software Foundation, please see
055: * <http://www.apache.org/>.
056: */
057:
058: package interop;
059:
060: import interop.wsifserviceWrapped.ArrayOfSimpleDocument;
061: import interop.wsifserviceWrapped.ChildDocument;
062: import interop.wsifserviceWrapped.ComplexDocumentResponse;
063: import interop.wsifserviceWrapped.ComplexDocument_ElemType;
064: import interop.wsifserviceWrapped.ComplexDocument_Type;
065: import interop.wsifserviceWrapped.Doc_TestPortType;
066: import interop.wsifserviceWrapped.SimpleDocument_ElemType;
067: import interop.wsifserviceWrapped.SimpleDocument_Type;
068: import interop.wsifserviceWrapped.SingleTagResponse;
069: import interop.wsifserviceWrapped.SingleTag_ElemType;
070: import interop.wsifserviceWrapped.SingleTag_Type;
071: import interop.wsifserviceWrapped.SimpleDocumentResponse;
072: import java.io.StringWriter;
073:
074: import junit.framework.Test;
075: import junit.framework.TestCase;
076: import junit.framework.TestSuite;
077:
078: import org.apache.wsif.WSIFException;
079: import org.apache.wsif.WSIFMessage;
080: import org.apache.wsif.WSIFOperation;
081: import org.apache.wsif.WSIFPort;
082: import org.apache.wsif.WSIFService;
083: import org.apache.wsif.WSIFServiceFactory;
084: import org.apache.xml.serialize.OutputFormat;
085: import org.apache.xml.serialize.XMLSerializer;
086: import org.w3c.dom.Element;
087: import util.TestUtilities;
088:
089: /**
090: * Junit test to test out the AXIS provider docstyle support using wrapped parts
091: *
092: * This test is part of the SOAP Builders interoperability testing
093: * effort described at http://www.whitemesa.net/. The WSDL is
094: * available online at http://www.whitemesa.net/wsdl/interopdoc.wsdl
095: *
096: * @author Ant Elder <ant.elder@uk.ibm.com>
097: */
098: public class InteropDocWrappedTest extends TestCase {
099:
100: String wsdlLocation = TestUtilities
101: .getWsdlPath("java\\test\\interop\\wsifservice")
102: + "interopdoc.wsdl";
103:
104: // + "interopdocLocal.wsdl";
105: // "http://www.whitemesa.net/wsdl/interopdoc.wsdl";
106:
107: public InteropDocWrappedTest(String name) {
108: super (name);
109: }
110:
111: public static void main(String[] args) {
112: // TestUtilities.startListeners(
113: // TestUtilities.ADDRESSBOOK_LISTENER
114: // | TestUtilities.ASYNC_LISTENER
115: // | TestUtilities.NATIVEJMS_LISTENER);
116: junit.textui.TestRunner.run(suite());
117: // TestUtilities.stopListeners();
118: }
119:
120: public static Test suite() {
121: return new TestSuite(InteropDocWrappedTest.class);
122: }
123:
124: public void setUp() {
125: TestUtilities.setUpExtensionsAndProviders();
126: }
127:
128: public void testSingleTagDII() {
129: doitSingleTagDII("interopDocPort", "axis");
130: }
131:
132: public void testSimpleDocumentDII() {
133: doitSimpleDocumentDII("interopDocPort", "axis");
134: }
135:
136: public void testComplexDocumentDII() {
137: doitComplexDocumentDII("interopDocPort", "axis");
138: }
139:
140: public void testSingleTagStub() {
141: doitSingleTagStub("interopDocPort", "axis");
142: }
143:
144: public void testSimpleDocumentStub() {
145: doitSimpleDocumentStub("interopDocPort", "axis");
146: }
147:
148: public void testComplexDocumentStub() {
149: doitComplexDocumentStub("interopDocPort", "axis");
150: }
151:
152: private void doitSingleTagDII(String portName, String protocol) {
153: if (portName.toUpperCase().indexOf("JMS") != -1
154: && !TestUtilities.areWeTesting("jms"))
155: return;
156:
157: TestUtilities.setProviderForProtocol(protocol);
158:
159: try {
160: WSIFServiceFactory factory = WSIFServiceFactory
161: .newInstance();
162: WSIFService service = factory.getService(wsdlLocation,
163: null, null, "http://soapinterop.org/",
164: "Doc_TestPortType");
165:
166: service.mapType(new javax.xml.namespace.QName(
167: "http://soapinterop.org/", ">SingleTag"),
168: SingleTag_ElemType.class);
169: service.mapType(new javax.xml.namespace.QName(
170: "http://soapinterop.org/", "SingleTag"),
171: SingleTag_Type.class);
172: service.mapType(new javax.xml.namespace.QName(
173: "http://soapinterop.org/", "SingleTagResponse"),
174: SingleTagResponse.class);
175:
176: WSIFPort port = service.getPort(portName);
177:
178: WSIFOperation operation = port.createOperation("SingleTag");
179:
180: WSIFMessage inMsg = operation.createInputMessage();
181: WSIFMessage outMsg = operation.createOutputMessage();
182: WSIFMessage faultMsg = operation.createFaultMessage();
183:
184: SingleTag_ElemType stet = new SingleTag_ElemType();
185: stet.setSingleTag(new SingleTag_Type());
186:
187: inMsg.setObjectPart("parameters", stet);
188:
189: boolean ok = operation.executeRequestResponseOperation(
190: inMsg, outMsg, faultMsg);
191:
192: assertTrue("operation returned false!!", ok);
193:
194: Object o = null;
195: try {
196: o = outMsg.getObjectPart("outputDoc");
197: assertTrue("response is null!!!", o != null);
198: } catch (WSIFException e) {
199: assertTrue(
200: "response part 'outputDoc' not found in output message!!!",
201: false);
202: }
203: assertTrue("response part has wrong type: " + o.getClass(),
204: SingleTagResponse.class.isAssignableFrom(o
205: .getClass()));
206:
207: SingleTagResponse response = (SingleTagResponse) o;
208: assertNotNull("response singleTag is null!!!", response
209: .getSingleTag());
210:
211: } catch (Exception ex) {
212: ex.printStackTrace();
213: assertTrue("InteropDocTest.doitSingleTagDII(" + portName
214: + ") caught exception " + ex.getLocalizedMessage(),
215: false);
216: }
217: }
218:
219: private void doitSimpleDocumentDII(String portName, String protocol) {
220: if (portName.toUpperCase().indexOf("JMS") != -1
221: && !TestUtilities.areWeTesting("jms"))
222: return;
223:
224: TestUtilities.setProviderForProtocol(protocol);
225:
226: try {
227: WSIFServiceFactory factory = WSIFServiceFactory
228: .newInstance();
229: WSIFService service = factory.getService(wsdlLocation,
230: null, null, "http://soapinterop.org/",
231: "Doc_TestPortType");
232:
233: service.mapPackage("http://soapinterop.org/",
234: "interop.wsifserviceWrapped");
235: service.mapType(new javax.xml.namespace.QName(
236: "http://soapinterop.org/", ">SimpleDocument"),
237: SimpleDocument_ElemType.class);
238: service.mapType(new javax.xml.namespace.QName(
239: "http://soapinterop.org/", "SimpleDocument"),
240: SimpleDocument_Type.class);
241: service.mapType(
242: new javax.xml.namespace.QName(
243: "http://soapinterop.org/",
244: "SimpleDocumentResponse"),
245: SimpleDocumentResponse.class);
246:
247: WSIFPort port = service.getPort(portName);
248:
249: WSIFOperation operation = port
250: .createOperation("SimpleDocument");
251:
252: WSIFMessage inMsg = operation.createInputMessage();
253: WSIFMessage outMsg = operation.createOutputMessage();
254: WSIFMessage faultMsg = operation.createFaultMessage();
255:
256: SimpleDocument_ElemType sdtet = new SimpleDocument_ElemType();
257: SimpleDocument_Type sdt = new SimpleDocument_Type();
258: sdt.setValue("petra");
259: sdtet.setSimpleDocument(sdt);
260:
261: inMsg.setObjectPart("parameters", sdtet);
262:
263: boolean ok = operation.executeRequestResponseOperation(
264: inMsg, outMsg, faultMsg);
265:
266: assertTrue("operation returned false!!", ok);
267:
268: Object o = null;
269: try {
270: o = outMsg.getObjectPart("outputDoc");
271: assertTrue("response is null!!!", o != null);
272: } catch (WSIFException e) {
273: assertTrue(
274: "response part 'outputDoc' not found in output message!!!",
275: false);
276: }
277: assertTrue("response part has wrong type: " + o.getClass(),
278: SimpleDocumentResponse.class.isAssignableFrom(o
279: .getClass()));
280:
281: SimpleDocumentResponse response = (SimpleDocumentResponse) o;
282: SimpleDocument_Type sdtResponse = response
283: .getSimpleDocument();
284: assertNotNull("response SimpleDocument is null!!!",
285: sdtResponse);
286:
287: assertTrue("document value wrong: "
288: + sdtResponse.getValue(), sdt.getValue().equals(
289: sdtResponse.getValue()));
290:
291: } catch (Exception ex) {
292: ex.printStackTrace();
293: assertTrue("InteropDocTest.doitSimpleDocumentDII("
294: + portName + ") caught exception "
295: + ex.getLocalizedMessage(), false);
296: }
297: }
298:
299: private void doitComplexDocumentDII(String portName, String protocol) {
300: if (portName.toUpperCase().indexOf("JMS") != -1
301: && !TestUtilities.areWeTesting("jms"))
302: return;
303:
304: TestUtilities.setProviderForProtocol(protocol);
305:
306: try {
307: WSIFServiceFactory factory = WSIFServiceFactory
308: .newInstance();
309: WSIFService service = factory.getService(wsdlLocation,
310: null, null, "http://soapinterop.org/",
311: "Doc_TestPortType");
312:
313: service.mapPackage("http://soapinterop.org/",
314: "interop.wsifserviceWrapped");
315:
316: service.mapType(new javax.xml.namespace.QName(
317: "http://soapinterop.org/", ">ComplexDocument"),
318: ComplexDocument_ElemType.class);
319: service.mapType(new javax.xml.namespace.QName(
320: "http://soapinterop.org/", "ComplexDocument"),
321: ComplexDocument_Type.class);
322: service.mapType(
323: new javax.xml.namespace.QName(
324: "http://soapinterop.org/",
325: "ArrayOfSimpleDocument"),
326: ArrayOfSimpleDocument.class);
327: service.mapType(new javax.xml.namespace.QName(
328: "http://soapinterop.org/", "SimpleDocument"),
329: SimpleDocument_Type.class);
330: service.mapType(new javax.xml.namespace.QName(
331: "http://soapinterop.org/", "ChildDocument"),
332: ChildDocument.class);
333: service.mapType(new javax.xml.namespace.QName(
334: "http://soapinterop.org/",
335: "ComplexDocumentResponse"),
336: ComplexDocumentResponse.class);
337:
338: WSIFPort port = service.getPort(portName);
339:
340: WSIFOperation operation = port
341: .createOperation("ComplexDocument");
342:
343: WSIFMessage inMsg = operation.createInputMessage();
344: WSIFMessage outMsg = operation.createOutputMessage();
345: WSIFMessage faultMsg = operation.createFaultMessage();
346:
347: ComplexDocument_ElemType cdtet = new ComplexDocument_ElemType();
348: ComplexDocument_Type cdt = makeComplexDocument();
349: checkComplexDocument(cdt);
350: cdtet.setComplexDocument(cdt);
351:
352: inMsg.setObjectPart("parameters", cdtet);
353:
354: boolean ok = operation.executeRequestResponseOperation(
355: inMsg, outMsg, faultMsg);
356:
357: assertTrue("operation returned false!!", ok);
358:
359: Object o = null;
360: try {
361: o = outMsg.getObjectPart("outputDoc");
362: assertTrue("response is null!!!", o != null);
363: } catch (WSIFException e) {
364: assertTrue(
365: "response part 'outputDoc' not found in output message!!!",
366: false);
367: }
368: assertTrue("response part has wrong type: " + o.getClass(),
369: ComplexDocumentResponse.class.isAssignableFrom(o
370: .getClass()));
371:
372: ComplexDocumentResponse response = (ComplexDocumentResponse) o;
373: ComplexDocument_Type cdtResponse = response
374: .getComplexDocument();
375: assertNotNull("response ComplexDocument is null!!!",
376: cdtResponse);
377:
378: checkComplexDocument(cdtResponse);
379:
380: } catch (Exception ex) {
381: ex.printStackTrace();
382: assertTrue("InteropDocTest.doitComplexDocumentDII("
383: + portName + ") caught exception "
384: + ex.getLocalizedMessage(), false);
385: }
386: }
387:
388: private void doitSingleTagStub(String portName, String protocol) {
389: if (portName.toUpperCase().indexOf("JMS") != -1
390: && !TestUtilities.areWeTesting("jms"))
391: return;
392:
393: TestUtilities.setProviderForProtocol(protocol);
394:
395: try {
396: WSIFServiceFactory factory = WSIFServiceFactory
397: .newInstance();
398: WSIFService service = factory.getService(wsdlLocation,
399: null, null, "http://soapinterop.org/",
400: "Doc_TestPortType");
401:
402: service.mapPackage("http://soapinterop.org/",
403: "interop.wsifserviceWrapped");
404:
405: service.mapType(new javax.xml.namespace.QName(
406: "http://soapinterop.org/", ">SingleTag"),
407: SingleTag_ElemType.class);
408: service.mapType(new javax.xml.namespace.QName(
409: "http://soapinterop.org/", "SingleTag"),
410: SingleTag_Type.class);
411: service.mapType(new javax.xml.namespace.QName(
412: "http://soapinterop.org/", "SingleTagResponse"),
413: SingleTagResponse.class);
414:
415: Doc_TestPortType stub = (Doc_TestPortType) service.getStub(
416: portName, Doc_TestPortType.class);
417:
418: SingleTag_ElemType stet = new SingleTag_ElemType();
419: stet.setSingleTag(new SingleTag_Type());
420:
421: SingleTagResponse response = stub.singleTag(stet);
422:
423: assertNotNull("response is null!!!", response);
424: assertNotNull("response singleTag is null!!!", response
425: .getSingleTag());
426:
427: } catch (Exception ex) {
428: ex.printStackTrace();
429: assertTrue("InteropDocTest.doitSingleTagDII(" + portName
430: + ") caught exception " + ex.getLocalizedMessage(),
431: false);
432: }
433: }
434:
435: private void doitSimpleDocumentStub(String portName, String protocol) {
436: if (portName.toUpperCase().indexOf("JMS") != -1
437: && !TestUtilities.areWeTesting("jms"))
438: return;
439:
440: TestUtilities.setProviderForProtocol(protocol);
441:
442: try {
443: WSIFServiceFactory factory = WSIFServiceFactory
444: .newInstance();
445: WSIFService service = factory.getService(wsdlLocation,
446: null, null, "http://soapinterop.org/",
447: "Doc_TestPortType");
448:
449: service.mapPackage("http://soapinterop.org/",
450: "interop.wsifserviceWrapped");
451:
452: service.mapType(new javax.xml.namespace.QName(
453: "http://soapinterop.org/", ">SimpleDocument"),
454: SimpleDocument_ElemType.class);
455: service.mapType(new javax.xml.namespace.QName(
456: "http://soapinterop.org/", "SimpleDocument"),
457: SimpleDocument_Type.class);
458: service.mapType(
459: new javax.xml.namespace.QName(
460: "http://soapinterop.org/",
461: "SimpleDocumentResponse"),
462: SimpleDocumentResponse.class);
463:
464: Doc_TestPortType stub = (Doc_TestPortType) service.getStub(
465: portName, Doc_TestPortType.class);
466:
467: SimpleDocument_ElemType sdtet = new SimpleDocument_ElemType();
468: SimpleDocument_Type sdt = new SimpleDocument_Type();
469: sdt.setValue("petra");
470: sdtet.setSimpleDocument(sdt);
471:
472: SimpleDocumentResponse response = stub
473: .simpleDocument(sdtet);
474:
475: assertNotNull("response is null!!!", response);
476:
477: SimpleDocument_Type sdtResponse = response
478: .getSimpleDocument();
479: assertNotNull("response simpleDocument is null!!!",
480: sdtResponse);
481:
482: assertTrue("simpleDocument value wrong: "
483: + sdtResponse.getValue(), sdt.getValue().equals(
484: sdtResponse.getValue()));
485:
486: } catch (Exception ex) {
487: ex.printStackTrace();
488: assertTrue("InteropDocTest.doitSimpleDocumentDII("
489: + portName + ") caught exception "
490: + ex.getLocalizedMessage(), false);
491: }
492: }
493:
494: private void doitComplexDocumentStub(String portName,
495: String protocol) {
496: if (portName.toUpperCase().indexOf("JMS") != -1
497: && !TestUtilities.areWeTesting("jms"))
498: return;
499:
500: TestUtilities.setProviderForProtocol(protocol);
501:
502: try {
503: WSIFServiceFactory factory = WSIFServiceFactory
504: .newInstance();
505: WSIFService service = factory.getService(wsdlLocation,
506: null, null, "http://soapinterop.org/",
507: "Doc_TestPortType");
508:
509: service.mapPackage("http://soapinterop.org/",
510: "interop.wsifserviceWrapped");
511:
512: service.mapType(new javax.xml.namespace.QName(
513: "http://soapinterop.org/", ">ComplexDocument"),
514: ComplexDocument_ElemType.class);
515: service.mapType(new javax.xml.namespace.QName(
516: "http://soapinterop.org/", "ComplexDocument"),
517: ComplexDocument_Type.class);
518: service.mapType(
519: new javax.xml.namespace.QName(
520: "http://soapinterop.org/",
521: "ArrayOfSimpleDocument"),
522: ArrayOfSimpleDocument.class);
523: service.mapType(new javax.xml.namespace.QName(
524: "http://soapinterop.org/", "SimpleDocument"),
525: SimpleDocument_Type.class);
526: service.mapType(new javax.xml.namespace.QName(
527: "http://soapinterop.org/", "ChildDocument"),
528: ChildDocument.class);
529: service.mapType(new javax.xml.namespace.QName(
530: "http://soapinterop.org/",
531: "ComplexDocumentResponse"),
532: ComplexDocumentResponse.class);
533:
534: Doc_TestPortType stub = (Doc_TestPortType) service.getStub(
535: portName, Doc_TestPortType.class);
536:
537: ComplexDocument_ElemType cdtet = new ComplexDocument_ElemType();
538: ComplexDocument_Type cdt = makeComplexDocument();
539: checkComplexDocument(cdt);
540: cdtet.setComplexDocument(cdt);
541:
542: ComplexDocumentResponse response = stub
543: .complexDocument(cdtet);
544: assertNotNull("response is null!!!", response);
545:
546: ComplexDocument_Type cdtResponse = response
547: .getComplexDocument();
548: assertNotNull("response complexDocument is null!!!",
549: cdtResponse);
550:
551: checkComplexDocument(cdtResponse);
552:
553: } catch (Exception ex) {
554: ex.printStackTrace();
555: assertTrue("InteropDocTest.doitComplexDocumentDII("
556: + portName + ") caught exception "
557: + ex.getLocalizedMessage(), false);
558: }
559: }
560:
561: private ComplexDocument_Type makeComplexDocument() {
562:
563: ComplexDocument_Type cdt = new ComplexDocument_Type();
564:
565: ArrayOfSimpleDocument asd = new ArrayOfSimpleDocument();
566: SimpleDocument_Type[] adt = new SimpleDocument_Type[2];
567: adt[0] = new SimpleDocument_Type("petra");
568: adt[1] = new SimpleDocument_Type("ant");
569: asd.setSimpleDocument(adt);
570: cdt.setSimpleDoc(asd);
571:
572: ChildDocument cd = new ChildDocument();
573: asd = new ArrayOfSimpleDocument();
574: adt = new SimpleDocument_Type[1];
575: adt[0] = new SimpleDocument_Type("sue");
576: asd.setSimpleDocument(adt);
577: cd.setChildSimpleDoc(asd);
578: cdt.setChild(cd);
579:
580: cdt.setAnAttribute("together");
581:
582: return cdt;
583: }
584:
585: private void checkComplexDocument(ComplexDocument_Type cdt) {
586:
587: ArrayOfSimpleDocument asd = cdt.getSimpleDoc();
588: assertTrue("asd is null!!!", asd != null);
589: SimpleDocument_Type[] adt = asd.getSimpleDocument();
590:
591: boolean b = "petra".equals(adt[0]);
592:
593: assertTrue("adt is null!!!", adt != null);
594: assertTrue("adt length not 2, is: " + adt.length,
595: adt.length == 2);
596: assertTrue("child adt[0] not 'petra', is: " + adt[0], "petra"
597: .equals(adt[0].getValue()));
598: assertTrue("child adt[1] not 'ant', is: " + adt[0], "ant"
599: .equals(adt[1].getValue()));
600:
601: ChildDocument cd = cdt.getChild();
602: asd = cd.getChildSimpleDoc();
603: assertTrue("child asd is null!!!", asd != null);
604: adt = asd.getSimpleDocument();
605: assertTrue("child adt is null!!!", adt != null);
606: assertTrue("child adt length not 1, is: " + adt.length,
607: adt.length == 1);
608: assertTrue("child adt[0] not 'sue', is: " + adt[0], "sue"
609: .equals(adt[0].getValue()));
610:
611: String s = cdt.getAnAttribute();
612: assertTrue("attribute not 'together' is: " + s, "together"
613: .equals(s));
614:
615: }
616:
617: }
|