KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > bpel > exe > flow > DPE2ExampleTest


1 package org.jbpm.bpel.exe.flow;
2
3 import org.jbpm.graph.exe.Token;
4
5 import org.jbpm.bpel.def.Flow;
6 import org.jbpm.bpel.def.Receive;
7 import org.jbpm.bpel.exe.AbstractExeTestCase;
8
9 /**
10  * @author Juan Cantú
11  * @version $Revision: 1.2 $ $Date: 2005/04/27 20:52:27 $
12  */

13 public class DPE2ExampleTest extends AbstractExeTestCase {
14   private Flow flow;
15   private Receive a;
16   private Receive b;
17   private Receive c;
18   private Receive x;
19   private Receive y;
20   
21   /* In the flow, five receive activities A, B, C, X and Y are all concurrently enabled
22    * to start when the flow starts. A, B, and C are connected through links
23    * (with transition conditions with constant truth-value of "true") instead of putting
24    * them into a sequence. B cannot start until the status of its incoming links from X
25    * and Y is determined and the implicit join condition is evaluated.
26    * B and thus C will always be performed. Because the join condition is a disjunction
27    * and the transition condition of link AtoB is the constant "true", the join condition
28    * will always evaluate "true", independent from the values of X and Y targets*/

29   
30   public void initActivities() {
31     a = (Receive) flow.getNode("A");
32     b = (Receive) flow.getNode("B");
33     c = (Receive) flow.getNode("C");
34     x = (Receive) flow.getNode("X");
35     y = (Receive) flow.getNode("Y");
36   }
37   
38   public void testFail() throws Exception JavaDoc {
39     flow = (Flow) readActivity(getClass().getResource("DPE2-Example.bpel"), false);
40     flow.setSuppressJoinFailure(Boolean.FALSE);
41     setNestedBlock(flow);
42     assertExecution();
43   }
44   
45   public void testSuppress() throws Exception JavaDoc {
46     flow = (Flow) readActivity(getClass().getResource("DPE2-Example.bpel"), false);
47     flow.setSuppressJoinFailure(Boolean.TRUE);
48     setNestedBlock(flow);
49     assertExecution();
50   }
51   
52   public void testInitialFail() throws Exception JavaDoc {
53     flow = (Flow) readActivity(getClass().getResource("DPE2-Example.bpel"), true);
54     flow.setSuppressJoinFailure(Boolean.FALSE);
55     setRootBlock(flow);
56     assertInitialExecution();
57   }
58   
59   public void testInitialSuppress() throws Exception JavaDoc {
60     flow = (Flow) readActivity(getClass().getResource("DPE2-Example.bpel"), true);
61     flow.setSuppressJoinFailure(Boolean.FALSE);
62     setRootBlock(flow);
63     assertInitialExecution();
64   }
65   
66   public void assertExecution() throws Exception JavaDoc {
67     initActivities();
68     Token startToken = startNested();
69     
70     //tokens for activities a, b, c, x, y where created upon activation. They must be
71
//waiting in their respective receive nodes
72
Token tokenA = findToken(startToken, a);
73     Token tokenB = findToken(startToken, b);
74     Token tokenC = findToken(startToken, c);
75     Token tokenX = findToken(startToken, x);
76     Token tokenY = findToken(startToken, y);
77     
78     //activity a message is received, advances to b.
79
assertReceiveAndAdvance( tokenA, a, flow.getEnd() );
80     //activity b is not executed due to its incoming sources
81
assertReceiveDisabled( tokenB, b );
82     
83     //activity x receives message and advances to the flow's end.
84
assertReceiveAndAdvance( tokenX, x, flow.getEnd() );
85     //activity y receives message and advances to the flow's end. All the links of b are
86
//determined.
87
assertReceiveAndAdvance( tokenY, y, flow.getEnd() );
88     //b is ready to advance.
89
assertReceiveAndAdvance( tokenB, b, flow.getEnd() );
90     
91     //complete the flow execution
92
assertReceiveAndComplete( tokenC, c );
93   }
94   
95   public void assertInitialExecution() throws Exception JavaDoc {
96     initActivities();
97     a.setCreateInstance(true);
98     Token startToken = startInitial(a.getReceiver());
99     //first receive was started, it must be at flow's end.
100
// TODO remove this search?
101
// Token tokenA = findToken(startToken, flow.getEnd());
102

103     //tokens for activities b, c, x, y where created upon activation.
104
Token tokenB = findToken(startToken, b);
105     //activity b is not executed due to its unresolved targets
106
assertReceiveDisabled( tokenB, b );
107     
108     Token tokenC = findToken(startToken, c);
109     Token tokenX = findToken(startToken, x);
110     Token tokenY = findToken(startToken, y);
111     
112     //activity x receives message and advances to the flow's end.
113
assertReceiveAndAdvance( tokenX, x, flow.getEnd() );
114     //activity y receives message and advances to the flow's end. All the links of b are
115
//determined.
116
assertReceiveAndAdvance( tokenY, y, flow.getEnd() );
117     //b is ready to advance.
118
assertReceiveAndAdvance( tokenB, b, flow.getEnd() );
119     
120     //complete the flow execution
121
assertReceiveAndComplete( tokenC, c );
122   }
123 }
124
Popular Tags