Search in sources :

Example 31 with ResourceShadowDiscriminator

use of com.evolveum.midpoint.schema.ResourceShadowDiscriminator in project midpoint by Evolveum.

the class TestProjector method test010BasicContextOperations.

@Test
public void test010BasicContextOperations() throws Exception {
    final String TEST_NAME = "test010BasicContextOperations";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestProjector.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    assumeAssignmentPolicy(AssignmentPolicyEnforcementType.NONE);
    LensContext<UserType> context = createUserLensContext();
    LensFocusContext<UserType> focusContext = fillContextWithUser(context, USER_ELAINE_OID, result);
    LensProjectionContext accountContext = fillContextWithAccount(context, ACCOUNT_SHADOW_ELAINE_DUMMY_OID, task, result);
    // User deltas
    ObjectDelta<UserType> userDeltaPrimary = createModifyUserReplaceDelta(USER_ELAINE_OID, UserType.F_FULL_NAME, PrismTestUtil.createPolyString("Elaine Threepwood"));
    ObjectDelta<UserType> userDeltaPrimaryClone = userDeltaPrimary.clone();
    ObjectDelta<UserType> userDeltaSecondary = createModifyUserReplaceDelta(USER_ELAINE_OID, UserType.F_FULL_NAME, PrismTestUtil.createPolyString("Elaine LeChuck"));
    ObjectDelta<UserType> userDeltaSecondaryClone = userDeltaSecondary.clone();
    focusContext.setPrimaryDelta(userDeltaPrimary);
    focusContext.setSecondaryDelta(userDeltaSecondary, 0);
    // Account Deltas
    ObjectDelta<ShadowType> accountDeltaPrimary = createModifyAccountShadowReplaceAttributeDelta(ACCOUNT_SHADOW_ELAINE_DUMMY_OID, getDummyResourceObject(), DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME, "Elie Marley");
    ObjectDelta<ShadowType> accountDeltaPrimaryClone = accountDeltaPrimary.clone();
    assert accountDeltaPrimaryClone != accountDeltaPrimary : "clone is not cloning";
    assert accountDeltaPrimaryClone.getModifications() != accountDeltaPrimary.getModifications() : "clone is not cloning (modifications)";
    ObjectDelta<ShadowType> accountDeltaSecondary = createModifyAccountShadowReplaceAttributeDelta(ACCOUNT_SHADOW_ELAINE_DUMMY_OID, getDummyResourceObject(), DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME, "Elie LeChuck");
    ObjectDelta<ShadowType> accountDeltaSecondaryClone = accountDeltaSecondary.clone();
    accountContext.setPrimaryDelta(accountDeltaPrimary);
    accountContext.setSecondaryDelta(accountDeltaSecondary);
    display("Context before", context);
    // WHEN: checkConsistence
    context.checkConsistence();
    display("Context after checkConsistence", context);
    assert focusContext == context.getFocusContext() : "focus context delta replaced";
    assert focusContext.getPrimaryDelta() == userDeltaPrimary : "focus primary delta replaced";
    assert userDeltaPrimaryClone.equals(userDeltaPrimary) : "focus primary delta changed";
    ObjectDelta<UserType> focusSecondaryDelta = focusContext.getSecondaryDelta();
    display("Focus secondary delta", focusSecondaryDelta);
    display("Orig user secondary delta", userDeltaSecondaryClone);
    assert focusSecondaryDelta.equals(userDeltaSecondaryClone) : "focus secondary delta not equal";
    assert accountContext == context.findProjectionContext(new ResourceShadowDiscriminator(RESOURCE_DUMMY_OID, ShadowKindType.ACCOUNT, null)) : "wrong account context";
    assert accountContext.getPrimaryDelta() == accountDeltaPrimary : "account primary delta replaced";
    assert accountDeltaPrimaryClone.equals(accountDeltaPrimary) : "account primary delta changed";
    assert accountContext.getSecondaryDelta() == accountDeltaSecondary : "account secondary delta replaced";
    assert accountDeltaSecondaryClone.equals(accountDeltaSecondary) : "account secondary delta changed";
    // WHEN: recompute
    context.recompute();
    display("Context after recompute", context);
    assert focusContext == context.getFocusContext() : "focus context delta replaced";
    assert focusContext.getPrimaryDelta() == userDeltaPrimary : "focus primary delta replaced";
    focusSecondaryDelta = focusContext.getSecondaryDelta();
    display("Focus secondary delta", focusSecondaryDelta);
    display("Orig user secondary delta", userDeltaSecondaryClone);
    assert focusSecondaryDelta.equals(userDeltaSecondaryClone) : "focus secondary delta not equal";
    assert accountContext == context.findProjectionContext(new ResourceShadowDiscriminator(RESOURCE_DUMMY_OID, ShadowKindType.ACCOUNT, null)) : "wrong account context";
    assert accountContext.getPrimaryDelta() == accountDeltaPrimary : "account primary delta replaced";
    display("Orig account primary delta", accountDeltaPrimaryClone);
    display("Account primary delta after recompute", accountDeltaPrimary);
    assert accountDeltaPrimaryClone.equals(accountDeltaPrimary) : "account primary delta changed";
    assert accountContext.getSecondaryDelta() == accountDeltaSecondary : "account secondary delta replaced";
    assert accountDeltaSecondaryClone.equals(accountDeltaSecondary) : "account secondary delta changed";
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test)

Example 32 with ResourceShadowDiscriminator

use of com.evolveum.midpoint.schema.ResourceShadowDiscriminator 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");
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ModelExecuteOptions(com.evolveum.midpoint.model.api.ModelExecuteOptions) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator) ModelProjectionContext(com.evolveum.midpoint.model.api.context.ModelProjectionContext) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test)

Example 33 with ResourceShadowDiscriminator

use of com.evolveum.midpoint.schema.ResourceShadowDiscriminator 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);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ModelExecuteOptions(com.evolveum.midpoint.model.api.ModelExecuteOptions) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator) ModelProjectionContext(com.evolveum.midpoint.model.api.context.ModelProjectionContext) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test)

Example 34 with ResourceShadowDiscriminator

use of com.evolveum.midpoint.schema.ResourceShadowDiscriminator 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);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ModelExecuteOptions(com.evolveum.midpoint.model.api.ModelExecuteOptions) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator) ModelProjectionContext(com.evolveum.midpoint.model.api.context.ModelProjectionContext) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test)

Example 35 with ResourceShadowDiscriminator

use of com.evolveum.midpoint.schema.ResourceShadowDiscriminator in project midpoint by Evolveum.

the class TestPreviewChanges method test630AddUserRogers.

// testing multiple resources with dependencies (dummy -> dummy lemon)
@Test
public void test630AddUserRogers() throws Exception {
    final String TEST_NAME = "test630AddUserRogers";
    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_ROGERS_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();
    // inbound from ship (explicitly specified) to organizationalUnit (dummy resource)
    // inbound from gossip (computed via outbound) to description (lemon resource)
    assertEffectualDeltas(userSecondaryDelta, "focus secondary delta", ActivationStatusType.ENABLED, 2);
    PrismObject<UserType> finalUser = user.clone();
    userSecondaryDelta.applyTo(finalUser);
    PrismAsserts.assertOrigEqualsPolyStringCollectionUnordered("Wrong organizationalUnit attribute", finalUser.asObjectable().getOrganizationalUnit(), "The crew of The Sea Monkey");
    assertEquals("Wrong description attribute", "Rum Rogers Sr. must be the best pirate the  has ever seen", finalUser.asObjectable().getDescription());
    Collection<? extends ModelProjectionContext> projectionContexts = modelContext.getProjectionContexts();
    assertNotNull("Null model projection context list", projectionContexts);
    assertEquals("Unexpected number of projection contexts", 2, 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);
    // administrativeStatus (ENABLED), enableTimestamp, name, drink, quote, iteration, iterationToken, password/value
    PrismAsserts.assertModifications(accountSecondaryDelta, 9);
    PrismAsserts.assertNoItemDelta(accountSecondaryDelta, getAttributePath(getDummyResourceObject(), DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME));
    // LEMON dummy resource
    accContext = modelContext.findProjectionContext(new ResourceShadowDiscriminator(RESOURCE_DUMMY_LEMON_OID, ShadowKindType.ACCOUNT, null));
    assertNotNull("Null model projection context (lemon)", 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 (lemon)", accountSecondaryDelta);
    // administrativeStatus (ENABLED), enableTimestamp, ship (from organizationalUnit), name, gossip, water, iteration, iterationToken, password/value
    PrismAsserts.assertModifications(accountSecondaryDelta, 10);
    PrismAsserts.assertPropertyReplace(accountSecondaryDelta, getAttributePath(getDummyResourceObject(RESOURCE_DUMMY_LEMON_NAME), DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_SHIP_NAME), "The crew of The Sea Monkey");
    PrismAsserts.assertPropertyReplace(accountSecondaryDelta, new ItemPath(ShadowType.F_ATTRIBUTES, SchemaConstants.ICFS_NAME), "rogers");
    PrismAsserts.assertPropertyAdd(accountSecondaryDelta, getAttributePath(getDummyResourceObject(RESOURCE_DUMMY_LEMON_NAME), DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_GOSSIP_NAME), "Rum Rogers Sr. must be the best pirate the  has ever seen");
    PrismAsserts.assertPropertyReplace(accountSecondaryDelta, getAttributePath(getDummyResourceObject(RESOURCE_DUMMY_LEMON_NAME), DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WATER_NAME), "pirate Rum Rogers Sr. drinks only rum!");
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ModelExecuteOptions(com.evolveum.midpoint.model.api.ModelExecuteOptions) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator) ModelProjectionContext(com.evolveum.midpoint.model.api.context.ModelProjectionContext) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Aggregations

ResourceShadowDiscriminator (com.evolveum.midpoint.schema.ResourceShadowDiscriminator)78 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)41 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)34 Task (com.evolveum.midpoint.task.api.Task)30 Test (org.testng.annotations.Test)30 LensProjectionContext (com.evolveum.midpoint.model.impl.lens.LensProjectionContext)28 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)18 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)17 ResourceObjectShadowChangeDescription (com.evolveum.midpoint.provisioning.api.ResourceObjectShadowChangeDescription)17 ModelProjectionContext (com.evolveum.midpoint.model.api.context.ModelProjectionContext)11 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)10 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)10 DummyAccount (com.evolveum.icf.dummy.resource.DummyAccount)9 ModelExecuteOptions (com.evolveum.midpoint.model.api.ModelExecuteOptions)9 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)9 AbstractInternalModelIntegrationTest (com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)8 MockLensDebugListener (com.evolveum.midpoint.model.impl.util.mock.MockLensDebugListener)8 PrismObject (com.evolveum.midpoint.prism.PrismObject)8 QName (javax.xml.namespace.QName)7 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)6