1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.impl.peopleflow;
17
18 import org.joda.time.DateTime;
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.kuali.rice.core.api.delegation.DelegationType;
22 import org.kuali.rice.core.api.membership.MemberType;
23 import org.kuali.rice.kew.api.KewApiServiceLocator;
24 import org.kuali.rice.kew.api.WorkflowDocument;
25 import org.kuali.rice.kew.api.WorkflowDocumentFactory;
26 import org.kuali.rice.kew.api.action.ActionRequest;
27 import org.kuali.rice.kew.api.action.ActionRequestPolicy;
28 import org.kuali.rice.kew.api.action.ActionRequestStatus;
29 import org.kuali.rice.kew.api.action.RecipientType;
30 import org.kuali.rice.kew.api.peopleflow.PeopleFlowDefinition;
31 import org.kuali.rice.kew.api.peopleflow.PeopleFlowDelegate;
32 import org.kuali.rice.kew.api.peopleflow.PeopleFlowMember;
33 import org.kuali.rice.kew.api.peopleflow.PeopleFlowService;
34 import org.kuali.rice.kew.test.KEWTestCase;
35 import org.kuali.rice.kim.api.common.delegate.DelegateMember;
36 import org.kuali.rice.kim.api.common.delegate.DelegateType;
37 import org.kuali.rice.kim.api.group.Group;
38 import org.kuali.rice.kim.api.group.GroupService;
39 import org.kuali.rice.kim.api.role.Role;
40 import org.kuali.rice.kim.api.role.RoleMember;
41 import org.kuali.rice.kim.api.role.RoleService;
42 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
43 import org.kuali.rice.test.BaselineTestCase;
44
45 import java.util.Collections;
46 import java.util.HashMap;
47 import java.util.List;
48
49 import static org.junit.Assert.*;
50
51
52
53
54
55
56 @BaselineTestCase.BaselineMode(BaselineTestCase.Mode.CLEAR_DB)
57 public class PeopleFlowRoutingTest extends KEWTestCase {
58
59 private static final String NAMESPACE_CODE = "TEST";
60 private static final String PEOPLE_FLOW_1 = "PeopleFlow1";
61 private static final String PEOPLE_FLOW_2 = "PeopleFlow2";
62 private static final String PEOPLE_FLOW_3 = "PeopleFlow3";
63 private static final String PEOPLE_FLOW_4 = "PeopleFlow4";
64 private static final String PEOPLE_FLOW_5 = "PeopleFlow5";
65 private static final String PEOPLE_FLOW_6 = "PeopleFlow6";
66 private static final String PEOPLE_FLOW_7 = "PeopleFlow7";
67 private static final String PEOPLE_FLOW_8 = "PeopleFlow8";
68 private static final String PEOPLE_FLOW_9 = "PeopleFlow9";
69 private static final String PEOPLE_FLOW_10 = "PeopleFlow10";
70 private static final String PEOPLE_FLOW_11 = "PeopleFlow11";
71 private static final String PEOPLE_FLOW_12 = "PeopleFlow12";
72 private static final String PEOPLE_FLOW_13 = "PeopleFlow13";
73
74 private static final String SINGLE_PEOPLE_FLOW_PARALLEL_APPROVE = "SinglePeopleFlow-Parallel-Approve";
75 private static final String SINGLE_PEOPLE_FLOW_SEQUENTIAL_APPROVE = "SinglePeopleFlow-Sequential-Approve";
76 private static final String SINGLE_PEOPLE_FLOW_PRIORITY_PARALLEL_APPROVE = "SinglePeopleFlow-PriorityParallel-Approve";
77 private static final String MULTIPLE_PEOPLE_FLOW_PRIORITY_PARALLEL = "MultiplePeopleFlow-PriorityParallel";
78 private static final String DELEGATE_PEOPLE_FLOW_PRIORITY_PARALLEL_APPROVE = "DelegatePeopleFlow-PriorityParallel-Approve";
79
80 private static final String ROLE_DELEGATE_PEOPLE_FLOW_JUST_KIM_DELEGATE = "RoleDelegatePeopleFlow-JustKimDelegate";
81 private static final String ROLE_DELEGATE_PEOPLE_FLOW_PRIMARY_DELEGATE = "RoleDelegatePeopleFlow-PrimaryDelegate";
82 private static final String ROLE_DELEGATE_PEOPLE_FLOW_SECONDARY_DELEGATE = "RoleDelegatePeopleFlow-SecondaryDelegate";
83 private static final String ROLE_DELEGATE_PEOPLE_FLOW_DELEGATE_ROLE_HAS_KIM_DELEGATE = "RoleDelegatePeopleFlow-DelegateRoleHasKimDelegate";
84
85 private static final String ROLE_DELEGATE_PEOPLE_FLOW_PRINCIPAL_MEMBER_HAS_ROLE_DELEGATE = "RoleDelegatePeopleFlow-PrincipalMemberHasRoleDelegate";
86 private static final String ROLE_DELEGATE_PEOPLE_FLOW_ROLE_MEMBER_HAS_PRINCIPAL_DELEGATE = "RoleDelegatePeopleFlow-RoleMemberHasPrincipalDelegate";
87 private static final String ROLE_DELEGATE_PEOPLE_FLOW_ROLE_MULTIPLE_MEMBERS = "RoleDelegatePeopleFlow-MultipleRoleMembers";
88
89 private static final String ROLE_DELEGATE_PEOPLE_FLOW_ROLE_MULTIPLE_MEMBERS_FIRST_APPROVE = "RoleDelegatePeopleFlow-MultipleRoleMembers-FirstApprove";
90 private static final String ROLE_DELEGATE_PEOPLE_FLOW_ROLE_MULTIPLE_MEMBERS_DELEGATE_FIRST_APPROVE = "RoleDelegatePeopleFlow-MultipleRoleMembers-DelegateFirstApprove";
91 private static final String GROUP_DELEGATE_PEOPLE_FLOW_ROLE_MULTIPLE_MEMBERS = "GroupDelegatePeopleFlow-MultipleRoleMembers";
92
93 private PeopleFlowService peopleFlowService;
94
95 private String user1;
96 private String user2;
97 private String user3;
98 private String testuser1;
99 private String testuser2;
100 private String testuser3;
101 private String ewestfal;
102 private String fran;
103 private String earl;
104 private String testWorkgroup;
105 private String ppfTestRole1;
106 private String ppfTestRole2;
107 private String ppfTestRole3;
108 private String ppfTestRole4;
109 private String ppfTestGroup1;
110
111 protected void loadTestData() throws Exception {
112 loadXmlFile("PeopleFlowRoutingTest.xml");
113 }
114
115 @Before
116 public void setupServiceUnderTest() {
117 setPeopleFlowService(KewApiServiceLocator.getPeopleFlowService());
118
119
120 user1 = getPrincipalIdForName("user1");
121 user2 = getPrincipalIdForName("user2");
122 user3 = getPrincipalIdForName("user3");
123 testuser1 = getPrincipalIdForName("testuser1");
124 testuser2 = getPrincipalIdForName("testuser2");
125 testuser3 = getPrincipalIdForName("testuser3");
126 ewestfal = getPrincipalIdForName("ewestfal");
127 fran = getPrincipalIdForName("fran");
128 earl = getPrincipalIdForName("earl");
129 testWorkgroup = getGroupIdForName("KR-WKFLW", "TestWorkgroup");
130
131 createTestRolesIfNotExists();
132 ppfTestRole1 = getRoleIdForName(NAMESPACE_CODE, "ppfTestRole1");
133 ppfTestRole2 = getRoleIdForName(NAMESPACE_CODE, "ppfTestRole2");
134 ppfTestRole3 = getRoleIdForName(NAMESPACE_CODE, "ppfTestRole3");
135 ppfTestRole4 = getRoleIdForName(NAMESPACE_CODE, "ppfTestRole4");
136
137 ppfTestGroup1 = getGroupIdForName(NAMESPACE_CODE, "ppfTestGroup1");
138 }
139
140 protected void setPeopleFlowService(PeopleFlowService peopleFlowService) {
141 this.peopleFlowService = peopleFlowService;
142 }
143
144 protected PeopleFlowService getPeopleFlowService() {
145 return peopleFlowService;
146 }
147
148 private void createTestRolesIfNotExists() {
149 RoleService roleService = KimApiServiceLocator.getRoleService();
150 GroupService groupService = KimApiServiceLocator.getGroupService();
151
152 if (groupService.getGroupByNamespaceCodeAndName(NAMESPACE_CODE, "ppfTestGroup1") == null) {
153 Group.Builder testgroup1Builder = Group.Builder.create(NAMESPACE_CODE, "ppfTestGroup1", "1");
154 testgroup1Builder.setActive(true);
155 Group testgroup1Group = groupService.createGroup(testgroup1Builder.build());
156
157 groupService.addPrincipalToGroup("earl", testgroup1Group.getId());
158 groupService.addPrincipalToGroup("fran", testgroup1Group.getId());
159 }
160
161 if (getRoleIdForName(NAMESPACE_CODE, "ppfTestRole1") == null) {
162
163
164
165 Role.Builder testRole1Builder = Role.Builder.create(null, "ppfTestRole1", NAMESPACE_CODE, "test role 1",
166 "1"
167
168 Role roleTestRole1 = roleService.createRole(testRole1Builder.build());
169 RoleMember user1RoleMember = roleService.assignPrincipalToRole(user1, NAMESPACE_CODE, "ppfTestRole1", Collections.<String, String>emptyMap());
170
171 DelegateType.Builder delegateTypeBuilder =
172 DelegateType.Builder.create(roleTestRole1.getId(), DelegationType.PRIMARY,
173 Collections.<DelegateMember.Builder>emptyList());
174 delegateTypeBuilder.setKimTypeId("1");
175
176 DelegateType delegateType = roleService.createDelegateType(delegateTypeBuilder.build());
177
178 DelegateMember.Builder testRole1DelegateBuilder = DelegateMember.Builder.create();
179 testRole1DelegateBuilder.setActiveFromDate(DateTime.now());
180 testRole1DelegateBuilder.setDelegationId(delegateType.getDelegationId());
181 testRole1DelegateBuilder.setRoleMemberId(user1RoleMember.getId());
182 testRole1DelegateBuilder.setMemberId(ewestfal);
183 testRole1DelegateBuilder.setType(MemberType.PRINCIPAL);
184
185 DelegateMember testRole1Delegate = roleService.createDelegateMember(testRole1DelegateBuilder.build());
186 }
187
188 if (getRoleIdForName(NAMESPACE_CODE, "ppfTestRole2") == null) {
189
190
191 Role.Builder testRole2Builder = Role.Builder.create(null, "ppfTestRole2", NAMESPACE_CODE, "test role 2",
192 "1"
193
194 Role roleTestRole2 = roleService.createRole(testRole2Builder.build());
195 RoleMember user2RoleMember = roleService.assignPrincipalToRole(user2, NAMESPACE_CODE, "ppfTestRole2", Collections.<String, String>emptyMap());
196 }
197
198 if (getRoleIdForName(NAMESPACE_CODE, "ppfTestRole3") == null) {
199
200
201 Role.Builder testRole3Builder = Role.Builder.create(null, "ppfTestRole3", NAMESPACE_CODE, "test role 3",
202 "1"
203
204 Role roleTestRole3 = roleService.createRole(testRole3Builder.build());
205 RoleMember user1RoleMember = roleService.assignPrincipalToRole(user1, NAMESPACE_CODE, "ppfTestRole3", Collections.<String, String>emptyMap());
206 RoleMember user2RoleMember = roleService.assignPrincipalToRole(user2, NAMESPACE_CODE, "ppfTestRole3", Collections.<String, String>emptyMap());
207 }
208
209 if (getRoleIdForName(NAMESPACE_CODE, "ppfTestRole4") == null) {
210
211
212 Role.Builder testRole4Builder = Role.Builder.create(null, "ppfTestRole4", NAMESPACE_CODE, "test role 4",
213 "1"
214
215 Role roleTestRole4 = roleService.createRole(testRole4Builder.build());
216 RoleMember testuser1RoleMember = roleService.assignPrincipalToRole(testuser1, NAMESPACE_CODE, "ppfTestRole4", Collections.<String, String>emptyMap());
217 RoleMember testuser2RoleMember = roleService.assignPrincipalToRole(testuser2, NAMESPACE_CODE, "ppfTestRole4", Collections.<String, String>emptyMap());
218 }
219 }
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235 private void createSimplePeopleFlow() {
236 PeopleFlowDefinition.Builder peopleFlow = PeopleFlowDefinition.Builder.create(NAMESPACE_CODE, PEOPLE_FLOW_1);
237 peopleFlow.addPrincipal(user1).setPriority(1);
238 peopleFlow.addPrincipal(user2).setPriority(2);
239 peopleFlow.addGroup(testWorkgroup).setPriority(3);
240 peopleFlowService.createPeopleFlow(peopleFlow.build());
241 }
242
243 @Test
244 public void test_SinglePeopleFlow_Parallel_Approve() throws Exception {
245 createSimplePeopleFlow();
246
247
248 WorkflowDocument document = WorkflowDocumentFactory.createDocument(user3, SINGLE_PEOPLE_FLOW_PARALLEL_APPROVE);
249 document.route("");
250 assertTrue("Document should be enroute.", document.isEnroute());
251
252
253 document.switchPrincipal(user3);
254
255
256 assertApproveRequested(document, user1, user2, ewestfal);
257
258
259 document.switchPrincipal(ewestfal);
260 document.approve("approving as ewestfal");
261 assertTrue("Document should still be enroute.", document.isEnroute());
262 document.switchPrincipal(user1);
263 document.approve("approving as user1");
264 assertTrue("Document should still be enroute.", document.isEnroute());
265 document.switchPrincipal(user2);
266 document.approve("approving as user2");
267 assertTrue("Document should now be FINAL.", document.isFinal());
268 }
269
270 @Test
271 public void test_SinglePeopleFlow_Sequential_Approve() throws Exception {
272 createSimplePeopleFlow();
273
274
275 WorkflowDocument document = WorkflowDocumentFactory.createDocument(user3, SINGLE_PEOPLE_FLOW_SEQUENTIAL_APPROVE);
276 document.route("");
277 assertTrue("Document should be enroute.", document.isEnroute());
278
279
280 document.switchPrincipal(user3);
281
282
283
284
285 List<ActionRequest> rootActionRequests = document.getRootActionRequests();
286 assertEquals("Should have 3 root action requests", 3, rootActionRequests.size());
287 ActionRequest user1Request = null;
288 ActionRequest user2Request = null;
289 ActionRequest testWorkgroupRequest = null;
290 for (ActionRequest actionRequest : rootActionRequests) {
291 RecipientType recipientType = actionRequest.getRecipientType();
292 if (recipientType == RecipientType.PRINCIPAL) {
293 if (user1.equals(actionRequest.getPrincipalId())) {
294 user1Request = actionRequest;
295 } else if (user2.equals(actionRequest.getPrincipalId())) {
296 user2Request = actionRequest;
297 }
298 } else if (recipientType == RecipientType.GROUP) {
299 if (testWorkgroup.equals(actionRequest.getGroupId())) {
300 testWorkgroupRequest = actionRequest;
301 }
302 }
303 }
304
305 assertNotNull(user1Request);
306 assertEquals(ActionRequestStatus.ACTIVATED, user1Request.getStatus());
307 assertNotNull(user2Request);
308 assertEquals(ActionRequestStatus.INITIALIZED, user2Request.getStatus());
309 assertNotNull(testWorkgroupRequest);
310 assertEquals(ActionRequestStatus.INITIALIZED, testWorkgroupRequest.getStatus());
311
312
313 assertApproveNotRequested(document, user2, ewestfal);
314
315
316 assertApproveRequested(document, user1);
317
318
319 document.switchPrincipal(user1);
320 document.approve("");
321
322
323 assertTrue(document.isEnroute());
324
325
326 assertApproveNotRequested(document, user1, ewestfal);
327 assertApproveRequested(document, user2);
328
329
330 document.switchPrincipal(user2);
331 document.approve("");
332
333 assertTrue(document.isEnroute());
334
335
336 assertApproveNotRequested(document, user2, user1);
337
338
339 assertApproveRequested(document, ewestfal);
340 document.switchPrincipal(ewestfal);
341 document.approve("");
342
343
344 assertTrue(document.isFinal());
345 }
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364 private void createPriorityParallelPeopleFlow() {
365 PeopleFlowDefinition.Builder peopleFlow = PeopleFlowDefinition.Builder.create(NAMESPACE_CODE, PEOPLE_FLOW_2);
366 peopleFlow.addPrincipal(user1).setPriority(1);
367 peopleFlow.addPrincipal(user2).setPriority(1);
368 peopleFlow.addPrincipal(testuser1).setPriority(2);
369 peopleFlow.addPrincipal(testuser2).setPriority(2);
370
371 peopleFlow.addGroup(testWorkgroup).setPriority(10);
372 peopleFlow.addPrincipal(testuser3).setPriority(10);
373 peopleFlowService.createPeopleFlow(peopleFlow.build());
374 }
375
376 @Test
377 public void test_SinglePeopleFlow_PriorityParallel_Approve() throws Exception {
378 createPriorityParallelPeopleFlow();
379
380
381 WorkflowDocument document = WorkflowDocumentFactory.createDocument(user3, SINGLE_PEOPLE_FLOW_PRIORITY_PARALLEL_APPROVE);
382 document.route("");
383 assertTrue("Document should be enroute.", document.isEnroute());
384
385
386 document.switchPrincipal(user3);
387
388
389
390
391 List<ActionRequest> rootActionRequests = document.getRootActionRequests();
392 assertEquals("Should have 6 root action requests", 6, rootActionRequests.size());
393 ActionRequest user1Request = null;
394 ActionRequest user2Request = null;
395 ActionRequest testuser1Request = null;
396 ActionRequest testuser2Request = null;
397 ActionRequest testWorkgroupRequest = null;
398 ActionRequest testuser3Request = null;
399 for (ActionRequest actionRequest : rootActionRequests) {
400 RecipientType recipientType = actionRequest.getRecipientType();
401 if (recipientType == RecipientType.PRINCIPAL) {
402 if (user1.equals(actionRequest.getPrincipalId())) {
403 user1Request = actionRequest;
404 } else if (user2.equals(actionRequest.getPrincipalId())) {
405 user2Request = actionRequest;
406 } else if (testuser1.equals(actionRequest.getPrincipalId())) {
407 testuser1Request = actionRequest;
408 } else if (testuser2.equals(actionRequest.getPrincipalId())) {
409 testuser2Request = actionRequest;
410 } else if (testuser3.equals(actionRequest.getPrincipalId())) {
411 testuser3Request = actionRequest;
412 }
413 } else if (recipientType == RecipientType.GROUP) {
414 if (testWorkgroup.equals(actionRequest.getGroupId())) {
415 testWorkgroupRequest = actionRequest;
416 }
417 }
418 }
419
420 assertNotNull(user1Request);
421 assertEquals(ActionRequestStatus.ACTIVATED, user1Request.getStatus());
422 assertNotNull(user2Request);
423 assertEquals(ActionRequestStatus.ACTIVATED, user2Request.getStatus());
424 assertNotNull(testuser1Request);
425 assertEquals(ActionRequestStatus.INITIALIZED, testuser1Request.getStatus());
426 assertNotNull(testuser2Request);
427 assertEquals(ActionRequestStatus.INITIALIZED, testuser2Request.getStatus());
428 assertNotNull(testWorkgroupRequest);
429 assertEquals(ActionRequestStatus.INITIALIZED, testWorkgroupRequest.getStatus());
430 assertNotNull(testuser3Request);
431 assertEquals(ActionRequestStatus.INITIALIZED, testuser3Request.getStatus());
432
433
434
435 assertApproveRequested(document, user1, user2);
436 assertApproveNotRequested(document, testuser1, testuser2, testuser3, ewestfal);
437
438
439 document.switchPrincipal(user1);
440 document.approve("");
441 assertApproveRequested(document, user2);
442 assertApproveNotRequested(document, user1);
443 document.switchPrincipal(user2);
444 document.approve("");
445 assertTrue(document.isEnroute());
446
447 assertApproveRequested(document, testuser1, testuser2);
448 assertApproveNotRequested(document, user1, user2, testuser3, ewestfal);
449
450
451 document.switchPrincipal(testuser1);
452 document.approve("");
453 document.switchPrincipal(testuser2);
454 document.approve("");
455 assertTrue(document.isEnroute());
456
457 assertApproveRequested(document, testuser3, ewestfal);
458 assertApproveNotRequested(document, user1, user2, testuser1, testuser2);
459
460
461 document.switchPrincipal(testuser3);
462 document.approve("");
463 document.switchPrincipal(ewestfal);
464 document.approve("");
465 assertTrue(document.isFinal());
466 }
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491 private void createMultiplePeopleFlows() {
492 PeopleFlowDefinition.Builder peopleFlow1 = PeopleFlowDefinition.Builder.create(NAMESPACE_CODE, PEOPLE_FLOW_1);
493 peopleFlow1.addPrincipal(user1).setPriority(1);
494 peopleFlow1.addPrincipal(user2).setPriority(2);
495 peopleFlowService.createPeopleFlow(peopleFlow1.build());
496
497 PeopleFlowDefinition.Builder peopleFlow2 = PeopleFlowDefinition.Builder.create(NAMESPACE_CODE, PEOPLE_FLOW_2);
498 peopleFlow2.addPrincipal(testuser1).setPriority(1);
499 peopleFlow2.addPrincipal(testuser2).setPriority(2);
500 peopleFlowService.createPeopleFlow(peopleFlow2.build());
501
502 PeopleFlowDefinition.Builder peopleFlow3 = PeopleFlowDefinition.Builder.create(NAMESPACE_CODE, PEOPLE_FLOW_3);
503 peopleFlow3.addGroup(testWorkgroup).setPriority(1);
504 peopleFlow3.addPrincipal(testuser3).setPriority(10);
505 peopleFlowService.createPeopleFlow(peopleFlow3.build());
506 }
507
508
509 @Test
510 public void test_MultiplePeopleFlow_PriorityParallel() throws Exception {
511 createMultiplePeopleFlows();
512
513
514 WorkflowDocument document = WorkflowDocumentFactory.createDocument(user3, MULTIPLE_PEOPLE_FLOW_PRIORITY_PARALLEL);
515 document.route("");
516 assertTrue("Document should be enroute.", document.isEnroute());
517
518
519 document.switchPrincipal(user3);
520
521
522
523
524 List<ActionRequest> rootActionRequests = document.getRootActionRequests();
525 assertEquals("Should have 2 root action requests", 2, rootActionRequests.size());
526 ActionRequest user1Request = null;
527 ActionRequest user2Request = null;
528 for (ActionRequest actionRequest : rootActionRequests) {
529 RecipientType recipientType = actionRequest.getRecipientType();
530 if (recipientType == RecipientType.PRINCIPAL) {
531 if (user1.equals(actionRequest.getPrincipalId())) {
532 user1Request = actionRequest;
533 } else if (user2.equals(actionRequest.getPrincipalId())) {
534 user2Request = actionRequest;
535 }
536 }
537 }
538
539 assertNotNull(user1Request);
540 assertEquals(ActionRequestStatus.ACTIVATED, user1Request.getStatus());
541 assertNotNull(user2Request);
542 assertEquals(ActionRequestStatus.INITIALIZED, user2Request.getStatus());
543
544
545 document.switchPrincipal(user1);
546 document.approve("");
547 document.switchPrincipal(user2);
548 assertTrue(document.isApprovalRequested());
549 document.approve("");
550
551
552
553
554 assertTrue(document.isEnroute());
555 assertApproveRequested(document, ewestfal);
556 assertApproveNotRequested(document, user1, user2, testuser1, testuser2, testuser3);
557 assertAcknowledgeRequested(document, testuser1, testuser2);
558
559
560 document.switchPrincipal(ewestfal);
561 assertTrue(document.isApprovalRequested());
562 document.approve("");
563 assertTrue(document.isEnroute());
564
565
566 assertApproveRequested(document, testuser3);
567
568 document.switchPrincipal(testuser2);
569 assertTrue(document.isAcknowledgeRequested());
570 document.acknowledge("");
571 assertTrue(document.isEnroute());
572
573
574 assertApproveRequested(document, testuser3);
575 document.switchPrincipal(testuser3);
576 document.approve("");
577
578
579 assertTrue(document.isProcessed());
580
581 document.switchPrincipal(testuser1);
582 assertTrue(document.isAcknowledgeRequested());
583 document.acknowledge("");
584
585
586 assertTrue(document.isFinal());
587 }
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602 @Test
603 public void test_PrincipalMember_roleDelegate() throws Exception {
604 PeopleFlowMember.Builder member = PeopleFlowMember.Builder.create(testuser3, MemberType.PRINCIPAL);
605 PeopleFlowDelegate.Builder delegate = PeopleFlowDelegate.Builder.create(ppfTestRole2, MemberType.ROLE);
606 delegate.setDelegationType(DelegationType.PRIMARY);
607 delegate.setActionRequestPolicy(ActionRequestPolicy.FIRST);
608
609 createSimplePeopleFlow(PEOPLE_FLOW_8, member, delegate);
610
611
612 WorkflowDocument document = WorkflowDocumentFactory.createDocument(user3, ROLE_DELEGATE_PEOPLE_FLOW_PRINCIPAL_MEMBER_HAS_ROLE_DELEGATE);
613 document.route("");
614 assertTrue("Document should be enroute.", document.isEnroute());
615
616
617
618
619 List<ActionRequest> rootActionRequests = document.getRootActionRequests();
620 assertEquals("Should have 1 root action requests", 1, rootActionRequests.size());
621 ActionRequest testuser3Request = null;
622 for (ActionRequest actionRequest : rootActionRequests) {
623 RecipientType recipientType = actionRequest.getRecipientType();
624 if (recipientType == RecipientType.PRINCIPAL) {
625 if (testuser3.equals(actionRequest.getPrincipalId())) {
626 testuser3Request = actionRequest;
627 }
628 }
629 }
630
631
632 assertNotNull(testuser3Request);
633 assertEquals(ActionRequestStatus.ACTIVATED, testuser3Request.getStatus());
634
635
636 assertEquals(1, testuser3Request.getChildRequests().size());
637 ActionRequest user2Request = testuser3Request.getChildRequests().get(0);
638 assertEquals(user2, user2Request.getPrincipalId());
639 assertEquals(DelegationType.PRIMARY, user2Request.getDelegationType());
640 assertEquals(ActionRequestStatus.ACTIVATED, user2Request.getStatus());
641
642
643 assertApproveRequested(document, user2, testuser3);
644 assertApproveNotRequested(document, user1, user3, testuser1, testuser2, ewestfal);
645
646
647 document.switchPrincipal(user2);
648 document.approve("");
649
650
651 assertApproveNotRequested(document, user2, testuser3);
652
653
654 assertTrue(document.isFinal());
655 }
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670 @Test
671 public void test_RoleMember_principalDelegate() throws Exception {
672 PeopleFlowMember.Builder member = PeopleFlowMember.Builder.create(ppfTestRole2, MemberType.ROLE);
673 member.setActionRequestPolicy(ActionRequestPolicy.FIRST);
674 PeopleFlowDelegate.Builder delegate = PeopleFlowDelegate.Builder.create(testuser3, MemberType.PRINCIPAL);
675 delegate.setDelegationType(DelegationType.PRIMARY);
676
677 createSimplePeopleFlow(PEOPLE_FLOW_9, member, delegate);
678
679
680 WorkflowDocument document = WorkflowDocumentFactory.createDocument(user3, ROLE_DELEGATE_PEOPLE_FLOW_ROLE_MEMBER_HAS_PRINCIPAL_DELEGATE);
681 document.route("");
682 assertTrue("Document should be enroute.", document.isEnroute());
683
684
685
686
687 List<ActionRequest> rootActionRequests = document.getRootActionRequests();
688 assertEquals("Should have 1 root action requests", 1, rootActionRequests.size());
689 ActionRequest user2Request = null;
690 for (ActionRequest actionRequest : rootActionRequests) {
691 RecipientType recipientType = actionRequest.getRecipientType();
692 if (recipientType == RecipientType.PRINCIPAL) {
693 if (user2.equals(actionRequest.getPrincipalId())) {
694 user2Request = actionRequest;
695 }
696 }
697 }
698
699
700 assertNotNull(user2Request);
701 assertEquals(ActionRequestStatus.ACTIVATED, user2Request.getStatus());
702
703
704 assertEquals(1, user2Request.getChildRequests().size());
705 ActionRequest testuser3Request = user2Request.getChildRequests().get(0);
706 assertEquals(testuser3, testuser3Request.getPrincipalId());
707 assertEquals(DelegationType.PRIMARY, testuser3Request.getDelegationType());
708 assertEquals(ActionRequestStatus.ACTIVATED, testuser3Request.getStatus());
709
710
711 assertApproveRequested(document, user2, testuser3);
712 assertApproveNotRequested(document, user1, user3, testuser1, testuser2, ewestfal);
713
714
715 document.switchPrincipal(testuser3);
716 document.approve("");
717
718
719 assertApproveNotRequested(document, user2, testuser3);
720
721
722 assertTrue(document.isFinal());
723
724 }
725
726
727
728
729
730
731
732
733
734
735
736
737
738 @Test
739 public void test_RoleDelegate_justKimDelegate() throws Exception {
740 createSimpleRoleDelegatePeopleFlow(PEOPLE_FLOW_4,
741 ppfTestRole1,
742 null,
743 null
744 );
745
746
747 WorkflowDocument document = WorkflowDocumentFactory.createDocument(user3, ROLE_DELEGATE_PEOPLE_FLOW_JUST_KIM_DELEGATE);
748 document.route("");
749 assertTrue("Document should be enroute.", document.isEnroute());
750
751
752
753
754 List<ActionRequest> rootActionRequests = document.getRootActionRequests();
755 assertEquals("Should have 1 root action requests", 1, rootActionRequests.size());
756 ActionRequest user1Request = null;
757 for (ActionRequest actionRequest : rootActionRequests) {
758 RecipientType recipientType = actionRequest.getRecipientType();
759 if (recipientType == RecipientType.PRINCIPAL) {
760 if (user1.equals(actionRequest.getPrincipalId())) {
761 user1Request = actionRequest;
762 }
763 }
764 }
765
766
767 assertNotNull(user1Request);
768 assertEquals(ActionRequestStatus.ACTIVATED, user1Request.getStatus());
769
770
771 assertEquals(1, user1Request.getChildRequests().size());
772 ActionRequest ewestfalDelegateRequest = user1Request.getChildRequests().get(0);
773 assertEquals(ewestfal, ewestfalDelegateRequest.getPrincipalId());
774 assertEquals(DelegationType.PRIMARY, ewestfalDelegateRequest.getDelegationType());
775 assertEquals(ActionRequestStatus.ACTIVATED, ewestfalDelegateRequest.getStatus());
776
777
778 assertApproveRequested(document, user1, ewestfal);
779 assertApproveNotRequested(document, user2, user3, testuser1, testuser2, testuser3);
780
781
782 document.switchPrincipal(ewestfal);
783 document.approve("");
784
785
786 assertApproveNotRequested(document, user1, ewestfal);
787
788
789 assertTrue(document.isFinal());
790 }
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808 @Test
809 public void test_RoleDelegate_primaryDelegateRole() throws Exception {
810 createSimpleRoleDelegatePeopleFlow(PEOPLE_FLOW_5,
811 ppfTestRole1,
812 ppfTestRole2,
813 DelegationType.PRIMARY);
814
815
816 WorkflowDocument document = WorkflowDocumentFactory.createDocument(user3, ROLE_DELEGATE_PEOPLE_FLOW_PRIMARY_DELEGATE);
817 document.route("");
818 assertTrue("Document should be enroute.", document.isEnroute());
819
820
821
822
823 List<ActionRequest> rootActionRequests = document.getRootActionRequests();
824 assertEquals("Should have 1 root action requests", 1, rootActionRequests.size());
825 ActionRequest user1Request = null;
826 for (ActionRequest actionRequest : rootActionRequests) {
827 RecipientType recipientType = actionRequest.getRecipientType();
828 if (recipientType == RecipientType.PRINCIPAL) {
829 if (user1.equals(actionRequest.getPrincipalId())) {
830 user1Request = actionRequest;
831 }
832 }
833 }
834
835
836 assertNotNull(user1Request);
837 assertEquals(ActionRequestStatus.ACTIVATED, user1Request.getStatus());
838
839
840 assertEquals(1, user1Request.getChildRequests().size());
841 ActionRequest user2DelegateRequest = user1Request.getChildRequests().get(0);
842 assertEquals(user2, user2DelegateRequest.getPrincipalId());
843 assertEquals(DelegationType.PRIMARY, user2DelegateRequest.getDelegationType());
844 assertEquals(ActionRequestStatus.ACTIVATED, user2DelegateRequest.getStatus());
845
846
847 assertApproveRequested(document, user1, user2);
848 assertApproveNotRequested(document, user3, testuser1, testuser2, testuser3, ewestfal);
849
850
851 document.switchPrincipal(user2);
852 document.approve("");
853
854
855 assertApproveNotRequested(document, user1, user2);
856
857
858 assertTrue(document.isFinal());
859 }
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876 @Test
877 public void test_RoleDelegate_secondaryDelegateRole() throws Exception {
878 createSimpleRoleDelegatePeopleFlow(
879 PEOPLE_FLOW_6,
880 ppfTestRole1,
881 ppfTestRole2,
882 DelegationType.SECONDARY
883 );
884
885
886 WorkflowDocument document = WorkflowDocumentFactory.createDocument(user3, ROLE_DELEGATE_PEOPLE_FLOW_SECONDARY_DELEGATE);
887 document.route("");
888 assertTrue("Document should be enroute.", document.isEnroute());
889
890
891
892
893 List<ActionRequest> rootActionRequests = document.getRootActionRequests();
894 assertEquals("Should have 1 root action requests", 1, rootActionRequests.size());
895 ActionRequest user1Request = null;
896 for (ActionRequest actionRequest : rootActionRequests) {
897 RecipientType recipientType = actionRequest.getRecipientType();
898 if (recipientType == RecipientType.PRINCIPAL) {
899 if (user1.equals(actionRequest.getPrincipalId())) {
900 user1Request = actionRequest;
901 }
902 }
903 }
904
905
906 assertNotNull(user1Request);
907 assertEquals(ActionRequestStatus.ACTIVATED, user1Request.getStatus());
908
909
910 assertEquals(1, user1Request.getChildRequests().size());
911 ActionRequest user2DelegateRequest = user1Request.getChildRequests().get(0);
912 assertEquals(user2, user2DelegateRequest.getPrincipalId());
913 assertEquals(DelegationType.SECONDARY, user2DelegateRequest.getDelegationType());
914 assertEquals(ActionRequestStatus.ACTIVATED, user2DelegateRequest.getStatus());
915
916
917 assertApproveRequested(document, user1, user2);
918 assertApproveNotRequested(document, user3, testuser1, testuser2, testuser3, ewestfal);
919
920
921 document.switchPrincipal(user2);
922 document.approve("");
923
924
925 assertApproveNotRequested(document, user1, user2);
926
927
928 assertTrue(document.isFinal());
929 }
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946 @Test
947 public void test_RoleDelegate_delegateRoleHasKimDelegate() throws Exception {
948 createSimpleRoleDelegatePeopleFlow(PEOPLE_FLOW_7,
949 ppfTestRole2,
950 ppfTestRole1,
951 DelegationType.PRIMARY);
952
953
954 WorkflowDocument document = WorkflowDocumentFactory.createDocument(user3, ROLE_DELEGATE_PEOPLE_FLOW_DELEGATE_ROLE_HAS_KIM_DELEGATE);
955 document.route("");
956 assertTrue("Document should be enroute.", document.isEnroute());
957
958
959
960
961 List<ActionRequest> rootActionRequests = document.getRootActionRequests();
962 assertEquals("Should have 1 root action requests", 1, rootActionRequests.size());
963 ActionRequest user2Request = null;
964 for (ActionRequest actionRequest : rootActionRequests) {
965 RecipientType recipientType = actionRequest.getRecipientType();
966 if (recipientType == RecipientType.PRINCIPAL) {
967 if (user2.equals(actionRequest.getPrincipalId())) {
968 user2Request = actionRequest;
969 }
970 }
971 }
972
973
974 assertNotNull(user2Request);
975 assertEquals(ActionRequestStatus.ACTIVATED, user2Request.getStatus());
976
977
978 assertEquals(1, user2Request.getChildRequests().size());
979 ActionRequest user1DelegateRequest = user2Request.getChildRequests().get(0);
980 assertEquals(user1, user1DelegateRequest.getPrincipalId());
981 assertEquals(DelegationType.PRIMARY, user1DelegateRequest.getDelegationType());
982 assertEquals(ActionRequestStatus.ACTIVATED, user1DelegateRequest.getStatus());
983
984
985 assertApproveRequested(document, user1, user2);
986 assertApproveNotRequested(document, user3, testuser1, testuser2, testuser3, ewestfal);
987
988
989 document.switchPrincipal(user1);
990 document.approve("");
991
992
993 assertApproveNotRequested(document, user1, user2);
994
995
996 assertTrue(document.isFinal());
997 }
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013 @Test
1014 public void test_RoleDelegate_RoleMemberWithMultiplePrincipals_AllApprove() throws Exception {
1015 PeopleFlowMember.Builder member = PeopleFlowMember.Builder.create(ppfTestRole3, MemberType.ROLE);
1016 member.setActionRequestPolicy(ActionRequestPolicy.ALL);
1017 PeopleFlowDelegate.Builder delegate = PeopleFlowDelegate.Builder.create(ppfTestRole4, MemberType.ROLE);
1018 delegate.setDelegationType(DelegationType.PRIMARY);
1019 delegate.setActionRequestPolicy(ActionRequestPolicy.ALL);
1020 createSimplePeopleFlow(PEOPLE_FLOW_10, member, delegate);
1021
1022
1023 {
1024
1025 WorkflowDocument document = WorkflowDocumentFactory.createDocument(user3,
1026 ROLE_DELEGATE_PEOPLE_FLOW_ROLE_MULTIPLE_MEMBERS);
1027 document.route("");
1028 assertTrue("Document should be enroute.", document.isEnroute());
1029
1030
1031
1032
1033
1034 assertApproveRequested(document, user1, user2, testuser1, testuser2);
1035 assertApproveNotRequested(document, user3, testuser3, ewestfal);
1036
1037
1038 document.switchPrincipal(user1);
1039 document.approve("");
1040
1041
1042 document.switchPrincipal(user2);
1043 document.approve("");
1044
1045
1046 assertApproveNotRequested(document, user1, user2, testuser1, testuser2);
1047
1048
1049 assertTrue(document.isFinal());
1050 }
1051
1052
1053 {
1054
1055 WorkflowDocument document = WorkflowDocumentFactory.createDocument(user3,
1056 ROLE_DELEGATE_PEOPLE_FLOW_ROLE_MULTIPLE_MEMBERS);
1057 document.route("");
1058 assertTrue("Document should be enroute.", document.isEnroute());
1059
1060
1061
1062
1063
1064 assertApproveRequested(document, user1, user2, testuser1, testuser2);
1065 assertApproveNotRequested(document, user3, testuser3, ewestfal);
1066
1067
1068 document.switchPrincipal(testuser1);
1069 document.approve("");
1070
1071
1072 document.switchPrincipal(testuser2);
1073 document.approve("");
1074
1075
1076 assertApproveNotRequested(document, user1, user2, testuser1, testuser2);
1077
1078
1079 assertTrue(document.isFinal());
1080 }
1081
1082
1083
1084 {
1085
1086 WorkflowDocument document = WorkflowDocumentFactory.createDocument(user3,
1087 ROLE_DELEGATE_PEOPLE_FLOW_ROLE_MULTIPLE_MEMBERS);
1088 document.route("");
1089 assertTrue("Document should be enroute.", document.isEnroute());
1090
1091
1092
1093
1094
1095 assertApproveRequested(document, user1, user2, testuser1, testuser2);
1096 assertApproveNotRequested(document, user3, testuser3, ewestfal);
1097
1098
1099 document.switchPrincipal(user1);
1100 document.approve("");
1101
1102 assertApproveNotRequested(document, user1);
1103
1104
1105 document.switchPrincipal(testuser1);
1106 document.approve("");
1107
1108
1109 document.switchPrincipal(testuser2);
1110 document.approve("");
1111
1112
1113 assertApproveNotRequested(document, user1, user2, testuser1, testuser2);
1114
1115
1116 assertTrue(document.isFinal());
1117 }
1118 }
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134 @Test
1135 public void test_RoleDelegate_RoleMemberWithMultiplePrincipals_FirstApprove() throws Exception {
1136 PeopleFlowMember.Builder member = PeopleFlowMember.Builder.create(ppfTestRole3, MemberType.ROLE);
1137 member.setActionRequestPolicy(ActionRequestPolicy.FIRST);
1138 PeopleFlowDelegate.Builder delegate = PeopleFlowDelegate.Builder.create(ppfTestRole4, MemberType.ROLE);
1139 delegate.setDelegationType(DelegationType.PRIMARY);
1140 delegate.setActionRequestPolicy(ActionRequestPolicy.FIRST);
1141
1142 createSimplePeopleFlow(PEOPLE_FLOW_11, member, delegate);
1143
1144
1145 {
1146
1147 WorkflowDocument document = WorkflowDocumentFactory.createDocument(user3,
1148 ROLE_DELEGATE_PEOPLE_FLOW_ROLE_MULTIPLE_MEMBERS_FIRST_APPROVE);
1149 document.route("");
1150 assertTrue("Document should be enroute.", document.isEnroute());
1151
1152
1153 assertApproveRequested(document, user1, user2, testuser1, testuser2);
1154 assertApproveNotRequested(document, user3, testuser3, ewestfal);
1155
1156
1157 document.switchPrincipal(testuser1);
1158 document.approve("");
1159
1160 assertApproveNotRequested(document, user1, user2, testuser1, testuser2, user3, ewestfal);
1161
1162 assertTrue(document.isFinal());
1163 }
1164
1165
1166 {
1167
1168 WorkflowDocument document = WorkflowDocumentFactory.createDocument(user3,
1169 ROLE_DELEGATE_PEOPLE_FLOW_ROLE_MULTIPLE_MEMBERS_FIRST_APPROVE);
1170 document.route("");
1171 assertTrue("Document should be enroute.", document.isEnroute());
1172
1173
1174 assertApproveRequested(document, user1, user2, testuser1, testuser2);
1175 assertApproveNotRequested(document, user3, testuser3, ewestfal);
1176
1177
1178 document.switchPrincipal(user1);
1179 document.approve("");
1180
1181 assertApproveNotRequested(document, user1, user2, testuser1, testuser2, user3, ewestfal);
1182
1183 assertTrue(document.isFinal());
1184 }
1185
1186 }
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201 @Test
1202 public void test_RoleDelegate_RoleMemberWithMultiplePrincipals_DelegateFirstApprove() throws Exception {
1203 PeopleFlowMember.Builder member = PeopleFlowMember.Builder.create(ppfTestRole3, MemberType.ROLE);
1204 member.setActionRequestPolicy(ActionRequestPolicy.ALL);
1205 PeopleFlowDelegate.Builder delegate = PeopleFlowDelegate.Builder.create(ppfTestRole4, MemberType.ROLE);
1206 delegate.setDelegationType(DelegationType.PRIMARY);
1207 delegate.setActionRequestPolicy(ActionRequestPolicy.FIRST);
1208 createSimplePeopleFlow(PEOPLE_FLOW_12, member, delegate);
1209
1210
1211
1212 {
1213
1214 WorkflowDocument document = WorkflowDocumentFactory.createDocument(user3, ROLE_DELEGATE_PEOPLE_FLOW_ROLE_MULTIPLE_MEMBERS_DELEGATE_FIRST_APPROVE);
1215 document.route("");
1216 assertTrue("Document should be enroute.", document.isEnroute());
1217
1218
1219
1220 assertApproveRequested(document, user1, user2, testuser1, testuser2);
1221 assertApproveNotRequested(document, user3, testuser3, ewestfal);
1222
1223
1224 document.switchPrincipal(user1);
1225 document.approve("");
1226
1227 assertApproveRequested(document, user2, testuser1, testuser2);
1228 assertApproveNotRequested(document, user1);
1229
1230
1231 document.switchPrincipal(user2);
1232 document.approve("");
1233
1234
1235 assertApproveNotRequested(document, user1, user2, testuser1, testuser2);
1236
1237
1238 assertTrue(document.isFinal());
1239 }
1240
1241
1242 {
1243
1244 WorkflowDocument document = WorkflowDocumentFactory.createDocument(user3, ROLE_DELEGATE_PEOPLE_FLOW_ROLE_MULTIPLE_MEMBERS_DELEGATE_FIRST_APPROVE);
1245 document.route("");
1246 assertTrue("Document should be enroute.", document.isEnroute());
1247
1248
1249
1250 assertApproveRequested(document, user1, user2, testuser1, testuser2);
1251 assertApproveNotRequested(document, user3, testuser3, ewestfal);
1252
1253
1254 document.switchPrincipal(testuser1);
1255 document.approve("");
1256
1257
1258 assertApproveNotRequested(document, user1, user2, testuser1, testuser2);
1259
1260
1261 assertTrue(document.isFinal());
1262 }
1263
1264
1265
1266 {
1267
1268 WorkflowDocument document = WorkflowDocumentFactory.createDocument(user3, ROLE_DELEGATE_PEOPLE_FLOW_ROLE_MULTIPLE_MEMBERS_DELEGATE_FIRST_APPROVE);
1269 document.route("");
1270 assertTrue("Document should be enroute.", document.isEnroute());
1271
1272
1273
1274 assertApproveRequested(document, user1, user2, testuser1, testuser2);
1275 assertApproveNotRequested(document, user3, testuser3, ewestfal);
1276
1277
1278 document.switchPrincipal(user1);
1279 document.approve("");
1280
1281 assertApproveRequested(document, user2, testuser1, testuser2);
1282 assertApproveNotRequested(document, user1);
1283
1284
1285 document.switchPrincipal(testuser1);
1286 document.approve("");
1287
1288
1289 assertApproveNotRequested(document, user1, user2, testuser1, testuser2);
1290
1291
1292 assertTrue(document.isFinal());
1293 }
1294 }
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310 @Test
1311 public void test_GroupDelegate_RoleMemberWithMultiplePrincipals_AllApprove() throws Exception {
1312 PeopleFlowMember.Builder member = PeopleFlowMember.Builder.create(ppfTestGroup1, MemberType.GROUP);
1313 PeopleFlowDelegate.Builder delegate = PeopleFlowDelegate.Builder.create(ppfTestRole4, MemberType.ROLE);
1314 delegate.setDelegationType(DelegationType.PRIMARY);
1315 delegate.setActionRequestPolicy(ActionRequestPolicy.ALL);
1316 createSimplePeopleFlow(PEOPLE_FLOW_13, member, delegate);
1317
1318
1319 {
1320
1321 WorkflowDocument document = WorkflowDocumentFactory.createDocument(user3,
1322 GROUP_DELEGATE_PEOPLE_FLOW_ROLE_MULTIPLE_MEMBERS);
1323 document.route("");
1324 assertTrue("Document should be enroute.", document.isEnroute());
1325
1326
1327 assertApproveRequested(document, earl, fran, testuser1, testuser2);
1328 assertApproveNotRequested(document, user1, user2, user3, testuser3, ewestfal);
1329
1330
1331 document.switchPrincipal(earl);
1332 document.approve("");
1333
1334
1335 assertApproveNotRequested(document, user1, user2, earl, fran, testuser1, testuser2);
1336
1337
1338 assertTrue(document.isFinal());
1339 }
1340
1341
1342 {
1343
1344 WorkflowDocument document = WorkflowDocumentFactory.createDocument(user3,
1345 GROUP_DELEGATE_PEOPLE_FLOW_ROLE_MULTIPLE_MEMBERS);
1346 document.route("");
1347 assertTrue("Document should be enroute.", document.isEnroute());
1348
1349 assertApproveRequested(document, earl, fran, testuser1, testuser2);
1350 assertApproveNotRequested(document, user1, user2, user3, testuser3, ewestfal);
1351
1352
1353 document.switchPrincipal(testuser1);
1354 document.approve("");
1355
1356 assertFalse(document.isFinal());
1357
1358
1359 document.switchPrincipal(testuser2);
1360 document.approve("");
1361
1362
1363 assertApproveNotRequested(document, user1, user2, earl, fran, testuser1, testuser2);
1364
1365
1366 assertTrue(document.isFinal());
1367 }
1368 }
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392 private PeopleFlowDefinition createSimpleRoleDelegatePeopleFlow(String peopleFlowName, String memberRoleId, String delegateRoleId,
1393 DelegationType delegationType) {
1394 PeopleFlowDefinition.Builder peopleFlow = PeopleFlowDefinition.Builder.create(NAMESPACE_CODE, peopleFlowName);
1395
1396
1397
1398 PeopleFlowMember.Builder memberBuilder = peopleFlow.addRole(memberRoleId);
1399 memberBuilder.setPriority(1);
1400 memberBuilder.setActionRequestPolicy(ActionRequestPolicy.FIRST);
1401
1402 if (delegateRoleId != null) {
1403
1404 PeopleFlowDelegate.Builder delegateBuilder =
1405 PeopleFlowDelegate.Builder.create(delegateRoleId, MemberType.ROLE);
1406 delegateBuilder.setDelegationType(delegationType);
1407 delegateBuilder.setActionRequestPolicy(ActionRequestPolicy.FIRST);
1408
1409 memberBuilder.getDelegates().add(delegateBuilder);
1410 }
1411
1412 return peopleFlowService.createPeopleFlow(peopleFlow.build());
1413 }
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428 private PeopleFlowDefinition createSimplePeopleFlow(String peopleFlowName, PeopleFlowMember.Builder member, PeopleFlowDelegate.Builder delegate) {
1429 PeopleFlowDefinition.Builder peopleFlow = PeopleFlowDefinition.Builder.create(NAMESPACE_CODE, peopleFlowName);
1430
1431 member.setPriority(1);
1432
1433 if (delegate != null) {
1434
1435 member.getDelegates().add(delegate);
1436 }
1437
1438 peopleFlow.getMembers().add(member);
1439
1440 return peopleFlowService.createPeopleFlow(peopleFlow.build());
1441 }
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460 private void createDelegatePeopleFlow() {
1461 PeopleFlowDefinition.Builder peopleFlow = PeopleFlowDefinition.Builder.create(NAMESPACE_CODE, PEOPLE_FLOW_1);
1462 peopleFlow.addPrincipal(user1).setPriority(1);
1463
1464 PeopleFlowMember.Builder user2Builder = peopleFlow.addPrincipal(user2);
1465 user2Builder.setPriority(1);
1466 PeopleFlowDelegate.Builder user2PrimaryDelegateBuilder = PeopleFlowDelegate.Builder.create(testuser2,
1467 MemberType.PRINCIPAL);
1468 user2PrimaryDelegateBuilder.setDelegationType(DelegationType.PRIMARY);
1469 user2Builder.getDelegates().add(user2PrimaryDelegateBuilder);
1470
1471 PeopleFlowMember.Builder testuser1Builder = peopleFlow.addPrincipal(testuser1);
1472 testuser1Builder.setPriority(2);
1473 PeopleFlowDelegate.Builder testWorkgroupSecondaryDelegateBuilder = PeopleFlowDelegate.Builder.create(testWorkgroup, MemberType.GROUP);
1474 testWorkgroupSecondaryDelegateBuilder.setDelegationType(DelegationType.SECONDARY);
1475 testuser1Builder.getDelegates().add(testWorkgroupSecondaryDelegateBuilder);
1476 PeopleFlowDelegate.Builder testuser3PrimaryDelegateBuilder = PeopleFlowDelegate.Builder.create(testuser3, MemberType.PRINCIPAL);
1477 testuser3PrimaryDelegateBuilder.setDelegationType(DelegationType.PRIMARY);
1478 testuser1Builder.getDelegates().add(testuser3PrimaryDelegateBuilder);
1479
1480 peopleFlow.addPrincipal(user3).setPriority(2);
1481
1482 peopleFlowService.createPeopleFlow(peopleFlow.build());
1483 }
1484
1485 @Test
1486 public void test_DelegatePeopleFlow_PriorityParallel_Approve() throws Exception {
1487 createDelegatePeopleFlow();
1488
1489 WorkflowDocument document = WorkflowDocumentFactory.createDocument(user3, DELEGATE_PEOPLE_FLOW_PRIORITY_PARALLEL_APPROVE);
1490 document.route("");
1491 assertTrue("Document should be enroute.", document.isEnroute());
1492
1493
1494 document.switchPrincipal(user3);
1495
1496
1497
1498
1499 List<ActionRequest> rootActionRequests = document.getRootActionRequests();
1500 assertEquals("Should have 4 root action requests", 4, rootActionRequests.size());
1501 ActionRequest user1Request = null;
1502 ActionRequest user2Request = null;
1503 ActionRequest user3Request = null;
1504 ActionRequest testuser1Request = null;
1505 for (ActionRequest actionRequest : rootActionRequests) {
1506 RecipientType recipientType = actionRequest.getRecipientType();
1507 if (recipientType == RecipientType.PRINCIPAL) {
1508 if (user1.equals(actionRequest.getPrincipalId())) {
1509 user1Request = actionRequest;
1510 } else if (user2.equals(actionRequest.getPrincipalId())) {
1511 user2Request = actionRequest;
1512 } else if (user3.equals(actionRequest.getPrincipalId())) {
1513 user3Request = actionRequest;
1514 } else if (testuser1.equals(actionRequest.getPrincipalId())) {
1515 testuser1Request = actionRequest;
1516 }
1517 }
1518 }
1519
1520 assertNotNull(user1Request);
1521 assertEquals(ActionRequestStatus.ACTIVATED, user1Request.getStatus());
1522 assertNotNull(user2Request);
1523 assertEquals(ActionRequestStatus.ACTIVATED, user2Request.getStatus());
1524 assertNotNull(user3Request);
1525 assertEquals(ActionRequestStatus.INITIALIZED, user3Request.getStatus());
1526 assertNotNull(testuser1Request);
1527 assertEquals(ActionRequestStatus.INITIALIZED, testuser1Request.getStatus());
1528
1529
1530 assertEquals(1, user2Request.getChildRequests().size());
1531 ActionRequest testuser2DelegateRequest = user2Request.getChildRequests().get(0);
1532 assertEquals(testuser2, testuser2DelegateRequest.getPrincipalId());
1533 assertEquals(DelegationType.PRIMARY, testuser2DelegateRequest.getDelegationType());
1534 assertEquals(ActionRequestStatus.ACTIVATED, testuser2DelegateRequest.getStatus());
1535
1536
1537 assertEquals(2, testuser1Request.getChildRequests().size());
1538 ActionRequest testWorkgroupRequest = null;
1539 ActionRequest testuser3Request = null;
1540 for (ActionRequest childActionRequest : testuser1Request.getChildRequests()) {
1541 RecipientType recipientType = childActionRequest.getRecipientType();
1542 if (recipientType == RecipientType.PRINCIPAL) {
1543 if (testuser3.equals(childActionRequest.getPrincipalId())) {
1544 testuser3Request = childActionRequest;
1545 }
1546 } else if (recipientType == RecipientType.GROUP) {
1547 if (testWorkgroup.equals(childActionRequest.getGroupId())) {
1548 testWorkgroupRequest = childActionRequest;
1549 }
1550 }
1551 }
1552 assertNotNull(testWorkgroupRequest);
1553 assertEquals(ActionRequestStatus.INITIALIZED, testWorkgroupRequest.getStatus());
1554 assertEquals(DelegationType.SECONDARY, testWorkgroupRequest.getDelegationType());
1555 assertNotNull(testuser3Request);
1556 assertEquals(ActionRequestStatus.INITIALIZED, testuser3Request.getStatus());
1557 assertEquals(DelegationType.PRIMARY, testuser3Request.getDelegationType());
1558
1559
1560 assertApproveRequested(document, user1, user2, testuser2);
1561 assertApproveNotRequested(document, testuser1, user3, ewestfal, testuser3);
1562
1563 document.switchPrincipal(testuser2);
1564 document.approve("");
1565
1566
1567 assertApproveRequested(document, user1);
1568 assertApproveNotRequested(document, user2, testuser2, testuser1, user3, ewestfal, testuser3);
1569 document.switchPrincipal(user1);
1570 document.approve("");
1571
1572
1573 assertApproveRequested(document, testuser1, user3, ewestfal, testuser3);
1574 assertApproveNotRequested(document, user1, user2, testuser2);
1575
1576 document.switchPrincipal(ewestfal);
1577 document.approve("");
1578
1579
1580 assertApproveRequested(document, user3);
1581 assertApproveNotRequested(document, user1, user2, testuser2, testuser1, ewestfal, testuser3);
1582 document.switchPrincipal(user3);
1583 document.approve("");
1584
1585
1586 assertTrue(document.isFinal());
1587
1588 }
1589
1590 private String roleId = null;
1591
1592
1593
1594 private void createFirstApproveRolePeopleFlow() {
1595 RoleService roleService = KimApiServiceLocator.getRoleService();
1596 Role role = roleService.getRoleByNamespaceCodeAndName("KR-SYS", "Technical Administrator");
1597 assertNotNull("Technical Administrator role should exist!", role);
1598 assertEquals(2, roleService.getRoleMembers(Collections.singletonList(role.getId()),
1599 new HashMap<String, String>()).size());
1600 roleId = role.getId();
1601
1602 PeopleFlowDefinition.Builder peopleFlow = PeopleFlowDefinition.Builder.create(NAMESPACE_CODE, PEOPLE_FLOW_2);
1603 PeopleFlowMember.Builder memberBuilder = peopleFlow.addRole(role.getId());
1604 memberBuilder.setPriority(1);
1605 memberBuilder.setActionRequestPolicy(ActionRequestPolicy.FIRST);
1606 peopleFlowService.createPeopleFlow(peopleFlow.build());
1607 }
1608
1609 @Test
1610 public void test_FirstApproveRolePeopleFlow() throws Exception {
1611 createFirstApproveRolePeopleFlow();
1612
1613 WorkflowDocument document = WorkflowDocumentFactory.createDocument(user3, SINGLE_PEOPLE_FLOW_PRIORITY_PARALLEL_APPROVE);
1614 document.route("");
1615 assertTrue("Document should be enroute.", document.isEnroute());
1616
1617
1618
1619 List<ActionRequest> rootActionRequests = document.getRootActionRequests();
1620 assertEquals(1, rootActionRequests.size());
1621 ActionRequest roleRequest = rootActionRequests.get(0);
1622 assertEquals(ActionRequestPolicy.FIRST, roleRequest.getRequestPolicy());
1623 assertEquals(roleId, roleRequest.getRoleName());
1624 assertEquals(RecipientType.ROLE, roleRequest.getRecipientType());
1625 assertEquals(2, roleRequest.getChildRequests().size());
1626 for (ActionRequest childRequest : roleRequest.getChildRequests()) {
1627 if (RecipientType.PRINCIPAL.equals(childRequest.getRecipientType())) {
1628 assertEquals(getPrincipalIdForName("admin"), childRequest.getPrincipalId());
1629 } else if (RecipientType.GROUP.equals(childRequest.getRecipientType())) {
1630 assertEquals(getGroupIdForName("KR-WKFLW", "WorkflowAdmin"), childRequest.getGroupId());
1631 } else {
1632 fail("Found a child request i didn't expect with a recipient type of: " + childRequest.getRecipientType());
1633 }
1634 }
1635
1636
1637
1638 document.switchPrincipal(getPrincipalNameForId("admin"));
1639 assertTrue(document.isApprovalRequested());
1640 document.switchPrincipal(getPrincipalIdForName("bmcgough"));
1641 assertTrue(document.isApprovalRequested());
1642
1643
1644 document.approve("");
1645
1646
1647 assertTrue(document.isFinal());
1648
1649
1650 document = WorkflowDocumentFactory.createDocument(user3, SINGLE_PEOPLE_FLOW_PRIORITY_PARALLEL_APPROVE);
1651 document.route("");
1652 assertTrue("Document should be enroute.", document.isEnroute());
1653 document.switchPrincipal(getPrincipalIdForName("bmcgough"));
1654 assertTrue(document.isApprovalRequested());
1655 document.switchPrincipal(getPrincipalNameForId("admin"));
1656 assertTrue(document.isApprovalRequested());
1657
1658 document.approve("");
1659
1660 assertTrue(document.isFinal());
1661 }
1662
1663
1664
1665
1666 private void createAllApproveRolePeopleFlow() {
1667 RoleService roleService = KimApiServiceLocator.getRoleService();
1668 Role role = roleService.getRoleByNamespaceCodeAndName("KR-SYS", "Technical Administrator");
1669 assertNotNull("Technical Administrator role should exist!", role);
1670 assertEquals(2, roleService.getRoleMembers(Collections.singletonList(role.getId()),
1671 new HashMap<String, String>()).size());
1672 roleId = role.getId();
1673
1674 PeopleFlowDefinition.Builder peopleFlow = PeopleFlowDefinition.Builder.create(NAMESPACE_CODE, PEOPLE_FLOW_2);
1675 PeopleFlowMember.Builder memberBuilder = peopleFlow.addRole(role.getId());
1676 memberBuilder.setPriority(1);
1677 memberBuilder.setActionRequestPolicy(ActionRequestPolicy.ALL);
1678 peopleFlowService.createPeopleFlow(peopleFlow.build());
1679 }
1680
1681 @Test
1682 public void test_AllApproveRolePeopleFlow() throws Exception {
1683 createAllApproveRolePeopleFlow();
1684
1685 WorkflowDocument document = WorkflowDocumentFactory.createDocument(user3, SINGLE_PEOPLE_FLOW_PRIORITY_PARALLEL_APPROVE);
1686 document.route("");
1687 assertTrue("Document should be enroute.", document.isEnroute());
1688
1689
1690
1691 List<ActionRequest> rootActionRequests = document.getRootActionRequests();
1692 assertEquals(1, rootActionRequests.size());
1693 ActionRequest roleRequest = rootActionRequests.get(0);
1694 assertEquals(ActionRequestPolicy.ALL, roleRequest.getRequestPolicy());
1695 assertEquals(roleId, roleRequest.getRoleName());
1696 assertEquals(RecipientType.ROLE, roleRequest.getRecipientType());
1697 assertEquals(2, roleRequest.getChildRequests().size());
1698 for (ActionRequest childRequest : roleRequest.getChildRequests()) {
1699 if (RecipientType.PRINCIPAL.equals(childRequest.getRecipientType())) {
1700 assertEquals(getPrincipalIdForName("admin"), childRequest.getPrincipalId());
1701 } else if (RecipientType.GROUP.equals(childRequest.getRecipientType())) {
1702 assertEquals(getGroupIdForName("KR-WKFLW", "WorkflowAdmin"), childRequest.getGroupId());
1703 } else {
1704 fail("Found a child request i didn't expect with a recipient type of: " + childRequest.getRecipientType());
1705 }
1706 }
1707
1708
1709
1710 document.switchPrincipal(getPrincipalNameForId("admin"));
1711 assertTrue(document.isApprovalRequested());
1712 document.switchPrincipal(getPrincipalIdForName("bmcgough"));
1713 assertTrue(document.isApprovalRequested());
1714
1715
1716 document.approve("");
1717
1718
1719 assertTrue(document.isEnroute());
1720 assertFalse(document.isApprovalRequested());
1721
1722 document.switchPrincipal(getPrincipalNameForId("admin"));
1723 assertTrue(document.isApprovalRequested());
1724 document.approve("");
1725
1726 assertTrue(document.isFinal());
1727 }
1728
1729 private void assertApproveRequested(WorkflowDocument document, String... principalIds) {
1730 for (String principalId : principalIds) {
1731 document.switchPrincipal(principalId);
1732 assertTrue("Approve should have been requested for '" + principalId + "'", document.isApprovalRequested());
1733 }
1734 }
1735
1736 private void assertAcknowledgeRequested(WorkflowDocument document, String... principalIds) {
1737 for (String principalId : principalIds) {
1738 document.switchPrincipal(principalId);
1739 assertTrue("Acknowledge should have been requested for '" + principalId + "'", document.isAcknowledgeRequested());
1740 }
1741 }
1742
1743 private void assertApproveNotRequested(WorkflowDocument document, String... principalIds) {
1744 for (String principalId : principalIds) {
1745 document.switchPrincipal(principalId);
1746 assertFalse("Approve should *NOT* have been requested for '" + principalId + "'", document.isApprovalRequested());
1747 }
1748 }
1749
1750 }