Skip to content

Commit

Permalink
Fixing and extending consistency story tests
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Sep 11, 2020
1 parent 7260097 commit 7900ead
Show file tree
Hide file tree
Showing 6 changed files with 961 additions and 54 deletions.
Expand Up @@ -1926,7 +1926,13 @@ public PrismObject<ShadowType> recordDeleteResult(
public void deleteShadow(ProvisioningContext ctx, PrismObject<ShadowType> oldRepoShadow, OperationResult parentResult)
throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
LOGGER.trace("Deleting repository {}", oldRepoShadow);
repositoryService.deleteObject(ShadowType.class, oldRepoShadow.getOid(), parentResult);
try {
repositoryService.deleteObject(ShadowType.class, oldRepoShadow.getOid(), parentResult);
} catch (ObjectNotFoundException e) {
// Attempt to delete shadow that is already deleted. No big deal.
parentResult.muteLastSubresultError();
LOGGER.trace("Attempt to delete repository {} that is already deleted. Ignoring error.", oldRepoShadow);
}
}


Expand Down
Expand Up @@ -4,7 +4,7 @@
* 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.testing.story;
package com.evolveum.midpoint.testing.story.consistency;

import static org.assertj.core.api.Assertions.assertThat;
import static org.testng.AssertJUnit.*;
Expand Down Expand Up @@ -82,7 +82,7 @@
@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
public class TestConsistencyMechanism extends AbstractModelIntegrationTest {

private static final String TEST_DIR = "src/test/resources/consistency/";
protected static final String TEST_DIR = "src/test/resources/consistency/";

private static final String SYSTEM_CONFIGURATION_FILENAME = TEST_DIR + "system-configuration.xml";

Expand All @@ -94,7 +94,7 @@ public class TestConsistencyMechanism extends AbstractModelIntegrationTest {

private static final String SAMPLE_CONFIGURATION_OBJECT_FILENAME = TEST_DIR + "sample-configuration-object.xml";

private static final String RESOURCE_OPENDJ_FILENAME = TEST_DIR + "resource-opendj.xml";
private static final File RESOURCE_OPENDJ_FILE = new File(TEST_DIR, "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");
Expand Down Expand Up @@ -136,7 +136,7 @@ public class TestConsistencyMechanism extends AbstractModelIntegrationTest {

private static final String USER_ELAINE_FILENAME = TEST_DIR + "user-elaine.xml";
private static final File USER_ELAINE_FILE = new File(USER_ELAINE_FILENAME);
private static final String USER_ELAINE_OID = "c0c010c0-d34d-b33f-f00d-111111116666";
protected static final String USER_ELAINE_OID = "c0c010c0-d34d-b33f-f00d-111111116666";

private static final String USER_HERMAN_FILENAME = TEST_DIR + "user-herman.xml";
private static final String USER_HERMAN_OID = "c0c010c0-d34d-b33f-f00d-111111119999";
Expand Down Expand Up @@ -186,7 +186,7 @@ public class TestConsistencyMechanism extends AbstractModelIntegrationTest {

private static final String ACCOUNT_DENIELS_FILENAME = TEST_DIR + "account-deniels.xml";
private static final File ACCOUNT_DENIELS_FILE = new File(ACCOUNT_DENIELS_FILENAME);
private static final String ACCOUNT_DENIELS_OID = "a0c010c0-d34d-b33f-f00d-111111111555";
protected static final String ACCOUNT_DENIELS_OID = "a0c010c0-d34d-b33f-f00d-111111111555";
private static final String ACCOUNT_DENIELS_LDAP_UID = "deniels";
private static final String ACCOUNT_DENIELS_LDAP_DN = "uid=" + ACCOUNT_DENIELS_LDAP_UID + "," + OPENDJ_PEOPLE_SUFFIX;

Expand Down Expand Up @@ -252,14 +252,18 @@ public void initSystem(Task initTask, OperationResult initResult) throws Excepti

// Need to import instead of add, so the (dynamic) connector reference
// will be resolved correctly
importObjectFromFile(RESOURCE_OPENDJ_FILENAME, initResult);
importObjectFromFile(getResourceFile(), initResult);

repoAddObjectFromFile(SAMPLE_CONFIGURATION_OBJECT_FILENAME, initResult);
repoAddObjectFromFile(USER_TEMPLATE_FILENAME, initResult);

assumeAssignmentPolicy(AssignmentPolicyEnforcementType.POSITIVE);
}

protected File getResourceFile() {
return RESOURCE_OPENDJ_FILE;
}

// @Override
// protected TracingProfileType getTestMethodTracingProfile() {
// return createModelAndProvisioningLoggingTracingProfile()
Expand Down Expand Up @@ -690,25 +694,11 @@ public void test130DeleteObjectNotFound() throws Exception {
executeChanges(deleteDelta, null, task, parentResult);
parentResult.computeStatus();

PrismObject<ShadowType> shadowRepo = getShadowRepo(ACCOUNT_GUYBRUSH_OID);
ShadowAsserter.forShadow(shadowRepo)
.assertTombstone()
.assertDead()
.assertIsNotExists();

clockForward("PT20M");

// THEN
then();
provisioningService.refreshShadow(shadowRepo, null, task, parentResult);
checkTest130DeadShadow(task, parentResult);

try {
repositoryService.getObject(ShadowType.class, ACCOUNT_GUYBRUSH_OID, null, parentResult);
fail("Unexpected object found");
} catch (Exception ex) {
if (!(ex instanceof ObjectNotFoundException)) {
fail("Expected ObjectNotFoundException but got " + ex);
}
}
assertNoRepoShadow(ACCOUNT_GUYBRUSH_OID);

clock.resetOverride();

Expand All @@ -719,6 +709,19 @@ public void test130DeleteObjectNotFound() throws Exception {
repositoryService.deleteObject(UserType.class, USER_GUYBRUSH_OID, parentResult);
}

protected void checkTest130DeadShadow(Task task, OperationResult parentResult) throws CommonException {
PrismObject<ShadowType> shadowRepo = getShadowRepo(ACCOUNT_GUYBRUSH_OID);
ShadowAsserter.forShadow(shadowRepo)
.assertTombstone()
.assertDead()
.assertIsNotExists();

clockForward("PT20M");

then();
provisioningService.refreshShadow(shadowRepo, null, task, parentResult);
}

/**
* Modify account not found => reaction: Delete account
* <p>
Expand Down Expand Up @@ -756,23 +759,9 @@ public void test140ModifyObjectNotFoundLinkedAccount() throws Exception {

// THEN
then();
PrismObject<ShadowType> shadowAfter = getShadowRepo(ACCOUNT_GUYBRUSH_OID);
ShadowAsserter.forShadow(shadowAfter)
.assertTombstone()
.assertDead()
.assertIsNotExists();

clockForward("PT20M");
provisioningService.refreshShadow(shadowAfter, null, task, result);
checkTest140DeadShadow(task, result);

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);
}
}
assertNoRepoShadow(ACCOUNT_GUYBRUSH_OID);

clock.resetOverride();
PrismObject<UserType> userAfter = getUser(USER_GUYBRUSH_OID);
Expand All @@ -782,6 +771,17 @@ public void test140ModifyObjectNotFoundLinkedAccount() throws Exception {
// repositoryService.deleteObject(UserType.class, USER_GUYBRUSH_OID, result);
}

protected void checkTest140DeadShadow(Task task, OperationResult result) throws CommonException {
PrismObject<ShadowType> shadowAfter = getShadowRepo(ACCOUNT_GUYBRUSH_OID);
ShadowAsserter.forShadow(shadowAfter)
.assertTombstone()
.assertDead()
.assertIsNotExists();

clockForward("PT20M");
provisioningService.refreshShadow(shadowAfter, null, task, result);
}

/**
* Modify account not found => reaction: Re-create account, apply changes.
* <p>
Expand Down Expand Up @@ -2576,7 +2576,17 @@ public void test800Reconciliation() throws Exception {
assertAttribute(modifiedAccount, "givenName", "Jackkk");
assertAttribute(modifiedAccount, "employeeNumber", "emp4321");

// check if the account was marked as dead during the reconciliation process
// check if the account was marked as dead (or deleted) during the reconciliation process
assert800DeadShadows();

accountOid = assertUserOneAccountRef(USER_JACKIE_OID);
ShadowType jack2Shadow = checkNormalizedShadowBasic(accountOid, "jack2", true, SelectorOptions.createCollection(GetOperationOptions.createDoNotDiscovery()), null, result);
assertAttribute(jack2Shadow, "givenName", "jackNew2a");
assertAttribute(jack2Shadow, "cn", "jackNew2a");

}

protected void assert800DeadShadows() throws CommonException {
assertRepoShadow(ACCOUNT_DENIELS_OID)
.assertDead();

Expand Down Expand Up @@ -2611,11 +2621,6 @@ public void test800Reconciliation() throws Exception {
.delta()
.assertAdd();

accountOid = assertUserOneAccountRef(USER_JACKIE_OID);
ShadowType jack2Shadow = checkNormalizedShadowBasic(accountOid, "jack2", true, SelectorOptions.createCollection(GetOperationOptions.createDoNotDiscovery()), null, result);
assertAttribute(jack2Shadow, "givenName", "jackNew2a");
assertAttribute(jack2Shadow, "cn", "jackNew2a");

}

//MID-5844
Expand Down
@@ -0,0 +1,123 @@
/*
* Copyright (c) 2010-2020 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.testing.story.consistency;

import com.evolveum.midpoint.common.refinery.RefinedResourceSchemaImpl;
import com.evolveum.midpoint.model.test.AbstractModelIntegrationTest;
import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.prism.crypto.EncryptionException;
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.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.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.MidPointConstants;
import com.evolveum.midpoint.schema.constants.ObjectTypes;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.processor.*;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.result.OperationResultStatus;
import com.evolveum.midpoint.schema.util.*;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.test.asserter.LinksAsserter;
import com.evolveum.midpoint.test.asserter.ShadowAsserter;
import com.evolveum.midpoint.test.asserter.ShadowReferenceAsserter;
import com.evolveum.midpoint.test.asserter.UserAsserter;
import com.evolveum.midpoint.test.ldap.OpenDJController;
import com.evolveum.midpoint.test.util.TestUtil;
import com.evolveum.midpoint.util.DOMUtil;
import com.evolveum.midpoint.util.exception.*;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFactory;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ActivationCapabilityType;
import com.evolveum.prism.xml.ns._public.types_3.ChangeTypeType;
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;

import org.apache.commons.lang3.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 javax.xml.bind.JAXBElement;
import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.namespace.QName;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import static com.evolveum.midpoint.prism.util.PrismTestUtil.getPrismContext;
import static com.evolveum.midpoint.test.IntegrationTestTools.assertNoRepoThreadLocalCache;

import static org.assertj.core.api.Assertions.assertThat;
import static org.testng.AssertJUnit.*;

/**
* Almost same sa TestConsistencyMechanism, but this reaps dead shadows immediately (deadShadowRetentionPeriod=0).
*
* @author Radovan Semancik
*/
@ContextConfiguration(locations = { "classpath:ctx-story-test-main.xml" })
@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
public class TestConsistencyReaper extends TestConsistencyMechanism {

private static final File RESOURCE_OPENDJ_FILE = new File(TEST_DIR, "resource-opendj-reaper.xml");

protected File getResourceFile() {
return RESOURCE_OPENDJ_FILE;
}

@Override
protected void checkTest130DeadShadow(Task task, OperationResult parentResult) {
// nothing to do. Dead shadows are reaped immediately.
}

@Override
protected void checkTest140DeadShadow(Task task, OperationResult parentResult) {
// nothing to do. Dead shadows are reaped immediately.
}

@Override
protected void assert800DeadShadows() throws CommonException {
assertNoRepoShadow(ACCOUNT_DENIELS_OID);

LinksAsserter linksAsserter = assertUser(USER_ELAINE_OID, "User after recon")
.assertLinks(1)
.links();

ShadowReferenceAsserter notDeadShadow = linksAsserter.by()
.dead(false)
.find();

assertModelShadow(notDeadShadow.getOid())
.display()
.attributes()
.assertHasPrimaryIdentifier()
.assertHasSecondaryIdentifier()
.end()
.end();

}

}

0 comments on commit 7900ead

Please sign in to comment.