-
Notifications
You must be signed in to change notification settings - Fork 188
/
TestStrings.java
1360 lines (1136 loc) · 67.9 KB
/
TestStrings.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
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
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2010-2017 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.evolveum.midpoint.testing.story;
import com.evolveum.midpoint.audit.api.AuditEventRecord;
import com.evolveum.midpoint.audit.api.AuditEventStage;
import com.evolveum.midpoint.audit.api.AuditEventType;
import com.evolveum.midpoint.model.api.WorkflowService;
import com.evolveum.midpoint.model.test.DummyTransport;
import com.evolveum.midpoint.notifications.api.transports.Message;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.PrismReference;
import com.evolveum.midpoint.prism.PrismReferenceValue;
import com.evolveum.midpoint.prism.delta.ItemDelta;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.prism.delta.builder.DeltaBuilder;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.util.PrismAsserts;
import com.evolveum.midpoint.prism.util.PrismUtil;
import com.evolveum.midpoint.prism.xml.XmlTypeConverter;
import com.evolveum.midpoint.schema.ObjectDeltaOperation;
import com.evolveum.midpoint.schema.SearchResultList;
import com.evolveum.midpoint.schema.constants.ObjectTypes;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.ObjectTypeUtil;
import com.evolveum.midpoint.schema.util.WfContextUtil;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.test.util.TestUtil;
import com.evolveum.midpoint.util.DebugUtil;
import com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException;
import com.evolveum.midpoint.util.exception.ObjectNotFoundException;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.wf.api.WorkflowConstants;
import com.evolveum.midpoint.wf.util.ApprovalUtils;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import org.apache.commons.collections4.multimap.ArrayListValuedHashMap;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.context.ContextConfiguration;
import org.testng.annotations.Test;
import javax.xml.namespace.QName;
import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;
import static com.evolveum.midpoint.prism.util.PrismAsserts.assertReferenceValues;
import static com.evolveum.midpoint.test.IntegrationTestTools.display;
import static org.testng.AssertJUnit.*;
/**
*
* @author mederly
*
*/
@SuppressWarnings("FieldCanBeLocal")
@ContextConfiguration(locations = {"classpath:ctx-story-test-main.xml"})
@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
public class TestStrings extends AbstractStoryTest {
@Autowired private WorkflowService workflowService;
@Autowired private DummyTransport dummyTransport;
private static final String TEST_DIR = "src/test/resources/strings";
private static final String ORG_DIR = TEST_DIR + "/orgs";
private static final String ROLES_DIR = TEST_DIR + "/roles";
private static final String ROLES_SPECIFIC_DIR = TEST_DIR + "/roles-specific";
private static final String USERS_DIR = TEST_DIR + "/users";
private static final File ORG_MONKEY_ISLAND_FILE = new File(ORG_DIR, "0-org-monkey-island-modified.xml");
private static final File ORG_TEAMS_FILE = new File(ORG_DIR, "1-teams.xml");
private static String orgTeamsOid;
private static final File ORG_ROLE_CATALOG_FILE = new File(ORG_DIR, "2-role-catalog.xml");
private static String orgRoleCatalogOid;
private static final File ORG_SECURITY_APPROVERS_FILE = new File(ORG_DIR, "security-approvers.xml");
private static String orgSecurityApproversOid;
private static final File ORG_SOD_APPROVERS_FILE = new File(ORG_DIR, "sod-approvers.xml");
private static String orgSodApproversOid;
private static final File ROLE_END_USER_FILE = new File(ROLES_DIR, "role-end-user.xml");
private static String roleEndUserOid;
private static final File FORM_USER_DETAILS_FILE = new File(ROLES_DIR, "form-user-details.xml");
private static String formUserDetailsOid;
private static final File METAROLE_APPROVAL_ROLE_APPROVERS_FIRST_FILE = new File(ROLES_DIR, "metarole-approval-role-approvers-first.xml");
private static String metaroleApprovalRoleApproversFirstOid;
private static final File METAROLE_APPROVAL_ROLE_APPROVERS_FORM_FILE = new File(ROLES_DIR, "metarole-approval-role-approvers-form.xml");
private static String metaroleApprovalRoleApproversFormOid;
private static final File METAROLE_APPROVAL_SECURITY_FILE = new File(ROLES_DIR, "metarole-approval-security.xml");
private static String metaroleApprovalSecurityOid;
private static final File ROLE_A_TEST_1 = new File(ROLES_SPECIFIC_DIR, "a-test-1.xml");
private static String roleATest1Oid;
private static final File ROLE_A_TEST_2A = new File(ROLES_SPECIFIC_DIR, "a-test-2a.xml");
private static String roleATest2aOid;
private static final File ROLE_A_TEST_2B = new File(ROLES_SPECIFIC_DIR, "a-test-2b.xml");
private static String roleATest2bOid;
private static final File ROLE_A_TEST_3A = new File(ROLES_SPECIFIC_DIR, "a-test-3a.xml");
private static String roleATest3aOid;
private static final File ROLE_A_TEST_3B = new File(ROLES_SPECIFIC_DIR, "a-test-3b.xml");
private static String roleATest3bOid;
private static final File ROLE_A_TEST_3X = new File(ROLES_SPECIFIC_DIR, "a-test-3x.xml");
private static String roleATest3xOid;
private static final File ROLE_A_TEST_3Y = new File(ROLES_SPECIFIC_DIR, "a-test-3y.xml");
private static String roleATest3yOid;
private static final File ROLE_A_TEST_4 = new File(ROLES_SPECIFIC_DIR, "a-test-4.xml");
private static String roleATest4Oid;
private static final File USER_BARKEEPER_FILE = new File(USERS_DIR, "barkeeper.xml");
private static String userBarkeeperOid;
private static final File USER_BOB_FILE = new File(USERS_DIR, "bob.xml");
private static String userBobOid;
private static final File USER_CARLA_FILE = new File(USERS_DIR, "carla.xml");
private static String userCarlaOid;
private static final File USER_CHEESE_FILE = new File(USERS_DIR, "cheese.xml");
private static String userCheeseOid;
private static final File USER_CHEF_FILE = new File(USERS_DIR, "chef.xml");
private static String userChefOid;
private static final File USER_ELAINE_FILE = new File(USERS_DIR, "elaine.xml");
private static String userElaineOid;
private static final File USER_GUYBRUSH_FILE = new File(USERS_DIR, "guybrush.xml");
private static String userGuybrushOid;
private static final File USER_LECHUCK_FILE = new File(USERS_DIR, "lechuck.xml");
private static String userLechuckOid;
private static final File USER_LECHUCK_DEPUTY_FILE = new File(USERS_DIR, "lechuck-deputy.xml");
private static String userLechuckDeputyOid;
private static final File USER_LECHUCK_DEPUTY_DEPUTY_FILE = new File(USERS_DIR, "lechuck-deputy-deputy.xml");
private static String userLechuckDeputyDeputyOid;
private static final File USER_LECHUCK_DEPUTY_LIMITED_FILE = new File(USERS_DIR, "lechuck-deputy-limited.xml");
private static String userLechuckDeputyLimitedOid;
private static final File CONFIG_WITH_GLOBAL_RULES_FILE = new File(ROLES_DIR, "global-policy-rules.xml");
public static final String NS_STRINGS_EXT = "http://midpoint.evolveum.com/xml/ns/strings";
private static final String DUMMY_WORK_ITEM_LIFECYCLE = "dummy:workItemLifecycle";
private static final String DUMMY_WORK_ITEM_ALLOCATION = "dummy:workItemAllocation";
private static final String DUMMY_WORK_ITEM_CUSTOM = "dummy:workItemCustom";
private static final String DUMMY_PROCESS = "dummy:process";
protected static final int TASK_WAIT_TIMEOUT = 40000;
@Override
public void initSystem(Task initTask, OperationResult initResult) throws Exception {
super.initSystem(initTask, initResult);
transplantGlobalPolicyRulesAdd(CONFIG_WITH_GLOBAL_RULES_FILE, initTask, initResult);
// we prefer running trigger scanner by hand
resetTriggerTask(TASK_TRIGGER_SCANNER_OID, TASK_TRIGGER_SCANNER_FILE, initResult);
// and we don't need validity scanner
taskManager.suspendAndDeleteTasks(Collections.singletonList(TASK_VALIDITY_SCANNER_OID), 60000L, true, initResult);
Task triggerScanner = taskManager.getTask(TASK_TRIGGER_SCANNER_OID, initResult);
display("triggerScanner", triggerScanner);
// import of story objects
repoAddObjectsFromFile(ORG_MONKEY_ISLAND_FILE, OrgType.class, initResult);
orgTeamsOid = repoAddObjectFromFile(ORG_TEAMS_FILE, initResult).getOid();
orgRoleCatalogOid = repoAddObjectFromFile(ORG_ROLE_CATALOG_FILE, initResult).getOid();
orgSecurityApproversOid = repoAddObjectFromFile(ORG_SECURITY_APPROVERS_FILE, initResult).getOid();
orgSodApproversOid = repoAddObjectFromFile(ORG_SOD_APPROVERS_FILE, initResult).getOid();
roleEndUserOid = repoAddObjectFromFile(ROLE_END_USER_FILE, initResult).getOid();
formUserDetailsOid = repoAddObjectFromFile(FORM_USER_DETAILS_FILE, initResult).getOid();
metaroleApprovalRoleApproversFirstOid = repoAddObjectFromFile(METAROLE_APPROVAL_ROLE_APPROVERS_FIRST_FILE, initResult).getOid();
metaroleApprovalRoleApproversFormOid = repoAddObjectFromFile(METAROLE_APPROVAL_ROLE_APPROVERS_FORM_FILE, initResult).getOid();
metaroleApprovalSecurityOid = repoAddObjectFromFile(METAROLE_APPROVAL_SECURITY_FILE, initResult).getOid();
roleATest1Oid = addAndRecompute(ROLE_A_TEST_1, initTask, initResult);
roleATest2aOid = addAndRecompute(ROLE_A_TEST_2A, initTask, initResult);
roleATest2bOid = addAndRecompute(ROLE_A_TEST_2B, initTask, initResult);
roleATest3aOid = addAndRecompute(ROLE_A_TEST_3A, initTask, initResult);
roleATest3bOid = addAndRecompute(ROLE_A_TEST_3B, initTask, initResult);
roleATest3xOid = addAndRecompute(ROLE_A_TEST_3X, initTask, initResult);
roleATest3yOid = addAndRecompute(ROLE_A_TEST_3Y, initTask, initResult);
roleATest4Oid = addAndRecompute(ROLE_A_TEST_4, initTask, initResult);
userBarkeeperOid = addAndRecomputeUser(USER_BARKEEPER_FILE, initTask, initResult);
userBobOid = addAndRecomputeUser(USER_BOB_FILE, initTask, initResult);
userCarlaOid = addAndRecomputeUser(USER_CARLA_FILE, initTask, initResult);
userCheeseOid = addAndRecomputeUser(USER_CHEESE_FILE, initTask, initResult);
userChefOid = addAndRecomputeUser(USER_CHEF_FILE, initTask, initResult);
userElaineOid = addAndRecomputeUser(USER_ELAINE_FILE, initTask, initResult);
userGuybrushOid = addAndRecomputeUser(USER_GUYBRUSH_FILE, initTask, initResult);
userLechuckOid = addAndRecomputeUser(USER_LECHUCK_FILE, initTask, initResult);
userLechuckDeputyOid = addAndRecomputeUser(USER_LECHUCK_DEPUTY_FILE, initTask, initResult);
userLechuckDeputyDeputyOid = addAndRecomputeUser(USER_LECHUCK_DEPUTY_DEPUTY_FILE, initTask, initResult);
userLechuckDeputyLimitedOid = addAndRecomputeUser(USER_LECHUCK_DEPUTY_LIMITED_FILE, initTask, initResult);
DebugUtil.setPrettyPrintBeansAs(PrismContext.LANG_YAML);
}
@Override
protected PrismObject<UserType> getDefaultActor() {
return userAdministrator;
}
@Test
public void test000Sanity() throws Exception {
final String TEST_NAME = "test000Sanity";
TestUtil.displayTestTitle(this, TEST_NAME);
Task task = createTask(TestStrings.class.getName() + "." + TEST_NAME);
// TODO
}
//region Basic approval
@Test
public void test100SimpleAssignmentStart() throws Exception {
final String TEST_NAME = "test100SimpleAssignmentStart";
TestUtil.displayTestTitle(this, TEST_NAME);
Task task = createTask(TestStrings.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
dummyAuditService.clear();
dummyTransport.clearMessages();
// WHEN
assignRole(userBobOid, roleATest1Oid, task, task.getResult());
// THEN
assertNotAssignedRole(getUser(userBobOid), roleATest1Oid);
WorkItemType workItem = getWorkItem(task, result);
display("Work item", workItem);
PrismObject<TaskType> wfTask = getTask(WfContextUtil.getTask(workItem).getOid());
display("wfTask", wfTask);
assertTriggers(wfTask, 2);
ItemApprovalProcessStateType info = WfContextUtil.getItemApprovalProcessInfo(wfTask.asObjectable().getWorkflowContext());
ApprovalSchemaType schema = info.getApprovalSchema();
assertEquals("Wrong # of approval levels", 3, schema.getStage().size());
assertApprovalLevel(schema, 1, "Line managers", "P5D", 2);
assertApprovalLevel(schema, 2, "Security", "P7D", 1);
assertApprovalLevel(schema, 3, "Role approvers (all)", "P5D", 2);
assertStage(wfTask, 1, 3, "Line managers", null);
assertAssignee(workItem, userLechuckOid, userLechuckOid);
List<Message> lifecycleMessages = dummyTransport.getMessages(DUMMY_WORK_ITEM_LIFECYCLE);
List<Message> allocationMessages = dummyTransport.getMessages(DUMMY_WORK_ITEM_ALLOCATION);
List<Message> processMessages = dummyTransport.getMessages(DUMMY_PROCESS);
display("work items lifecycle notifications", lifecycleMessages);
display("work items allocation notifications", allocationMessages);
display("processes notifications", processMessages);
assertEquals("Wrong # of work items lifecycle messages", 3, lifecycleMessages.size());
Map<String,Message> sorted = sortByRecipientsSingle(lifecycleMessages);
assertMessage(sorted.get("lechuck@evolveum.com"), "lechuck@evolveum.com", "A new work item has been created",
"Stage: Line managers (1/3)", "Allocated to: Captain LeChuck (lechuck)", "(in 5 days)");
assertMessage(sorted.get("lechuck-deputy@evolveum.com"), "lechuck-deputy@evolveum.com", "A new work item has been created",
"Stage: Line managers (1/3)", "Allocated to: Captain LeChuck (lechuck)", "(in 5 days)");
assertMessage(sorted.get("lechuck-deputy-deputy@evolveum.com"), "lechuck-deputy-deputy@evolveum.com", "A new work item has been created",
"Stage: Line managers (1/3)", "Allocated to: Captain LeChuck (lechuck)", "(in 5 days)");
assertEquals("Wrong # of work items allocation messages", 3, allocationMessages.size());
Map<String,Message> sorted2 = sortByRecipientsSingle(allocationMessages);
assertMessage(sorted2.get("lechuck@evolveum.com"), "lechuck@evolveum.com", "Work item has been allocated to you",
"Stage: Line managers (1/3)", "Allocated to: Captain LeChuck (lechuck)", "(in 5 days)");
assertMessage(sorted2.get("lechuck-deputy@evolveum.com"), "lechuck-deputy@evolveum.com", "Work item has been allocated to you",
"Stage: Line managers (1/3)", "Allocated to: Captain LeChuck (lechuck)", "(in 5 days)");
assertMessage(sorted2.get("lechuck-deputy-deputy@evolveum.com"), "lechuck-deputy-deputy@evolveum.com", "Work item has been allocated to you",
"Stage: Line managers (1/3)", "Allocated to: Captain LeChuck (lechuck)", "(in 5 days)");
assertEquals("Wrong # of process messages", 1, processMessages.size());
assertMessage(processMessages.get(0), "administrator@evolveum.com", "Workflow process instance has been started",
"Process instance name: Assigning a-test-1 to bob", "Stage: Line managers (1/3)");
display("audit", dummyAuditService);
}
@Test
public void test102SimpleAssignmentApproveByLechuck() throws Exception {
final String TEST_NAME = "test102SimpleAssignmentApproveByLechuck";
TestUtil.displayTestTitle(this, TEST_NAME);
Task task = createTask(TestStrings.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
dummyAuditService.clear();
dummyTransport.clearMessages();
// GIVEN
login(userAdministrator);
WorkItemType workItem = getWorkItem(task, result);
// WHEN
PrismObject<UserType> lechuck = getUserFromRepo(userLechuckOid);
login(lechuck);
workflowService.completeWorkItem(workItem.getExternalId(), true, "OK. LeChuck", null, result);
// THEN
login(userAdministrator);
List<WorkItemType> workItems = getWorkItems(task, result);
displayWorkItems("Work item after 1st approval", workItems);
assertEquals("Wrong # of work items on level 2", 2, workItems.size());
PrismObject<TaskType> wfTask = getTask(WfContextUtil.getTask(workItem).getOid());
display("wfTask after 1st approval", wfTask);
assertStage(wfTask, 2, 3, "Security", null);
assertTriggers(wfTask, 4);
// notifications
List<Message> lifecycleMessages = dummyTransport.getMessages(DUMMY_WORK_ITEM_LIFECYCLE);
List<Message> allocationMessages = dummyTransport.getMessages(DUMMY_WORK_ITEM_ALLOCATION);
List<Message> processMessages = dummyTransport.getMessages(DUMMY_PROCESS);
display("work items lifecycle notifications", lifecycleMessages);
display("work items allocation notifications", allocationMessages);
display("processes notifications", processMessages);
dummyTransport.clearMessages();
assertEquals("Wrong # of work items lifecycle messages", 5, lifecycleMessages.size());
assertEquals("Wrong # of work items allocation messages", 5, allocationMessages.size());
assertNull("process messages", processMessages);
Map<String,Message> sorted = sortByRecipientsSingle(lifecycleMessages);
assertMessage(sorted.get("lechuck@evolveum.com"), "lechuck@evolveum.com", "Work item has been completed",
"Work item: Approve assigning a-test-1 to bob", "Stage: Line managers (1/3)",
"Allocated to: Captain LeChuck (lechuck)", "Result: APPROVED", "^Deadline:");
assertMessage(sorted.get("lechuck-deputy@evolveum.com"), "lechuck-deputy@evolveum.com", "Work item has been completed",
"Work item: Approve assigning a-test-1 to bob", "Stage: Line managers (1/3)",
"Allocated to: Captain LeChuck (lechuck)", "Result: APPROVED", "^Deadline:");
assertMessage(sorted.get("lechuck-deputy-deputy@evolveum.com"), "lechuck-deputy-deputy@evolveum.com", "Work item has been completed",
"Work item: Approve assigning a-test-1 to bob", "Stage: Line managers (1/3)",
"Allocated to: Captain LeChuck (lechuck)", "Result: APPROVED", "^Deadline:");
assertMessage(sorted.get("elaine@evolveum.com"), "elaine@evolveum.com", "A new work item has been created",
"Work item: Approve assigning a-test-1 to bob", "Stage: Security (2/3)",
"Allocated to: Elaine Marley (elaine)", "(in 7 days)", "^Result:");
assertMessage(sorted.get("barkeeper@evolveum.com"), "barkeeper@evolveum.com", "A new work item has been created",
"Work item: Approve assigning a-test-1 to bob", "Stage: Security (2/3)",
"Allocated to: Horridly Scarred Barkeep (barkeeper)", "(in 7 days)", "^Result:");
Map<String,Message> sorted2 = sortByRecipientsSingle(allocationMessages);
assertMessage(sorted2.get("lechuck@evolveum.com"), "lechuck@evolveum.com", "Work item has been completed",
"Work item: Approve assigning a-test-1 to bob", "Stage: Line managers (1/3)",
"Allocated to: Captain LeChuck (lechuck)", "Result: APPROVED", "^Deadline:");
assertMessage(sorted2.get("lechuck-deputy@evolveum.com"), "lechuck-deputy@evolveum.com", "Work item has been completed",
"Work item: Approve assigning a-test-1 to bob", "Stage: Line managers (1/3)",
"Allocated to: Captain LeChuck (lechuck)", "Result: APPROVED", "^Deadline:");
assertMessage(sorted2.get("lechuck-deputy-deputy@evolveum.com"), "lechuck-deputy-deputy@evolveum.com", "Work item has been completed",
"Work item: Approve assigning a-test-1 to bob", "Stage: Line managers (1/3)",
"Allocated to: Captain LeChuck (lechuck)", "Result: APPROVED", "^Deadline:");
assertMessage(sorted2.get("elaine@evolveum.com"), "elaine@evolveum.com", "Work item has been allocated to you",
"Work item: Approve assigning a-test-1 to bob", "Stage: Security (2/3)", "Allocated to: Elaine Marley (elaine)",
"(in 7 days)", "^Result:");
assertMessage(sorted2.get("barkeeper@evolveum.com"), "barkeeper@evolveum.com", "Work item has been allocated to you",
"Work item: Approve assigning a-test-1 to bob", "Stage: Security (2/3)",
"Allocated to: Horridly Scarred Barkeep (barkeeper)", "(in 7 days)", "^Result:");
// events
List<CaseEventType> events = assertEvents(wfTask, 2);
assertCompletionEvent(events.get(1), userLechuckOid, userLechuckOid, 1, "Line managers", WorkItemOutcomeType.APPROVE, "OK. LeChuck");
display("audit", dummyAuditService);
}
@Test
public void test104SimpleAssignmentApproveByAdministrator() throws Exception {
final String TEST_NAME = "test104SimpleAssignmentApproveByAdministrator";
TestUtil.displayTestTitle(this, TEST_NAME);
Task task = createTask(TestStrings.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
dummyAuditService.clear();
dummyTransport.clearMessages();
// GIVEN
login(userAdministrator);
List<WorkItemType> workItems = getWorkItems(task, result);
displayWorkItems("Work item after 1st approval", workItems);
WorkItemType elaineWorkItem = workItems.stream()
.filter(wi -> userElaineOid.equals(wi.getOriginalAssigneeRef().getOid()))
.findFirst().orElseThrow(() -> new AssertionError("No work item for elaine"));
// WHEN
// Second approval
workflowService.completeWorkItem(elaineWorkItem.getExternalId(), true, "OK. Security.", null, result);
// THEN
workItems = getWorkItems(task, result);
displayWorkItems("Work item after 2nd approval", workItems);
assertEquals("Wrong # of work items on level 3", 2, workItems.size());
PrismObject<TaskType> wfTask = getTask(WfContextUtil.getTask(workItems.get(0)).getOid());
display("wfTask after 2nd approval", wfTask);
assertStage(wfTask, 3, 3, "Role approvers (all)", null);
assertTriggers(wfTask, 4);
Map<String, WorkItemType> workItemsMap = sortByOriginalAssignee(workItems);
assertNotNull("chef is not an approver", workItemsMap.get(userChefOid));
assertNotNull("cheese is not an approver", workItemsMap.get(userCheeseOid));
List<Message> lifecycleMessages = dummyTransport.getMessages(DUMMY_WORK_ITEM_LIFECYCLE);
List<Message> allocationMessages = dummyTransport.getMessages(DUMMY_WORK_ITEM_ALLOCATION);
List<Message> processMessages = dummyTransport.getMessages(DUMMY_PROCESS);
display("work items lifecycle notifications", lifecycleMessages);
display("work items allocation notifications", allocationMessages);
display("processes notifications", processMessages);
dummyTransport.clearMessages();
assertEquals("Wrong # of work items lifecycle messages", 4, lifecycleMessages.size());
assertEquals("Wrong # of work items allocation messages", 4, allocationMessages.size());
assertNull("process messages", processMessages);
Map<String,Message> sorted = sortByRecipientsSingle(lifecycleMessages);
assertMessage(sorted.get("elaine@evolveum.com"), "elaine@evolveum.com", "Work item has been completed",
"Work item: Approve assigning a-test-1 to bob", "Stage: Security (2/3)", "Allocated to: Elaine Marley (elaine)",
"Carried out by: midPoint Administrator (administrator)", "Result: APPROVED", "^Deadline:");
assertMessage(sorted.get("barkeeper@evolveum.com"), "barkeeper@evolveum.com", "Work item has been cancelled",
"Work item: Approve assigning a-test-1 to bob", "Stage: Security (2/3)",
"Allocated to: Horridly Scarred Barkeep (barkeeper)", "^Result:", "^Deadline:", "^Carried out by:");
assertMessage(sorted.get("cheese@evolveum.com"), "cheese@evolveum.com", "A new work item has been created",
"Work item: Approve assigning a-test-1 to bob", "Role approvers (all) (3/3)",
"Allocated to: Ignatius Cheese (cheese)", "^Result:", "(in 5 days)");
assertMessage(sorted.get("chef@evolveum.com"), "chef@evolveum.com", "A new work item has been created",
"Work item: Approve assigning a-test-1 to bob", "Role approvers (all) (3/3)",
"Allocated to: Scumm Bar Chef (chef)", "^Result:", "(in 5 days)");
Map<String,Message> sorted2 = sortByRecipientsSingle(allocationMessages);
assertMessage(sorted2.get("elaine@evolveum.com"), "elaine@evolveum.com", "Work item has been completed",
"Work item: Approve assigning a-test-1 to bob", "Stage: Security (2/3)", "Allocated to: Elaine Marley (elaine)",
"Carried out by: midPoint Administrator (administrator)", "Result: APPROVED", "^Deadline:");
assertMessage(sorted2.get("barkeeper@evolveum.com"), "barkeeper@evolveum.com", "Work item has been cancelled",
"Work item: Approve assigning a-test-1 to bob", "Stage: Security (2/3)",
"Allocated to: Horridly Scarred Barkeep (barkeeper)", "^Result:", "^Deadline:", "^Carried out by:");
assertMessage(sorted2.get("cheese@evolveum.com"), "cheese@evolveum.com", "Work item has been allocated to you",
"Work item: Approve assigning a-test-1 to bob", "Role approvers (all) (3/3)",
"Allocated to: Ignatius Cheese (cheese)", "^Result:", "(in 5 days)");
assertMessage(sorted2.get("chef@evolveum.com"), "chef@evolveum.com", "Work item has been allocated to you",
"Work item: Approve assigning a-test-1 to bob", "Role approvers (all) (3/3)",
"Allocated to: Scumm Bar Chef (chef)", "^Result:", "(in 5 days)");
display("audit", dummyAuditService);
}
@Test
public void test106SimpleAssignmentApproveByCheese() throws Exception {
final String TEST_NAME = "test106SimpleAssignmentApproveByCheese";
TestUtil.displayTestTitle(this, TEST_NAME);
Task task = createTask(TestStrings.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
dummyAuditService.clear();
dummyTransport.clearMessages();
// GIVEN
login(userAdministrator);
List<WorkItemType> workItems = getWorkItems(task, result);
Map<String, WorkItemType> workItemsMap = sortByOriginalAssignee(workItems);
// WHEN
login(getUser(userCheeseOid));
workflowService.completeWorkItem(workItemsMap.get(userCheeseOid).getExternalId(), true, "OK. Cheese.", null, result);
// THEN
login(userAdministrator);
workItems = getWorkItems(task, result);
displayWorkItems("Work item after 3rd approval", workItems);
assertEquals("Wrong # of work items on level 3", 1, workItems.size());
workItemsMap = sortByOriginalAssignee(workItems);
PrismObject<TaskType> wfTask = getTask(WfContextUtil.getTask(workItems.get(0)).getOid());
display("wfTask after 3rd approval", wfTask);
assertStage(wfTask, 3, 3, "Role approvers (all)", null);
assertTriggers(wfTask, 2);
assertNotNull("chef is not an approver", workItemsMap.get(userChefOid));
List<Message> lifecycleMessages = dummyTransport.getMessages(DUMMY_WORK_ITEM_LIFECYCLE);
List<Message> allocationMessages = dummyTransport.getMessages(DUMMY_WORK_ITEM_ALLOCATION);
List<Message> processMessages = dummyTransport.getMessages(DUMMY_PROCESS);
display("work items lifecycle notifications", lifecycleMessages);
display("work items allocation notifications", allocationMessages);
display("processes notifications", processMessages);
dummyTransport.clearMessages();
assertEquals("Wrong # of work items lifecycle messages", 1, lifecycleMessages.size());
assertEquals("Wrong # of work items allocation messages", 1, allocationMessages.size());
assertNull("process messages", processMessages);
assertMessage(lifecycleMessages.get(0), "cheese@evolveum.com", "Work item has been completed",
"Work item: Approve assigning a-test-1 to bob", "Role approvers (all) (3/3)",
"Allocated to: Ignatius Cheese (cheese)", "Carried out by: Ignatius Cheese (cheese)",
"Result: APPROVED", "^Deadline:");
assertMessage(allocationMessages.get(0), "cheese@evolveum.com", "Work item has been completed",
"Work item: Approve assigning a-test-1 to bob", "Role approvers (all) (3/3)",
"Allocated to: Ignatius Cheese (cheese)", "Carried out by: Ignatius Cheese (cheese)",
"Result: APPROVED", "^Deadline:");
display("audit", dummyAuditService);
}
@Test
public void test108SimpleAssignmentApproveByChef() throws Exception {
final String TEST_NAME = "test108SimpleAssignmentApproveByChef";
TestUtil.displayTestTitle(this, TEST_NAME);
Task task = createTask(TestStrings.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
// GIVEN
login(userAdministrator);
List<WorkItemType> workItems = getWorkItems(task, result);
String taskOid = WfContextUtil.getTask(workItems.get(0)).getOid();
Map<String, WorkItemType> workItemsMap = sortByOriginalAssignee(workItems);
// WHEN
login(getUser(userChefOid));
String workItemId = workItemsMap.get(userChefOid).getExternalId();
workflowService.completeWorkItem(workItemId, true, "OK. Chef.", null, result);
// THEN
login(userAdministrator);
workItems = getWorkItems(task, result);
displayWorkItems("Work item after 4th approval", workItems);
assertEquals("Wrong # of work items on level 3", 0, workItems.size());
PrismObject<TaskType> wfTask = getTask(taskOid);
display("wfTask after 4th approval", wfTask);
Task parent = getParentTask(wfTask, result);
waitForTaskFinish(parent, false, 60000);
assertAssignedRole(getUser(userBobOid), roleATest1Oid);
assertTriggers(wfTask, 0);
List<Message> lifecycleMessages = dummyTransport.getMessages(DUMMY_WORK_ITEM_LIFECYCLE);
List<Message> allocationMessages = dummyTransport.getMessages(DUMMY_WORK_ITEM_ALLOCATION);
List<Message> processMessages = dummyTransport.getMessages(DUMMY_PROCESS);
display("work items lifecycle notifications", lifecycleMessages);
display("work items allocation notifications", allocationMessages);
display("processes notifications", processMessages);
dummyTransport.clearMessages();
assertEquals("Wrong # of work items lifecycle messages", 1, lifecycleMessages.size());
assertEquals("Wrong # of work items allocation messages", 1, allocationMessages.size());
assertEquals("Wrong # of process messages", 1, processMessages.size());
assertMessage(lifecycleMessages.get(0), "chef@evolveum.com", "Work item has been completed",
"Work item: Approve assigning a-test-1 to bob", "Role approvers (all) (3/3)",
"Allocated to: Scumm Bar Chef (chef)", "Carried out by: Scumm Bar Chef (chef)",
"Result: APPROVED", "^Deadline:");
assertMessage(allocationMessages.get(0), "chef@evolveum.com", "Work item has been completed",
"Work item: Approve assigning a-test-1 to bob", "Role approvers (all) (3/3)",
"Allocated to: Scumm Bar Chef (chef)", "Carried out by: Scumm Bar Chef (chef)",
"Result: APPROVED", "^Deadline:");
assertMessage(processMessages.get(0), "administrator@evolveum.com", "Workflow process instance has finished",
"Process instance name: Assigning a-test-1 to bob", "Result: APPROVED");
display("audit", dummyAuditService);
List<AuditEventRecord> workItemEvents = filter(getParamAuditRecords(
WorkflowConstants.AUDIT_WORK_ITEM_ID, workItemId, result), AuditEventStage.EXECUTION);
assertAuditReferenceValue(workItemEvents, WorkflowConstants.AUDIT_OBJECT, userBobOid, UserType.COMPLEX_TYPE, "bob");
assertAuditTarget(workItemEvents.get(0), userBobOid, UserType.COMPLEX_TYPE, "bob");
assertAuditReferenceValue(workItemEvents.get(0), WorkflowConstants.AUDIT_TARGET, roleATest1Oid, RoleType.COMPLEX_TYPE, "a-test-1");
// TODO other items
List<AuditEventRecord> processEvents = filter(getParamAuditRecords(
WorkflowConstants.AUDIT_PROCESS_INSTANCE_ID, wfTask.asObjectable().getWorkflowContext().getProcessInstanceId(), result),
AuditEventType.WORKFLOW_PROCESS_INSTANCE, AuditEventStage.EXECUTION);
assertAuditReferenceValue(processEvents, WorkflowConstants.AUDIT_OBJECT, userBobOid, UserType.COMPLEX_TYPE, "bob");
assertAuditTarget(processEvents.get(0), userBobOid, UserType.COMPLEX_TYPE, "bob");
assertAuditReferenceValue(processEvents.get(0), WorkflowConstants.AUDIT_TARGET, roleATest1Oid, RoleType.COMPLEX_TYPE, "a-test-1");
// TODO other items
}
//endregion
//region Testing escalation
@Test
public void test200EscalatedApprovalStart() throws Exception {
final String TEST_NAME = "test200EscalatedApprovalStart";
TestUtil.displayTestTitle(this, TEST_NAME);
Task task = createTask(TestStrings.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
dummyAuditService.clear();
dummyTransport.clearMessages();
// WHEN
assignRole(userCarlaOid, roleATest1Oid, task, task.getResult());
// THEN
assertNotAssignedRole(getUser(userCarlaOid), roleATest1Oid);
WorkItemType workItem = getWorkItem(task, result);
display("Work item", workItem);
PrismObject<TaskType> wfTask = getTask(WfContextUtil.getTask(workItem).getOid());
display("wfTask", wfTask);
assertTriggers(wfTask, 2);
assertStage(wfTask, 1, 3, "Line managers", null);
assertAssignee(workItem, userGuybrushOid, userGuybrushOid);
List<Message> lifecycleMessages = dummyTransport.getMessages(DUMMY_WORK_ITEM_LIFECYCLE);
List<Message> allocationMessages = dummyTransport.getMessages(DUMMY_WORK_ITEM_ALLOCATION);
List<Message> processMessages = dummyTransport.getMessages(DUMMY_PROCESS);
display("work items lifecycle notifications", lifecycleMessages);
display("work items allocation notifications", allocationMessages);
display("processes notifications", processMessages);
dummyTransport.clearMessages();
assertEquals("Wrong # of work items messages", 1, lifecycleMessages.size());
assertMessage(lifecycleMessages.get(0), "guybrush@evolveum.com", "A new work item has been created", "Stage: Line managers (1/3)", "Allocated to: Guybrush Threepwood (guybrush)");
assertMessage(allocationMessages.get(0), "guybrush@evolveum.com", "Work item has been allocated to you", "Stage: Line managers (1/3)", "Allocated to: Guybrush Threepwood (guybrush)");
assertEquals("Wrong # of work items allocation messages", 1, allocationMessages.size());
//assertMessage(lifecycleMessages.get(0), "guybrush@evolveum.com", "A new work item has been created", "Stage: Line managers (1/3)", "Guybrush Threepwood (guybrush)");
assertEquals("Wrong # of process messages", 1, processMessages.size());
assertMessage(processMessages.get(0), "administrator@evolveum.com", "Workflow process instance has been started",
"Process instance name: Assigning a-test-1 to carla", "Stage: Line managers (1/3)");
display("audit", dummyAuditService);
}
@Test
public void test202FourDaysLater() throws Exception {
final String TEST_NAME = "test202FourDaysLater";
TestUtil.displayTestTitle(this, TEST_NAME);
Task task = createTask(TestStrings.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
dummyAuditService.clear();
dummyTransport.clearMessages();
// WHEN
clock.overrideDuration("P4D");
waitForTaskNextRun(TASK_TRIGGER_SCANNER_OID, true, 20000, true);
// THEN
List<Message> lifecycleMessages = dummyTransport.getMessages(DUMMY_WORK_ITEM_LIFECYCLE);
List<Message> allocationMessages = dummyTransport.getMessages(DUMMY_WORK_ITEM_ALLOCATION);
List<Message> processMessages = dummyTransport.getMessages(DUMMY_PROCESS);
display("work items lifecycle notifications", lifecycleMessages);
display("work items allocation notifications", allocationMessages);
display("processes notifications", processMessages);
dummyTransport.clearMessages();
assertNull("lifecycle messages", lifecycleMessages);
assertEquals("Wrong # of work items allocation messages", 1, allocationMessages.size());
assertMessage(allocationMessages.get(0), "guybrush@evolveum.com", "Work item will be automatically escalated in 1 day",
"Stage: Line managers (1/3)", "Allocated to (before escalation): Guybrush Threepwood (guybrush)");
assertNull("process messages", processMessages);
display("audit", dummyAuditService);
}
// escalation should occur here
@Test
public void test204SixDaysLater() throws Exception {
final String TEST_NAME = "test204SixDaysLater";
TestUtil.displayTestTitle(this, TEST_NAME);
Task task = createTask(TestStrings.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
dummyAuditService.clear();
dummyTransport.clearMessages();
// WHEN
clock.resetOverride();
clock.overrideDuration("P6D");
waitForTaskNextRun(TASK_TRIGGER_SCANNER_OID, true, 20000, true);
// THEN
List<WorkItemType> workItems = getWorkItems(task, result);
displayWorkItems("Work items after timed escalation", workItems);
assertEquals("Wrong # of work items after timed escalation", 1, workItems.size());
String taskOid = WfContextUtil.getTask(workItems.get(0)).getOid();
PrismObject<TaskType> wfTask = getTask(taskOid);
display("wfTask after timed escalation", wfTask);
List<Message> lifecycleMessages = dummyTransport.getMessages(DUMMY_WORK_ITEM_LIFECYCLE);
List<Message> allocationMessages = dummyTransport.getMessages(DUMMY_WORK_ITEM_ALLOCATION);
List<Message> processMessages = dummyTransport.getMessages(DUMMY_PROCESS);
display("work items lifecycle notifications", lifecycleMessages);
display("work items allocation notifications", allocationMessages);
display("processes notifications", processMessages);
dummyTransport.clearMessages();
// asserts - work item
WorkItemType workItem = workItems.get(0);
PrismAsserts.assertReferenceValues(ref(workItem.getAssigneeRef()), userGuybrushOid, userCheeseOid);
PrismAsserts.assertDuration("Wrong duration between now and deadline", "P9D", System.currentTimeMillis(), workItem.getDeadline(), null);
PrismAsserts.assertReferenceValue(ref(workItem.getOriginalAssigneeRef()), userGuybrushOid);
assertEquals("Wrong stage #", (Integer) 1, workItem.getStageNumber());
assertEquals("Wrong escalation level #", 1, WfContextUtil.getEscalationLevelNumber(workItem));
assertEquals("Wrong escalation level name", "Line manager escalation", WfContextUtil.getEscalationLevelName(workItem));
List<CaseEventType> events = assertEvents(wfTask, 2);
assertEscalationEvent(events.get(1), userAdministrator.getOid(), userGuybrushOid, 1, "Line managers",
Collections.singletonList(userGuybrushOid), Collections.singletonList(userCheeseOid), WorkItemDelegationMethodType.ADD_ASSIGNEES,
1, "Line manager escalation");
// asserts - notifications
assertNull("lifecycle messages", lifecycleMessages);
assertNull("process messages", processMessages);
assertEquals("Wrong # of work items allocation messages", 3, allocationMessages.size());
ArrayListValuedHashMap<String, Message> sorted = sortByRecipients(allocationMessages);
assertMessage(sorted.get("guybrush@evolveum.com").get(0), "guybrush@evolveum.com", "Work item has been escalated",
"Work item: Approve assigning a-test-1 to carla", "Stage: Line managers (1/3)",
"Allocated to (before escalation): Guybrush Threepwood (guybrush)",
"(in 5 days)");
assertMessage(sorted.get("guybrush@evolveum.com").get(1), "guybrush@evolveum.com", "Work item has been allocated to you",
"Work item: Approve assigning a-test-1 to carla", "Stage: Line managers (1/3)",
"Escalation level: Line manager escalation (1)",
"|Allocated to (after escalation): Guybrush Threepwood (guybrush), Ignatius Cheese (cheese)|Allocated to (after escalation): Ignatius Cheese (cheese), Guybrush Threepwood (guybrush)",
"(in 9 days)");
assertMessage(sorted.get("cheese@evolveum.com").get(0), "cheese@evolveum.com", "Work item has been allocated to you",
"Work item: Approve assigning a-test-1 to carla", "Stage: Line managers (1/3)",
"Escalation level: Line manager escalation (1)",
"|Allocated to (after escalation): Guybrush Threepwood (guybrush), Ignatius Cheese (cheese)|Allocated to (after escalation): Ignatius Cheese (cheese), Guybrush Threepwood (guybrush)",
"(in 9 days)");
display("audit", dummyAuditService);
}
@Test
public void test205EightDaysLater() throws Exception {
final String TEST_NAME = "test205EightDaysLater";
TestUtil.displayTestTitle(this, TEST_NAME);
Task task = createTask(TestStrings.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
dummyAuditService.clear();
dummyTransport.clearMessages();
// WHEN
clock.resetOverride();
clock.overrideDuration("P8D");
waitForTaskNextRun(TASK_TRIGGER_SCANNER_OID, true, 20000, true);
// THEN
List<Message> lifecycleMessages = dummyTransport.getMessages(DUMMY_WORK_ITEM_LIFECYCLE);
List<Message> allocationMessages = dummyTransport.getMessages(DUMMY_WORK_ITEM_ALLOCATION);
List<Message> processMessages = dummyTransport.getMessages(DUMMY_PROCESS);
display("work items lifecycle notifications", lifecycleMessages);
display("work items allocation notifications", allocationMessages);
display("processes notifications", processMessages);
dummyTransport.clearMessages();
assertNull("lifecycle messages", lifecycleMessages);
assertNull("process messages", processMessages);
assertEquals("Wrong # of work items allocation messages", 4, allocationMessages.size());
ArrayListValuedHashMap<String, Message> sorted = sortByRecipients(allocationMessages);
assertMessage(sorted.get("guybrush@evolveum.com").get(0), "guybrush@evolveum.com", "Work item will be automatically completed in 2 days 12 hours",
"Work item: Approve assigning a-test-1 to carla", "Stage: Line managers (1/3)",
"Escalation level: Line manager escalation (1)",
"|Allocated to: Guybrush Threepwood (guybrush), Ignatius Cheese (cheese)|Allocated to: Ignatius Cheese (cheese), Guybrush Threepwood (guybrush)",
"(in 9 days)");
assertMessage(sorted.get("guybrush@evolveum.com").get(1), "guybrush@evolveum.com", "Work item will be automatically completed in 2 days",
"Work item: Approve assigning a-test-1 to carla", "Stage: Line managers (1/3)",
"Escalation level: Line manager escalation (1)",
"|Allocated to: Guybrush Threepwood (guybrush), Ignatius Cheese (cheese)|Allocated to: Ignatius Cheese (cheese), Guybrush Threepwood (guybrush)",
"(in 9 days)");
assertMessage(sorted.get("cheese@evolveum.com").get(0), "cheese@evolveum.com", "Work item will be automatically completed in 2 days 12 hours",
"Work item: Approve assigning a-test-1 to carla", "Stage: Line managers (1/3)",
"Escalation level: Line manager escalation (1)",
"|Allocated to: Guybrush Threepwood (guybrush), Ignatius Cheese (cheese)|Allocated to: Ignatius Cheese (cheese), Guybrush Threepwood (guybrush)",
"(in 9 days)");
assertMessage(sorted.get("cheese@evolveum.com").get(1), "cheese@evolveum.com", "Work item will be automatically completed in 2 days",
"Work item: Approve assigning a-test-1 to carla", "Stage: Line managers (1/3)",
"Escalation level: Line manager escalation (1)",
"|Allocated to: Guybrush Threepwood (guybrush), Ignatius Cheese (cheese)|Allocated to: Ignatius Cheese (cheese), Guybrush Threepwood (guybrush)",
"(in 9 days)");
display("audit", dummyAuditService);
}
@Test
public void test206ApproveByCheese() throws Exception {
final String TEST_NAME = "test206ApproveByCheese";
TestUtil.displayTestTitle(this, TEST_NAME);
Task task = createTask(TestStrings.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
dummyAuditService.clear();
dummyTransport.clearMessages();
// GIVEN
login(userAdministrator);
clock.resetOverride();
WorkItemType workItem = getWorkItem(task, result);
PrismObject<UserType> cheese = getUserFromRepo(userCheeseOid);
login(cheese);
// WHEN
workflowService.completeWorkItem(workItem.getExternalId(), true, "OK. Cheese.", null, result);
// THEN
login(userAdministrator);
List<WorkItemType> workItems = getWorkItems(task, result);
assertEquals("Wrong # of work items on level 2", 2, workItems.size());
displayWorkItems("Work item after 1st approval", workItems);
PrismObject<TaskType> wfTask = getTask(WfContextUtil.getTask(workItem).getOid());
display("wfTask after 1st approval", wfTask);
assertStage(wfTask, 2, 3, "Security", null);
assertTriggers(wfTask, 4);
List<Message> lifecycleMessages = dummyTransport.getMessages(DUMMY_WORK_ITEM_LIFECYCLE);
List<Message> allocationMessages = dummyTransport.getMessages(DUMMY_WORK_ITEM_ALLOCATION);
List<Message> processMessages = dummyTransport.getMessages(DUMMY_PROCESS);
display("work items lifecycle notifications", lifecycleMessages);
display("work items allocation notifications", allocationMessages);
display("processes notifications", processMessages);
dummyTransport.clearMessages();
assertEquals("Wrong # of work items lifecycle messages", 4, lifecycleMessages.size());
assertEquals("Wrong # of work items allocation messages", 4, allocationMessages.size());
assertNull("process messages", processMessages);
Map<String,Message> sorted = sortByRecipientsSingle(lifecycleMessages);
assertMessage(sorted.get("guybrush@evolveum.com"), "guybrush@evolveum.com", "Work item has been completed",
"Work item: Approve assigning a-test-1 to carla", "Stage: Line managers (1/3)",
"Escalation level: Line manager escalation (1)",
"Originally allocated to: Guybrush Threepwood (guybrush)",
"|Allocated to: Guybrush Threepwood (guybrush), Ignatius Cheese (cheese)|Allocated to: Ignatius Cheese (cheese), Guybrush Threepwood (guybrush)",
"Carried out by: Ignatius Cheese (cheese)",
"Result: APPROVED", "^Deadline:");
assertMessage(sorted.get("cheese@evolveum.com"), "cheese@evolveum.com", "Work item has been completed",
"Work item: Approve assigning a-test-1 to carla", "Stage: Line managers (1/3)",
"Escalation level: Line manager escalation (1)",
"Originally allocated to: Guybrush Threepwood (guybrush)",
"|Allocated to: Guybrush Threepwood (guybrush), Ignatius Cheese (cheese)|Allocated to: Ignatius Cheese (cheese), Guybrush Threepwood (guybrush)",
"Carried out by: Ignatius Cheese (cheese)",
"Result: APPROVED", "^Deadline:");
assertMessage(sorted.get("elaine@evolveum.com"), "elaine@evolveum.com", "A new work item has been created",
"Work item: Approve assigning a-test-1 to carla", "Stage: Security (2/3)",
"Allocated to: Elaine Marley (elaine)", "(in 7 days)", "^Result:");
assertMessage(sorted.get("barkeeper@evolveum.com"), "barkeeper@evolveum.com", "A new work item has been created",
"Work item: Approve assigning a-test-1 to carla", "Stage: Security (2/3)",
"Allocated to: Horridly Scarred Barkeep (barkeeper)", "(in 7 days)", "^Result:");
Map<String,Message> sorted2 = sortByRecipientsSingle(allocationMessages);
assertMessage(sorted2.get("guybrush@evolveum.com"), "guybrush@evolveum.com", "Work item has been completed",
"Work item: Approve assigning a-test-1 to carla", "Stage: Line managers (1/3)",
"Escalation level: Line manager escalation (1)",
"Originally allocated to: Guybrush Threepwood (guybrush)",
"|Allocated to: Guybrush Threepwood (guybrush), Ignatius Cheese (cheese)|Allocated to: Ignatius Cheese (cheese), Guybrush Threepwood (guybrush)",
"Carried out by: Ignatius Cheese (cheese)",
"Result: APPROVED", "^Deadline:");
assertMessage(sorted2.get("cheese@evolveum.com"), "cheese@evolveum.com", "Work item has been completed",
"Work item: Approve assigning a-test-1 to carla", "Stage: Line managers (1/3)",
"Escalation level: Line manager escalation (1)",
"Originally allocated to: Guybrush Threepwood (guybrush)",
"|Allocated to: Guybrush Threepwood (guybrush), Ignatius Cheese (cheese)|Allocated to: Ignatius Cheese (cheese), Guybrush Threepwood (guybrush)",
"Carried out by: Ignatius Cheese (cheese)",
"Result: APPROVED", "^Deadline:");
assertMessage(sorted2.get("elaine@evolveum.com"), "elaine@evolveum.com", "Work item has been allocated to you",
"Work item: Approve assigning a-test-1 to carla", "Stage: Security (2/3)",
"Allocated to: Elaine Marley (elaine)", "(in 7 days)", "^Result:");
assertMessage(sorted2.get("barkeeper@evolveum.com"), "barkeeper@evolveum.com", "Work item has been allocated to you",
"Work item: Approve assigning a-test-1 to carla", "Stage: Security (2/3)",
"Allocated to: Horridly Scarred Barkeep (barkeeper)", "(in 7 days)", "^Result:");
display("audit", dummyAuditService);
}
// notification should be send
@Test
public void test208SixDaysLater() throws Exception {
final String TEST_NAME = "test208SixDaysLater";
TestUtil.displayTestTitle(this, TEST_NAME);
Task task = createTask(TestStrings.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
dummyAuditService.clear();
dummyTransport.clearMessages();
// GIVEN
clock.resetOverride();
resetTriggerTask(TASK_TRIGGER_SCANNER_OID, TASK_TRIGGER_SCANNER_FILE, result);
clock.overrideDuration("P6D");
// WHEN
waitForTaskNextRun(TASK_TRIGGER_SCANNER_OID, true, 20000, true);
// THEN
List<Message> lifecycleMessages = dummyTransport.getMessages(DUMMY_WORK_ITEM_LIFECYCLE);
List<Message> allocationMessages = dummyTransport.getMessages(DUMMY_WORK_ITEM_ALLOCATION);
List<Message> processMessages = dummyTransport.getMessages(DUMMY_PROCESS);
display("work items lifecycle notifications", lifecycleMessages);
display("work items allocation notifications", allocationMessages);
display("processes notifications", processMessages);
dummyTransport.clearMessages();
assertNull("lifecycle messages", lifecycleMessages);
assertNull("process messages", processMessages);
assertEquals("Wrong # of work items allocation messages", 2, allocationMessages.size());
Map<String, Message> sorted = sortByRecipientsSingle(allocationMessages);
assertMessage(sorted.get("elaine@evolveum.com"), "elaine@evolveum.com",
"Work item will be automatically completed in 2 days",
"Security (2/3)", "Allocated to: Elaine Marley (elaine)", "(in 7 days)");
assertMessage(sorted.get("barkeeper@evolveum.com"), "barkeeper@evolveum.com",
"Work item will be automatically completed in 2 days",
"Security (2/3)", "Allocated to: Horridly Scarred Barkeep (barkeeper)", "(in 7 days)");
display("audit", dummyAuditService);
}
@Test
public void test209EightDaysLater() throws Exception {
final String TEST_NAME = "test209EightDaysLater";
TestUtil.displayTestTitle(this, TEST_NAME);
Task task = createTask(TestStrings.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
dummyAuditService.clear();
dummyTransport.clearMessages();
// GIVEN
clock.resetOverride();
clock.overrideDuration("P8D");
// WHEN
waitForTaskNextRun(TASK_TRIGGER_SCANNER_OID, true, 20000, true);
// THEN
List<Message> lifecycleMessages = dummyTransport.getMessages(DUMMY_WORK_ITEM_LIFECYCLE);
List<Message> allocationMessages = dummyTransport.getMessages(DUMMY_WORK_ITEM_ALLOCATION);
List<Message> processMessages = dummyTransport.getMessages(DUMMY_PROCESS);
display("work items lifecycle notifications", lifecycleMessages);
display("work items allocation notifications", allocationMessages);
display("processes notifications", processMessages);
dummyTransport.clearMessages();
assertEquals("Wrong # of work items lifecycle messages", 2, lifecycleMessages.size());
assertEquals("Wrong # of work items allocation messages", 2, allocationMessages.size());
assertEquals("Wrong # of process messages", 1, processMessages.size());
checkTwoCompleted(lifecycleMessages);
checkTwoCompleted(allocationMessages);
assertMessage(processMessages.get(0), "administrator@evolveum.com", "Workflow process instance has finished",
"Process instance name: Assigning a-test-1 to carla", "Result: REJECTED");
display("audit", dummyAuditService);
}
private void checkTwoCompleted(List<Message> lifecycleMessages) {
Map<String, Message> sorted = sortByRecipientsSingle(lifecycleMessages);
assertMessage(sorted.get("elaine@evolveum.com"), "elaine@evolveum.com",
null,
"Security (2/3)", "Allocated to: Elaine Marley (elaine)");
assertMessage(sorted.get("barkeeper@evolveum.com"), "barkeeper@evolveum.com",
null,
"Security (2/3)", "Allocated to: Horridly Scarred Barkeep (barkeeper)");
int completed;
assertMessage(lifecycleMessages.get(0), null, "Work item has been completed",
"^Carried out by:",
"Reason: Timed action",
"Result: REJECTED");
assertMessage(lifecycleMessages.get(1), null, "Work item has been completed",
"^Carried out by:",
"Reason: Timed action",
"Result: REJECTED");
}
@Test
public void test220FormRoleAssignmentStart() throws Exception {
final String TEST_NAME = "test220FormRoleAssignmentStart";
TestUtil.displayTestTitle(this, TEST_NAME);
PrismObject<UserType> bob = getUserFromRepo(userBobOid);
login(bob);
Task task = createTask(TestStrings.class.getName() + "." + TEST_NAME);
task.setOwner(bob);
OperationResult result = task.getResult();
dummyAuditService.clear();
dummyTransport.clearMessages();
// WHEN
assignRole(userBobOid, roleATest4Oid, task, task.getResult());
// THEN
login(userAdministrator);