KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > bpel > exe > FlowExeTest


1 package org.jbpm.bpel.exe;
2
3 import org.jbpm.graph.exe.Token;
4
5 import org.jbpm.bpel.def.Flow;
6 import org.jbpm.bpel.def.Receive;
7
8 /**
9  * @author Juan Cantú
10  * @version $Revision: 1.5 $ $Date: 2005/06/16 19:15:44 $
11  */

12 public class FlowExeTest extends AbstractExeTestCase {
13   Flow flow;
14   Receive receiveA;
15   Receive receiveB;
16   Receive receiveC;
17   
18   String JavaDoc xml =
19     "<flow>" +
20       " <receive name='a' partnerLink='aPartner' operation='o'/>" +
21       " <receive name='b' partnerLink='aPartner' operation='o'/>" +
22       " <receive name='c' partnerLink='aPartner' operation='o'/>" +
23     "</flow>";
24   
25   public void testInitialFirstScenario() throws Exception JavaDoc {
26     flow = (Flow) readActivity(xml, true);
27     setRootBlock(flow);
28     validateInitial("a", "b", "c");
29   }
30   
31   public void testInitialSecondScenario() throws Exception JavaDoc {
32     flow = (Flow) readActivity(xml, true);
33     setRootBlock(flow);
34     validateInitial("b", "a", "c");
35   }
36   
37   public void testInitialThirdScenario() throws Exception JavaDoc {
38     flow = (Flow) readActivity(xml, true);
39     setRootBlock(flow);
40     validateInitial("c", "a", "b");
41   }
42   
43   public void testNestedFirstScenario() throws Exception JavaDoc {
44     flow = (Flow) readActivity(xml, false);
45     setNestedBlock(flow);
46     validateNested("a", "b", "c");
47   }
48   
49   public void testNestedSecondScenario() throws Exception JavaDoc {
50     flow = (Flow) readActivity(xml, false);
51     setNestedBlock(flow);
52     validateNested("b", "a", "c");
53   }
54   
55   public void testNestedThirdScenario() throws Exception JavaDoc {
56     flow = (Flow) readActivity(xml, false);
57     setNestedBlock(flow);
58     validateNested("c", "a", "b");
59   }
60   
61   public void initActivities(String JavaDoc a, String JavaDoc b, String JavaDoc c, boolean initial) {
62     receiveA = (Receive) flow.getNode(a);
63     if(initial) receiveA.setCreateInstance(true);
64     receiveB = (Receive) flow.getNode(b);
65     receiveC = (Receive) flow.getNode(c);
66   }
67   
68   public void validateInitial(String JavaDoc a, String JavaDoc b, String JavaDoc c) {
69     initActivities(a, b, c, true);
70     Token parent = startInitial(receiveA.getReceiver());
71     
72     Token tokenA = parent.getChild(receiveA.getName());
73     //tokenA must be waiting at the flow end for tokenB and tokenC
74
assertSame( flow.getEnd() , tokenA.getNode() );
75     
76     //tokenB and tokenC where created upon activation. They must be
77
//waiting in their respective receive nodes.
78
Token tokenB = parent.getChild(receiveB.getName());
79     Token tokenC = parent.getChild(receiveC.getName());
80     
81     //tokenB is triggered. It must move to the flow's end.
82
assertReceiveAndAdvance(tokenB, receiveB, flow.getEnd());
83
84     //tokenC is triggered. The process instance is completed.
85
assertReceiveAndComplete(tokenC, receiveC);
86   }
87   
88   public void validateNested(String JavaDoc a, String JavaDoc b, String JavaDoc c) {
89     initActivities(a, b, c, false);
90     Token startToken = startNested();
91     
92     //tokenA, tokenB and tokenC where created upon activation. They must be
93
//waiting in their respective receive nodes
94
Token tokenA = startToken.getChild(a);
95     Token tokenB = startToken.getChild(b);
96     Token tokenC = startToken.getChild(c);
97   
98     //tokenA is triggered. It must move to the flow's end.
99
assertReceiveAndAdvance(tokenA, receiveA, flow.getEnd());
100     
101     //tokenB is triggered. It must move to the flow's end.
102
assertReceiveAndAdvance(tokenB, receiveB, flow.getEnd());
103
104     //tokenC is triggered. The process instance is completed.
105
assertReceiveAndComplete(tokenC, receiveC);
106   }
107 }
108
Popular Tags