KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > bpel > def > SequenceDefTest


1 package org.jbpm.bpel.def;
2
3 import java.util.Iterator JavaDoc;
4
5 import org.jbpm.graph.def.Transition;
6
7 import junit.framework.TestCase;
8
9 /**
10  * @author Juan Cantu
11  * @version $Revision: 1.3 $ $Date: 2005/06/03 00:13:42 $
12  */

13 public class SequenceDefTest extends TestCase {
14
15   Sequence sequence;
16   Activity activity;
17   public void setUp() {
18     sequence = new Sequence();
19     activity = new Empty("5");
20     sequence.addNode(activity);
21     activity = new Empty("6");
22     sequence.addNode(activity);
23     activity = new Empty("7");
24     sequence.addNode(activity);
25     activity = new Empty("8's");
26     sequence.addNode(activity);
27   }
28   
29   public void testAddNode() {
30     //validate that nodes are connected in sequential order
31
assertEquals(sequence.getStart().getDefaultLeavingTransition().getTo(), sequence.getNode("5"));
32     assertEquals(sequence.getNode("5").getDefaultLeavingTransition().getTo(), sequence.getNode("6"));
33     assertEquals(sequence.getNode("6").getDefaultLeavingTransition().getTo(), sequence.getNode("7"));
34     assertEquals(sequence.getNode("7").getDefaultLeavingTransition().getTo(), sequence.getNode("8's"));
35     assertEquals(sequence.getNode("8's").getDefaultLeavingTransition().getTo(), sequence.getEnd());
36   }
37  
38   public void testRemoveNode() {
39     //remove first, middle and last activities
40
Activity first = (Activity) sequence.getNode("5");
41     Activity middle = (Activity) sequence.getNode("7");
42     Activity last = (Activity) sequence.getNode("8's");
43     
44     sequence.removeNode(first);
45     sequence.removeNode(middle);
46     sequence.removeNode(last);
47     
48     //validate that remaining nodes are connected in sequential order
49
assertEquals(sequence.getStart().getDefaultLeavingTransition().getTo(), sequence.getNode("6"));
50     assertEquals(sequence.getNode("6").getDefaultLeavingTransition().getTo(), sequence.getEnd());
51     
52     //validate that removed nodes don't have incoming / outgoing transitions
53
assertEquals(0, first.getArrivingTransitions().size());
54     assertEquals(0, first.getLeavingTransitions().size());
55     
56     assertEquals(0, middle.getArrivingTransitions().size());
57     assertEquals(0, middle.getLeavingTransitions().size());
58     
59     assertEquals(0, last.getArrivingTransitions().size());
60     assertEquals(0, last.getLeavingTransitions().size());
61   }
62   
63   public void testReorder() {
64     //this sequence of reorder invocation inverts list order
65
sequence.reorderNode(1, 2);
66     sequence.reorderNode(0, 3);
67     sequence.reorderNode(2, 0);
68
69     //validate that the nodes are connected in inverse sequential order
70
Iterator JavaDoc it = sequence.getNodes().iterator();
71     
72     assertEquals(sequence.getStart().getDefaultLeavingTransition().getTo(), it.next());
73     assertEquals(sequence.getNode("8's").getDefaultLeavingTransition().getTo(), it.next());
74     assertEquals(sequence.getNode("7").getDefaultLeavingTransition().getTo(), it.next());
75     assertEquals(sequence.getNode("6").getDefaultLeavingTransition().getTo(), it.next());
76     assertEquals(sequence.getNode("5").getDefaultLeavingTransition().getTo(), sequence.getEnd());
77   }
78   
79   public void testMixedConnectionScenario() {
80     sequence.removeNode(sequence.getNode("7"));
81     sequence.removeNode(sequence.getNode("6"));
82     sequence.reorderNode(0, 1);
83     
84     Activity start = sequence.getStart();
85     Activity end = sequence.getEnd();
86     Activity first = (Activity) sequence.getNode("8's");
87     Activity last = (Activity) sequence.getNode("5");
88     
89     Transition from = (Transition) start.getLeavingTransitions().get(0);
90     Transition to = (Transition) end.getArrivingTransitions().iterator().next();
91     
92     assertEquals(from, first.getDefaultArrivingTransition());
93     assertEquals(first.getDefaultLeavingTransition(), last.getDefaultArrivingTransition());
94     assertEquals(to, last.getDefaultLeavingTransition());
95   }
96 }
Popular Tags