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.Merge; 8 9 12 public class Wfp08MultiMergeTest extends TestCase { 13 14 private static ProcessDefinition multiMergeProcessDefinition = createMultiMergeProcessDefinition(); 15 16 public static ProcessDefinition createMultiMergeProcessDefinition() { 17 ProcessDefinition processDefinition = ProcessDefinition.parseXmlString( 18 "<process-definition>" + 19 " <start-state name='start'>" + 20 " <transition to='a' />" + 21 " </start-state>" + 22 " <state name='a'>" + 23 " <transition to='multichoice' />" + 24 " </state>" + 25 " <fork name='multichoice'>" + 26 " <script>" + 27 " <variable name='transitionNames' access='write' />" + 28 " <expression>" + 29 " transitionNames = new ArrayList();" + 30 " if ( scenario == 1 ) {" + 31 " transitionNames.add( \"to b\" );" + 32 " } else if ( scenario == 2 ) {" + 33 " transitionNames.add( \"to c\" );" + 34 " } else if ( scenario >= 3 ) {" + 35 " transitionNames.add( \"to b\" );" + 36 " transitionNames.add( \"to c\" );" + 37 " }" + 38 " </expression>" + 39 " </script>" + 40 " <transition name='to b' to='b' />" + 41 " <transition name='to c' to='c' />" + 42 " </fork>" + 43 " <state name='b'>" + 44 " <transition to='multimerge' />" + 45 " </state>" + 46 " <state name='c'>" + 47 " <transition to='multimerge' />" + 48 " </state>" + 49 " <merge name='multimerge'>" + 50 " <transition to='d' />" + 51 " </merge>" + 52 " <state name='d' />" + 53 "</process-definition>" 54 ); 55 56 return processDefinition; 57 } 58 59 public void testMultiMergeScenario1() { 60 ProcessDefinition pd = multiMergeProcessDefinition; 61 Token root = Wfp06MultiChoiceTest.executeScenario(pd,1); 62 Token tokenB = root.getChild("to b"); 63 tokenB.signal(); 64 assertSame( pd.getNode("d"), tokenB.getNode() ); 65 } 66 67 public void testMultiMergeScenario2() { 68 ProcessDefinition pd = multiMergeProcessDefinition; 69 Token root = Wfp06MultiChoiceTest.executeScenario(pd,2); 70 Token tokenC = root.getChild("to c"); 71 tokenC.signal(); 72 assertSame( pd.getNode("d"), tokenC.getNode() ); 73 } 74 75 private static ProcessDefinition synchronizingMultiMergeProcessDefinition = createSynchronizingMultiMergeProcessDefinition(); 76 77 public static ProcessDefinition createSynchronizingMultiMergeProcessDefinition() { 78 ProcessDefinition pd = createMultiMergeProcessDefinition(); 79 80 Merge merge = (Merge) pd.getNode("multimerge"); 82 merge.setSynchronized( true ); 83 84 return pd; 85 } 86 87 public void testMultiMergeScenario3() { 88 ProcessDefinition pd = synchronizingMultiMergeProcessDefinition; 89 Token root = Wfp06MultiChoiceTest.executeScenario(pd,3); 90 Token tokenB = root.getChild("to b"); 91 Token tokenC = root.getChild("to c"); 92 93 tokenB.signal(); 94 assertSame( pd.getNode("multimerge"), tokenB.getNode() ); 95 assertSame( pd.getNode("c"), tokenC.getNode() ); 96 97 tokenC.signal(); 98 assertSame( pd.getNode("d"), tokenB.getNode() ); 99 assertSame( pd.getNode("d"), tokenC.getNode() ); 100 } 101 102 public void testMultiMergeScenario4() { 103 ProcessDefinition pd = synchronizingMultiMergeProcessDefinition; 104 Token root = Wfp06MultiChoiceTest.executeScenario(pd,4); 105 Token tokenB = root.getChild("to b"); 106 Token tokenC = root.getChild("to c"); 107 108 tokenC.signal(); 109 assertSame( pd.getNode("b"), tokenB.getNode() ); 110 assertSame( pd.getNode("multimerge"), tokenC.getNode() ); 111 112 tokenB.signal(); 113 assertSame( pd.getNode("d"), tokenB.getNode() ); 114 assertSame( pd.getNode("d"), tokenC.getNode() ); 115 } 116 117 public void testMultiMergeScenario5() { 118 ProcessDefinition pd = multiMergeProcessDefinition; 119 Token root = Wfp06MultiChoiceTest.executeScenario(pd,5); 120 Token tokenB = root.getChild("to b"); 121 Token tokenC = root.getChild("to c"); 122 123 tokenB.signal(); 124 assertSame( pd.getNode("d"), tokenB.getNode() ); 125 assertSame( pd.getNode("c"), tokenC.getNode() ); 126 127 tokenC.signal(); 128 assertSame( pd.getNode("d"), tokenB.getNode() ); 129 assertSame( pd.getNode("d"), tokenC.getNode() ); 130 } 131 132 public void testMultiMergeScenario6() { 133 ProcessDefinition pd = multiMergeProcessDefinition; 134 Token root = Wfp06MultiChoiceTest.executeScenario(pd,6); 135 Token tokenB = root.getChild("to b"); 136 Token tokenC = root.getChild("to c"); 137 138 tokenC.signal(); 139 assertSame( pd.getNode("b"), tokenB.getNode() ); 140 assertSame( pd.getNode("d"), tokenC.getNode() ); 141 142 tokenB.signal(); 143 assertSame( pd.getNode("d"), tokenB.getNode() ); 144 assertSame( pd.getNode("d"), tokenC.getNode() ); 145 } 146 } 147 | Popular Tags |