use of com.evolveum.midpoint.model.api.context.ModelProjectionContext in project midpoint by Evolveum.
the class TestPreviewChanges method test600ModifyElaineUserDummyReplace.
/**
* Changing USER fullName (replace delta), no account changes.
*/
@Test
public void test600ModifyElaineUserDummyReplace() throws Exception {
final String TEST_NAME = "test600ModifyElaineUserDummyReplace";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestPreviewChanges.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.NONE);
ObjectDelta<UserType> userDelta = createModifyUserReplaceDelta(USER_ELAINE_OID, UserType.F_FULL_NAME, PrismTestUtil.createPolyString("Elaine Threepwood"));
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta);
display("Input deltas: ", deltas);
// WHEN
TestUtil.displayWhen(TEST_NAME);
ModelContext<UserType> modelContext = modelInteractionService.previewChanges(deltas, new ModelExecuteOptions(), task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
display("Preview context", modelContext);
assertNotNull("Null model context", modelContext);
result.computeStatus();
TestUtil.assertSuccess(result);
ModelElementContext<UserType> focusContext = modelContext.getFocusContext();
assertNotNull("Null model focus context", focusContext);
ObjectDelta<UserType> userPrimaryDelta = focusContext.getPrimaryDelta();
assertNotNull("No focus primary delta: " + userPrimaryDelta, userPrimaryDelta);
PrismAsserts.assertModifications(userPrimaryDelta, 1);
PrismAsserts.assertPropertyReplace(userPrimaryDelta, UserType.F_FULL_NAME, PrismTestUtil.createPolyString("Elaine Threepwood"));
ObjectDelta<UserType> userSecondaryDelta = focusContext.getSecondaryDelta();
assertSideEffectiveDeltasOnly("focus secondary delta", userSecondaryDelta);
Collection<? extends ModelProjectionContext> projectionContexts = modelContext.getProjectionContexts();
assertNotNull("Null model projection context list", projectionContexts);
assertEquals("Unexpected number of projection contexts", 3, projectionContexts.size());
// DEFAULT dummy resource: normal mappings
ModelProjectionContext accContext = modelContext.findProjectionContext(new ResourceShadowDiscriminator(RESOURCE_DUMMY_OID, ShadowKindType.ACCOUNT, null));
assertNotNull("Null model projection context (default)", accContext);
assertEquals("Wrong policy decision (default)", SynchronizationPolicyDecision.KEEP, accContext.getSynchronizationPolicyDecision());
ObjectDelta<ShadowType> accountPrimaryDelta = accContext.getPrimaryDelta();
assertNull("Unexpected account primary delta (default)", accountPrimaryDelta);
ObjectDelta<ShadowType> accountSecondaryDelta = accContext.getSecondaryDelta();
assertNotNull("No account secondary delta (default)", accountSecondaryDelta);
PrismAsserts.assertModifications(accountSecondaryDelta, 3);
PrismAsserts.assertPropertyReplace(accountSecondaryDelta, getDummyResourceController().getAttributePath(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME), "Elaine Threepwood");
PrismAsserts.assertPropertyAdd(accountSecondaryDelta, getDummyResourceController().getAttributePath(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_DRINK_NAME), "rum");
PrismAsserts.assertPropertyAdd(accountSecondaryDelta, getDummyResourceController().getAttributePath(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_QUOTE_NAME), "Arr!");
// RED dummy resource: strong mappings
accContext = modelContext.findProjectionContext(new ResourceShadowDiscriminator(RESOURCE_DUMMY_RED_OID, ShadowKindType.ACCOUNT, null));
assertNotNull("Null model projection context (red)", accContext);
assertEquals("Wrong policy decision", SynchronizationPolicyDecision.KEEP, accContext.getSynchronizationPolicyDecision());
accountPrimaryDelta = accContext.getPrimaryDelta();
assertNull("Unexpected account primary delta (red)", accountPrimaryDelta);
accountSecondaryDelta = accContext.getSecondaryDelta();
assertNotNull("No account secondary delta (red)", accountSecondaryDelta);
PrismAsserts.assertModifications(accountSecondaryDelta, 2);
PrismAsserts.assertPropertyReplace(accountSecondaryDelta, getAttributePath(getDummyResourceObject(RESOURCE_DUMMY_RED_NAME), DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME), "Elaine Threepwood");
PrismAsserts.assertPropertyAdd(accountSecondaryDelta, getAttributePath(getDummyResourceObject(RESOURCE_DUMMY_RED_NAME), DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_QUOTE_NAME), "null -- red resource");
// BLUE dummy resource: weak mappings
accContext = modelContext.findProjectionContext(new ResourceShadowDiscriminator(RESOURCE_DUMMY_BLUE_OID, ShadowKindType.ACCOUNT, null));
assertNotNull("Null model projection context (blue)", accContext);
assertEquals("Wrong policy decision", SynchronizationPolicyDecision.KEEP, accContext.getSynchronizationPolicyDecision());
accountPrimaryDelta = accContext.getPrimaryDelta();
assertNull("Unexpected account primary delta (blue)", accountPrimaryDelta);
accountSecondaryDelta = accContext.getSecondaryDelta();
PrismAsserts.assertModifications(accountSecondaryDelta, 3);
PrismAsserts.assertPropertyAdd(accountSecondaryDelta, getAttributePath(resourceDummyBlue, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_GOSSIP_NAME), "SystemConfiguration");
}
use of com.evolveum.midpoint.model.api.context.ModelProjectionContext in project midpoint by Evolveum.
the class TestPreviewChanges method test242PreviewGuybrushAddRolePirateRelative.
/**
* MID-3079
* Relative operation on a relative resource. The account is not retrieved.
* There are no old values at all.
*/
@Test
public void test242PreviewGuybrushAddRolePirateRelative() throws Exception {
final String TEST_NAME = "test242PreviewGuybrushAddRolePirateRelative";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestPreviewChanges.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.RELATIVE);
ObjectDelta<UserType> delta = createAssignmentFocusDelta(UserType.class, USER_GUYBRUSH_OID, ROLE_PIRATE_RELATIVE_OID, RoleType.COMPLEX_TYPE, null, null, null, true);
// WHEN
TestUtil.displayWhen(TEST_NAME);
ModelContext<UserType> modelContext = modelInteractionService.previewChanges(MiscSchemaUtil.createCollection(delta), null, task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
display("Preview context", modelContext);
assertNotNull("Null model context", modelContext);
result.computeStatus();
TestUtil.assertSuccess(result);
ModelElementContext<UserType> focusContext = modelContext.getFocusContext();
assertNotNull("Model focus context missing", focusContext);
Collection<? extends ModelProjectionContext> projectionContexts = modelContext.getProjectionContexts();
assertNotNull("Null model projection context list", projectionContexts);
assertEquals("Unexpected number of projection contexts", 1, projectionContexts.size());
ModelProjectionContext accContext = projectionContexts.iterator().next();
assertNotNull("Null model projection context", accContext);
ObjectDelta<ShadowType> accountPrimaryDelta = accContext.getPrimaryDelta();
assertNull("Unexpected account primary delta", accountPrimaryDelta);
ObjectDelta<ShadowType> accountSecondaryDelta = accContext.getSecondaryDelta();
assertEquals(ChangeType.MODIFY, accountSecondaryDelta.getChangeType());
assertAccountDummyAttributeModify(accountSecondaryDelta, RESOURCE_DUMMY_RELATIVE_NAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME, // old
null, // add
new String[] { ROLE_PIRATE_WEAPON }, // delete
null, // replace
null);
assertAccountDummyAttributeModify(accountSecondaryDelta, RESOURCE_DUMMY_RELATIVE_NAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_TITLE_NAME, // old
null, // add
new String[] { ROLE_PIRATE_TITLE }, // delete
null, // replace
null);
assertAccountDummyAttributeModify(accountSecondaryDelta, RESOURCE_DUMMY_RELATIVE_NAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_GOSSIP_NAME, // old
null, // add
new String[] { "Guybrush Threepwood is the best pirate Melee Island has ever seen" }, // delete
null, // replace
null);
PrismAsserts.assertModifications(accountSecondaryDelta, 3);
}
use of com.evolveum.midpoint.model.api.context.ModelProjectionContext in project midpoint by Evolveum.
the class TestPreviewChanges method assertAddAccount.
private void assertAddAccount(ModelContext<UserType> modelContext, boolean expectFullNameDelta) {
assertNotNull("Null model context", modelContext);
ModelElementContext<UserType> focusContext = modelContext.getFocusContext();
assertNotNull("Null model focus context", focusContext);
assertNull("Unexpected focus primary delta: " + focusContext.getPrimaryDelta(), focusContext.getPrimaryDelta());
assertSideEffectiveDeltasOnly(focusContext.getSecondaryDelta(), "focus secondary delta", ActivationStatusType.ENABLED);
Collection<? extends ModelProjectionContext> projectionContexts = modelContext.getProjectionContexts();
assertNotNull("Null model projection context list", projectionContexts);
assertEquals("Unexpected number of projection contexts", 1, projectionContexts.size());
ModelProjectionContext accContext = projectionContexts.iterator().next();
assertNotNull("Null model projection context", accContext);
assertEquals("Wrong policy decision", SynchronizationPolicyDecision.ADD, accContext.getSynchronizationPolicyDecision());
ObjectDelta<ShadowType> accountPrimaryDelta = accContext.getPrimaryDelta();
assertEquals(ChangeType.ADD, accountPrimaryDelta.getChangeType());
PrismObject<ShadowType> accountToAddPrimary = accountPrimaryDelta.getObjectToAdd();
assertNotNull("No object in account primary add delta", accountToAddPrimary);
assertEquals(getDummyResourceController().getAccountObjectClass(), accountToAddPrimary.findProperty(ShadowType.F_OBJECT_CLASS).getRealValue());
PrismReference resourceRef = accountToAddPrimary.findReference(ShadowType.F_RESOURCE_REF);
assertEquals(getDummyResourceObject().getOid(), resourceRef.getOid());
ObjectDelta<ShadowType> accountSecondaryDelta = accContext.getSecondaryDelta();
assertEquals(ChangeType.MODIFY, accountSecondaryDelta.getChangeType());
PropertyDelta<String> fullNameDelta = accountSecondaryDelta.findPropertyDelta(dummyResourceCtl.getAttributeFullnamePath());
if (expectFullNameDelta) {
assertNotNull("No full name delta in account secondary delta", fullNameDelta);
PrismAsserts.assertReplace(fullNameDelta, "Jack Sparrow");
PrismAsserts.assertOrigin(fullNameDelta, OriginType.OUTBOUND);
} else {
assertNull("Unexpected full name delta in account secondary delta", fullNameDelta);
}
PrismObject<ShadowType> accountNew = accContext.getObjectNew();
IntegrationTestTools.assertIcfsNameAttribute(accountNew, "jack");
IntegrationTestTools.assertAttribute(accountNew, dummyResourceCtl.getAttributeFullnameQName(), "Jack Sparrow");
}
use of com.evolveum.midpoint.model.api.context.ModelProjectionContext in project midpoint by Evolveum.
the class TestPreviewChanges method test500ModifyElaineAccountDummyBlueReplace.
// the test5xx is testing mappings with blue dummy resource. It has WEAK mappings.
/**
* Changing ACCOUNT fullname (replace delta), no user changes.
*/
@Test
public void test500ModifyElaineAccountDummyBlueReplace() throws Exception {
final String TEST_NAME = "test500ModifyElaineAccountDummyBlueReplace";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestPreviewChanges.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.NONE);
ObjectDelta<ShadowType> accountDelta = createModifyAccountShadowReplaceAttributeDelta(ACCOUNT_SHADOW_ELAINE_DUMMY_BLUE_OID, resourceDummyBlue, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME, "Elaine Threepwood");
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(accountDelta);
display("Input deltas: ", deltas);
// WHEN
ModelContext<UserType> modelContext = modelInteractionService.previewChanges(deltas, new ModelExecuteOptions(), task, result);
// THEN
display("Preview context", modelContext);
assertNotNull("Null model context", modelContext);
result.computeStatus();
TestUtil.assertSuccess(result);
ModelElementContext<UserType> focusContext = modelContext.getFocusContext();
assertNotNull("Null model focus context", focusContext);
assertNull("Unexpected focus primary delta: " + focusContext.getPrimaryDelta(), focusContext.getPrimaryDelta());
ObjectDelta<UserType> userSecondaryDelta = focusContext.getSecondaryDelta();
assertSideEffectiveDeltasOnly("focus secondary delta", userSecondaryDelta);
Collection<? extends ModelProjectionContext> projectionContexts = modelContext.getProjectionContexts();
assertNotNull("Null model projection context list", projectionContexts);
assertEquals("Unexpected number of projection contexts", 3, projectionContexts.size());
ModelProjectionContext accContext = modelContext.findProjectionContext(new ResourceShadowDiscriminator(RESOURCE_DUMMY_BLUE_OID, ShadowKindType.ACCOUNT, null));
assertNotNull("Null model projection context", accContext);
assertEquals("Wrong policy decision", SynchronizationPolicyDecision.KEEP, accContext.getSynchronizationPolicyDecision());
ObjectDelta<ShadowType> accountPrimaryDelta = accContext.getPrimaryDelta();
assertNotNull("No account primary delta", accountPrimaryDelta);
PrismAsserts.assertModifications(accountPrimaryDelta, 1);
PrismAsserts.assertPropertyReplace(accountPrimaryDelta, getAttributePath(resourceDummyBlue, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME), "Elaine Threepwood");
ObjectDelta<ShadowType> accountSecondaryDelta = accContext.getSecondaryDelta();
assertNull("Unexpected account secondary delta: " + accountSecondaryDelta, accountSecondaryDelta);
}
use of com.evolveum.midpoint.model.api.context.ModelProjectionContext in project midpoint by Evolveum.
the class TestPreviewChanges method test620AddUserCapsize.
@Test
public void test620AddUserCapsize() throws Exception {
final String TEST_NAME = "test620AddUserCapsize";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestPreviewChanges.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.NONE);
PrismObject<UserType> user = PrismTestUtil.parseObject(USER_CAPSIZE_FILE);
ObjectDelta<UserType> userDelta = ObjectDelta.createAddDelta(user);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta);
// WHEN
ModelContext<UserType> modelContext = modelInteractionService.previewChanges(deltas, new ModelExecuteOptions(), task, result);
// THEN
display("Preview context", modelContext);
assertNotNull("Null model context", modelContext);
result.computeStatus();
TestUtil.assertSuccess(result);
ModelElementContext<UserType> focusContext = modelContext.getFocusContext();
assertNotNull("Null model focus context", focusContext);
ObjectDelta<UserType> userPrimaryDelta = focusContext.getPrimaryDelta();
assertNotNull("No focus primary delta: " + userPrimaryDelta, userPrimaryDelta);
PrismAsserts.assertIsAdd(userPrimaryDelta);
ObjectDelta<UserType> userSecondaryDelta = focusContext.getSecondaryDelta();
assertSideEffectiveDeltasOnly(userSecondaryDelta, "focus secondary delta", ActivationStatusType.ENABLED);
Collection<? extends ModelProjectionContext> projectionContexts = modelContext.getProjectionContexts();
assertNotNull("Null model projection context list", projectionContexts);
assertEquals("Unexpected number of projection contexts", 3, projectionContexts.size());
// DEFAULT dummy resource: normal mappings
ModelProjectionContext accContext = modelContext.findProjectionContext(new ResourceShadowDiscriminator(RESOURCE_DUMMY_OID, ShadowKindType.ACCOUNT, null));
assertNotNull("Null model projection context (default)", accContext);
assertEquals("Wrong policy decision (default)", SynchronizationPolicyDecision.ADD, accContext.getSynchronizationPolicyDecision());
ObjectDelta<ShadowType> accountPrimaryDelta = accContext.getPrimaryDelta();
assertNotNull("No account primary delta (default)", accountPrimaryDelta);
PrismAsserts.assertIsAdd(accountPrimaryDelta);
ObjectDelta<ShadowType> accountSecondaryDelta = accContext.getSecondaryDelta();
assertNotNull("No account secondary delta (default)", accountSecondaryDelta);
PrismAsserts.assertModifications(accountSecondaryDelta, 9);
PrismAsserts.assertNoItemDelta(accountSecondaryDelta, getAttributePath(getDummyResourceObject(), DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME));
// RED dummy resource: strong mappings
accContext = modelContext.findProjectionContext(new ResourceShadowDiscriminator(RESOURCE_DUMMY_RED_OID, ShadowKindType.ACCOUNT, null));
assertNotNull("Null model projection context (red)", accContext);
assertEquals("Wrong policy decision", SynchronizationPolicyDecision.ADD, accContext.getSynchronizationPolicyDecision());
accountPrimaryDelta = accContext.getPrimaryDelta();
assertNotNull("No account primary delta (default)", accountPrimaryDelta);
PrismAsserts.assertIsAdd(accountPrimaryDelta);
accountSecondaryDelta = accContext.getSecondaryDelta();
assertNotNull("No account secondary delta (red)", accountSecondaryDelta);
PrismAsserts.assertModifications(accountSecondaryDelta, 9);
PrismAsserts.assertPropertyReplace(accountSecondaryDelta, getAttributePath(getDummyResourceObject(RESOURCE_DUMMY_RED_NAME), DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME), "Kate Capsize");
// BLUE dummy resource: weak mappings
accContext = modelContext.findProjectionContext(new ResourceShadowDiscriminator(RESOURCE_DUMMY_BLUE_OID, ShadowKindType.ACCOUNT, null));
assertNotNull("Null model projection context (blue)", accContext);
assertEquals("Wrong policy decision", SynchronizationPolicyDecision.ADD, accContext.getSynchronizationPolicyDecision());
accountPrimaryDelta = accContext.getPrimaryDelta();
assertNotNull("No account primary delta (default)", accountPrimaryDelta);
PrismAsserts.assertIsAdd(accountPrimaryDelta);
accountSecondaryDelta = accContext.getSecondaryDelta();
assertNotNull("No account secondary delta (default)", accountSecondaryDelta);
PrismAsserts.assertModifications(accountSecondaryDelta, 10);
PrismAsserts.assertNoItemDelta(accountSecondaryDelta, getAttributePath(resourceDummyBlue, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME));
assertPasswordDelta(accountSecondaryDelta);
}
Aggregations