1
2
3
4
5
6
7
8
9 package bexee.model;
10
11 import java.util.*;
12
13 import javax.xml.namespace.QName;
14
15 import org.jmock.*;
16
17 import bexee.core.*;
18 import bexee.model.activity.*;
19 import bexee.model.activity.impl.*;
20 import bexee.model.elements.*;
21 import bexee.model.elements.impl.*;
22 import bexee.model.process.Process;
23 import bexee.model.process.impl.ProcessImpl;
24
25 /***
26 * @version $Revision: 1.1 $, $Date: 2004/12/15 14:18:17 $
27 * @author Pawel Kowalski
28 */
29 public class BPELProcessTest extends MockObjectTestCase {
30
31
32
33
34 protected void setUp() throws Exception {
35 super.setUp();
36 }
37
38
39
40
41 protected void tearDown() throws Exception {
42 super.tearDown();
43 }
44
45 //***************************************************/
46
47 //***************************************************/
48
49 public final void testCreateBPELElements() {
50
51
52
53 String clientPartnerLinkName = "client";
54 PartnerLink clientPartnerLink = new PartnerLinkImpl();
55 assertNotNull(clientPartnerLink);
56 clientPartnerLink.setName(clientPartnerLinkName);
57 assertEquals(clientPartnerLinkName, clientPartnerLink.getName());
58
59
60
61 String servicePartnerLinkName = "service";
62 PartnerLink servicePartnerLink = new PartnerLinkImpl();
63 assertNotNull(servicePartnerLink);
64 servicePartnerLink.setName(servicePartnerLinkName);
65 assertEquals(servicePartnerLinkName, servicePartnerLink.getName());
66
67
68
69 String inputVariableName = "input";
70 QName messageType = new QName("tns", "ReceiveRequestMessage");
71 Variable inputVariable = new VariableImpl();
72 assertNotNull(inputVariable);
73 inputVariable.setName(inputVariableName);
74 inputVariable.setMessageType(messageType);
75 assertEquals(inputVariableName, inputVariable.getName());
76 assertEquals(messageType, inputVariable.getMessageType());
77
78
79
80 String responseVariableName = "response";
81 messageType = new QName("tns", "ReceiveResultMessage");
82 Variable responseVariable = new VariableImpl();
83 assertNotNull(responseVariable);
84 responseVariable.setName(responseVariableName);
85 responseVariable.setMessageType(messageType);
86 assertEquals(responseVariableName, responseVariable.getName());
87 assertEquals(messageType, responseVariable.getMessageType());
88
89
90
91 Sequence sequence = new SequenceImpl();
92 assertNotNull(sequence);
93
94
95
96 String receiveName = "receiveInput";
97 String operationName = "initiate";
98 boolean createInstance = true;
99
100
101 Receive receiveInput = new ReceiveImpl();
102 assertNotNull(receiveInput);
103 receiveInput.setName(receiveName);
104 receiveInput.setPartnerLink(clientPartnerLink);
105 receiveInput.setOperation(operationName);
106 receiveInput.setVariable(inputVariable);
107 receiveInput.setCreateInstance(createInstance);
108
109
110 assertEquals(receiveName, receiveInput.getName());
111 assertEquals(clientPartnerLink, receiveInput.getPartnerLink());
112 assertEquals(operationName, receiveInput.getOperation());
113 assertEquals(inputVariable, receiveInput.getVariable());
114 assertEquals(createInstance, receiveInput.isCreateInstance());
115
116
117
118 String invokeName = "asynchInvoke";
119 QName invokePortType = new QName("services", "AsynchBPELService");
120 String invokeOperationName = "initiate";
121
122
123 Invoke invoke = new InvokeImpl();
124 assertNotNull(invoke);
125 invoke.setName(invokeName);
126 invoke.setPartnerLink(servicePartnerLink);
127 invoke.setPortType(invokePortType);
128 invoke.setOperation(invokeOperationName);
129 invoke.setInputVariable(inputVariable);
130
131
132 assertEquals(invokeName, invoke.getName());
133 assertEquals(servicePartnerLink, invoke.getPartnerLink());
134 assertEquals(invokePortType, invoke.getPortType());
135 assertEquals(invokeOperationName, invoke.getOperation());
136 assertEquals(inputVariable, invoke.getInputVariable());
137
138
139
140 receiveName = "receiveResult";
141 operationName = "onResult";
142 createInstance = false;
143 QName receiveResultPortType = new QName("services",
144 "AsyncBPELServiceCallback");
145
146
147 Receive receiveResult = new ReceiveImpl();
148 receiveResult.setName(receiveName);
149 receiveResult.setPartnerLink(servicePartnerLink);
150 receiveResult.setOperation(operationName);
151 receiveResult.setVariable(responseVariable);
152
153
154 assertNotNull(receiveResult);
155 assertEquals(receiveName, receiveResult.getName());
156 assertEquals(servicePartnerLink, receiveResult.getPartnerLink());
157 assertEquals(operationName, receiveResult.getOperation());
158 assertEquals(responseVariable, receiveResult.getVariable());
159 assertEquals(createInstance, receiveResult.isCreateInstance());
160
161
162
163 sequence.addActivity(receiveInput);
164 sequence.addActivity(invoke);
165 sequence.addActivity(receiveResult);
166
167
168 Collection sequenceActivities = sequence.getActivities();
169 assertEquals(sequenceActivities.size(), 3);
170 Iterator iter = sequenceActivities.iterator();
171 assertEquals(receiveInput, (Activity) iter.next());
172 assertTrue(iter.hasNext());
173 assertEquals(invoke, (Activity) iter.next());
174 assertTrue(iter.hasNext());
175 assertEquals(receiveResult, (Activity) iter.next());
176 assertFalse(iter.hasNext());
177
178
179
180 String processName = "bexeeExample";
181 Process process = new ProcessImpl();
182 assertNotNull(process);
183 process.setName(processName);
184 process.setPartnerLinks(new PartnerLinksImpl());
185 process.getPartnerLinks().addPartnerLink(clientPartnerLink);
186 process.getPartnerLinks().addPartnerLink(servicePartnerLink);
187 process.setVariables(new VariablesImpl());
188 process.getVariables().addVariable(inputVariable);
189 process.getVariables().addVariable(responseVariable);
190 process.setActivity(sequence);
191
192
193 assertEquals(processName, process.getName());
194 assertTrue(process.getPartnerLinks().getPartnerLinks().contains(
195 clientPartnerLink));
196 assertTrue(process.getPartnerLinks().getPartnerLinks().contains(
197 servicePartnerLink));
198 assertTrue(process.getVariables().getVariables()
199 .contains(inputVariable));
200 assertTrue(process.getVariables().getVariables().contains(
201 responseVariable));
202 assertEquals(sequence, process.getActivity());
203
204
205
206 Mock mockProcessController = new Mock(ProcessController.class);
207 ProcessInstance processInstance = new ProcessInstance(null, null);
208
209 mockProcessController.expects(once()).method("process").with(
210 same(process), same(processInstance));
211 mockProcessController.expects(once()).method("process").with(
212 same(inputVariable), same(processInstance));
213 mockProcessController.expects(once()).method("process").with(
214 same(responseVariable), same(processInstance));
215 mockProcessController.expects(once()).method("process").with(
216 same(clientPartnerLink), same(processInstance));
217 mockProcessController.expects(once()).method("process").with(
218 same(servicePartnerLink), same(processInstance));
219 mockProcessController.expects(once()).method("process").with(
220 same(sequence), same(processInstance));
221 mockProcessController.expects(once()).method("process").with(
222 same(receiveInput), same(processInstance));
223 mockProcessController.expects(once()).method("process").with(
224 same(invoke), same(processInstance));
225 mockProcessController.expects(once()).method("process").with(
226 same(receiveResult), same(processInstance));
227
228 try {
229 process.accept((ProcessController) mockProcessController.proxy(),
230 processInstance);
231 inputVariable.accept((ProcessController) mockProcessController
232 .proxy(), processInstance);
233 responseVariable.accept((ProcessController) mockProcessController
234 .proxy(), processInstance);
235 clientPartnerLink.accept((ProcessController) mockProcessController
236 .proxy(), processInstance);
237 servicePartnerLink.accept((ProcessController) mockProcessController
238 .proxy(), processInstance);
239 sequence.accept((ProcessController) mockProcessController.proxy(),
240 processInstance);
241 receiveInput.accept((ProcessController) mockProcessController
242 .proxy(), processInstance);
243 invoke.accept((ProcessController) mockProcessController.proxy(),
244 processInstance);
245 receiveResult.accept((ProcessController) mockProcessController
246 .proxy(), processInstance);
247 } catch (Exception e) {
248 fail("Shoult not throw an Exception");
249
250 }
251
252 mockProcessController.verify();
253
254 }
255 }