Skip to content

Commit

Permalink
repo-sqale: hasConflict() result status fix if getVersion find no object
Browse files Browse the repository at this point in the history
hasConflict() now uses internal executeGetVersion(); if getVersion()
fails to find an object, it still sets fatal error on the result.
If this proves to be a problem (old repo doesn't do that) it can be
changed as well.
  • Loading branch information
virgo47 committed Jul 21, 2021
1 parent 8252601 commit bb92462
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 48 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2017 Evolveum and contributors
* Copyright (C) 2010-2021 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
Expand All @@ -12,8 +12,6 @@
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 All @@ -30,6 +28,7 @@
import com.evolveum.midpoint.prism.util.PrismTestUtil;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.test.DummyResourceContoller;
import com.evolveum.midpoint.test.IntegrationTestTools;
import com.evolveum.midpoint.test.util.TestUtil;
import com.evolveum.midpoint.util.exception.ObjectNotFoundException;
Expand Down Expand Up @@ -73,19 +72,19 @@ public void initSystem(Task initTask, OperationResult initResult) throws Excepti

@Test
public void test050AddResourceMaroon() throws Exception {
// GIVEN
given();
Task task = getTestTask();
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.NONE);

ResourceType resourceType = (ResourceType) PrismTestUtil.parseObject(RESOURCE_MAROON_FILE).asObjectable();

// WHEN
when();
PrismObject<ResourceType> object = resourceType.asPrismObject();
prismContext.adopt(resourceType);
modelCrudService.addObject(object, null, task, result);

// THEN
then();
result.computeStatus();
TestUtil.assertSuccess(result);

Expand All @@ -103,8 +102,7 @@ public void test100ModifyUserAddAccount() throws Exception {

@Test
public void test119ModifyUserDeleteAccount() throws Exception {

// GIVEN
given();
Task task = taskManager.createTaskInstance(TestModelCrudService.class.getName() + ".test119ModifyUserDeleteAccount");
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.NONE);
Expand All @@ -118,10 +116,10 @@ public void test119ModifyUserDeleteAccount() throws Exception {
ReferenceDelta accountDelta = prismContext.deltaFactory().reference().createModificationDelete(UserType.F_LINK_REF, getUserDefinition(), account);
modifications.add(accountDelta);

// WHEN
when();
modelCrudService.modifyObject(UserType.class, USER_JACK_OID, modifications, null, task, result);

// THEN
then();
// Check accountRef
PrismObject<UserType> userJack = modelService.getObject(UserType.class, USER_JACK_OID, null, task, result);
assertUserJack(userJack);
Expand All @@ -142,18 +140,17 @@ public void test119ModifyUserDeleteAccount() throws Exception {

@Test
public void test120AddAccount() throws Exception {

// GIVEN
given();
Task task = taskManager.createTaskInstance(TestModelCrudService.class.getName() + ".test120AddAccount");
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.NONE);

PrismObject<ShadowType> account = PrismTestUtil.parseObject(ACCOUNT_JACK_DUMMY_FILE);

// WHEN
when();
accountOid = modelCrudService.addObject(account, null, task, result);

// THEN
then();
// Check accountRef (should be none)
PrismObject<UserType> userJack = modelService.getObject(UserType.class, USER_JACK_OID, null, task, result);
assertUserJack(userJack);
Expand All @@ -174,8 +171,7 @@ public void test120AddAccount() throws Exception {

@Test
public void test121ModifyUserAddAccountRef() throws Exception {

// GIVEN
given();
Task task = taskManager.createTaskInstance(TestModelCrudService.class.getName() + ".test121ModifyUserAddAccountRef");
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.NONE);
Expand All @@ -184,10 +180,10 @@ public void test121ModifyUserAddAccountRef() throws Exception {
ReferenceDelta accountDelta = prismContext.deltaFactory().reference().createModificationAdd(UserType.F_LINK_REF, getUserDefinition(), accountOid);
modifications.add(accountDelta);

// WHEN
when();
modelCrudService.modifyObject(UserType.class, USER_JACK_OID, modifications, null, task, result);

// THEN
then();
// Check accountRef
PrismObject<UserType> userJack = getUser(USER_JACK_OID);
assertUserJack(userJack);
Expand All @@ -207,8 +203,7 @@ public void test121ModifyUserAddAccountRef() throws Exception {

@Test
public void test128ModifyUserDeleteAccountRef() throws Exception {

// GIVEN
given();
Task task = taskManager.createTaskInstance(TestModelCrudService.class.getName() + ".test128ModifyUserDeleteAccountRef");
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.NONE);
Expand All @@ -222,10 +217,10 @@ public void test128ModifyUserDeleteAccountRef() throws Exception {
.createModificationDelete(UserType.F_LINK_REF, getUserDefinition(), accountOid);
modifications.add(accountDelta);

// WHEN
when();
modelCrudService.modifyObject(UserType.class, USER_JACK_OID, modifications, null, task, result);

// THEN
then();
PrismObject<UserType> userJack = getUser(USER_JACK_OID);
assertUserJack(userJack);
assertUser(userJack, "after")
Expand All @@ -246,16 +241,15 @@ public void test128ModifyUserDeleteAccountRef() throws Exception {

@Test
public void test129DeleteAccount() throws Exception {

// GIVEN
given();
Task task = taskManager.createTaskInstance(TestModelCrudService.class.getName() + ".test129DeleteAccount");
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.NONE);

// WHEN
when();
modelCrudService.deleteObject(ShadowType.class, accountOid, null, task, result);

// THEN
then();
PrismObject<UserType> userJack = getUser(USER_JACK_OID);
assertUserJack(userJack);
// Check accountRef
Expand All @@ -270,19 +264,18 @@ public void test129DeleteAccount() throws Exception {

@Test
public void test150AddUserBlackbeardWithAccount() throws Exception {

// GIVEN
given();
Task task = taskManager.createTaskInstance(TestModelCrudService.class.getName() + ".test150AddUserBlackbeardWithAccount");
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.POSITIVE);

PrismObject<UserType> user = PrismTestUtil.parseObject(new File(TEST_CONTRACT_DIR, "user-blackbeard-account-dummy.xml"));
addAccountLinkRef(user, new File(TEST_CONTRACT_DIR, "account-blackbeard-dummy.xml"));

// WHEN
when();
modelCrudService.addObject(user, null, task, result);

// THEN
then();
// Check accountRef
PrismObject<UserType> userMorgan = modelService.getObject(UserType.class, USER_BLACKBEARD_OID, null, task, result);
UserType userMorganType = userMorgan.asObjectable();
Expand All @@ -305,18 +298,17 @@ public void test150AddUserBlackbeardWithAccount() throws Exception {

@Test
public void test210AddUserMorganWithAssignment() throws Exception {

// GIVEN
given();
Task task = taskManager.createTaskInstance(TestModelCrudService.class.getName() + ".test210AddUserMorganWithAssignment");
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);

PrismObject<UserType> user = PrismTestUtil.parseObject(new File(TEST_CONTRACT_DIR, "user-morgan-assignment-dummy.xml"));

// WHEN
when();
modelCrudService.addObject(user, null, task, result);

// THEN
then();
// Check accountRef
PrismObject<UserType> userMorgan = modelService.getObject(UserType.class, USER_MORGAN_OID, null, task, result);
UserType userMorganType = userMorgan.asObjectable();
Expand All @@ -339,18 +331,17 @@ public void test210AddUserMorganWithAssignment() throws Exception {

@Test
public void test220DeleteUserMorgan() throws Exception {

// GIVEN
Task task = taskManager.createTaskInstance(TestModelCrudService.class.getName() + ".test220DeleteUserMorgan");
given();
Task task = createTask();
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);

assertDummyAccount(null, "morgan");

// WHEN
when();
modelCrudService.deleteObject(FocusType.class, USER_MORGAN_OID, null, task, result);

// THEN
then();
try {
getUser(USER_MORGAN_OID);
fail("User morgan exists even if he should not");
Expand All @@ -373,20 +364,20 @@ public void test301modifyJAckAddAccount() throws Exception {
// test302 has to run after test301, because test302 relies on accountOid set in test301
@Test
public void test302deleteUserJack() throws Exception {
// GIVEN
given();
Task task = getTestTask();
OperationResult result = task.getResult();

//WHEN
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
then();
// Check shadow, must be still in repo, because 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
Expand All @@ -395,7 +386,7 @@ public void test302deleteUserJack() throws Exception {
}

private void testModifyUserJackAddAccount(File accountFile, DummyResourceContoller dummyController) throws Exception {
// GIVEN
given();
Task task = getTestTask();
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.NONE);
Expand All @@ -409,10 +400,10 @@ private void testModifyUserJackAddAccount(File accountFile, DummyResourceContoll
.createModificationAdd(UserType.F_LINK_REF, getUserDefinition(), accountRefVal);
modifications.add(accountDelta);

// WHEN
when();
modelCrudService.modifyObject(UserType.class, USER_JACK_OID, modifications, null, task, result);

// THEN
then();
// Check accountRef
PrismObject<UserType> userJack = modelService.getObject(UserType.class, USER_JACK_OID, null, task, result);
assertUserJack(userJack);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1189,8 +1189,8 @@ public boolean hasConflict(ConflictWatcher watcher, OperationResult parentResult
rv = true;
} else {
try {
getVersion(ObjectType.class, watcher.getOid(), result);
} catch (ObjectNotFoundException | SchemaException e) {
executeGetVersion(ObjectType.class, UUID.fromString(watcher.getOid()));
} catch (ObjectNotFoundException e) {
// just ignore this
}
rv = watcher.hasConflict();
Expand Down

0 comments on commit bb92462

Please sign in to comment.