Skip to content

Commit

Permalink
adding test for MID-4038
Browse files Browse the repository at this point in the history
  • Loading branch information
katkav committed Mar 18, 2020
1 parent 9dc71a4 commit 7841029
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 42 deletions.
Expand Up @@ -679,6 +679,10 @@ private <O extends ObjectType, F extends FocusType> void updateLinks(LensContext
}

private <F extends FocusType> boolean linkShouldExist(LensFocusContext<F> focusContext, LensProjectionContext projCtx, PrismObject<ShadowType> 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;
Expand All @@ -691,7 +695,7 @@ private <F extends FocusType> boolean linkShouldExist(LensFocusContext<F> focusC
}
if (projCtx.getSynchronizationPolicyDecision() == SynchronizationPolicyDecision.DELETE
|| projCtx.isDelete()) {
return !focusContext.isDelete() && shadowAfterModification != null;
return shadowAfterModification != null;
}
if (projCtx.hasPendingOperations()) {
return true;
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -78,50 +93,12 @@ public void test050AddResource() throws Exception {
PrismObject<ResourceType> 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<ShadowType> account = PrismTestUtil.parseObject(ACCOUNT_JACK_DUMMY_FILE);

Collection<ItemDelta<?, ?>> 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<UserType> 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<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result);
assertDummyAccountShadowRepo(accountShadow, accountOid, "jack");

// Check account
PrismObject<ShadowType> 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
Expand Down Expand Up @@ -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<ShadowType> 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<ShadowType> account = PrismTestUtil.parseObject(accountFile);

Collection<ItemDelta<?, ?>> 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<UserType> 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<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result);
assertAccountShadowRepo(accountShadow, accountOid, "jack", dummyController.getResourceType());
assertSituation(accountShadow, SynchronizationSituationType.LINKED);

// Check account
PrismObject<ShadowType> 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);
}
}
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->

<shadow
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:icfs="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/resource-schema-3"
xmlns:ri="http://midpoint.evolveum.com/xml/ns/public/resource/instance-3">
<resourceRef oid="10000000-0000-0000-0000-00000000e105"/>
<objectClass>ri:AccountObjectClass</objectClass>
<attributes>
<icfs:name>jack</icfs:name>
<ri:fullname>Jack Sparrow</ri:fullname>
</attributes>
<activation>
<administrativeStatus>enabled</administrativeStatus>
</activation>
</shadow>
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2010-2017 Evolveum and contributors
~
~ This work is dual-licensed under the Apache License 2.0
~ and European Union Public License. See LICENSE file for details.
-->

<resource oid="10000000-0000-0000-0000-00000000e105"
xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
xmlns:c="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
xmlns:q="http://prism.evolveum.com/xml/ns/public/query-3"
xmlns:t="http://prism.evolveum.com/xml/ns/public/types-3"
xmlns:icfs="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/resource-schema-3"
xmlns:ri="http://midpoint.evolveum.com/xml/ns/public/resource/instance-3"
xmlns:cap="http://midpoint.evolveum.com/xml/ns/public/resource/capabilities-3"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<name>
<t:orig>Dummy Resource Maroon No Delete</t:orig>
<!-- t:norm is intentionally missing -->
</name>
<description>Resource used for add test in CRUD interface</description>
<connectorRef type="c:ConnectorType">
<filter>
<q:and>
<q:equal>
<q:path>connectorType</q:path>
<q:value>com.evolveum.icf.dummy.connector.DummyConnector</q:value>
</q:equal>
<q:equal>
<q:path>connectorVersion</q:path>
<q:value>2.0</q:value>
</q:equal>
</q:and>
</filter>
</connectorRef>
<connectorConfiguration xmlns:icfi="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/bundle/com.evolveum.icf.dummy/com.evolveum.icf.dummy.connector.DummyConnector"
xmlns:icfc="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/connector-schema-3">

<icfc:configurationProperties>
<icfi:instanceId>maroonNoDelete</icfi:instanceId>
</icfc:configurationProperties>

</connectorConfiguration>

<capabilities>
<configured>
<cap:delete>
<cap:enabled>false</cap:enabled>
</cap:delete>
</configured>
</capabilities>

</resource>

0 comments on commit 7841029

Please sign in to comment.