1 package org.jbpm.graph.exe; 2 3 import junit.framework.TestCase; 4 5 import org.jbpm.graph.def.ActionHandler; 6 import org.jbpm.graph.def.Node; 7 import org.jbpm.graph.def.ProcessDefinition; 8 9 public class NodeActionTest extends TestCase { 10 11 private ProcessDefinition processDefinition = ProcessDefinition.parseXmlString( 12 "<process-definition>" + 13 " <start-state>" + 14 " <transition to='n' />" + 15 " </start-state>" + 16 " <node name='n'>" + 17 " <action class='org.jbpm.graph.exe.NodeActionTest$RuntimeCalculation'/>" + 18 " <transition name='a' to='a' />" + 19 " <transition name='b' to='b' />" + 20 " <transition name='c' to='c' />" + 21 " </node>" + 22 " <state name='a' />" + 23 " <state name='b' />" + 24 " <state name='c' />" + 25 " <task name='undress' />" + 26 "</process-definition>" 27 ); 28 29 private ProcessInstance processInstance = new ProcessInstance(processDefinition); 30 private Token token = processInstance.getRootToken(); 31 private Node n = processDefinition.getNode("n"); 32 private Node a = processDefinition.getNode("a"); 33 private Node b = processDefinition.getNode("b"); 34 private Node c = processDefinition.getNode("c"); 35 36 private static int scenario = 0; 37 38 public static class RuntimeCalculation implements ActionHandler { 39 private static final long serialVersionUID = 1L; 40 public void execute(ExecutionContext executionContext) throws Exception { 41 if (scenario==1) { 42 executionContext.leaveNode("a"); 43 } else if (scenario==2) { 44 executionContext.leaveNode("b"); 45 } else if (scenario==3) { 46 executionContext.leaveNode("c"); 47 } else if (scenario==4) { 48 } 50 } 51 } 52 53 public void setUp() { 54 } 55 56 public void testSituation1() { 57 scenario = 1; 58 processInstance.signal(); 59 assertSame(a, token.getNode()); 60 } 61 62 public void testSituation2() { 63 scenario = 2; 64 processInstance.signal(); 65 assertSame(b, token.getNode()); 66 } 67 68 public void testSituation3() { 69 scenario = 3; 70 processInstance.signal(); 71 assertSame(c, token.getNode()); 72 } 73 74 public void testSituation4() { 75 scenario = 4; 76 processInstance.signal(); 77 assertSame(n, token.getNode()); 78 } 79 } 80 | Popular Tags |