KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.jbpm.jpdl.patterns;
2
3 import junit.framework.TestCase;
4
5 import org.jbpm.context.def.ContextDefinition;
6 import org.jbpm.context.exe.ContextInstance;
7 import org.jbpm.graph.def.ProcessDefinition;
8 import org.jbpm.graph.exe.ProcessInstance;
9 import org.jbpm.graph.exe.Token;
10
11 /**
12  * http://is.tm.tue.nl/research/patterns/download/swf/pat_4.swf
13  *
14  * <p>we make a distinction in the api between process and client based
15  * decisions. the first tests show the situations as described in the
16  * pattern. after that a demonstration of client based decision is
17  * added.
18  * </p>
19  *
20  * <p>process based
21  * decisions makes use of a decision node. the node has a piece of
22  * programming logic associated that calculates the leaving transition
23  * name. the programming logic is executed within the calculation of
24  * the next state of the process instance.
25  * </p>
26  *
27  * <p>client based decisions allow clients to select on of the multiple
28  * transitions that leave the current state.
29  * </p>
30  */

31 public class Wfp04ExclusiveChoiceTest extends TestCase {
32   
33   static ProcessDefinition exclusiveChoiceProcessDefinition = ProcessDefinition.parseXmlString(
34       "<process-definition>" +
35       " <start-state name='start'>" +
36       " <transition to='a' />" +
37       " </start-state>" +
38       " <state name='a'>" +
39       " <transition to='xor' />" +
40       " </state>" +
41       " <decision name='xor'>" +
42       " <transition name='urgent' to='b'>" +
43       " <condition>scenario==1</condition>" +
44       " </transition>" +
45       " <transition name='dont care' to='c'>" +
46       " <condition>scenario==2</condition>" +
47       " </transition>" +
48       " <transition name='forget about it' to='d'/>" +
49       " </decision>" +
50       " <state name='b' />" +
51       " <state name='c' />" +
52       " <state name='d' />" +
53       "</process-definition>" );
54   static {
55     exclusiveChoiceProcessDefinition.addDefinition( new ContextDefinition() );
56   }
57
58   /**
59    * situation 1
60    */

61   public void testExclusiveChoiceSituation1() {
62     ProcessDefinition pd = exclusiveChoiceProcessDefinition;
63
64     ProcessInstance pi = new ProcessInstance( pd );
65     ContextInstance ci = (ContextInstance) pi.getInstance( ContextInstance.class );
66     pi.signal();
67     Token root = pi.getRootToken();
68
69     assertSame( pd.getNode("a"), root.getNode() );
70     
71     ci.setVariable( "scenario", new Integer JavaDoc(1) );
72     root.signal();
73     
74     assertSame( pd.getNode("b"), root.getNode() );
75   }
76
77   /**
78    * situation 2
79    */

80   public void testExclusiveChoiceSituation2() {
81     ProcessDefinition pd = exclusiveChoiceProcessDefinition;
82
83     ProcessInstance pi = new ProcessInstance( pd );
84     ContextInstance ci = (ContextInstance) pi.getInstance( ContextInstance.class );
85     pi.signal();
86     Token root = pi.getRootToken();
87
88     assertSame( pd.getNode("a"), root.getNode() );
89     
90     ci.setVariable( "scenario", new Integer JavaDoc(2) );
91     root.signal();
92     
93     assertSame( pd.getNode("c"), root.getNode() );
94   }
95
96 }
97
Popular Tags