1 package org.jbpm.graph.def; 2 3 import java.util.Iterator ; 4 import java.util.List ; 5 6 import junit.framework.TestCase; 7 8 public class LeavingTransitionsTest extends TestCase { 9 10 private Node node = new Node("n"); 11 private Transition transition = new Transition("t"); 12 13 public void testAddLeavingTransitionWithoutName() { 14 Transition transitionWithoutName = new Transition(); 15 node.addLeavingTransition( transitionWithoutName ); 16 assertEquals( 1, node.getLeavingTransitionsMap().size() ); 17 assertEquals( 1, node.getLeavingTransitionsMap().size() ); 18 assertSame( transitionWithoutName, node.getLeavingTransition(null) ); 19 assertSame( transitionWithoutName, node.getLeavingTransitionsList().get(0) ); 20 assertSame( node, transitionWithoutName.getFrom() ); 21 } 22 23 public void testAddLeavingTransition() { 24 node.addLeavingTransition( transition ); 25 assertEquals( 1, node.getLeavingTransitionsMap().size() ); 26 assertEquals( 1, node.getLeavingTransitionsMap().size() ); 27 assertSame( transition, node.getLeavingTransition("t") ); 28 assertSame( transition, node.getLeavingTransitionsList().get(0) ); 29 assertSame( node, transition.getFrom() ); 30 } 31 32 public void testRename() { 33 node.addLeavingTransition( transition ); 34 transition.setName("t2"); 35 assertSame(transition, node.getLeavingTransition("t2")); 36 } 37 38 public void testRemoveLeavingTransition() { 39 node.addLeavingTransition( transition ); 40 node.removeLeavingTransition( transition ); 41 assertNull( node.getLeavingTransition("t") ); 42 assertNull( transition.getFrom() ); 43 assertEquals( 0, node.getLeavingTransitionsMap().size() ); 44 } 45 46 public void testOverwriteLeavingTransitionAllowed() { 47 node.addLeavingTransition( transition ); 48 node.addLeavingTransition( new Transition() ); 49 assertEquals(2, node.getLeavingTransitionsMap().size()); 50 51 Iterator iter = node.getLeavingTransitionsList().iterator(); 52 while (iter.hasNext()) { 53 assertSame( node, ((Transition)iter.next()).getFrom() ); 54 } 55 } 56 57 public void testLeavingTransitionsXmlTest() { 58 ProcessDefinition processDefinition = ProcessDefinition.parseXmlString( 59 "<process-definition>" + 60 " <state name='a'>" + 61 " <transition to='b' />" + 62 " <transition name='to-c' to='c' />" + 63 " <transition name='to-d' to='d' />" + 64 " </state>" + 65 " <state name='b' />" + 66 " <state name='c'/>" + 67 " <state name='d'/>" + 68 "</process-definition>" 69 ); 70 71 List leavingTransitions = processDefinition.getNode("a").getLeavingTransitionsList(); 72 assertEquals(3, leavingTransitions.size()); 73 assertNull( ((Transition)leavingTransitions.get(0)).getName()); 74 } 75 } 76 | Popular Tags |