KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.jbpm.bpel.data.exe;
2
3 import java.util.HashMap JavaDoc;
4 import java.util.Map JavaDoc;
5
6 import junit.framework.TestCase;
7
8 import org.jbpm.context.def.ContextDefinition;
9 import org.jbpm.graph.def.ProcessDefinition;
10 import org.jbpm.graph.exe.ProcessInstance;
11 import org.jbpm.graph.exe.Token;
12
13 import org.jbpm.bpel.data.def.Snippet;
14 import org.jbpm.bpel.def.Empty;
15 import org.jbpm.bpel.def.Link;
16 import org.jbpm.bpel.exe.LinkInstance;
17 import org.jbpm.bpel.xml.BpelConstants;
18 import org.jbpm.bpel.xml.BpelException;
19 import org.jbpm.bpel.xml.util.DatatypeUtil;
20
21 /**
22  * @author Juan Cantú
23  * @version $Revision: 1.5 $ $Date: 2005/06/23 02:17:26 $
24  */

25 public class JoinConditionTest extends TestCase {
26   private Token token;
27   private LinkInstance firstLink;
28   private LinkInstance secondLink;
29   private LinkInstance thirdLink;
30   private Map JavaDoc namespaceDeclarations;
31   
32   public void setUp() throws Exception JavaDoc {
33     // process and context
34
ProcessDefinition pd = new ProcessDefinition();
35     pd.addDefinition(new ContextDefinition());
36     ProcessInstance pi = new ProcessInstance(pd);
37     token = pi.getRootToken();
38     
39     Empty activity = new Empty("activity");
40     token.setNode(activity);
41
42     activity.addTarget(new Link("l1"));
43     firstLink = LinkInstance.create(token, "l1");
44     
45     activity.addTarget(new Link("l2"));
46     secondLink = LinkInstance.create(token, "l2");
47     
48     activity.addTarget(new Link("l3"));
49     thirdLink = LinkInstance.create(token, "l3");
50     
51     // enclosing element
52
namespaceDeclarations = new HashMap JavaDoc();
53     namespaceDeclarations.put("bpws", BpelConstants.NS_BPWS_1_1);
54   }
55   
56   public void testSimpleEval() {
57     firstLink.setReached(Boolean.TRUE);
58     assertTrue(eval("$l1"));
59   }
60   
61   public void testSimpleFunctionEval() {
62     firstLink.setReached(Boolean.TRUE);
63     assertTrue(eval("bpws:getLinkStatus('l1')"));
64   }
65   
66   public void testOrEval() {
67     firstLink.setReached(Boolean.FALSE);
68     secondLink.setReached(Boolean.TRUE);
69     assertTrue(eval("$l1 or $l2"));
70   }
71   
72   public void testAndEval() {
73     firstLink.setReached(Boolean.FALSE);
74     secondLink.setReached(Boolean.TRUE);
75     assertFalse(eval("bpws:getLinkStatus('l2') and $l1"));
76   }
77   
78   public void testEvalTrue() {
79     firstLink.setReached(Boolean.TRUE);
80     secondLink.setReached(Boolean.FALSE);
81     thirdLink.setReached(Boolean.TRUE);
82     assertTrue(eval("($l1 and $l2) or $l3"));
83   }
84   
85   public void testEvalFalse() {
86     firstLink.setReached(Boolean.TRUE);
87     secondLink.setReached(Boolean.FALSE);
88     thirdLink.setReached(Boolean.FALSE);
89     assertFalse(eval("(bpws:getLinkStatus('l3') or $l2) and $l1"));
90   }
91   
92   public void testEvalNull() {
93     firstLink.setReached(null);
94     assertNull(evalBoolean("$l1"));
95   }
96   
97   private boolean eval(String JavaDoc exprText) {
98     return evalBoolean(exprText).booleanValue();
99   }
100   
101   private Boolean JavaDoc evalBoolean(String JavaDoc exprText) {
102     Boolean JavaDoc value = null;
103     try {
104       Snippet expr = new Snippet();
105       expr.setText(exprText);
106       expr.setUse(Snippet.Use.JOIN_CONDITION);
107       expr.setNamespaces(namespaceDeclarations);
108       expr.parseScript();
109       value = DatatypeUtil.toBoolean(expr.getScript().evaluate(token));
110     }
111     catch (BpelException e) {
112       fail(e.getMessage());
113     }
114     return value;
115   }
116 }
117
Popular Tags