Skip to content

Commit

Permalink
Consistency update: fixing TestMultiResource ... hopefully without br…
Browse files Browse the repository at this point in the history
…eaking anything else
  • Loading branch information
semancik committed Aug 15, 2018
1 parent d48e20f commit 90d1a9b
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 51 deletions.
Expand Up @@ -1080,7 +1080,9 @@ private <F extends ObjectType> void finishLoadOfProjectionContext(LensContext<F>
projContext.setFullShadow(false);
}
projectionObject = objectOld;
if (!ShadowUtil.isExists(objectOld.asObjectable())) {
if (ShadowUtil.isExists(objectOld.asObjectable())) {
projContext.setExists(true);
} else {
projContext.setExists(false);
if (ShadowUtil.isDead(objectOld.asObjectable())) {
projContext.markTombstone();
Expand Down
Expand Up @@ -685,6 +685,7 @@ public void test226JackKillBothAccounsAndRecompute() throws Exception {
OperationResult result = task.getResult();

assertUserBefore(USER_JACK_OID)
.displayWithProjections()
.assertLinks(2);

getDummyResource().deleteAccountByName(ACCOUNT_JACK_DUMMY_USERNAME);
Expand All @@ -702,13 +703,17 @@ public void test226JackKillBothAccounsAndRecompute() throws Exception {
assertSuccess(result);

assertUserAfter(USER_JACK_OID)
.displayWithProjections()
.links()
.assertLinks(4)
.by()
.resourceOid(RESOURCE_DUMMY_OID)
.dead(true)
.find()
.end()
.assertLinks(3)
// No reason to keep default dummy dead shadow here.
// The "delete" operation is "complete", there are no pending operations
// in the shadow. Therefore provisioning just deletes it.
// .by()
// .resourceOid(RESOURCE_DUMMY_OID)
// .dead(true)
// .find()
// .end()
.by()
.resourceOid(RESOURCE_DUMMY_OID)
.dead(false)
Expand All @@ -728,18 +733,23 @@ public void test226JackKillBothAccounsAndRecompute() throws Exception {
display("dummy resource after", getDummyResource());
display("beige dummy resource after", getDummyResource(RESOURCE_DUMMY_BEIGE_NAME));

assertDummyAccount(null, ACCOUNT_JACK_DUMMY_USERNAME, ACCOUNT_JACK_DUMMY_FULLNAME, true);
assertDummyAccount(RESOURCE_DUMMY_BEIGE_NAME, ACCOUNT_JACK_DUMMY_USERNAME, ACCOUNT_JACK_DUMMY_FULLNAME, true);
// No value for ship ... no place to get it from
assertDummyAccountAttribute(RESOURCE_DUMMY_BEIGE_NAME, ACCOUNT_JACK_DUMMY_USERNAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_SHIP_NAME);

assertDummyAccountByUsername(null, ACCOUNT_JACK_DUMMY_USERNAME)
.assertFullName(ACCOUNT_JACK_DUMMY_FULLNAME)
.assertEnabled();

assertDummyAccountByUsername(RESOURCE_DUMMY_BEIGE_NAME, ACCOUNT_JACK_DUMMY_USERNAME)
.assertFullName(ACCOUNT_JACK_DUMMY_FULLNAME)
.assertEnabled()
// No value for ship ... no place to get it from
.assertNoAttribute(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_SHIP_NAME);

assertNoDummyAccount(RESOURCE_DUMMY_LAVENDER_NAME, ACCOUNT_JACK_DUMMY_USERNAME);
assertNoDummyAccount(RESOURCE_DUMMY_IVORY_NAME, ACCOUNT_JACK_DUMMY_USERNAME);
}

/**
* Cause schema violation on the account during a provisioning operation. This should fail
* the operation, but other operations should proceed and the account should definitelly NOT
* the operation, but other operations should proceed and the account should definitely NOT
* be unlinked.
* MID-2134
*/
Expand All @@ -758,24 +768,48 @@ public void test227ModifyUserJackDefaultDummyBrokenSchemaViolation() throws Exce
// WHEN
displayWhen(TEST_NAME);
modifyUserReplace(USER_JACK_OID, UserType.F_FULL_NAME, task, result,
new PolyString("Cpt. Jack Sparrow", null));
createPolyString("Cpt. Jack Sparrow"));

// THEN
displayThen(TEST_NAME);
result.computeStatus();
display("Result", result);
TestUtil.assertPartialError(result);
assertPartialError(result);

PrismObject<UserType> userJack = getUser(USER_JACK_OID);
assertLinks(userJack, 2);
assertUserAfter(USER_JACK_OID)
.links()
.assertLinks(3)
.by()
.resourceOid(RESOURCE_DUMMY_OID)
.dead(false)
.find()
.end()
.by()
// dead shadow from previous test. We leave it here
// by purpose. It causes some nuisance. But it should not
// ruin anything.
.resourceOid(RESOURCE_DUMMY_BEIGE_OID)
.dead(true)
.find()
.end()
.by()
.resourceOid(RESOURCE_DUMMY_BEIGE_OID)
.dead(false)
.find()
.end();

display("dummy resource after", getDummyResource());
display("beige dummy resource after", getDummyResource(RESOURCE_DUMMY_BEIGE_NAME));

assertDummyAccount(null, ACCOUNT_JACK_DUMMY_USERNAME, ACCOUNT_JACK_DUMMY_FULLNAME, true);
assertDummyAccount(RESOURCE_DUMMY_BEIGE_NAME, ACCOUNT_JACK_DUMMY_USERNAME, "Cpt. Jack Sparrow", true);
// No value for ship ... no place to get it from
assertDummyAccountAttribute(RESOURCE_DUMMY_BEIGE_NAME, ACCOUNT_JACK_DUMMY_USERNAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_SHIP_NAME);
assertDummyAccountByUsername(null, ACCOUNT_JACK_DUMMY_USERNAME)
// Full name is NOT modified here because of (simulated) schema exception.
.assertFullName(ACCOUNT_JACK_DUMMY_FULLNAME)
.assertEnabled();

assertDummyAccountByUsername(RESOURCE_DUMMY_BEIGE_NAME, ACCOUNT_JACK_DUMMY_USERNAME)
// Full name is modified here. Operation done.
.assertFullName("Cpt. Jack Sparrow")
.assertEnabled()
// No value for ship ... no place to get it from
.assertNoAttribute(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_SHIP_NAME);

assertNoDummyAccount(RESOURCE_DUMMY_LAVENDER_NAME, ACCOUNT_JACK_DUMMY_USERNAME);
assertNoDummyAccount(RESOURCE_DUMMY_IVORY_NAME, ACCOUNT_JACK_DUMMY_USERNAME);
Expand All @@ -801,27 +835,49 @@ public void test228ModifyUserJackDefaultDummyNoError() throws Exception {
// WHEN
displayWhen(TEST_NAME);
modifyUserReplace(USER_JACK_OID, UserType.F_FULL_NAME, task, result,
new PolyString(USER_JACK_FULL_NAME, null));
createPolyString(USER_JACK_FULL_NAME));

// THEN
displayThen(TEST_NAME);
result.computeStatus();
display("Result", result);
TestUtil.assertSuccess(result);

PrismObject<UserType> userJack = getUser(USER_JACK_OID);
assertLinks(userJack, 2);

display("dummy resource after", getDummyResource());
display("beige dummy resource after", getDummyResource(RESOURCE_DUMMY_BEIGE_NAME));

assertDummyAccount(null, ACCOUNT_JACK_DUMMY_USERNAME, ACCOUNT_JACK_DUMMY_FULLNAME, true);
assertDummyAccount(RESOURCE_DUMMY_BEIGE_NAME, ACCOUNT_JACK_DUMMY_USERNAME, ACCOUNT_JACK_DUMMY_FULLNAME, true);
// No value for ship ... no place to get it from
assertDummyAccountAttribute(RESOURCE_DUMMY_BEIGE_NAME, ACCOUNT_JACK_DUMMY_USERNAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_SHIP_NAME);
assertSuccess(result);

assertNoDummyAccount(RESOURCE_DUMMY_LAVENDER_NAME, ACCOUNT_JACK_DUMMY_USERNAME);
assertNoDummyAccount(RESOURCE_DUMMY_IVORY_NAME, ACCOUNT_JACK_DUMMY_USERNAME);
assertUserAfter(USER_JACK_OID)
.links()
.assertLinks(3)
.by()
.resourceOid(RESOURCE_DUMMY_OID)
.dead(false)
.find()
.end()
.by()
// dead shadow from previous test. We leave it here
// by purpose. It causes some nuisance. But it should not
// ruin anything.
.resourceOid(RESOURCE_DUMMY_BEIGE_OID)
.dead(true)
.find()
.end()
.by()
.resourceOid(RESOURCE_DUMMY_BEIGE_OID)
.dead(false)
.find()
.end();

display("dummy resource after", getDummyResource());
display("beige dummy resource after", getDummyResource(RESOURCE_DUMMY_BEIGE_NAME));

assertDummyAccountByUsername(null, ACCOUNT_JACK_DUMMY_USERNAME)
.assertFullName(ACCOUNT_JACK_DUMMY_FULLNAME)
.assertEnabled();

assertDummyAccountByUsername(RESOURCE_DUMMY_BEIGE_NAME, ACCOUNT_JACK_DUMMY_USERNAME)
.assertFullName(ACCOUNT_JACK_DUMMY_FULLNAME)
.assertEnabled()
// No value for ship ... no place to get it from
.assertNoAttribute(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_SHIP_NAME);

assertNoDummyAccount(RESOURCE_DUMMY_LAVENDER_NAME, ACCOUNT_JACK_DUMMY_USERNAME);
assertNoDummyAccount(RESOURCE_DUMMY_IVORY_NAME, ACCOUNT_JACK_DUMMY_USERNAME);
}

/**
Expand All @@ -848,16 +904,31 @@ public void test229JackUnassignDummyBeigeAndDefault() throws Exception {

// THEN
displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);

PrismObject<UserType> userJack = getUser(USER_JACK_OID);
assertLinks(userJack, 0);
assertSuccess(result);

String deadShadowOid = assertUserAfter(USER_JACK_OID)
.links()
.single()
// dead shadow from previous test. We leave it here
// by purpose. It causes some nuisance. But it should not
// ruin anything.
.resolveTarget()
.assertResource(RESOURCE_DUMMY_BEIGE_OID)
.assertDead()
.getOid();

assertNoDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME);
assertNoDummyAccount(RESOURCE_DUMMY_LAVENDER_NAME, ACCOUNT_JACK_DUMMY_USERNAME);
assertNoDummyAccount(RESOURCE_DUMMY_IVORY_NAME, ACCOUNT_JACK_DUMMY_USERNAME);
assertNoDummyAccount(RESOURCE_DUMMY_BEIGE_NAME, ACCOUNT_JACK_DUMMY_USERNAME);

// CLEANUP - make sure we have clean slate for next tests
displayCleanup(TEST_NAME);
forceDeleteShadow(deadShadowOid);

assertNoShadow(deadShadowOid);
assertUserAfter(USER_JACK_OID)
.assertLinks(0);
}


Expand Down Expand Up @@ -2128,8 +2199,7 @@ public void test419DavidAndGoliathUnassignRole() throws Exception {

// THEN
displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result, 2);
assertSuccess(result, 2);

assertUserAfter(userBefore.getOid())
.assertName(USER_FIELD_NAME)
Expand All @@ -2151,7 +2221,6 @@ public void test419DavidAndGoliathUnassignRole() throws Exception {
dummyAuditService.assertExecutionDeltas(2,2);
dummyAuditService.assertHasDelta(1,ChangeType.MODIFY, UserType.class);
dummyAuditService.assertHasDelta(1,ChangeType.DELETE, ShadowType.class);
dummyAuditService.assertExecutionSuccess();
}

@Test
Expand Down Expand Up @@ -2417,7 +2486,6 @@ public void test428DavidAndGoliathUnassignRole() throws Exception {
dummyAuditService.assertHasDelta(1,ChangeType.DELETE, ShadowType.class);
dummyAuditService.assertExecutionDeltas(2,1);
dummyAuditService.assertHasDelta(1,ChangeType.DELETE, ShadowType.class);
dummyAuditService.assertExecutionSuccess();
}

/**
Expand Down
Expand Up @@ -34,6 +34,7 @@
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.PrismReference;
import com.evolveum.midpoint.prism.util.PrismAsserts;
import com.evolveum.midpoint.schema.util.ShadowUtil;
import com.evolveum.midpoint.test.IntegrationTestTools;
import com.evolveum.midpoint.util.exception.ObjectNotFoundException;
import com.evolveum.midpoint.util.exception.SchemaException;
Expand Down Expand Up @@ -221,13 +222,33 @@ PrismObject<ShadowType> getLinkTarget(String oid) throws ObjectNotFoundException
}

public FocusAsserter<F,RA> displayWithProjections() throws ObjectNotFoundException, SchemaException {
display();
StringBuilder sb = new StringBuilder();
List<PrismObject<ShadowType>> linkTargets = getLinkTargets();
sb.append(getObject()).append(" ").append(linkTargets.size()).append(" projections:");
for (PrismObject<ShadowType> linkTarget: getLinkTargets()) {
IntegrationTestTools.display("projetion of "+desc(), linkTarget);
sb.append("\n ");
sb.append(linkTarget);
ShadowType shadowType = linkTarget.asObjectable();
ObjectReferenceType resourceRef = shadowType.getResourceRef();
sb.append(", resource=").append(resourceRef.getOid());
appendFlag(sb, "dead", shadowType.isDead());
appendFlag(sb, "exists", shadowType.isExists());
List<PendingOperationType> pendingOperations = shadowType.getPendingOperation();
if (!pendingOperations.isEmpty()) {
sb.append(", ").append(pendingOperations.size()).append(" pending operations");
}

}
IntegrationTestTools.display(desc(), sb.toString());
return this;
}

private void appendFlag(StringBuilder sb, String label, Boolean val) {
if (val != null) {
sb.append(", ").append(label).append("=").append(val);
}
}

public AssignmentsAsserter<F, ? extends FocusAsserter<F,RA>, RA> assignments() {
AssignmentsAsserter<F,FocusAsserter<F,RA>,RA> asserter = new AssignmentsAsserter<>(this, getDetails());
copySetupTo(asserter);
Expand Down
Expand Up @@ -31,6 +31,7 @@
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationStatusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.PendingOperationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType;
Expand Down Expand Up @@ -147,6 +148,15 @@ public ShadowAsserter<R> assertAdministrativeStatus(ActivationStatusType expecte
return this;
}

public ShadowAsserter<R> assertResource(String expectedResourceOid) {
ObjectReferenceType resourceRef = getObject().asObjectable().getResourceRef();
if (resourceRef == null) {
fail("No resourceRef in "+desc());
}
assertEquals("Wrong resourceRef OID in "+desc(), expectedResourceOid, resourceRef.getOid());
return this;
}

private ActivationType getActivation() {
return getObject().asObjectable().getActivation();
}
Expand Down

0 comments on commit 90d1a9b

Please sign in to comment.