1 package org.jbpm.bpel.def; 2 3 import java.util.Collection ; 4 5 import junit.framework.TestCase; 6 7 import org.jbpm.bpel.service.def.Receiver; 8 import org.jbpm.bpel.timer.def.Alarm; 9 10 14 public class PickDefTest extends TestCase { 15 Pick pick; 16 Activity first; 17 Activity second; 18 19 public void setUp() { 20 pick = new Pick(); 21 first = new Empty("first"); 22 second = new Empty("second"); 23 } 24 25 public void testAddNode() { 26 pick.addNode(first); 27 assertConnected(first); 28 pick.addNode(second); 29 assertConnected(second); 30 assertEquals(2, pick.getOnMessages().size()); 31 } 32 33 public void testRemoveNode() { 34 pick.addNode(first); 35 pick.addNode(second); 36 pick.setOnAlarm(first, new Alarm(pick)); 37 pick.setOnMessage(second, new Receiver(pick)); 38 39 pick.removeNode(first); 40 assertDisconnected(first); 41 42 pick.removeNode(second); 43 assertDisconnected(second); 44 45 assertEquals(0, pick.getStart().getLeavingTransitions().size()); 46 assertEquals(0, pick.getEnd().getArrivingTransitions().size()); 47 48 assertEquals(0, pick.getNodes().size()); 49 assertEquals(0, pick.getOnMessages().size()); 50 assertEquals(0, pick.getOnAlarms().size()); 51 } 52 53 public void testOnAlarm() { 54 Alarm firstAlarm = new Alarm(pick); 55 Alarm secondAlarm = new Alarm(pick); 56 pick.addNode(first); 57 pick.addNode(second); 58 pick.setOnAlarm(first, firstAlarm); 59 pick.setOnAlarm(second, secondAlarm); 60 61 assertEquals(first, pick.getOnAlarm(firstAlarm)); 62 assertEquals(second, pick.getOnAlarm(secondAlarm)); 63 } 64 65 public void testOnMessage() { 66 Receiver firstReceiver = new Receiver(pick); 67 Receiver secondReceiver = new Receiver(pick); 68 pick.addNode(first); 69 pick.addNode(second); 70 pick.setOnMessage(first, firstReceiver); 71 pick.setOnMessage(second, secondReceiver); 72 73 assertEquals(first, pick.getOnMessage(firstReceiver)); 74 assertEquals(second, pick.getOnMessage(secondReceiver)); 75 } 76 77 public void testOnMessageOverride() { 78 Receiver receiver = new Receiver(pick); 79 pick.addNode(first); 80 pick.addNode(second); 81 82 pick.setOnAlarm(first, new Alarm(pick)); 83 pick.setOnMessage(first, receiver); 84 85 assertEquals(first, pick.getOnMessage(receiver)); 86 } 87 88 public void testOnAlarmOverride() { 89 Alarm alarm = new Alarm(pick); 90 pick.addNode(first); 91 pick.addNode(second); 92 93 pick.setOnMessage(first, new Receiver(pick)); 94 pick.setOnAlarm(first, alarm); 95 96 assertEquals(first, pick.getOnAlarm(alarm)); 97 } 98 99 private void assertConnected(Activity activity) { 100 Collection transitions = pick.getStart().getLeavingTransitions(); 101 assertTrue( transitions.contains( activity.getDefaultArrivingTransition() ) ); 102 103 transitions = pick.getEnd().getArrivingTransitions(); 104 assertTrue( transitions.contains(activity.getDefaultLeavingTransition()) ); 105 } 106 107 private void assertDisconnected(Activity activity) { 108 assertEquals(0, activity.getArrivingTransitions().size()); 110 assertEquals(0, activity.getLeavingTransitions().size()); 111 } 112 113 } 114 | Popular Tags |