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 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 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 (1) ); 72 root.signal(); 73 74 assertSame( pd.getNode("b"), root.getNode() ); 75 } 76 77 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 (2) ); 91 root.signal(); 92 93 assertSame( pd.getNode("c"), root.getNode() ); 94 } 95 96 } 97 | Popular Tags |