From 78410299f04d6cc8174b6d2c68ae2e012315c651 Mon Sep 17 00:00:00 2001 From: Katarina Valalikova Date: Wed, 18 Mar 2020 15:24:58 +0100 Subject: [PATCH] adding test for MID-4038 --- .../model/impl/lens/ChangeExecutor.java | 6 +- .../model/intest/TestModelCrudService.java | 132 ++++++++++++------ .../account-jack-dummy-maroon-no-delete.xml | 24 ++++ .../crud/resource-dummy-maroon-no-delete.xml | 56 ++++++++ 4 files changed, 176 insertions(+), 42 deletions(-) create mode 100644 model/model-intest/src/test/resources/crud/account-jack-dummy-maroon-no-delete.xml create mode 100644 model/model-intest/src/test/resources/crud/resource-dummy-maroon-no-delete.xml diff --git a/model/model-impl/src/main/java/com/evolveum/midpoint/model/impl/lens/ChangeExecutor.java b/model/model-impl/src/main/java/com/evolveum/midpoint/model/impl/lens/ChangeExecutor.java index da47f9f5ca4..3ee803bfe3f 100644 --- a/model/model-impl/src/main/java/com/evolveum/midpoint/model/impl/lens/ChangeExecutor.java +++ b/model/model-impl/src/main/java/com/evolveum/midpoint/model/impl/lens/ChangeExecutor.java @@ -679,6 +679,10 @@ private void updateLinks(LensContext } private boolean linkShouldExist(LensFocusContext focusContext, LensProjectionContext projCtx, PrismObject shadowAfterModification, OperationResult result) { + if (focusContext.isDelete()) { + // if we delete focus, link doesn't exist anymore, but be sure, that the situation is updated in shadow + return false; + } if (!projCtx.isShadowExistsInRepo()) { // Nothing to link to return false; @@ -691,7 +695,7 @@ private boolean linkShouldExist(LensFocusContext focusC } if (projCtx.getSynchronizationPolicyDecision() == SynchronizationPolicyDecision.DELETE || projCtx.isDelete()) { - return !focusContext.isDelete() && shadowAfterModification != null; + return shadowAfterModification != null; } if (projCtx.hasPendingOperations()) { return true; diff --git a/model/model-intest/src/test/java/com/evolveum/midpoint/model/intest/TestModelCrudService.java b/model/model-intest/src/test/java/com/evolveum/midpoint/model/intest/TestModelCrudService.java index cf628993b63..67c8144e1dd 100644 --- a/model/model-intest/src/test/java/com/evolveum/midpoint/model/intest/TestModelCrudService.java +++ b/model/model-intest/src/test/java/com/evolveum/midpoint/model/intest/TestModelCrudService.java @@ -12,6 +12,8 @@ import java.util.ArrayList; import java.util.Collection; +import com.evolveum.midpoint.test.DummyResourceContoller; + import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.annotation.DirtiesContext; @@ -48,16 +50,29 @@ public class TestModelCrudService extends AbstractInitializedModelIntegrationTes public static final File RESOURCE_MAROON_FILE = new File(TEST_DIR, "resource-dummy-maroon.xml"); public static final String RESOURCE_MAROON_OID = "10000000-0000-0000-0000-00000000e104"; + private static final File RESOURCE_MAROON_NO_DELETE_FILE = new File(TEST_DIR, "resource-dummy-maroon-no-delete.xml"); + private static final String RESOURCE_MAROON_NO_DELETE_OID = "10000000-0000-0000-0000-00000000e105"; + private static final String RESOURCE_MAROON_NO_DELETE_NAME = "maroonNoDelete"; + private static final String USER_MORGAN_OID = "c0c010c0-d34d-b33f-f00d-171171117777"; private static final String USER_BLACKBEARD_OID = "c0c010c0-d34d-b33f-f00d-161161116666"; + private static final File ACCOUNT_JACK_DUMMY_MAROON_NO_DELETE_FILE = new File(TEST_DIR, "account-jack-dummy-maroon-no-delete.xml"); private static String accountOid; @Autowired protected ModelCrudService modelCrudService; + private DummyResourceContoller maroonNoDeleteCtl; + + @Override + public void initSystem(Task initTask, OperationResult initResult) throws Exception { + super.initSystem(initTask, initResult); + maroonNoDeleteCtl = initDummyResource(RESOURCE_MAROON_NO_DELETE_NAME, RESOURCE_MAROON_NO_DELETE_FILE, RESOURCE_MAROON_NO_DELETE_OID, initTask, initResult); + } + @Test - public void test050AddResource() throws Exception { + public void test050AddResourceMaroon() throws Exception { // GIVEN Task task = getTestTask(); OperationResult result = task.getResult(); @@ -78,50 +93,12 @@ public void test050AddResource() throws Exception { PrismObject resourceAfter = modelService.getObject(ResourceType.class, RESOURCE_MAROON_OID, null, task, result); assertEquals("Wrong orig in resource name", "Dummy Resource Maroon", resourceAfter.asObjectable().getName().getOrig()); assertEquals("Wrong norm in resource name", "dummy resource maroon", resourceAfter.asObjectable().getName().getNorm()); + } @Test public void test100ModifyUserAddAccount() throws Exception { - // GIVEN - Task task = getTestTask(); - OperationResult result = task.getResult(); - assumeAssignmentPolicy(AssignmentPolicyEnforcementType.NONE); - - PrismObject account = PrismTestUtil.parseObject(ACCOUNT_JACK_DUMMY_FILE); - - Collection> modifications = new ArrayList<>(); - PrismReferenceValue accountRefVal = itemFactory().createReferenceValue(); - accountRefVal.setObject(account); - ReferenceDelta accountDelta = prismContext.deltaFactory().reference() - .createModificationAdd(UserType.F_LINK_REF, getUserDefinition(), accountRefVal); - modifications.add(accountDelta); - - // WHEN - modelCrudService.modifyObject(UserType.class, USER_JACK_OID, modifications, null, task, result); - - // THEN - // Check accountRef - PrismObject userJack = modelService.getObject(UserType.class, USER_JACK_OID, null, task, result); - assertUserJack(userJack); - UserType userJackType = userJack.asObjectable(); - assertEquals("Unexpected number of accountRefs", 1, userJackType.getLinkRef().size()); - ObjectReferenceType accountRefType = userJackType.getLinkRef().get(0); - accountOid = accountRefType.getOid(); - assertFalse("No accountRef oid", StringUtils.isBlank(accountOid)); - PrismReferenceValue accountRefValue = accountRefType.asReferenceValue(); - assertEquals("OID mismatch in accountRefValue", accountOid, accountRefValue.getOid()); - assertNull("Unexpected object in accountRefValue", accountRefValue.getObject()); - - // Check shadow - PrismObject accountShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result); - assertDummyAccountShadowRepo(accountShadow, accountOid, "jack"); - - // Check account - PrismObject accountModel = modelService.getObject(ShadowType.class, accountOid, null, task, result); - assertDummyAccountShadowModel(accountModel, accountOid, "jack", "Jack Sparrow"); - - // Check account in dummy resource - assertDefaultDummyAccount("jack", "Jack Sparrow", true); + testModifyUserJackAddAccount(ACCOUNT_JACK_DUMMY_FILE, dummyResourceCtl); } @Test @@ -385,4 +362,77 @@ public void test220DeleteUserMorgan() throws Exception { IntegrationTestTools.display(result); TestUtil.assertSuccess(result); } + + @Test + public void test301modifyJAckAddAccount() throws Exception { + testModifyUserJackAddAccount(ACCOUNT_JACK_DUMMY_MAROON_NO_DELETE_FILE, maroonNoDeleteCtl); + } + + // test302 has to run after test301, because test302 relies on accountOid set in test301 + @Test + public void test302deleteUserJack() throws Exception { + // GIVEN + Task task = getTestTask(); + OperationResult result = task.getResult(); + + //WHEN + try { + deleteObject(UserType.class, USER_JACK_OID, task, result); + fail("Unexpected success. Should fail because resource doesn't support delete and criticality is not set"); + } catch (UnsupportedOperationException e) { + // this is expected + } + + //THEN + // Check shadow, must be still in repo, becuase resource doesn't support delete + PrismObject accountShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result); + assertAccountShadowRepo(accountShadow, accountOid, "jack", maroonNoDeleteCtl.getResourceType()); + //check that situation was updated MID-4038 + assertSituation(accountShadow, null); + + } + + private void testModifyUserJackAddAccount(File accountFile, DummyResourceContoller dummyController) throws Exception { + // GIVEN + Task task = getTestTask(); + OperationResult result = task.getResult(); + assumeAssignmentPolicy(AssignmentPolicyEnforcementType.NONE); + + PrismObject account = PrismTestUtil.parseObject(accountFile); + + Collection> modifications = new ArrayList<>(); + PrismReferenceValue accountRefVal = itemFactory().createReferenceValue(); + accountRefVal.setObject(account); + ReferenceDelta accountDelta = prismContext.deltaFactory().reference() + .createModificationAdd(UserType.F_LINK_REF, getUserDefinition(), accountRefVal); + modifications.add(accountDelta); + + // WHEN + modelCrudService.modifyObject(UserType.class, USER_JACK_OID, modifications, null, task, result); + + // THEN + // Check accountRef + PrismObject userJack = modelService.getObject(UserType.class, USER_JACK_OID, null, task, result); + assertUserJack(userJack); + UserType userJackType = userJack.asObjectable(); + assertEquals("Unexpected number of accountRefs", 1, userJackType.getLinkRef().size()); + ObjectReferenceType accountRefType = userJackType.getLinkRef().get(0); + accountOid = accountRefType.getOid(); + assertFalse("No accountRef oid", StringUtils.isBlank(accountOid)); + PrismReferenceValue accountRefValue = accountRefType.asReferenceValue(); + assertEquals("OID mismatch in accountRefValue", accountOid, accountRefValue.getOid()); + assertNull("Unexpected object in accountRefValue", accountRefValue.getObject()); + + // Check shadow + PrismObject accountShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result); + assertAccountShadowRepo(accountShadow, accountOid, "jack", dummyController.getResourceType()); + assertSituation(accountShadow, SynchronizationSituationType.LINKED); + + // Check account + PrismObject accountModel = modelService.getObject(ShadowType.class, accountOid, null, task, result); + assertAccountShadowModel(accountModel, accountOid, "jack", dummyController.getResourceType()); + + // Check account in dummy resource + assertDummyAccount(dummyController.getDummyResource().getInstanceName(), "jack", "Jack Sparrow", true); + } } diff --git a/model/model-intest/src/test/resources/crud/account-jack-dummy-maroon-no-delete.xml b/model/model-intest/src/test/resources/crud/account-jack-dummy-maroon-no-delete.xml new file mode 100644 index 00000000000..2242170d1bf --- /dev/null +++ b/model/model-intest/src/test/resources/crud/account-jack-dummy-maroon-no-delete.xml @@ -0,0 +1,24 @@ + + + + + + ri:AccountObjectClass + + jack + Jack Sparrow + + + enabled + + diff --git a/model/model-intest/src/test/resources/crud/resource-dummy-maroon-no-delete.xml b/model/model-intest/src/test/resources/crud/resource-dummy-maroon-no-delete.xml new file mode 100644 index 00000000000..d0404d7806c --- /dev/null +++ b/model/model-intest/src/test/resources/crud/resource-dummy-maroon-no-delete.xml @@ -0,0 +1,56 @@ + + + + + + + Dummy Resource Maroon No Delete + + + Resource used for add test in CRUD interface + + + + + connectorType + com.evolveum.icf.dummy.connector.DummyConnector + + + connectorVersion + 2.0 + + + + + + + + maroonNoDelete + + + + + + + + false + + + + +