-
Notifications
You must be signed in to change notification settings - Fork 188
/
TestIteration.java
2146 lines (1712 loc) · 99.7 KB
/
TestIteration.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-2013 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.model.intest;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertNotNull;
import static org.testng.AssertJUnit.assertNull;
import static com.evolveum.midpoint.test.IntegrationTestTools.display;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import com.evolveum.midpoint.model.api.PolicyViolationException;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.util.exception.ExpressionEvaluationException;
import com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException;
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 com.evolveum.icf.dummy.resource.DummyAccount;
import com.evolveum.icf.dummy.resource.DummyResource;
import com.evolveum.icf.dummy.resource.DummySyncStyle;
import com.evolveum.midpoint.model.test.AbstractModelIntegrationTest;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.delta.ChangeType;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.prism.query.EqualFilter;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.prism.util.PrismAsserts;
import com.evolveum.midpoint.prism.util.PrismTestUtil;
import com.evolveum.midpoint.schema.constants.MidPointConstants;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.ObjectQueryUtil;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.test.DummyResourceContoller;
import com.evolveum.midpoint.test.util.TestUtil;
import com.evolveum.midpoint.util.exception.CommunicationException;
import com.evolveum.midpoint.util.exception.ConfigurationException;
import com.evolveum.midpoint.util.exception.ObjectNotFoundException;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.exception.SecurityViolationException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentPolicyEnforcementType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;
/**
* @author semancik
*
*/
@ContextConfiguration(locations = {"classpath:ctx-model-intest-test-main.xml"})
@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
public class TestIteration extends AbstractInitializedModelIntegrationTest {
public static final File TEST_DIR = new File("src/test/resources/iteration");
protected static final File USER_XAVIER_FILE = new File(TEST_DIR, "user-xavier.xml");
protected static final String USER_XAVIER_OID = "c0c010c0-d34d-b33f-f00d-11111111aaa1";
protected static final File RESOURCE_DUMMY_PINK_FILE = new File(TEST_DIR, "resource-dummy-pink.xml");
protected static final String RESOURCE_DUMMY_PINK_OID = "10000000-0000-0000-0000-00000000a104";
protected static final String RESOURCE_DUMMY_PINK_NAME = "pink";
protected static final String RESOURCE_DUMMY_PINK_NAMESPACE = MidPointConstants.NS_RI;
protected static final File RESOURCE_DUMMY_VIOLET_FILE = new File(TEST_DIR, "resource-dummy-violet.xml");
protected static final String RESOURCE_DUMMY_VIOLET_OID = "10000000-0000-0000-0000-00000000a204";
protected static final String RESOURCE_DUMMY_VIOLET_NAME = "violet";
protected static final String RESOURCE_DUMMY_VIOLET_NAMESPACE = MidPointConstants.NS_RI;
protected static final File RESOURCE_DUMMY_DARK_VIOLET_FILE = new File(TEST_DIR, "resource-dummy-dark-violet.xml");
protected static final String RESOURCE_DUMMY_DARK_VIOLET_OID = "10000000-0000-0000-0000-0000000da204";
protected static final String RESOURCE_DUMMY_DARK_VIOLET_NAME = "darkViolet";
protected static final String RESOURCE_DUMMY_DARK_VIOLET_NAMESPACE = MidPointConstants.NS_RI;
protected static final File RESOURCE_DUMMY_MAGENTA_FILE = new File(TEST_DIR, "resource-dummy-magenta.xml");
protected static final String RESOURCE_DUMMY_MAGENTA_OID = "10000000-0000-0000-0000-00000000a304";
protected static final String RESOURCE_DUMMY_MAGENTA_NAME = "magenta";
protected static final String RESOURCE_DUMMY_MAGENTA_NAMESPACE = MidPointConstants.NS_RI;
protected static final File RESOURCE_DUMMY_FUCHSIA_FILE = new File(TEST_DIR, "resource-dummy-fuchsia.xml");
protected static final String RESOURCE_DUMMY_FUCHSIA_OID = "10000000-0000-0000-0000-0000000dd204";
protected static final String RESOURCE_DUMMY_FUCHSIA_NAME = "fuchsia";
protected static final String RESOURCE_DUMMY_FUCHSIA_NAMESPACE = MidPointConstants.NS_RI;
protected static final File TASK_LIVE_SYNC_DUMMY_DARK_VIOLET_FILE = new File(TEST_DIR, "task-dumy-dark-violet-livesync.xml");
protected static final String TASK_LIVE_SYNC_DUMMY_DARK_VIOLET_OID = "10000000-0000-0000-5555-555500da0204";
protected static final File USER_TEMPLATE_ITERATION_FILE = new File(TEST_DIR, "user-template-iteration.xml");
protected static final String USER_TEMPLATE_ITERATION_OID = "10000000-0000-0000-0000-0000000d0002";
protected static final File USER_TEMPLATE_ITERATION_RANDOM_FILE = new File(TEST_DIR, "user-template-iteration-random.xml");
protected static final String USER_TEMPLATE_ITERATION_RANDOM_OID = "10000000-0000-0000-0000-0000000d0002"; // SAME OID as USER_TEMPLATE_ITERATION
private static final String USER_ANGELICA_NAME = "angelica";
private static final String ACCOUNT_SPARROW_NAME = "sparrow";
private static final String USER_DEWATT_NAME = "dewatt";
private static final String ACCOUNT_DEWATT_NAME = "DeWatt";
private static final String USER_LARGO_NAME = "largo";
private static final String ACCOUNT_LARGO_NAME = "largo";
public static final String ACCOUNT_LARGO_DUMMY_USERNAME = "largo";
private static final String DESCRIPTION_RUM = "Where's the rum?";
private static final String USER_JACK_RENAMED_NAME = "cptjack";
private static final String ACCOUNT_LECHUCK_USERNAME = "lechuck";
private static final String LECHUCK_FULLNAME = "LeChuck";
private static final String ACCOUNT_CHARLES_USERNAME = "charles";
private static final String ACCOUNT_SHINETOP_USERNAME = "shinetop";
private static final String CHUCKIE_FULLNAME = "Chuckie";
private static final String ACCOUNT_MATUSALEM_USERNAME = "matusalem";
private static final String ACCOUNT_DIPLOMATICO_USERNAME = "diplomatico";
private static final String ACCOUNT_MILLONARIO_USERNAME = "millonario";
private static final String RUM_FULLNAME = "Rum";
private static final String RON_FULLNAME = "Ron";
private static final File USER_JUPITER_FILE = new File(TEST_DIR, "user-jupiter.xml");
private static final String USER_JUPITER_NAME = "jupiter";
private static final String ACCOUNT_JUPITER_DUMMY_FUCHSIA_USERNAME = "Jupiter Jones";
private static final File USER_ALFRED_FILE = new File(TEST_DIR, "user-alfred.xml");
private static final String USER_ALFRED_NAME = "alfred";
private static final String USER_BOB_NAME = "bob";
protected String jupiterUserOid;
protected static DummyResource dummyResourcePink;
protected static DummyResourceContoller dummyResourceCtlPink;
protected ResourceType resourceDummyPinkType;
protected PrismObject<ResourceType> resourceDummyPink;
protected static DummyResource dummyResourceViolet;
protected static DummyResourceContoller dummyResourceCtlViolet;
protected ResourceType resourceDummyVioletType;
protected PrismObject<ResourceType> resourceDummyViolet;
protected static DummyResource dummyResourceDarkViolet;
protected static DummyResourceContoller dummyResourceCtlDarkViolet;
protected ResourceType resourceDummyDarkVioletType;
protected PrismObject<ResourceType> resourceDummyDarkViolet;
protected static DummyResource dummyResourceMagenta;
protected static DummyResourceContoller dummyResourceCtlMagenta;
protected ResourceType resourceDummyMagentaType;
protected PrismObject<ResourceType> resourceDummyMagenta;
protected static DummyResource dummyResourceFuchsia;
protected static DummyResourceContoller dummyResourceCtlFuchsia;
protected ResourceType resourceDummyFuchsiaType;
protected PrismObject<ResourceType> resourceDummyFuchsia;
String iterationTokenDiplomatico;
String iterationTokenMillonario;
@Override
public void initSystem(Task initTask, OperationResult initResult) throws Exception {
super.initSystem(initTask, initResult);
dummyResourceCtlPink = DummyResourceContoller.create(RESOURCE_DUMMY_PINK_NAME, resourceDummyPink);
dummyResourceCtlPink.extendSchemaPirate();
dummyResourcePink = dummyResourceCtlPink.getDummyResource();
resourceDummyPink = importAndGetObjectFromFile(ResourceType.class, RESOURCE_DUMMY_PINK_FILE, RESOURCE_DUMMY_PINK_OID, initTask, initResult);
resourceDummyPinkType = resourceDummyPink.asObjectable();
dummyResourceCtlPink.setResource(resourceDummyPink);
dummyResourceCtlViolet = DummyResourceContoller.create(RESOURCE_DUMMY_VIOLET_NAME, resourceDummyViolet);
dummyResourceCtlViolet.extendSchemaPirate();
dummyResourceViolet = dummyResourceCtlViolet.getDummyResource();
resourceDummyViolet = importAndGetObjectFromFile(ResourceType.class, RESOURCE_DUMMY_VIOLET_FILE, RESOURCE_DUMMY_VIOLET_OID, initTask, initResult);
resourceDummyVioletType = resourceDummyViolet.asObjectable();
dummyResourceCtlViolet.setResource(resourceDummyViolet);
dummyResourceCtlDarkViolet = DummyResourceContoller.create(RESOURCE_DUMMY_DARK_VIOLET_NAME, resourceDummyViolet);
dummyResourceCtlDarkViolet.extendSchemaPirate();
dummyResourceDarkViolet = dummyResourceCtlDarkViolet.getDummyResource();
resourceDummyDarkViolet = importAndGetObjectFromFile(ResourceType.class, RESOURCE_DUMMY_DARK_VIOLET_FILE, RESOURCE_DUMMY_DARK_VIOLET_OID, initTask, initResult);
resourceDummyDarkVioletType = resourceDummyDarkViolet.asObjectable();
dummyResourceCtlDarkViolet.setResource(resourceDummyDarkViolet);
dummyResourceDarkViolet.setSyncStyle(DummySyncStyle.SMART);
dummyResourceCtlMagenta = DummyResourceContoller.create(RESOURCE_DUMMY_MAGENTA_NAME, resourceDummyMagenta);
dummyResourceCtlMagenta.extendSchemaPirate();
dummyResourceMagenta = dummyResourceCtlMagenta.getDummyResource();
resourceDummyMagenta = importAndGetObjectFromFile(ResourceType.class, RESOURCE_DUMMY_MAGENTA_FILE, RESOURCE_DUMMY_MAGENTA_OID, initTask, initResult);
resourceDummyMagentaType = resourceDummyMagenta.asObjectable();
dummyResourceCtlMagenta.setResource(resourceDummyMagenta);
dummyResourceCtlFuchsia = DummyResourceContoller.create(RESOURCE_DUMMY_FUCHSIA_NAME, resourceDummyFuchsia);
dummyResourceCtlFuchsia.extendSchemaAd();
dummyResourceFuchsia = dummyResourceCtlFuchsia.getDummyResource();
resourceDummyFuchsia = importAndGetObjectFromFile(ResourceType.class, RESOURCE_DUMMY_FUCHSIA_FILE, RESOURCE_DUMMY_FUCHSIA_OID, initTask, initResult);
resourceDummyFuchsiaType = resourceDummyFuchsia.asObjectable();
dummyResourceCtlFuchsia.setResource(resourceDummyFuchsia);
addObject(USER_TEMPLATE_ITERATION_FILE);
addObject(USER_LARGO_FILE);
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.RELATIVE);
}
/**
* The default dummy instance will not iterate. It has correlation rule which will link the account instead.
*/
@Test
public void test100JackAssignAccountDummyConflicting() throws Exception {
final String TEST_NAME = "test100JackAssignAccountDummyConflicting";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestIteration.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
dummyAuditService.clear();
// Make sure there is a conflicting account and also a shadow for it
DummyAccount account = new DummyAccount(ACCOUNT_JACK_DUMMY_USERNAME);
account.setEnabled(true);
account.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME, "Jack Sparrow");
account.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_LOCATION_NAME, "Tortuga");
dummyResource.addAccount(account);
repoAddObject(ShadowType.class, createShadow(resourceDummy, ACCOUNT_JACK_DUMMY_USERNAME), result);
Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<ObjectDelta<? extends ObjectType>>();
ObjectDelta<UserType> accountAssignmentUserDelta = createAccountAssignmentUserDelta(USER_JACK_OID, RESOURCE_DUMMY_OID, null, true);
deltas.add(accountAssignmentUserDelta);
// WHEN
TestUtil.displayWhen(TEST_NAME);
modelService.executeChanges(deltas, null, task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);
PrismObject<UserType> userJack = getUser(USER_JACK_OID);
display("User after change execution", userJack);
assertUserJack(userJack);
String accountOid = getSingleLinkOid(userJack);
// Check shadow
PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result);
assertDummyAccountShadowRepo(accountShadow, accountOid, ACCOUNT_JACK_DUMMY_USERNAME);
// Check account
PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountOid, null, task, result);
assertDummyAccountShadowModel(accountModel, accountOid, ACCOUNT_JACK_DUMMY_USERNAME, "Jack Sparrow");
// Check account in dummy resource
assertDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME, "Jack Sparrow", true);
// Check audit
display("Audit", dummyAuditService);
dummyAuditService.assertRecords(2);
dummyAuditService.assertSimpleRecordSanity();
dummyAuditService.assertAnyRequestDeltas();
dummyAuditService.assertExecutionDeltas(3);
dummyAuditService.asserHasDelta(ChangeType.MODIFY, UserType.class);
dummyAuditService.asserHasDelta(ChangeType.MODIFY, ShadowType.class);
dummyAuditService.assertExecutionSuccess();
}
@Test
public void test200JackAssignAccountDummyPinkConflicting() throws Exception {
final String TEST_NAME = "test200JackAssignAccountDummyPinkConflicting";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestIteration.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
dummyAuditService.clear();
// Make sure there is a conflicting account and also a shadow for it
DummyAccount account = new DummyAccount(ACCOUNT_JACK_DUMMY_USERNAME);
account.setEnabled(true);
account.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME, "Jack Pinky");
account.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_LOCATION_NAME, "Red Sea");
dummyResourcePink.addAccount(account);
repoAddObject(ShadowType.class, createShadow(resourceDummyPink, ACCOUNT_JACK_DUMMY_USERNAME), result);
Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<ObjectDelta<? extends ObjectType>>();
ObjectDelta<UserType> accountAssignmentUserDelta = createAccountAssignmentUserDelta(USER_JACK_OID, RESOURCE_DUMMY_PINK_OID, null, true);
deltas.add(accountAssignmentUserDelta);
// WHEN
TestUtil.displayWhen(TEST_NAME);
modelService.executeChanges(deltas, null, task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);
PrismObject<UserType> userJack = getUser(USER_JACK_OID);
display("User after change execution", userJack);
assertUserJack(userJack);
assertLinks(userJack, 2);
assertAccount(userJack, RESOURCE_DUMMY_OID);
assertAccount(userJack, RESOURCE_DUMMY_PINK_OID);
String accountPinkOid = getLinkRefOid(userJack, RESOURCE_DUMMY_PINK_OID);
// Check shadow
PrismObject<ShadowType> accountPinkShadow = repositoryService.getObject(ShadowType.class, accountPinkOid, null, result);
assertAccountShadowRepo(accountPinkShadow, accountPinkOid, "jack1", resourceDummyPinkType);
// Check account
PrismObject<ShadowType> accountPinkModel = modelService.getObject(ShadowType.class, accountPinkOid, null, task, result);
assertAccountShadowModel(accountPinkModel, accountPinkOid, "jack1", resourceDummyPinkType);
// Check account in dummy resource
assertDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME, "Jack Sparrow", true);
// The original conflicting account should still remain
assertDummyAccount(RESOURCE_DUMMY_PINK_NAME, ACCOUNT_JACK_DUMMY_USERNAME, "Jack Pinky", true);
// The new account
assertDummyAccount(RESOURCE_DUMMY_PINK_NAME, "jack1", "Jack Sparrow", true);
// Check audit
display("Audit", dummyAuditService);
dummyAuditService.assertRecords(2);
dummyAuditService.assertSimpleRecordSanity();
dummyAuditService.assertAnyRequestDeltas();
dummyAuditService.assertExecutionDeltas(3);
dummyAuditService.asserHasDelta(ChangeType.MODIFY, UserType.class);
dummyAuditService.asserHasDelta(ChangeType.ADD, ShadowType.class);
dummyAuditService.assertExecutionSuccess();
}
/**
* Test the normal case. Just to be sure the default iteration algorithm works well.
*/
@Test
public void test210GuybrushAssignAccountDummyPink() throws Exception {
final String TEST_NAME = "test210GuybrushAssignAccountDummyPink";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestIteration.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
dummyAuditService.clear();
Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<ObjectDelta<? extends ObjectType>>();
ObjectDelta<UserType> accountAssignmentUserDelta = createAccountAssignmentUserDelta(USER_GUYBRUSH_OID, RESOURCE_DUMMY_PINK_OID, null, true);
deltas.add(accountAssignmentUserDelta);
// WHEN
TestUtil.displayWhen(TEST_NAME);
modelService.executeChanges(deltas, null, task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);
PrismObject<UserType> userGuybrush = getUser(USER_GUYBRUSH_OID);
display("User after change execution", userGuybrush);
assertUser(userGuybrush, USER_GUYBRUSH_OID, ACCOUNT_GUYBRUSH_DUMMY_USERNAME, "Guybrush Threepwood", "Guybrush", "Threepwood");
assertLinks(userGuybrush, 2);
// Guybrush had dummy account before
assertAccount(userGuybrush, RESOURCE_DUMMY_OID);
assertAccount(userGuybrush, RESOURCE_DUMMY_PINK_OID);
String accountPinkOid = getLinkRefOid(userGuybrush, RESOURCE_DUMMY_PINK_OID);
// Check shadow
PrismObject<ShadowType> accountPinkShadow = repositoryService.getObject(ShadowType.class, accountPinkOid, null, result);
assertAccountShadowRepo(accountPinkShadow, accountPinkOid, ACCOUNT_GUYBRUSH_DUMMY_USERNAME, resourceDummyPinkType);
// Check account
PrismObject<ShadowType> accountPinkModel = modelService.getObject(ShadowType.class, accountPinkOid, null, task, result);
assertAccountShadowModel(accountPinkModel, accountPinkOid, ACCOUNT_GUYBRUSH_DUMMY_USERNAME, resourceDummyPinkType);
// The new account
assertDummyAccount(RESOURCE_DUMMY_PINK_NAME, ACCOUNT_GUYBRUSH_DUMMY_USERNAME, "Guybrush Threepwood", true);
// Check audit
display("Audit", dummyAuditService);
dummyAuditService.assertRecords(2);
dummyAuditService.assertSimpleRecordSanity();
dummyAuditService.assertAnyRequestDeltas();
dummyAuditService.assertExecutionDeltas(3);
dummyAuditService.asserHasDelta(ChangeType.MODIFY, UserType.class);
dummyAuditService.asserHasDelta(ChangeType.ADD, ShadowType.class);
dummyAuditService.assertExecutionSuccess();
}
@Test
public void test220DeWattAssignAccountDummyPinkCaseIgnore() throws Exception {
final String TEST_NAME = "test220DeWattAssignAccountDummyPinkCaseIgnore";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestIteration.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
PrismObject<UserType> userDeWatt = createUser(USER_DEWATT_NAME, "Augustus DeWatt", true);
addObject(userDeWatt);
String userDeWattkOid = userDeWatt.getOid();
PrismObject<ShadowType> accountDeWatt = createAccount(resourceDummyPink, ACCOUNT_DEWATT_NAME, true);
addAttributeToShadow(accountDeWatt, resourceDummyPink,
DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME, "Augustus DeWatt");
addObject(accountDeWatt);
// precondition
assertDummyAccount(RESOURCE_DUMMY_PINK_NAME, ACCOUNT_DEWATT_NAME, "Augustus DeWatt", true);
Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<ObjectDelta<? extends ObjectType>>();
ObjectDelta<UserType> accountAssignmentUserDelta = createAccountAssignmentUserDelta(userDeWattkOid,
RESOURCE_DUMMY_PINK_OID, null, true);
deltas.add(accountAssignmentUserDelta);
dummyAuditService.clear();
// WHEN
TestUtil.displayWhen(TEST_NAME);
modelService.executeChanges(deltas, null, task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);
PrismObject<UserType> userDeWattAfter = getUser(userDeWattkOid);
display("User after change execution", userDeWattAfter);
assertUser(userDeWattAfter, userDeWattkOid, USER_DEWATT_NAME, "Augustus DeWatt", null, null);
assertLinks(userDeWattAfter, 1);
assertAccount(userDeWattAfter, RESOURCE_DUMMY_PINK_OID);
String accountPinkOid = getLinkRefOid(userDeWattAfter, RESOURCE_DUMMY_PINK_OID);
// Check shadow
PrismObject<ShadowType> accountPinkShadow = repositoryService.getObject(ShadowType.class, accountPinkOid, null, result);
assertAccountShadowRepo(accountPinkShadow, accountPinkOid, USER_DEWATT_NAME+"1", resourceDummyPinkType);
// Check account
PrismObject<ShadowType> accountPinkModel = modelService.getObject(ShadowType.class, accountPinkOid, null, task, result);
assertAccountShadowModel(accountPinkModel, accountPinkOid, USER_DEWATT_NAME+"1", resourceDummyPinkType);
// Old account
assertDummyAccount(RESOURCE_DUMMY_PINK_NAME, ACCOUNT_DEWATT_NAME, "Augustus DeWatt", true);
// The new account
assertDummyAccount(RESOURCE_DUMMY_PINK_NAME, USER_DEWATT_NAME+"1", "Augustus DeWatt", true);
// Check audit
display("Audit", dummyAuditService);
dummyAuditService.assertRecords(2);
dummyAuditService.assertSimpleRecordSanity();
dummyAuditService.assertAnyRequestDeltas();
dummyAuditService.assertExecutionDeltas(3);
dummyAuditService.asserHasDelta(ChangeType.MODIFY, UserType.class);
dummyAuditService.asserHasDelta(ChangeType.ADD, ShadowType.class);
dummyAuditService.assertExecutionSuccess();
}
@Test
public void test230ScroogeAddAccountDummyConflictingNoShadow() throws Exception {
final String TEST_NAME = "test230ScroogeAddAccountDummyConflictingNoShadow";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestIteration.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
dummyAuditService.clear();
// Make sure there is a conflicting account and NO shadow for it
DummyAccount account = new DummyAccount("scrooge");
account.setEnabled(true);
account.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME, "Scrooge Pinky");
dummyResourcePink.addAccount(account);
PrismObject<UserType> userScrooge = createUser("scrooge", "Scrooge McDuck", true);
ShadowType newPinkyShadow = createShadow(resourceDummyPinkType.asPrismObject(), null, null).asObjectable();
userScrooge.asObjectable().getLink().add(newPinkyShadow);
Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<ObjectDelta<? extends ObjectType>>();
deltas.add(ObjectDelta.createAddDelta(userScrooge));
// WHEN
TestUtil.displayWhen(TEST_NAME);
modelService.executeChanges(deltas, null, task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);
PrismObject<UserType> userScroogeAfter = findUserByUsername("scrooge");
display("User after change execution", userScroogeAfter);
assertUser(userScroogeAfter, null, "scrooge", "Scrooge McDuck", null, null, null);
String accountOid = getSingleLinkOid(userScroogeAfter);
// Check shadow
PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result);
assertAccountShadowRepo(accountShadow, accountOid, "scrooge1", resourceDummyPinkType);
// Check account
PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountOid, null, task, result);
assertAccountShadowModel(accountModel, accountOid, "scrooge1", resourceDummyPinkType);
// Check account in dummy resource
assertDummyAccount(RESOURCE_DUMMY_PINK_NAME, "scrooge1", "Scrooge McDuck", true);
}
@Test
public void test240LargoAssignAccountDummyConflictingNoShadow() throws Exception {
final String TEST_NAME = "test240LargoAssignAccountDummyConflictingNoShadow";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestIteration.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
dummyAuditService.clear();
// Make sure there is a conflicting account and NO shadow for it
DummyAccount account = new DummyAccount(ACCOUNT_LARGO_DUMMY_USERNAME);
account.setEnabled(true);
account.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME, "Largo Pinky");
dummyResourcePink.addAccount(account);
Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<ObjectDelta<? extends ObjectType>>();
ObjectDelta<UserType> accountAssignmentUserDelta = createAccountAssignmentUserDelta(USER_LARGO_OID, RESOURCE_DUMMY_PINK_OID, null, true);
deltas.add(accountAssignmentUserDelta);
// WHEN
TestUtil.displayWhen(TEST_NAME);
modelService.executeChanges(deltas, null, task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);
PrismObject<UserType> userLargo = getUser(USER_LARGO_OID);
display("User after change execution", userLargo);
assertUserLargo(userLargo);
String accountOid = getSingleLinkOid(userLargo);
// Check shadow
PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result);
assertAccountShadowRepo(accountShadow, accountOid, "largo1", resourceDummyPinkType);
// Check account
PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountOid, null, task, result);
assertAccountShadowModel(accountModel, accountOid, "largo1", resourceDummyPinkType);
// Check account in dummy resource
assertDummyAccount(RESOURCE_DUMMY_PINK_NAME, "largo1", null, true);
// Check audit
// USER Largo MODIFY(add-assignment): request + execution (focus(assignment) + account/failed) + execution (focus(linkRef) / account/OK)
display("Audit", dummyAuditService);
dummyAuditService.assertRecords(3);
dummyAuditService.assertSimpleRecordSanity();
dummyAuditService.assertAnyRequestDeltas();
dummyAuditService.assertExecutionDeltas(2);
dummyAuditService.asserHasDelta(ChangeType.MODIFY, UserType.class);
dummyAuditService.asserHasDelta(ChangeType.ADD, ShadowType.class);
dummyAuditService.assertExecutionSuccess();
}
/**
* Doing the same as test240 (conflict without pre-existing shadow -> surprising the model with AlreadyExists,
* causing re-running given wave in model. But this time doing this on resource that has synchronization
* defined (fuchsia).
*
* test260: first case - existing account corresponds to user being created
*
* 1) manually create account Jupiter Jones (no shadow!), description = "jupiter"
* 2) create user Jupiter Jones (name = jupiter)
*
* Create account operation should fail, account should be synchronized back to repo (creating the user!), and
* model should clean it up somehow...
*/
@Test
public void test260JupiterConflictNoShadowSyncBack() throws Exception {
final String TEST_NAME = "test260JupiterConflictNoShadowSyncBack";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestIteration.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
dummyAuditService.clear();
// Make sure there is a conflicting account and NO shadow for it
DummyAccount account = new DummyAccount(ACCOUNT_JUPITER_DUMMY_FUCHSIA_USERNAME); // Jupiter Jones
account.setEnabled(true);
account.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_AD_SAM_ACCOUNT_NAME_NAME, USER_JUPITER_NAME); // jupiter
dummyResourceFuchsia.addAccount(account);
Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<>();
PrismObject<UserType> userJupiter = PrismTestUtil.parseObject(USER_JUPITER_FILE);
deltas.add(ObjectDelta.createAddDelta(userJupiter));
// WHEN
TestUtil.displayWhen(TEST_NAME);
modelService.executeChanges(deltas, null, task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);
PrismObject<UserType> userJupiterAfter = findUserByUsername(USER_JUPITER_NAME); // jupiter
display("User after change execution", userJupiterAfter);
assertUserJupiter(userJupiterAfter);
jupiterUserOid = userJupiterAfter.getOid();
String accountOid = getSingleLinkOid(userJupiterAfter);
// Check shadow
PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result);
display("Account shadow from repo", accountShadow);
assertAccountShadowRepo(accountShadow, accountOid, ACCOUNT_JUPITER_DUMMY_FUCHSIA_USERNAME, resourceDummyFuchsiaType);
// Check account
PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountOid, null, task, result);
assertAccountShadowModel(accountModel, accountOid, ACCOUNT_JUPITER_DUMMY_FUCHSIA_USERNAME, resourceDummyFuchsiaType);
// Check account in dummy resource (actually, the fullname attribute does not exist but it's OK)
assertDummyAccount(RESOURCE_DUMMY_FUCHSIA_NAME, ACCOUNT_JUPITER_DUMMY_FUCHSIA_USERNAME, null, true);
// TODO Check audit
display("Audit", dummyAuditService);
// dummyAuditService.assertRecords(3);
// dummyAuditService.assertSimpleRecordSanity();
// dummyAuditService.assertAnyRequestDeltas();
// dummyAuditService.assertExecutionDeltas(2);
// dummyAuditService.asserHasDelta(ChangeType.MODIFY, UserType.class);
// dummyAuditService.asserHasDelta(ChangeType.ADD, ShadowType.class);
// dummyAuditService.assertExecutionSuccess();
}
// remove the assignment, shadow and account to prepare for following tests
@Test
public void test262JupiterCleanup() throws Exception {
final String TEST_NAME = "test262JupiterCleanup";
cleanUpJupiter(TEST_NAME);
}
protected void cleanUpJupiter(String TEST_NAME) throws SchemaException, ObjectAlreadyExistsException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException, PolicyViolationException, SecurityViolationException {
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestIteration.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
dummyAuditService.clear();
Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<>();
deltas.add(createAccountAssignmentUserDelta(jupiterUserOid, RESOURCE_DUMMY_FUCHSIA_OID, "default", false));
// WHEN
TestUtil.displayWhen(TEST_NAME);
modelService.executeChanges(deltas, null, task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);
PrismObject<UserType> userJupiterAfter = findUserByUsername(USER_JUPITER_NAME); // jupiter
display("User after change execution", userJupiterAfter);
assertUserJupiter(userJupiterAfter);
assertEquals("Unexpected number of linkRefs", 0, userJupiterAfter.asObjectable().getLinkRef().size());
assertNull("Unexpected account for jupiter", getDummyAccount(RESOURCE_DUMMY_FUCHSIA_NAME, ACCOUNT_JUPITER_DUMMY_FUCHSIA_USERNAME));
// TODO Check audit
display("Audit", dummyAuditService);
// dummyAuditService.assertRecords(3);
// dummyAuditService.assertSimpleRecordSanity();
// dummyAuditService.assertAnyRequestDeltas();
// dummyAuditService.assertExecutionDeltas(2);
// dummyAuditService.asserHasDelta(ChangeType.MODIFY, UserType.class);
// dummyAuditService.asserHasDelta(ChangeType.ADD, ShadowType.class);
// dummyAuditService.assertExecutionSuccess();
}
/**
* Doing the same as test260. But this time assigns the account in separate step.
*/
@Test
public void test264JupiterConflictNoShadowSyncBackSeparate() throws Exception {
final String TEST_NAME = "test264JupiterConflictNoShadowSyncBackSeparate";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestIteration.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
dummyAuditService.clear();
// Make sure there is a conflicting account and NO shadow for it
DummyAccount account = new DummyAccount(ACCOUNT_JUPITER_DUMMY_FUCHSIA_USERNAME); // Jupiter Jones
account.setEnabled(true);
account.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_AD_SAM_ACCOUNT_NAME_NAME, USER_JUPITER_NAME); // jupiter
dummyResourceFuchsia.addAccount(account);
Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<>();
deltas.add(createAccountAssignmentUserDelta(jupiterUserOid, RESOURCE_DUMMY_FUCHSIA_OID, "default", true));
// WHEN
TestUtil.displayWhen(TEST_NAME);
modelService.executeChanges(deltas, null, task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);
PrismObject<UserType> userJupiterAfter = findUserByUsername(USER_JUPITER_NAME); // jupiter
display("User after change execution", userJupiterAfter);
assertUserJupiter(userJupiterAfter);
jupiterUserOid = userJupiterAfter.getOid();
String accountOid = getSingleLinkOid(userJupiterAfter);
// Check shadow
PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result);
display("Account shadow from repo", accountShadow);
assertAccountShadowRepo(accountShadow, accountOid, ACCOUNT_JUPITER_DUMMY_FUCHSIA_USERNAME, resourceDummyFuchsiaType);
// Check account
PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountOid, null, task, result);
assertAccountShadowModel(accountModel, accountOid, ACCOUNT_JUPITER_DUMMY_FUCHSIA_USERNAME, resourceDummyFuchsiaType);
// Check account in dummy resource (actually, the fullname attribute does not exist but it's OK)
assertDummyAccount(RESOURCE_DUMMY_FUCHSIA_NAME, ACCOUNT_JUPITER_DUMMY_FUCHSIA_USERNAME, null, true);
// TODO Check audit
display("Audit", dummyAuditService);
// dummyAuditService.assertRecords(3);
// dummyAuditService.assertSimpleRecordSanity();
// dummyAuditService.assertAnyRequestDeltas();
// dummyAuditService.assertExecutionDeltas(2);
// dummyAuditService.asserHasDelta(ChangeType.MODIFY, UserType.class);
// dummyAuditService.asserHasDelta(ChangeType.ADD, ShadowType.class);
// dummyAuditService.assertExecutionSuccess();
}
// remove the assignment, shadow and account to prepare for following tests
@Test
public void test266JupiterCleanupAgain() throws Exception {
final String TEST_NAME = "test266JupiterCleanupAgain";
cleanUpJupiter(TEST_NAME);
}
/**
* Doing the same as test264, but the conflicting account does not belong to the user being created
* (and causes another user to be added).
*/
@Test
public void test270JupiterConflictOtherNoShadowSyncBack() throws Exception {
final String TEST_NAME = "test270JupiterConflictOtherNoShadowSyncBack";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestIteration.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
dummyAuditService.clear();
// Make sure there is a conflicting account and NO shadow for it
DummyAccount account = new DummyAccount(ACCOUNT_JUPITER_DUMMY_FUCHSIA_USERNAME); // Jupiter Jones
account.setEnabled(true);
account.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_AD_SAM_ACCOUNT_NAME_NAME, "jupiter0"); // different from our jupiter
dummyResourceFuchsia.addAccount(account);
Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<>();
deltas.add(createAccountAssignmentUserDelta(jupiterUserOid, RESOURCE_DUMMY_FUCHSIA_OID, "default", true));
// WHEN
TestUtil.displayWhen(TEST_NAME);
modelService.executeChanges(deltas, null, task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);
PrismObject<UserType> userJupiterAfter = findUserByUsername(USER_JUPITER_NAME); // jupiter
display("User after change execution", userJupiterAfter);
assertUserJupiter(userJupiterAfter);
jupiterUserOid = userJupiterAfter.getOid();
String accountOid = getSingleLinkOid(userJupiterAfter);
// Check shadow & account
PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result);
display("Account shadow from repo", accountShadow);
PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountOid, null, task, result);
display("Account shadow from model", accountModel);
assertAccountShadowRepo(accountShadow, accountOid, "Jupiter Jones1", resourceDummyFuchsiaType);
assertAccountShadowModel(accountModel, accountOid, "Jupiter Jones1", resourceDummyFuchsiaType);
// Check account in dummy resource (actually, the fullname attribute does not exist but it's OK)
assertDummyAccount(RESOURCE_DUMMY_FUCHSIA_NAME, "Jupiter Jones1", null, true);
assertDummyAccountAttribute(RESOURCE_DUMMY_FUCHSIA_NAME, "Jupiter Jones1", DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_AD_SAM_ACCOUNT_NAME_NAME, "jupiter");
// Now check the other (newly created) user, jupiter0
PrismObject<UserType> userJupiter0 = findUserByUsername("jupiter0");
display("Newly created jupiter0 user", userJupiter0);
assertUser(userJupiter0, null, "jupiter0", "Jupiter Jones", null, null, null);
String accountOidJ0 = getSingleLinkOid(userJupiter0);
// Check shadow
PrismObject<ShadowType> accountShadowJ0 = repositoryService.getObject(ShadowType.class, accountOidJ0, null, result);
display("Account shadow from repo (jupiter0)", accountShadowJ0);
assertAccountShadowRepo(accountShadowJ0, accountOidJ0, "Jupiter Jones", resourceDummyFuchsiaType);
// Check account
PrismObject<ShadowType> accountModelJ0 = modelService.getObject(ShadowType.class, accountOidJ0, null, task, result);
assertAccountShadowModel(accountModelJ0, accountOidJ0, "Jupiter Jones", resourceDummyFuchsiaType);
// Check account in dummy resource (actually, the fullname attribute does not exist but it's OK)
assertDummyAccount(RESOURCE_DUMMY_FUCHSIA_NAME, "Jupiter Jones", null, true);
assertDummyAccountAttribute(RESOURCE_DUMMY_FUCHSIA_NAME, "Jupiter Jones", DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_AD_SAM_ACCOUNT_NAME_NAME, "jupiter0");
// TODO Check audit
display("Audit", dummyAuditService);
// dummyAuditService.assertRecords(3);
// dummyAuditService.assertSimpleRecordSanity();
// dummyAuditService.assertAnyRequestDeltas();
// dummyAuditService.assertExecutionDeltas(2);
// dummyAuditService.asserHasDelta(ChangeType.MODIFY, UserType.class);
// dummyAuditService.asserHasDelta(ChangeType.ADD, ShadowType.class);
// dummyAuditService.assertExecutionSuccess();
}
private void assertUserJupiter(PrismObject<UserType> user) {
assertUser(user, null, USER_JUPITER_NAME, "Jupiter Jones", "Jupiter", "Jones", null);
}
/**
* Same as test240 (conflict with no shadow), but including rename operation.
*/
@Test
public void test280RenameBobNoShadow() throws Exception {
final String TEST_NAME = "test280RenameBobNoShadow";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestIteration.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
PrismObject<UserType> userBob = createUser(USER_BOB_NAME, "Bob Andrews", true);
addObject(userBob);
String userBobOid = userBob.getOid();
// Make sure there is a conflicting account and NO shadow for it
DummyAccount account = new DummyAccount("bobby");
account.setEnabled(true);
account.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME, "Bobby Pinky");
dummyResourcePink.addAccount(account);
// preconditions
assertNoDummyAccount(RESOURCE_DUMMY_PINK_NAME, USER_BOB_NAME);
assertDummyAccount(RESOURCE_DUMMY_PINK_NAME, "bobby", "Bobby Pinky", true);
// prepare change
ObjectDelta<UserType> objectDelta = createAccountAssignmentUserDelta(userBobOid, RESOURCE_DUMMY_PINK_OID, "default", true);
objectDelta.addModification(createUserPropertyReplaceModification(UserType.F_NAME, new PolyString("bobby"))); // will conflict with Bobby Pinky
objectDelta.addModification(createUserPropertyReplaceModification(UserType.F_FULL_NAME, new PolyString("Bobby Andrews")));
Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<>();
deltas.add(objectDelta);
// WHEN
TestUtil.displayWhen(TEST_NAME);
modelService.executeChanges(deltas, null, task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
PrismObject<UserType> userBobAfter = getUser(userBobOid);
display("User after change execution", userBobAfter);
assertUser(userBobAfter, userBobOid, "bobby", "Bobby Andrews", null, null, null);
String accountOid = getSingleLinkOid(userBobAfter);
// Check shadow & account
PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result);
display("Account shadow from repo", accountShadow);
PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountOid, null, task, result);
display("Account shadow from model", accountModel);
assertAccountShadowRepo(accountShadow, accountOid, "bobby1", resourceDummyPinkType);
assertAccountShadowModel(accountModel, accountOid, "bobby1", resourceDummyPinkType);
// THEN
assertDummyAccount(RESOURCE_DUMMY_PINK_NAME, "bobby", "Bobby Pinky", true);
assertDummyAccount(RESOURCE_DUMMY_PINK_NAME, "bobby1", "Bobby Andrews", true);
assertNoDummyAccount(RESOURCE_DUMMY_PINK_NAME, "bob");
}
/**
* Same as test280 (conflict with no shadow with rename), but including synchronization.
*/
@Test
public void test282RenamePeterNoShadowSync() throws Exception {
final String TEST_NAME = "test282RenamePeterNoShadowSync";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestIteration.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
PrismObject<UserType> userPeter = createUser("peter", "Peter Crenshaw", true);
addObject(userPeter);
String userPeterOid = userPeter.getOid();
// Make sure there is a conflicting account and NO shadow for it
DummyAccount account = new DummyAccount("Pete Crenshaw"); // will conflict after rename
account.setEnabled(true);
account.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_AD_SAM_ACCOUNT_NAME_NAME, "pete0");
dummyResourceFuchsia.addAccount(account);
// preconditions
assertNoDummyAccount(RESOURCE_DUMMY_FUCHSIA_NAME, "Peter Crenshaw");
assertDummyAccount(RESOURCE_DUMMY_FUCHSIA_NAME, "Pete Crenshaw", null, true); // conflicting account (pete0)
// prepare change
ObjectDelta<UserType> objectDelta = createAccountAssignmentUserDelta(userPeterOid, RESOURCE_DUMMY_FUCHSIA_OID, "default", true);
objectDelta.addModification(createUserPropertyReplaceModification(UserType.F_NAME, new PolyString("pete")));
objectDelta.addModification(createUserPropertyReplaceModification(UserType.F_FULL_NAME, new PolyString("Pete Crenshaw")));
Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<>();
deltas.add(objectDelta);
// WHEN
TestUtil.displayWhen(TEST_NAME);
modelService.executeChanges(deltas, null, task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
PrismObject<UserType> userPeteAfter = getUser(userPeterOid);
display("User after change execution", userPeteAfter);
assertUser(userPeteAfter, userPeterOid, "pete", "Pete Crenshaw", null, null, null);
String accountOid = getSingleLinkOid(userPeteAfter);
// Check shadow & account
PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result);
display("Account shadow from repo", accountShadow);
PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountOid, null, task, result);
display("Account shadow from model", accountModel);
assertAccountShadowRepo(accountShadow, accountOid, "Pete Crenshaw1", resourceDummyFuchsiaType);
assertAccountShadowModel(accountModel, accountOid, "Pete Crenshaw1", resourceDummyFuchsiaType);
// Now check the other (newly created) user, pete0
PrismObject<UserType> userPete0 = findUserByUsername("pete0");
display("Newly created pete0 user", userPete0);
assertUser(userPete0, null, "pete0", "Pete Crenshaw", null, null, null);
String accountOidP0 = getSingleLinkOid(userPete0);
// Check shadow
PrismObject<ShadowType> accountShadowP0 = repositoryService.getObject(ShadowType.class, accountOidP0, null, result);
display("Account shadow from repo (pete0)", accountShadowP0);
assertAccountShadowRepo(accountShadowP0, accountOidP0, "Pete Crenshaw", resourceDummyFuchsiaType);
// Check account
PrismObject<ShadowType> accountModelP0 = modelService.getObject(ShadowType.class, accountOidP0, null, task, result);
display("Account shadow from model (pete0)", accountModelP0);
assertAccountShadowModel(accountModelP0, accountOidP0, "Pete Crenshaw", resourceDummyFuchsiaType);
// accounts on the resource
assertDummyAccount(RESOURCE_DUMMY_FUCHSIA_NAME, "Pete Crenshaw", null, true); // pete0
assertDummyAccountAttribute(RESOURCE_DUMMY_FUCHSIA_NAME, "Pete Crenshaw", DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_AD_SAM_ACCOUNT_NAME_NAME, "pete0");
assertDummyAccount(RESOURCE_DUMMY_FUCHSIA_NAME, "Pete Crenshaw1", null, true); // pete
assertDummyAccountAttribute(RESOURCE_DUMMY_FUCHSIA_NAME, "Pete Crenshaw1", DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_AD_SAM_ACCOUNT_NAME_NAME, "pete");
assertNoDummyAccount(RESOURCE_DUMMY_PINK_NAME, "peter");
}
// as with jupiter, but ADD instead of ASSIGN account
@Test
public void test290AlfredConflictNoShadowSyncBackAdd() throws Exception {
final String TEST_NAME = "test290AlfredConflictNoShadowSyncBackAdd";
TestUtil.displayTestTile(this, TEST_NAME);