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