KickJava   Java API By Example, From Geeks To Geeks.

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


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_5.swf
10  *
11  * <p>in jbpm every node has an implicit merge in front of it.
12  * so it's not necessary to use the merge node. in fact, i can
13  * not think of a situation where implicit merge nodeMap are not
14  * sufficient. for the sake of workflow patterns, we leave if in.
15  * jbpm supports merging of both alternative paths of execution
16  * and concurrent paths of execution.
17  * </p>
18  *
19  * <p>first the merge node is demonstrated exactly as in the pattern.
20  * then the implicit variant is demonstrated, then the merging of
21  * concurrent paths is demonstrated.
22  * </p>
23  */

24 public class Wfp05SimpleMergeTest extends TestCase {
25
26   private static ProcessDefinition simpleMergeProcessDefinition = createSimpleMergeProcessDefinition();
27   
28   public static ProcessDefinition createSimpleMergeProcessDefinition() {
29     ProcessDefinition pd = new ProcessDefinition(
30       new String JavaDoc[]{"start-state start",
31                    "state a",
32                    "state b",
33                    "merge xor",
34                    "state c"},
35       new String JavaDoc[]{"start --to a--> a",
36                    "start --to b--> b",
37                    "a --> xor",
38                    "b --> xor",
39                    "xor --> c"});
40     return pd;
41   }
42
43   public void testSimpleMergeScenario1() {
44     ProcessDefinition pd = simpleMergeProcessDefinition;
45     ProcessInstance pi = new ProcessInstance( pd );
46     pi.signal("to a");
47     Token root = pi.getRootToken();
48     assertSame( pd.getNode("a"), root.getNode() );
49     root.signal();
50     assertSame( pd.getNode("c"), root.getNode() );
51   }
52
53   public void testSimpleMergeScenario2() {
54     ProcessDefinition pd = simpleMergeProcessDefinition;
55     ProcessInstance pi = new ProcessInstance( pd );
56     pi.signal("to b");
57     Token root = pi.getRootToken();
58     assertSame( pd.getNode("b"), root.getNode() );
59     root.signal();
60     assertSame( pd.getNode("c"), root.getNode() );
61   }
62   
63   private static ProcessDefinition implicitMergeProcessDefinition = createImplicitMergeProcessDefinition();
64   
65   public static ProcessDefinition createImplicitMergeProcessDefinition() {
66     ProcessDefinition pd = new ProcessDefinition(
67       new String JavaDoc[]{"start-state start",
68                    "state a",
69                    "state b",
70                    "state c"},
71       new String JavaDoc[]{"start --to a--> a",
72                    "start --to b--> b",
73                    "a --> c",
74                    "b --> c"});
75     return pd;
76   }
77
78   public void testImplicitMergeScenario1() {
79     ProcessDefinition pd = implicitMergeProcessDefinition;
80     ProcessInstance pi = new ProcessInstance( implicitMergeProcessDefinition );
81     pi.signal("to a");
82     Token root = pi.getRootToken();
83     assertSame( pd.getNode("a"), root.getNode() );
84     root.signal();
85     assertSame( pd.getNode("c"), root.getNode() );
86   }
87   
88   public void testImplicitMergeScenario2() {
89     ProcessDefinition pd = implicitMergeProcessDefinition;
90     ProcessInstance pi = new ProcessInstance( implicitMergeProcessDefinition );
91     pi.signal("to b");
92     Token root = pi.getRootToken();
93     assertSame( pd.getNode("b"), root.getNode() );
94     root.signal();
95     assertSame( pd.getNode("c"), root.getNode() );
96   }
97   
98 }
99
Popular Tags