1 package org.jbpm.bpel.wsdl.xml; 2 3 import java.io.CharArrayWriter ; 4 import java.util.HashMap ; 5 import java.util.Iterator ; 6 import java.util.Map ; 7 8 import javax.wsdl.Definition; 9 import javax.wsdl.factory.WSDLFactory; 10 import javax.xml.namespace.QName ; 11 12 import junit.framework.TestCase; 13 14 import org.jbpm.bpel.data.def.Snippet; 15 import org.jbpm.bpel.wsdl.def.PropertyAlias; 16 import org.jbpm.bpel.wsdl.util.WsdlUtil; 17 import org.jbpm.bpel.xml.BpelConstants; 18 import org.jbpm.bpel.xml.util.NodeUtil; 19 20 24 public class PropertyAliasTest extends TestCase { 25 26 private WSDLFactory factory; 27 private Definition definition; 28 private Map namespaceDeclarations; 29 30 private static final String NS_COR = "http://example.com/supplyCorrelation.wsdl"; 31 private static final String NS_PUR = "http://manufacturing.org/wsdl/purchase"; 32 private static final String FILE_NAME = "propertyAliasSample.wsdl"; 33 34 protected void setUp() throws Exception { 35 factory = WsdlUtil.getFactory(); 36 definition = factory.newWSDLReader().readWSDL(getClass().getResource(FILE_NAME).toString()); 37 38 namespaceDeclarations = new HashMap (); 39 namespaceDeclarations.put("xsd", BpelConstants.NS_XML_SCHEMA); 40 namespaceDeclarations.put("bpws", BpelConstants.NS_BPWS); 41 namespaceDeclarations.put("cor", NS_COR); 42 namespaceDeclarations.put("def", NS_PUR); 43 namespaceDeclarations.put("tns", "http://example.com/supplyMessages.wsdl"); 44 namespaceDeclarations.put("po", "http://example.com/po.xsd"); 45 namespaceDeclarations.put("xml", "http://www.w3.org/XML/1998/namespace"); 46 } 47 48 public void testUnmarshall() { 49 Iterator aliases = WsdlUtil.getExtensions(definition.getExtensibilityElements(), WsdlConstants.Q_PROPERTY_ALIAS); 50 51 PropertyAlias alias = (PropertyAlias) aliases.next(); 53 assertEquals(new QName (NS_COR, "customerID"), alias.getProperty().getQName()); 54 assertEquals(new QName (NS_PUR, "POMessage"), alias.getMessage().getQName()); 55 Snippet query = alias.getQuery(); 56 assertEquals("purchaseOrder/CID", query.getText()); 57 assertEquals(namespaceDeclarations, query.getNamespaces()); 58 59 alias = (PropertyAlias) aliases.next(); 61 query = alias.getQuery(); 62 63 assertEquals(new QName (NS_COR, "vendorID"), alias.getProperty().getQName()); 64 assertEquals(new QName (NS_PUR, "InvMessage"), alias.getMessage().getQName()); 65 assertEquals("http://www.w3.org/TR/1999/REC-xpath-19991116", query.getLanguage()); 66 assertEquals("IVC/po:Invoice/VID", query.getText()); 67 assertEquals(namespaceDeclarations, query.getNamespaces()); 68 } 69 70 public void testMarshall() throws Exception { 71 CharArrayWriter output = new CharArrayWriter (); 72 factory.newWSDLWriter().writeWSDL(definition, output); 73 output.close(); 74 75 definition = factory.newWSDLReader().readWSDL( 76 definition.getDocumentBaseURI(), NodeUtil.parseElement(output.toString())); 77 testUnmarshall(); 78 } 79 } 80 | Popular Tags |