use of com.evolveum.midpoint.model.api.context.ModelProjectionContext in project midpoint by Evolveum.
the class TestPreviewChanges method test234PreviewGuybrushAddRolePirateRecon.
/**
* MID-3079
*/
@Test
public void test234PreviewGuybrushAddRolePirateRecon() throws Exception {
final String TEST_NAME = "test234PreviewGuybrushAddRolePirateRecon";
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_OID, RoleType.COMPLEX_TYPE, null, null, null, true);
ModelExecuteOptions options = ModelExecuteOptions.createReconcile();
// WHEN
TestUtil.displayWhen(TEST_NAME);
ModelContext<UserType> modelContext = modelInteractionService.previewChanges(MiscSchemaUtil.createCollection(delta), options, 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());
assertAccountDefaultDummyAttributeModify(accountSecondaryDelta, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_TITLE_NAME, // old
new String[] { "Great Pirate" }, // add
new String[] { ROLE_PIRATE_TITLE }, // delete
null, // replace
null);
assertAccountDefaultDummyAttributeModify(accountSecondaryDelta, DUMMY_ACCOUNT_ATTRIBUTE_SEA_NAME, // old
null, // add
null, // delete
null, // replace
new String[] { "guybrush sailed The Seven Seas, immediately , role , with this The Seven Seas while focused on (in Pirate)" });
assertAccountDefaultDummyAttributeModify(accountSecondaryDelta, 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 test220PreviewJackAssignRolePirate.
/**
* MID-3079
*/
@Test
public void test220PreviewJackAssignRolePirate() throws Exception {
final String TEST_NAME = "test220PreviewJackAssignRolePirate";
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_JACK_OID, ROLE_PIRATE_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());
assertAccountItemModify(accountSecondaryDelta, SchemaConstants.PATH_ACTIVATION_ADMINISTRATIVE_STATUS, // old
null, // add
null, // delete
null, // replace
new ActivationStatusType[] { ActivationStatusType.ENABLED });
assertAccountDefaultDummyAttributeModify(accountSecondaryDelta, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME, // old
null, // add
new String[] { ROLE_PIRATE_WEAPON }, // delete
null, // replace
null);
assertAccountDefaultDummyAttributeModify(accountSecondaryDelta, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_TITLE_NAME, // old
null, // add
new String[] { ROLE_PIRATE_TITLE }, // delete
null, // replace
null);
assertAccountDefaultDummyAttributeModify(accountSecondaryDelta, DUMMY_ACCOUNT_ATTRIBUTE_SEA_NAME, // old
null, // add
null, // delete
null, // replace
new String[] { "jack sailed The Seven Seas, immediately , role , with this The Seven Seas while focused on (in Pirate)" });
assertAccountDefaultDummyAttributeModify(accountSecondaryDelta, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_GOSSIP_NAME, // old
null, // add
new String[] { "Jack Sparrow is the best pirate Caribbean has ever seen" }, // delete
null, // replace
null);
assertAccountDefaultDummyAttributeModify(accountSecondaryDelta, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_QUOTE_NAME, // old
null, // add
new String[] { RESOURCE_DUMMY_QUOTE }, // delete
null, // replace
null);
assertAccountDefaultDummyAttributeModify(accountSecondaryDelta, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_DRINK_NAME, // old
null, // add
new String[] { RESOURCE_DUMMY_DRINK }, // delete
null, // replace
null);
PrismAsserts.assertModifications(accountSecondaryDelta, 15);
}
use of com.evolveum.midpoint.model.api.context.ModelProjectionContext in project midpoint by Evolveum.
the class TestPreviewChanges method test501ModifyElaineAccountDummyBlueDeleteAdd.
/**
* Changing ACCOUNT fullname (add/delete delta), no user changes.
*/
@Test
public void test501ModifyElaineAccountDummyBlueDeleteAdd() throws Exception {
final String TEST_NAME = "test501ModifyElaineAccountDummyBlueDeleteAdd";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestPreviewChanges.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.NONE);
display("elaine blue account before", getDummyAccount(RESOURCE_DUMMY_BLUE_NAME, ACCOUNT_ELAINE_DUMMY_BLUE_USERNAME));
ObjectDelta<ShadowType> accountDelta = createModifyAccountShadowEmptyDelta(ACCOUNT_SHADOW_ELAINE_DUMMY_BLUE_OID);
PropertyDelta<String> fullnameDelta = createAttributeAddDelta(resourceDummyBlue, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME, "Elaine Threepwood");
fullnameDelta.addValueToDelete(new PrismPropertyValue<String>("Elaine Marley"));
accountDelta.addModification(fullnameDelta);
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.assertPropertyAdd(accountPrimaryDelta, getAttributePath(resourceDummyBlue, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME), "Elaine Threepwood");
PrismAsserts.assertPropertyDelete(accountPrimaryDelta, getAttributePath(resourceDummyBlue, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME), "Elaine Marley");
ObjectDelta<ShadowType> accountSecondaryDelta = accContext.getSecondaryDelta();
assertNotNull("Missing account secondary delta", accountSecondaryDelta);
// these are originally empty attributes with weak mappings
assertEquals("Wrong items in account secondary delta", new HashSet<>(Arrays.asList(dummyResourceCtlBlue.getAttributePath(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_DRINK_NAME), dummyResourceCtlBlue.getAttributePath(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_GOSSIP_NAME), dummyResourceCtlBlue.getAttributePath(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_QUOTE_NAME))), new HashSet<>(accountSecondaryDelta.getModifiedItems()));
}
use of com.evolveum.midpoint.model.api.context.ModelProjectionContext in project midpoint by Evolveum.
the class TestPreviewChanges method test244PreviewGuybrushAddRolePirateRelativeRecon.
/**
* MID-3079
*/
@Test
public void test244PreviewGuybrushAddRolePirateRelativeRecon() throws Exception {
final String TEST_NAME = "test244PreviewGuybrushAddRolePirateRelativeRecon";
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), ModelExecuteOptions.createReconcile(), 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
new String[] { "tongue" }, // add
new String[] { ROLE_PIRATE_WEAPON }, // delete
null, // replace
null);
assertAccountDummyAttributeModify(accountSecondaryDelta, RESOURCE_DUMMY_RELATIVE_NAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_TITLE_NAME, // old
new String[] { "Great Pirate" }, // 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 test610ModifyElaineUserAccountDummyReplace.
/**
* Changing USER fullName (replace delta), change account fullname (replace delta).
*/
@Test
public void test610ModifyElaineUserAccountDummyReplace() throws Exception {
final String TEST_NAME = "test610ModifyElaineUserAccountDummyReplace";
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"));
ObjectDelta<ShadowType> accountDelta = createModifyAccountShadowReplaceAttributeDelta(ACCOUNT_SHADOW_ELAINE_DUMMY_OID, getDummyResourceObject(), DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME, "Elaine LeChuck");
// Cannot change the attribute on RED resource. It would conflict with the strong mapping and therefore fail.
// ObjectDelta<ResourceObjectShadowType> accountDeltaRed = createModifyAccountShadowReplaceAttributeDelta(
// ACCOUNT_SHADOW_ELAINE_DUMMY_RED_OID, resourceDummyRed,
// DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME, "Elaine LeChuck");
ObjectDelta<ShadowType> accountDeltaBlue = createModifyAccountShadowReplaceAttributeDelta(ACCOUNT_SHADOW_ELAINE_DUMMY_BLUE_OID, resourceDummyBlue, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME, "Elaine LeChuck");
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta, accountDelta, accountDeltaBlue);
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();
assertNotNull("No account primary delta (default)", accountPrimaryDelta);
PrismAsserts.assertModifications(accountPrimaryDelta, 1);
PrismAsserts.assertPropertyReplace(accountPrimaryDelta, getAttributePath(getDummyResourceObject(), DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME), "Elaine LeChuck");
ObjectDelta<ShadowType> accountSecondaryDelta = accContext.getSecondaryDelta();
assertEquals("Unexpected size of account secondary delta (default): " + accountSecondaryDelta, 2, accountSecondaryDelta.getModifications().size());
PrismAsserts.assertPropertyAdd(accountSecondaryDelta, dummyResourceCtl.getAttributePath(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_DRINK_NAME), "rum");
PrismAsserts.assertPropertyAdd(accountSecondaryDelta, dummyResourceCtl.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();
assertNotNull("No account primary delta (blue)", accountPrimaryDelta);
PrismAsserts.assertModifications(accountPrimaryDelta, 1);
PrismAsserts.assertPropertyReplace(accountPrimaryDelta, getAttributePath(resourceDummyBlue, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME), "Elaine LeChuck");
accountSecondaryDelta = accContext.getSecondaryDelta();
PrismAsserts.assertModifications("account secondary delta (blue)", accountSecondaryDelta, 3);
}
Aggregations