KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > model > ImportTest


1 package org.netbeans.modules.xml.wsdl.model;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.List JavaDoc;
5 import javax.swing.text.Document JavaDoc;
6 import junit.framework.*;
7 import org.netbeans.modules.xml.schema.model.GlobalElement;
8 import org.netbeans.modules.xml.schema.model.GlobalType;
9 import org.netbeans.modules.xml.wsdl.model.impl.WSDLModelImpl;
10 import org.netbeans.modules.xml.wsdl.model.visitor.FindWSDLComponent;
11 import org.netbeans.modules.xml.xam.dom.NamedComponentReference;
12
13 /**
14  *
15  * @author nn136682
16  */

17 public class ImportTest extends TestCase {
18     
19     public ImportTest(String JavaDoc testName) {
20         super(testName);
21     }
22
23     protected void setUp() throws Exception JavaDoc {
24         //System.out.println(System.getProperty("java.class.path"));
25
//Thread.dumpStack();
26
//throw new IllegalStateException("Setup Exception");*/
27
}
28
29     protected void tearDown() throws Exception JavaDoc {
30         TestCatalogModel.getDefault().clearDocumentPool();
31     }
32
33     public static Test suite() {
34         TestSuite suite = new TestSuite(ImportTest.class);
35         
36         return suite;
37     }
38
39     public void testReadPortBinding() throws Exception JavaDoc {
40         NamespaceLocation.AIRLINE.refreshResourceFile();
41         WSDLModel travelModel = TestCatalogModel.getDefault().getWSDLModel(NamespaceLocation.TRAVEL);
42         Definitions root = travelModel.getDefinitions();
43         String JavaDoc xpath = "/definitions/service[1]/port[2]";
44         Port airlinePort = FindWSDLComponent.findComponent(Port.class, root, xpath);
45         Binding airlineBinding = airlinePort.getBinding().get();
46         assertEquals("testPortBinding", "AirlineReservationCallbackSoapBinding", airlineBinding.getName());
47     }
48     
49     public void testWritePortBinding() throws Exception JavaDoc {
50         WSDLModel travelModel = TestCatalogModel.getDefault().getWSDLModel(NamespaceLocation.TRAVEL);
51         Definitions root = travelModel.getDefinitions();
52         
53         travelModel.startTransaction();
54         Service s = travelModel.getFactory().createService();
55         root.addService(s);
56         s.setName("testWritePortBinding");
57         Port p = travelModel.getFactory().createPort(); s.addPort(p);
58         p.setName("TestPort");
59         WSDLModel vehModel = TestCatalogModel.getDefault().getWSDLModel(NamespaceLocation.VEHICLE);
60         Binding b = FindWSDLComponent.findComponent(Binding.class, vehModel.getDefinitions(), "/definitions/binding[1]");
61         p.setBinding(p.createReferenceTo(b, Binding.class));
62         travelModel.endTransaction();
63         //TODO
64
travelModel = Util.dumpAndReloadModel((Document JavaDoc)travelModel.getModelSource().getLookup().lookup(Document JavaDoc.class));
65         root = travelModel.getDefinitions();
66         String JavaDoc xpath = "/definitions/service[@name='testWritePortBinding']/port[@name='TestPort']";
67         Port airlinePort = FindWSDLComponent.findComponent(Port.class, root, xpath);
68         Binding b2 = airlinePort.getBinding().get();
69         assertEquals("testPortBinding", "VehicleReservationSoapBinding", b2.getName());
70     }
71     
72     public void testSchemaThroughWsdlImport() throws Exception JavaDoc {
73         NamespaceLocation.PO.refreshResourceFile();
74         WSDLModel model = TestCatalogModel.getDefault().getWSDLModel(NamespaceLocation.TESTOP);
75         Definitions d = model.getDefinitions();
76         List JavaDoc<Message> messages = new ArrayList JavaDoc(d.getMessages());
77         
78         Message m1 = messages.get(0);
79         NamedComponentReference<GlobalType> type = m1.getParts().iterator().next().getType();
80         assertEquals("PurchaseOrderType", type.get().getName());
81         Message m2 = messages.get(1);
82         NamedComponentReference<GlobalElement> ge = m2.getParts().iterator().next().getElement();
83         assertEquals("comment", ge.get().getName());
84     }
85     
86     public void testImportSchemaWithSameNamespace() throws Exception JavaDoc {
87         NamespaceLocation.PO_1.refreshResourceFile();
88         WSDLModel model = TestCatalogModel.getDefault().getWSDLModel(NamespaceLocation.TESTIMPORT);
89         Definitions d = model.getDefinitions();
90         List JavaDoc<Message> messages = new ArrayList JavaDoc(d.getMessages());
91         Message m1 = messages.get(0);
92         GlobalElement ge = m1.getParts().iterator().next().getElement().get();
93         assertEquals("purchaseOrder", ge.getName());
94     }
95
96     public void testXsdTypeWithoutImport() throws Exception JavaDoc {
97         WSDLModel model = TestCatalogModel.getDefault().getWSDLModel(NamespaceLocation.ECHO);
98         Definitions d = model.getDefinitions();
99         List JavaDoc<Message> messages = new ArrayList JavaDoc(d.getMessages());
100         Message m1 = messages.get(0);
101         assertEquals("message_0", m1.getName());
102         Part part = m1.getParts().iterator().next();
103         GlobalType gt = part.getType().get();
104         assertEquals("string", gt.getName());
105     }
106     
107     public void testImportSameNamespaceWsdl() throws Exception JavaDoc {
108         WSDLModel model = Util.loadWSDLModel("resources/GoogleFlow.wsdl");
109         Operation op = model.findComponentByName("initiate", Operation.class);
110         Message referencedMessage = op.getInput().getMessage().get();
111         assertEquals("Imported model has same namespace", model.getDefinitions().getTargetNamespace(),
112             referencedMessage.getModel().getDefinitions().getTargetNamespace());
113     }
114     
115     public void testUnqualifiedSchemaReference() throws Exception JavaDoc {
116         WSDLModelImpl model = (WSDLModelImpl)Util.loadWSDLModel("resources/SiebelInterface.wsdl");
117         String JavaDoc xpath = "/definitions/message[@name='SiebelInterfaceRequest']/part[@name='SWEExtData']";
118         Part part = Util.find(Part.class, model, xpath);
119         assertNotNull("part.element should resolve w/o prefix", part.getElement().get());
120     }
121 }
122
Popular Tags