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