KickJava   Java API By Example, From Geeks To Geeks.

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


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.jaxen.dom.DocumentNavigator;
15 import org.w3c.dom.Attr JavaDoc;
16 import org.w3c.dom.Element JavaDoc;
17
18 import org.jbpm.graph.exe.ProcessInstance;
19 import org.jbpm.graph.exe.Token;
20
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.util.NodeUtil;
28
29 /**
30  * @author Alejandro Guízar
31  * @version $Revision: 1.3 $ $Date: 2005/06/23 02:17:27 $
32  */

33 public class GetVariableDataTest extends TestCase {
34
35   private MessageVariableInstance messageInstance;
36   private Context context;
37   private Map JavaDoc namespaceDeclarations;
38   
39   private static final String JavaDoc WSDL_TEXT =
40     "<definitions targetNamespace='http://jbpm.org/bpel/examples'" +
41     " xmlns:tns='http://jbpm.org/bpel/examples'" +
42     " xmlns:xsd='http://www.w3.org/2001/XMLSchema'" +
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     "</definitions>";
49   private static final String JavaDoc ELEM_PART_TEXT =
50     "<tns:surpriseElement xmlns:tns='http://jbpm.org/bpel/examples'>" +
51     " <b on=\"true\">true</b>" +
52     " <c name=\"venus\"/>" +
53     " <d amount=\"20\"/>" +
54     " <e>30</e>" +
55     "</tns:surpriseElement>";
56   
57   public GetVariableDataTest(String JavaDoc name) {
58     super(name);
59   }
60   
61   protected void setUp() throws Exception JavaDoc {
62     // process and context
63
BpelDefinition pd = new BpelDefinition();
64     ProcessInstance pi = new ProcessInstance(pd);
65     Token token = pi.getRootToken();
66     // message definition
67
Definition def = WsdlUtil.readText(WSDL_TEXT);
68     ImportsDefinition imports = pd.getImports();
69     imports.addImport(WsdlUtil.createImport(def));
70     // message variable
71
VariableDefinition messageDefinition = new VariableDefinition();
72     messageDefinition.setName("msg");
73     messageDefinition.setTypeInfo(imports.getMessageTypeInfo(new QName JavaDoc(BpelConstants.NS_EXAMPLES, "request")));
74     messageInstance = (MessageVariableInstance) messageDefinition.createInstance(token);
75     // namespace declarations
76
namespaceDeclarations = def.getNamespaces();
77     namespaceDeclarations.remove("");
78     // jaxen context
79
ContextSupport sup = new ContextSupport(new SimpleNamespaceContext(namespaceDeclarations),
80         null, new ScopeVariables(token), DocumentNavigator.getInstance());
81     context = new Context(sup);
82   }
83
84   public void testEvaluateVariable() throws FunctionCallException {
85     messageInstance.setMessage(MessageVariableInstance.createMessageElement());
86     assertSame(messageInstance.getValue(), GetVariableDataFunction.evaluate("msg", context));
87   }
88
89   public void testEvaluateSimplePart() throws FunctionCallException {
90     Element JavaDoc simplePart = messageInstance.getOrCreatePart("simplePart");
91     assertSame(simplePart, GetVariableDataFunction.evaluate("msg", "simplePart", context));
92   }
93   
94   public void testEvaluateElementPart() throws FunctionCallException {
95     Element JavaDoc elementPart = messageInstance.getOrCreatePart("elementPart");
96     assertSame(elementPart, GetVariableDataFunction.evaluate("msg", "elementPart", context));
97   }
98
99   public void testEvaluateAttributeLocation() throws Exception JavaDoc {
100     Element JavaDoc partValue = NodeUtil.parseElement(ELEM_PART_TEXT);
101     messageInstance.setPart("elementPart", partValue);
102     Element JavaDoc c = NodeUtil.getElement(messageInstance.getPart("elementPart"), "c");
103     Attr JavaDoc nameAttr = c.getAttributeNode("name");
104     Object JavaDoc data = GetVariableDataFunction.evaluate("msg", "elementPart", "/tns:surpriseElement/c/@name", context);
105     assertSame(nameAttr, data);
106   }
107   
108   public void testEvaluateElementLocation() throws Exception JavaDoc {
109     Element JavaDoc partValue = NodeUtil.parseElement(ELEM_PART_TEXT);
110     messageInstance.setPart("elementPart", partValue);
111     Element JavaDoc e = NodeUtil.getElement(messageInstance.getPart("elementPart"), "e");
112     Object JavaDoc data = GetVariableDataFunction.evaluate("msg", "elementPart", "/tns:surpriseElement/e", context);
113     assertSame(e, data);
114   }
115 }
116
Popular Tags