KickJava   Java API By Example, From Geeks To Geeks.

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


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

12 public class Wfp09DiscriminatorTest extends TestCase {
13
14   private static ProcessDefinition discriminatorProcessDefinition = createDiscriminatorProcessDefinition();
15
16   public static ProcessDefinition createDiscriminatorProcessDefinition() {
17     ProcessDefinition pd = createSynchronizingDiscriminatorProcessDefinition();
18     
19     // configure the join as a discriminator
20
Join join = (Join) pd.getNode("discriminator");
21     join.setDiscriminator(true);
22     
23     return pd;
24   }
25
26   private static ProcessDefinition synchronizingdiscriminatorProcessDefinition = createSynchronizingDiscriminatorProcessDefinition();
27
28   public static ProcessDefinition createSynchronizingDiscriminatorProcessDefinition() {
29     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
30       "<process-definition>" +
31       " <start-state name='start'>" +
32       " <transition to='a' />" +
33       " </start-state>" +
34       " <state name='a'>" +
35       " <transition to='multichoice' />" +
36       " </state>" +
37       " <fork name='multichoice'>" +
38       " <script>" +
39       " <variable name='transitionNames' access='write' />" +
40       " <expression>" +
41       " transitionNames = new ArrayList();" +
42       " if ( scenario == 1 ) {" +
43       " transitionNames.add( \"to b\" );" +
44       " } else if ( scenario == 2 ) {" +
45       " transitionNames.add( \"to c\" );" +
46       " } else if ( scenario >= 3 ) {" +
47       " transitionNames.add( \"to b\" );" +
48       " transitionNames.add( \"to c\" );" +
49       " }" +
50       " </expression>" +
51       " </script>" +
52       " <transition name='to b' to='b' />" +
53       " <transition name='to c' to='c' />" +
54       " </fork>" +
55       " <state name='b'>" +
56       " <transition to='discriminator' />" +
57       " </state>" +
58       " <state name='c'>" +
59       " <transition to='discriminator' />" +
60       " </state>" +
61       " <join name='discriminator'>" +
62       " <transition to='d' />" +
63       " </join>" +
64       " <state name='d' />" +
65       "</process-definition>"
66     );
67           
68     return processDefinition;
69   }
70
71   public void testDiscriminatorScenario1() {
72     ProcessDefinition pd = discriminatorProcessDefinition;
73     Token root = Wfp06MultiChoiceTest.executeScenario(pd,1);
74     Token tokenB = root.getChild("to b");
75
76     tokenB.signal();
77     assertSame( pd.getNode("d"), root.getNode() );
78     assertSame( pd.getNode("discriminator"), tokenB.getNode() );
79   }
80   
81   public void testDiscriminatorScenario2() {
82     ProcessDefinition pd = discriminatorProcessDefinition;
83     Token root = Wfp06MultiChoiceTest.executeScenario(pd,2);
84     Token tokenC = root.getChild("to c");
85
86     tokenC.signal();
87     assertSame( pd.getNode("d"), root.getNode() );
88     assertSame( pd.getNode("discriminator"), tokenC.getNode() );
89   }
90   
91   public void testDiscriminatorScenario3() {
92     ProcessDefinition pd = discriminatorProcessDefinition;
93     Token root = Wfp06MultiChoiceTest.executeScenario(pd,3);
94     Token tokenB = root.getChild("to b");
95     Token tokenC = root.getChild("to c");
96
97     tokenB.signal();
98     assertSame( pd.getNode("d"), root.getNode() );
99     assertSame( pd.getNode("discriminator"), tokenB.getNode() );
100     assertSame( pd.getNode("c"), tokenC.getNode() );
101
102     tokenC.signal();
103     assertSame( pd.getNode("d"), root.getNode() );
104     assertSame( pd.getNode("discriminator"), tokenB.getNode() );
105     assertSame( pd.getNode("discriminator"), tokenC.getNode() );
106   }
107   
108   public void testDiscriminatorScenario4() {
109     ProcessDefinition pd = discriminatorProcessDefinition;
110     Token root = Wfp06MultiChoiceTest.executeScenario(pd,4);
111     Token tokenB = root.getChild("to b");
112     Token tokenC = root.getChild("to c");
113
114     tokenC.signal();
115     assertSame( pd.getNode("d"), root.getNode() );
116     assertSame( pd.getNode("b"), tokenB.getNode() );
117     assertSame( pd.getNode("discriminator"), tokenC.getNode() );
118
119     tokenB.signal();
120     assertSame( pd.getNode("d"), root.getNode() );
121     assertSame( pd.getNode("discriminator"), tokenB.getNode() );
122     assertSame( pd.getNode("discriminator"), tokenC.getNode() );
123   }
124
125   public void testDiscriminatorScenario5() {
126     ProcessDefinition pd = synchronizingdiscriminatorProcessDefinition;
127     Token root = Wfp06MultiChoiceTest.executeScenario(pd,5);
128     Token tokenB = root.getChild("to b");
129     Token tokenC = root.getChild("to c");
130
131     tokenB.signal();
132     assertSame( pd.getNode("multichoice"), root.getNode() );
133     assertSame( pd.getNode("discriminator"), tokenB.getNode() );
134     assertSame( pd.getNode("c"), tokenC.getNode() );
135
136     tokenC.signal();
137     assertSame( pd.getNode("d"), root.getNode() );
138     assertSame( pd.getNode("discriminator"), tokenB.getNode() );
139     assertSame( pd.getNode("discriminator"), tokenC.getNode() );
140   }
141
142   public void testDiscriminatorScenario6() {
143     ProcessDefinition pd = synchronizingdiscriminatorProcessDefinition;
144     Token root = Wfp06MultiChoiceTest.executeScenario(pd,3);
145     Token tokenB = root.getChild("to b");
146     Token tokenC = root.getChild("to c");
147
148     tokenC.signal();
149     assertSame( pd.getNode("multichoice"), root.getNode() );
150     assertSame( pd.getNode("b"), tokenB.getNode() );
151     assertSame( pd.getNode("discriminator"), tokenC.getNode() );
152
153     tokenB.signal();
154     assertSame( pd.getNode("d"), root.getNode() );
155     assertSame( pd.getNode("discriminator"), tokenB.getNode() );
156     assertSame( pd.getNode("discriminator"), tokenC.getNode() );
157   }
158 }
159
Popular Tags