Skip to content

Commit

Permalink
Provisioning tests almost fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Mar 11, 2015
1 parent bc300e1 commit 9f38522
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 42 deletions.
Expand Up @@ -1030,6 +1030,9 @@ public List<Change<ShadowType>> fetchChanges(ResourceType resourceType,
InternalMonitor.recordShadowOtherOperation();

RefinedObjectClassDefinition refinedObjectClassDefinition = determineObjectClassDefinition(objectClass, resourceType);
if (refinedObjectClassDefinition == null) {
throw new SchemaException("Unknown object class "+objectClass+" in "+resourceType);
}
ConnectorInstance connector = getConnectorInstance(resourceType, parentResult);

List<Change<ShadowType>> changes = null;
Expand Down
Expand Up @@ -77,6 +77,7 @@
import org.identityconnectors.framework.common.objects.OperationalAttributes;
import org.identityconnectors.framework.common.objects.QualifiedUid;
import org.identityconnectors.framework.common.objects.ResultsHandler;
import org.identityconnectors.framework.common.objects.Schema;
import org.identityconnectors.framework.common.objects.ScriptContext;
import org.identityconnectors.framework.common.objects.SearchResult;
import org.identityconnectors.framework.common.objects.SortKey;
Expand Down Expand Up @@ -471,6 +472,10 @@ public void initialize(ResourceSchema resourceSchema, Collection<Object> capabil
this.resourceSchema = resourceSchema;
this.capabilities = capabilities;
this.caseIgnoreAttributeNames = caseIgnoreAttributeNames;

if (resourceSchema != null) {
legacySchema = isLegacySchema(resourceSchema);
}

if (resourceSchema == null || capabilities == null) {
try {
Expand Down Expand Up @@ -621,15 +626,9 @@ private void parseResourceSchema(org.identityconnectors.framework.common.objects
// New instance of midPoint schema object
resourceSchema = new ResourceSchema(getSchemaNamespace(), prismContext);

Set<ObjectClassInfo> objectClassInfoSet = icfSchema.getObjectClassInfo();
for (ObjectClassInfo objectClassInfo : objectClassInfoSet) {
if (objectClassInfo.is(ObjectClass.ACCOUNT_NAME) || objectClassInfo.is(ObjectClass.GROUP_NAME)) {
legacySchema = true;
LOGGER.trace("This is legacy schema");
break;
}
}
legacySchema = isLegacySchema(icfSchema);

Set<ObjectClassInfo> objectClassInfoSet = icfSchema.getObjectClassInfo();
// Let's convert every objectclass in the ICF schema ...
for (ObjectClassInfo objectClassInfo : objectClassInfoSet) {

Expand Down Expand Up @@ -902,6 +901,23 @@ private void parseResourceSchema(org.identityconnectors.framework.common.objects

}

private boolean isLegacySchema(Schema icfSchema) {
Set<ObjectClassInfo> objectClassInfoSet = icfSchema.getObjectClassInfo();
for (ObjectClassInfo objectClassInfo : objectClassInfoSet) {
if (objectClassInfo.is(ObjectClass.ACCOUNT_NAME) || objectClassInfo.is(ObjectClass.GROUP_NAME)) {
LOGGER.trace("This is legacy schema");
return true;
}
}
return false;
}

private boolean isLegacySchema(ResourceSchema resourceSchema) {
ComplexTypeDefinition accountObjectClass = resourceSchema.findComplexTypeDefinition(
new QName(getSchemaNamespace(), ConnectorFactoryIcfImpl.ACCOUNT_OBJECT_CLASS_LOCAL_NAME));
return accountObjectClass != null;
}

private boolean shouldBeGenerated(List<QName> generateObjectClasses,
QName objectClassXsdName) {
if (generateObjectClasses == null || generateObjectClasses.isEmpty()){
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2013 Evolveum
* Copyright (c) 2010-2015 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -55,7 +55,7 @@
@DirtiesContext
public class TestConnectorDiscovery extends AbstractIntegrationTest {

private static final String LDAP_CONNECTOR_TYPE = "org.identityconnectors.ldap.LdapConnector";
private static final String LDAP_CONNECTOR_TYPE = "com.evolveum.polygon.connector.ldap.LdapConnector";

@Autowired
private ProvisioningService provisioningService;
Expand Down Expand Up @@ -120,9 +120,10 @@ public void testListConnectors() throws Exception{

@Test
public void testSearchConnectorSimple() throws SchemaException{
TestUtil.displayTestTile("testSearchConnectorSimple");
final String TEST_NAME = "testSearchConnectorSimple";
TestUtil.displayTestTile(TEST_NAME);
OperationResult result = new OperationResult(TestConnectorDiscovery.class.getName()
+ ".testSearchConnector");
+ "." + TEST_NAME);

PrismObject<ConnectorType> ldapConnector = findConnectorByType(LDAP_CONNECTOR_TYPE, result);
assertEquals("Type does not match", LDAP_CONNECTOR_TYPE, ldapConnector.asObjectable().getConnectorType());
Expand All @@ -136,16 +137,6 @@ public void testSearchConnectorAnd() throws SchemaException{
+ ".testSearchConnector");

Document doc = DOMUtil.getDocument();
// Element filter = QueryUtil
// .createAndFilter(
// doc,
// QueryUtil.createEqualFilter(doc, null, SchemaConstants.C_CONNECTOR_FRAMEWORK,
// ConnectorFactoryIcfImpl.ICF_FRAMEWORK_URI),
// QueryUtil.createEqualFilter(doc, null, SchemaConstants.C_CONNECTOR_CONNECTOR_TYPE,
// LDAP_CONNECTOR_TYPE));
//
// QueryType query = new QueryType();
// query.setFilter(filter);
AndFilter filter = AndFilter.createAnd(
EqualFilter.createEqual(SchemaConstants.C_CONNECTOR_FRAMEWORK, ConnectorType.class, prismContext, null, ConnectorFactoryIcfImpl.ICF_FRAMEWORK_URI),
EqualFilter.createEqual(SchemaConstants.C_CONNECTOR_CONNECTOR_TYPE, ConnectorType.class, prismContext, null, LDAP_CONNECTOR_TYPE));
Expand Down
Expand Up @@ -266,7 +266,7 @@ public void test121SearchAccounts() throws SchemaException, ObjectNotFoundExcept
+ "." + TEST_NAME);

final String resourceNamespace = ResourceTypeUtil.getResourceNamespace(resource);
QName objectClass = new QName(resourceNamespace, "AccountObjectClass");
QName objectClass = new QName(resourceNamespace, OBJECT_CLASS_INETORGPERSON_NAME);

ObjectQuery query = ObjectQueryUtil.createResourceAndAccountQuery(resource.getOid(), objectClass, prismContext);

Expand Down Expand Up @@ -296,7 +296,7 @@ public void test122SearchAccountsIterative() throws SchemaException, ObjectNotFo
+ "." + TEST_NAME);

final String resourceNamespace = ResourceTypeUtil.getResourceNamespace(resource);
QName objectClass = new QName(resourceNamespace, "AccountObjectClass");
QName objectClass = new QName(resourceNamespace, OBJECT_CLASS_INETORGPERSON_NAME);

ObjectQuery query = ObjectQueryUtil.createResourceAndAccountQuery(resource.getOid(), objectClass, prismContext);

Expand Down Expand Up @@ -546,7 +546,7 @@ public void test521SearchAccounts() throws SchemaException, ObjectNotFoundExcept
+ "." + TEST_NAME);

final String resourceNamespace = ResourceTypeUtil.getResourceNamespace(resource);
QName objectClass = new QName(resourceNamespace, "AccountObjectClass");
QName objectClass = new QName(resourceNamespace, OBJECT_CLASS_INETORGPERSON_NAME);

ObjectQuery query = ObjectQueryUtil.createResourceAndAccountQuery(resource.getOid(), objectClass, prismContext);

Expand Down Expand Up @@ -575,7 +575,7 @@ public void test522SearchAccountsIterative() throws SchemaException, ObjectNotFo
+ "." + TEST_NAME);

final String resourceNamespace = ResourceTypeUtil.getResourceNamespace(resource);
QName objectClass = new QName(resourceNamespace, "AccountObjectClass");
QName objectClass = new QName(resourceNamespace, OBJECT_CLASS_INETORGPERSON_NAME);

ObjectQuery query = ObjectQueryUtil.createResourceAndAccountQuery(resource.getOid(), objectClass, prismContext);

Expand Down
Expand Up @@ -117,7 +117,7 @@ public void initSystem(Task initTask, OperationResult initResult) throws Excepti
// let provisioning discover the connectors
provisioningService.postInit(initResult);

resourceType = addResourceFromFile(FILENAME_RESOURCE_OPENDJ, "org.identityconnectors.ldap.LdapConnector", initResult).asObjectable();
resourceType = addResourceFromFile(FILENAME_RESOURCE_OPENDJ, AbstractOpenDJTest.LDAP_CONNECTOR_TYPE, initResult).asObjectable();

//it is needed to declare the task owner, so we add the user admin to the reposiotry
repoAddObjectFromFile(FILENAME_USER_ADMIN, UserType.class, initResult);
Expand Down Expand Up @@ -189,7 +189,7 @@ public void test100SyncAddWill() throws Exception {
addOperation.getResultCode());

// WHEN
provisioningService.synchronize(resourceType.getOid(), ProvisioningTestUtil.getDefaultAccountObjectClass(resourceType),
provisioningService.synchronize(resourceType.getOid(), AbstractOpenDJTest.RESOURCE_OPENDJ_ACCOUNT_OBJECTCLASS,
syncTask, result);

// THEN
Expand Down
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2010-2013 Evolveum
~ Copyright (c) 2010-2015 Evolveum
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
Expand All @@ -21,6 +21,7 @@
<resource oid="ef2bc95b-76e0-59e2-86d6-3d4f02d3ffff"
xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
xmlns:c="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
xmlns:t="http://prism.evolveum.com/xml/ns/public/types-3"
xmlns:ri="http://midpoint.evolveum.com/xml/ns/public/resource/instance/ef2bc95b-76e0-59e2-86d6-3d4f02d3ffff"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
Expand All @@ -32,16 +33,17 @@
<name>Embedded Test OpenDJ</name>
<!-- NOTE: The connector OID will get dynamically replaced in the integration tests -->
<connectorRef oid="ef2bc95b-76e0-59e2-86d6-3d4f02d3eedd"/>
<connectorConfiguration xmlns:icfcldap="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/bundle/com.evolveum.polygon.connector-ldap/org.identityconnectors.ldap.LdapConnector">
<connectorConfiguration xmlns:icfcldap="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/bundle/com.evolveum.polygon.connector-ldap/com.evolveum.polygon.connector.ldap.LdapConnector">

<icfc:configurationProperties>
<icfcldap:port>10389</icfcldap:port>
<icfcldap:host>localhost</icfcldap:host>
<icfcldap:baseContexts>dc=example,dc=com</icfcldap:baseContexts>
<icfcldap:principal>cn=directory manager</icfcldap:principal>
<icfcldap:credentials><clearValue>secret</clearValue></icfcldap:credentials>
<icfcldap:vlvSortAttribute>uid</icfcldap:vlvSortAttribute>
<icfcldap:accountOperationalAttributes>ds-pwp-account-disabled</icfcldap:accountOperationalAttributes>
<icfcldap:baseContext>dc=example,dc=com</icfcldap:baseContext>
<icfcldap:bindDn>cn=directory manager</icfcldap:bindDn>
<icfcldap:bindPassword><t:clearValue>secret</t:clearValue></icfcldap:bindPassword>
<icfcldap:pagingStrategy>auto</icfcldap:pagingStrategy>
<icfcldap:vlvSortAttribute>entryUUID</icfcldap:vlvSortAttribute>
<icfcldap:operationalAttributes>ds-pwp-account-disabled</icfcldap:operationalAttributes>
</icfc:configurationProperties>

<icfc:connectorPoolConfiguration>
Expand All @@ -68,6 +70,10 @@
<icfc:sync>-1</icfc:sync>
<icfc:schema>-1</icfc:schema>
</icfc:timeouts>

<icfc:resultsHandlerConfiguration>
<icfc:enableFilteredResultsHandler>false</icfc:enableFilteredResultsHandler>
</icfc:resultsHandlerConfiguration>

</connectorConfiguration>

Expand All @@ -91,14 +97,14 @@
<xsd:import namespace="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/resource-schema-3" />

<xsd:import namespace="http://prism.evolveum.com/xml/ns/public/annotation-3" />
<xsd:complexType name="GroupObjectClass">
<xsd:complexType name="groupsOfUniqueNames">
<xsd:annotation>
<xsd:appinfo>
<ra:resourceObject/>
<ra:identifier>icfs:uid</ra:identifier>
<ra:displayNameAttribute>icfs:name</ra:displayNameAttribute>
<ra:namingAttribute>icfs:name</ra:namingAttribute>
<ra:nativeObjectClass>__GROUP__</ra:nativeObjectClass>
<ra:nativeObjectClass>groupsOfUniqueNames</ra:nativeObjectClass>
</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
Expand All @@ -115,14 +121,14 @@
<xsd:element maxOccurs="unbounded" minOccurs="0" name="ou" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="AccountObjectClass">
<xsd:complexType name="inetOrgPerson">
<xsd:annotation>
<xsd:appinfo>
<ra:resourceObject/>
<ra:identifier>icfs:uid</ra:identifier>
<ra:displayNameAttribute>icfs:name</ra:displayNameAttribute>
<ra:namingAttribute>icfs:name</ra:namingAttribute>
<ra:nativeObjectClass>__ACCOUNT__</ra:nativeObjectClass>
<ra:nativeObjectClass>inetOrgPerson</ra:nativeObjectClass>
<ra:account/>
<ra:default/>
</xsd:appinfo>
Expand Down Expand Up @@ -195,7 +201,7 @@
<intent>default</intent>
<displayName>Default Account</displayName>
<default>true</default>
<objectClass>ri:AccountObjectClass</objectClass>
<objectClass>ri:inetOrgPerson</objectClass>
<association>
<ref>ri:group</ref>
<displayName>LDAP Group Membership</displayName>
Expand All @@ -211,7 +217,7 @@
<kind>entitlement</kind>
<intent>ldapGroup</intent>
<displayName>LDAP Group</displayName>
<objectClass>ri:GroupObjectClass</objectClass>
<objectClass>ri:groupsOfUniqueNames</objectClass>
</objectType>

</schemaHandling>
Expand Down
Expand Up @@ -255,7 +255,11 @@ public void assertDummyResourceSchemaSanity(ResourceSchema resourceSchema, Resou
public void assertDummyResourceSchemaSanityExtended(ResourceSchema resourceSchema, ResourceType resourceType) {
assertDummyResourceSchemaSanity(resourceSchema, resourceType);

ObjectClassComplexTypeDefinition accountDef = resourceSchema.findDefaultObjectClassDefinition(ShadowKindType.ACCOUNT);
ObjectClassComplexTypeDefinition accountDef = resourceSchema.findDefaultObjectClassDefinition(ShadowKindType.ACCOUNT);
assertNotNull("No default account definition", accountDef);
ObjectClassComplexTypeDefinition accountObjectClassDef = resourceSchema.findObjectClassDefinition(SchemaTestConstants.ICF_ACCOUNT_OBJECT_CLASS_LOCAL_NAME);
assertNotNull("No AccountObjectClass definition", accountObjectClassDef);
assertTrue("Default account definition is not same as AccountObjectClass", accountDef == accountObjectClassDef);
assertEquals("Unexpected number of defnitions", 17, accountDef.getDefinitions().size());
ResourceAttributeDefinition treasureDef = accountDef.findAttributeDefinition(DUMMY_ACCOUNT_ATTRIBUTE_TREASURE_NAME);
assertFalse("Treasure IS returned by default and should not be", treasureDef.isReturnedByDefault());
Expand Down

0 comments on commit 9f38522

Please sign in to comment.