KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > graph > exe > RuntimeActionsTest


1 package org.jbpm.graph.exe;
2
3 import junit.framework.TestCase;
4
5 import org.jbpm.graph.def.Action;
6 import org.jbpm.graph.def.ActionHandler;
7 import org.jbpm.graph.def.Event;
8 import org.jbpm.graph.def.ProcessDefinition;
9
10 public class RuntimeActionsTest extends TestCase {
11   
12   private ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
13     "<process-definition>" +
14     " <start-state name='start'>" +
15     " <transition to='a' />" +
16     " </start-state>" +
17     " <state name='a'>" +
18     " <transition to='a' />" +
19     " </state>" +
20     " <action name='plusplus' class='org.jbpm.graph.exe.RuntimeActionsTest$PlusPlus' />" +
21     "</process-definition>"
22   );
23   
24   private static int count = 0;
25
26   public static class PlusPlus implements ActionHandler {
27     private static final long serialVersionUID = 1L;
28     public void execute(ExecutionContext executionContext) throws Exception JavaDoc {
29       // increase the static counter of the test class
30
count++;
31     }
32   }
33   
34   public void testRuntimeAction() throws Exception JavaDoc {
35     // start the process instance
36
ProcessInstance processInstance = new ProcessInstance(processDefinition);
37     // make sure node a was entered once before the runtime action was added
38
processInstance.signal();
39
40     // no action was added on enter of node a yet...
41
assertEquals(0,count);
42
43     // add the runtime action on entrance of node a
44
Action plusplusAction = processDefinition.getAction("plusplus");
45     Event enterB = new Event(Event.EVENTTYPE_NODE_ENTER);
46     processDefinition.getNode("a").addEvent(enterB);
47     RuntimeAction runtimeAction = new RuntimeAction(enterB,plusplusAction);
48     processInstance.addRuntimeAction(runtimeAction);
49
50     // loop back to node a, firing event node-enter for the second time
51
processInstance.signal();
52     
53     // only the second time, the counter should have been plusplussed
54
assertEquals(1,count);
55   }
56 }
57
Popular Tags