KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > bpel > data > xpath > GetVariablePropertyTest


1 package org.jbpm.bpel.data.xpath;
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.jaxen.Context;
11 import org.jaxen.ContextSupport;
12 import org.jaxen.FunctionCallException;
13 import org.jaxen.SimpleNamespaceContext;
14 import org.w3c.dom.Document JavaDoc;
15 import org.w3c.dom.Element JavaDoc;
16
17 import org.jbpm.graph.exe.ProcessInstance;
18 import org.jbpm.graph.exe.Token;
19
20 import org.jbpm.bpel.data.def.MessageTypeInfo;
21 import org.jbpm.bpel.data.def.VariableDefinition;
22 import org.jbpm.bpel.data.exe.MessageVariableInstance;
23 import org.jbpm.bpel.def.BpelDefinition;
24 import org.jbpm.bpel.def.ImportsDefinition;
25 import org.jbpm.bpel.wsdl.util.WsdlUtil;
26 import org.jbpm.bpel.xml.BpelConstants;
27 import org.jbpm.bpel.xml.BpelReader;
28
29 /**
30  * @author Alejandro Guízar
31  * @version $Revision: 1.4 $ $Date: 2005/06/23 02:17:27 $
32  */

33 public class GetVariablePropertyTest extends TestCase {
34   
35   private MessageVariableInstance messageInstance;
36   private Context context;
37
38   private static final String JavaDoc WSDL_TEXT =
39     "<definitions targetNamespace='http://jbpm.org/bpel/examples'" +
40     " xmlns:tns='http://jbpm.org/bpel/examples'" +
41     " xmlns:xsd='http://www.w3.org/2001/XMLSchema'" +
42     " xmlns:bpws='http://schemas.xmlsoap.org/ws/2004/03/business-process/'" +
43     " xmlns='http://schemas.xmlsoap.org/wsdl/'>" +
44     " <message name='request'>" +
45     " <part name='simplePart' type='xsd:string'/>" +
46     " <part name='elementPart' element='tns:surpriseElement'/>" +
47     " </message>" +
48     " <bpws:property name='nameProperty' type='xsd:string'/>" +
49     " <bpws:property name='idProperty' type='xsd:int'/>" +
50     " <bpws:propertyAlias propertyName='tns:nameProperty' messageType='tns:request'>" +
51     " <bpws:query>elementPart/tns:surpriseElement/c/@name</bpws:query>" +
52     " </bpws:propertyAlias>" +
53     " <bpws:propertyAlias propertyName='tns:idProperty' messageType='tns:request'>" +
54     " <bpws:query>elementPart/tns:surpriseElement/e</bpws:query>" +
55     " </bpws:propertyAlias>" +
56     "</definitions>";
57   
58   public GetVariablePropertyTest(String JavaDoc name) {
59     super(name);
60   }
61   
62   protected void setUp() throws Exception JavaDoc {
63     // process and context
64
BpelDefinition pd = new BpelDefinition();
65     Token token = new ProcessInstance(pd).getRootToken();
66     // read wsdl
67
Definition def = WsdlUtil.readText(WSDL_TEXT);
68     ImportsDefinition imports = pd.getImports();
69     imports.addImport(WsdlUtil.createImport(def));
70     BpelReader.getInstance().registerPropertyAliases(imports);
71     // message variable
72
MessageTypeInfo typeInfo = imports.getMessageTypeInfo(new QName JavaDoc(BpelConstants.NS_EXAMPLES, "request"));
73     VariableDefinition messageDefinition = new VariableDefinition();
74     messageDefinition.setName("msg");
75     messageDefinition.setTypeInfo(typeInfo);
76     messageInstance = (MessageVariableInstance) messageDefinition.createInstance(token);
77     // jaxen context
78
ContextSupport sup = new ContextSupport();
79     sup.setVariableContext(new ScopeVariables(token));
80     // namespace declarations
81
Map JavaDoc namespaceDeclarations = def.getNamespaces();
82     // remove default namespace association
83
namespaceDeclarations.remove("");
84     sup.setNamespaceContext(new SimpleNamespaceContext(namespaceDeclarations));
85     context = new Context(sup);
86   }
87
88   public void testEvaluateAttribute() throws FunctionCallException {
89     Element JavaDoc elementPart = messageInstance.getOrCreatePart("elementPart");
90     Document JavaDoc doc = elementPart.getOwnerDocument();
91     Element JavaDoc elemC = (Element JavaDoc) elementPart.appendChild(doc.createElementNS(null, "c"));
92     elemC.setAttribute("name", "wazabi");
93     assertEquals("wazabi", GetVariablePropertyFunction.evaluate("msg", "tns:nameProperty", context));
94   }
95   
96   public void testEvaluateElement() throws FunctionCallException {
97     Element JavaDoc elementPart = messageInstance.getOrCreatePart("elementPart");
98     Document JavaDoc doc = elementPart.getOwnerDocument();
99     Element JavaDoc elemE = (Element JavaDoc) elementPart.appendChild(doc.createElementNS(null, "e"));
100     elemE.appendChild(doc.createTextNode("30"));
101     assertEquals("30", GetVariablePropertyFunction.evaluate("msg", "tns:idProperty", context));
102   }
103 }
104
Popular Tags