KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > bpel > def > assign > FromExpressionTest


1 package org.jbpm.bpel.def.assign;
2
3 import java.util.HashMap JavaDoc;
4 import java.util.Map JavaDoc;
5
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.context.def.ContextDefinition;
13 import org.jbpm.graph.def.ProcessDefinition;
14 import org.jbpm.graph.exe.ProcessInstance;
15 import org.jbpm.graph.exe.Token;
16
17 import org.jbpm.bpel.data.def.ElementTypeInfo;
18 import org.jbpm.bpel.data.def.Snippet;
19 import org.jbpm.bpel.data.def.VariableDefinition;
20 import org.jbpm.bpel.xml.BpelConstants;
21 import org.jbpm.bpel.xml.BpelException;
22 import org.jbpm.bpel.xml.util.NodeUtil;
23
24 /**
25  * @author Alejandro Guízar
26  * @version $Revision: 1.6 $ $Date: 2005/06/23 02:17:26 $
27  */

28 public class FromExpressionTest extends TestCase {
29
30   private FromExpression from = new FromExpression();
31   private Token token;
32   private Map JavaDoc namespaceDeclarations;
33   
34   private static final String JavaDoc ELEM1_TEXT =
35     "<a>" +
36     " <b on=\"true\">true</b>" +
37     " <c name=\"venus\"/>" +
38     " <d amount=\"20\"/>" +
39     " <e>30</e>" +
40     "</a>";
41   private static final String JavaDoc ELEM2_TEXT =
42     "<a>" +
43     " <b on=\"\"/>" +
44     " <c name=\"mars\"/>" +
45     " <d amount=\"30\"/>" +
46     " <e>40</e>" +
47     "</a>";
48   
49   public FromExpressionTest(String JavaDoc name) {
50     super(name);
51   }
52   
53   protected void setUp() throws Exception JavaDoc {
54     // process and context
55
ProcessDefinition pd = new ProcessDefinition();
56     pd.addDefinition(new ContextDefinition());
57     ProcessInstance pi = new ProcessInstance(pd);
58     token = pi.getRootToken();
59     // element variables
60
Element JavaDoc elem1 = NodeUtil.parseElement(ELEM1_TEXT);
61     VariableDefinition var1 = new VariableDefinition();
62     var1.setName("var1");
63     var1.setTypeInfo(new ElementTypeInfo(new QName JavaDoc(elem1.getNamespaceURI(), elem1.getLocalName())));
64     var1.createInstance(token).setValue(elem1);
65     Element JavaDoc elem2 = NodeUtil.parseElement(ELEM2_TEXT);
66     VariableDefinition var2 = new VariableDefinition();
67     var2.setName("var2");
68     var2.setTypeInfo(new ElementTypeInfo(new QName JavaDoc(elem2.getNamespaceURI(), elem2.getLocalName())));
69     var2.createInstance(token).setValue(elem2);
70     // enclosing element
71
namespaceDeclarations = new HashMap JavaDoc();
72     namespaceDeclarations.put("bpws", BpelConstants.NS_BPWS_1_1);
73   }
74
75   public void testExtract() {
76     try {
77       Snippet expr = new Snippet();
78       expr.setText("concat(bpws:getVariableData('var1')/c/@name, 'and', bpws:getVariableData('var2')/c/@name)");
79       expr.setUse(Snippet.Use.EXPRESSION);
80       expr.setNamespaces(namespaceDeclarations);
81       expr.parseScript();
82       from.setExpression(expr);
83       assertEquals("venusandmars", from.extract(token));
84     }
85     catch (BpelException e) {
86       fail(e.getMessage());
87     }
88   }
89 }
90
Popular Tags