KickJava   Java API By Example, From Geeks To Geeks.

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


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

13 public class WhileDefTest extends TestCase {
14   While whileBlock;
15   Activity child;
16   Activity otherChild;
17   
18   public void setUp() {
19     whileBlock = new While();
20     child = new Empty("first");
21     otherChild = new Empty("second");
22   }
23   
24   public void testAddNode() {
25     whileBlock.addNode(child);
26     assertConnected(child);
27     assertEquals(whileBlock, child.getCompositeActivity());
28   }
29   
30   public void testAddNodeOverride() {
31     whileBlock.addNode(child);
32     whileBlock.addNode(otherChild);
33     assertConnected(otherChild);
34     assertDisconnected(child);
35   }
36   
37   public void testRemoveNode() {
38     whileBlock.addNode(child);
39     whileBlock.removeNode(child);
40     assertDisconnected(child);
41     
42     assertEquals(0, whileBlock.getNodes().size());
43   }
44   
45   public void testCondition() {
46     Snippet expression = new Snippet();
47     whileBlock.setCondition(expression);
48     assertEquals(expression, whileBlock.getCondition());
49   }
50   
51   private void assertConnected(Activity activity) {
52     Collection JavaDoc transitions = whileBlock.getLoopNode().getLeavingTransitions();
53     assertTrue( transitions.contains( activity.getDefaultArrivingTransition() ) );
54     
55     transitions = whileBlock.getLoopNode().getArrivingTransitions();
56     assertTrue( transitions.contains(activity.getDefaultLeavingTransition()) );
57     
58     assertEquals(whileBlock, activity.getCompositeActivity());
59     assertEquals(1, whileBlock.getNodes().size());
60   }
61   
62   private void assertDisconnected(Activity activity) {
63     //validate that removed activity doesn't have incoming / outgoing transitions
64
assertEquals(0, activity.getArrivingTransitions().size());
65     assertEquals(0, activity.getLeavingTransitions().size());
66     assertEquals(null, activity.getCompositeActivity());
67   }
68  
69 }
70
Popular Tags