KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.jbpm.graph.exe;
2
3 import org.jbpm.db.AbstractDbTestCase;
4 import org.jbpm.graph.def.Action;
5 import org.jbpm.graph.def.Event;
6 import org.jbpm.graph.def.ProcessDefinition;
7
8 public class RuntimeActionDbTest extends AbstractDbTestCase {
9
10   public void testRuntimeActionProcessInstance() {
11     ProcessInstance processInstance = new ProcessInstance();
12     processInstance.addRuntimeAction(new RuntimeAction());
13
14     processInstance = saveAndReload(processInstance);
15     
16     RuntimeAction runtimeAction = (RuntimeAction) processInstance.getRuntimeActions().get(0);
17     
18     assertSame(processInstance , runtimeAction.getProcessInstance());
19   }
20   
21   public void testRuntimeActionEvent() {
22     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
23       "<process-definition>" +
24       " <event type='process-start' />" +
25       " <action name='gotocheetahs' class='com.secret.LetsDoItSneeky'/>" +
26       "</process-definition>" );
27     graphSession.saveProcessDefinition(processDefinition);
28     ProcessInstance processInstance = new ProcessInstance(processDefinition);
29     Event event = processInstance.getProcessDefinition().getEvent("process-start");
30     Action action = processInstance.getProcessDefinition().getAction("gotocheetahs");
31     processInstance.addRuntimeAction(new RuntimeAction(event, action));
32
33     processInstance = saveAndReload(processInstance);
34
35     RuntimeAction runtimeAction = (RuntimeAction) processInstance.getRuntimeActions().get(0);
36     event = processInstance.getProcessDefinition().getEvent("process-start");
37     assertSame(event.getGraphElement(), runtimeAction.getGraphElement());
38     assertSame(event.getEventType(), runtimeAction.getEventType());
39   }
40
41   public void testRuntimeActionAction() {
42     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
43       "<process-definition>" +
44       " <event type='process-start' />" +
45       " <action name='gotocheetahs' class='com.secret.LetsDoItSneeky'/>" +
46       "</process-definition>" );
47     graphSession.saveProcessDefinition(processDefinition);
48     ProcessInstance processInstance = new ProcessInstance(processDefinition);
49     Event event = processInstance.getProcessDefinition().getEvent("process-start");
50     Action action = processInstance.getProcessDefinition().getAction("gotocheetahs");
51     processInstance.addRuntimeAction(new RuntimeAction(event, action));
52
53     processInstance = saveAndReload(processInstance);
54
55     RuntimeAction runtimeAction = (RuntimeAction) processInstance.getRuntimeActions().get(0);
56     action = processInstance.getProcessDefinition().getAction("gotocheetahs");
57     assertSame(action, runtimeAction.getAction());
58   }
59
60   public void testRuntimeActionOnNonExistingEvent() {
61     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
62       "<process-definition>" +
63       " <action name='gotocheetahs' class='com.secret.LetsDoItSneeky'/>" +
64       "</process-definition>" );
65     graphSession.saveProcessDefinition(processDefinition);
66     
67     ProcessInstance processInstance = new ProcessInstance(processDefinition);
68     Action action = processInstance.getProcessDefinition().getAction("gotocheetahs");
69     processInstance.addRuntimeAction(new RuntimeAction(processDefinition, "process-start", action));
70
71     processInstance = saveAndReload(processInstance);
72
73     RuntimeAction runtimeAction = (RuntimeAction) processInstance.getRuntimeActions().get(0);
74     action = processInstance.getProcessDefinition().getAction("gotocheetahs");
75     assertSame(action, runtimeAction.getAction());
76   }
77
78 }
79
Popular Tags