-
Notifications
You must be signed in to change notification settings - Fork 188
/
ConsistencyTest.java
2638 lines (2028 loc) · 124 KB
/
ConsistencyTest.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.consistency;
import static com.evolveum.midpoint.test.IntegrationTestTools.assertAttributeNotNull;
import static com.evolveum.midpoint.test.IntegrationTestTools.assertNoRepoCache;
import static com.evolveum.midpoint.test.IntegrationTestTools.displayJaxb;
import static com.evolveum.midpoint.test.IntegrationTestTools.waitFor;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertFalse;
import static org.testng.AssertJUnit.assertNotNull;
import static org.testng.AssertJUnit.assertNull;
import static org.testng.AssertJUnit.assertTrue;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.namespace.QName;
import javax.xml.ws.Holder;
import com.evolveum.midpoint.common.refinery.RefinedResourceSchemaImpl;
import org.apache.commons.lang.StringUtils;
import org.opends.server.types.Entry;
import org.opends.server.util.EmbeddedUtils;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.context.ContextConfiguration;
import org.testng.AssertJUnit;
import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;
import org.w3c.dom.Element;
import com.evolveum.midpoint.model.api.ModelExecuteOptions;
import com.evolveum.midpoint.model.test.AbstractModelIntegrationTest;
import com.evolveum.midpoint.prism.Containerable;
import com.evolveum.midpoint.prism.Item;
import com.evolveum.midpoint.prism.ItemDefinition;
import com.evolveum.midpoint.prism.OriginType;
import com.evolveum.midpoint.prism.PrismContainer;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.PrismProperty;
import com.evolveum.midpoint.prism.PrismPropertyDefinition;
import com.evolveum.midpoint.prism.PrismPropertyValue;
import com.evolveum.midpoint.prism.PrismReference;
import com.evolveum.midpoint.prism.PrismReferenceValue;
import com.evolveum.midpoint.prism.crypto.EncryptionException;
import com.evolveum.midpoint.prism.delta.ChangeType;
import com.evolveum.midpoint.prism.delta.ContainerDelta;
import com.evolveum.midpoint.prism.delta.DiffUtil;
import com.evolveum.midpoint.prism.delta.ItemDelta;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.prism.delta.PropertyDelta;
import com.evolveum.midpoint.prism.delta.ReferenceDelta;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.prism.schema.SchemaRegistry;
import com.evolveum.midpoint.prism.util.PrismAsserts;
import com.evolveum.midpoint.prism.util.PrismTestUtil;
import com.evolveum.midpoint.prism.xnode.PrimitiveXNode;
import com.evolveum.midpoint.schema.DeltaConvertor;
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.SearchResultList;
import com.evolveum.midpoint.schema.SelectorOptions;
import com.evolveum.midpoint.schema.constants.ObjectTypes;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition;
import com.evolveum.midpoint.schema.processor.ResourceAttribute;
import com.evolveum.midpoint.schema.processor.ResourceAttributeContainer;
import com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition;
import com.evolveum.midpoint.schema.processor.ResourceSchema;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.result.OperationResultStatus;
import com.evolveum.midpoint.schema.util.MiscSchemaUtil;
import com.evolveum.midpoint.schema.util.ObjectQueryUtil;
import com.evolveum.midpoint.schema.util.ObjectTypeUtil;
import com.evolveum.midpoint.schema.util.ResourceTypeUtil;
import com.evolveum.midpoint.schema.util.SchemaTestConstants;
import com.evolveum.midpoint.schema.util.ShadowUtil;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.task.api.TaskManagerException;
import com.evolveum.midpoint.test.Checker;
import com.evolveum.midpoint.test.ldap.OpenDJController;
import com.evolveum.midpoint.test.util.MidPointAsserts;
import com.evolveum.midpoint.test.util.TestUtil;
import com.evolveum.midpoint.util.DOMUtil;
import com.evolveum.midpoint.util.JAXBUtil;
import com.evolveum.midpoint.util.exception.CommonException;
import com.evolveum.midpoint.util.exception.CommunicationException;
import com.evolveum.midpoint.util.exception.ConfigurationException;
import com.evolveum.midpoint.util.exception.ExpressionEvaluationException;
import com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException;
import com.evolveum.midpoint.util.exception.ObjectNotFoundException;
import com.evolveum.midpoint.util.exception.PolicyViolationException;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.exception.SecurityViolationException;
import com.evolveum.midpoint.util.exception.SystemException;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.api_types_3.PropertyReferenceListType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationStatusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentPolicyEnforcementType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AvailabilityStatusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.FailedOperationTypeType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFactory;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.OperationalStateType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceAttributeDefinitionType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SchemaHandlingType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SynchronizationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;
import com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ActivationCapabilityType;
import com.evolveum.prism.xml.ns._public.types_3.ItemPathType;
import com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType;
import com.evolveum.prism.xml.ns._public.types_3.RawType;
/**
* Consistency test suite. It tests consistency mechanisms. It works as end-to-end integration test accross all subsystems.
*
* @author Katarina Valalikova
*/
@ContextConfiguration(locations = { "classpath:ctx-consistency-test-main.xml" })
@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
public class ConsistencyTest extends AbstractModelIntegrationTest {
private static final String REPO_DIR_NAME = "src/test/resources/repo/";
private static final String REQUEST_DIR_NAME = "src/test/resources/request/";
private static final String SYSTEM_CONFIGURATION_FILENAME = REPO_DIR_NAME + "system-configuration.xml";
private static final String ROLE_SUPERUSER_FILENAME = REPO_DIR_NAME + "role-superuser.xml";
private static final String ROLE_SUPERUSER_OID = "00000000-0000-0000-0000-000000000004";
private static final String ROLE_LDAP_ADMINS_FILENAME = REPO_DIR_NAME + "role-admins.xml";
private static final String ROLE_LDAP_ADMINS_OID = "88888888-8888-8888-8888-000000000009";
private static final String SAMPLE_CONFIGURATION_OBJECT_FILENAME = REPO_DIR_NAME + "sample-configuration-object.xml";
private static final String SAMPLE_CONFIGURATION_OBJECT_OID = "c0c010c0-d34d-b33f-f00d-999111111111";
private static final String RESOURCE_OPENDJ_FILENAME = REPO_DIR_NAME + "resource-opendj.xml";
private static final String RESOURCE_OPENDJ_OID = "ef2bc95b-76e0-59e2-86d6-3d4f02d3ffff";
private static final String RESOURCE_OPENDJ_NS = "http://midpoint.evolveum.com/xml/ns/public/resource/instance-3";
private static final QName RESOURCE_OPENDJ_ACCOUNT_OBJECTCLASS = new QName(RESOURCE_OPENDJ_NS,"inetOrgPerson");
private static final QName RESOURCE_OPENDJ_GROUP_OBJECTCLASS = new QName(RESOURCE_OPENDJ_NS,"groupOfUniqueNames");
private static final String RESOURCE_OPENDJ_PRIMARY_IDENTIFIER_LOCAL_NAME = "entryUUID";
private static final String RESOURCE_OPENDJ_SECONDARY_IDENTIFIER_LOCAL_NAME = "dn";
private static final QName RESOURCE_OPENDJ_SECONDARY_IDENTIFIER = new QName(RESOURCE_OPENDJ_NS, RESOURCE_OPENDJ_SECONDARY_IDENTIFIER_LOCAL_NAME);
private static final String CONNECTOR_LDAP_NAMESPACE = "http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/bundle/com.evolveum.polygon.connector-ldap/com.evolveum.polygon.connector.ldap.LdapConnector";
private static final String USER_TEMPLATE_FILENAME = REPO_DIR_NAME + "user-template.xml";
private static final String USER_ADMINISTRATOR_FILENAME = REPO_DIR_NAME + "user-administrator.xml";
private static final String USER_ADMINISTRATOR_NAME = "administrator";
private static final String USER_JACK_FILENAME = REPO_DIR_NAME + "user-jack.xml";
private static final String USER_JACK_OID = "c0c010c0-d34d-b33f-f00d-111111111111";
private static final String USER_DENIELS_FILENAME = REPO_DIR_NAME + "user-deniels.xml";
private static final String USER_DENIELS_OID = "c0c010c0-d34d-b33f-f00d-222111111111";
private static final String USER_JACK2_FILENAME = REPO_DIR_NAME + "user-jack2.xml";
private static final String USER_JACK2_OID = "c0c010c0-d34d-b33f-f00d-111111114444";
private static final String USER_WILL_FILENAME = REPO_DIR_NAME + "user-will.xml";
private static final String USER_WILL_OID = "c0c010c0-d34d-b33f-f00d-111111115555";
private static final String USER_JACK_LDAP_UID = "jackie";
private static final String USER_JACK_LDAP_DN = "uid=" + USER_JACK_LDAP_UID + "," + OPENDJ_PEOPLE_SUFFIX;
private static final String USER_GUYBRUSH_FILENAME = REPO_DIR_NAME + "user-guybrush.xml";
private static final String USER_GUYBRUSH_OID = "c0c010c0-d34d-b33f-f00d-111111111222";
private static final String USER_GUYBRUSH_NOT_FOUND_FILENAME = REPO_DIR_NAME + "user-guybrush-modify-not-found.xml";
private static final String USER_GUYBRUSH_NOT_FOUND_OID = "c0c010c0-d34d-b33f-f00d-111111111333";
private static final String USER_HECTOR_NOT_FOUND_FILENAME = REPO_DIR_NAME + "user-hector.xml";
private static final String USER_HECTOR_NOT_FOUND_OID = "c0c010c0-d34d-b33f-f00d-111111222333";
private static final String USER_E_FILENAME = REPO_DIR_NAME + "user-e.xml";
private static final String USER_E_OID = "c0c010c0-d34d-b33f-f00d-111111111100";
private static final String USER_ELAINE_FILENAME = REPO_DIR_NAME + "user-elaine.xml";
private static final String USER_ELAINE_OID = "c0c010c0-d34d-b33f-f00d-111111116666";
private static final String USER_HERMAN_FILENAME = REPO_DIR_NAME + "user-herman.xml";
private static final String USER_HERMAN_OID = "c0c010c0-d34d-b33f-f00d-111111119999";
private static final String USER_MORGAN_FILENAME = REQUEST_DIR_NAME + "user-morgan.xml";
private static final String USER_MORGAN_OID = "c0c010c0-d34d-b33f-f00d-171171117777";
private static final String USER_CHUCK_FILENAME = REQUEST_DIR_NAME + "user-chuck.xml";
private static final String USER_CHUCK_OID = "c0c010c0-d34d-b33f-f00d-171171118888";
private static final String USER_ANGELIKA_FILENAME = REPO_DIR_NAME + "user-angelika.xml";
private static final String USER_ANGELIKA_OID = "c0c010c0-d34d-b33f-f00d-111111111888";
private static final String USER_ALICE_FILENAME = REPO_DIR_NAME + "user-alice.xml";
private static final String USER_ALICE_OID = "c0c010c0-d34d-b33f-f00d-111111111999";
private static final String USER_BOB_NO_GIVEN_NAME_FILENAME = REPO_DIR_NAME + "user-bob-no-given-name.xml";
private static final String USER_BOB_NO_GIVEN_NAME_OID = "c0c010c0-d34d-b33f-f00d-222111222999";
private static final String USER_JOHN_WEAK_FILENAME = REPO_DIR_NAME + "user-john.xml";
private static final String USER_JOHN_WEAK_OID = "c0c010c0-d34d-b33f-f00d-999111111888";
private static final String USER_DONALD_FILENAME = REPO_DIR_NAME + "user-donald.xml";
private static final String USER_DONALD_OID = "c0c010c0-d34d-b33f-f00d-999111111777";
private static final String USER_DISCOVERY_FILENAME = REPO_DIR_NAME + "user-discovery.xml";
private static final String USER_DISCOVERY_OID = "c0c010c0-d34d-b33f-f00d-111112226666";
private static final String USER_ABOMBA_FILENAME = REPO_DIR_NAME + "user-abomba.xml";
private static final String USER_ABOMBA_OID = "c0c010c0-d34d-b33f-f00d-016016111111";
private static final String USER_ABOM_FILENAME = REPO_DIR_NAME + "user-abom.xml";
private static final String USER_ABOM_OID = "c0c010c0-d34d-b33f-f00d-111111016016";
private static final File ACCOUNT_GUYBRUSH_FILE = new File(REPO_DIR_NAME, "account-guybrush.xml");
private static final String ACCOUNT_GUYBRUSH_OID = "a0c010c0-d34d-b33f-f00d-111111111222";
private static final File ACCOUNT_HECTOR_FILE = new File(REPO_DIR_NAME, "account-hector-not-found.xml");
private static final String ACCOUNT_HECTOR_OID = "a0c010c0-d34d-b33f-f00d-111111222333";
private static final File ACCOUNT_GUYBRUSH_MODIFY_DELETE_FILE = new File(REPO_DIR_NAME, "account-guybrush-not-found.xml");
private static final String ACCOUNT_GUYBRUSH_MODIFY_DELETE_OID = "a0c010c0-d34d-b33f-f00d-111111111333";
private static final String ACCOUNT_DENIELS_FILENAME = REPO_DIR_NAME + "account-deniels.xml";
private static final String ACCOUNT_DENIELS_OID = "a0c010c0-d34d-b33f-f00d-111111111555";
private static final String ACCOUNT_CHUCK_FILENAME = REPO_DIR_NAME + "account-chuck.xml";
private static final String ACCOUNT_HERMAN_FILENAME = REPO_DIR_NAME + "account-herman.xml";
private static final String ACCOUNT_HERMAN_OID = "22220000-2200-0000-0000-333300003333";
private static final String REQUEST_USER_MODIFY_ASSIGN_ACCOUNT = "src/test/resources/request/user-modify-assign-account.xml";
private static final String REQUEST_USER_MODIFY_ADD_ACCOUNT_DIRECTLY = "src/test/resources/request/user-modify-add-account-directly.xml";
private static final String REQUEST_USER_MODIFY_DELETE_ACCOUNT = "src/test/resources/request/user-modify-delete-account.xml";
private static final String REQUEST_USER_MODIFY_DELETE_ACCOUNT_COMMUNICATION_PROBLEM = "src/test/resources/request/user-modify-delete-account-communication-problem.xml";
private static final String REQUEST_USER_MODIFY_ASSIGN_ROLE_ADMINS = "src/test/resources/request/user-modify-assign-role-admin.xml";
private static final String REQUEST_ACCOUNT_MODIFY_NOT_FOUND_DELETE_ACCOUNT = "src/test/resources/request/account-guybrush-modify-attributes.xml";
private static final String REQUEST_ACCOUNT_MODIFY_COMMUNICATION_PROBLEM = "src/test/resources/request/account-modify-attrs-communication-problem.xml";
private static final String REQUEST_ADD_ACCOUNT_JACKIE = "src/test/resources/request/add-account-jack.xml";
private static final String REQUEST_USER_MODIFY_WEAK_MAPPING_COMMUNICATION_PROBLEM = "src/test/resources/request/user-modify-employeeType.xml";
private static final String REQUEST_USER_MODIFY_WEAK_STRONG_MAPPING_COMMUNICATION_PROBLEM = "src/test/resources/request/user-modify-employeeType-givenName.xml";
private static final String REQUEST_RESOURCE_MODIFY_RESOURCE_SCHEMA = "src/test/resources/request/resource-modify-resource-schema.xml";
private static final String REQUEST_RESOURCE_MODIFY_SYNCHRONIZATION = "src/test/resources/request/resource-modify-synchronization.xml";
private static final String REQUEST_USER_MODIFY_CHANGE_PASSWORD_1 = "src/test/resources/request/user-modify-change-password-1.xml";
private static final String REQUEST_USER_MODIFY_CHANGE_PASSWORD_2 = "src/test/resources/request/user-modify-change-password-2.xml";
private static final String TASK_OPENDJ_RECONCILIATION_FILENAME = "src/test/resources/repo/task-opendj-reconciliation.xml";
private static final String TASK_OPENDJ_RECONCILIATION_OID = "91919191-76e0-59e2-86d6-3d4f02d30000";
private static final String LDIF_WILL_FILENAME = "src/test/resources/request/will.ldif";
private static final String LDIF_ELAINE_FILENAME = "src/test/resources/request/elaine.ldif";
private static final String LDIF_MORGAN_FILENAME = "src/test/resources/request/morgan.ldif";
private static final String LDIF_DISCOVERY_FILENAME = "src/test/resources/request/discovery.ldif";
private static final String LDIF_CREATE_USERS_OU_FILENAME = "src/test/resources/request/usersOu.ldif";
private static final String LDIF_CREATE_ADMINS_GROUP_FILENAME = "src/test/resources/request/adminsGroup.ldif";
private static final String LDIF_MODIFY_RENAME_FILENAME = "src/test/resources/request/modify-rename.ldif";
private static final Trace LOGGER = TraceManager.getTrace(ConsistencyTest.class);
private static final String NS_MY = "http://whatever.com/my";
private static final QName MY_SHIP_STATE = new QName(NS_MY, "shipState");
private static ResourceType resourceTypeOpenDjrepo;
private static String accountShadowOidOpendj;
private String aliceAccountDn;
// This will get called from the superclass to init the repository
// It will be called only once
public void initSystem(Task initTask, OperationResult initResult) throws Exception {
LOGGER.trace("initSystem");
super.initSystem(initTask, initResult);
repoAddObjectFromFile(ROLE_SUPERUSER_FILENAME, initResult);
repoAddObjectFromFile(ROLE_LDAP_ADMINS_FILENAME, initResult);
repoAddObjectFromFile(USER_ADMINISTRATOR_FILENAME, initResult);
// This should discover the connectors
LOGGER.trace("initSystem: trying modelService.postInit()");
modelService.postInit(initResult);
LOGGER.trace("initSystem: modelService.postInit() done");
login(USER_ADMINISTRATOR_NAME);
// We need to add config after calling postInit() so it will not be applied.
// we want original logging configuration from the test logback config file, not
// the one from the system config.
repoAddObjectFromFile(SYSTEM_CONFIGURATION_FILENAME, initResult);
// Need to import instead of add, so the (dynamic) connector reference
// will be resolved correctly
importObjectFromFile(RESOURCE_OPENDJ_FILENAME, initResult);
repoAddObjectFromFile(SAMPLE_CONFIGURATION_OBJECT_FILENAME, initResult);
repoAddObjectFromFile(USER_TEMPLATE_FILENAME, initResult);
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.POSITIVE);
// DebugUtil.setDetailedDebugDump(true);
}
/**
* Initialize embedded OpenDJ instance Note: this is not in the abstract
* superclass so individual tests may avoid starting OpenDJ.
*/
@Override
public void startResources() throws Exception {
openDJController.startCleanServer();
}
/**
* Shutdown embedded OpenDJ instance Note: this is not in the abstract
* superclass so individual tests may avoid starting OpenDJ.
*/
@AfterClass
public static void stopResources() throws Exception {
openDJController.stop();
}
/**
* Test integrity of the test setup.
*/
@Test
public void test000Integrity() throws Exception {
final String TEST_NAME = "test000Integrity";
displayTestTitle(TEST_NAME);
assertNotNull(modelWeb);
assertNotNull(modelService);
assertNotNull(repositoryService);
assertTrue(isSystemInitialized());
assertNotNull(taskManager);
assertNotNull(prismContext);
SchemaRegistry schemaRegistry = prismContext.getSchemaRegistry();
assertNotNull(schemaRegistry);
// This is defined in extra schema. So this effectively checks whether
// the extra schema was loaded
PrismPropertyDefinition shipStateDefinition = schemaRegistry
.findPropertyDefinitionByElementName(MY_SHIP_STATE);
assertNotNull("No my:shipState definition", shipStateDefinition);
assertEquals("Wrong maxOccurs in my:shipState definition", 1, shipStateDefinition.getMaxOccurs());
assertNoRepoCache();
OperationResult result = new OperationResult(ConsistencyTest.class.getName() + "." + TEST_NAME);
// Check if OpenDJ resource was imported correctly
PrismObject<ResourceType> openDjResource = repositoryService.getObject(ResourceType.class,
RESOURCE_OPENDJ_OID, null, result);
display("Imported OpenDJ resource (repository)", openDjResource);
AssertJUnit.assertEquals(RESOURCE_OPENDJ_OID, openDjResource.getOid());
assertNoRepoCache();
String ldapConnectorOid = openDjResource.asObjectable().getConnectorRef().getOid();
PrismObject<ConnectorType> ldapConnector = repositoryService.getObject(ConnectorType.class,
ldapConnectorOid, null, result);
display("LDAP Connector: ", ldapConnector);
}
/**
* Test the testResource method. Expect a complete success for now.
*/
@Test
public void test001TestConnectionOpenDJ() throws Exception {
final String TEST_NAME = "test001TestConnectionOpenDJ";
TestUtil.displayTestTitle(TEST_NAME);
Task task = taskManager.createTaskInstance();
// GIVEN
assertNoRepoCache();
// WHEN
OperationResultType result = modelWeb.testResource(RESOURCE_OPENDJ_OID);
// THEN
assertNoRepoCache();
displayJaxb("testResource result:", result, SchemaConstants.C_RESULT);
TestUtil.assertSuccess("testResource has failed", result);
OperationResult opResult = new OperationResult(ConsistencyTest.class.getName()
+ "." + TEST_NAME);
PrismObject<ResourceType> resourceOpenDjRepo = repositoryService.getObject(ResourceType.class,
RESOURCE_OPENDJ_OID, null, opResult);
resourceTypeOpenDjrepo = resourceOpenDjRepo.asObjectable();
assertNoRepoCache();
assertEquals(RESOURCE_OPENDJ_OID, resourceTypeOpenDjrepo.getOid());
display("Initialized OpenDJ resource (respository)", resourceTypeOpenDjrepo);
assertNotNull("Resource schema was not generated", resourceTypeOpenDjrepo.getSchema());
Element resourceOpenDjXsdSchemaElement = ResourceTypeUtil
.getResourceXsdSchema(resourceTypeOpenDjrepo);
assertNotNull("Resource schema was not generated", resourceOpenDjXsdSchemaElement);
PrismObject<ResourceType> openDjResourceProvisioninig = provisioningService.getObject(
ResourceType.class, RESOURCE_OPENDJ_OID, null, task, opResult);
display("Initialized OpenDJ resource resource (provisioning)", openDjResourceProvisioninig);
PrismObject<ResourceType> openDjResourceModel = provisioningService.getObject(ResourceType.class,
RESOURCE_OPENDJ_OID, null, task, opResult);
display("Initialized OpenDJ resource OpenDJ resource (model)", openDjResourceModel);
checkOpenDjResource(resourceTypeOpenDjrepo, "repository");
System.out.println("------------------------------------------------------------------");
display("OpenDJ resource schema (repo XML)",
DOMUtil.serializeDOMToString(ResourceTypeUtil.getResourceXsdSchema(resourceOpenDjRepo)));
System.out.println("------------------------------------------------------------------");
checkOpenDjResource(openDjResourceProvisioninig.asObjectable(), "provisioning");
checkOpenDjResource(openDjResourceModel.asObjectable(), "model");
// TODO: model web
}
/**
* Attempt to add new user. It is only added to the repository, so check if
* it is in the repository after the operation.
*/
@Test
public void test100AddUser() throws Exception {
final String TEST_NAME = "test100AddUser";
UserType userType = testAddUserToRepo(TEST_NAME, USER_JACK_FILENAME, USER_JACK_OID);
OperationResult repoResult = new OperationResult("getObject");
PropertyReferenceListType resolve = new PropertyReferenceListType();
PrismObject<UserType> uObject = repositoryService
.getObject(UserType.class, USER_JACK_OID, null, repoResult);
UserType repoUser = uObject.asObjectable();
repoResult.computeStatus();
display("repository.getObject result", repoResult);
TestUtil.assertSuccess("getObject has failed", repoResult);
AssertJUnit.assertEquals(USER_JACK_OID, repoUser.getOid());
PrismAsserts.assertEqualsPolyString("User full name not equals as expected.", userType.getFullName(),
repoUser.getFullName());
// TODO: better checks
}
/**
* Add account to user. This should result in account provisioning. Check if
* that happens in repo and in LDAP.
*/
@Test
public void test110PrepareOpenDjWithAccounts() throws Exception {
final String TEST_NAME = "test110PrepareOpenDjWithAccounts";
TestUtil.displayTestTitle(TEST_NAME);
OperationResult parentResult = new OperationResult(TEST_NAME);
ShadowType jackeAccount = unmarshallValueFromFile(REQUEST_ADD_ACCOUNT_JACKIE,
ShadowType.class);
Task task = taskManager.createTaskInstance();
String oid = provisioningService.addObject(jackeAccount.asPrismObject(), null, null, task, parentResult);
PrismObject<ShadowType> jackFromRepo = repositoryService.getObject(ShadowType.class,
oid, null, parentResult);
LOGGER.debug("account jack after provisioning: {}", jackFromRepo.debugDump());
PrismObject<UserType> jackUser = repositoryService.getObject(UserType.class, USER_JACK_OID,
null, parentResult);
ObjectReferenceType ort = new ObjectReferenceType();
ort.setOid(oid);
ort.setType(ShadowType.COMPLEX_TYPE);
jackUser.asObjectable().getLinkRef().add(ort);
PrismObject<UserType> jackUserRepo = repositoryService.getObject(UserType.class, USER_JACK_OID,
null, parentResult);
ObjectDelta delta = DiffUtil.diff(jackUserRepo, jackUser);
repositoryService.modifyObject(UserType.class, USER_JACK_OID, delta.getModifications(), parentResult);
// GIVEN
OperationResult repoResult = new OperationResult("getObject");
// Check if user object was modified in the repo
accountShadowOidOpendj = assertUserOneAccountRef(USER_JACK_OID);
assertFalse(accountShadowOidOpendj.isEmpty());
// Check if shadow was created in the repo
repoResult = new OperationResult("getObject");
PrismObject<ShadowType> repoShadow = repositoryService.getObject(ShadowType.class,
accountShadowOidOpendj, null, repoResult);
ShadowType repoShadowType = repoShadow.asObjectable();
repoResult.computeStatus();
TestUtil.assertSuccess("getObject has failed", repoResult);
display("Shadow (repository)", repoShadow);
assertNotNull(repoShadowType);
assertEquals(RESOURCE_OPENDJ_OID, repoShadowType.getResourceRef().getOid());
assertNotNull("Shadow stored in repository has no name", repoShadowType.getName());
// Check the "name" property, it should be set to DN, not entryUUID
assertEquals("Wrong name property", USER_JACK_LDAP_DN.toLowerCase(), repoShadowType.getName()
.getOrig().toLowerCase());
// check attributes in the shadow: should be only identifiers (ICF UID)
String uid = checkRepoShadow(repoShadow);
// check if account was created in LDAP
Entry entry = openDJController.searchAndAssertByEntryUuid(uid);
display("LDAP account", entry);
OpenDJController.assertAttribute(entry, "uid", "jackie");
OpenDJController.assertAttribute(entry, "givenName", "Jack");
OpenDJController.assertAttribute(entry, "sn", "Sparrow");
OpenDJController.assertAttribute(entry, "cn", "Jack Sparrow");
assertNoRepoCache();
Holder<OperationResultType> resultHolder = new Holder<OperationResultType>();
Holder<ObjectType> objectHolder = new Holder<ObjectType>();
// WHEN
PropertyReferenceListType resolve = new PropertyReferenceListType();
// List<ObjectOperationOptions> options = new ArrayList<ObjectOperationOptions>();
modelWeb.getObject(ObjectTypes.SHADOW.getTypeQName(), accountShadowOidOpendj, null,
objectHolder, resultHolder);
// THEN
assertNoRepoCache();
displayJaxb("getObject result", resultHolder.value, SchemaConstants.C_RESULT);
TestUtil.assertSuccess("getObject has failed", resultHolder.value);
ShadowType modelShadow = (ShadowType) objectHolder.value;
display("Shadow (model)", modelShadow);
AssertJUnit.assertNotNull(modelShadow);
AssertJUnit.assertEquals(RESOURCE_OPENDJ_OID, modelShadow.getResourceRef().getOid());
assertAttributeNotNull(modelShadow, getOpenDjPrimaryIdentifierQName());
assertAttributes(modelShadow, "jackie", "Jack", "Sparrow", "Jack Sparrow");
// "middle of nowhere");
assertNull("carLicense attribute sneaked to LDAP",
OpenDJController.getAttributeValue(entry, "carLicense"));
assertNotNull("Activation is null", modelShadow.getActivation());
assertNotNull("No 'enabled' in the shadow", modelShadow.getActivation().getAdministrativeStatus());
assertEquals("The account is not enabled in the shadow", ActivationStatusType.ENABLED, modelShadow.getActivation().getAdministrativeStatus());
TestUtil.displayTestTitle("test013prepareOpenDjWithAccounts - add second account");
OperationResult secondResult = new OperationResult(
"test013prepareOpenDjWithAccounts - add second account");
ShadowType shadow = unmarshallValueFromFile(ACCOUNT_DENIELS_FILENAME, ShadowType.class);
provisioningService.addObject(shadow.asPrismObject(), null, null, task, secondResult);
repoAddObjectFromFile(USER_DENIELS_FILENAME, secondResult);
}
@Test
public void test120AddAccountAlreadyExistLinked() throws Exception {
final String TEST_NAME = "test120AddAccountAlreadyExistLinked";
TestUtil.displayTestTitle(TEST_NAME);
Task task = taskManager.createTaskInstance();
// GIVEN
OperationResult parentResult = new OperationResult("Add account already exist linked");
testAddUserToRepo("test014testAssAccountAlreadyExistLinked", USER_JACK2_FILENAME, USER_JACK2_OID);
assertUserNoAccountRef(USER_JACK2_OID, parentResult);
// //check if the jackie account already exists on the resource
String accountRef = assertUserOneAccountRef(USER_JACK_OID);
PrismObject<ShadowType> jackUserAccount = repositoryService.getObject(ShadowType.class, accountRef, null, parentResult);
display("Jack's account: ", jackUserAccount.debugDump());
// WHEN REQUEST_USER_MODIFY_ADD_ACCOUNT_ALERADY_EXISTS_LINKED_OPENDJ_FILENAME
requestToExecuteChanges(REQUEST_USER_MODIFY_ASSIGN_ACCOUNT, USER_JACK2_OID, UserType.class, task, null, parentResult);
// THEN
//expected thet the dn and ri:uid will be jackie1 because jackie already exists and is liked to another user..
String accountOid = checkUser(USER_JACK2_OID, task, parentResult);
checkAccount(accountOid, "jackie1", "Jack", "Russel", "Jack Russel", task, parentResult);
}
@Test
public void test122AddAccountAlreadyExistUnlinked() throws Exception {
final String TEST_NAME = "test122AddAccountAlreadyExistUnlinked";
TestUtil.displayTestTitle(TEST_NAME);
// GIVEN
OperationResult parentResult = new OperationResult("Add account already exist unlinked.");
Entry entry = openDJController.addEntryFromLdifFile(LDIF_WILL_FILENAME);
Entry searchResult = openDJController.searchByUid("wturner");
OpenDJController.assertAttribute(searchResult, "l", "Caribbean");
OpenDJController.assertAttribute(searchResult, "givenName", "Will");
OpenDJController.assertAttribute(searchResult, "sn", "Turner");
OpenDJController.assertAttribute(searchResult, "cn", "Will Turner");
OpenDJController.assertAttribute(searchResult, "mail", "will.turner@blackpearl.com");
OpenDJController.assertAttribute(searchResult, "telephonenumber", "+1 408 555 1234");
OpenDJController.assertAttribute(searchResult, "facsimiletelephonenumber", "+1 408 555 4321");
String dn = searchResult.getDN().toString();
assertEquals("DN attribute " + dn + " not equals", dn, "uid=wturner,ou=People,dc=example,dc=com");
testAddUserToRepo("add user - test015 account already exist unlinked", USER_WILL_FILENAME,
USER_WILL_OID);
assertUserNoAccountRef(USER_WILL_OID, parentResult);
Task task = taskManager.createTaskInstance();
//WHEN
TestUtil.displayWhen(TEST_NAME);
requestToExecuteChanges(REQUEST_USER_MODIFY_ASSIGN_ACCOUNT, USER_WILL_OID, UserType.class, task, null, parentResult);
// THEN
TestUtil.displayThen(TEST_NAME);
String accountOid = checkUser(USER_WILL_OID, task, parentResult);
// MidPointAsserts.assertAssignments(user, 1);
PrismObject<ShadowType> account = provisioningService.getObject(ShadowType.class,
accountOid, null, task, parentResult);
ResourceAttributeContainer attributes = ShadowUtil.getAttributesContainer(account);
assertEquals("shadow secondary identifier not equal with the account dn. ", dn, attributes
.findAttribute(getOpenDjSecondaryIdentifierQName()).getRealValue(String.class));
String identifier = attributes.getPrimaryIdentifier().getRealValue(String.class);
openDJController.searchAndAssertByEntryUuid(identifier);
}
//MID-1595, MID-1577
@Test
public void test124AddAccountDirectAlreadyExists() throws Exception {
final String TEST_NAME = "test124AddAccountDirectAlreadyExists";
TestUtil.displayTestTitle(TEST_NAME);
OperationResult parentResult = new OperationResult(TEST_NAME);
Task task = taskManager.createTaskInstance();
SchemaHandlingType oldSchemaHandling = resourceTypeOpenDjrepo
.getSchemaHandling();
SynchronizationType oldSynchronization = resourceTypeOpenDjrepo
.getSynchronization();
try {
// we will reapply this schema handling after this test finish
ItemDefinition syncDef = resourceTypeOpenDjrepo.asPrismObject().getDefinition().findItemDefinition(ResourceType.F_SYNCHRONIZATION);
assertNotNull("null definition for sync delta", syncDef);
ObjectDeltaType omt = unmarshallValueFromFile(REQUEST_RESOURCE_MODIFY_SYNCHRONIZATION, ObjectDeltaType.class);
ObjectDelta objectDelta = DeltaConvertor.createObjectDelta(omt, prismContext);
repositoryService.modifyObject(ResourceType.class, RESOURCE_OPENDJ_OID, objectDelta.getModifications(), parentResult);
requestToExecuteChanges(REQUEST_RESOURCE_MODIFY_RESOURCE_SCHEMA,
RESOURCE_OPENDJ_OID, ResourceType.class, task, null,
parentResult);
PrismObject<ResourceType> res = repositoryService
.getObject(ResourceType.class, RESOURCE_OPENDJ_OID, null,
parentResult);
// LOGGER.trace("resource schema handling after modify: {}",
// prismContext.silentMarshalObject(res.asObjectable(), LOGGER));
repoAddObjectFromFile(USER_ABOMBA_FILENAME,
parentResult);
requestToExecuteChanges(REQUEST_USER_MODIFY_ADD_ACCOUNT_DIRECTLY,
USER_ABOMBA_OID, UserType.class, task, null, parentResult);
String abombaOid = assertUserOneAccountRef(USER_ABOMBA_OID);
ShadowType abombaShadow = repositoryService.getObject(
ShadowType.class, abombaOid, null, parentResult)
.asObjectable();
assertShadowName(abombaShadow,
"uid=abomba,OU=people,DC=example,DC=com");
repoAddObjectFromFile(USER_ABOM_FILENAME,
parentResult);
requestToExecuteChanges(REQUEST_USER_MODIFY_ADD_ACCOUNT_DIRECTLY,
USER_ABOM_OID, UserType.class, task, null, parentResult);
String abomOid = assertUserOneAccountRef(USER_ABOM_OID);
ShadowType abomShadow = repositoryService.getObject(
ShadowType.class, abomOid, null, parentResult)
.asObjectable();
assertShadowName(abomShadow,
"uid=abomba1,OU=people,DC=example,DC=com");
ReferenceDelta abombaDeleteAccDelta = ReferenceDelta
.createModificationDelete(ShadowType.class,
UserType.F_LINK_REF, prismContext,
new PrismReferenceValue(abombaOid));
ObjectDelta d = ObjectDelta.createModifyDelta(USER_ABOMBA_OID,
abombaDeleteAccDelta, UserType.class, prismContext);
modelService.executeChanges(MiscSchemaUtil.createCollection(d), null, task,
parentResult);
assertUserNoAccountRef(USER_ABOMBA_OID, parentResult);
repositoryService.getObject(ShadowType.class, abombaOid, null,
parentResult);
ReferenceDelta abomDeleteAccDelta = ReferenceDelta
.createModificationDelete(ShadowType.class,
UserType.F_LINK_REF, prismContext,
abomShadow.asPrismObject());
ObjectDelta d2 = ObjectDelta.createModifyDelta(USER_ABOM_OID,
abomDeleteAccDelta, UserType.class, prismContext);
modelService.executeChanges(MiscSchemaUtil.createCollection(d2), null, task,
parentResult);
assertUserNoAccountRef(USER_ABOM_OID, parentResult);
try {
repositoryService.getObject(ShadowType.class, abomOid, null,
parentResult);
fail("Expected that shadow abom does not exist, but it is");
} catch (ObjectNotFoundException ex) {
// this is expected
} catch (Exception ex) {
fail("Expected object not found exception but got " + ex);
}
LOGGER.info("starting second execution request for user abomba");
OperationResult result = new OperationResult("Add account already exist result.");
requestToExecuteChanges(REQUEST_USER_MODIFY_ADD_ACCOUNT_DIRECTLY,
USER_ABOMBA_OID, UserType.class, task, null, result);
String abombaOid2 = assertUserOneAccountRef(USER_ABOMBA_OID);
ShadowType abombaShadow2 = repositoryService.getObject(
ShadowType.class, abombaOid2, null, result)
.asObjectable();
assertShadowName(abombaShadow2,
"uid=abomba,OU=people,DC=example,DC=com");
result.computeStatus();
LOGGER.info("Displaying execute changes result");
display(result);
// return the previous changes of resource back
Collection<? extends ItemDelta> schemaHandlingDelta = ContainerDelta
.createModificationReplaceContainerCollection(
ResourceType.F_SCHEMA_HANDLING,
resourceTypeOpenDjrepo.asPrismObject()
.getDefinition(), oldSchemaHandling.asPrismContainerValue().clone());
PropertyDelta syncDelta = PropertyDelta
.createModificationReplaceProperty(
ResourceType.F_SYNCHRONIZATION,
resourceTypeOpenDjrepo.asPrismObject()
.getDefinition(), oldSynchronization);
((Collection) schemaHandlingDelta).add(syncDelta);
repositoryService.modifyObject(ResourceType.class,
RESOURCE_OPENDJ_OID, schemaHandlingDelta, parentResult);
} catch (Exception ex) {
LOGGER.info("error: " + ex.getMessage(), ex);
throw ex;
}
}
@Test
public void test130DeleteObjectNotFound() throws Exception {
final String TEST_NAME = "test130DeleteObjectNotFound";
TestUtil.displayTestTitle(TEST_NAME);
OperationResult parentResult = new OperationResult(TEST_NAME);
repoAddShadowFromFile(ACCOUNT_GUYBRUSH_FILE, parentResult);
repoAddObjectFromFile(USER_GUYBRUSH_FILENAME, parentResult);
Task task = taskManager.createTaskInstance();
requestToExecuteChanges(REQUEST_USER_MODIFY_DELETE_ACCOUNT, USER_GUYBRUSH_OID, UserType.class, task, null, parentResult);
// WHEN
ObjectDelta deleteDelta = ObjectDelta.createDeleteDelta(ShadowType.class, ACCOUNT_GUYBRUSH_OID, prismContext);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(deleteDelta);
modelService.executeChanges(deltas, null, task, parentResult);
try {
repositoryService.getObject(ShadowType.class, ACCOUNT_GUYBRUSH_OID, null, parentResult);
} catch (Exception ex) {
if (!(ex instanceof ObjectNotFoundException)) {
fail("Expected ObjectNotFoundException but got " + ex);
}
}
assertUserNoAccountRef(USER_GUYBRUSH_OID, parentResult);
repositoryService.deleteObject(UserType.class, USER_GUYBRUSH_OID, parentResult);
}
/**
* Modify account not found => reaction: Delete account
*/
@SuppressWarnings("unchecked")
@Test
public void test140ModifyObjectNotFound() throws Exception {
final String TEST_NAME = "test140ModifyObjectNotFound";
TestUtil.displayTestTitle(TEST_NAME);
OperationResult result = new OperationResult(TEST_NAME);
repoAddShadowFromFile(ACCOUNT_GUYBRUSH_FILE, result);
repoAddObjectFromFile(USER_GUYBRUSH_FILENAME, result);
assertUserOneAccountRef(USER_GUYBRUSH_OID);
Task task = taskManager.createTaskInstance();
// WHEN
requestToExecuteChanges(REQUEST_ACCOUNT_MODIFY_NOT_FOUND_DELETE_ACCOUNT, ACCOUNT_GUYBRUSH_OID, ShadowType.class, task, null, result);
// THEN
try {
repositoryService.getObject(ShadowType.class, ACCOUNT_GUYBRUSH_OID, null, result);
fail("Expected ObjectNotFound but did not get one.");
} catch (Exception ex) {
if (!(ex instanceof ObjectNotFoundException)) {
fail("Expected ObjectNotFoundException but got " + ex);
}
}
assertUserNoAccountRef(USER_GUYBRUSH_OID, result);
repositoryService.deleteObject(UserType.class, USER_GUYBRUSH_OID, result);
}
/**
* Modify account not found => reaction: Re-create account, apply changes.
*/
@Test
public void test142ModifyObjectNotFoundAssignedAccount() throws Exception {
final String TEST_NAME = "test142ModifyObjectNotFoundAssignedAccount";
TestUtil.displayTestTitle(TEST_NAME);
// GIVEN
OperationResult parentResult = new OperationResult(TEST_NAME);
repoAddShadowFromFile(ACCOUNT_GUYBRUSH_MODIFY_DELETE_FILE, parentResult);
repoAddObjectFromFile(USER_GUYBRUSH_NOT_FOUND_FILENAME, parentResult);
assertUserOneAccountRef(USER_GUYBRUSH_NOT_FOUND_OID);
Task task = taskManager.createTaskInstance();
//WHEN
TestUtil.displayWhen(TEST_NAME);
requestToExecuteChanges(REQUEST_ACCOUNT_MODIFY_NOT_FOUND_DELETE_ACCOUNT, ACCOUNT_GUYBRUSH_MODIFY_DELETE_OID, ShadowType.class, task, null, parentResult);
// THEN
TestUtil.displayThen(TEST_NAME);
String accountOid = assertUserOneAccountRef(USER_GUYBRUSH_NOT_FOUND_OID);
PrismObject<ShadowType> modifiedAccount = provisioningService.getObject(
ShadowType.class, accountOid, null, task, parentResult);
assertNotNull(modifiedAccount);
display("Modified shadow", modifiedAccount);
assertShadowName(modifiedAccount.asObjectable(), "uid=guybrush123,ou=people,dc=example,dc=com");
// PrismAsserts.assertEqualsPolyString("Wrong shadow name", "uid=guybrush123,ou=people,dc=example,dc=com", modifiedAccount.asObjectable().getName());
ResourceAttributeContainer attributeContainer = ShadowUtil
.getAttributesContainer(modifiedAccount);
assertAttribute(modifiedAccount.asObjectable(),
new QName(ResourceTypeUtil.getResourceNamespace(resourceTypeOpenDjrepo), "roomNumber"),
"cabin");
assertNotNull(attributeContainer.findProperty(new QName(ResourceTypeUtil
.getResourceNamespace(resourceTypeOpenDjrepo), "businessCategory")));
}
/**
* Get account not found => reaction: Re-create account, return re-created.
*/
@Test
public void test144GetObjectNotFoundAssignedAccount() throws Exception {
final String TEST_NAME = "test144GetObjectNotFoundAssignedAccount";
TestUtil.displayTestTitle(TEST_NAME);
// GIVEN
OperationResult parentResult = new OperationResult(TEST_NAME);
repoAddShadowFromFile(ACCOUNT_HECTOR_FILE, parentResult);
repoAddObjectFromFile(USER_HECTOR_NOT_FOUND_FILENAME, parentResult);
assertUserOneAccountRef(USER_HECTOR_NOT_FOUND_OID);
Task task = taskManager.createTaskInstance();
//WHEN
PrismObject<UserType> modificatedUser = modelService.getObject(UserType.class, USER_HECTOR_NOT_FOUND_OID, null, task, parentResult);
// THEN
String accountOid = assertOneAccountRef(modificatedUser);
PrismObject<ShadowType> modifiedAccount = modelService.getObject(ShadowType.class, accountOid, null, task, parentResult);
assertNotNull(modifiedAccount);
assertShadowName(modifiedAccount.asObjectable(), "uid=hector,ou=people,dc=example,dc=com");
}
/**
* Recompute user => account not found => reaction: Re-create account
* MID-3093
*/
@Test
public void test150RecomputeUserAccountNotFound() throws Exception {
final String TEST_NAME = "test150RecomputeUserAccountNotFound";
TestUtil.displayTestTitle(TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TEST_NAME);
OperationResult result = task.getResult();
PrismObject<UserType> userGuybrushFromFile = PrismTestUtil.parseObject(new File(USER_GUYBRUSH_FILENAME));
userGuybrushFromFile.asObjectable().getLinkRef().clear();
repoAddObject(userGuybrushFromFile, result);
assignAccount(USER_GUYBRUSH_OID, RESOURCE_OPENDJ_OID, null);
PrismObject<UserType> userBefore = getUser(USER_GUYBRUSH_OID);
display("User before", userBefore);
String accountShadowOid = assertOneAccountRef(userBefore);
PrismObject<ShadowType> shadowBefore = getShadowModel(accountShadowOid);
display("Model Shadow before", shadowBefore);
String dn = ShadowUtil.getAttributeValue(shadowBefore, RESOURCE_OPENDJ_SECONDARY_IDENTIFIER);
openDJController.delete(dn);
PrismObject<ShadowType> repoShadowBefore = repositoryService.getObject(ShadowType.class, accountShadowOid, null, result);
assertNotNull("Repo shadow is gone!", repoShadowBefore);
display("Repository shadow before", repoShadowBefore);
assertTrue("Oh my! Shadow is dead!", repoShadowBefore.asObjectable().isDead() != Boolean.TRUE);
// WHEN
TestUtil.displayWhen(TEST_NAME);
recomputeUser(USER_GUYBRUSH_OID, task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);
PrismObject<UserType> userAfter = getUser(USER_GUYBRUSH_OID);
display("User after", userAfter);
String accountShadowOidAfter = assertOneAccountRef(userAfter);
PrismObject<ShadowType> shadowAfter = getShadowModel(accountShadowOidAfter);
display("Shadow after", shadowAfter);
Entry entryAfter = openDJController.fetchEntry(dn);
display("Entry after", entryAfter);
}
/**
* Recompute user => account not found => reaction: Re-create account
* MID-3093
*/
@Test