1 package org.jbpm.graph.node; 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 public class ProcessStateTest extends TestCase { 12 13 public void testBasicScenario() { 14 ProcessDefinition superProcessDefinition = ProcessDefinition.parseXmlString( 15 "<process-definition>" + 16 " <start-state>" + 17 " <transition to='subprocessnode' />" + 18 " </start-state>" + 19 " <process-state name='subprocessnode'>" + 20 " <transition to='end' />" + 21 " </process-state>" + 22 " <end-state name='end' />" + 23 "</process-definition>" 24 ); 25 26 ProcessDefinition subProcessDefinition = ProcessDefinition.parseXmlString( 27 "<process-definition>" + 28 " <start-state>" + 29 " <transition to='state' />" + 30 " </start-state>" + 31 " <state name='state'>" + 32 " <transition to='end' />" + 33 " </state>" + 34 " <end-state name='end' />" + 35 "</process-definition>" 36 ); 37 38 ProcessState processState = (ProcessState) superProcessDefinition.getNode("subprocessnode"); 39 processState.setSubProcessDefinition(subProcessDefinition); 40 41 ProcessInstance superProcessInstance = new ProcessInstance(superProcessDefinition); 42 superProcessInstance.signal(); 43 44 Token superToken = superProcessInstance.getRootToken(); 45 assertSame(processState, superToken.getNode()); 46 47 ProcessInstance subProcessInstance = superToken.getSubProcessInstance(); 48 assertSame(subProcessDefinition, subProcessInstance.getProcessDefinition()); 49 Token subToken = subProcessInstance.getRootToken(); 50 51 assertSame(subProcessDefinition.getNode("state"), subToken.getNode()); 52 53 subToken.signal(); 54 55 assertSame(subProcessDefinition.getNode("end"), subToken.getNode()); 56 assertTrue(subToken.hasEnded()); 57 assertTrue(subProcessInstance.hasEnded()); 58 59 assertSame(superProcessDefinition.getNode("end"), superToken.getNode()); 60 assertTrue(superToken.hasEnded()); 61 assertTrue(superProcessInstance.hasEnded()); 62 } 63 64 public void testScenarioWithVariables() { 65 ProcessDefinition superProcessDefinition = ProcessDefinition.parseXmlString( 66 "<process-definition>" + 67 " <start-state>" + 68 " <transition to='subprocessnode' />" + 69 " </start-state>" + 70 " <process-state name='subprocessnode'>" + 71 " <variable name='a' mapped-name='aa' />" + 72 " <variable name='b' mapped-name='bb' />" + 73 " <transition to='end' />" + 74 " </process-state>" + 75 " <end-state name='end' />" + 76 "</process-definition>" 77 ); 78 superProcessDefinition.addDefinition(new ContextDefinition()); 79 80 ProcessDefinition subProcessDefinition = ProcessDefinition.parseXmlString( 81 "<process-definition>" + 82 " <start-state>" + 83 " <transition to='state' />" + 84 " </start-state>" + 85 " <state name='state'>" + 86 " <transition to='end' />" + 87 " </state>" + 88 " <end-state name='end' />" + 89 "</process-definition>" 90 ); 91 subProcessDefinition.addDefinition(new ContextDefinition()); 92 93 ProcessState processState = (ProcessState) superProcessDefinition.getNode("subprocessnode"); 95 processState.setSubProcessDefinition(subProcessDefinition); 96 97 ProcessInstance superProcessInstance = new ProcessInstance(superProcessDefinition); 99 Token superToken = superProcessInstance.getRootToken(); 100 101 ContextInstance superContextInstance = superProcessInstance.getContextInstance(); 103 superContextInstance.setVariable("a", "hello"); 104 superContextInstance.setVariable("b", new Integer (3)); 105 106 superProcessInstance.signal(); 108 109 ProcessInstance subProcessInstance = superToken.getSubProcessInstance(); 111 ContextInstance subContextInstance = subProcessInstance.getContextInstance(); 112 113 assertEquals("hello", subContextInstance.getVariable("aa")); 114 assertEquals(new Integer (3), subContextInstance.getVariable("bb")); 115 subContextInstance.setVariable("aa", "new hello"); 117 118 subProcessInstance.signal(); 120 121 assertEquals("new hello", superContextInstance.getVariable("a")); 123 assertEquals(new Integer (3), superContextInstance.getVariable("b")); 124 } 125 } 126 | Popular Tags |