KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > bpel > wsdl > xml > PropertyAliasTest


1 package org.jbpm.bpel.wsdl.xml;
2
3 import java.io.CharArrayWriter JavaDoc;
4 import java.util.HashMap JavaDoc;
5 import java.util.Iterator JavaDoc;
6 import java.util.Map JavaDoc;
7
8 import javax.wsdl.Definition;
9 import javax.wsdl.factory.WSDLFactory;
10 import javax.xml.namespace.QName JavaDoc;
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 /**
21  * @author Alejandro Guízar
22  * @version $Revision: 1.8 $ $Date: 2005/06/23 02:17:27 $
23  */

24 public class PropertyAliasTest extends TestCase {
25
26   private WSDLFactory factory;
27   private Definition definition;
28   private Map JavaDoc namespaceDeclarations;
29   
30   private static final String JavaDoc NS_COR = "http://example.com/supplyCorrelation.wsdl";
31   private static final String JavaDoc NS_PUR = "http://manufacturing.org/wsdl/purchase";
32   private static final String JavaDoc FILE_NAME = "propertyAliasSample.wsdl";
33
34   protected void setUp() throws Exception JavaDoc {
35     factory = WsdlUtil.getFactory();
36     definition = factory.newWSDLReader().readWSDL(getClass().getResource(FILE_NAME).toString());
37     
38     namespaceDeclarations = new HashMap JavaDoc();
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 JavaDoc aliases = WsdlUtil.getExtensions(definition.getExtensibilityElements(), WsdlConstants.Q_PROPERTY_ALIAS);
50
51     // customer ID alias
52
PropertyAlias alias = (PropertyAlias) aliases.next();
53     assertEquals(new QName JavaDoc(NS_COR, "customerID"), alias.getProperty().getQName());
54     assertEquals(new QName JavaDoc(NS_PUR, "POMessage"), alias.getMessage().getQName());
55     Snippet query = alias.getQuery();
56     assertEquals("purchaseOrder/CID", query.getText());
57     assertEquals(namespaceDeclarations, query.getNamespaces());
58
59     // vendor ID alias
60
alias = (PropertyAlias) aliases.next();
61     query = alias.getQuery();
62
63     assertEquals(new QName JavaDoc(NS_COR, "vendorID"), alias.getProperty().getQName());
64     assertEquals(new QName JavaDoc(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 JavaDoc {
71     CharArrayWriter JavaDoc output = new CharArrayWriter JavaDoc();
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