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