KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > bpel > service > exe > CorrelationSetTest


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

28 public class CorrelationSetTest extends TestCase {
29   
30   private CorrelationSetInstance correlationInstance;
31   private MessageVariableInstance messageInstance;
32
33   private static final String JavaDoc WSDL_TEXT =
34     "<definitions targetNamespace='http://jbpm.org/bpel/examples'" +
35     " xmlns:tns='http://jbpm.org/bpel/examples'" +
36     " xmlns:xsd='http://www.w3.org/2001/XMLSchema'" +
37     " xmlns:bpws='http://schemas.xmlsoap.org/ws/2004/03/business-process/'" +
38     " xmlns='http://schemas.xmlsoap.org/wsdl/'>" +
39     " <message name='request'>" +
40     " <part name='simplePart' type='xsd:string'/>" +
41     " <part name='elementPart' element='tns:surpriseElement'/>" +
42     " </message>" +
43     " <bpws:property name='nameProperty' type='xsd:string'/>" +
44     " <bpws:property name='idProperty' type='xsd:int'/>" +
45     " <bpws:propertyAlias propertyName='tns:nameProperty' messageType='tns:request'>" +
46     " <bpws:query>elementPart/tns:surpriseElement/c/@name</bpws:query>" +
47     " </bpws:propertyAlias>" +
48     " <bpws:propertyAlias propertyName='tns:idProperty' messageType='tns:request'>" +
49     " <bpws:query>elementPart/tns:surpriseElement/e</bpws:query>" +
50     " </bpws:propertyAlias>" +
51     "</definitions>";
52   private static final String JavaDoc ELEM_PART_TEXT =
53     "<tns:surpriseElement xmlns:tns='http://jbpm.org/bpel/examples'>" +
54     " <b on=\"true\">true</b>" +
55     " <c name=\"venus\"/>" +
56     " <d amount=\"20\"/>" +
57     " <e>30</e>" +
58     "</tns:surpriseElement>";
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 CorrelationSetTest(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     // message variable
73
VariableDefinition variableDefinition = new VariableDefinition();
74     variableDefinition.setName("msg");
75     variableDefinition.setTypeInfo(imports.getMessageTypeInfo(new QName JavaDoc(BpelConstants.NS_EXAMPLES, "request")));
76     messageInstance = new MessageVariableInstance();
77     messageInstance.setDefinition(variableDefinition);
78     // correlation set
79
CorrelationSetDefinition correlationDefinition = new CorrelationSetDefinition();
80     correlationDefinition.setName("cset");
81     Set JavaDoc properties = new HashSet JavaDoc();
82     properties.add(WsdlUtil.getProperty(def, Q_NAME_PROP));
83     properties.add(WsdlUtil.getProperty(def, Q_ID_PROP));
84     correlationDefinition.setProperties(properties);
85     // correlation set
86
correlationInstance = new CorrelationSetInstance();
87     correlationInstance.setDefinition(correlationDefinition);
88   }
89   
90   public void testGetProperty() {
91     HashMap JavaDoc propertyValues = new HashMap JavaDoc();
92     propertyValues.put(Q_NAME_PROP, "elle");
93     propertyValues.put(Q_ID_PROP, "1981");
94     correlationInstance.initialize(propertyValues);
95     assertEquals("elle", correlationInstance.getProperty(Q_NAME_PROP));
96   }
97   
98   public void testGetProperties() {
99     Set JavaDoc properties = correlationInstance.getDefinition().getProperties();
100     assertEquals(2, properties.size());
101   }
102
103   public void testInitializeMap() {
104     HashMap JavaDoc propertyValues = new HashMap JavaDoc();
105     propertyValues.put(Q_NAME_PROP, "elle");
106     propertyValues.put(Q_ID_PROP, "1981");
107     correlationInstance.initialize(propertyValues);
108     assertEquals(propertyValues, correlationInstance.getProperties());
109   }
110
111   public void testInitializeMessage() throws Exception JavaDoc {
112     Element JavaDoc partValue = NodeUtil.parseElement(ELEM_PART_TEXT);
113     messageInstance.setPart("elementPart", partValue);
114     
115     correlationInstance.initialize(messageInstance);
116     assertEquals("venus", correlationInstance.getProperty(Q_NAME_PROP));
117     assertEquals("30", correlationInstance.getProperty(Q_ID_PROP));
118   }
119
120   public void testValidConstraint() throws SAXException JavaDoc {
121     Element JavaDoc partValue = NodeUtil.parseElement(ELEM_PART_TEXT);
122     messageInstance.setPart("elementPart", partValue);
123     
124     HashMap JavaDoc propertyValues = new HashMap JavaDoc();
125     propertyValues.put(Q_NAME_PROP, "venus");
126     propertyValues.put(Q_ID_PROP, "30");
127     correlationInstance.initialize(propertyValues);
128     try {
129       correlationInstance.validateConstraint(messageInstance);
130     }
131     catch (RuntimeException JavaDoc e) {
132       fail(e.toString());
133     }
134   }
135   
136   public void testInvalidConstraint() throws SAXException JavaDoc {
137     Element JavaDoc partValue = NodeUtil.parseElement(ELEM_PART_TEXT);
138     messageInstance.setPart("elementPart", partValue);
139     
140     HashMap JavaDoc propertyValues = new HashMap JavaDoc();
141     propertyValues.put(Q_NAME_PROP, "elle");
142     propertyValues.put(Q_ID_PROP, "1981");
143     correlationInstance.initialize(propertyValues);
144     try {
145       correlationInstance.validateConstraint(messageInstance);
146       fail("constraint validation should throw an exception");
147     }
148     catch (RuntimeException JavaDoc e) {
149       // this exception is expected
150
}
151   }
152 }
153
Popular Tags