1 package org.jbpm.jpdl.patterns; 2 3 import java.util.Collection ; 4 5 import junit.framework.TestCase; 6 7 import org.jbpm.graph.def.ProcessDefinition; 8 import org.jbpm.graph.exe.ProcessInstance; 9 import org.jbpm.graph.exe.Token; 10 import org.jbpm.graph.node.InterleaveStart; 11 import org.jbpm.graph.node.State; 12 13 16 public class Wfp18InterleavedParallelRoutingTest extends TestCase { 17 18 private int scenario = -1; 19 private ProcessDefinition processDefinition = ProcessDefinition.parseXmlString( 20 "<process-definition>" + 21 " <start-state name='a'>" + 22 " <transition to='startinterleaving' />" + 23 " </start-state>" + 24 " <interleave-start name='startinterleaving'>" + 25 " <transition name='b' to='b' />" + 26 " <transition name='c' to='c' />" + 27 " <transition name='d' to='d' />" + 28 " </interleave-start>" + 29 " <state name='b'>" + 30 " <transition to='endinterleaving' />" + 31 " </state>" + 32 " <state name='c'>" + 33 " <transition to='endinterleaving' />" + 34 " </state>" + 35 " <state name='d'>" + 36 " <transition to='endinterleaving' />" + 37 " </state>" + 38 " <interleave-end name='endinterleaving'>" + 39 " <transition name='back' to='startinterleaving' />" + 40 " <transition name='done' to='e' />" + 41 " </interleave-end>" + 42 " <state name='e' />" + 43 "</process-definition>" 44 ); 45 46 private InterleaveStart interleaveStart = (InterleaveStart) processDefinition.getNode("startinterleaving"); 47 private State b = (State) processDefinition.getNode("b"); 48 private State c = (State) processDefinition.getNode("c"); 49 private State d = (State) processDefinition.getNode("d"); 50 private State e = (State) processDefinition.getNode("e"); 51 52 private static String [][] scenarioSequences = new String [][] { 53 new String [] {"b", "c", "d"}, 54 new String [] {"b", "d", "c"}, 55 new String [] {"c", "b", "d"}, 56 new String [] {"c", "d", "b"}, 57 new String [] {"d", "b", "c"}, 58 new String [] {"d", "c", "b"} 59 }; 60 61 public class ScenarioInterleaver implements InterleaveStart.Interleaver { 62 public String selectNextTransition(Collection transitionNames) { 63 return scenarioSequences[scenario-1][3-transitionNames.size()]; 67 } 68 } 69 70 public void setUp() { 71 interleaveStart.setInterleaver(new ScenarioInterleaver()); 72 } 73 74 public void testInterleavedParallelRoutingScenario1() { 75 scenario = 1; 76 77 ProcessInstance processInstance = new ProcessInstance( processDefinition ); 78 Token token = processInstance.getRootToken(); 79 processInstance.signal(); 80 81 assertSame( b, token.getNode() ); 82 token.signal(); 83 assertSame( c, token.getNode() ); 84 token.signal(); 85 assertSame( d, token.getNode() ); 86 token.signal(); 87 assertSame( e, token.getNode() ); 88 } 89 90 public void testInterleavedParallelRoutingScenario2() { 91 scenario = 2; 92 93 ProcessInstance processInstance = new ProcessInstance( processDefinition ); 94 Token token = processInstance.getRootToken(); 95 processInstance.signal(); 96 97 assertSame( b, token.getNode() ); 98 token.signal(); 99 assertSame( d, token.getNode() ); 100 token.signal(); 101 assertSame( c, token.getNode() ); 102 token.signal(); 103 assertSame( e, token.getNode() ); 104 } 105 106 public void testInterleavedParallelRoutingScenario3() { 107 scenario = 3; 108 109 ProcessInstance processInstance = new ProcessInstance( processDefinition ); 110 Token token = processInstance.getRootToken(); 111 processInstance.signal(); 112 113 assertSame( c, token.getNode() ); 114 token.signal(); 115 assertSame( b, token.getNode() ); 116 token.signal(); 117 assertSame( d, token.getNode() ); 118 token.signal(); 119 assertSame( e, token.getNode() ); 120 } 121 122 public void testInterleavedParallelRoutingScenario4() { 123 scenario = 4; 124 125 ProcessInstance processInstance = new ProcessInstance( processDefinition ); 126 Token token = processInstance.getRootToken(); 127 processInstance.signal(); 128 129 assertSame( c, token.getNode() ); 130 token.signal(); 131 assertSame( d, token.getNode() ); 132 token.signal(); 133 assertSame( b, token.getNode() ); 134 token.signal(); 135 assertSame( e, token.getNode() ); 136 } 137 138 public void testInterleavedParallelRoutingScenario5() { 139 scenario = 5; 140 141 ProcessInstance processInstance = new ProcessInstance( processDefinition ); 142 Token token = processInstance.getRootToken(); 143 processInstance.signal(); 144 145 assertSame( d, token.getNode() ); 146 token.signal(); 147 assertSame( b, token.getNode() ); 148 token.signal(); 149 assertSame( c, token.getNode() ); 150 token.signal(); 151 assertSame( e, token.getNode() ); 152 } 153 154 public void testInterleavedParallelRoutingScenario6() { 155 scenario = 6; 156 157 ProcessInstance processInstance = new ProcessInstance( processDefinition ); 158 Token token = processInstance.getRootToken(); 159 processInstance.signal(); 160 161 assertSame( d, token.getNode() ); 162 token.signal(); 163 assertSame( c, token.getNode() ); 164 token.signal(); 165 assertSame( b, token.getNode() ); 166 token.signal(); 167 assertSame( e, token.getNode() ); 168 } 169 } 170 | Popular Tags |