KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > celtix > tools > processors > wsdl2 > WSDLToXMLProcessorTest


1 package org.objectweb.celtix.tools.processors.wsdl2;
2
3 import java.io.File JavaDoc;
4 import java.util.Iterator JavaDoc;
5
6 import javax.wsdl.Binding;
7 import javax.wsdl.BindingOperation;
8 import javax.wsdl.Service;
9 import javax.xml.namespace.QName JavaDoc;
10
11 import org.objectweb.celtix.tools.WSDLToXML;
12 import org.objectweb.celtix.tools.common.ToolConstants;
13 import org.objectweb.celtix.tools.common.ToolException;
14 import org.objectweb.celtix.tools.extensions.xmlformat.XMLFormat;
15 import org.objectweb.celtix.tools.extensions.xmlformat.XMLFormatBinding;
16 import org.objectweb.celtix.tools.extensions.xmlformat.XMLHttpAddress;
17 import org.objectweb.celtix.tools.processors.ProcessorTestBase;
18
19 public class WSDLToXMLProcessorTest extends ProcessorTestBase {
20
21     public void setUp() throws Exception JavaDoc {
22         super.setUp();
23         env.put(ToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
24     }
25
26     public void testAllDefault() throws Exception JavaDoc {
27         String JavaDoc[] args = new String JavaDoc[] {"-i", "Greeter", "-d", output.getCanonicalPath(),
28                                       getLocation("/wsdl/hello_world.wsdl")};
29         WSDLToXML.main(args);
30
31         File JavaDoc outputFile = new File JavaDoc(output, "hello_world-xmlbinding.wsdl");
32         assertTrue("New wsdl file is not generated", outputFile.exists());
33
34         WSDLToJavaProcessor processor = new WSDLToJavaProcessor();
35         processor.setEnvironment(env);
36         try {
37             processor.parseWSDL(outputFile.getAbsolutePath());
38             Binding binding = processor.getWSDLDefinition().getBinding(
39                                                                        new QName JavaDoc(processor
40                                                                            .getWSDLDefinition()
41                                                                            .getTargetNamespace(),
42                                                                                  "Greeter_XMLBinding"));
43             if (binding == null) {
44                 fail("Element wsdl:binding Greeter_XMLBinding Missed!");
45             }
46             Iterator JavaDoc it = binding.getExtensibilityElements().iterator();
47             boolean found = false;
48             while (it.hasNext()) {
49                 Object JavaDoc obj = it.next();
50                 if (obj instanceof XMLFormatBinding) {
51                     found = true;
52                     break;
53                 }
54             }
55             if (!found) {
56                 fail("Element <xformat:binding/> Missed!");
57             }
58             BindingOperation bo = binding.getBindingOperation("sayHi", null, null);
59             if (bo == null) {
60                 fail("Element <wsdl:operation name=\"sayHi\"> Missed!");
61             }
62             it = bo.getBindingInput().getExtensibilityElements().iterator();
63             found = false;
64             while (it.hasNext()) {
65                 Object JavaDoc obj = it.next();
66                 if (obj instanceof XMLFormat
67                     && ((XMLFormat)obj).getRootNode().getLocalPart().equals("sayHi")) {
68                     found = true;
69                     break;
70                 }
71             }
72             if (!found) {
73                 fail("Element <xformat:body rootNode=\"tns:sayHi\" /> Missed!");
74             }
75             Service service = processor.getWSDLDefinition().getService(
76                                                                        new QName JavaDoc(processor
77                                                                            .getWSDLDefinition()
78                                                                            .getTargetNamespace(),
79                                                                                  "Greeter_XMLService"));
80             if (service == null) {
81                 fail("Element wsdl:service Greeter_XMLService Missed!");
82             }
83             it = service.getPort("Greeter_XMLPort").getExtensibilityElements().iterator();
84             found = false;
85             while (it.hasNext()) {
86                 Object JavaDoc obj = it.next();
87                 if (obj instanceof XMLHttpAddress) {
88                     XMLHttpAddress xmlHttpAddress = (XMLHttpAddress)obj;
89                     if (xmlHttpAddress.getLocation() != null) {
90                         found = true;
91                         break;
92                     }
93                 }
94             }
95             if (!found) {
96                 fail("Element http:address of service port Missed!");
97             }
98         } catch (ToolException e) {
99             fail("Exception Encountered when parsing wsdl, error: " + e.getMessage());
100         }
101     }
102
103     private String JavaDoc getLocation(String JavaDoc wsdlFile) {
104         return WSDLToXMLProcessorTest.class.getResource(wsdlFile).getFile();
105     }
106
107 }
108
Popular Tags