KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > jpdl > patterns > Wfp10NOutOfMJoin


1 package org.jbpm.jpdl.patterns;
2
3 import junit.framework.*;
4 import org.jbpm.graph.def.*;
5 import org.jbpm.graph.exe.*;
6 import org.jbpm.graph.node.*;
7
8 public class Wfp10NOutOfMJoin extends TestCase {
9
10   private static ProcessDefinition nOutOfMProcessDefinition = createNOutOfMProcessDefinition();
11
12   public static ProcessDefinition createNOutOfMProcessDefinition() {
13     ProcessDefinition pd = new ProcessDefinition(
14       new String JavaDoc[]{"start-state start",
15                    "state a",
16                    "fork fork",
17                    "state b",
18                    "state c",
19                    "state d",
20                    "join noutofm",
21                    "state e"},
22       new String JavaDoc[]{"start --> a",
23                    "a --> fork",
24                    "fork --b--> b",
25                    "fork --c--> c",
26                    "fork --d--> d",
27                    "b --> noutofm",
28                    "c --> noutofm",
29                    "d --> noutofm",
30                    "noutofm --> e"});
31     
32     // put the script in the multichoice handler
33
Join nOutOfMJoin = (Join) pd.getNode("noutofm");
34     nOutOfMJoin.setNOutOfM( 2 );
35
36     return pd;
37   }
38
39
40   public void testNOutOfMScenario1() {
41     ProcessDefinition pd = nOutOfMProcessDefinition;
42     Token root = startNOutOfMScenario(pd);
43     Token tokenB = root.getChild("b");
44     Token tokenC = root.getChild("c");
45     Token tokenD = root.getChild("d");
46     
47     tokenB.signal();
48     assertSame( pd.getNode("fork"), root.getNode() );
49     assertSame( pd.getNode("noutofm"), tokenB.getNode() );
50     assertSame( pd.getNode("c"), tokenC.getNode() );
51     assertSame( pd.getNode("d"), tokenD.getNode() );
52
53     tokenC.signal();
54     assertSame( pd.getNode("e"), root.getNode() );
55     assertSame( pd.getNode("noutofm"), tokenB.getNode() );
56     assertSame( pd.getNode("noutofm"), tokenC.getNode() );
57     assertSame( pd.getNode("d"), tokenD.getNode() );
58
59     tokenD.signal();
60     assertSame( pd.getNode("e"), root.getNode() );
61     assertSame( pd.getNode("noutofm"), tokenB.getNode() );
62     assertSame( pd.getNode("noutofm"), tokenC.getNode() );
63     assertSame( pd.getNode("noutofm"), tokenD.getNode() );
64   }
65   
66   public void testNOutOfMScenario2() {
67     ProcessDefinition pd = nOutOfMProcessDefinition;
68     Token root = startNOutOfMScenario(pd);
69     Token tokenB = root.getChild("b");
70     Token tokenC = root.getChild("c");
71     Token tokenD = root.getChild("d");
72     
73     tokenC.signal();
74     assertSame( pd.getNode("fork"), root.getNode() );
75     assertSame( pd.getNode("b"), tokenB.getNode() );
76     assertSame( pd.getNode("noutofm"), tokenC.getNode() );
77     assertSame( pd.getNode("d"), tokenD.getNode() );
78
79     tokenB.signal();
80     assertSame( pd.getNode("e"), root.getNode() );
81     assertSame( pd.getNode("noutofm"), tokenB.getNode() );
82     assertSame( pd.getNode("noutofm"), tokenC.getNode() );
83     assertSame( pd.getNode("d"), tokenD.getNode() );
84
85     tokenD.signal();
86     assertSame( pd.getNode("e"), root.getNode() );
87     assertSame( pd.getNode("noutofm"), tokenB.getNode() );
88     assertSame( pd.getNode("noutofm"), tokenC.getNode() );
89     assertSame( pd.getNode("noutofm"), tokenD.getNode() );
90   }
91
92   public void testNOutOfMScenario3() {
93     ProcessDefinition pd = nOutOfMProcessDefinition;
94     Token root = startNOutOfMScenario(pd);
95     Token tokenB = root.getChild("b");
96     Token tokenC = root.getChild("c");
97     Token tokenD = root.getChild("d");
98     
99     tokenC.signal();
100     assertSame( pd.getNode("fork"), root.getNode() );
101     assertSame( pd.getNode("b"), tokenB.getNode() );
102     assertSame( pd.getNode("noutofm"), tokenC.getNode() );
103     assertSame( pd.getNode("d"), tokenD.getNode() );
104
105     tokenD.signal();
106     assertSame( pd.getNode("e"), root.getNode() );
107     assertSame( pd.getNode("b"), tokenB.getNode() );
108     assertSame( pd.getNode("noutofm"), tokenC.getNode() );
109     assertSame( pd.getNode("noutofm"), tokenD.getNode() );
110
111     tokenB.signal();
112     assertSame( pd.getNode("e"), root.getNode() );
113     assertSame( pd.getNode("noutofm"), tokenB.getNode() );
114     assertSame( pd.getNode("noutofm"), tokenC.getNode() );
115     assertSame( pd.getNode("noutofm"), tokenD.getNode() );
116   }
117   
118   public static Token startNOutOfMScenario(ProcessDefinition pd) {
119     ProcessInstance pi = new ProcessInstance( pd );
120     pi.signal();
121     Token root = pi.getRootToken();
122     root.signal();
123     return root;
124   }
125 }
126
Popular Tags