KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > interop > InteropDocTest


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 2002 The Apache Software Foundation. All rights
6  * reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "WSIF" and "Apache Software Foundation" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact apache@apache.org.
31  *
32  * 5. Products derived from this software may not be called "Apache",
33  * nor may "Apache" appear in their name, without prior written
34  * permission of the Apache Software Foundation.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This software consists of voluntary contributions made by many
51  * individuals on behalf of the Apache Software Foundation and was
52  * originally based on software copyright (c) 2001, 2002, International
53  * Business Machines, Inc., http://www.apache.org. For more
54  * information on the Apache Software Foundation, please see
55  * <http://www.apache.org/>.
56  */

57
58 package interop;
59
60 import interop.wsifservice.ArrayOfSimpleDocument;
61 import interop.wsifservice.ChildDocument;
62 import interop.wsifservice.ComplexDocument_Type;
63 import interop.wsifservice.Doc_TestPortType;
64 import interop.wsifservice.SimpleDocument_Type;
65 import interop.wsifservice.SingleTag_Type;
66
67 import junit.framework.Test;
68 import junit.framework.TestCase;
69 import junit.framework.TestSuite;
70
71 import org.apache.wsif.WSIFConstants;
72 import org.apache.wsif.WSIFException;
73 import org.apache.wsif.WSIFMessage;
74 import org.apache.wsif.WSIFOperation;
75 import org.apache.wsif.WSIFPort;
76 import org.apache.wsif.WSIFService;
77 import org.apache.wsif.WSIFServiceFactory;
78 import util.TestUtilities;
79
80 /**
81  * Junit test to test out the AXIS provider docstyle support
82  *
83  * This test is part of the SOAP Builders interoperability testing
84  * effort described at http://www.whitemesa.net/. The WSDL is
85  * available online at http://www.whitemesa.net/wsdl/interopdoc.wsdl
86  *
87  * TODO: tests using stubs (see bugzilla 15780)
88  * TODO: tests using messaging
89  *
90  * @author Ant Elder <ant.elder@uk.ibm.com>
91  */

92 public class InteropDocTest extends TestCase {
93     
94     String JavaDoc wsdlLocation =
95         TestUtilities.getWsdlPath("java\\test\\interop\\wsifservice")
96             + "interopdoc.wsdl";
97 // + "interopdocLocal.wsdl";
98
// "http://www.whitemesa.net/wsdl/interopdoc.wsdl";
99

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