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.wsifservice.ArrayOfSimpleDocument;
061: import interop.wsifservice.ChildDocument;
062: import interop.wsifservice.ComplexDocument_Type;
063: import interop.wsifservice.Doc_TestPortType;
064: import interop.wsifservice.SimpleDocument_Type;
065: import interop.wsifservice.SingleTag_Type;
066:
067: import junit.framework.Test;
068: import junit.framework.TestCase;
069: import junit.framework.TestSuite;
070:
071: import org.apache.wsif.WSIFConstants;
072: import org.apache.wsif.WSIFException;
073: import org.apache.wsif.WSIFMessage;
074: import org.apache.wsif.WSIFOperation;
075: import org.apache.wsif.WSIFPort;
076: import org.apache.wsif.WSIFService;
077: import org.apache.wsif.WSIFServiceFactory;
078: import util.TestUtilities;
079:
080: /**
081: * Junit test to test out the AXIS provider docstyle support
082: *
083: * This test is part of the SOAP Builders interoperability testing
084: * effort described at http://www.whitemesa.net/. The WSDL is
085: * available online at http://www.whitemesa.net/wsdl/interopdoc.wsdl
086: *
087: * TODO: tests using stubs (see bugzilla 15780)
088: * TODO: tests using messaging
089: *
090: * @author Ant Elder <ant.elder@uk.ibm.com>
091: */
092: public class InteropDocTest extends TestCase {
093:
094: String wsdlLocation = TestUtilities
095: .getWsdlPath("java\\test\\interop\\wsifservice")
096: + "interopdoc.wsdl";
097:
098: // + "interopdocLocal.wsdl";
099: // "http://www.whitemesa.net/wsdl/interopdoc.wsdl";
100:
101: public InteropDocTest(String name) {
102: super (name);
103: }
104:
105: public static void main(String[] args) {
106: // TestUtilities.startListeners(
107: // TestUtilities.ADDRESSBOOK_LISTENER
108: // | TestUtilities.ASYNC_LISTENER
109: // | TestUtilities.NATIVEJMS_LISTENER);
110: junit.textui.TestRunner.run(suite());
111: // TestUtilities.stopListeners();
112: }
113:
114: public static Test suite() {
115: return new TestSuite(InteropDocTest.class);
116: }
117:
118: public void setUp() {
119: TestUtilities.setUpExtensionsAndProviders();
120: }
121:
122: public void testSingleTagDII() {
123: doitSingleTagDII("interopDocPort", "axis");
124: }
125:
126: public void testSimpleDocumentDII() {
127: doitSimpleDocumentDII("interopDocPort", "axis");
128: }
129:
130: public void testComplexDocumentDII() {
131: doitComplexDocumentDII("interopDocPort", "axis");
132: }
133:
134: public void testSingleTagStub() {
135: doitSingleTagStub("interopDocPort", "axis");
136: }
137:
138: public void testSimpleDocumentStub() {
139: doitSimpleDocumentStub("interopDocPort", "axis");
140: }
141:
142: public void testComplexDocumentStub() {
143: doitComplexDocumentStub("interopDocPort", "axis");
144: }
145:
146: private void doitSingleTagDII(String portName, String protocol) {
147: if (portName.toUpperCase().indexOf("JMS") != -1
148: && !TestUtilities.areWeTesting("jms"))
149: return;
150:
151: TestUtilities.setProviderForProtocol(protocol);
152:
153: try {
154: WSIFServiceFactory factory = WSIFServiceFactory
155: .newInstance();
156: WSIFService service = factory.getService(wsdlLocation,
157: null, null, "http://soapinterop.org/",
158: "Doc_TestPortType");
159:
160: service.mapType(new javax.xml.namespace.QName(
161: "http://soapinterop.org/", "SingleTag"),
162: SingleTag_Type.class);
163:
164: WSIFPort port = service.getPort(portName);
165:
166: WSIFOperation operation = port.createOperation("SingleTag");
167:
168: WSIFMessage inMsg = operation.createInputMessage();
169: WSIFMessage outMsg = operation.createOutputMessage();
170: WSIFMessage faultMsg = operation.createFaultMessage();
171:
172: SingleTag_Type stt = new SingleTag_Type();
173: inMsg.setObjectPart("SingleTag", stt);
174:
175: boolean ok = operation.executeRequestResponseOperation(
176: inMsg, outMsg, faultMsg);
177:
178: assertTrue("operation returned false!!", ok);
179:
180: Object o = null;
181: try {
182: o = outMsg.getObjectPart("SingleTag");
183: assertTrue("response is null!!!", o != null);
184: } catch (WSIFException e) {
185: assertTrue(
186: "response part 'SingleTag' not found in output message!!!",
187: false);
188: }
189: assertTrue("response part has wrong type: " + o.getClass(),
190: SingleTag_Type.class.isAssignableFrom(o.getClass()));
191:
192: } catch (Exception ex) {
193: ex.printStackTrace();
194: assertTrue("InteropDocTest.doitSingleTagDII(" + portName
195: + ") caught exception " + ex.getLocalizedMessage(),
196: false);
197: }
198: }
199:
200: private void doitSimpleDocumentDII(String portName, String protocol) {
201: if (portName.toUpperCase().indexOf("JMS") != -1
202: && !TestUtilities.areWeTesting("jms"))
203: return;
204:
205: TestUtilities.setProviderForProtocol(protocol);
206:
207: try {
208: WSIFServiceFactory factory = WSIFServiceFactory
209: .newInstance();
210: WSIFService service = factory.getService(wsdlLocation,
211: null, null, "http://soapinterop.org/",
212: "Doc_TestPortType");
213:
214: service.mapType(new javax.xml.namespace.QName(
215: "http://soapinterop.org/", "SimpleDocument"),
216: SimpleDocument_Type.class);
217:
218: WSIFPort port = service.getPort(portName);
219:
220: WSIFOperation operation = port
221: .createOperation("SimpleDocument");
222:
223: WSIFMessage inMsg = operation.createInputMessage();
224: WSIFMessage outMsg = operation.createOutputMessage();
225: WSIFMessage faultMsg = operation.createFaultMessage();
226:
227: SimpleDocument_Type sdt = new SimpleDocument_Type();
228: sdt.setValue("petra");
229: inMsg.setObjectPart("SimpleDocument", sdt);
230:
231: boolean ok = operation.executeRequestResponseOperation(
232: inMsg, outMsg, faultMsg);
233:
234: assertTrue("operation returned false!!", ok);
235:
236: Object o = null;
237: try {
238: o = outMsg.getObjectPart("SimpleDocument");
239: assertTrue("response is null!!!", o != null);
240: } catch (WSIFException e) {
241: assertTrue(
242: "response part 'SimpleDocument' not found in output message!!!",
243: false);
244: }
245: assertTrue("response part has wrong type: " + o.getClass(),
246: SimpleDocument_Type.class.isAssignableFrom(o
247: .getClass()));
248:
249: SimpleDocument_Type response = (SimpleDocument_Type) o;
250: assertTrue("document value wrong: " + response.getValue(),
251: sdt.getValue().equals(response.getValue()));
252:
253: } catch (Exception ex) {
254: ex.printStackTrace();
255: assertTrue("InteropDocTest.doitSimpleDocumentDII("
256: + portName + ") caught exception "
257: + ex.getLocalizedMessage(), false);
258: }
259: }
260:
261: private void doitComplexDocumentDII(String portName, String protocol) {
262: if (portName.toUpperCase().indexOf("JMS") != -1
263: && !TestUtilities.areWeTesting("jms"))
264: return;
265:
266: TestUtilities.setProviderForProtocol(protocol);
267:
268: try {
269: WSIFServiceFactory factory = WSIFServiceFactory
270: .newInstance();
271: WSIFService service = factory.getService(wsdlLocation,
272: null, null, "http://soapinterop.org/",
273: "Doc_TestPortType");
274:
275: service.mapType(new javax.xml.namespace.QName(
276: "http://soapinterop.org/", "ComplexDocument"),
277: ComplexDocument_Type.class);
278: service.mapType(
279: new javax.xml.namespace.QName(
280: "http://soapinterop.org/",
281: "ArrayOfSimpleDocument"),
282: ArrayOfSimpleDocument.class);
283: service.mapType(new javax.xml.namespace.QName(
284: "http://soapinterop.org/", "SimpleDocument"),
285: SimpleDocument_Type.class);
286: service.mapType(new javax.xml.namespace.QName(
287: "http://soapinterop.org/", "ChildDocument"),
288: ChildDocument.class);
289:
290: WSIFPort port = service.getPort(portName);
291:
292: WSIFOperation operation = port
293: .createOperation("ComplexDocument");
294:
295: WSIFMessage inMsg = operation.createInputMessage();
296: WSIFMessage outMsg = operation.createOutputMessage();
297: WSIFMessage faultMsg = operation.createFaultMessage();
298:
299: ComplexDocument_Type cdt = makeComplexDocument();
300: checkComplexDocument(cdt);
301:
302: inMsg.setObjectPart("ComplexDocument", cdt);
303:
304: boolean ok = operation.executeRequestResponseOperation(
305: inMsg, outMsg, faultMsg);
306:
307: assertTrue("operation returned false!!", ok);
308:
309: Object o = null;
310: try {
311: o = outMsg.getObjectPart("ComplexDocument");
312: assertTrue("response is null!!!", o != null);
313: } catch (WSIFException e) {
314: assertTrue(
315: "response part 'ComplexDocument' not found in output message!!!",
316: false);
317: }
318: assertTrue("response part has wrong type: " + o.getClass(),
319: ComplexDocument_Type.class.isAssignableFrom(o
320: .getClass()));
321: checkComplexDocument((ComplexDocument_Type) o);
322:
323: } catch (Exception ex) {
324: ex.printStackTrace();
325: assertTrue("InteropDocTest.doitComplexDocumentDII("
326: + portName + ") caught exception "
327: + ex.getLocalizedMessage(), false);
328: }
329: }
330:
331: private void doitSingleTagStub(String portName, String protocol) {
332: if (portName.toUpperCase().indexOf("JMS") != -1
333: && !TestUtilities.areWeTesting("jms"))
334: return;
335:
336: TestUtilities.setProviderForProtocol(protocol);
337:
338: try {
339: WSIFServiceFactory factory = WSIFServiceFactory
340: .newInstance();
341: WSIFService service = factory.getService(wsdlLocation,
342: null, null, "http://soapinterop.org/",
343: "Doc_TestPortType");
344:
345: service.mapPackage("http://soapinterop.org/",
346: "interop.wsifservice");
347:
348: service.mapType(new javax.xml.namespace.QName(
349: "http://soapinterop.org/", "SingleTag"),
350: SingleTag_Type.class);
351:
352: // force to use a 'wrapped' type operation
353: WSIFMessage context = service.getContext();
354: context.setObjectPart(
355: WSIFConstants.CONTEXT_OPERATION_STYLE,
356: WSIFConstants.CONTEXT_OPERATION_STYLE_WRAPPED);
357: service.setContext(context);
358:
359: Doc_TestPortType stub = (Doc_TestPortType) service.getStub(
360: portName, Doc_TestPortType.class);
361:
362: SingleTag_Type stet = new SingleTag_Type();
363:
364: SingleTag_Type response = stub.singleTag(stet);
365:
366: assertNotNull("response is null!!!", response);
367:
368: } catch (Exception ex) {
369: ex.printStackTrace();
370: assertTrue("InteropDocTest.doitSingleTagDII(" + portName
371: + ") caught exception " + ex.getLocalizedMessage(),
372: false);
373: }
374: }
375:
376: private void doitSimpleDocumentStub(String portName, String protocol) {
377: if (portName.toUpperCase().indexOf("JMS") != -1
378: && !TestUtilities.areWeTesting("jms"))
379: return;
380:
381: TestUtilities.setProviderForProtocol(protocol);
382:
383: try {
384: WSIFServiceFactory factory = WSIFServiceFactory
385: .newInstance();
386: WSIFService service = factory.getService(wsdlLocation,
387: null, null, "http://soapinterop.org/",
388: "Doc_TestPortType");
389:
390: service.mapPackage("http://soapinterop.org/",
391: "interop.wsifservice");
392:
393: service.mapType(new javax.xml.namespace.QName(
394: "http://soapinterop.org/", "SimpleDocument"),
395: SimpleDocument_Type.class);
396:
397: // force to use a 'wrapped' type operation
398: WSIFMessage context = service.getContext();
399: context.setObjectPart(
400: WSIFConstants.CONTEXT_OPERATION_STYLE,
401: WSIFConstants.CONTEXT_OPERATION_STYLE_WRAPPED);
402: service.setContext(context);
403:
404: Doc_TestPortType stub = (Doc_TestPortType) service.getStub(
405: portName, Doc_TestPortType.class);
406:
407: SimpleDocument_Type sdt = new SimpleDocument_Type();
408: sdt.setValue("petra");
409:
410: SimpleDocument_Type response = stub.simpleDocument(sdt);
411:
412: assertNotNull("response is null!!!", response);
413:
414: assertTrue("simpleDocument value wrong: "
415: + response.getValue(), sdt.getValue().equals(
416: response.getValue()));
417:
418: } catch (Exception ex) {
419: ex.printStackTrace();
420: assertTrue("InteropDocTest.doitSimpleDocumentDII("
421: + portName + ") caught exception "
422: + ex.getLocalizedMessage(), false);
423: }
424: }
425:
426: private void doitComplexDocumentStub(String portName,
427: String protocol) {
428: if (portName.toUpperCase().indexOf("JMS") != -1
429: && !TestUtilities.areWeTesting("jms"))
430: return;
431:
432: TestUtilities.setProviderForProtocol(protocol);
433:
434: try {
435: WSIFServiceFactory factory = WSIFServiceFactory
436: .newInstance();
437: WSIFService service = factory.getService(wsdlLocation,
438: null, null, "http://soapinterop.org/",
439: "Doc_TestPortType");
440:
441: service.mapPackage("http://soapinterop.org/",
442: "interop.wsifservice");
443:
444: service.mapType(new javax.xml.namespace.QName(
445: "http://soapinterop.org/", "ComplexDocument"),
446: ComplexDocument_Type.class);
447: service.mapType(
448: new javax.xml.namespace.QName(
449: "http://soapinterop.org/",
450: "ArrayOfSimpleDocument"),
451: ArrayOfSimpleDocument.class);
452: service.mapType(new javax.xml.namespace.QName(
453: "http://soapinterop.org/", "SimpleDocument"),
454: SimpleDocument_Type.class);
455: service.mapType(new javax.xml.namespace.QName(
456: "http://soapinterop.org/", "ChildDocument"),
457: ChildDocument.class);
458:
459: // force to use a 'wrapped' type operation
460: WSIFMessage context = service.getContext();
461: context.setObjectPart(
462: WSIFConstants.CONTEXT_OPERATION_STYLE,
463: WSIFConstants.CONTEXT_OPERATION_STYLE_WRAPPED);
464: service.setContext(context);
465:
466: Doc_TestPortType stub = (Doc_TestPortType) service.getStub(
467: portName, Doc_TestPortType.class);
468:
469: ComplexDocument_Type cdt = makeComplexDocument();
470: checkComplexDocument(cdt);
471:
472: ComplexDocument_Type response = stub.complexDocument(cdt);
473: assertNotNull("response is null!!!", response);
474:
475: checkComplexDocument(response);
476:
477: } catch (Exception ex) {
478: ex.printStackTrace();
479: assertTrue("InteropDocTest.doitComplexDocumentDII("
480: + portName + ") caught exception "
481: + ex.getLocalizedMessage(), false);
482: }
483: }
484:
485: private ComplexDocument_Type makeComplexDocument() {
486:
487: ComplexDocument_Type cdt = new ComplexDocument_Type();
488:
489: ArrayOfSimpleDocument asd = new ArrayOfSimpleDocument();
490: SimpleDocument_Type[] adt = new SimpleDocument_Type[2];
491: adt[0] = new SimpleDocument_Type("petra");
492: adt[1] = new SimpleDocument_Type("ant");
493: asd.setSimpleDocument(adt);
494: cdt.setSimpleDoc(asd);
495:
496: ChildDocument cd = new ChildDocument();
497: asd = new ArrayOfSimpleDocument();
498: adt = new SimpleDocument_Type[1];
499: adt[0] = new SimpleDocument_Type("sue");
500: asd.setSimpleDocument(adt);
501: cd.setChildSimpleDoc(asd);
502: cdt.setChild(cd);
503:
504: cdt.setAnAttribute("together");
505:
506: return cdt;
507: }
508:
509: private void checkComplexDocument(ComplexDocument_Type cdt) {
510:
511: ArrayOfSimpleDocument asd = cdt.getSimpleDoc();
512: assertTrue("asd is null!!!", asd != null);
513: SimpleDocument_Type[] adt = asd.getSimpleDocument();
514:
515: boolean b = "petra".equals(adt[0]);
516:
517: assertTrue("adt is null!!!", adt != null);
518: assertTrue("adt length not 2, is: " + adt.length,
519: adt.length == 2);
520: assertTrue("child adt[0] not 'petra', is: " + adt[0], "petra"
521: .equals(adt[0].getValue()));
522: assertTrue("child adt[1] not 'ant', is: " + adt[0], "ant"
523: .equals(adt[1].getValue()));
524:
525: ChildDocument cd = cdt.getChild();
526: asd = cd.getChildSimpleDoc();
527: assertTrue("child asd is null!!!", asd != null);
528: adt = asd.getSimpleDocument();
529: assertTrue("child adt is null!!!", adt != null);
530: assertTrue("child adt length not 1, is: " + adt.length,
531: adt.length == 1);
532: assertTrue("child adt[0] not 'sue', is: " + adt[0], "sue"
533: .equals(adt[0].getValue()));
534:
535: String s = cdt.getAnAttribute();
536: assertTrue("attribute not 'together' is: " + s, "together"
537: .equals(s));
538:
539: }
540:
541: }
|