KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.jbpm.jpdl.patterns;
2
3 import junit.framework.*;
4
5 import org.jbpm.graph.def.*;
6 import org.jbpm.graph.exe.*;
7
8 /**
9  * http://is.tm.tue.nl/research/patterns/download/swf/pat_10.swf
10  */

11 public class Wfp11ArbitraryCyclesTest extends TestCase {
12   
13   private static ProcessDefinition arbitraryCycleProcessDefinition = createArbitraryCycleProcessDefinition();
14
15   public static ProcessDefinition createArbitraryCycleProcessDefinition() {
16     ProcessDefinition pd = new ProcessDefinition(
17       new String JavaDoc[]{"start-state start",
18                    "state a",
19                    "state b",
20                    "state c",
21                    "state d",
22                    "state e"},
23       new String JavaDoc[]{"start --> a",
24                    "a --> b",
25                    "b --> c",
26                    "c --forward--> d",
27                    "c --back--> b",
28                    "d --forward--> e",
29                    "d --back--> c"});
30     return pd;
31   }
32
33
34   public void testArbitraryCycleScenario1() {
35     ProcessDefinition pd = arbitraryCycleProcessDefinition;
36     ProcessInstance pi = new ProcessInstance(pd);
37     pi.signal();
38     Token root = pi.getRootToken();
39     root.signal();
40     assertSame( pd.getNode("b"), root.getNode() );
41     root.signal();
42     assertSame( pd.getNode("c"), root.getNode() );
43     root.signal("forward");
44     assertSame( pd.getNode("d"), root.getNode() );
45     root.signal("forward");
46     assertSame( pd.getNode("e"), root.getNode() );
47   }
48
49   public void testArbitraryCycleScenario2() {
50     ProcessDefinition pd = arbitraryCycleProcessDefinition;
51     ProcessInstance pi = new ProcessInstance(pd);
52     pi.signal();
53     Token root = pi.getRootToken();
54     root.signal();
55     assertSame( pd.getNode("b"), root.getNode() );
56     root.signal();
57     assertSame( pd.getNode("c"), root.getNode() );
58     root.signal("back");
59     assertSame( pd.getNode("b"), root.getNode() );
60     root.signal();
61     assertSame( pd.getNode("c"), root.getNode() );
62     root.signal("forward");
63     assertSame( pd.getNode("d"), root.getNode() );
64     root.signal("forward");
65     assertSame( pd.getNode("e"), root.getNode() );
66   }
67
68   public void testArbitraryCycleScenario3() {
69     ProcessDefinition pd = arbitraryCycleProcessDefinition;
70     ProcessInstance pi = new ProcessInstance(pd);
71     pi.signal();
72     Token root = pi.getRootToken();
73     root.signal();
74     assertSame( pd.getNode("b"), root.getNode() );
75     root.signal();
76     assertSame( pd.getNode("c"), root.getNode() );
77     root.signal("forward");
78     assertSame( pd.getNode("d"), root.getNode() );
79     root.signal("back");
80     assertSame( pd.getNode("c"), root.getNode() );
81     root.signal("forward");
82     assertSame( pd.getNode("d"), root.getNode() );
83     root.signal("forward");
84     assertSame( pd.getNode("e"), root.getNode() );
85   }
86
87   public void testArbitraryCycleScenario4() {
88     ProcessDefinition pd = arbitraryCycleProcessDefinition;
89     ProcessInstance pi = new ProcessInstance(pd);
90     pi.signal();
91     Token root = pi.getRootToken();
92     root.signal();
93     assertSame( pd.getNode("b"), root.getNode() );
94     root.signal();
95     assertSame( pd.getNode("c"), root.getNode() );
96     root.signal("back");
97     assertSame( pd.getNode("b"), root.getNode() );
98     root.signal();
99     assertSame( pd.getNode("c"), root.getNode() );
100     root.signal("forward");
101     assertSame( pd.getNode("d"), root.getNode() );
102     root.signal("back");
103     assertSame( pd.getNode("c"), root.getNode() );
104     root.signal("forward");
105     assertSame( pd.getNode("d"), root.getNode() );
106     root.signal("forward");
107     assertSame( pd.getNode("e"), root.getNode() );
108   }
109 }
110
Popular Tags