KickJava   Java API By Example, From Geeks To Geeks.

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


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.def.Sequence;
8 import org.jbpm.bpel.exe.AbstractExeTestCase;
9
10 /**
11  * @author Juan Cantú
12  * @version $Revision: 1.2 $ $Date: 2005/04/27 20:52:27 $
13  */

14 public class DPE1ExampleTest extends AbstractExeTestCase {
15   private Flow flow;
16   private Sequence s;
17   private Receive a;
18   private Receive b;
19   private Receive c;
20   private Receive x;
21   private Receive y;
22   
23   /* In the flow, the sequence S and the two receive activities X and Y are all
24    * concurrently enabled to start when the flow starts. Within S, after activity
25    * A is completed, B cannot start until the status of its incoming links from X
26    * and Y is determined and the implicit join condition is evaluated.
27    * When activities X and Y complete, the join condition for B is evaluated.
28    * Suppose that the expression P(X,B) OR P(Y,B) evaluates to false. */

29   
30   public void initActivities() {
31     s = (Sequence) flow.getNode("S");
32     a = (Receive) s.getNode("A");
33     b = (Receive) s.getNode("B");
34     c = (Receive) s.getNode("C");
35     x = (Receive) flow.getNode("X");
36     y = (Receive) flow.getNode("Y");
37   }
38   
39   /* The standard fault bpws:joinFailure will be thrown,
40    * because the environmental attribute suppressJoinFailure is set to "no".
41    * Thus the behavior of the flow is interrupted and neither B nor C will
42    * be performed. */

43   public void testFail() throws Exception JavaDoc {
44     flow = (Flow) readActivity(getClass().getResource("DPE1-Example.bpel"), false);
45     flow.setSuppressJoinFailure(Boolean.FALSE);
46     setNestedBlock(flow);
47     initActivities();
48     
49     Token startToken = startNested();
50     
51     //tokens for activities a, x, y where created upon activation. They must be
52
//waiting in their respective receive nodes
53
Token tokenS = findToken(startToken, a);
54     Token tokenX = findToken(startToken, x);
55     Token tokenY = findToken(startToken, y);
56
57     //activity a message is received, advances to b.
58
assertReceiveAndAdvance( tokenS, a, b );
59     //activity b is not executed due to its incoming sources
60
assertReceiveDisabled( tokenS, b );
61     
62     //activity x receives message and advances to the flow's end.
63
assertReceiveAndAdvance( tokenX, x, flow.getEnd() );
64     
65     try {
66       //activity y receives message. Join condition at b fails
67
y.messageReceived(y.getReceiver(), null, tokenY);
68     }
69     catch(RuntimeException JavaDoc e) {
70       assertReceiveDisabled( tokenS, b );
71       return;
72     }
73     fail("y must throw an error since join condition at b fails");
74   }
75
76   public void testInitialFail() throws Exception JavaDoc {
77     flow = (Flow) readActivity(getClass().getResource("DPE1-Example.bpel"), true);
78     flow.setSuppressJoinFailure(Boolean.FALSE);
79     setRootBlock(flow);
80     initActivities();
81     a.setCreateInstance(true);
82     
83     Token startToken = startInitial(a.getReceiver());
84     
85     //first receive was started, it must be at b.
86
Token tokenS = findToken(startToken, b);
87     assertNotNull( tokenS );
88     //activity b is not executed due to its unresolved targets
89
assertReceiveDisabled( tokenS, b );
90     
91     //tokens for activities x, y where created upon activation. They must be
92
//waiting in their respective receive nodes
93
Token tokenX = findToken(startToken, x);
94     Token tokenY = findToken(startToken, y);
95
96     //activity x receives message and advances to the flow's end.
97
assertReceiveAndAdvance( tokenX, x, flow.getEnd() );
98     
99     try {
100       //activity y receives message. Join condition at b fails
101
y.messageReceived(y.getReceiver(), null, tokenY);
102     }
103     catch(RuntimeException JavaDoc e) {
104       assertReceiveDisabled( tokenS, b );
105       return;
106     }
107     fail("y must throw an error since join condition at b fails");
108   }
109   
110   /* The environmental attribute suppressJoinFailure is set to "yes".
111    * B will be skipped but C will be performed because the bpws:joinFailure
112    * will be suppressed by the implicit scope associated with B.*/

113   
114   public void testSuppress() throws Exception JavaDoc {
115     flow = (Flow) readActivity(getClass().getResource("DPE1-Example.bpel"), false);
116     flow.setSuppressJoinFailure(Boolean.TRUE);
117     setNestedBlock(flow);
118     initActivities();
119     
120     Token startToken = startNested();
121     
122     //tokens for activities a, x, y where created upon activation. They must be
123
//waiting in their respective receive nodes
124
Token tokenS = findToken(startToken, a); //getChild(startName + BpelReader.TRANSITION + s.getName());
125
Token tokenX = findToken(startToken, x);//startToken.getChild(startName + BpelReader.TRANSITION + x.getName());
126
Token tokenY = findToken(startToken, y);//startToken.getChild(startName + BpelReader.TRANSITION + y.getName());
127

128     //activity a message is received, advances to b.
129
assertReceiveAndAdvance( tokenS, a, b );
130     //activity b is not executed due to its incoming sources
131
assertReceiveDisabled( tokenS, b );
132     
133     //activity x receives message and advances to the flow's end.
134
assertReceiveAndAdvance( tokenX, x, flow.getEnd() );
135     //activity y receives message and advances to the flow's end. b join failure suppressed.
136
assertReceiveAndAdvance( tokenY, y, flow.getEnd() );
137     
138     //b was skipped and token must be at c.
139
assertReceiveDisabled( tokenS, b );
140     //complete the flow execution
141
assertReceiveAndComplete( tokenS, c );
142   }
143   
144
145
146   public void testInitialSuppress() throws Exception JavaDoc {
147     flow = (Flow) readActivity(getClass().getResource("DPE1-Example.bpel"), true);
148     flow.setSuppressJoinFailure(Boolean.TRUE);
149     setRootBlock(flow);
150     initActivities();
151     
152     a.setCreateInstance(true);
153     Token startToken = startInitial(a.getReceiver());
154     //first receive was started, it must be at b.
155
Token tokenS = findToken(startToken, b);
156     assertSame( b, tokenS.getNode() );
157     //activity b is not executed due to its unresolved targets
158
assertReceiveDisabled( tokenS, b );
159     
160     //tokens for activities x, y where created upon activation. They must be
161
//waiting in their respective receive nodes
162
Token tokenX = findToken(startToken, x);
163     Token tokenY = findToken(startToken, y);
164
165     //activity x receives message and advances to the flow's end.
166
assertReceiveAndAdvance( tokenX, x, flow.getEnd() );
167     //activity y receives message and advances to the flow's end. b join failure suppressed.
168
assertReceiveAndAdvance( tokenY, y, flow.getEnd() );
169     
170     //b was skipped and token must be at c.
171
assertReceiveDisabled( tokenS, b );
172     //complete the flow execution
173
assertReceiveAndComplete( tokenS, c );
174   }
175 }
176
Popular Tags