1 package org.jbpm.jpdl.patterns; 2 3 import junit.framework.*; 4 5 import org.jbpm.context.def.*; 6 import org.jbpm.graph.def.*; 7 import org.jbpm.graph.exe.*; 8 import org.jbpm.graph.node.*; 9 import org.jbpm.instantiation.*; 10 11 public class Wfp19MilestoneTest extends TestCase { 12 13 public static ProcessDefinition milestoneProcessDefinition = createMilestoneProcessDefinition(); 14 15 public static ProcessDefinition createMilestoneProcessDefinition() { 16 ProcessDefinition pd = new ProcessDefinition( 17 new String []{"start-state start", 18 "fork fork", 19 "state b", 20 "milestone-node m", 21 "state c", 22 "state d", 23 "join join", 24 "end-state end"}, 25 new String []{"start --> fork", 26 "fork --m--> b", 27 "fork --d--> d", 28 "b --> m", 29 "m --> c", 30 "c --> join", 31 "d --> join", 32 "join --> end"}); 33 34 Node d = pd.getNode("d"); 35 36 Delegation instantiatableDelegate = new Delegation(new MilestoneEvent("m", "../m")); 37 Event event = new Event(Event.EVENTTYPE_NODE_LEAVE); 38 d.addEvent(event); 39 event.addAction(new Action(instantiatableDelegate)); 40 41 pd.addDefinition(new ContextDefinition()); 42 43 return pd; 44 } 45 46 public void testMilestoneScenario1() { 47 ProcessDefinition pd = milestoneProcessDefinition; 48 Token root = startScenario(); 49 Token tokenM = root.getChild("m"); 50 Token tokenD = root.getChild("d"); 51 assertSame( pd.getNode("b"), tokenM.getNode() ); 52 assertSame( pd.getNode("d"), tokenD.getNode() ); 53 tokenM.signal(); 54 assertSame( pd.getNode("m"), tokenM.getNode() ); 55 assertSame( pd.getNode("d"), tokenD.getNode() ); 56 tokenD.signal(); 57 assertSame( pd.getNode("c"), tokenM.getNode() ); 58 assertSame( pd.getNode("join"), tokenD.getNode() ); 59 } 60 61 public void testMilestoneScenario2() { 62 ProcessDefinition pd = milestoneProcessDefinition; 63 Token root = startScenario(); 64 Token tokenM = root.getChild("m"); 65 Token tokenD = root.getChild("d"); 66 assertSame( pd.getNode("b"), tokenM.getNode() ); 67 assertSame( pd.getNode("d"), tokenD.getNode() ); 68 tokenD.signal(); 69 assertSame( pd.getNode("b"), tokenM.getNode() ); 70 assertSame( pd.getNode("join"), tokenD.getNode() ); 71 tokenM.signal(); 72 assertSame( pd.getNode("c"), tokenM.getNode() ); 73 assertSame( pd.getNode("join"), tokenD.getNode() ); 74 } 75 76 public Token startScenario() { 77 ProcessDefinition pd = milestoneProcessDefinition; 78 ProcessInstance pi = new ProcessInstance( pd ); 79 pi.signal(); 80 return pi.getRootToken(); 81 } 82 } 83 | Popular Tags |