1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.rice.kew.actionrequest;
18
19 import org.junit.Test;
20 import org.kuali.rice.kew.api.WorkflowDocument;
21 import org.kuali.rice.kew.api.WorkflowDocumentFactory;
22 import org.kuali.rice.kew.api.action.ActionRequestPolicy;
23 import org.kuali.rice.kew.service.KEWServiceLocator;
24 import org.kuali.rice.kew.test.KEWTestCase;
25 import org.kuali.rice.kew.test.TestUtilities;
26 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
27
28 import java.util.Iterator;
29 import java.util.List;
30
31 import static org.junit.Assert.*;
32
33
34
35
36
37
38
39
40
41
42
43
44 public class ActionRequestScenariosTest extends KEWTestCase {
45
46 protected void loadTestData() throws Exception {
47 loadXmlFile("ActionRequestsConfig.xml");
48 }
49
50
51
52
53
54
55 @Test public void testInlineRequestsRouteModule() throws Exception {
56
57 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdFromPrincipalName("arh14"), "InlineRequestsDocumentType");
58 document.setApplicationContent("<blah><step>step1</step></blah>");
59 document.route("");
60
61 TestUtilities.assertAtNode(document, "step1");
62 List requests = KEWServiceLocator.getActionRequestService().findPendingRootRequestsByDocId(document.getDocumentId());
63 assertEquals("Should be 1 request.", 1, requests.size());
64 ActionRequestValue user1Request = (ActionRequestValue) requests.get(0);
65 assertEquals(getPrincipalIdForName("user1"), user1Request.getPrincipalId());
66
67
68 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdFromPrincipalName("user1"), document.getDocumentId());
69 document.setApplicationContent("<blah><step>step2</step></blah>");
70 document.approve("");
71
72 TestUtilities.assertAtNode(document, "step2");
73 requests = KEWServiceLocator.getActionRequestService().findPendingRootRequestsByDocId(document.getDocumentId());
74 assertEquals("Should be 1 request.", 1, requests.size());
75 ActionRequestValue workgroupRequest = (ActionRequestValue) requests.get(0);
76 assertEquals(getGroupIdFromGroupName("KR-WKFLW", "TestWorkgroup"), workgroupRequest.getGroupId());
77
78
79 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdFromPrincipalName("temay"), document.getDocumentId());
80 document.setApplicationContent("<blah><step>step3</step></blah>");
81 document.approve("");
82
83 TestUtilities.assertAtNode(document, "step3");
84 requests = KEWServiceLocator.getActionRequestService().findPendingRootRequestsByDocId(document.getDocumentId());
85 assertEquals("Should be 1 request.", 1, requests.size());
86 ActionRequestValue initiatorRequest = (ActionRequestValue) requests.get(0);
87 assertEquals("INITIATOR", initiatorRequest.getRoleName());
88
89
90
91 assertFalse("Document should not be FINAL", document.isFinal());
92
93
94 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdFromPrincipalName("arh14"), document.getDocumentId());
95 document.approve("");
96
97 assertTrue("Document should be FINAL", document.isFinal());
98 }
99
100 @Test public void testInlineRequestsRouteModule_UsingAttributes() throws Exception {
101
102
103
104
105
106
107
108
109 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdFromPrincipalName("arh14"), "InlineRequestsDocumentType_UsingAttributes");
110 document.setApplicationContent("<blah><step>step1</step></blah>");
111 document.route("");
112
113 TestUtilities.assertAtNode(document, "step1");
114 List requests = KEWServiceLocator.getActionRequestService().findPendingRootRequestsByDocId(document.getDocumentId());
115 assertEquals("Should be 1 request.", 1, requests.size());
116 ActionRequestValue user1Request = (ActionRequestValue) requests.get(0);
117 assertEquals(getPrincipalIdForName("user1"), user1Request.getPrincipalId());
118
119
120 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdFromPrincipalName("user1"), document.getDocumentId());
121 document.setApplicationContent("<blah><step>step2</step></blah>");
122 document.approve("");
123
124 TestUtilities.assertAtNode(document, "step2");
125 requests = KEWServiceLocator.getActionRequestService().findPendingRootRequestsByDocId(document.getDocumentId());
126 assertEquals("Should be 1 request.", 1, requests.size());
127 ActionRequestValue workgroupRequest = (ActionRequestValue) requests.get(0);
128 assertEquals(getGroupIdFromGroupName("KR-WKFLW", "TestWorkgroup"), workgroupRequest.getGroupId());
129
130
131 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdFromPrincipalName("temay"), document.getDocumentId());
132 document.setApplicationContent("<blah><step>step3</step></blah>");
133 document.approve("");
134
135 TestUtilities.assertAtNode(document, "step3");
136 requests = KEWServiceLocator.getActionRequestService().findPendingRootRequestsByDocId(document.getDocumentId());
137 assertEquals("Should be 1 request.", 1, requests.size());
138 ActionRequestValue initiatorRequest = (ActionRequestValue) requests.get(0);
139 assertEquals("INITIATOR", initiatorRequest.getRoleName());
140
141
142
143 assertFalse("Document should not be FINAL", document.isFinal());
144
145
146 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdFromPrincipalName("arh14"), document.getDocumentId());
147 document.approve("");
148
149 assertTrue("Document should be FINAL", document.isFinal());
150 }
151
152
153
154
155
156
157
158 @Test public void testForceActionWithDelegation() throws Exception {
159
160 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdFromPrincipalName("user1"), "testForceActionWithDelegation");
161 document.route("");
162 TestUtilities.assertAtNode(document, "Node1");
163 List rootRequests = KEWServiceLocator.getActionRequestService().findPendingRootRequestsByDocId(document.getDocumentId());
164 assertEquals("Should be 1 root request.", 1, rootRequests.size());
165 ActionRequestValue ewestfalRequest = (ActionRequestValue)rootRequests.get(0);
166 assertTrue("Request to ewestfal should be force action of true", ewestfalRequest.getForceAction());
167 assertEquals("Should have 1 child request.", 1, ewestfalRequest.getChildrenRequests().size());
168 ActionRequestValue rkirkendRequest = (ActionRequestValue)ewestfalRequest.getChildrenRequests().get(0);
169 assertFalse("Request to rkirkend should be force action of false", rkirkendRequest.getForceAction());
170
171 document = WorkflowDocumentFactory.createDocument(getPrincipalIdFromPrincipalName("ewestfal"), "testForceActionWithDelegation");
172
173
174
175
176
177
178 document.route("");
179
180
181 TestUtilities.assertAtNode(document, "Node1");
182
183 document.approve("");
184 assertTrue("Document should be FINAL", document.isFinal());
185
186
187 }
188
189
190
191
192
193
194 @Test public void testRoleToRoleDelegation() throws Exception {
195 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdFromPrincipalName("user1"), "testRoleToRoleDelegation");
196 document.route("");
197
198
199
200 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdFromPrincipalName("ewestfal"), document.getDocumentId());
201 assertTrue("ewestfal should have an approve request.", document.isApprovalRequested());
202
203 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdFromPrincipalName("jhopf"), document.getDocumentId());
204 assertTrue("Should have an approve request.", document.isApprovalRequested());
205 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdFromPrincipalName("xqi"), document.getDocumentId());
206 assertTrue("Should have an approve request.", document.isApprovalRequested());
207 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdFromPrincipalName("jitrue"), document.getDocumentId());
208 assertTrue("Should have an approve request.", document.isApprovalRequested());
209
210
211
212
213 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdFromPrincipalName("jhopf"), document.getDocumentId());
214 document.approve("Approving as primary delegate.");
215
216
217
218 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdFromPrincipalName("ewestfal"), document.getDocumentId());
219 assertFalse("the primary approver should no longer have an approve request.", document.isApprovalRequested());
220 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdFromPrincipalName("jhopf"), document.getDocumentId());
221 assertFalse("Should not have an approve request.", document.isApprovalRequested());
222 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdFromPrincipalName("xqi"), document.getDocumentId());
223 assertFalse("Should not have an approve request.", document.isApprovalRequested());
224 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdFromPrincipalName("jitrue"), document.getDocumentId());
225 assertFalse("Should not have an approve request.", document.isApprovalRequested());
226
227 List actionRequests = KEWServiceLocator.getActionRequestService().findAllActionRequestsByDocumentId(document.getDocumentId());
228 assertEquals("Wrong number of action requests.", 7, actionRequests.size());
229 for (Iterator iterator = actionRequests.iterator(); iterator.hasNext();) {
230 ActionRequestValue request = (ActionRequestValue) iterator.next();
231 assertTrue("Request should be deactivated.", request.isDeactivated());
232 if (request.isRoleRequest()) {
233 assertEquals("Should be all approve request", ActionRequestPolicy.ALL.getCode(), request.getApprovePolicy());
234 } else {
235 assertEquals("Should not have first approve policy set", ActionRequestPolicy.FIRST.getCode(), request.getApprovePolicy());
236 }
237 }
238
239 }
240
241
242
243 @Test public void testRoleToRoleMixedApprovePoliciesDelegation() throws Exception {
244 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdFromPrincipalName("user1"), "testMixedbagRoleToRoleDelegation");
245 document.route("");
246
247
248
249 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdFromPrincipalName("ewestfal"), document.getDocumentId());
250 assertTrue("ewestfal should have an approve request.", document.isApprovalRequested());
251
252 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdFromPrincipalName("jhopf"), document.getDocumentId());
253 assertTrue("Should have an approve request.", document.isApprovalRequested());
254 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdFromPrincipalName("xqi"), document.getDocumentId());
255 assertTrue("Should have an approve request.", document.isApprovalRequested());
256 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdFromPrincipalName("jitrue"), document.getDocumentId());
257 assertTrue("Should have an approve request.", document.isApprovalRequested());
258
259
260
261
262 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdFromPrincipalName("jhopf"), document.getDocumentId());
263 document.approve("Approving as primary delegate.");
264
265
266
267 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdFromPrincipalName("ewestfal"), document.getDocumentId());
268 assertFalse("the primary approver should no longer have an approve request.", document.isApprovalRequested());
269 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdFromPrincipalName("jhopf"), document.getDocumentId());
270 assertFalse("Should not have an approve request.", document.isApprovalRequested());
271 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdFromPrincipalName("xqi"), document.getDocumentId());
272 assertFalse("Should not have an approve request.", document.isApprovalRequested());
273 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdFromPrincipalName("jitrue"), document.getDocumentId());
274 assertFalse("Should not have an approve request.", document.isApprovalRequested());
275
276 List actionRequests = KEWServiceLocator.getActionRequestService().findAllActionRequestsByDocumentId(document.getDocumentId());
277 assertEquals("Wrong number of action requests.", 7, actionRequests.size());
278 for (Iterator iterator = actionRequests.iterator(); iterator.hasNext();) {
279 ActionRequestValue request = (ActionRequestValue) iterator.next();
280 assertTrue("Request should be deactivated.", request.isDeactivated());
281 if (request.isRoleRequest() && request.getRoleName().equals(RoleToRoleDelegationRole.MAIN_ROLE)) {
282 assertEquals("Should be all approve request", ActionRequestPolicy.ALL.getCode(), request.getApprovePolicy());
283 } else if (request.isRoleRequest() && request.getRoleName().equals(RoleToRoleDelegationRole.PRIMARY_DELEGATE_ROLE)) {
284 assertEquals("Should be first approve request", ActionRequestPolicy.FIRST.getCode(), request.getApprovePolicy());
285 } else if (request.isRoleRequest() && request.getRoleName().equals(RoleToRoleDelegationRole.SECONDARY_DELEGATE_ROLE)) {
286 assertEquals("Should be first approve request", ActionRequestPolicy.FIRST.getCode(), request.getApprovePolicy());
287 } else if (request.isRoleRequest()) {
288 fail("the roles have been messed up");
289 } else {
290 assertEquals("Should not have first approve policy set", ActionRequestPolicy.FIRST.getCode(), request.getApprovePolicy());
291 }
292 }
293
294 }
295
296
297 @Test public void testUnresolvableRoleAttributeRecipients() throws Exception {
298 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdFromPrincipalName("user1"), "UnresolvableRoleRecipsDocType");
299 try {
300 document.route("");
301 } catch (Exception e) {
302
303
304 TestUtilities.getExceptionThreader().join();
305 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("user1"), document.getDocumentId());
306 assertTrue("Document should be in exception routing", document.isException());
307 }
308 }
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345 private String getPrincipalIdFromPrincipalName(String principalName) {
346 return KimApiServiceLocator.getIdentityService().getPrincipalByPrincipalName(principalName).getPrincipalId();
347 }
348
349 private String getGroupIdFromGroupName(String namespace, String groupName) {
350 return KimApiServiceLocator.getGroupService().getGroupByName(namespace, groupName).getId();
351 }
352
353 private String getRoleIdFromRoleName(String namespaceCode, String roleName) {
354 return KimApiServiceLocator.getRoleService().getRoleIdByName(namespaceCode, roleName);
355 }
356 }