KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > graph > def > ProcessDefinitionDbTest


1 package org.jbpm.graph.def;
2
3 import org.jbpm.context.def.ContextDefinition;
4 import org.jbpm.db.AbstractDbTestCase;
5 import org.jbpm.file.def.FileDefinition;
6 import org.jbpm.graph.node.StartState;
7 import org.jbpm.taskmgmt.def.TaskMgmtDefinition;
8
9 public class ProcessDefinitionDbTest extends AbstractDbTestCase {
10
11   public void testProcessDefinitionVersion() {
12     ProcessDefinition processDefinition = new ProcessDefinition("name");
13     processDefinition.setVersion(3);
14
15     processDefinition = saveAndReload(processDefinition);
16
17     assertNotNull(processDefinition);
18     assertEquals(3, processDefinition.getVersion());
19   }
20
21   public void testProcessDefinitionIsTerminationImplicit() {
22     ProcessDefinition processDefinition = new ProcessDefinition("name");
23     processDefinition.setTerminationImplicit(false);
24
25     processDefinition = saveAndReload(processDefinition);
26
27     assertNotNull(processDefinition);
28     assertFalse(processDefinition.isTerminationImplicit());
29   }
30
31   public void testProcessDefinitionStartState() {
32     ProcessDefinition processDefinition = new ProcessDefinition();
33     processDefinition.setStartState(new StartState());
34
35     processDefinition = saveAndReload(processDefinition);
36
37     assertTrue(StartState.class.isAssignableFrom(processDefinition.getStartState().getClass()));
38   }
39
40   public void testProcessDefinitionNodes() {
41     ProcessDefinition processDefinition = new ProcessDefinition();
42     processDefinition.setStartState(new StartState("s"));
43     processDefinition.addNode(new Node("a"));
44     processDefinition.addNode(new Node("b"));
45     processDefinition.addNode(new Node("c"));
46     processDefinition.addNode(new Node("d"));
47
48     processDefinition = saveAndReload(processDefinition);
49
50     assertEquals("s", processDefinition.getStartState().getName());
51     assertEquals("s", ((Node)processDefinition.getNodes().get(0)).getName());
52     assertEquals("a", ((Node)processDefinition.getNodes().get(1)).getName());
53     assertEquals("b", ((Node)processDefinition.getNodes().get(2)).getName());
54     assertEquals("c", ((Node)processDefinition.getNodes().get(3)).getName());
55     assertEquals("d", ((Node)processDefinition.getNodes().get(4)).getName());
56   }
57   
58   public void testActions() {
59     ProcessDefinition processDefinition = new ProcessDefinition();
60     Action action = new Action();
61     action.setName("a");
62     processDefinition.addAction(action);
63     action = new Action();
64     action.setName("b");
65     processDefinition.addAction(action);
66
67     processDefinition = saveAndReload(processDefinition);
68
69     assertEquals(2, processDefinition.getActions().size());
70     assertNotNull(processDefinition.getActions().get("a"));
71     assertNotNull(processDefinition.getActions().get("b"));
72     assertTrue(Action.class.isAssignableFrom(processDefinition.getAction("a").getClass()));
73     assertTrue(Action.class.isAssignableFrom(processDefinition.getAction("b").getClass()));
74   }
75   
76   public void testEvents() {
77     ProcessDefinition processDefinition = new ProcessDefinition();
78     processDefinition.addEvent(new Event("node-enter"));
79     processDefinition.addEvent(new Event("node-leave"));
80     processDefinition.addEvent(new Event("transition"));
81     processDefinition.addEvent(new Event("process-start"));
82     processDefinition.addEvent(new Event("process-end"));
83
84     processDefinition = saveAndReload(processDefinition);
85
86     assertNotNull(processDefinition.getEvent("node-enter"));
87     assertNotNull(processDefinition.getEvent("node-leave"));
88     assertNotNull(processDefinition.getEvent("transition"));
89     assertNotNull(processDefinition.getEvent("process-start"));
90     assertNotNull(processDefinition.getEvent("process-end"));
91   }
92
93   public void testExceptionHandlers() {
94     ProcessDefinition processDefinition = new ProcessDefinition();
95     ExceptionHandler exceptionHandler = new ExceptionHandler();
96     exceptionHandler.setExceptionClassName("org.disaster.FirstException");
97     processDefinition.addExceptionHandler(exceptionHandler);
98     exceptionHandler = new ExceptionHandler();
99     exceptionHandler.setExceptionClassName("org.disaster.SecondException");
100     processDefinition.addExceptionHandler(exceptionHandler);
101     exceptionHandler = new ExceptionHandler();
102     exceptionHandler.setExceptionClassName("org.disaster.ThirdException");
103     processDefinition.addExceptionHandler(exceptionHandler);
104
105     processDefinition = saveAndReload(processDefinition);
106
107     assertEquals("org.disaster.FirstException",((ExceptionHandler)processDefinition.getExceptionHandlers().get(0)).getExceptionClassName());
108     assertEquals("org.disaster.SecondException",((ExceptionHandler)processDefinition.getExceptionHandlers().get(1)).getExceptionClassName());
109     assertEquals("org.disaster.ThirdException",((ExceptionHandler)processDefinition.getExceptionHandlers().get(2)).getExceptionClassName());
110   }
111
112   public void testContextModuleDefinition() {
113     ProcessDefinition processDefinition = new ProcessDefinition();
114     processDefinition.addDefinition(new ContextDefinition());
115     graphSession.saveProcessDefinition(processDefinition);
116     newTransaction();
117     processDefinition = graphSession.loadProcessDefinition(processDefinition.getId());
118     assertNotNull(processDefinition.getContextDefinition());
119     assertTrue(ContextDefinition.class.isAssignableFrom(processDefinition.getContextDefinition().getClass()));
120   }
121   
122   public void testFileDefinition() {
123     ProcessDefinition processDefinition = new ProcessDefinition();
124     processDefinition.addDefinition(new FileDefinition());
125
126     processDefinition = saveAndReload(processDefinition);
127
128     assertNotNull(processDefinition.getFileDefinition());
129     assertTrue(FileDefinition.class.isAssignableFrom(processDefinition.getFileDefinition().getClass()));
130   }
131
132   public void testTaskMgmtDefinition() {
133     ProcessDefinition processDefinition = new ProcessDefinition();
134     processDefinition.addDefinition(new TaskMgmtDefinition());
135
136     processDefinition = saveAndReload(processDefinition);
137
138     assertNotNull(processDefinition.getTaskMgmtDefinition());
139     assertTrue(TaskMgmtDefinition.class.isAssignableFrom(processDefinition.getTaskMgmtDefinition().getClass()));
140   }
141   
142 }
143
Popular Tags