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
608 createSimplePeopleFlow(PEOPLE_FLOW_8, member, delegate);
609
610
611 WorkflowDocument document = WorkflowDocumentFactory.createDocument(user3, ROLE_DELEGATE_PEOPLE_FLOW_PRINCIPAL_MEMBER_HAS_ROLE_DELEGATE);
612 document.route("");
613 assertTrue("Document should be enroute.", document.isEnroute());
614
615
616
617
618 List<ActionRequest> rootActionRequests = document.getRootActionRequests();
619 assertEquals("Should have 1 root action requests", 1, rootActionRequests.size());
620 ActionRequest testuser3Request = null;
621 for (ActionRequest actionRequest : rootActionRequests) {
622 RecipientType recipientType = actionRequest.getRecipientType();
623 if (recipientType == RecipientType.PRINCIPAL) {
624 if (testuser3.equals(actionRequest.getPrincipalId())) {
625 testuser3Request = actionRequest;
626 }
627 }
628 }
629
630
631 assertNotNull(testuser3Request);
632 assertEquals(ActionRequestStatus.ACTIVATED, testuser3Request.getStatus());
633
634
635 assertEquals(1, testuser3Request.getChildRequests().size());
636 ActionRequest user2Request = testuser3Request.getChildRequests().get(0);
637 assertEquals(user2, user2Request.getPrincipalId());
638 assertEquals(DelegationType.PRIMARY, user2Request.getDelegationType());
639 assertEquals(ActionRequestStatus.ACTIVATED, user2Request.getStatus());
640
641
642 assertApproveRequested(document, user2, testuser3);
643 assertApproveNotRequested(document, user1, user3, testuser1, testuser2, ewestfal);
644
645
646 document.switchPrincipal(user2);
647 document.approve("");
648
649
650 assertApproveNotRequested(document, user2, testuser3);
651
652
653 assertTrue(document.isFinal());
654 }
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669 @Test
670 public void test_RoleMember_principalDelegate() throws Exception {
671 PeopleFlowMember.Builder member = PeopleFlowMember.Builder.create(ppfTestRole2, MemberType.ROLE);
672 PeopleFlowDelegate.Builder delegate = PeopleFlowDelegate.Builder.create(testuser3, MemberType.PRINCIPAL);
673 delegate.setDelegationType(DelegationType.PRIMARY);
674
675 createSimplePeopleFlow(PEOPLE_FLOW_9, member, delegate);
676
677
678 WorkflowDocument document = WorkflowDocumentFactory.createDocument(user3, ROLE_DELEGATE_PEOPLE_FLOW_ROLE_MEMBER_HAS_PRINCIPAL_DELEGATE);
679 document.route("");
680 assertTrue("Document should be enroute.", document.isEnroute());
681
682
683
684
685 List<ActionRequest> rootActionRequests = document.getRootActionRequests();
686 assertEquals("Should have 1 root action requests", 1, rootActionRequests.size());
687 ActionRequest user2Request = null;
688 for (ActionRequest actionRequest : rootActionRequests) {
689 RecipientType recipientType = actionRequest.getRecipientType();
690 if (recipientType == RecipientType.PRINCIPAL) {
691 if (user2.equals(actionRequest.getPrincipalId())) {
692 user2Request = actionRequest;
693 }
694 }
695 }
696
697
698 assertNotNull(user2Request);
699 assertEquals(ActionRequestStatus.ACTIVATED, user2Request.getStatus());
700
701
702 assertEquals(1, user2Request.getChildRequests().size());
703 ActionRequest testuser3Request = user2Request.getChildRequests().get(0);
704 assertEquals(testuser3, testuser3Request.getPrincipalId());
705 assertEquals(DelegationType.PRIMARY, testuser3Request.getDelegationType());
706 assertEquals(ActionRequestStatus.ACTIVATED, testuser3Request.getStatus());
707
708
709 assertApproveRequested(document, user2, testuser3);
710 assertApproveNotRequested(document, user1, user3, testuser1, testuser2, ewestfal);
711
712
713 document.switchPrincipal(testuser3);
714 document.approve("");
715
716
717 assertApproveNotRequested(document, user2, testuser3);
718
719
720 assertTrue(document.isFinal());
721
722 }
723
724
725
726
727
728
729
730
731
732
733
734
735
736 @Test
737 public void test_RoleDelegate_justKimDelegate() throws Exception {
738 createSimpleRoleDelegatePeopleFlow(PEOPLE_FLOW_4,
739 ppfTestRole1,
740 null,
741 null
742 );
743
744
745 WorkflowDocument document = WorkflowDocumentFactory.createDocument(user3, ROLE_DELEGATE_PEOPLE_FLOW_JUST_KIM_DELEGATE);
746 document.route("");
747 assertTrue("Document should be enroute.", document.isEnroute());
748
749
750
751
752 List<ActionRequest> rootActionRequests = document.getRootActionRequests();
753 assertEquals("Should have 1 root action requests", 1, rootActionRequests.size());
754 ActionRequest user1Request = null;
755 for (ActionRequest actionRequest : rootActionRequests) {
756 RecipientType recipientType = actionRequest.getRecipientType();
757 if (recipientType == RecipientType.PRINCIPAL) {
758 if (user1.equals(actionRequest.getPrincipalId())) {
759 user1Request = actionRequest;
760 }
761 }
762 }
763
764
765 assertNotNull(user1Request);
766 assertEquals(ActionRequestStatus.ACTIVATED, user1Request.getStatus());
767
768
769 assertEquals(1, user1Request.getChildRequests().size());
770 ActionRequest ewestfalDelegateRequest = user1Request.getChildRequests().get(0);
771 assertEquals(ewestfal, ewestfalDelegateRequest.getPrincipalId());
772 assertEquals(DelegationType.PRIMARY, ewestfalDelegateRequest.getDelegationType());
773 assertEquals(ActionRequestStatus.ACTIVATED, ewestfalDelegateRequest.getStatus());
774
775
776 assertApproveRequested(document, user1, ewestfal);
777 assertApproveNotRequested(document, user2, user3, testuser1, testuser2, testuser3);
778
779
780 document.switchPrincipal(ewestfal);
781 document.approve("");
782
783
784 assertApproveNotRequested(document, user1, ewestfal);
785
786
787 assertTrue(document.isFinal());
788 }
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806 @Test
807 public void test_RoleDelegate_primaryDelegateRole() throws Exception {
808 createSimpleRoleDelegatePeopleFlow(PEOPLE_FLOW_5,
809 ppfTestRole1,
810 ppfTestRole2,
811 DelegationType.PRIMARY);
812
813
814 WorkflowDocument document = WorkflowDocumentFactory.createDocument(user3, ROLE_DELEGATE_PEOPLE_FLOW_PRIMARY_DELEGATE);
815 document.route("");
816 assertTrue("Document should be enroute.", document.isEnroute());
817
818
819
820
821 List<ActionRequest> rootActionRequests = document.getRootActionRequests();
822 assertEquals("Should have 1 root action requests", 1, rootActionRequests.size());
823 ActionRequest user1Request = null;
824 for (ActionRequest actionRequest : rootActionRequests) {
825 RecipientType recipientType = actionRequest.getRecipientType();
826 if (recipientType == RecipientType.PRINCIPAL) {
827 if (user1.equals(actionRequest.getPrincipalId())) {
828 user1Request = actionRequest;
829 }
830 }
831 }
832
833
834 assertNotNull(user1Request);
835 assertEquals(ActionRequestStatus.ACTIVATED, user1Request.getStatus());
836
837
838 assertEquals(1, user1Request.getChildRequests().size());
839 ActionRequest user2DelegateRequest = user1Request.getChildRequests().get(0);
840 assertEquals(user2, user2DelegateRequest.getPrincipalId());
841 assertEquals(DelegationType.PRIMARY, user2DelegateRequest.getDelegationType());
842 assertEquals(ActionRequestStatus.ACTIVATED, user2DelegateRequest.getStatus());
843
844
845 assertApproveRequested(document, user1, user2);
846 assertApproveNotRequested(document, user3, testuser1, testuser2, testuser3, ewestfal);
847
848
849 document.switchPrincipal(user2);
850 document.approve("");
851
852
853 assertApproveNotRequested(document, user1, user2);
854
855
856 assertTrue(document.isFinal());
857 }
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874 @Test
875 public void test_RoleDelegate_secondaryDelegateRole() throws Exception {
876 createSimpleRoleDelegatePeopleFlow(
877 PEOPLE_FLOW_6,
878 ppfTestRole1,
879 ppfTestRole2,
880 DelegationType.SECONDARY
881 );
882
883
884 WorkflowDocument document = WorkflowDocumentFactory.createDocument(user3, ROLE_DELEGATE_PEOPLE_FLOW_SECONDARY_DELEGATE);
885 document.route("");
886 assertTrue("Document should be enroute.", document.isEnroute());
887
888
889
890
891 List<ActionRequest> rootActionRequests = document.getRootActionRequests();
892 assertEquals("Should have 1 root action requests", 1, rootActionRequests.size());
893 ActionRequest user1Request = null;
894 for (ActionRequest actionRequest : rootActionRequests) {
895 RecipientType recipientType = actionRequest.getRecipientType();
896 if (recipientType == RecipientType.PRINCIPAL) {
897 if (user1.equals(actionRequest.getPrincipalId())) {
898 user1Request = actionRequest;
899 }
900 }
901 }
902
903
904 assertNotNull(user1Request);
905 assertEquals(ActionRequestStatus.ACTIVATED, user1Request.getStatus());
906
907
908 assertEquals(1, user1Request.getChildRequests().size());
909 ActionRequest user2DelegateRequest = user1Request.getChildRequests().get(0);
910 assertEquals(user2, user2DelegateRequest.getPrincipalId());
911 assertEquals(DelegationType.SECONDARY, user2DelegateRequest.getDelegationType());
912 assertEquals(ActionRequestStatus.ACTIVATED, user2DelegateRequest.getStatus());
913
914
915 assertApproveRequested(document, user1, user2);
916 assertApproveNotRequested(document, user3, testuser1, testuser2, testuser3, ewestfal);
917
918
919 document.switchPrincipal(user2);
920 document.approve("");
921
922
923 assertApproveNotRequested(document, user1, user2);
924
925
926 assertTrue(document.isFinal());
927 }
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944 @Test
945 public void test_RoleDelegate_delegateRoleHasKimDelegate() throws Exception {
946 createSimpleRoleDelegatePeopleFlow(PEOPLE_FLOW_7,
947 ppfTestRole2,
948 ppfTestRole1,
949 DelegationType.PRIMARY);
950
951
952 WorkflowDocument document = WorkflowDocumentFactory.createDocument(user3, ROLE_DELEGATE_PEOPLE_FLOW_DELEGATE_ROLE_HAS_KIM_DELEGATE);
953 document.route("");
954 assertTrue("Document should be enroute.", document.isEnroute());
955
956
957
958
959 List<ActionRequest> rootActionRequests = document.getRootActionRequests();
960 assertEquals("Should have 1 root action requests", 1, rootActionRequests.size());
961 ActionRequest user2Request = null;
962 for (ActionRequest actionRequest : rootActionRequests) {
963 RecipientType recipientType = actionRequest.getRecipientType();
964 if (recipientType == RecipientType.PRINCIPAL) {
965 if (user2.equals(actionRequest.getPrincipalId())) {
966 user2Request = actionRequest;
967 }
968 }
969 }
970
971
972 assertNotNull(user2Request);
973 assertEquals(ActionRequestStatus.ACTIVATED, user2Request.getStatus());
974
975
976 assertEquals(1, user2Request.getChildRequests().size());
977 ActionRequest user1DelegateRequest = user2Request.getChildRequests().get(0);
978 assertEquals(user1, user1DelegateRequest.getPrincipalId());
979 assertEquals(DelegationType.PRIMARY, user1DelegateRequest.getDelegationType());
980 assertEquals(ActionRequestStatus.ACTIVATED, user1DelegateRequest.getStatus());
981
982
983 assertApproveRequested(document, user1, user2);
984 assertApproveNotRequested(document, user3, testuser1, testuser2, testuser3, ewestfal);
985
986
987 document.switchPrincipal(user1);
988 document.approve("");
989
990
991 assertApproveNotRequested(document, user1, user2);
992
993
994 assertTrue(document.isFinal());
995 }
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011 @Test
1012 public void test_RoleDelegate_RoleMemberWithMultiplePrincipals_AllApprove() throws Exception {
1013 PeopleFlowMember.Builder member = PeopleFlowMember.Builder.create(ppfTestRole3, MemberType.ROLE);
1014 member.setActionRequestPolicy(ActionRequestPolicy.ALL);
1015 PeopleFlowDelegate.Builder delegate = PeopleFlowDelegate.Builder.create(ppfTestRole4, MemberType.ROLE);
1016 delegate.setDelegationType(DelegationType.PRIMARY);
1017 delegate.setActionRequestPolicy(ActionRequestPolicy.ALL);
1018 createSimplePeopleFlow(PEOPLE_FLOW_10, member, delegate);
1019
1020
1021 {
1022
1023 WorkflowDocument document = WorkflowDocumentFactory.createDocument(user3,
1024 ROLE_DELEGATE_PEOPLE_FLOW_ROLE_MULTIPLE_MEMBERS);
1025 document.route("");
1026 assertTrue("Document should be enroute.", document.isEnroute());
1027
1028
1029
1030
1031
1032 assertApproveRequested(document, user1, user2, testuser1, testuser2);
1033 assertApproveNotRequested(document, user3, testuser3, ewestfal);
1034
1035
1036 document.switchPrincipal(user1);
1037 document.approve("");
1038
1039
1040 document.switchPrincipal(user2);
1041 document.approve("");
1042
1043
1044 assertApproveNotRequested(document, user1, user2, testuser1, testuser2);
1045
1046
1047 assertTrue(document.isFinal());
1048 }
1049
1050
1051 {
1052
1053 WorkflowDocument document = WorkflowDocumentFactory.createDocument(user3,
1054 ROLE_DELEGATE_PEOPLE_FLOW_ROLE_MULTIPLE_MEMBERS);
1055 document.route("");
1056 assertTrue("Document should be enroute.", document.isEnroute());
1057
1058
1059
1060
1061
1062 assertApproveRequested(document, user1, user2, testuser1, testuser2);
1063 assertApproveNotRequested(document, user3, testuser3, ewestfal);
1064
1065
1066 document.switchPrincipal(testuser1);
1067 document.approve("");
1068
1069
1070 document.switchPrincipal(testuser2);
1071 document.approve("");
1072
1073
1074 assertApproveNotRequested(document, user1, user2, testuser1, testuser2);
1075
1076
1077 assertTrue(document.isFinal());
1078 }
1079
1080
1081
1082 {
1083
1084 WorkflowDocument document = WorkflowDocumentFactory.createDocument(user3,
1085 ROLE_DELEGATE_PEOPLE_FLOW_ROLE_MULTIPLE_MEMBERS);
1086 document.route("");
1087 assertTrue("Document should be enroute.", document.isEnroute());
1088
1089
1090
1091
1092
1093 assertApproveRequested(document, user1, user2, testuser1, testuser2);
1094 assertApproveNotRequested(document, user3, testuser3, ewestfal);
1095
1096
1097 document.switchPrincipal(user1);
1098 document.approve("");
1099
1100 assertApproveNotRequested(document, user1);
1101
1102
1103 document.switchPrincipal(testuser1);
1104 document.approve("");
1105
1106
1107 document.switchPrincipal(testuser2);
1108 document.approve("");
1109
1110
1111 assertApproveNotRequested(document, user1, user2, testuser1, testuser2);
1112
1113
1114 assertTrue(document.isFinal());
1115 }
1116 }
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132 @Test
1133 public void test_RoleDelegate_RoleMemberWithMultiplePrincipals_FirstApprove() throws Exception {
1134 PeopleFlowMember.Builder member = PeopleFlowMember.Builder.create(ppfTestRole3, MemberType.ROLE);
1135 member.setActionRequestPolicy(ActionRequestPolicy.FIRST);
1136 PeopleFlowDelegate.Builder delegate = PeopleFlowDelegate.Builder.create(ppfTestRole4, MemberType.ROLE);
1137 delegate.setDelegationType(DelegationType.PRIMARY);
1138 delegate.setActionRequestPolicy(ActionRequestPolicy.FIRST);
1139
1140 createSimplePeopleFlow(PEOPLE_FLOW_11, member, delegate);
1141
1142
1143 {
1144
1145 WorkflowDocument document = WorkflowDocumentFactory.createDocument(user3,
1146 ROLE_DELEGATE_PEOPLE_FLOW_ROLE_MULTIPLE_MEMBERS_FIRST_APPROVE);
1147 document.route("");
1148 assertTrue("Document should be enroute.", document.isEnroute());
1149
1150
1151 assertApproveRequested(document, user1, user2, testuser1, testuser2);
1152 assertApproveNotRequested(document, user3, testuser3, ewestfal);
1153
1154
1155 document.switchPrincipal(testuser1);
1156 document.approve("");
1157
1158 assertApproveNotRequested(document, user1, user2, testuser1, testuser2, user3, ewestfal);
1159
1160 assertTrue(document.isFinal());
1161 }
1162
1163
1164 {
1165
1166 WorkflowDocument document = WorkflowDocumentFactory.createDocument(user3,
1167 ROLE_DELEGATE_PEOPLE_FLOW_ROLE_MULTIPLE_MEMBERS_FIRST_APPROVE);
1168 document.route("");
1169 assertTrue("Document should be enroute.", document.isEnroute());
1170
1171
1172 assertApproveRequested(document, user1, user2, testuser1, testuser2);
1173 assertApproveNotRequested(document, user3, testuser3, ewestfal);
1174
1175
1176 document.switchPrincipal(user1);
1177 document.approve("");
1178
1179 assertApproveNotRequested(document, user1, user2, testuser1, testuser2, user3, ewestfal);
1180
1181 assertTrue(document.isFinal());
1182 }
1183
1184 }
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199 @Test
1200 public void test_RoleDelegate_RoleMemberWithMultiplePrincipals_DelegateFirstApprove() throws Exception {
1201 PeopleFlowMember.Builder member = PeopleFlowMember.Builder.create(ppfTestRole3, MemberType.ROLE);
1202 member.setActionRequestPolicy(ActionRequestPolicy.ALL);
1203 PeopleFlowDelegate.Builder delegate = PeopleFlowDelegate.Builder.create(ppfTestRole4, MemberType.ROLE);
1204 delegate.setDelegationType(DelegationType.PRIMARY);
1205 delegate.setActionRequestPolicy(ActionRequestPolicy.FIRST);
1206 createSimplePeopleFlow(PEOPLE_FLOW_12, member, delegate);
1207
1208
1209
1210 {
1211
1212 WorkflowDocument document = WorkflowDocumentFactory.createDocument(user3, ROLE_DELEGATE_PEOPLE_FLOW_ROLE_MULTIPLE_MEMBERS_DELEGATE_FIRST_APPROVE);
1213 document.route("");
1214 assertTrue("Document should be enroute.", document.isEnroute());
1215
1216
1217
1218 assertApproveRequested(document, user1, user2, testuser1, testuser2);
1219 assertApproveNotRequested(document, user3, testuser3, ewestfal);
1220
1221
1222 document.switchPrincipal(user1);
1223 document.approve("");
1224
1225 assertApproveRequested(document, user2, testuser1, testuser2);
1226 assertApproveNotRequested(document, user1);
1227
1228
1229 document.switchPrincipal(user2);
1230 document.approve("");
1231
1232
1233 assertApproveNotRequested(document, user1, user2, testuser1, testuser2);
1234
1235
1236 assertTrue(document.isFinal());
1237 }
1238
1239
1240 {
1241
1242 WorkflowDocument document = WorkflowDocumentFactory.createDocument(user3, ROLE_DELEGATE_PEOPLE_FLOW_ROLE_MULTIPLE_MEMBERS_DELEGATE_FIRST_APPROVE);
1243 document.route("");
1244 assertTrue("Document should be enroute.", document.isEnroute());
1245
1246
1247
1248 assertApproveRequested(document, user1, user2, testuser1, testuser2);
1249 assertApproveNotRequested(document, user3, testuser3, ewestfal);
1250
1251
1252 document.switchPrincipal(testuser1);
1253 document.approve("");
1254
1255
1256 assertApproveNotRequested(document, user1, user2, testuser1, testuser2);
1257
1258
1259 assertTrue(document.isFinal());
1260 }
1261
1262
1263
1264 {
1265
1266 WorkflowDocument document = WorkflowDocumentFactory.createDocument(user3, ROLE_DELEGATE_PEOPLE_FLOW_ROLE_MULTIPLE_MEMBERS_DELEGATE_FIRST_APPROVE);
1267 document.route("");
1268 assertTrue("Document should be enroute.", document.isEnroute());
1269
1270
1271
1272 assertApproveRequested(document, user1, user2, testuser1, testuser2);
1273 assertApproveNotRequested(document, user3, testuser3, ewestfal);
1274
1275
1276 document.switchPrincipal(user1);
1277 document.approve("");
1278
1279 assertApproveRequested(document, user2, testuser1, testuser2);
1280 assertApproveNotRequested(document, user1);
1281
1282
1283 document.switchPrincipal(testuser1);
1284 document.approve("");
1285
1286
1287 assertApproveNotRequested(document, user1, user2, testuser1, testuser2);
1288
1289
1290 assertTrue(document.isFinal());
1291 }
1292 }
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308 @Test
1309 public void test_GroupDelegate_RoleMemberWithMultiplePrincipals_AllApprove() throws Exception {
1310 PeopleFlowMember.Builder member = PeopleFlowMember.Builder.create(ppfTestGroup1, MemberType.GROUP);
1311 PeopleFlowDelegate.Builder delegate = PeopleFlowDelegate.Builder.create(ppfTestRole4, MemberType.ROLE);
1312 delegate.setDelegationType(DelegationType.PRIMARY);
1313 delegate.setActionRequestPolicy(ActionRequestPolicy.ALL);
1314 createSimplePeopleFlow(PEOPLE_FLOW_13, member, delegate);
1315
1316
1317 {
1318
1319 WorkflowDocument document = WorkflowDocumentFactory.createDocument(user3,
1320 GROUP_DELEGATE_PEOPLE_FLOW_ROLE_MULTIPLE_MEMBERS);
1321 document.route("");
1322 assertTrue("Document should be enroute.", document.isEnroute());
1323
1324
1325 assertApproveRequested(document, earl, fran, testuser1, testuser2);
1326 assertApproveNotRequested(document, user1, user2, user3, testuser3, ewestfal);
1327
1328
1329 document.switchPrincipal(earl);
1330 document.approve("");
1331
1332
1333 assertApproveNotRequested(document, user1, user2, earl, fran, testuser1, testuser2);
1334
1335
1336 assertTrue(document.isFinal());
1337 }
1338
1339
1340 {
1341
1342 WorkflowDocument document = WorkflowDocumentFactory.createDocument(user3,
1343 GROUP_DELEGATE_PEOPLE_FLOW_ROLE_MULTIPLE_MEMBERS);
1344 document.route("");
1345 assertTrue("Document should be enroute.", document.isEnroute());
1346
1347 assertApproveRequested(document, earl, fran, testuser1, testuser2);
1348 assertApproveNotRequested(document, user1, user2, user3, testuser3, ewestfal);
1349
1350
1351 document.switchPrincipal(testuser1);
1352 document.approve("");
1353
1354 assertFalse(document.isFinal());
1355
1356
1357 document.switchPrincipal(testuser2);
1358 document.approve("");
1359
1360
1361 assertApproveNotRequested(document, user1, user2, earl, fran, testuser1, testuser2);
1362
1363
1364 assertTrue(document.isFinal());
1365 }
1366 }
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390 private PeopleFlowDefinition createSimpleRoleDelegatePeopleFlow(String peopleFlowName, String memberRoleId, String delegateRoleId,
1391 DelegationType delegationType) {
1392 PeopleFlowDefinition.Builder peopleFlow = PeopleFlowDefinition.Builder.create(NAMESPACE_CODE, peopleFlowName);
1393
1394
1395
1396 PeopleFlowMember.Builder memberBuilder = peopleFlow.addRole(memberRoleId);
1397 memberBuilder.setPriority(1);
1398
1399 if (delegateRoleId != null) {
1400
1401 PeopleFlowDelegate.Builder delegateBuilder =
1402 PeopleFlowDelegate.Builder.create(delegateRoleId, MemberType.ROLE);
1403 delegateBuilder.setDelegationType(delegationType);
1404
1405 memberBuilder.getDelegates().add(delegateBuilder);
1406 }
1407
1408 return peopleFlowService.createPeopleFlow(peopleFlow.build());
1409 }
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424 private PeopleFlowDefinition createSimplePeopleFlow(String peopleFlowName, PeopleFlowMember.Builder member, PeopleFlowDelegate.Builder delegate) {
1425 PeopleFlowDefinition.Builder peopleFlow = PeopleFlowDefinition.Builder.create(NAMESPACE_CODE, peopleFlowName);
1426
1427 member.setPriority(1);
1428
1429 if (delegate != null) {
1430
1431 member.getDelegates().add(delegate);
1432 }
1433
1434 peopleFlow.getMembers().add(member);
1435
1436 return peopleFlowService.createPeopleFlow(peopleFlow.build());
1437 }
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456 private void createDelegatePeopleFlow() {
1457 PeopleFlowDefinition.Builder peopleFlow = PeopleFlowDefinition.Builder.create(NAMESPACE_CODE, PEOPLE_FLOW_1);
1458 peopleFlow.addPrincipal(user1).setPriority(1);
1459
1460 PeopleFlowMember.Builder user2Builder = peopleFlow.addPrincipal(user2);
1461 user2Builder.setPriority(1);
1462 PeopleFlowDelegate.Builder user2PrimaryDelegateBuilder = PeopleFlowDelegate.Builder.create(testuser2,
1463 MemberType.PRINCIPAL);
1464 user2PrimaryDelegateBuilder.setDelegationType(DelegationType.PRIMARY);
1465 user2Builder.getDelegates().add(user2PrimaryDelegateBuilder);
1466
1467 PeopleFlowMember.Builder testuser1Builder = peopleFlow.addPrincipal(testuser1);
1468 testuser1Builder.setPriority(2);
1469 PeopleFlowDelegate.Builder testWorkgroupSecondaryDelegateBuilder = PeopleFlowDelegate.Builder.create(testWorkgroup, MemberType.GROUP);
1470 testWorkgroupSecondaryDelegateBuilder.setDelegationType(DelegationType.SECONDARY);
1471 testuser1Builder.getDelegates().add(testWorkgroupSecondaryDelegateBuilder);
1472 PeopleFlowDelegate.Builder testuser3PrimaryDelegateBuilder = PeopleFlowDelegate.Builder.create(testuser3, MemberType.PRINCIPAL);
1473 testuser3PrimaryDelegateBuilder.setDelegationType(DelegationType.PRIMARY);
1474 testuser1Builder.getDelegates().add(testuser3PrimaryDelegateBuilder);
1475
1476 peopleFlow.addPrincipal(user3).setPriority(2);
1477
1478 peopleFlowService.createPeopleFlow(peopleFlow.build());
1479 }
1480
1481 @Test
1482 public void test_DelegatePeopleFlow_PriorityParallel_Approve() throws Exception {
1483 createDelegatePeopleFlow();
1484
1485 WorkflowDocument document = WorkflowDocumentFactory.createDocument(user3, DELEGATE_PEOPLE_FLOW_PRIORITY_PARALLEL_APPROVE);
1486 document.route("");
1487 assertTrue("Document should be enroute.", document.isEnroute());
1488
1489
1490 document.switchPrincipal(user3);
1491
1492
1493
1494
1495 List<ActionRequest> rootActionRequests = document.getRootActionRequests();
1496 assertEquals("Should have 4 root action requests", 4, rootActionRequests.size());
1497 ActionRequest user1Request = null;
1498 ActionRequest user2Request = null;
1499 ActionRequest user3Request = null;
1500 ActionRequest testuser1Request = null;
1501 for (ActionRequest actionRequest : rootActionRequests) {
1502 RecipientType recipientType = actionRequest.getRecipientType();
1503 if (recipientType == RecipientType.PRINCIPAL) {
1504 if (user1.equals(actionRequest.getPrincipalId())) {
1505 user1Request = actionRequest;
1506 } else if (user2.equals(actionRequest.getPrincipalId())) {
1507 user2Request = actionRequest;
1508 } else if (user3.equals(actionRequest.getPrincipalId())) {
1509 user3Request = actionRequest;
1510 } else if (testuser1.equals(actionRequest.getPrincipalId())) {
1511 testuser1Request = actionRequest;
1512 }
1513 }
1514 }
1515
1516 assertNotNull(user1Request);
1517 assertEquals(ActionRequestStatus.ACTIVATED, user1Request.getStatus());
1518 assertNotNull(user2Request);
1519 assertEquals(ActionRequestStatus.ACTIVATED, user2Request.getStatus());
1520 assertNotNull(user3Request);
1521 assertEquals(ActionRequestStatus.INITIALIZED, user3Request.getStatus());
1522 assertNotNull(testuser1Request);
1523 assertEquals(ActionRequestStatus.INITIALIZED, testuser1Request.getStatus());
1524
1525
1526 assertEquals(1, user2Request.getChildRequests().size());
1527 ActionRequest testuser2DelegateRequest = user2Request.getChildRequests().get(0);
1528 assertEquals(testuser2, testuser2DelegateRequest.getPrincipalId());
1529 assertEquals(DelegationType.PRIMARY, testuser2DelegateRequest.getDelegationType());
1530 assertEquals(ActionRequestStatus.ACTIVATED, testuser2DelegateRequest.getStatus());
1531
1532
1533 assertEquals(2, testuser1Request.getChildRequests().size());
1534 ActionRequest testWorkgroupRequest = null;
1535 ActionRequest testuser3Request = null;
1536 for (ActionRequest childActionRequest : testuser1Request.getChildRequests()) {
1537 RecipientType recipientType = childActionRequest.getRecipientType();
1538 if (recipientType == RecipientType.PRINCIPAL) {
1539 if (testuser3.equals(childActionRequest.getPrincipalId())) {
1540 testuser3Request = childActionRequest;
1541 }
1542 } else if (recipientType == RecipientType.GROUP) {
1543 if (testWorkgroup.equals(childActionRequest.getGroupId())) {
1544 testWorkgroupRequest = childActionRequest;
1545 }
1546 }
1547 }
1548 assertNotNull(testWorkgroupRequest);
1549 assertEquals(ActionRequestStatus.INITIALIZED, testWorkgroupRequest.getStatus());
1550 assertEquals(DelegationType.SECONDARY, testWorkgroupRequest.getDelegationType());
1551 assertNotNull(testuser3Request);
1552 assertEquals(ActionRequestStatus.INITIALIZED, testuser3Request.getStatus());
1553 assertEquals(DelegationType.PRIMARY, testuser3Request.getDelegationType());
1554
1555
1556 assertApproveRequested(document, user1, user2, testuser2);
1557 assertApproveNotRequested(document, testuser1, user3, ewestfal, testuser3);
1558
1559 document.switchPrincipal(testuser2);
1560 document.approve("");
1561
1562
1563 assertApproveRequested(document, user1);
1564 assertApproveNotRequested(document, user2, testuser2, testuser1, user3, ewestfal, testuser3);
1565 document.switchPrincipal(user1);
1566 document.approve("");
1567
1568
1569 assertApproveRequested(document, testuser1, user3, ewestfal, testuser3);
1570 assertApproveNotRequested(document, user1, user2, testuser2);
1571
1572 document.switchPrincipal(ewestfal);
1573 document.approve("");
1574
1575
1576 assertApproveRequested(document, user3);
1577 assertApproveNotRequested(document, user1, user2, testuser2, testuser1, ewestfal, testuser3);
1578 document.switchPrincipal(user3);
1579 document.approve("");
1580
1581
1582 assertTrue(document.isFinal());
1583
1584 }
1585
1586 private String roleId = null;
1587
1588
1589
1590 private void createFirstApproveRolePeopleFlow() {
1591 RoleService roleService = KimApiServiceLocator.getRoleService();
1592 Role role = roleService.getRoleByNamespaceCodeAndName("KR-SYS", "Technical Administrator");
1593 assertNotNull("Technical Administrator role should exist!", role);
1594 assertEquals(2, roleService.getRoleMembers(Collections.singletonList(role.getId()),
1595 new HashMap<String, String>()).size());
1596 roleId = role.getId();
1597
1598 PeopleFlowDefinition.Builder peopleFlow = PeopleFlowDefinition.Builder.create(NAMESPACE_CODE, PEOPLE_FLOW_2);
1599 PeopleFlowMember.Builder memberBuilder = peopleFlow.addRole(role.getId());
1600 memberBuilder.setPriority(1);
1601 memberBuilder.setActionRequestPolicy(ActionRequestPolicy.FIRST);
1602 peopleFlowService.createPeopleFlow(peopleFlow.build());
1603 }
1604
1605 @Test
1606 public void test_FirstApproveRolePeopleFlow() throws Exception {
1607 createFirstApproveRolePeopleFlow();
1608
1609 WorkflowDocument document = WorkflowDocumentFactory.createDocument(user3, SINGLE_PEOPLE_FLOW_PRIORITY_PARALLEL_APPROVE);
1610 document.route("");
1611 assertTrue("Document should be enroute.", document.isEnroute());
1612
1613
1614
1615 List<ActionRequest> rootActionRequests = document.getRootActionRequests();
1616 assertEquals(1, rootActionRequests.size());
1617 ActionRequest roleRequest = rootActionRequests.get(0);
1618 assertEquals(ActionRequestPolicy.FIRST, roleRequest.getRequestPolicy());
1619 assertEquals(roleId, roleRequest.getRoleName());
1620 assertEquals(RecipientType.ROLE, roleRequest.getRecipientType());
1621 assertEquals(2, roleRequest.getChildRequests().size());
1622 for (ActionRequest childRequest : roleRequest.getChildRequests()) {
1623 if (RecipientType.PRINCIPAL.equals(childRequest.getRecipientType())) {
1624 assertEquals(getPrincipalIdForName("admin"), childRequest.getPrincipalId());
1625 } else if (RecipientType.GROUP.equals(childRequest.getRecipientType())) {
1626 assertEquals(getGroupIdForName("KR-WKFLW", "WorkflowAdmin"), childRequest.getGroupId());
1627 } else {
1628 fail("Found a child request i didn't expect with a recipient type of: " + childRequest.getRecipientType());
1629 }
1630 }
1631
1632
1633
1634 document.switchPrincipal(getPrincipalNameForId("admin"));
1635 assertTrue(document.isApprovalRequested());
1636 document.switchPrincipal(getPrincipalIdForName("bmcgough"));
1637 assertTrue(document.isApprovalRequested());
1638
1639
1640 document.approve("");
1641
1642
1643 assertTrue(document.isFinal());
1644
1645
1646 document = WorkflowDocumentFactory.createDocument(user3, SINGLE_PEOPLE_FLOW_PRIORITY_PARALLEL_APPROVE);
1647 document.route("");
1648 assertTrue("Document should be enroute.", document.isEnroute());
1649 document.switchPrincipal(getPrincipalIdForName("bmcgough"));
1650 assertTrue(document.isApprovalRequested());
1651 document.switchPrincipal(getPrincipalNameForId("admin"));
1652 assertTrue(document.isApprovalRequested());
1653
1654 document.approve("");
1655
1656 assertTrue(document.isFinal());
1657 }
1658
1659
1660
1661
1662 private void createAllApproveRolePeopleFlow() {
1663 RoleService roleService = KimApiServiceLocator.getRoleService();
1664 Role role = roleService.getRoleByNamespaceCodeAndName("KR-SYS", "Technical Administrator");
1665 assertNotNull("Technical Administrator role should exist!", role);
1666 assertEquals(2, roleService.getRoleMembers(Collections.singletonList(role.getId()),
1667 new HashMap<String, String>()).size());
1668 roleId = role.getId();
1669
1670 PeopleFlowDefinition.Builder peopleFlow = PeopleFlowDefinition.Builder.create(NAMESPACE_CODE, PEOPLE_FLOW_2);
1671 PeopleFlowMember.Builder memberBuilder = peopleFlow.addRole(role.getId());
1672 memberBuilder.setPriority(1);
1673 memberBuilder.setActionRequestPolicy(ActionRequestPolicy.ALL);
1674 peopleFlowService.createPeopleFlow(peopleFlow.build());
1675 }
1676
1677 @Test
1678 public void test_AllApproveRolePeopleFlow() throws Exception {
1679 createAllApproveRolePeopleFlow();
1680
1681 WorkflowDocument document = WorkflowDocumentFactory.createDocument(user3, SINGLE_PEOPLE_FLOW_PRIORITY_PARALLEL_APPROVE);
1682 document.route("");
1683 assertTrue("Document should be enroute.", document.isEnroute());
1684
1685
1686
1687 List<ActionRequest> rootActionRequests = document.getRootActionRequests();
1688 assertEquals(1, rootActionRequests.size());
1689 ActionRequest roleRequest = rootActionRequests.get(0);
1690 assertEquals(ActionRequestPolicy.ALL, roleRequest.getRequestPolicy());
1691 assertEquals(roleId, roleRequest.getRoleName());
1692 assertEquals(RecipientType.ROLE, roleRequest.getRecipientType());
1693 assertEquals(2, roleRequest.getChildRequests().size());
1694 for (ActionRequest childRequest : roleRequest.getChildRequests()) {
1695 if (RecipientType.PRINCIPAL.equals(childRequest.getRecipientType())) {
1696 assertEquals(getPrincipalIdForName("admin"), childRequest.getPrincipalId());
1697 } else if (RecipientType.GROUP.equals(childRequest.getRecipientType())) {
1698 assertEquals(getGroupIdForName("KR-WKFLW", "WorkflowAdmin"), childRequest.getGroupId());
1699 } else {
1700 fail("Found a child request i didn't expect with a recipient type of: " + childRequest.getRecipientType());
1701 }
1702 }
1703
1704
1705
1706 document.switchPrincipal(getPrincipalNameForId("admin"));
1707 assertTrue(document.isApprovalRequested());
1708 document.switchPrincipal(getPrincipalIdForName("bmcgough"));
1709 assertTrue(document.isApprovalRequested());
1710
1711
1712 document.approve("");
1713
1714
1715 assertTrue(document.isEnroute());
1716 assertFalse(document.isApprovalRequested());
1717
1718 document.switchPrincipal(getPrincipalNameForId("admin"));
1719 assertTrue(document.isApprovalRequested());
1720 document.approve("");
1721
1722 assertTrue(document.isFinal());
1723 }
1724
1725 private void assertApproveRequested(WorkflowDocument document, String... principalIds) {
1726 for (String principalId : principalIds) {
1727 document.switchPrincipal(principalId);
1728 assertTrue("Approve should have been requested for '" + principalId + "'", document.isApprovalRequested());
1729 }
1730 }
1731
1732 private void assertAcknowledgeRequested(WorkflowDocument document, String... principalIds) {
1733 for (String principalId : principalIds) {
1734 document.switchPrincipal(principalId);
1735 assertTrue("Acknowledge should have been requested for '" + principalId + "'", document.isAcknowledgeRequested());
1736 }
1737 }
1738
1739 private void assertApproveNotRequested(WorkflowDocument document, String... principalIds) {
1740 for (String principalId : principalIds) {
1741 document.switchPrincipal(principalId);
1742 assertFalse("Approve should *NOT* have been requested for '" + principalId + "'", document.isApprovalRequested());
1743 }
1744 }
1745
1746 }