KickJava   Java API By Example, From Geeks To Geeks.

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


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.def.VariableTypeInfo;
10 import org.jbpm.bpel.data.exe.VariableInstance;
11 import org.jbpm.bpel.def.Link;
12 import org.jbpm.bpel.def.Receive;
13 import org.jbpm.bpel.def.Switch;
14
15 /**
16  * @author Juan Cantú
17  * @version $Revision: 1.5 $ $Date: 2005/05/07 00:03:44 $
18  */

19 public class SwitchExeTest extends AbstractExeTestCase {
20   VariableInstance condition1;
21   VariableInstance condition2;
22   Switch switchBlock;
23   Receive case1R;
24   Receive case2R;
25   Receive otherwiseR;
26   LinkInstance case1L;
27   LinkInstance case2L;
28   LinkInstance otherwiseL;
29   Token root;
30   
31   String JavaDoc xml =
32     "<switch>" +
33     " <case>" +
34     " <condition>$condition1</condition>" +
35     " <receive name='case1' partnerLink='aPartner' operation='o'/>" +
36     " </case>" +
37     " <case>" +
38     " <condition>$condition2</condition>" +
39     " <receive name='case2' partnerLink='aPartner' operation='o'/>" +
40     " </case>" +
41     " <otherwise>" +
42     " <receive name='otherwise' partnerLink='aPartner' operation='o'/>" +
43     " </otherwise>" +
44     "</switch>";
45   
46   public void setUp() throws Exception JavaDoc {
47     super.setUp();
48     switchBlock = (Switch) readActivity(xml, false);
49     setNestedBlock(switchBlock);
50     initActivities();
51     
52     VariableTypeInfo boolTypeInfo = new SchemaTypeInfo(new QName JavaDoc("boolean"));
53     VariableDefinition definition1 = new VariableDefinition();
54     definition1.setName("condition1");
55     definition1.setTypeInfo(boolTypeInfo);
56     condition1 = definition1.createInstance(root);
57     VariableDefinition definition2 = new VariableDefinition();
58     definition2.setName("condition2");
59     definition2.setTypeInfo(boolTypeInfo);
60     condition2 = definition2.createInstance(root);
61   }
62   
63   public void initActivities() {
64     case1R = (Receive) switchBlock.getNode("case1");
65     case2R = (Receive) switchBlock.getNode("case2");
66     otherwiseR = (Receive) switchBlock.getNode("otherwise");
67     
68     root = pi.getRootToken();
69     
70     Link case1Link = new TestLink("case1");
71     case1R.addSource(case1Link);
72     case1L = LinkInstance.create(root, case1Link.getName());
73     
74     Link case2Link = new TestLink("case2");
75     case2R.addSource(case2Link);
76     case2L = LinkInstance.create(root, case2Link.getName());
77     
78     Link otherwiseLink = new TestLink("otherwise");
79     otherwiseR.addSource(otherwiseLink);
80     otherwiseL = LinkInstance.create(root, otherwiseLink.getName());
81   }
82   
83   public void testFirstCase() {
84     condition1.setValue(Boolean.TRUE);
85     condition2.setValue(Boolean.FALSE);
86     Token token = startNested();
87   
88     assertReceiveAndComplete(token, case1R);
89     assertReceiveDisabled(token, case2R);
90     assertReceiveDisabled(token, otherwiseR);
91     
92     assertNotNull( case1L.getReached() );
93     assertEquals( Boolean.FALSE, case2L.getReached() );
94     assertEquals( Boolean.FALSE, otherwiseL.getReached() );
95   }
96
97   public void testSecondCase() {
98     condition1.setValue(Boolean.FALSE);
99     condition2.setValue(Boolean.TRUE);
100     Token token = startNested();
101     
102     assertReceiveAndComplete(token, case2R);
103     assertReceiveDisabled(token, case1R);
104     assertReceiveDisabled(token, otherwiseR);
105     
106     assertNotNull( case2L.getReached() );
107     assertEquals( Boolean.FALSE, case1L.getReached() );
108     assertEquals( Boolean.FALSE, otherwiseL.getReached() );
109   }
110   
111   public void testOtherwise() {
112     condition1.setValue(Boolean.FALSE);
113     condition2.setValue(Boolean.FALSE);
114     Token token = startNested();
115     
116     assertReceiveAndComplete(token, otherwiseR);
117     assertReceiveDisabled(token, case1R);
118     assertReceiveDisabled(token, case2R);
119     
120     assertNotNull( otherwiseL.getReached() );
121     assertEquals( Boolean.FALSE, case1L.getReached() );
122     assertEquals( Boolean.FALSE, case2L.getReached() );
123   }
124   
125   public void testOtherwiseDefault() {
126     switchBlock.removeNode(otherwiseR);
127     condition1.setValue(Boolean.FALSE);
128     condition2.setValue(Boolean.FALSE);
129     Token token = startNested();
130     
131     assertReceiveDisabled(token, case1R);
132     assertReceiveDisabled(token, case2R);
133     
134     assertEquals( Boolean.FALSE, case1L.getReached() );
135     assertEquals( Boolean.FALSE, case2L.getReached() );
136     
137     assertCompleted(token);
138   }
139 }
140
Popular Tags