1 package org.jbpm.bpel.def; 2 3 import java.util.Iterator ; 4 5 import org.jbpm.graph.def.Transition; 6 7 import junit.framework.TestCase; 8 9 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 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 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 assertEquals(sequence.getStart().getDefaultLeavingTransition().getTo(), sequence.getNode("6")); 50 assertEquals(sequence.getNode("6").getDefaultLeavingTransition().getTo(), sequence.getEnd()); 51 52 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 sequence.reorderNode(1, 2); 66 sequence.reorderNode(0, 3); 67 sequence.reorderNode(2, 0); 68 69 Iterator 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 |