KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.jbpm.graph.def;
2
3 import java.util.HashSet JavaDoc;
4 import java.util.Set JavaDoc;
5
6 import junit.framework.TestCase;
7
8 import org.jbpm.graph.node.Decision;
9 import org.jbpm.graph.node.EndState;
10 import org.jbpm.graph.node.Fork;
11 import org.jbpm.graph.node.InterleaveEnd;
12 import org.jbpm.graph.node.InterleaveStart;
13 import org.jbpm.graph.node.Join;
14 import org.jbpm.graph.node.Merge;
15 import org.jbpm.graph.node.MilestoneNode;
16 import org.jbpm.graph.node.ProcessState;
17 import org.jbpm.graph.node.StartState;
18 import org.jbpm.graph.node.State;
19 import org.jbpm.graph.node.TaskNode;
20 import org.jbpm.taskmgmt.def.Task;
21
22 /**
23  * All decendents of {@link org.jbpm.graph.def.GraphElement} have an concrete
24  * implementation of the method getSupportedEventTypes() which returns a String
25  * array of event names that are accepted by this graph element.
26  *
27  * This test case has two purposes: 1) insuring that the graph elements return
28  * their expected list 2) document which graph elements support which events
29  * through logging
30  *
31  * @author Jim Rigsbee
32  * @since 3.0
33  */

34 public class SupportedEventsTest extends TestCase {
35
36   public void testNodeEvents() {
37     assertSupportedEvents(new Node(), new String JavaDoc[] { "node-enter", "node-leave", "before-signal", "after-signal" });
38   }
39
40   public void testDecisionEvents() {
41     assertSupportedEvents(new Decision(), new String JavaDoc[] { "node-enter", "node-leave", "before-signal", "after-signal" });
42   }
43
44   public void testEndStateEvents() {
45     assertSupportedEvents(new EndState(), new String JavaDoc[] { "node-enter" });
46   }
47
48   public void testForkEvents() {
49     assertSupportedEvents(new Fork(), new String JavaDoc[] { "node-enter", "node-leave", "before-signal", "after-signal" });
50   }
51
52   public void testInterleaveEndEvents() {
53     assertSupportedEvents(new InterleaveEnd(), new String JavaDoc[] { "node-enter", "node-leave", "before-signal", "after-signal" });
54   }
55
56   public void testInterleaveStartEvents() {
57     assertSupportedEvents(new InterleaveStart(), new String JavaDoc[] { "node-enter", "node-leave", "before-signal", "after-signal" });
58   }
59
60   public void testJoinEvents() {
61     assertSupportedEvents(new Join(), new String JavaDoc[] { "node-enter", "node-leave", "before-signal", "after-signal" });
62   }
63
64   public void testMergeEvents() {
65     assertSupportedEvents(new Merge(), new String JavaDoc[] { "node-enter", "node-leave", "before-signal", "after-signal" });
66   }
67
68   public void testMilestoneNodeEvents() {
69     assertSupportedEvents(new MilestoneNode(), new String JavaDoc[] { "node-enter", "node-leave", "before-signal", "after-signal" });
70   }
71
72   public void testProcessStateEvents() {
73     assertSupportedEvents(new ProcessState(), new String JavaDoc[] { "node-leave", "node-enter", "after-signal", "before-signal", "subprocess-created",
74         "subprocess-end" });
75   }
76
77   public void testStartStateEvents() {
78     assertSupportedEvents(new StartState(), new String JavaDoc[] { "node-leave", "after-signal" });
79   }
80
81   public void testStateEvents() {
82     assertSupportedEvents(new State(), new String JavaDoc[] { "node-enter", "node-leave", "before-signal", "after-signal" });
83   }
84
85   public void testSuperStateEvents() {
86     assertSupportedEvents(new SuperState(), new String JavaDoc[] { "transition", "before-signal", "after-signal", "node-enter", "node-leave", "superstate-enter",
87         "superstate-leave", "subprocess-created", "subprocess-end", "task-create", "task-assign", "task-start", "task-end", "timer" });
88   }
89
90   public void testTaskNodeEvents() {
91     assertSupportedEvents(new TaskNode(), new String JavaDoc[] { "node-enter", "node-leave", "before-signal", "after-signal" });
92   }
93
94   public void testTaskEvents() {
95     assertSupportedEvents(new Task(), new String JavaDoc[] { "task-create", "task-assign", "task-start", "task-end" });
96   }
97
98   public void testProcessDefinitionEvents() {
99     assertSupportedEvents(new ProcessDefinition(), new String JavaDoc[] { "transition", "before-signal", "after-signal", "process-start", "process-end", "node-enter",
100         "node-leave", "superstate-enter", "superstate-leave", "subprocess-created", "subprocess-end", "task-create", "task-assign", "task-start", "task-end",
101         "timer" });
102   }
103
104   public void testTransitionEvents() {
105     assertSupportedEvents(new Transition(), new String JavaDoc[] { "transition" });
106   }
107
108   private void assertSupportedEvents(GraphElement graphElement, String JavaDoc[] expectedEventTypes) {
109     String JavaDoc[] supportedEventTypes = graphElement.getSupportedEventTypes();
110
111     Set JavaDoc expectedSet = getHashSet(expectedEventTypes);
112     Set JavaDoc supportedSet = getHashSet(supportedEventTypes);
113
114     assertEquals(expectedSet, supportedSet);
115   }
116
117   private HashSet JavaDoc getHashSet(String JavaDoc[] strings) {
118     HashSet JavaDoc set = new HashSet JavaDoc();
119     for (int i = 0; i < strings.length; i++) {
120       set.add(strings[i]);
121     }
122     return set;
123   }
124 }
125
Popular Tags