KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > bpel > exe > InitialActivitiesTest


1 package org.jbpm.bpel.exe;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.Iterator JavaDoc;
5 import java.util.List JavaDoc;
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 /**
13  * @author Juan Cantú
14  * @version $Revision: 1.2 $ $Date: 2005/04/27 20:52:27 $
15  */

16 public class InitialActivitiesTest extends AbstractExeTestCase {
17   private List JavaDoc receivers;
18   private Receive receiveR;
19   private Receive sequenceR;
20   private Pick pick;
21   private Receive flowR1;
22   private Receive flowR2;
23   
24   String JavaDoc 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 JavaDoc {
46     super.setUp();
47     
48     StructuredActivity root = (StructuredActivity) readActivity(xml, true);
49     setRootBlock(root);
50     
51     //Create a list with all the receivers that can trigger new instances
52
receivers = new ArrayList JavaDoc();
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 JavaDoc 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 JavaDoc 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   //validate for every receiver that when a new instance is triggered,
106
//a token is created for the rest of the receivers.
107
public void validateOtherReceivers(Receiver trigger) {
108     Token parent = startInitial(trigger).getProcessInstance().getRootToken();
109       
110     for(Iterator JavaDoc it = receivers.iterator(); it.hasNext();) {
111       Receiver otherReceiver = (Receiver) it.next();
112       
113       if(!otherReceiver.equals(trigger)) {
114         Object JavaDoc 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