KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.jbpm.bpel.exe;
2
3 import javax.xml.namespace.QName JavaDoc;
4
5 import org.jbpm.graph.exe.Token;
6
7 import org.jbpm.bpel.data.def.SchemaTypeInfo;
8 import org.jbpm.bpel.data.def.VariableDefinition;
9 import org.jbpm.bpel.data.exe.VariableInstance;
10 import org.jbpm.bpel.def.Receive;
11 import org.jbpm.bpel.def.While;
12 import org.jbpm.bpel.xml.BpelConstants;
13
14 /**
15  * @author Juan Cantú
16  * @version $Revision: 1.4 $ $Date: 2005/05/07 00:03:44 $
17  */

18 public class WhileExeTest extends AbstractExeTestCase {
19   VariableInstance condition;
20   While whileBlock;
21   Receive receive;
22   
23   String JavaDoc xml =
24     "<while>" +
25     "<condition>$condition</condition>" +
26     " <receive name='receive' partnerLink='aPartner' operation='o'/>" +
27     "</while>";
28   
29   public void setUp() throws Exception JavaDoc {
30     super.setUp();
31     whileBlock = (While) readActivity(xml, false);
32     setNestedBlock(whileBlock);
33
34     receive = (Receive) whileBlock.getNode("receive");
35     Token root = pi.getRootToken();
36     VariableDefinition conditionDefinition = new VariableDefinition();
37     conditionDefinition.setName("condition");
38     conditionDefinition.setTypeInfo(new SchemaTypeInfo(new QName JavaDoc(BpelConstants.NS_XML_SCHEMA, "boolean")));
39     condition = conditionDefinition.createInstance(root);
40   }
41   
42   public void testFalseCondition() {
43     condition.setValue(Boolean.FALSE);
44     Token startToken = startNested();
45     
46     assertReceiveDisabled(startToken, receive);
47     assertCompleted(startToken);
48   }
49   
50   public void testTrueCondition() {
51     condition.setValue(Boolean.TRUE);
52     Token startToken = startNested();
53     
54     //execute receive again, test that token returns to the same activity.
55
assertReceiveAndAdvance(startToken, receive, receive);
56     //set condition to false and finish cycle
57
condition.setValue(Boolean.FALSE);
58     assertReceiveAndComplete(startToken, receive);
59   }
60 }
61
Popular Tags