KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > graph > log > TransitionLogTest


1 package org.jbpm.graph.log;
2
3 import java.util.List JavaDoc;
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.logging.exe.LoggingInstance;
11
12 public class TransitionLogTest extends TestCase {
13
14   public void testBasicTransitionLogs() {
15     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
16       "<process-definition>" +
17       " <start-state>" +
18       " <transition to='state' />" +
19       " </start-state>" +
20       " <state name='state'>" +
21       " <transition to='end' />" +
22       " </state>" +
23       " <end-state name='end' />" +
24       "</process-definition>"
25     );
26
27     // start a process instance
28
ProcessInstance processInstance = new ProcessInstance(processDefinition);
29     Token token = processInstance.getRootToken();
30     processInstance.signal();
31     
32     // check the transition log (from the start state to the state)
33
LoggingInstance loggingInstance = processInstance.getLoggingInstance();
34     List JavaDoc transitionLogs = loggingInstance.getLogs(TransitionLog.class);
35     assertEquals(1, transitionLogs.size());
36     TransitionLog transitionLog = (TransitionLog) transitionLogs.get(0);
37     assertSame(token, transitionLog.getToken());
38     assertNotNull(transitionLog.getDate());
39     assertSame(processDefinition.getStartState(), transitionLog.getSourceNode());
40     assertSame(processDefinition.getNode("state"), transitionLog.getDestinationNode());
41
42     // signal the process to continue (which will move it to the end state)
43
processInstance.signal();
44     
45     // check the transition log (from the state to the end state)
46
transitionLogs = loggingInstance.getLogs(TransitionLog.class);
47     assertEquals(2, transitionLogs.size());
48     transitionLog = (TransitionLog) transitionLogs.get(1);
49     assertSame(token, transitionLog.getToken());
50     assertNotNull(transitionLog.getDate());
51     assertSame(processDefinition.getNode("state"), transitionLog.getSourceNode());
52     assertSame(processDefinition.getNode("end"), transitionLog.getDestinationNode());
53   }
54
55   public void testUseSuperStateTransitionLogs() {
56     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
57       "<process-definition>" +
58       " <start-state>" +
59       " <transition to='superstate/state' />" +
60       " </start-state>" +
61       " <super-state name='superstate'>" +
62       " <state name='state'/>" +
63       " <transition to='end' />" +
64       " </super-state>" +
65       " <end-state name='end' />" +
66       "</process-definition>"
67     );
68
69     // start a process instance
70
ProcessInstance processInstance = new ProcessInstance(processDefinition);
71     Token token = processInstance.getRootToken();
72     processInstance.signal();
73     processInstance.signal();
74     
75     // check the transition log (from the start state to the state)
76
LoggingInstance loggingInstance = processInstance.getLoggingInstance();
77     List JavaDoc transitionLogs = loggingInstance.getLogs(TransitionLog.class);
78     assertEquals(2, transitionLogs.size());
79     TransitionLog transitionLog = (TransitionLog) transitionLogs.get(1);
80     assertSame(token, transitionLog.getToken());
81     assertNotNull(transitionLog.getDate());
82     assertSame(processDefinition.findNode("superstate/state"), transitionLog.getSourceNode());
83     assertSame(processDefinition.getNode("end"), transitionLog.getDestinationNode());
84   }
85
86   public void testTransitionToSuperStateFirstChildLogs() {
87     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
88       "<process-definition>" +
89       " <start-state>" +
90       " <transition to='superstate' />" +
91       " </start-state>" +
92       " <super-state name='superstate'>" +
93       " <state name='state'/>" +
94       " </super-state>" +
95       "</process-definition>"
96     );
97
98     // start a process instance
99
ProcessInstance processInstance = new ProcessInstance(processDefinition);
100     Token token = processInstance.getRootToken();
101     processInstance.signal();
102     
103     // check the transition log (from the start state to the state)
104
LoggingInstance loggingInstance = processInstance.getLoggingInstance();
105     List JavaDoc transitionLogs = loggingInstance.getLogs(TransitionLog.class);
106     assertEquals(1, transitionLogs.size());
107     TransitionLog transitionLog = (TransitionLog) transitionLogs.get(0);
108     assertSame(token, transitionLog.getToken());
109     assertNotNull(transitionLog.getDate());
110     assertSame(processDefinition.getStartState(), transitionLog.getSourceNode());
111     assertSame(processDefinition.findNode("superstate/state"), transitionLog.getDestinationNode());
112   }
113 }
114
Popular Tags