KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.jbpm.bpel.def;
2
3 import java.util.Collection JavaDoc;
4
5 import junit.framework.TestCase;
6
7 /**
8  * @author Juan Cantu
9  * @version $Revision: 1.2 $ $Date: 2005/05/07 00:03:43 $
10  */

11 public class FlowDefTest extends TestCase {
12   Flow flow;
13   Activity first;
14   Activity second;
15   
16   public void setUp() {
17     flow = new Flow();
18     first = new Empty("first");
19     second = new Empty("second");
20   }
21   
22   public void testAddNode() {
23     flow.addNode(first);
24     assertConnected(first);
25     flow.addNode(second);
26     assertConnected(second);
27   }
28  
29   public void testRemoveNode() {
30     //remove first, middle and last activities
31
flow.addNode(first);
32     flow.addNode(second);
33     
34     flow.removeNode(first);
35     assertDisconnected(first);
36     flow.removeNode(second);
37     assertDisconnected(second);
38     
39     assertEquals(0, flow.getStart().getLeavingTransitions().size());
40     assertEquals(0, flow.getEnd().getArrivingTransitions().size());
41   }
42   
43   private void assertConnected(Activity activity) {
44     Collection JavaDoc transitions = flow.getStart().getLeavingTransitions();
45     assertTrue( transitions.contains( activity.getDefaultArrivingTransition() ) );
46     
47     transitions = flow.getEnd().getArrivingTransitions();
48     assertTrue( transitions.contains(activity.getDefaultLeavingTransition()) );
49   }
50   
51   private void assertDisconnected(Activity activity) {
52     //validate that removed activity doesn't have incoming / outgoing transitions
53
assertEquals(0, activity.getArrivingTransitions().size());
54     assertEquals(0, activity.getLeavingTransitions().size());
55   }
56  
57 }
58
Popular Tags