1 package org.jbpm.bpel.exe; 2 3 import java.util.ArrayList ; 4 import java.util.Iterator ; 5 import java.util.List ; 6 7 import org.jbpm.graph.exe.Token; 8 9 import org.jbpm.bpel.def.*; 10 import org.jbpm.bpel.service.def.Receiver; 11 12 16 public class InitialActivitiesTest extends AbstractExeTestCase { 17 private List receivers; 18 private Receive receiveR; 19 private Receive sequenceR; 20 private Pick pick; 21 private Receive flowR1; 22 private Receive flowR2; 23 24 String xml = 25 "<flow>" + 26 " <receive name='a' partnerLink='aPartner' operation='o'/>" + 27 " <pick name='b'>" + 28 " <onMessage partnerLink='aPartner' operation='o'>" + 29 " <empty/>" + 30 " </onMessage>" + 31 " <onMessage partnerLink='aPartner' operation='o'>" + 32 " <empty/>" + 33 " </onMessage>" + 34 " </pick>" + 35 " <sequence name='sequence'>" + 36 " <receive name='c' partnerLink='aPartner' operation='o'/>" + 37 " <empty/>" + 38 " </sequence>" + 39 " <flow name='flow'>" + 40 " <receive name='d' partnerLink='aPartner' operation='o'/>" + 41 " <receive name='e' partnerLink='aPartner' operation='o'/>" + 42 " </flow>" + 43 "</flow>"; 44 45 public void setUp() throws Exception { 46 super.setUp(); 47 48 StructuredActivity root = (StructuredActivity) readActivity(xml, true); 49 setRootBlock(root); 50 51 receivers = new ArrayList (); 53 receiveR = ((Receive) root.getNode("a")); 54 receivers.add(receiveR.getReceiver()); 55 56 pick = ((Pick) root.getNode("b")); 57 receivers.addAll(pick.getOnMessages()); 58 59 Sequence sequence = (Sequence) root.getNode("sequence"); 60 sequenceR = ((Receive)sequence.getNode("c")); 61 receivers.add(sequenceR.getReceiver()); 62 63 Flow flow = ((Flow) root.getNode("flow")); 64 flowR1 = ((Receive)flow.getNode("d")); 65 receivers.add(flowR1.getReceiver()); 66 flowR2 = ((Receive)flow.getNode("e")); 67 receivers.add(flowR2.getReceiver()); 68 } 69 70 public void testReceiveReceiver() { 71 receiveR.setCreateInstance(true); 72 validateOtherReceivers(receiveR.getReceiver()); 73 } 74 75 public void testSequenceReceiver() { 76 sequenceR.setCreateInstance(true); 77 validateOtherReceivers(sequenceR.getReceiver()); 78 } 79 80 public void testPickFirstReceiver() { 81 pick.setCreateInstance(true); 82 Iterator it = pick.getOnMessages().iterator(); 83 Receiver receiver = (Receiver) it.next(); 84 receivers.remove(it.next()); 85 validateOtherReceivers( receiver ); 86 } 87 88 public void testPickSecondReceiver() { 89 pick.setCreateInstance(true); 90 Iterator it = pick.getOnMessages().iterator(); 91 receivers.remove(it.next()); 92 validateOtherReceivers((Receiver) it.next()); 93 } 94 95 public void testFlowFirstReceiver() { 96 flowR1.setCreateInstance(true); 97 validateOtherReceivers(flowR1.getReceiver()); 98 } 99 100 public void testFlowSecondReceiver() { 101 flowR2.setCreateInstance(true); 102 validateOtherReceivers(flowR2.getReceiver()); 103 } 104 105 public void validateOtherReceivers(Receiver trigger) { 108 Token parent = startInitial(trigger).getProcessInstance().getRootToken(); 109 110 for(Iterator it = receivers.iterator(); it.hasNext();) { 111 Receiver otherReceiver = (Receiver) it.next(); 112 113 if(!otherReceiver.equals(trigger)) { 114 Object activity = otherReceiver.getInboundMessageActivity(); 115 Activity node = 116 activity instanceof Pick ? ((Pick)activity).getStart() : (Activity)activity; 117 Token token = (Token)parent.getChildrenAtNode(node).iterator().next(); 118 assertReceiverEnabled( token, otherReceiver ); 119 } 120 } 121 } 122 } 123 | Popular Tags |