1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.actions;
17
18 import org.junit.Test;
19 import org.kuali.rice.kew.actionitem.ActionItem;
20 import org.kuali.rice.kew.actionitem.ActionItemActionListExtension;
21 import org.kuali.rice.kew.actionrequest.ActionRequestValue;
22 import org.kuali.rice.kew.api.WorkflowDocument;
23 import org.kuali.rice.kew.api.WorkflowDocumentFactory;
24 import org.kuali.rice.kew.api.action.ActionRequest;
25 import org.kuali.rice.kew.api.action.ActionRequestStatus;
26 import org.kuali.rice.kew.api.action.ActionRequestType;
27 import org.kuali.rice.kew.api.action.AdHocToPrincipal;
28 import org.kuali.rice.kew.api.exception.WorkflowException;
29 import org.kuali.rice.kew.service.KEWServiceLocator;
30 import org.kuali.rice.kew.test.KEWTestCase;
31 import org.kuali.rice.kew.test.TestUtilities;
32 import org.kuali.rice.kim.api.KimConstants;
33 import org.kuali.rice.kim.api.group.Group;
34 import org.kuali.rice.kim.api.identity.Person;
35 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
36 import org.kuali.rice.test.BaselineTestCase;
37
38 import java.util.ArrayList;
39 import java.util.Collection;
40 import java.util.Iterator;
41 import java.util.List;
42
43 import static org.junit.Assert.*;
44
45 @BaselineTestCase.BaselineMode(BaselineTestCase.Mode.NONE)
46 public class AdHocRouteTest extends KEWTestCase {
47
48 private static final String ADHOC_DOC = "AdhocRouteTest";
49 private static final String ADHOC_NO_NODE_DOC = "AdHocNoNodeTest";
50 private static final String ADHOC_PRIORITY_PARALLEL_DOC = "AdhocRouteTest-PriorityParallel";
51 private String docId;
52
53 protected void loadTestData() throws Exception {
54 loadXmlFile("ActionsConfig.xml");
55 }
56
57 @Test
58 public void testRequestLabel() throws Exception{
59 String note = "test note";
60 Person per = KimApiServiceLocator.getPersonService().getPersonByPrincipalName("rkirkend");
61 WorkflowDocument doc = WorkflowDocumentFactory.createDocument(per.getPrincipalId(), ADHOC_DOC);
62
63 docId = doc.getDocumentId();
64
65 doc.adHocToPrincipal(ActionRequestType.FYI, "AdHoc", "annotation1", getPrincipalIdForName("dewey"), "respDesc1", false, note);
66
67 doc = getDocument(per.getPrincipalId(), docId);
68 List<ActionRequestValue> actionRequests = KEWServiceLocator.getActionRequestService().findAllActionRequestsByDocumentId(docId);
69 for(ActionRequestValue arv : actionRequests){
70 assertTrue("The note we passed in should equal the one we get out. note=["+ note +"]", note.equals(arv.getRequestLabel()));
71 }
72 }
73
74 @Test
75 public void testParallelAdHocRouting() throws Exception {
76 WorkflowDocument doc = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("rkirkend"), ADHOC_DOC);
77 docId = doc.getDocumentId();
78 doc.adHocToPrincipal(ActionRequestType.APPROVE, "AdHoc", "annotation1", getPrincipalIdForName("dewey"), "respDesc1", false);
79
80 doc = getDocument("dewey");
81 assertFalse("User andlee should not have an approve request yet. Document not yet routed.", doc.isApprovalRequested());
82
83 doc.adHocToGroup(ActionRequestType.APPROVE, "AdHoc", "annotation2", getGroupIdForName(KimConstants.KIM_GROUP_WORKFLOW_NAMESPACE_CODE, "WorkflowAdmin"), "respDesc2", true);
84
85 doc = getDocument("quickstart");
86 assertFalse("User should not have approve request yet. Document not yet routed.", doc.isApprovalRequested());
87
88 doc = getDocument("rkirkend");
89 doc.route("");
90
91
92 List<ActionRequest> actionRequests = doc.getRootActionRequests();
93 for (ActionRequest actionRequest : actionRequests) {
94 assertTrue("Request should be an adhoc request.", actionRequest.isAdHocRequest());
95 }
96
97
98 WorkflowDocument deweyDoc = getDocument("dewey");
99 assertTrue("Dewey should have an approve request", deweyDoc.isApprovalRequested());
100
101 doc = getDocument("ewestfal");
102
103 assertTrue("WorkflowAdmin should have an approve request", doc.isApprovalRequested());
104
105 deweyDoc.approve("");
106 doc.approve("");
107 doc = getDocument("user1");
108 doc.approve("");
109 assertTrue("The document should be final", doc.isFinal());
110 }
111
112
113
114
115
116
117
118 @Test
119 public void testAdHocToInitiator() throws Exception {
120 final String ADHOC_NODE = "AdHoc";
121 WorkflowDocument doc = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("rkirkend"), ADHOC_DOC);
122 docId = doc.getDocumentId();
123 doc.adHocToPrincipal(ActionRequestType.APPROVE, ADHOC_NODE, "annotation1", getPrincipalIdForName("rkirkend"), "", true);
124
125 doc.route("");
126 assertTrue(doc.isEnroute());
127
128 doc = getDocument("rkirkend");
129 assertTrue("rkirkend should have an approval request on the document", doc.isApprovalRequested());
130 TestUtilities.assertAtNodeNew(doc, ADHOC_NODE);
131
132
133 doc = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("rkirkend"), ADHOC_DOC);
134 docId = doc.getDocumentId();
135 doc.adHocToPrincipal(ActionRequestType.APPROVE, ADHOC_NODE, "annotation1", getPrincipalIdForName("rkirkend"), "", false);
136
137 doc.route("");
138 assertTrue(doc.isEnroute());
139
140 doc = getDocument("rkirkend");
141 assertFalse("rkirkend should NOT have an approval request on the document", doc.isApprovalRequested());
142 TestUtilities.assertAtNodeNew(doc, "One");
143 doc = getDocument("user1");
144 assertTrue("user1 should have an approval request on the document", doc.isApprovalRequested());
145 }
146
147 @Test
148 public void testSerialAdHocRouting() throws Exception {
149 WorkflowDocument doc = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("rkirkend"), ADHOC_DOC);
150 docId = doc.getDocumentId();
151 doc.route("");
152 doc = getDocument("user1");
153 doc.adHocToPrincipal(ActionRequestType.APPROVE, "One", "annotation1", getPrincipalIdForName("user2"), "", false);
154 doc.adHocToPrincipal(ActionRequestType.APPROVE, "One", "annotation1", getPrincipalIdForName("rkirkend"), "", true);
155 doc.approve("");
156 doc = getDocument("rkirkend");
157 assertFalse("rkirkend should not have the document at this point 'S' activation", doc.isApprovalRequested());
158 doc = getDocument("user2");
159 assertTrue("user2 should have an approve request", doc.isApprovalRequested());
160 doc.approve("");
161 doc = getDocument("rkirkend");
162 doc.approve("");
163 assertTrue("The document should be final", doc.isFinal());
164 }
165
166 @Test
167 public void testRepeatedAdHocRouting() throws Exception {
168 final String ADHOC_NODE = "AdHoc";
169 WorkflowDocument doc = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("rkirkend"), ADHOC_DOC);
170 docId = doc.getDocumentId();
171 doc.adHocToPrincipal(ActionRequestType.APPROVE, ADHOC_NODE, "annotation1", getPrincipalIdForName("user2"), "", false);
172 doc.route("");
173 doc = getDocument("rkirkend");
174 assertFalse("rkirkend should NOT have an approval request on the document", doc.isApprovalRequested());
175
176 doc = getDocument("user1");
177 assertFalse("user1 should NOT have an approval request on the document", doc.isApprovalRequested());
178
179 doc = getDocument("user2");
180 assertTrue("user2 should have an approval request on document", doc.isApprovalRequested());
181 doc.adHocToPrincipal(ActionRequestType.APPROVE, ADHOC_NODE, "annotation1", getPrincipalIdForName("user3"), "", false);
182 doc.approve("");
183 doc = getDocument("user2");
184 assertFalse("user2 should NOT have an approval request on the document", doc.isApprovalRequested());
185
186 doc = getDocument("user3");
187 assertTrue("user3 should have an approval request on document", doc.isApprovalRequested());
188 doc.adHocToPrincipal(ActionRequestType.APPROVE, ADHOC_NODE, "annotation1", getPrincipalIdForName("rkirkend"), "", true);
189 doc.approve("");
190 doc = getDocument("user3");
191 assertFalse("user3 should NOT have an approval request on the document", doc.isApprovalRequested());
192
193 doc = getDocument("rkirkend");
194 assertTrue("rkirkend should have an approval request on document", doc.isApprovalRequested());
195 doc.approve("");
196 doc = getDocument("rkirkend");
197 assertFalse("rkirkend should NOT have an approval request on the document", doc.isApprovalRequested());
198
199
200 doc = getDocument("user1");
201 assertTrue("user1 should have an approval request on document", doc.isApprovalRequested());
202 doc.approve("");
203 doc = getDocument("user1");
204 assertFalse("user1 should NOT have an approval request on the document", doc.isApprovalRequested());
205
206
207 doc = getDocument("rkirkend");
208 assertFalse("rkirkend should NOT have an approval request on the document", doc.isApprovalRequested());
209 doc = getDocument("user2");
210 assertFalse("user2 should NOT have an approval request on the document", doc.isApprovalRequested());
211 doc = getDocument("user3");
212 assertFalse("user3 should NOT have an approval request on the document", doc.isApprovalRequested());
213
214 assertTrue("The document should be final", doc.isFinal());
215 }
216
217 @Test public void testAdHocWhenDocumentIsInitiated() throws Exception {
218 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), "TakeWorkgroupAuthorityDoc");
219 document.saveDocumentData();
220 assertTrue(document.isInitiated());
221
222 document.adHocToPrincipal(ActionRequestType.APPROVE, "My Annotation", getPrincipalIdForName("rkirkend"), "", true);
223 document.adHocToPrincipal(ActionRequestType.FYI, "My Annotation", getPrincipalIdForName("user1"), "", true);
224
225
226 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId());
227 assertFalse(document.isApprovalRequested());
228 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("user1"), document.getDocumentId());
229 assertFalse(document.isFYIRequested());
230
231
232 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId());
233 document.route("");
234 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId());
235 assertTrue(document.isApprovalRequested());
236 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("user1"), document.getDocumentId());
237 assertTrue(document.isFYIRequested());
238 }
239
240 @Test public void testAdHocWhenDocumentIsFinal() throws Exception {
241 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), "TakeWorkgroupAuthorityDoc");
242 document.route("");
243 TestUtilities.assertAtNodeNew(document, "WorkgroupByDocument");
244
245 try {
246 document.adHocToPrincipal(ActionRequestType.APPROVE, "AdHoc", "", getPrincipalIdForName("ewestfal"), "", true);
247 fail("document should not be allowed to route to nodes that are complete");
248 } catch (Exception e) {
249 }
250
251
252 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId());
253 assertTrue("rkirkend should have request", document.isApprovalRequested());
254 document.approve("");
255
256 assertTrue("Document should be final", document.isFinal());
257
258 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("user1"), document.getDocumentId());
259 List<ActionRequest> requests = document.getRootActionRequests();
260 for (ActionRequest request : requests) {
261 if (request.isActivated()) {
262 fail("Active requests should not be present on a final document");
263 }
264 }
265
266
267 try {
268 document.adHocToPrincipal(ActionRequestType.APPROVE, "WorkgroupByDocument", "", getPrincipalIdForName("ewestfal"), "", true);
269 fail("Should not be allowed to adhoc approve to a final document.");
270 } catch (Exception e) {
271
272 }
273
274
275 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId());
276 assertFalse("rkirkend should not have an FYI request.", document.isFYIRequested());
277 document.adHocToPrincipal(ActionRequestType.FYI, "WorkgroupByDocument", "", getPrincipalIdForName("rkirkend"), "", true);
278 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId());
279 assertTrue("rkirkend should have an FYI request", document.isFYIRequested());
280 }
281
282 @Test public void testAdHocWhenDocumentIsSaved() throws Exception {
283 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), "TakeWorkgroupAuthorityDoc");
284 document.saveDocument("");
285
286
287
288 assertTrue("Document should be saved.", document.isSaved());
289 document.adHocToPrincipal(ActionRequestType.FYI, "AdHoc", "", getPrincipalIdForName("rkirkend"), "", true);
290 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId());
291 assertTrue("rkirkend should have an FYI request", document.isFYIRequested());
292 }
293
294 @Test public void testAdHocFieldsSavedCorrectly() throws Exception {
295 WorkflowDocument doc = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("rkirkend"), ADHOC_DOC);
296 docId = doc.getDocumentId();
297 doc.route("");
298
299 List<String> oldRequestIds = new ArrayList<String>();
300 for (Iterator iterator = KEWServiceLocator.getActionRequestService().findAllActionRequestsByDocumentId(doc.getDocumentId()).iterator(); iterator.hasNext();) {
301 oldRequestIds.add(((ActionRequestValue) iterator.next()).getActionRequestId());
302 }
303
304
305 doc = getDocument("user1");
306 doc.adHocToPrincipal(ActionRequestType.APPROVE, "One", "annotation1", getPrincipalIdForName("user2"), "respDesc", false);
307
308
309 ActionRequestValue request = null;
310 for (Iterator iter = KEWServiceLocator.getActionRequestService().findAllActionRequestsByDocumentId(doc.getDocumentId()).iterator(); iter.hasNext();) {
311 ActionRequestValue actionRequest = (ActionRequestValue) iter.next();
312 if (!oldRequestIds.contains(actionRequest.getActionRequestId())) {
313 request = actionRequest;
314 break;
315 }
316 }
317 assertNotNull("Could not find adhoc routed action request", request);
318
319
320 assertEquals("wrong person", request.getPrincipalId(), getPrincipalIdForName("user2"));
321 assertEquals("annotation incorrect", "annotation1", request.getAnnotation());
322 assertEquals("action requested code incorrect", request.getActionRequested(), ActionRequestType.APPROVE.getCode());
323 assertEquals("responsibility desc incorrect", request.getResponsibilityDesc(), "respDesc");
324 assertEquals("wrong force action", request.getForceAction(), Boolean.FALSE);
325
326 }
327
328 @Test
329 public void testAdHocDissaprovedDocument() throws Exception {
330 WorkflowDocument doc = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), ADHOC_DOC);
331 docId = doc.getDocumentId();
332 doc.route("");
333
334 doc = getDocument("user1");
335 TestUtilities.assertAtNodeNew(doc, "One");
336 doc.disapprove("");
337 TestUtilities.assertAtNodeNew(doc, "One");
338
339
340 doc.adHocToPrincipal(ActionRequestType.FYI, "One", "", getPrincipalIdForName("rkirkend"), "", true);
341 doc.adHocToPrincipal(ActionRequestType.ACKNOWLEDGE, "One", "", getPrincipalIdForName("user2"), "", true);
342
343 doc = getDocument("rkirkend");
344 assertTrue(doc.isFYIRequested());
345 doc.fyi();
346 doc = getDocument("user2");
347 assertTrue(doc.isAcknowledgeRequested());
348 doc.acknowledge("");
349
350
351 doc = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("rkirkend"), ADHOC_DOC);
352 docId = doc.getDocumentId();
353 doc.route("");
354
355 doc = getDocument("user1");
356 doc.disapprove("");
357
358
359 try {
360 doc.adHocToPrincipal(ActionRequestType.APPROVE, "One", "", getPrincipalIdForName("rkirkend"), "", true);
361 fail("should have thrown exception cant adhoc approvals on dissaproved documents");
362 } catch (Exception e) {
363
364 }
365
366
367 try {
368 doc.adHocToPrincipal(ActionRequestType.COMPLETE, "One", "", getPrincipalIdForName("rkirkend"), "", true);
369 fail("should have thrown exception cant ad hoc completes on dissaproved documents");
370 } catch (Exception e) {
371
372 }
373
374
375 try {
376 doc.adHocToPrincipal(ActionRequestType.ACKNOWLEDGE, "", getPrincipalIdForName("user1"), "", true);
377 } catch (Exception e) {
378 e.printStackTrace();
379 fail("should have thrown exception cant ad hoc completes on dissaproved documents");
380 }
381
382
383 try {
384 doc.adHocToPrincipal(ActionRequestType.FYI, "", getPrincipalIdForName("user1"), "", true);
385 } catch (Exception e) {
386 e.printStackTrace();
387 fail("should have thrown exception cant ad hoc completes on dissaproved documents");
388 }
389
390 }
391
392
393
394
395
396 @Test
397 public void testAdHocNoNodeName() throws Exception {
398 WorkflowDocument doc = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("user1"), ADHOC_DOC);
399 docId = doc.getDocumentId();
400
401
402
403
404 doc.adHocToPrincipal(ActionRequestType.APPROVE, "", getPrincipalIdForName("jitrue"), "", false);
405 doc.adHocToGroup(ActionRequestType.APPROVE, "", getGroupIdForName(KimConstants.KIM_GROUP_WORKFLOW_NAMESPACE_CODE, "NonSIT"), "", false);
406 doc.route("");
407
408
409
410 doc = getDocument("user1");
411 assertFalse(doc.isApprovalRequested());
412 doc = getDocument("jitrue");
413 assertTrue(doc.isApprovalRequested());
414
415
416 TestUtilities.assertAtNodeNew(doc, "AdHoc");
417
418
419 doc = getDocument("jitrue");
420 TestUtilities.assertAtNodeNew(doc, "AdHoc");
421 doc.disapprove("");
422
423 TestUtilities.assertAtNodeNew(doc, "AdHoc");
424 assertTrue(doc.isDisapproved());
425
426
427 doc.adHocToPrincipal(ActionRequestType.FYI, "", getPrincipalIdForName("rkirkend"), "", true);
428 doc.adHocToPrincipal(ActionRequestType.ACKNOWLEDGE, "", getPrincipalIdForName("user2"), "", true);
429
430 doc.adHocToGroup(ActionRequestType.ACKNOWLEDGE, "", getGroupIdForName(KimConstants.KIM_GROUP_WORKFLOW_NAMESPACE_CODE, "NonSIT"), "", true);
431
432
433 doc = getDocument("rkirkend");
434 assertTrue(doc.isFYIRequested());
435 doc.fyi();
436
437
438
439 doc = getDocument("user3");
440 assertTrue(doc.isAcknowledgeRequested());
441
442
443
444 doc = getDocument("user2");
445 assertTrue(doc.isAcknowledgeRequested());
446 doc.acknowledge("");
447
448
449
450 doc = getDocument("user3");
451 assertFalse(doc.isAcknowledgeRequested());
452
453
454
455 doc = getDocument("user1");
456 assertTrue(doc.isAcknowledgeRequested());
457 doc.acknowledge("");
458
459
460 TestUtilities.assertNumberOfPendingRequests(doc.getDocumentId(), 0);
461
462
463
464 try {
465 doc.adHocToPrincipal(ActionRequestType.APPROVE, "", getPrincipalIdForName("rkirkend"), "", true);
466 fail("should have thrown exception cant adhoc approvals on dissaproved documents");
467 } catch (Exception e) {
468 }
469
470 try {
471 doc.adHocToPrincipal(ActionRequestType.COMPLETE, "", getPrincipalIdForName("rkirkend"), "", true);
472 fail("should have thrown exception cant ad hoc completes on dissaproved documents");
473 } catch (Exception e) {
474 }
475
476 }
477
478 @Test
479 public void testAdHocWithRequestLabel_ToPrincipal() throws Exception {
480 WorkflowDocument doc = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("user1"), ADHOC_DOC);
481 String label = "MY PRINCIPAL LABEL";
482 doc.adHocToPrincipal(ActionRequestType.APPROVE, null, "", getPrincipalIdForName("ewestfal"), "", true, label);
483
484 List<ActionRequestValue> actionRequests = KEWServiceLocator.getActionRequestService().findPendingRootRequestsByDocId(doc.getDocumentId());
485 assertEquals("Shoudl have 1 request.", 1, actionRequests.size());
486 ActionRequestValue actionRequest = actionRequests.get(0);
487 assertEquals("Should be an approve request", ActionRequestType.APPROVE.getCode(), actionRequest.getActionRequested());
488 assertEquals("Invalid request label", label, actionRequest.getRequestLabel());
489 assertEquals("Request should be initialized", ActionRequestStatus.INITIALIZED.getCode(), actionRequest.getStatus());
490
491
492 doc.route("");
493
494 Collection<ActionItemActionListExtension> actionItems = KEWServiceLocator.getActionListService().getActionListForSingleDocument(doc.getDocumentId());
495 assertEquals("Should have 1 action item.", 1, actionItems.size());
496 ActionItem actionItem = actionItems.iterator().next();
497 assertEquals("ActionItem should be constructed from request.", actionRequest.getActionRequestId(), actionItem.getActionRequestId());
498 assertEquals("ActionItem should have same label", label, actionItem.getRequestLabel());
499 }
500
501 @Test
502 public void testAdHocWithRequestLabel_ToGroup() throws Exception {
503 WorkflowDocument doc = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("user1"), ADHOC_DOC);
504 String label = "MY GROUP LABEL";
505 Group workflowAdmin = KEWServiceLocator.getIdentityHelperService().getGroupByName("KR-WKFLW", "WorkflowAdmin");
506 doc.adHocToGroup(ActionRequestType.APPROVE, null, "", workflowAdmin.getId(), "", true, label);
507
508 List<ActionRequestValue> actionRequests = KEWServiceLocator.getActionRequestService().findPendingRootRequestsByDocId(doc.getDocumentId());
509 assertEquals("Should have 1 request.", 1, actionRequests.size());
510 ActionRequestValue actionRequest = actionRequests.get(0);
511 assertEquals("Should be an approve request", ActionRequestType.APPROVE.getCode(), actionRequest.getActionRequested());
512 assertEquals("Invalid request label", label, actionRequest.getRequestLabel());
513 assertEquals("Request should be initialized", ActionRequestStatus.INITIALIZED.getCode(), actionRequest.getStatus());
514
515
516 doc.route("");
517
518 Collection<ActionItemActionListExtension> actionItems = KEWServiceLocator.getActionListService().getActionListForSingleDocument(doc.getDocumentId());
519 assertTrue("Should have more than 1 action item.", actionItems.size() > 1);
520 for (ActionItem actionItem : actionItems) {
521 assertEquals("ActionItem should be constructed from request.", actionRequest.getActionRequestId(), actionItem.getActionRequestId());
522 assertEquals("ActionItem should have same label", label, actionItem.getRequestLabel());
523 }
524 }
525
526 @Test
527 public void testAdHocWithNoNodes() throws Exception {
528 WorkflowDocument doc = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("user1"), ADHOC_NO_NODE_DOC);
529 String label = "MY PRINCIPAL LABEL";
530
531
532 doc.adHocToPrincipal(ActionRequestType.FYI, null, "", getPrincipalIdForName("ewestfal"), "", true, label);
533
534 List<ActionRequestValue> actionRequests = KEWServiceLocator.getActionRequestService().findPendingRootRequestsByDocId(doc.getDocumentId());
535 assertEquals("Should have 1 request.", 1, actionRequests.size());
536 ActionRequestValue actionRequest = actionRequests.get(0);
537 assertEquals("Should be a FYI request", ActionRequestType.FYI.getCode(), actionRequest.getActionRequested());
538 assertEquals("Invalid request label", label, actionRequest.getRequestLabel());
539 assertEquals("Request should be initialized", ActionRequestStatus.INITIALIZED.getCode(), actionRequest.getStatus());
540
541
542 doc.route("");
543
544 Collection<ActionItemActionListExtension> actionItems = KEWServiceLocator.getActionListService().getActionListForSingleDocument(doc.getDocumentId());
545 assertEquals("Should have 0 action item.", 0, actionItems.size());
546
547
548
549 }
550
551
552
553
554 @Test
555 public void testAdHocWithPriorityParallelActivation() throws Exception {
556 String user1 = getPrincipalIdForName("user1");
557 String user2 = getPrincipalIdForName("user2");
558 String user3 = getPrincipalIdForName("user3");
559 String testuser1 = getPrincipalIdForName("testuser1");
560 String testuser2 = getPrincipalIdForName("testuser2");
561 String testuser3 = getPrincipalIdForName("testuser3");
562
563 WorkflowDocument document = WorkflowDocumentFactory.createDocument(user1, ADHOC_PRIORITY_PARALLEL_DOC);
564
565
566
567
568
569
570
571
572
573
574 AdHocToPrincipal.Builder adHocToPrincipal = AdHocToPrincipal.Builder.create(ActionRequestType.ACKNOWLEDGE, null, user2);
575 adHocToPrincipal.setPriority(1);
576 document.adHocToPrincipal(adHocToPrincipal.build(), "");
577
578 adHocToPrincipal.setPriority(2);
579 adHocToPrincipal.setActionRequested(ActionRequestType.APPROVE);
580 adHocToPrincipal.setTargetPrincipalId(user3);
581 document.adHocToPrincipal(adHocToPrincipal.build(), "");
582
583 adHocToPrincipal.setTargetPrincipalId(testuser1);
584 document.adHocToPrincipal(adHocToPrincipal.build(), "");
585
586 adHocToPrincipal.setActionRequested(ActionRequestType.ACKNOWLEDGE);
587 adHocToPrincipal.setTargetPrincipalId(testuser2);
588 document.adHocToPrincipal(adHocToPrincipal.build(), "");
589
590 adHocToPrincipal.setPriority(3);
591 adHocToPrincipal.setActionRequested(ActionRequestType.FYI);
592 adHocToPrincipal.setTargetPrincipalId(testuser3);
593 document.adHocToPrincipal(adHocToPrincipal.build(), "");
594
595
596 document.route("");
597 assertTrue(document.isEnroute());
598
599
600 List<ActionRequest> rootActionRequests = document.getRootActionRequests();
601 assertEquals("Should have 5 root action requests", 5, rootActionRequests.size());
602 ActionRequest user2Request = null;
603 ActionRequest user3Request = null;
604 ActionRequest testuser1Request = null;
605 ActionRequest testuser2Request = null;
606 ActionRequest testuser3Request = null;
607 for (ActionRequest actionRequest : rootActionRequests) {
608 if (user2.equals(actionRequest.getPrincipalId())) {
609 user2Request = actionRequest;
610 } else if (user3.equals(actionRequest.getPrincipalId())) {
611 user3Request = actionRequest;
612 } else if (testuser1.equals(actionRequest.getPrincipalId())) {
613 testuser1Request = actionRequest;
614 } else if (testuser2.equals(actionRequest.getPrincipalId())) {
615 testuser2Request = actionRequest;
616 } else if (testuser3.equals(actionRequest.getPrincipalId())) {
617 testuser3Request = actionRequest;
618 }
619 }
620
621 assertNotNull(user2Request);
622 assertEquals(ActionRequestStatus.ACTIVATED, user2Request.getStatus());
623 assertNotNull(user3Request);
624 assertEquals(ActionRequestStatus.ACTIVATED, user3Request.getStatus());
625 assertNotNull(testuser1Request);
626 assertEquals(ActionRequestStatus.ACTIVATED, testuser1Request.getStatus());
627 assertNotNull(testuser2Request);
628 assertEquals(ActionRequestStatus.ACTIVATED, testuser2Request.getStatus());
629 assertNotNull(testuser3Request);
630 assertEquals(ActionRequestStatus.INITIALIZED, testuser3Request.getStatus());
631
632
633 document.switchPrincipal(user3);
634 assertTrue(document.isApprovalRequested());
635 document.approve("");
636 assertTrue(document.isEnroute());
637
638
639 document.switchPrincipal(testuser3);
640 assertFalse(document.isFYIRequested());
641
642
643 document.switchPrincipal(testuser1);
644 assertTrue(document.isApprovalRequested());
645 document.approve("");
646
647
648 assertTrue(document.isProcessed());
649
650
651 document.switchPrincipal(testuser3);
652 assertTrue(document.isFYIRequested());
653 document.fyi();
654
655
656 assertTrue(document.isProcessed());
657 document.switchPrincipal(user2);
658 assertTrue(document.isAcknowledgeRequested());
659 document.acknowledge("");
660 assertTrue(document.isProcessed());
661 document.switchPrincipal(testuser2);
662 assertTrue(document.isAcknowledgeRequested());
663 document.acknowledge("");
664
665
666 assertTrue(document.isFinal());
667 }
668
669
670 private WorkflowDocument getDocument(String netid) throws WorkflowException {
671 return WorkflowDocumentFactory.loadDocument(getPrincipalIdForName(netid), docId);
672 }
673 private WorkflowDocument getDocument(String principalId, String docId) throws WorkflowException {
674 return WorkflowDocumentFactory.loadDocument(principalId, docId);
675 }
676
677 }