KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > bpel > xml > WsdlConverterTest


1 package org.jbpm.bpel.xml;
2
3 import javax.xml.namespace.QName JavaDoc;
4 import javax.xml.transform.Transformer JavaDoc;
5 import javax.xml.transform.TransformerFactory JavaDoc;
6 import javax.xml.transform.dom.DOMResult JavaDoc;
7 import javax.xml.transform.dom.DOMSource JavaDoc;
8 import javax.xml.transform.stream.StreamSource JavaDoc;
9
10 import junit.framework.TestCase;
11
12 import org.w3c.dom.Document JavaDoc;
13 import org.w3c.dom.Element JavaDoc;
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 /**
22  * @author Juan Cantú
23  * @version $Revision: 1.7 $ $Date: 2005/06/23 02:17:26 $
24  */

25 public class WsdlConverterTest extends TestCase {
26
27   private Transformer JavaDoc t;
28   private static final String JavaDoc TNS_URI = "http://www.manufacturing.org";
29   
30   public void setUp() throws Exception JavaDoc {
31     TransformerFactory JavaDoc f = TransformerFactory.newInstance();
32     t = f.newTransformer(new StreamSource JavaDoc(BpelReader.class.getResourceAsStream("wsdl-1-1-converter.xsl")));
33   }
34   
35   /////////////////////// Renamed Elements
36

37   public void testRole() throws Exception JavaDoc {
38     String JavaDoc xml = "<plnk:role name='schedulingRequester'><plnk:portType name='tns:schedulingCallbackPT'/></plnk:role>";
39     Element JavaDoc 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 JavaDoc {
46     String JavaDoc xml = "<bpws:propertyAlias messageType='tns:POMessage' propertyName='tns:invoiceId'/>";
47     Element JavaDoc propertyAlias = transform(xml);
48     QName JavaDoc propertyName = NodeUtil.getQName(propertyAlias.getAttribute("propertyName"), propertyAlias);
49     assertEquals("invoiceId", propertyName.getLocalPart());
50     assertEquals(TNS_URI, propertyName.getNamespaceURI());
51     QName JavaDoc 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 JavaDoc {
57     String JavaDoc xml = "<bpws:propertyAlias propertyName='tns:invoiceId' messageType='tns:POMessage' part='PO'/>";
58     Element JavaDoc propertyAlias = transform(xml);
59     assertNull(NodeUtil.getAttribute(propertyAlias, "part"));
60     Element JavaDoc 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 JavaDoc {
66     String JavaDoc xml = "<bpws:propertyAlias propertyName='tns:invoiceId' messageType='tns:POMessage' part='PO' query='/PO/orderNumber'/>";
67     Element JavaDoc propertyAlias = transform(xml);
68     assertNull(NodeUtil.getAttribute(propertyAlias, "part"));
69     assertNull(NodeUtil.getAttribute(propertyAlias, "query"));
70     Element JavaDoc 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 JavaDoc {
76     String JavaDoc xml = "<bpws:propertyAlias xmlns:tns='http://www.mecachi.com' part='PO' query='/tns:q'/>";
77     Element JavaDoc propertyAlias = transform(xml);
78     Element JavaDoc 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 JavaDoc {
84     String JavaDoc xml = "<bpws:propertyAlias xmlns:tns='http://www.mecachi.com' part='PO' query='/tns:q/tns:child'/>";
85     Element JavaDoc propertyAlias = transform(xml);
86     Element JavaDoc 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 JavaDoc transform(String JavaDoc oldVersion) throws Exception JavaDoc {
92     String JavaDoc 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 JavaDoc oldDoc = NodeUtil.parseElement(textToParse).getOwnerDocument();
100     Document JavaDoc resultDoc = NodeUtil.createDocument();
101     t.transform(new DOMSource JavaDoc(oldDoc), new DOMResult JavaDoc(resultDoc));
102     return (Element JavaDoc) resultDoc.getDocumentElement().getChildNodes().item(0);
103   }
104 }
105
Popular Tags