KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.jbpm.graph.def;
2
3 import java.util.*;
4
5 import org.jbpm.db.*;
6
7 public class NodeDbTest extends AbstractDbTestCase {
8   
9   public void testNodeName() {
10     ProcessDefinition processDefinition = new ProcessDefinition();
11     Node node = new Node("n");
12     processDefinition.addNode(node);
13
14     processDefinition = saveAndReload(processDefinition);
15
16     assertNotNull(processDefinition);
17     assertEquals("n", processDefinition.getNode("n").getName());
18   }
19   
20   public void testNodeProcessDefinition() {
21     ProcessDefinition processDefinition = new ProcessDefinition("p");
22     Node node = new Node("n");
23     processDefinition.addNode(node);
24
25     processDefinition = saveAndReload(processDefinition);
26
27     assertNotNull(processDefinition);
28     assertEquals("p", processDefinition.getNode("n").getProcessDefinition().getName());
29   }
30   
31   public void testNodeEvents() {
32     ProcessDefinition processDefinition = new ProcessDefinition();
33     Node node = new Node("n");
34     processDefinition.addNode(node);
35     node.addEvent(new Event("node-enter"));
36     node.addEvent(new Event("node-leave"));
37     node.addEvent(new Event("transition"));
38     node.addEvent(new Event("process-start"));
39     node.addEvent(new Event("process-end"));
40
41     processDefinition = saveAndReload(processDefinition);
42
43     node = processDefinition.getNode("n");
44     assertNotNull(node.getEvent("node-enter"));
45     assertNotNull(node.getEvent("node-leave"));
46     assertNotNull(node.getEvent("transition"));
47     assertNotNull(node.getEvent("process-start"));
48     assertNotNull(node.getEvent("process-end"));
49   }
50
51   public void testNodeExceptionHandlers() {
52     ProcessDefinition processDefinition = new ProcessDefinition();
53     Node node = new Node("n");
54     processDefinition.addNode(node);
55     ExceptionHandler exceptionHandler = new ExceptionHandler();
56     exceptionHandler.setExceptionClassName("org.disaster.FirstException");
57     node.addExceptionHandler(exceptionHandler);
58     exceptionHandler = new ExceptionHandler();
59     exceptionHandler.setExceptionClassName("org.disaster.SecondException");
60     node.addExceptionHandler(exceptionHandler);
61     exceptionHandler = new ExceptionHandler();
62     exceptionHandler.setExceptionClassName("org.disaster.ThirdException");
63     node.addExceptionHandler(exceptionHandler);
64
65     processDefinition = saveAndReload(processDefinition);
66
67     assertEquals("org.disaster.FirstException",((ExceptionHandler)processDefinition.getNode("n").getExceptionHandlers().get(0)).getExceptionClassName());
68     assertEquals("org.disaster.SecondException",((ExceptionHandler)processDefinition.getNode("n").getExceptionHandlers().get(1)).getExceptionClassName());
69     assertEquals("org.disaster.ThirdException",((ExceptionHandler)processDefinition.getNode("n").getExceptionHandlers().get(2)).getExceptionClassName());
70   }
71
72   public void testNodeLeavingTransitions() {
73     ProcessDefinition processDefinition = new ProcessDefinition();
74     Node a = new Node("a");
75     Node b = new Node("b");
76     processDefinition.addNode(a);
77     processDefinition.addNode(b);
78     
79     Transition t = new Transition("one");
80     a.addLeavingTransition(t);
81     b.addArrivingTransition(t);
82     
83     t = new Transition("two");
84     a.addLeavingTransition(t);
85     b.addArrivingTransition(t);
86     
87     t = new Transition("three");
88     a.addLeavingTransition(t);
89     b.addArrivingTransition(t);
90
91     processDefinition = saveAndReload(processDefinition);
92
93     a = processDefinition.getNode("a");
94     b = processDefinition.getNode("b");
95     
96     assertEquals("one", ((Transition)a.getLeavingTransitionsList().get(0)).getName());
97     assertEquals("two", ((Transition)a.getLeavingTransitionsList().get(1)).getName());
98     assertEquals("three", ((Transition)a.getLeavingTransitionsList().get(2)).getName());
99     
100     assertSame(b, a.getLeavingTransition("one").getTo());
101     assertSame(b, a.getLeavingTransition("two").getTo());
102     assertSame(b, a.getLeavingTransition("three").getTo());
103   }
104
105   public void testNodeArrivingTransitions() {
106     ProcessDefinition processDefinition = new ProcessDefinition();
107     Node a = new Node("a");
108     Node b = new Node("b");
109     processDefinition.addNode(a);
110     processDefinition.addNode(b);
111     
112     Transition t = new Transition("one");
113     a.addLeavingTransition(t);
114     b.addArrivingTransition(t);
115     
116     t = new Transition("two");
117     a.addLeavingTransition(t);
118     b.addArrivingTransition(t);
119     
120     t = new Transition("three");
121     a.addLeavingTransition(t);
122     b.addArrivingTransition(t);
123
124     processDefinition = saveAndReload(processDefinition);
125
126     a = processDefinition.getNode("a");
127     b = processDefinition.getNode("b");
128     
129     Iterator arrivingTransitionIter = b.getArrivingTransitions().iterator();
130     assertSame(b, ((Transition)arrivingTransitionIter.next()).getTo());
131     assertSame(b, ((Transition)arrivingTransitionIter.next()).getTo());
132     assertSame(b, ((Transition)arrivingTransitionIter.next()).getTo());
133
134     Collection expectedTransitionNames = new HashSet(Arrays.asList(new String JavaDoc[]{"one", "two", "three"}));
135     arrivingTransitionIter = b.getArrivingTransitions().iterator();
136     expectedTransitionNames.remove( ((Transition)arrivingTransitionIter.next()).getName() );
137     expectedTransitionNames.remove( ((Transition)arrivingTransitionIter.next()).getName() );
138     expectedTransitionNames.remove( ((Transition)arrivingTransitionIter.next()).getName() );
139     assertEquals(0, expectedTransitionNames.size());
140   }
141
142   public void testNodeAction() {
143     ProcessDefinition processDefinition = new ProcessDefinition();
144     Node node = new Node("n");
145     processDefinition.addNode(node);
146     Action action = new Action();
147     action.setName("a");
148     node.setAction(action);
149
150     processDefinition = saveAndReload(processDefinition);
151
152     assertNotNull(processDefinition.getNode("n").getAction());
153   }
154
155   public void testNodeSuperState() {
156     ProcessDefinition processDefinition = new ProcessDefinition();
157     SuperState superState = new SuperState("s");
158     processDefinition.addNode(superState);
159     Node node = new Node("n");
160     superState.addNode(node);
161
162     processDefinition = saveAndReload(processDefinition);
163
164     superState = (SuperState) processDefinition.getNode("s");
165     node = superState.getNode("n");
166     assertNotNull(node);
167     assertNotNull(superState);
168     assertSame(node, superState.getNode("n"));
169   }
170 }
171
Popular Tags