1 19 20 package org.netbeans.modules.xml.wsdl.model.extensions.bpel; 21 22 import java.util.ArrayList ; 23 import java.util.Collection ; 24 25 import junit.framework.TestCase; 26 27 import org.netbeans.modules.xml.schema.model.GlobalElement; 28 import org.netbeans.modules.xml.schema.model.GlobalSimpleType; 29 import org.netbeans.modules.xml.schema.model.GlobalType; 30 import org.netbeans.modules.xml.schema.model.Schema; 31 import org.netbeans.modules.xml.schema.model.SchemaModel; 32 import org.netbeans.modules.xml.schema.model.visitor.FindSchemaComponentFromDOM; 33 import org.netbeans.modules.xml.wsdl.model.Definitions; 34 import org.netbeans.modules.xml.wsdl.model.Fault; 35 import org.netbeans.modules.xml.wsdl.model.Import; 36 import org.netbeans.modules.xml.wsdl.model.Input; 37 import org.netbeans.modules.xml.wsdl.model.Message; 38 import org.netbeans.modules.xml.wsdl.model.Output; 39 import org.netbeans.modules.xml.wsdl.model.PortType; 40 import org.netbeans.modules.xml.wsdl.model.RequestResponseOperation; 41 import org.netbeans.modules.xml.wsdl.model.Types; 42 import org.netbeans.modules.xml.wsdl.model.WSDLModel; 43 import org.netbeans.modules.xml.wsdl.model.extensions.NamespaceLocation; 44 import org.netbeans.modules.xml.wsdl.model.extensions.TestCatalogModel; 45 import org.netbeans.modules.xml.wsdl.model.extensions.Util; 46 import org.netbeans.modules.xml.wsdl.model.extensions.bpel.impl.PartnerLinkTypeImpl; 47 import org.netbeans.modules.xml.wsdl.model.extensions.xsd.WSDLSchema; 48 import org.netbeans.modules.xml.wsdl.model.visitor.FindWSDLComponent; 49 import org.netbeans.modules.xml.xam.dom.AbstractDocumentComponent; 50 import org.netbeans.modules.xml.xam.dom.NamedComponentReference; 51 52 56 public class BPELReadWriteTest extends TestCase { 57 58 public BPELReadWriteTest(String testName) { 59 super(testName); 60 } 61 62 protected void setUp() throws Exception { 63 } 64 65 protected void tearDown() throws Exception { 66 } 67 68 public void testRead() throws Exception { 69 NamespaceLocation.VEHICLE.refreshResourceFile(); 70 NamespaceLocation.HOTEL.refreshResourceFile(); 71 NamespaceLocation.AIRLINE.refreshResourceFile(); 72 NamespaceLocation.OTA.refreshResourceFile(); 73 WSDLModel model = TestCatalogModel.getDefault().getWSDLModel(NamespaceLocation.TRAVEL); 74 checkRead(model); 75 } 76 77 private void checkRead(WSDLModel model) throws Exception { 78 Definitions d = model.getDefinitions(); 79 80 Collection <CorrelationProperty> ees = d.getExtensibilityElements(CorrelationProperty.class); 82 CorrelationProperty cp = ees.iterator().next(); 83 assertEquals("CorrelationProperty.name", "ItineraryRefId", cp.getName()); 84 NamedComponentReference<GlobalType> typeRef = ees.iterator().next().getType(); 85 assertEquals("CorrelationProperty.type", "http://www.w3.org/2001/XMLSchema", typeRef.getEffectiveNamespace()); 86 GlobalType type = typeRef.get(); 87 assertEquals("orrelationProperty.type.name", "string", type.getName()); 88 89 92 Collection <PropertyAlias> pas = d.getExtensibilityElements(PropertyAlias.class); 93 assertEquals("PropertyAlias.count", 7, pas.size()); 94 ArrayList <PropertyAlias> pasl = new ArrayList <PropertyAlias>(pas); 95 PropertyAlias pa = pasl.get(2); 96 assertEquals("PropertyAlias.property", d.getTargetNamespace(), pa.getPropertyName().getEffectiveNamespace()); 97 AbstractDocumentComponent ac = (AbstractDocumentComponent) pa; 98 assertEquals("property prefix", BPELQName.VPROP_PREFIX, ac.getPeer().getPrefix()); 99 NamedComponentReference<CorrelationProperty> gr = pa.getPropertyName(); 100 assertEquals("PropertyAlias.propertyName", "tres:ItineraryRefId", gr.getRefString()); 101 NamedComponentReference<Message> msgRef = pa.getMessageType(); 102 assertEquals("PropertyAlias.messageType", "ares:ReserveAirlineIn", msgRef.getRefString()); 103 WSDLModel airModel = TestCatalogModel.getDefault().getWSDLModel(NamespaceLocation.AIRLINE); 104 Message resairIn = FindWSDLComponent.findComponent(Message.class, airModel.getDefinitions(), "/definitions/message[@name='ReserveAirlineIn']"); 105 assertEquals("PropertyAlias.property", cp, pa.getPropertyName().get()); 106 assertEquals("PropertyAlias.messageType", resairIn.getName(), pa.getMessageType().get().getName()); 107 assertEquals("PropertyAlias.part", "itinerary", pa.getPart()); 108 Query q = pa.getQuery(); 109 assertEquals("PropertyAlias.query", "/TravelItinerary/ItineraryRef/UniqueID", q.getContent()); 110 111 PartnerLinkType plt = d.getExtensibilityElements(PartnerLinkType.class).iterator().next(); 115 assertEquals("partnerLinkType.name", "TravelReservationPartnerLinkType", plt.getName()); 116 Role role1 = plt.getRole1(); 117 assertEquals("partnerLinkType.role1.name", "TravelReservationServiceRole", role1.getName()); 118 NamedComponentReference<PortType> ptRef = role1.getPortType(); 119 PortType pt = d.getPortTypes().iterator().next(); 120 assertEquals("partnerLinkType.role1.portType", pt, ptRef.get()); 121 assertEquals("element prefix", "plnk", ((PartnerLinkTypeImpl)plt).getPeer().getPrefix()); 122 assertNotNull("definitions.xmlns."+BPELQName.PLNK_PREFIX, ((AbstractDocumentComponent)d).getPrefixes().get(BPELQName.PLNK_PREFIX)); 123 assertNotNull("definitions.xmlns."+BPELQName.VPROP_PREFIX, ((AbstractDocumentComponent)d).getPrefixes().get(BPELQName.VPROP_PREFIX)); 124 } 125 126 private PropertyAlias addPropertyAlias(BPELComponentFactory fact, Definitions d, CorrelationProperty property, Message messageType) { 127 PropertyAlias pa = fact.createPropertyAlias(d); 128 d.addExtensibilityElement(pa); 129 pa.setPropertyName(pa.createReferenceTo(property, CorrelationProperty.class));; 130 pa.setMessageType(pa.createReferenceTo(messageType, Message.class)); 131 pa.setPart("itinerary"); 132 Query q = new BPELComponentFactory(pa.getModel()).createQuery(pa); 133 q.setContent("/TravelItinerary/ItineraryRef/UniqueID"); 134 pa.setQuery(q); 135 return pa; 136 } 137 138 private void doWrite(WSDLModel model) throws Exception { 139 BPELComponentFactory fact = new BPELComponentFactory(model); 140 Definitions d = model.getDefinitions(); 141 d.setTargetNamespace(NamespaceLocation.TRAVEL.getNamespace()); 142 143 Import im = model.getFactory().createImport(); d.addImport(im); 144 im.setNamespace(NamespaceLocation.AIRLINE.getNamespace()); 145 im.setLocation(NamespaceLocation.AIRLINE.getLocation()); 146 im = model.getFactory().createImport(); d.addImport(im); 147 im.setNamespace(NamespaceLocation.HOTEL.getNamespace()); 148 im.setLocation(NamespaceLocation.HOTEL.getLocation()); 149 im = model.getFactory().createImport(); d.addImport(im); 150 im.setNamespace(NamespaceLocation.VEHICLE.getNamespace()); 151 im.setLocation(NamespaceLocation.VEHICLE.getLocation()); 152 153 Types types = model.getFactory().createTypes(); d.setTypes(types); 154 WSDLSchema wschema = model.getFactory().createWSDLSchema(); 155 types.addExtensibilityElement(wschema); 156 Schema emSchema = wschema.getSchemaModel().getSchema(); 157 emSchema.setTargetNamespace("http://www.sun.com/javaone/05/TravelReservationService"); 158 GlobalElement ge = wschema.getSchemaModel().getFactory().createGlobalElement(); 159 ge.setName("itineraryFault"); 160 ge.setType(ge.createReferenceTo(Util.getPrimitiveType("string"), GlobalSimpleType.class)); 161 emSchema.addElement(ge); 162 163 Message inMsg = model.getFactory().createMessage(); d.addMessage(inMsg); 164 inMsg.setName("ItineraryIn"); 165 Message outMsg = model.getFactory().createMessage(); d.addMessage(outMsg); 166 outMsg.setName("ItineraryOut"); 167 168 PortType pt = model.getFactory().createPortType(); 174 d.addPortType(pt); pt.setName("TravelReservationPortType"); 175 RequestResponseOperation rro = model.getFactory().createRequestResponseOperation(); 176 pt.addOperation(rro); rro.setName("buildItinerary"); 177 Input in = model.getFactory().createInput(); rro.setInput(in); 178 in.setMessage(in.createReferenceTo(inMsg, Message.class)); 179 180 Output out = model.getFactory().createOutput(); rro.setOutput(out); 181 out.setMessage(out.createReferenceTo(outMsg, Message.class)); 182 183 Fault fault = model.getFactory().createFault(); rro.addFault(fault); 184 Message faultMsg = model.getFactory().createMessage(); faultMsg.setName("ItineraryFault"); 185 fault.setMessage(fault.createReferenceTo(faultMsg, Message.class)); 186 187 SchemaModel schemaModel = TestCatalogModel.getDefault().getSchemaModel(NamespaceLocation.OTA); 188 Schema primitives = schemaModel.findSchemas("http://www.w3.org/2001/XMLSchema").iterator().next(); 189 GlobalSimpleType stringType = FindSchemaComponentFromDOM.find( 190 GlobalSimpleType.class, primitives, "/schema/simpleType[@name='string']"); 191 CorrelationProperty cp = fact.createCorrelationProperty(d); 193 d.addExtensibilityElement(cp); 194 cp.setName("ItineraryRefId"); 195 cp.setType(cp.createSchemaReference(stringType, GlobalType.class)); 196 model.endTransaction(); 197 model.startTransaction(); 198 addPropertyAlias(fact, d, cp, FindWSDLComponent.findComponent(Message.class, d, 200 "/definitions/message[@name='ItineraryIn']")); 201 202 WSDLModel airModel = TestCatalogModel.getDefault().getWSDLModel(NamespaceLocation.AIRLINE); 204 addPropertyAlias(fact, d, cp, FindWSDLComponent.findComponent(Message.class, airModel.getDefinitions(), 205 "/definitions/message[@name='AirlineReservedIn']")); 206 addPropertyAlias(fact, d, cp, FindWSDLComponent.findComponent(Message.class, airModel.getDefinitions(), 208 "/definitions/message[@name='ReserveAirlineIn']")); 209 210 WSDLModel vehModel = TestCatalogModel.getDefault().getWSDLModel(NamespaceLocation.VEHICLE); 212 addPropertyAlias(fact, d, cp, FindWSDLComponent.findComponent(Message.class, vehModel.getDefinitions(), 213 "/definitions/message[@name='VehicleReservedIn']")); 214 addPropertyAlias(fact, d, cp, FindWSDLComponent.findComponent(Message.class, vehModel.getDefinitions(), 216 "/definitions/message[@name='ReserveVehicleIn']")); 217 218 WSDLModel hotelModel = TestCatalogModel.getDefault().getWSDLModel(NamespaceLocation.HOTEL); 220 addPropertyAlias(fact, d, cp, FindWSDLComponent.findComponent(Message.class, hotelModel.getDefinitions(), 221 "/definitions/message[@name='HotelReservedIn']")); 222 addPropertyAlias(fact, d, cp, FindWSDLComponent.findComponent(Message.class, hotelModel.getDefinitions(), 224 "/definitions/message[@name='ReserveHotelIn']")); 225 226 230 PartnerLinkType plt = fact.createPartnerLinkType(d); 231 d.addExtensibilityElement(plt); 232 plt.setName("TravelReservationPartnerLinkType"); 233 Role role1 = fact.createRole(plt); 234 plt.setRole1(role1); 235 role1.setName("TravelReservationServiceRole"); 236 role1.setPortType(role1.createReferenceTo(pt, PortType.class)); 237 238 assertEquals("element prefix", "plnk", ((PartnerLinkTypeImpl)plt).getPeer().getPrefix()); 239 } 240 241 public void testWrite() throws Exception { 242 TestCatalogModel.getDefault().addNamespace(NamespaceLocation.EMPTY_TRAVEL); 243 WSDLModel model = TestCatalogModel.getDefault().getWSDLModel(NamespaceLocation.EMPTY_TRAVEL); 244 model.startTransaction(); 245 doWrite(model); 246 model.endTransaction(); 247 checkRead(model); 248 } 249 250 public String getTestResourcePath() { 251 return "resources/TravelReservationService.wsdl"; 252 } 253 } 254 | Popular Tags |