01: package com.sample;
02:
03: import junit.framework.TestCase;
04:
05: import org.jbpm.graph.def.ProcessDefinition;
06: import org.jbpm.graph.exe.ProcessInstance;
07:
08: public class SimpleProcessTest extends TestCase {
09:
10: public void testSimpleProcess() throws Exception {
11:
12: // Extract a process definition from the processdefinition.xml file.
13: ProcessDefinition processDefinition = ProcessDefinition
14: .parseXmlResource("simple/processdefinition.xml");
15: assertNotNull("Definition should not be null",
16: processDefinition);
17:
18: // Create an instance of the process definition.
19: ProcessInstance instance = new ProcessInstance(
20: processDefinition);
21: assertEquals("Instance is in start state", instance
22: .getRootToken().getNode().getName(), "start");
23: assertNull("Message variable should not exist yet", instance
24: .getContextInstance().getVariable("message"));
25:
26: // Move the process instance from its start state to the first state.
27: // The configured action should execute and the appropriate message
28: // should appear in the message process variable.
29: instance.signal();
30: assertEquals("Instance is in first state", instance
31: .getRootToken().getNode().getName(), "first");
32: assertEquals("Message variable contains message", instance
33: .getContextInstance().getVariable("message"),
34: "Going to the first state!");
35:
36: // Move the process instance to the end state. The configured action
37: // should execute again. The message variable contains a new value.
38: instance.signal();
39: assertEquals("Instance is in end state", instance
40: .getRootToken().getNode().getName(), "end");
41: assertTrue("Instance has ended", instance.hasEnded());
42: assertEquals("Message variable is changed", instance
43: .getContextInstance().getVariable("message"),
44: "About to finish!");
45:
46: }
47:
48: }
|