KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > bpel > data > exe > MessageVariableTest


1 package org.jbpm.bpel.data.exe;
2
3 import java.util.Map JavaDoc;
4
5 import javax.wsdl.Definition;
6 import javax.xml.namespace.QName JavaDoc;
7
8 import junit.framework.TestCase;
9
10 import org.w3c.dom.Element JavaDoc;
11
12 import org.jbpm.bpel.data.def.VariableDefinition;
13 import org.jbpm.bpel.def.ImportsDefinition;
14 import org.jbpm.bpel.wsdl.util.WsdlUtil;
15 import org.jbpm.bpel.xml.BpelConstants;
16 import org.jbpm.bpel.xml.BpelReader;
17 import org.jbpm.bpel.xml.util.NodeUtil;
18
19 /**
20  * @author Alejandro Guízar
21  * @version $Revision: 1.10 $ $Date: 2005/06/23 02:17:26 $
22  */

23 public class MessageVariableTest extends TestCase {
24
25   private MessageVariableInstance messageInstance;
26   private Map JavaDoc namespaceDeclarations;
27
28   private static final String JavaDoc WSDL_TEXT =
29     "<definitions targetNamespace='http://jbpm.org/bpel/examples'" +
30     " xmlns:tns='http://jbpm.org/bpel/examples'" +
31     " xmlns:xsd='http://www.w3.org/2001/XMLSchema'" +
32     " xmlns:bpws='http://schemas.xmlsoap.org/ws/2004/03/business-process/'" +
33     " xmlns='http://schemas.xmlsoap.org/wsdl/'>" +
34     " <message name='request'>" +
35     " <part name='simplePart' type='xsd:string'/>" +
36     " <part name='elementPart' element='tns:surpriseElement'/>" +
37     " </message>" +
38     " <bpws:property name='nameProperty' type='xsd:string'/>" +
39     " <bpws:property name='idProperty' type='xsd:int'/>" +
40     " <bpws:propertyAlias propertyName='tns:nameProperty' messageType='tns:request'>" +
41     " <bpws:query>elementPart/tns:surpriseElement/c/@name</bpws:query>" +
42     " </bpws:propertyAlias>" +
43     " <bpws:propertyAlias propertyName='tns:idProperty' messageType='tns:request'>" +
44     " <bpws:query>elementPart/tns:surpriseElement/e</bpws:query>" +
45     " </bpws:propertyAlias>" +
46     "</definitions>";
47   private static final String JavaDoc MESSAGE_TEXT =
48     "<vendor:msg0 xmlns:vendor='http://jbpm.org'>" +
49     " <simplePart>wawa</simplePart>" +
50     " <elementPart>" +
51     " <tns:surpriseElement xmlns:tns='http://jbpm.org/bpel/examples'>" +
52     " <b on=\"true\">true</b>" +
53     " <c name=\"venus\"/>" +
54     " <d amount=\"20\"/>" +
55     " <e>30</e>" +
56     " </tns:surpriseElement>" +
57     " </elementPart>" +
58     "</vendor:msg0>";
59   private static final QName JavaDoc Q_NAME_PROP = new QName JavaDoc(BpelConstants.NS_EXAMPLES, "nameProperty");
60   private static final QName JavaDoc Q_ID_PROP = new QName JavaDoc(BpelConstants.NS_EXAMPLES, "idProperty");
61
62   public MessageVariableTest(String JavaDoc name) {
63     super(name);
64   }
65
66   protected void setUp() throws Exception JavaDoc {
67     // read wsdl
68
Definition def = WsdlUtil.readText(WSDL_TEXT);
69     ImportsDefinition imports = new ImportsDefinition();
70     imports.addImport(WsdlUtil.createImport(def));
71     BpelReader.getInstance().registerPropertyAliases(imports);
72     // namespace declarations
73
namespaceDeclarations = def.getNamespaces();
74     namespaceDeclarations.remove(""); // remove default namespace association
75
// message variable
76
VariableDefinition variableDefinition = new VariableDefinition();
77     variableDefinition.setName("msg");
78     variableDefinition.setTypeInfo(imports.getMessageTypeInfo(new QName JavaDoc(BpelConstants.NS_EXAMPLES, "request")));
79     messageInstance = new MessageVariableInstance();
80     messageInstance.setDefinition(variableDefinition);
81   }
82
83   public void testGetSimplePart() throws Exception JavaDoc {
84     messageInstance.setMessage(NodeUtil.parseElement(MESSAGE_TEXT));
85     Element JavaDoc part = messageInstance.getPart("simplePart");
86     assertEquals("simplePart", part.getLocalName());
87     assertEquals(null, part.getNamespaceURI());
88     assertEquals("wawa", NodeUtil.getValue(part));
89   }
90
91   public void testGetElementPart() throws Exception JavaDoc {
92     messageInstance.setMessage(NodeUtil.parseElement(MESSAGE_TEXT));
93     Element JavaDoc part = messageInstance.getPart("elementPart");
94     assertEquals("surpriseElement", part.getLocalName());
95     assertEquals(BpelConstants.NS_EXAMPLES, part.getNamespaceURI());
96     assertNotNull(NodeUtil.getElement(part, "b"));
97     assertNotNull(NodeUtil.getElement(part, "c"));
98     assertNotNull(NodeUtil.getElement(part, "d"));
99     assertNotNull(NodeUtil.getElement(part, "e"));
100   }
101
102   public void testGetInvalidPart() {
103     try {
104       messageInstance.getPart("invalidPart");
105       fail("set part should have failed");
106     }
107     catch (RuntimeException JavaDoc e) {
108       // this exception is expected
109
}
110   }
111   
112   public void testSetSimplePart() {
113     messageInstance.setPart("simplePart", "wawa");
114     Element JavaDoc part = messageInstance.getPart("simplePart");
115     assertEquals("wawa", NodeUtil.getValue(part));
116   }
117   
118   public void testSetElementPart() throws Exception JavaDoc {
119     Element JavaDoc message = NodeUtil.parseElement(MESSAGE_TEXT);
120     Element JavaDoc partWrapper = NodeUtil.getElement(message, "elementPart");
121     Element JavaDoc partValue = NodeUtil.getElement(partWrapper, BpelConstants.NS_EXAMPLES, "surpriseElement");
122     messageInstance.setPart("elementPart", partValue);
123     Element JavaDoc part = messageInstance.getPart("elementPart");
124     assertNotNull(NodeUtil.getElement(part, "b"));
125     assertNotNull(NodeUtil.getElement(part, "c"));
126     assertNotNull(NodeUtil.getElement(part, "d"));
127     assertNotNull(NodeUtil.getElement(part, "e"));
128   }
129   
130   public void testGetAttributeProperty() throws Exception JavaDoc {
131     messageInstance.setMessage(NodeUtil.parseElement(MESSAGE_TEXT));
132     assertEquals("venus", messageInstance.getProperty(Q_NAME_PROP));
133   }
134   
135   public void testGetElementProperty() throws Exception JavaDoc {
136     messageInstance.setMessage(NodeUtil.parseElement(MESSAGE_TEXT));
137     assertEquals("30", messageInstance.getProperty(Q_ID_PROP));
138   }
139 }
140
Popular Tags