-
Notifications
You must be signed in to change notification settings - Fork 188
/
TestOpenDj.java
3582 lines (2750 loc) · 161 KB
/
TestOpenDj.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-2018 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/
package com.evolveum.midpoint.provisioning.impl.opendj;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertFalse;
import static org.testng.AssertJUnit.assertNull;
import static org.testng.AssertJUnit.assertNotNull;
import static org.testng.AssertJUnit.assertTrue;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.namespace.QName;
import com.evolveum.midpoint.common.refinery.RefinedResourceSchemaImpl;
import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.prism.delta.*;
import com.evolveum.midpoint.prism.path.ItemName;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.prism.query.*;
import com.evolveum.midpoint.schema.processor.*;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import org.apache.commons.lang.StringUtils;
import org.opends.server.types.Entry;
import org.opends.server.util.LDIFException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.testng.Assert;
import org.testng.AssertJUnit;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.w3c.dom.Element;
import com.evolveum.midpoint.common.refinery.RefinedAttributeDefinition;
import com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition;
import com.evolveum.midpoint.common.refinery.RefinedResourceSchema;
import com.evolveum.midpoint.prism.util.PrismAsserts;
import com.evolveum.midpoint.prism.util.PrismTestUtil;
import com.evolveum.midpoint.prism.xml.XmlTypeConverter;
import com.evolveum.midpoint.provisioning.impl.ProvisioningTestUtil;
import com.evolveum.midpoint.schema.CapabilityUtil;
import com.evolveum.midpoint.schema.DeltaConvertor;
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.ResultHandler;
import com.evolveum.midpoint.schema.SearchResultList;
import com.evolveum.midpoint.schema.SearchResultMetadata;
import com.evolveum.midpoint.schema.constants.ConnectorTestOperation;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.internals.InternalCounters;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.MiscSchemaUtil;
import com.evolveum.midpoint.schema.util.ObjectQueryUtil;
import com.evolveum.midpoint.schema.util.ShadowUtil;
import com.evolveum.midpoint.schema.util.ResourceTypeUtil;
import com.evolveum.midpoint.schema.util.SchemaDebugUtil;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.task.api.TaskManager;
import com.evolveum.midpoint.test.IntegrationTestTools;
import com.evolveum.midpoint.test.asserter.ShadowAsserter;
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.MiscUtil;
import com.evolveum.midpoint.util.exception.CommunicationException;
import com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException;
import com.evolveum.midpoint.util.exception.ObjectNotFoundException;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType;
import com.evolveum.midpoint.xml.ns._public.common.api_types_3.PropertyReferenceListType;
import com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ActivationCapabilityType;
import com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.CreateCapabilityType;
import com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.CredentialsCapabilityType;
import com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.DeleteCapabilityType;
import com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.PagedSearchCapabilityType;
import com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.PasswordCapabilityType;
import com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ReadCapabilityType;
import com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ScriptCapabilityType;
import com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ScriptCapabilityType.Host;
import com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.UpdateCapabilityType;
import com.evolveum.prism.xml.ns._public.query_3.QueryType;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;
import com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType;
import com.evolveum.midpoint.provisioning.ucf.api.ConnectorInstance;
/**
* Test for provisioning service implementation.
*
* This test will initialize mock repository and fill-in some test data. The
* "default" repository objects cannot be used, as the new provisioning service
* implementation assumes a slightly different connector configuration that was
* used in the OpenIDM.
*
* This test will initialize embedded OpenDJ as a target resource.
*
* The test calls the new Provisioning Service Interface (java). No WSDL mess.
*
* @author Radovan Semancik
* @author Katka Valalikova
*/
@ContextConfiguration(locations = "classpath:ctx-provisioning-test-main.xml")
@DirtiesContext
public class TestOpenDj extends AbstractOpenDjTest {
protected static final String USER_JACK_FULL_NAME = "Jack Sparrow";
private static final File FILE_MODIFY_ASSOCIATION_REPLACE = new File(TEST_DIR, "account-modify-association.xml");
private static final String[] JACK_FULL_NAME_LANG_EN_SK = {
"en", "Jack Sparrow",
"sk", "Džek Sperou"
};
private static final String[] JACK_FULL_NAME_LANG_EN_SK_RU_HR = {
"en", "Jack Sparrow",
"sk", "Džek Sperou",
"ru", "Джек Воробей",
"hr", "Ðek Sperou"
};
private static final String[] JACK_FULL_NAME_LANG_CZ_HR = {
"cz", "Džek Sperou",
"hr", "Ðek Sperou"
};
protected static final String USER_JACK_FULL_NAME_CAPTAIN = "Captain Jack Sparrow";
private static final String[] JACK_FULL_NAME_LANG_CAPTAIN_EN_CZ_SK = {
"en", "Captain Jack Sparrow",
"cz", "Kapitán Džek Sperou",
"sk", "Kapitán Džek Sperou"
};
private static Trace LOGGER = TraceManager.getTrace(TestOpenDj.class);
private String groupSailorOid;
@Autowired
TaskManager taskManager;
protected int getNumberOfBaseContextShadows() {
return 0;
}
@Override
public void initSystem(Task initTask, OperationResult initResult) throws Exception {
super.initSystem(initTask, initResult);
openDJController.addEntry("dn: ou=specialgroups,dc=example,dc=com\n"+
"objectclass: organizationalUnit\n"+
"ou: specialgroups\n");
// This is useful when debugging polystring issues, but too much noise otherwise
// DebugUtil.setDetailedDebugDump(true);
}
@BeforeClass
public static void startLdap() throws Exception {
LOGGER.info("------------------------------------------------------------------------------");
LOGGER.info("START: ProvisioningServiceImplOpenDJTest");
LOGGER.info("------------------------------------------------------------------------------");
try {
openDJController.startCleanServer();
} catch (IOException ex) {
LOGGER.error("Couldn't start LDAP.", ex);
throw ex;
}
}
@AfterClass
public static void stopLdap() throws Exception {
openDJController.stop();
LOGGER.info("------------------------------------------------------------------------------");
LOGGER.info("STOP: ProvisioningServiceImplOpenDJTest");
LOGGER.info("------------------------------------------------------------------------------");
}
/**
* This should be the very first test that works with the resource.
*
* The original repository object does not have resource schema. The schema should be generated from
* the resource on the first use. This is the test that executes testResource and checks whether the
* schema was generated.
*/
@Test
public void test003Connection() throws Exception {
final String TEST_NAME = "test003Connection";
displayTestTitle(TEST_NAME);
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
ResourceType resourceTypeBefore = repositoryService.getObject(ResourceType.class,RESOURCE_OPENDJ_OID, null, result).asObjectable();
assertNotNull("No connector ref",resourceTypeBefore.getConnectorRef());
assertNotNull("No connector ref OID",resourceTypeBefore.getConnectorRef().getOid());
connector = repositoryService.getObject(ConnectorType.class, resourceTypeBefore.getConnectorRef().getOid(), null, result);
ConnectorType connectorType = connector.asObjectable();
assertNotNull(connectorType);
Element resourceXsdSchemaElementBefore = ResourceTypeUtil.getResourceXsdSchema(resourceTypeBefore);
AssertJUnit.assertNull("Found schema before test connection. Bad test setup?", resourceXsdSchemaElementBefore);
OperationResult operationResult = provisioningService.testResource(RESOURCE_OPENDJ_OID, task);
display("Test connection result",operationResult);
TestUtil.assertSuccess("Test connection failed",operationResult);
PrismObject<ResourceType> resourceRepoAfter = repositoryService.getObject(ResourceType.class,RESOURCE_OPENDJ_OID, null, result);
ResourceType resourceTypeRepoAfter = resourceRepoAfter.asObjectable();
display("Resource after testResource (repository)",resourceTypeRepoAfter);
display("Resource after testResource (repository, XML)", PrismTestUtil.serializeObjectToString(resourceTypeRepoAfter.asPrismObject(), PrismContext.LANG_XML));
XmlSchemaType xmlSchemaTypeAfter = resourceTypeRepoAfter.getSchema();
assertNotNull("No schema after test connection",xmlSchemaTypeAfter);
Element resourceXsdSchemaElementAfter = ResourceTypeUtil.getResourceXsdSchema(resourceTypeRepoAfter);
assertNotNull("No schema after test connection", resourceXsdSchemaElementAfter);
CachingMetadataType cachingMetadata = xmlSchemaTypeAfter.getCachingMetadata();
assertNotNull("No caching metadata",cachingMetadata);
assertNotNull("No retrievalTimestamp",cachingMetadata.getRetrievalTimestamp());
assertNotNull("No serialNumber",cachingMetadata.getSerialNumber());
Element xsdElement = ResourceTypeUtil.getResourceXsdSchema(resourceTypeRepoAfter);
ResourceSchema parsedSchema = ResourceSchemaImpl.parse(xsdElement, resourceTypeRepoAfter.toString(), prismContext);
assertNotNull("No schema after parsing",parsedSchema);
Collection<ObjectClassComplexTypeDefinition> objectClasses = parsedSchema.getObjectClassDefinitions();
List<QName> objectClassesToGenerate = ResourceTypeUtil.getSchemaGenerationConstraints(resourceTypeRepoAfter);
if (objectClassesToGenerate != null && !objectClasses.isEmpty()) {
assertEquals("Unexpected object classes in generate schema", objectClassesToGenerate.size(), objectClasses.size());
}
ObjectClassComplexTypeDefinition inetOrgPersonDefinition = parsedSchema.findObjectClassDefinition(RESOURCE_OPENDJ_ACCOUNT_OBJECTCLASS);
assertNull("The _PASSSWORD_ attribute sneaked into schema", inetOrgPersonDefinition.findAttributeDefinition(
new QName(SchemaConstants.NS_ICF_SCHEMA,"password")));
assertNull("The userPassword attribute sneaked into schema", inetOrgPersonDefinition.findAttributeDefinition(
new QName(ResourceTypeUtil.getResourceNamespace(resourceTypeRepoAfter),"userPassword")));
assertShadows(1);
}
@Test
public void test004ResourceAndConnectorCaching() throws Exception {
final String TEST_NAME = "test004ResourceAndConnectorCaching";
displayTestTitle(TEST_NAME);
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
resource = provisioningService.getObject(ResourceType.class,RESOURCE_OPENDJ_OID, null, null, result);
resourceType = resource.asObjectable();
ConnectorInstance configuredConnectorInstance = resourceManager.getConfiguredConnectorInstance(
resource, ReadCapabilityType.class, false, result);
assertNotNull("No configuredConnectorInstance", configuredConnectorInstance);
ResourceSchema resourceSchema = RefinedResourceSchemaImpl.getResourceSchema(resource, prismContext);
assertNotNull("No resource schema", resourceSchema);
// WHEN
PrismObject<ResourceType> resourceAgain = provisioningService.getObject(ResourceType.class,RESOURCE_OPENDJ_OID, null, task, result);
// THEN
ResourceType resourceTypeAgain = resourceAgain.asObjectable();
assertNotNull("No connector ref",resourceTypeAgain.getConnectorRef());
assertNotNull("No connector ref OID",resourceTypeAgain.getConnectorRef().getOid());
PrismContainer<Containerable> configurationContainer = resource.findContainer(ResourceType.F_CONNECTOR_CONFIGURATION);
PrismContainer<Containerable> configurationContainerAgain = resourceAgain.findContainer(ResourceType.F_CONNECTOR_CONFIGURATION);
assertTrue("Configurations not equivalent", configurationContainer.equivalent(configurationContainerAgain));
assertTrue("Configurations not equals", configurationContainer.equals(configurationContainerAgain));
ResourceSchema resourceSchemaAgain = RefinedResourceSchemaImpl.getResourceSchema(resourceAgain, prismContext);
assertNotNull("No resource schema (again)", resourceSchemaAgain);
assertEquals("Schema serial number mismatch", resourceType.getSchema().getCachingMetadata().getSerialNumber(),
resourceTypeAgain.getSchema().getCachingMetadata().getSerialNumber());
assertTrue("Resource schema was not cached", resourceSchema == resourceSchemaAgain);
// Now we stick our nose deep inside the provisioning impl. But we need to make sure that the
// configured connector is properly cached
ConnectorInstance configuredConnectorInstanceAgain = resourceManager.getConfiguredConnectorInstance(
resourceAgain, ReadCapabilityType.class, false, result);
assertTrue("Connector instance was not cached", configuredConnectorInstance == configuredConnectorInstanceAgain);
assertShadows(1);
}
@Test
public void test005Capabilities() throws Exception {
final String TEST_NAME = "test005Capabilities";
displayTestTitle(TEST_NAME);
// GIVEN
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
// WHEN
ResourceType resource = provisioningService.getObject(ResourceType.class, RESOURCE_OPENDJ_OID, null, task, result).asObjectable();
// THEN
display("Resource from provisioninig", resource);
display("Resource from provisioninig (XML)", PrismTestUtil.serializeObjectToString(resource.asPrismObject(), PrismContext.LANG_XML));
CapabilityCollectionType nativeCapabilities = resource.getCapabilities().getNative();
List<Object> nativeCapabilitiesList = nativeCapabilities.getAny();
assertFalse("Empty capabilities returned",nativeCapabilitiesList.isEmpty());
CredentialsCapabilityType capCred = CapabilityUtil.getCapability(nativeCapabilitiesList, CredentialsCapabilityType.class);
assertNotNull("credentials capability not found",capCred);
PasswordCapabilityType capPassword = capCred.getPassword();
assertNotNull("password capability not present", capPassword);
assertPasswordCapability(capPassword);
// Connector cannot do activation, this should be null
ActivationCapabilityType capAct = CapabilityUtil.getCapability(nativeCapabilitiesList, ActivationCapabilityType.class);
assertNull("Found activation capability while not expecting it" ,capAct);
ScriptCapabilityType capScript = CapabilityUtil.getCapability(nativeCapabilitiesList, ScriptCapabilityType.class);
assertNotNull("No script capability", capScript);
List<Host> scriptHosts = capScript.getHost();
assertEquals("Wrong number of script hosts", 1, scriptHosts.size());
Host scriptHost = scriptHosts.get(0);
assertEquals("Wrong script host type", ProvisioningScriptHostType.CONNECTOR, scriptHost.getType());
// assertEquals("Wrong script host language", ....., scriptHost.getLanguage());
ReadCapabilityType capRead = CapabilityUtil.getCapability(nativeCapabilitiesList, ReadCapabilityType.class);
assertNotNull("No read capability", capRead);
assertNull("Read capability is caching only", capRead.isCachingOnly());
assertTrue("Read capability is not 'return default'", capRead.isReturnDefaultAttributesOption());
CreateCapabilityType capCreate = CapabilityUtil.getCapability(nativeCapabilitiesList, CreateCapabilityType.class);
assertNotNull("No create capability", capCreate);
UpdateCapabilityType capUpdate = CapabilityUtil.getCapability(nativeCapabilitiesList, UpdateCapabilityType.class);
assertNotNull("No update capability", capUpdate);
DeleteCapabilityType capDelete = CapabilityUtil.getCapability(nativeCapabilitiesList, DeleteCapabilityType.class);
assertNotNull("No delete capability", capDelete);
List<Object> effectiveCapabilities = ResourceTypeUtil.getEffectiveCapabilities(resource);
for (Object capability : effectiveCapabilities) {
System.out.println("Capability: "+CapabilityUtil.getCapabilityDisplayName(capability)+" : "+capability);
}
capCred = ResourceTypeUtil.getEffectiveCapability(resource, CredentialsCapabilityType.class);
assertNotNull("credentials effective capability not found",capCred);
assertNotNull("password effective capability not found",capCred.getPassword());
// Although connector does not support activation, the resource specifies a way how to simulate it.
// Therefore the following should succeed
capAct = ResourceTypeUtil.getEffectiveCapability(resource, ActivationCapabilityType.class);
assertNotNull("activation capability not found",capAct);
PagedSearchCapabilityType capPage = ResourceTypeUtil.getEffectiveCapability(resource, PagedSearchCapabilityType.class);
assertNotNull("paged search capability not present", capPage);
assertShadows(1);
}
protected void assertPasswordCapability(PasswordCapabilityType capPassword) {
assertTrue("Wrong password capability readable flag: "+capPassword.isReadable(),
capPassword.isReadable() != Boolean.TRUE);
}
@Test
public void test006Schema() throws Exception {
final String TEST_NAME = "test006RefinedSchema";
displayTestTitle(TEST_NAME);
// GIVEN
// WHEN
ResourceSchema resourceSchema = RefinedResourceSchemaImpl.getResourceSchema(resourceType, prismContext);
display("Resource schema", resourceSchema);
ObjectClassComplexTypeDefinition accountDef = resourceSchema.findObjectClassDefinition(RESOURCE_OPENDJ_ACCOUNT_OBJECTCLASS);
assertNotNull("Account definition is missing", accountDef);
assertNotNull("Null identifiers in account", accountDef.getPrimaryIdentifiers());
assertFalse("Empty identifiers in account", accountDef.getPrimaryIdentifiers().isEmpty());
assertNotNull("Null secondary identifiers in account", accountDef.getSecondaryIdentifiers());
assertFalse("Empty secondary identifiers in account", accountDef.getSecondaryIdentifiers().isEmpty());
assertNotNull("No naming attribute in account", accountDef.getNamingAttribute());
assertFalse("No nativeObjectClass in account", StringUtils.isEmpty(accountDef.getNativeObjectClass()));
ResourceAttributeDefinition<String> idPrimaryDef = accountDef.findAttributeDefinition(getPrimaryIdentifierQName());
assertEquals(1, idPrimaryDef.getMaxOccurs());
assertEquals(0, idPrimaryDef.getMinOccurs());
assertFalse("UID has create", idPrimaryDef.canAdd());
assertFalse("UID has update", idPrimaryDef.canModify());
assertTrue("No UID read", idPrimaryDef.canRead());
assertTrue("UID definition not in identifiers", accountDef.getPrimaryIdentifiers().contains(idPrimaryDef));
assertEquals("Wrong "+OpenDJController.RESOURCE_OPENDJ_PRIMARY_IDENTIFIER_LOCAL_NAME+" frameworkAttributeName", ProvisioningTestUtil.CONNID_UID_NAME, idPrimaryDef.getFrameworkAttributeName());
assertEquals("Wrong primary identifier matching rule", PrismConstants.UUID_MATCHING_RULE_NAME, idPrimaryDef.getMatchingRuleQName());
ResourceAttributeDefinition<String> idSecondaryDef = accountDef.findAttributeDefinition(getSecondaryIdentifierQName());
assertEquals(1, idSecondaryDef.getMaxOccurs());
assertEquals(1, idSecondaryDef.getMinOccurs());
assertTrue("No NAME create", idSecondaryDef.canAdd());
assertTrue("No NAME update", idSecondaryDef.canModify());
assertTrue("No NAME read", idSecondaryDef.canRead());
assertTrue("NAME definition not in secondary identifiers", accountDef.getSecondaryIdentifiers().contains(idSecondaryDef));
assertEquals("Wrong "+OpenDJController.RESOURCE_OPENDJ_SECONDARY_IDENTIFIER_LOCAL_NAME+" frameworkAttributeName", ProvisioningTestUtil.CONNID_NAME_NAME, idSecondaryDef.getFrameworkAttributeName());
assertEquals("Wrong secondary identifier matching rule", PrismConstants.DISTINGUISHED_NAME_MATCHING_RULE_NAME, idSecondaryDef.getMatchingRuleQName());
ResourceAttributeDefinition<String> cnDef = accountDef.findAttributeDefinition("cn");
assertNotNull("No definition for cn", cnDef);
assertEquals(-1, cnDef.getMaxOccurs());
assertEquals(1, cnDef.getMinOccurs());
assertTrue("No cn create", cnDef.canAdd());
assertTrue("No cn update", cnDef.canModify());
assertTrue("No cn read", cnDef.canRead());
assertEquals("Wrong cn matching rule", PrismConstants.STRING_IGNORE_CASE_MATCHING_RULE_NAME, cnDef.getMatchingRuleQName());
ResourceAttributeDefinition<byte[]> jpegPhoto = accountDef.findAttributeDefinition("jpegPhoto");
assertNotNull("No definition for jpegPhoto", jpegPhoto);
assertEquals(-1, jpegPhoto.getMaxOccurs());
assertEquals(0, jpegPhoto.getMinOccurs());
assertTrue("No jpegPhoto create", jpegPhoto.canAdd());
assertTrue("No jpegPhoto update", jpegPhoto.canModify());
assertTrue("No jpegPhoto read", jpegPhoto.canRead());
assertEquals("Wrong jpegPhoto matching rule", null, jpegPhoto.getMatchingRuleQName());
ResourceAttributeDefinition<String> dsDef = accountDef.findAttributeDefinition("ds-pwp-account-disabled");
assertNotNull("No definition for ds-pwp-account-disabled", dsDef);
assertEquals(1, dsDef.getMaxOccurs());
assertEquals(0, dsDef.getMinOccurs());
assertTrue("No ds-pwp-account-disabled read", dsDef.canRead());
assertTrue("No ds-pwp-account-disabled create", dsDef.canAdd());
assertTrue("No ds-pwp-account-disabled update", dsDef.canModify());
// TODO: MID-2358
// assertTrue("ds-pwp-account-disabled is NOT operational", dsDef.isOperational());
ResourceAttributeDefinition<String> memberOfDef = accountDef.findAttributeDefinition("isMemberOf");
assertNotNull("No definition for isMemberOf", memberOfDef);
assertEquals(-1, memberOfDef.getMaxOccurs());
assertEquals(0, memberOfDef.getMinOccurs());
assertFalse("isMemberOf create", memberOfDef.canAdd());
assertFalse("isMemberOf update", memberOfDef.canModify());
assertTrue("No isMemberOf read", memberOfDef.canRead());
assertEquals("Wrong isMemberOf matching rule", PrismConstants.DISTINGUISHED_NAME_MATCHING_RULE_NAME, memberOfDef.getMatchingRuleQName());
ResourceAttributeDefinition<String> labeledUriDef = accountDef.findAttributeDefinition("labeledURI");
assertNotNull("No definition for labeledUri", labeledUriDef);
assertEquals(-1, labeledUriDef.getMaxOccurs());
assertEquals(0, labeledUriDef.getMinOccurs());
assertTrue("No labeledUri create", labeledUriDef.canAdd());
assertTrue("No labeledUri update", labeledUriDef.canModify());
assertTrue("No labeledUri read", labeledUriDef.canRead());
assertEquals("Wrong labeledUri matching rule", null, labeledUriDef.getMatchingRuleQName());
ResourceAttributeDefinition<String> secretaryDef = accountDef.findAttributeDefinition("secretary");
assertNotNull("No definition for secretary", secretaryDef);
assertEquals(-1, secretaryDef.getMaxOccurs());
assertEquals(0, secretaryDef.getMinOccurs());
assertTrue("No secretary create", secretaryDef.canAdd());
assertTrue("No secretary update", secretaryDef.canModify());
assertTrue("No secretary read", secretaryDef.canRead());
assertEquals("Wrong secretary matching rule", PrismConstants.DISTINGUISHED_NAME_MATCHING_RULE_NAME, secretaryDef.getMatchingRuleQName());
ResourceAttributeDefinition<String> createTimestampDef = accountDef.findAttributeDefinition("createTimestamp");
assertNotNull("No definition for createTimestamp", createTimestampDef);
assertTimestampType("createTimestamp", createTimestampDef);
assertEquals(1, createTimestampDef.getMaxOccurs());
assertEquals(0, createTimestampDef.getMinOccurs());
assertTrue("No createTimestamp read", createTimestampDef.canRead());
assertFalse("Bad createTimestamp create", createTimestampDef.canAdd());
assertFalse("Bad createTimestamp update", createTimestampDef.canModify());
assertEquals("Wrong createTimestamp matching rule", null, createTimestampDef.getMatchingRuleQName());
// MID-5210
ResourceAttributeDefinition<String> descriptionDef = accountDef.findAttributeDefinition(ATTRIBUTE_DESCRIPTION_NAME);
assertNotNull("No definition for description", descriptionDef);
assertPolyStringType("description", descriptionDef);
assertEquals(-1, descriptionDef.getMaxOccurs());
assertEquals(0, descriptionDef.getMinOccurs());
assertTrue("No description read", descriptionDef.canRead());
assertTrue("Bad description create", descriptionDef.canAdd());
assertTrue("Bad description update", descriptionDef.canModify());
assertEquals("Wrong description matching rule", null, descriptionDef.getMatchingRuleQName());
assertNull("The _PASSSWORD_ attribute sneaked into schema",
accountDef.findAttributeDefinition(new QName(SchemaConstants.NS_ICF_SCHEMA, "password")));
assertNull("The userPassword attribute sneaked into schema",
accountDef.findAttributeDefinition(new QName(accountDef.getTypeName().getNamespaceURI(), "userPassword")));
assertNull("The objectClass attribute sneaked into schema",
accountDef.findAttributeDefinition(new QName(accountDef.getTypeName().getNamespaceURI(), "objectClass")));
assertNull("The objectclass attribute sneaked into schema",
accountDef.findAttributeDefinition(new QName(accountDef.getTypeName().getNamespaceURI(), "objectclass")));
ObjectClassComplexTypeDefinition posixAccountDef = resourceSchema.findObjectClassDefinition(RESOURCE_OPENDJ_POSIX_ACCOUNT_OBJECTCLASS);
assertNotNull("posixAccount definition is missing", posixAccountDef);
assertNotNull("Null identifiers in posixAccount", posixAccountDef.getPrimaryIdentifiers());
assertFalse("Empty identifiers in posixAccount", posixAccountDef.getPrimaryIdentifiers().isEmpty());
assertNotNull("Null secondary identifiers in posixAccount", posixAccountDef.getSecondaryIdentifiers());
assertFalse("Empty secondary identifiers in posixAccount", posixAccountDef.getSecondaryIdentifiers().isEmpty());
assertNotNull("No naming attribute in posixAccount", posixAccountDef.getNamingAttribute());
assertFalse("No nativeObjectClass in posixAccount", StringUtils.isEmpty(posixAccountDef.getNativeObjectClass()));
assertTrue("posixAccount is not auxiliary", posixAccountDef.isAuxiliary());
ResourceAttributeDefinition<String> posixIdPrimaryDef = posixAccountDef.findAttributeDefinition(getPrimaryIdentifierQName());
assertEquals(1, posixIdPrimaryDef.getMaxOccurs());
assertEquals(0, posixIdPrimaryDef.getMinOccurs());
assertFalse("UID has create", posixIdPrimaryDef.canAdd());
assertFalse("UID has update", posixIdPrimaryDef.canModify());
assertTrue("No UID read", posixIdPrimaryDef.canRead());
assertTrue("UID definition not in identifiers", accountDef.getPrimaryIdentifiers().contains(posixIdPrimaryDef));
assertEquals("Wrong "+OpenDJController.RESOURCE_OPENDJ_PRIMARY_IDENTIFIER_LOCAL_NAME+" frameworkAttributeName", ProvisioningTestUtil.CONNID_UID_NAME, posixIdPrimaryDef.getFrameworkAttributeName());
ResourceAttributeDefinition<String> posixIdSecondaryDef = posixAccountDef.findAttributeDefinition(getSecondaryIdentifierQName());
assertEquals(1, posixIdSecondaryDef.getMaxOccurs());
assertEquals(1, posixIdSecondaryDef.getMinOccurs());
assertTrue("No NAME create", posixIdSecondaryDef.canAdd());
assertTrue("No NAME update", posixIdSecondaryDef.canModify());
assertTrue("No NAME read", posixIdSecondaryDef.canRead());
assertTrue("NAME definition not in secondary identifiers", accountDef.getSecondaryIdentifiers().contains(posixIdSecondaryDef));
assertEquals("Wrong "+OpenDJController.RESOURCE_OPENDJ_SECONDARY_IDENTIFIER_LOCAL_NAME+" frameworkAttributeName", ProvisioningTestUtil.CONNID_NAME_NAME, posixIdSecondaryDef.getFrameworkAttributeName());
ObjectClassComplexTypeDefinition normalDef = resourceSchema.findObjectClassDefinition(new QName(RESOURCE_NS, "normalTestingObjectClass"));
display("normalTestingObjectClass object class def", normalDef);
assertNotNull("No definition for normalTestingObjectClass", normalDef);
assertNotNull("The cn attribute missing in normalTestingObjectClass",
normalDef.findAttributeDefinition(new QName(normalDef.getTypeName().getNamespaceURI(), "cn")));
ObjectClassComplexTypeDefinition hybridDef = resourceSchema.findObjectClassDefinition(new QName(RESOURCE_NS, "hybridTestingObjectClass"));
display("Hybrid object class def", hybridDef);
assertNotNull("No definition for hybridTestingObjectClass", hybridDef);
assertNotNull("The cn attribute missing in hybridTestingObjectClass",
hybridDef.findAttributeDefinition(new QName(hybridDef.getTypeName().getNamespaceURI(), "cn")));
assertNotNull("The uuidIdentifiedAttribute attribute missing in hybridTestingObjectClass",
hybridDef.findAttributeDefinition(new QName(hybridDef.getTypeName().getNamespaceURI(), "uuidIdentifiedAttribute")));
ObjectClassComplexTypeDefinition uuidDef = resourceSchema.findObjectClassDefinition(new QName(RESOURCE_NS, "uuidIdentifiedObjectClass"));
display("uuidIdentifiedObjectClass object class def", uuidDef);
assertNotNull("No definition for uuidIdentifiedObjectClass", uuidDef);
assertNotNull("The uuidIdentifiedAttribute attribute missing in uuidIdentifiedObjectClass",
uuidDef.findAttributeDefinition(new QName(uuidDef.getTypeName().getNamespaceURI(), "uuidIdentifiedAttribute")));
assertShadows(1);
}
protected void assertTimestampType(String attrName, ResourceAttributeDefinition<?> def) {
assertEquals("Wrong "+attrName+" type", DOMUtil.XSD_DATETIME, def.getTypeName());
}
protected void assertPolyStringType(String attrName, ResourceAttributeDefinition<?> def) {
assertEquals("Wrong "+attrName+" type", PolyStringType.COMPLEX_TYPE, def.getTypeName());
}
@Test
public void test007RefinedSchema() throws Exception {
final String TEST_NAME = "test007RefinedSchema";
displayTestTitle(TEST_NAME);
// GIVEN
// WHEN
RefinedResourceSchema refinedSchema = RefinedResourceSchemaImpl.getRefinedSchema(resourceType, prismContext);
display("Refined schema", refinedSchema);
// Check whether it is reusing the existing schema and not parsing it
// all over again
// Not equals() but == ... we want to really know if exactly the same
// object instance is returned
assertTrue("Broken caching",
refinedSchema == RefinedResourceSchemaImpl.getRefinedSchema(resourceType, prismContext));
RefinedObjectClassDefinition accountDef = refinedSchema.getDefaultRefinedDefinition(ShadowKindType.ACCOUNT);
assertNotNull("Account definition is missing", accountDef);
assertNotNull("Null identifiers in account", accountDef.getPrimaryIdentifiers());
assertFalse("Empty identifiers in account", accountDef.getPrimaryIdentifiers().isEmpty());
assertNotNull("Null secondary identifiers in account", accountDef.getSecondaryIdentifiers());
assertFalse("Empty secondary identifiers in account", accountDef.getSecondaryIdentifiers().isEmpty());
assertNotNull("No naming attribute in account", accountDef.getNamingAttribute());
assertFalse("No nativeObjectClass in account", StringUtils.isEmpty(accountDef.getNativeObjectClass()));
RefinedAttributeDefinition<String> idPrimaryDef = accountDef.findAttributeDefinition(getPrimaryIdentifierQName());
assertEquals(1, idPrimaryDef.getMaxOccurs());
assertEquals(0, idPrimaryDef.getMinOccurs());
assertFalse("UID has create", idPrimaryDef.canAdd());
assertFalse("UID has update", idPrimaryDef.canModify());
assertTrue("No UID read", idPrimaryDef.canRead());
assertTrue("UID definition not in identifiers", accountDef.getPrimaryIdentifiers().contains(idPrimaryDef));
assertEquals("Wrong "+OpenDJController.RESOURCE_OPENDJ_PRIMARY_IDENTIFIER_LOCAL_NAME+" frameworkAttributeName", ProvisioningTestUtil.CONNID_UID_NAME, idPrimaryDef.getFrameworkAttributeName());
RefinedAttributeDefinition<String> idSecondaryDef = accountDef.findAttributeDefinition(getSecondaryIdentifierQName());
assertEquals(1, idSecondaryDef.getMaxOccurs());
assertEquals(1, idSecondaryDef.getMinOccurs());
assertTrue("No NAME create", idSecondaryDef.canAdd());
assertTrue("No NAME update", idSecondaryDef.canModify());
assertTrue("No NAME read", idSecondaryDef.canRead());
assertTrue("NAME definition not in identifiers", accountDef.getSecondaryIdentifiers().contains(idSecondaryDef));
assertEquals("Wrong NAME matching rule", PrismConstants.DISTINGUISHED_NAME_MATCHING_RULE_NAME, idSecondaryDef.getMatchingRuleQName());
assertEquals("Wrong "+OpenDJController.RESOURCE_OPENDJ_SECONDARY_IDENTIFIER_LOCAL_NAME+" frameworkAttributeName", ProvisioningTestUtil.CONNID_NAME_NAME, idSecondaryDef.getFrameworkAttributeName());
RefinedAttributeDefinition<String> cnDef = accountDef.findAttributeDefinition("cn");
assertNotNull("No definition for cn", cnDef);
assertEquals(-1, cnDef.getMaxOccurs());
assertEquals(1, cnDef.getMinOccurs());
assertTrue("No cn create", cnDef.canAdd());
assertTrue("No cn update", cnDef.canModify());
assertTrue("No cn read", cnDef.canRead());
ResourceAttributeDefinition<String> memberOfDef = accountDef.findAttributeDefinition("isMemberOf");
assertNotNull("No definition for isMemberOf", memberOfDef);
assertEquals(-1, memberOfDef.getMaxOccurs());
assertEquals(0, memberOfDef.getMinOccurs());
assertFalse("isMemberOf create", memberOfDef.canAdd());
assertFalse("isMemberOf update", memberOfDef.canModify());
assertTrue("No isMemberOf read", memberOfDef.canRead());
assertEquals("Wrong isMemberOf matching rule", PrismConstants.DISTINGUISHED_NAME_MATCHING_RULE_NAME, memberOfDef.getMatchingRuleQName());
ResourceAttributeDefinition<String> secretaryDef = accountDef.findAttributeDefinition("secretary");
assertNotNull("No definition for secretary", secretaryDef);
assertEquals(-1, secretaryDef.getMaxOccurs());
assertEquals(0, secretaryDef.getMinOccurs());
assertTrue("No secretary create", secretaryDef.canAdd());
assertTrue("No secretary update", secretaryDef.canModify());
assertTrue("No secretary read", secretaryDef.canRead());
assertEquals("Wrong secretary matching rule", PrismConstants.XML_MATCHING_RULE_NAME, secretaryDef.getMatchingRuleQName());
RefinedAttributeDefinition<String> dsDef = accountDef.findAttributeDefinition("ds-pwp-account-disabled");
assertNotNull("No definition for cn", dsDef);
assertEquals(1, dsDef.getMaxOccurs());
assertEquals(0, dsDef.getMinOccurs());
assertTrue("No ds-pwp-account-disabled create", dsDef.canAdd());
assertTrue("No ds-pwp-account-disabled update", dsDef.canModify());
assertTrue("No ds-pwp-account-disabled read", dsDef.canRead());
// TODO: MID-2358
// assertTrue("ds-pwp-account-disabled is NOT operational", dsDef.isOperational());
assertTrue("ds-pwp-account-disabled is NOT ignored", dsDef.isIgnored());
assertNull("The _PASSSWORD_ attribute sneaked into schema",
accountDef.findAttributeDefinition(new QName(SchemaConstants.NS_ICF_SCHEMA, "password")));
RefinedObjectClassDefinition posixAccountDef = refinedSchema.getRefinedDefinition(RESOURCE_OPENDJ_POSIX_ACCOUNT_OBJECTCLASS);
assertNotNull("posixAccount definition is missing", posixAccountDef);
assertNotNull("Null identifiers in posixAccount", posixAccountDef.getPrimaryIdentifiers());
assertFalse("Empty identifiers in posixAccount", posixAccountDef.getPrimaryIdentifiers().isEmpty());
assertNotNull("Null secondary identifiers in posixAccount", posixAccountDef.getSecondaryIdentifiers());
assertFalse("Empty secondary identifiers in posixAccount", posixAccountDef.getSecondaryIdentifiers().isEmpty());
assertNotNull("No naming attribute in posixAccount", posixAccountDef.getNamingAttribute());
assertFalse("No nativeObjectClass in posixAccount", StringUtils.isEmpty(posixAccountDef.getNativeObjectClass()));
assertTrue("posixAccount is not auxiliary", posixAccountDef.isAuxiliary());
RefinedAttributeDefinition<String> posixIdPrimaryDef = posixAccountDef.findAttributeDefinition(getPrimaryIdentifierQName());
assertEquals(1, posixIdPrimaryDef.getMaxOccurs());
assertEquals(0, posixIdPrimaryDef.getMinOccurs());
assertFalse("UID has create", posixIdPrimaryDef.canAdd());
assertFalse("UID has update", posixIdPrimaryDef.canModify());
assertTrue("No UID read", posixIdPrimaryDef.canRead());
assertTrue("UID definition not in identifiers", accountDef.getPrimaryIdentifiers().contains(posixIdPrimaryDef));
assertEquals("Wrong "+OpenDJController.RESOURCE_OPENDJ_PRIMARY_IDENTIFIER_LOCAL_NAME+" frameworkAttributeName", ProvisioningTestUtil.CONNID_UID_NAME, posixIdPrimaryDef.getFrameworkAttributeName());
RefinedAttributeDefinition<String> posixIdSecondaryDef = posixAccountDef.findAttributeDefinition(getSecondaryIdentifierQName());
assertEquals(1, posixIdSecondaryDef.getMaxOccurs());
assertEquals(1, posixIdSecondaryDef.getMinOccurs());
assertTrue("No NAME create", posixIdSecondaryDef.canAdd());
assertTrue("No NAME update", posixIdSecondaryDef.canModify());
assertTrue("No NAME read", posixIdSecondaryDef.canRead());
assertTrue("NAME definition not in secondary identifiers", accountDef.getSecondaryIdentifiers().contains(posixIdSecondaryDef));
assertEquals("Wrong "+OpenDJController.RESOURCE_OPENDJ_SECONDARY_IDENTIFIER_LOCAL_NAME+" frameworkAttributeName", ProvisioningTestUtil.CONNID_NAME_NAME, posixIdSecondaryDef.getFrameworkAttributeName());
assertShadows(1);
}
@Test
public void test020ListResourceObjects() throws Exception {
final String TEST_NAME = "test020ListResourceObjects";
displayTestTitle(TEST_NAME);
// GIVEN
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
// WHEN
List<PrismObject<? extends ShadowType>> objectList = provisioningService.listResourceObjects(
RESOURCE_OPENDJ_OID, RESOURCE_OPENDJ_ACCOUNT_OBJECTCLASS, null, task, result);
// THEN
assertNotNull(objectList);
assertFalse("Empty list returned",objectList.isEmpty());
display("Resource object list "+RESOURCE_OPENDJ_ACCOUNT_OBJECTCLASS,objectList);
assertShadows(1 + getNumberOfBaseContextShadows());
}
@Test
public void test110GetObject() throws Exception {
final String TEST_NAME = "test110GetObject";
displayTestTitle(TEST_NAME);
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
ShadowType objectToAdd = parseObjectType(ACCOUNT_JBOND_FILE, ShadowType.class);
display(SchemaDebugUtil.prettyPrint(objectToAdd));
display(objectToAdd.asPrismObject().debugDump());
String addedObjectOid = provisioningService.addObject(objectToAdd.asPrismObject(), null, null, task, result);
assertEquals(ACCOUNT_JBOND_OID, addedObjectOid);
PropertyReferenceListType resolve = new PropertyReferenceListType();
// WHEN
displayWhen(TEST_NAME);
ShadowType provisioningShadow = provisioningService.getObject(ShadowType.class, ACCOUNT_JBOND_OID, null, task, result).asObjectable();
// THEN
displayThen(TEST_NAME);
assertSuccess(result);
assertNotNull(provisioningShadow);
display("Account provisioning", provisioningShadow);
PrismAsserts.assertEqualsPolyString("Name not equals.", "uid=jbond,ou=People,dc=example,dc=com", provisioningShadow.getName());
final String resourceNamespace = ResourceTypeUtil.getResourceNamespace(resource);
assertNotNull(provisioningShadow.getOid());
assertNotNull(provisioningShadow.getName());
assertEquals(new QName(resourceNamespace, OBJECT_CLASS_INETORGPERSON_NAME), provisioningShadow.getObjectClass());
assertEquals(RESOURCE_OPENDJ_OID, provisioningShadow.getResourceRef().getOid());
String idPrimaryVal = getAttributeValue(provisioningShadow, getPrimaryIdentifierQName());
assertNotNull("No primary identifier ("+getPrimaryIdentifierQName().getLocalPart()+")", idPrimaryVal);
String idSecondaryVal = getAttributeValue(provisioningShadow, getSecondaryIdentifierQName());
assertNotNull("No secondary ("+getSecondaryIdentifierQName().getLocalPart()+")", idSecondaryVal);
// Capitalization is the same as returned by OpenDJ
assertEquals("Wrong secondary identifier", "uid=jbond,ou=People,dc=example,dc=com", idSecondaryVal);
assertEquals("Wrong LDAP uid", "jbond", getAttributeValue(provisioningShadow, new QName(resourceNamespace, "uid")));
assertEquals("Wrong LDAP cn", "James Bond", getAttributeValue(provisioningShadow, new QName(resourceNamespace, "cn")));
assertEquals("Wrong LDAP sn", "Bond", getAttributeValue(provisioningShadow, new QName(resourceNamespace, "sn")));
assertNotNull("Missing activation", provisioningShadow.getActivation());
assertNotNull("Missing activation status", provisioningShadow.getActivation().getAdministrativeStatus());
assertEquals("Not enabled", ActivationStatusType.ENABLED, provisioningShadow.getActivation().getAdministrativeStatus());
assertShadowPassword(provisioningShadow);
Object createTimestamp = ShadowUtil.getAttributeValue(provisioningShadow, new QName(resourceNamespace, "createTimestamp"));
assertTimestamp("createTimestamp", createTimestamp);
ShadowType repoShadow = getShadowRepo(provisioningShadow.getOid()).asObjectable();
display("Account repo", repoShadow);
assertEquals(new QName(resourceNamespace, OBJECT_CLASS_INETORGPERSON_NAME), repoShadow.getObjectClass());
assertEquals(RESOURCE_OPENDJ_OID, repoShadow.getResourceRef().getOid());
idPrimaryVal = getAttributeValue(repoShadow, getPrimaryIdentifierQName());
assertNotNull("No primary identifier ("+getPrimaryIdentifierQName().getLocalPart()+") (repo)", idPrimaryVal);
idSecondaryVal = getAttributeValue(repoShadow, getSecondaryIdentifierQName());
assertNotNull("No secondary ("+getSecondaryIdentifierQName().getLocalPart()+") (repo)", idSecondaryVal);
// must be all lowercase
assertEquals("Wrong secondary identifier (repo)", "uid=jbond,ou=people,dc=example,dc=com", idSecondaryVal);
assertShadows(2 + getNumberOfBaseContextShadows());
}
protected void assertTimestamp(String attrName, Object timestampValue) {
if (!(timestampValue instanceof XMLGregorianCalendar)) {
fail("Wrong type of "+attrName+", expected XMLGregorianCalendar but was "+timestampValue.getClass());
}
assertBetween("Unreasonable date in "+attrName,
XmlTypeConverter.createXMLGregorianCalendar(1900, 1, 1, 0, 0, 0),
XmlTypeConverter.createXMLGregorianCalendar(2200, 1, 1, 0, 0, 0),
(XMLGregorianCalendar)timestampValue);
}
protected void assertShadowPassword(ShadowType provisioningShadow) throws Exception {
CredentialsType credentials = provisioningShadow.getCredentials();
if (credentials == null) {
return;
}
PasswordType passwordType = credentials.getPassword();
if (passwordType == null) {
return;
}
ProtectedStringType passwordValue = passwordType.getValue();
assertNull("Unexpected password value in "+provisioningShadow+": "+passwordValue, passwordValue);
}
/**
* Let's try to fetch object that does not exist in the repository.
*/
@Test
public void test111GetObjectNotFoundRepo() throws Exception {
final String TEST_NAME = "test111GetObjectNotFoundRepo";
displayTestTitle(TEST_NAME);
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
try {
ObjectType object = provisioningService.getObject(ObjectType.class, NON_EXISTENT_OID, null, task, result).asObjectable();
Assert.fail("Expected exception, but haven't got one");
} catch (ObjectNotFoundException e) {
// This is expected
// Just to close the top-level result.
result.recordFatalError("Error :-)");
System.out.println("NOT FOUND REPO result:");
System.out.println(result.debugDump());
assertFalse(result.hasUnknownStatus());
// TODO: check result
} catch (CommunicationException e) {
Assert.fail("Expected ObjectNotFoundException, but got" + e);
} catch (SchemaException e) {
Assert.fail("Expected ObjectNotFoundException, but got" + e);
}
assertShadows(2 + getNumberOfBaseContextShadows());
}
/**
* Let's try to fetch object that does exit in the repository but does not
* exist in the resource.
*/
@Test
public void test112GetObjectNotFoundResource() throws Exception {
final String TEST_NAME = "test112GetObjectNotFoundResource";
displayTestTitle(TEST_NAME);
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
// WHEN
displayWhen(TEST_NAME);
PrismObject<ShadowType> shadow = provisioningService.getObject(ShadowType.class, ACCOUNT_BAD_OID, null, task, result);
// THEN
displayWhen(TEST_NAME);
ShadowAsserter.forShadow(shadow, "provisioning")
.assertTombstone();
}
@Test
public void test119Cleanup() throws Exception {
final String TEST_NAME = "test119Cleanup";
displayTestTitle(TEST_NAME);
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
repositoryService.deleteObject(ShadowType.class, ACCOUNT_BAD_OID, result);
repositoryService.deleteObject(ShadowType.class, ACCOUNT_JBOND_OID, result);
assertShadows(0 + getNumberOfBaseContextShadows());
}
@Test
public void test120AddAccountWill() throws Exception {
final String TEST_NAME = "test120AddAccountWill";
displayTestTitle(TEST_NAME);
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
PrismObject<ShadowType> accountBefore = parseObject(ACCOUNT_WILL_FILE);
display("Account before", accountBefore);
// WHEN
displayWhen(TEST_NAME);
String addedObjectOid = provisioningService.addObject(accountBefore, null, null, task, result);
// THEN
displayThen(TEST_NAME);
assertSuccess(result);
assertEquals(ACCOUNT_WILL_OID, addedObjectOid);
ShadowType repoShadowTypeAfter = getShadowRepo(ACCOUNT_WILL_OID).asObjectable();
PrismAsserts.assertEqualsPolyString("Name not equal (repo)", "uid=will,ou=People,dc=example,dc=com", repoShadowTypeAfter.getName());
assertAttribute(repoShadowTypeAfter, getSecondaryIdentifierQName(), StringUtils.lowerCase(ACCOUNT_WILL_DN));
ShadowType provisioningAccountTypeAfter = provisioningService.getObject(ShadowType.class, ACCOUNT_WILL_OID,
null, task, result).asObjectable();
PrismAsserts.assertEqualsPolyString("Name not equal.", "uid=will,ou=People,dc=example,dc=com", provisioningAccountTypeAfter.getName());
assertShadows(1 + getNumberOfBaseContextShadows());
}
@Test
public void test121RenameAccountWillOnResource() throws Exception{
String TEST_NAME = "test121RenameAccountWillOnResource";
displayTestTitle(TEST_NAME);
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
openDJController.executeRenameChange(new File(TEST_DIR, "rename.ldif").getPath());
Entry entry = openDJController.fetchEntry("uid=will123,ou=People,dc=example,dc=com");
assertNotNull("Entry with dn uid=will123,ou=People,dc=example,dc=com does not exist", entry);
ShadowType repoShadowType = getShadowRepo(ACCOUNT_WILL_OID).asObjectable();
PrismAsserts.assertEqualsPolyString("Name not equal (repo)", "uid=will,ou=People,dc=example,dc=com", repoShadowType.getName());
assertAttribute(repoShadowType, getSecondaryIdentifierQName(), StringUtils.lowerCase(ACCOUNT_WILL_DN));
ShadowType provisioningAccountType = provisioningService.getObject(ShadowType.class, ACCOUNT_WILL_OID,
null, task, result).asObjectable();
PrismAsserts.assertEqualsPolyString("Name not equal.", "uid=will123,ou=People,dc=example,dc=com", provisioningAccountType.getName());
assertAttribute(provisioningAccountType, getSecondaryIdentifierQName(), "uid=will123,ou=People,dc=example,dc=com");
repoShadowType = getShadowRepo(ACCOUNT_WILL_OID).asObjectable();
PrismAsserts.assertEqualsPolyString("Name not equal (repo after provisioning)", "uid=will123,ou=People,dc=example,dc=com", repoShadowType.getName());
assertAttribute(repoShadowType, getSecondaryIdentifierQName(), "uid=will123,ou=people,dc=example,dc=com");
assertShadows(1 + getNumberOfBaseContextShadows());
}
@Test
public void test125AddObjectNull() throws Exception {
final String TEST_NAME = "test125AddObjectNull";
displayTestTitle(TEST_NAME);
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
String addedObjectOid = null;
try {
// WHEN
addedObjectOid = provisioningService.addObject(null, null, null, task, result);
Assert.fail("Expected IllegalArgumentException but haven't got one.");
} catch(IllegalArgumentException ex){
assertEquals("Object to add must not be null.", ex.getMessage());
}
assertShadows(1 + getNumberOfBaseContextShadows());
}
@Test
public void test130AddDeleteAccountSparrow() throws Exception {
final String TEST_NAME = "test130AddDeleteAccountSparrow";
displayTestTitle(TEST_NAME);
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
ShadowType object = parseObjectType(ACCOUNT_SPARROW_FILE, ShadowType.class);
System.out.println(SchemaDebugUtil.prettyPrint(object));
System.out.println(object.asPrismObject().debugDump());
String addedObjectOid = provisioningService.addObject(object.asPrismObject(), null, null, task, result);
assertEquals(ACCOUNT_SPARROW_OID, addedObjectOid);
// WHEN
displayWhen(TEST_NAME);
provisioningService.deleteObject(ShadowType.class, ACCOUNT_SPARROW_OID, null, null, task, result);
// THEN
displayThen(TEST_NAME);
ShadowType objType = null;
try {
provisioningService.getObject(ShadowType.class, ACCOUNT_SPARROW_OID,
null, task, result);
Assert.fail("Expected exception ObjectNotFoundException, but haven't got one.");
} catch (ObjectNotFoundException ex) {
display("Expected exception", ex);
}
try {
objType = getShadowRepo(ACCOUNT_SPARROW_OID).asObjectable();
// objType = container.getObject();
Assert.fail("Expected exception, but haven't got one.");
} catch (ObjectNotFoundException ex) {
display("Expected exception", ex);
assertTrue(ex.getMessage().contains(ACCOUNT_SPARROW_OID));
}
// Account shadow + shadow for base context
assertShadows(2);
}
@Test
public void test140AddAndModifyAccountJack() throws Exception {
final String TEST_NAME = "test140AddAndModifyAccountJack";
displayTestTitle(TEST_NAME);