KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.jbpm.bpel.exe.LinkInstance;
9
10 /**
11  * @author Juan Cantú
12  * @version $Revision: 1.4 $ $Date: 2005/05/07 00:03:47 $
13  */

14 public class LinkScopingExampleTest extends AbstractExeTestCase {
15
16   private Flow f1;
17   private Flow f2;
18   private Receive r1;
19   private Receive r2;
20   private Receive nestedR1;
21   private Receive nestedR2;
22   
23   public void initActivities() {
24     f2 = (Flow) f1.getNode("F2");
25     r1 = (Receive) f1.getNode("R1");
26     r2 = (Receive) f1.getNode("R2");
27     nestedR1 = (Receive) f2.getNode("R1");
28     nestedR2 = (Receive) f2.getNode("R2");
29   }
30   
31   public void testNested() throws Exception JavaDoc {
32     f1 = (Flow)
33     readActivity(getClass().getResource("linkScopingExample.bpel"), false);
34     setNestedBlock(f1);
35     initActivities();
36     
37     Token startToken = startNested();
38     Token r1Token = findToken( startToken, r1 );
39     Token r2Token = findToken( startToken, r2 );
40     Token nestedR1Token = findToken( startToken, nestedR1 );
41     Token nestedR2Token = findToken( startToken, nestedR2 );
42     
43     assertReceiveDisabled( r2Token, r2 );
44     assertReceiveDisabled(nestedR2Token, nestedR2 );
45     
46     //r1 is started, it must move at the flow's end. r2 target link is determined.
47
assertReceiveAndAdvance(r1Token, r1, f1.getEnd());
48
49     //validate outer L1 link is determined and inner is unset
50
assertEquals(Boolean.FALSE, LinkInstance.get(r1Token, "L1").getReached());
51     assertEquals(null, LinkInstance.get(nestedR1Token, "L1").getReached());
52     
53     //r2 is not executed because its targets. it is skipped.
54
assertReceiveDisabled( r2Token, r2 );
55     assertReceiveDisabled( nestedR2Token, nestedR2 );
56     assertReceiveAndAdvance( nestedR1Token, nestedR1, f2.getEnd() );
57     assertReceiveAndComplete( nestedR2Token, nestedR2) ;
58   }
59   
60   public void testInitial() throws Exception JavaDoc {
61     f1 = (Flow)
62     readActivity(getClass().getResource("linkScopingExample.bpel"), true);
63     setRootBlock(f1);
64     initActivities();
65     nestedR1.setCreateInstance(true);
66     
67     Token startToken = startInitial( nestedR1.getReceiver() );
68     Token f2Token = startToken.getChild(f2.getName());
69     //nested r1 is started, it must be at the flow's end. nested r2 target is determined.
70
Token nestedR1Token = f2Token.getChild(nestedR1.getName());
71     assertSame( f2.getEnd(), nestedR1Token.getNode() );
72     
73     //validate inner L1 link is determined and outer is unset
74
assertEquals(Boolean.TRUE, LinkInstance.get(f2Token, "L1").getReached());
75     assertEquals(null, LinkInstance.get(startToken, "L1").getReached());
76
77     Token nestedR2Token = f2Token.getChild(nestedR2.getName());
78     //nested r2 receives message and moves to f1 end. (f2 flow is completed).
79
assertReceiveAndAdvance(nestedR2Token, nestedR2, f2.getEnd());
80     assertEquals(f1.getEnd(), f2Token.getNode());
81
82     Token r2Token = startToken.getChild(r2.getName());
83     //r2 receives haven't executed since its link (f1r1 is not yet resolved).
84
assertEquals(r2, r2Token.getNode());
85     assertReceiveDisabled( r2Token, r2 );
86     
87     Token r1Token = startToken.getChild(r1.getName());
88     assertReceiveAndComplete(r1Token, r1);
89     //r2 was skipped (never executed since r1 resolved this link as negative)
90
assertReceiveDisabled( r2Token, r2);
91   }
92 }
93
Popular Tags