KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > model > visitor > FindWSDLComponentTest


1 package org.netbeans.modules.xml.wsdl.model.visitor;
2
3 import junit.framework.*;
4 import org.netbeans.modules.xml.wsdl.model.Binding;
5 import org.netbeans.modules.xml.wsdl.model.Definitions;
6 import org.netbeans.modules.xml.wsdl.model.Message;
7 import org.netbeans.modules.xml.wsdl.model.NamespaceLocation;
8 import org.netbeans.modules.xml.wsdl.model.RequestResponseOperation;
9 import org.netbeans.modules.xml.wsdl.model.TestCatalogModel;
10 import org.netbeans.modules.xml.wsdl.model.Util;
11 import org.netbeans.modules.xml.wsdl.model.WSDLComponent;
12 import org.netbeans.modules.xml.wsdl.model.WSDLComponentFactory;
13 import org.netbeans.modules.xml.wsdl.model.WSDLModel;
14 import org.netbeans.modules.xml.wsdl.model.extensions.soap.SOAPBinding;
15
16 /**
17  *
18  * @author Nam Nguyen
19  */

20 public class FindWSDLComponentTest extends TestCase {
21     
22     public FindWSDLComponentTest(String JavaDoc testName) {
23         super(testName);
24     }
25
26     protected void setUp() throws Exception JavaDoc {
27     }
28
29     protected void tearDown() throws Exception JavaDoc {
30         TestCatalogModel.getDefault().clearDocumentPool();
31     }
32     
33     public void testFindComponent() throws Exception JavaDoc {
34         WSDLModel model = Util.loadWSDLModel("resources/HelloService.wsdl");
35         Definitions d = model.getDefinitions();
36         RequestResponseOperation rro = (RequestResponseOperation) d.getPortTypes().iterator().next().getOperations().iterator().next();
37         String JavaDoc xpath = "/definitions/portType/operation[1]/input";
38         WSDLComponent found = (WSDLComponent) new FindWSDLComponent().findComponent(model.getRootComponent(), xpath);
39         assertEquals(xpath, rro.getInput(), found);
40         
41         xpath = "/definitions/portType/operation[1]/output";
42         found = (WSDLComponent) new FindWSDLComponent().findComponent(model.getRootComponent(), xpath);
43         assertEquals(xpath, rro.getOutput(), found);
44         
45         Binding b = d.getBindings().iterator().next();
46         SOAPBinding sb = (SOAPBinding) b.getExtensibilityElements().iterator().next();
47         xpath = "/definitions/binding[@name='HelloServiceSEIBinding']/binding";
48         found = (WSDLComponent) new FindWSDLComponent().findComponent(model.getRootComponent(), xpath);
49         
50         assertEquals("binding.soap", sb, found);
51     }
52
53     public void testFindComponentAfterWrite() throws Exception JavaDoc {
54         WSDLModel model = Util.loadWSDLModel("resources/empty.wsdl");
55         model.startTransaction();
56         Definitions d = model.getDefinitions();
57         d.setName("HelloService");
58         d.setTargetNamespace("urn:HelloService/wsdl");
59         WSDLComponentFactory fact = d.getModel().getFactory();
60
61         Message m1 = fact.createMessage();
62         d.addMessage(m1);
63         m1.setName("HelloServiceSEI_sayHello");
64         
65         model.endTransaction();
66         
67         String JavaDoc xpath = "/definitions";
68         WSDLComponent found = (WSDLComponent) new FindWSDLComponent().findComponent(model.getRootComponent(), xpath);
69         assertEquals(xpath, model.getRootComponent(), found);
70     }
71
72     public void testFindSchemaComponent() throws Exception JavaDoc {
73         WSDLModel model = TestCatalogModel.getDefault().getWSDLModel(NamespaceLocation.TRAVEL);
74         Definitions root = model.getDefinitions();
75         String JavaDoc xpath = "/definitions/types/xs:schema/xs:element[1]";
76         // <xs:element name="itineraryFault" type="xs:string" />
77
new FindWSDLComponent().findComponent(root, xpath);
78     }
79 }
80
Popular Tags