1 package org.jbpm.bpel.xml; 2 3 import javax.xml.namespace.QName ; 4 import javax.xml.transform.Transformer ; 5 import javax.xml.transform.TransformerFactory ; 6 import javax.xml.transform.dom.DOMResult ; 7 import javax.xml.transform.dom.DOMSource ; 8 import javax.xml.transform.stream.StreamSource ; 9 10 import junit.framework.TestCase; 11 12 import org.w3c.dom.Document ; 13 import org.w3c.dom.Element ; 14 15 import com.ibm.wsdl.Constants; 16 import com.ibm.wsdl.util.xml.DOMUtils; 17 18 import org.jbpm.bpel.wsdl.xml.WsdlConstants; 19 import org.jbpm.bpel.xml.util.NodeUtil; 20 21 25 public class WsdlConverterTest extends TestCase { 26 27 private Transformer t; 28 private static final String TNS_URI = "http://www.manufacturing.org"; 29 30 public void setUp() throws Exception { 31 TransformerFactory f = TransformerFactory.newInstance(); 32 t = f.newTransformer(new StreamSource (BpelReader.class.getResourceAsStream("wsdl-1-1-converter.xsl"))); 33 } 34 35 37 public void testRole() throws Exception { 38 String xml = "<plnk:role name='schedulingRequester'><plnk:portType name='tns:schedulingCallbackPT'/></plnk:role>"; 39 Element role = transform(xml); 40 assertNull(NodeUtil.getElement(role, WsdlConstants.NS_PLNK_1_1, "portType")); 41 assertEquals("schedulingRequester", role.getAttribute("name")); 42 assertEquals("tns:schedulingCallbackPT", role.getAttribute("portType")); 43 } 44 45 public void testPropertyAliasUnchangedAttributes() throws Exception { 46 String xml = "<bpws:propertyAlias messageType='tns:POMessage' propertyName='tns:invoiceId'/>"; 47 Element propertyAlias = transform(xml); 48 QName propertyName = NodeUtil.getQName(propertyAlias.getAttribute("propertyName"), propertyAlias); 49 assertEquals("invoiceId", propertyName.getLocalPart()); 50 assertEquals(TNS_URI, propertyName.getNamespaceURI()); 51 QName messageType = NodeUtil.getQName(propertyAlias.getAttribute("messageType"), propertyAlias); 52 assertEquals("POMessage", messageType.getLocalPart()); 53 assertEquals(TNS_URI, messageType.getNamespaceURI()); 54 } 55 56 public void testPropertyAliasPart() throws Exception { 57 String xml = "<bpws:propertyAlias propertyName='tns:invoiceId' messageType='tns:POMessage' part='PO'/>"; 58 Element propertyAlias = transform(xml); 59 assertNull(NodeUtil.getAttribute(propertyAlias, "part")); 60 Element query = NodeUtil.getElement(propertyAlias, BpelConstants.NS_BPWS, "query"); 61 assertNotNull(query); 62 assertEquals("PO", DOMUtils.getChildCharacterData(query)); 63 } 64 65 public void testPropertyAliasQuery() throws Exception { 66 String xml = "<bpws:propertyAlias propertyName='tns:invoiceId' messageType='tns:POMessage' part='PO' query='/PO/orderNumber'/>"; 67 Element propertyAlias = transform(xml); 68 assertNull(NodeUtil.getAttribute(propertyAlias, "part")); 69 assertNull(NodeUtil.getAttribute(propertyAlias, "query")); 70 Element query = NodeUtil.getElement(propertyAlias, BpelConstants.NS_BPWS, "query"); 71 assertNotNull(query); 72 assertEquals("PO/orderNumber", DOMUtils.getChildCharacterData(query)); 73 } 74 75 public void testPropertyAliasRootElementQuery() throws Exception { 76 String xml = "<bpws:propertyAlias xmlns:tns='http://www.mecachi.com' part='PO' query='/tns:q'/>"; 77 Element propertyAlias = transform(xml); 78 Element query = NodeUtil.getElement(propertyAlias, BpelConstants.NS_BPWS, "query"); 79 assertNotNull(query); 80 assertEquals("PO/tns:q", DOMUtils.getChildCharacterData(query)); 81 } 82 83 public void testPropertyAliasElementQuery() throws Exception { 84 String xml = "<bpws:propertyAlias xmlns:tns='http://www.mecachi.com' part='PO' query='/tns:q/tns:child'/>"; 85 Element propertyAlias = transform(xml); 86 Element query = NodeUtil.getElement(propertyAlias, BpelConstants.NS_BPWS, "query"); 87 assertNotNull(query); 88 assertEquals("PO/tns:q/tns:child", DOMUtils.getChildCharacterData(query)); 89 } 90 91 public Element transform(String oldVersion) throws Exception { 92 String textToParse = 93 "<definitions xmlns='" + Constants.NS_URI_WSDL + "' " + 94 "xmlns:plnk='" + WsdlConstants.NS_PLNK_1_1 + "' " + 95 "xmlns:bpws='" + BpelConstants.NS_BPWS_1_1 + "' " + 96 "xmlns:tns='" + TNS_URI + "'" + 97 ">" + oldVersion + 98 "</definitions>"; 99 Document oldDoc = NodeUtil.parseElement(textToParse).getOwnerDocument(); 100 Document resultDoc = NodeUtil.createDocument(); 101 t.transform(new DOMSource (oldDoc), new DOMResult (resultDoc)); 102 return (Element ) resultDoc.getDocumentElement().getChildNodes().item(0); 103 } 104 } 105 | Popular Tags |