Search in sources :

Example 11 with ModelProjectionContext

use of com.evolveum.midpoint.model.api.context.ModelProjectionContext in project midpoint by Evolveum.

the class TestPreviewChanges method test200ModifyUserGuybrushDeleteAccount.

@Test
public void test200ModifyUserGuybrushDeleteAccount() throws Exception {
    final String TEST_NAME = "test200ModifyUserGuybrushDeleteAccount";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestPreviewChanges.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    assumeAssignmentPolicy(AssignmentPolicyEnforcementType.NONE);
    PrismObject<ShadowType> account = PrismTestUtil.parseObject(ACCOUNT_GUYBRUSH_DUMMY_FILE);
    ObjectDelta<UserType> userDelta = ObjectDelta.createEmptyModifyDelta(UserType.class, USER_GUYBRUSH_OID, prismContext);
    PrismReferenceValue accountRefVal = new PrismReferenceValue();
    accountRefVal.setObject(account);
    ReferenceDelta accountDelta = ReferenceDelta.createModificationDelete(UserType.F_LINK_REF, getUserDefinition(), account);
    userDelta.addModification(accountDelta);
    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);
    assertNull("Unexpected focus primary delta: " + focusContext.getPrimaryDelta(), focusContext.getPrimaryDelta());
    assertSideEffectiveDeltasOnly("focus secondary delta", focusContext.getSecondaryDelta());
    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.DELETE, accContext.getSynchronizationPolicyDecision());
    ObjectDelta<ShadowType> accountPrimaryDelta = accContext.getPrimaryDelta();
    assertEquals(ChangeType.DELETE, accountPrimaryDelta.getChangeType());
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ReferenceDelta(com.evolveum.midpoint.prism.delta.ReferenceDelta) 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) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) 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 12 with ModelProjectionContext

use of com.evolveum.midpoint.model.api.context.ModelProjectionContext 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)

Example 13 with ModelProjectionContext

use of com.evolveum.midpoint.model.api.context.ModelProjectionContext in project midpoint by Evolveum.

the class TestVisualizer method fillDeltas.

protected void fillDeltas(ModelContext<UserType> modelContext, List<ObjectDelta<? extends ObjectType>> primaryDeltas, List<ObjectDelta<? extends ObjectType>> secondaryDeltas) throws SchemaException {
    if (modelContext != null) {
        if (modelContext.getFocusContext() != null) {
            addIgnoreNull(primaryDeltas, modelContext.getFocusContext().getPrimaryDelta());
            addIgnoreNull(secondaryDeltas, modelContext.getFocusContext().getSecondaryDelta());
        }
        for (ModelProjectionContext projCtx : modelContext.getProjectionContexts()) {
            addIgnoreNull(primaryDeltas, projCtx.getPrimaryDelta());
            addIgnoreNull(secondaryDeltas, projCtx.getExecutableDelta());
        }
    }
    display("primary deltas", primaryDeltas);
    display("secondary deltas", secondaryDeltas);
}
Also used : ModelProjectionContext(com.evolveum.midpoint.model.api.context.ModelProjectionContext)

Example 14 with ModelProjectionContext

use of com.evolveum.midpoint.model.api.context.ModelProjectionContext in project midpoint by Evolveum.

the class ModelEvent method getAllExecutedDeltas.

public List<ObjectDeltaOperation> getAllExecutedDeltas() {
    List<ObjectDeltaOperation> retval = new ArrayList<ObjectDeltaOperation>();
    retval.addAll(getFocusContext().getExecutedDeltas());
    for (Object o : modelContext.getProjectionContexts()) {
        ModelProjectionContext modelProjectionContext = (ModelProjectionContext) o;
        retval.addAll(modelProjectionContext.getExecutedDeltas());
    }
    return retval;
}
Also used : ObjectDeltaOperation(com.evolveum.midpoint.schema.ObjectDeltaOperation) ArrayList(java.util.ArrayList) ModelProjectionContext(com.evolveum.midpoint.model.api.context.ModelProjectionContext)

Example 15 with ModelProjectionContext

use of com.evolveum.midpoint.model.api.context.ModelProjectionContext in project midpoint by Evolveum.

the class AbstractModelIntegrationTest method assertResolvedResourceRefs.

protected <F extends ObjectType> void assertResolvedResourceRefs(ModelContext<F> context) {
    for (ModelProjectionContext projectionContext : context.getProjectionContexts()) {
        assertResolvedResourceRefs(projectionContext.getObjectOld(), "objectOld in " + projectionContext);
        assertResolvedResourceRefs(projectionContext.getObjectNew(), "objectNew in " + projectionContext);
        assertResolvedResourceRefs(projectionContext.getPrimaryDelta(), "primaryDelta in " + projectionContext);
        assertResolvedResourceRefs(projectionContext.getSecondaryDelta(), "secondaryDelta in " + projectionContext);
    }
}
Also used : ModelProjectionContext(com.evolveum.midpoint.model.api.context.ModelProjectionContext)

Aggregations

ModelProjectionContext (com.evolveum.midpoint.model.api.context.ModelProjectionContext)26 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)21 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)20 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)19 Task (com.evolveum.midpoint.task.api.Task)18 Test (org.testng.annotations.Test)18 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)15 ModelExecuteOptions (com.evolveum.midpoint.model.api.ModelExecuteOptions)13 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)12 ResourceShadowDiscriminator (com.evolveum.midpoint.schema.ResourceShadowDiscriminator)11 LensContext (com.evolveum.midpoint.model.impl.lens.LensContext)3 PrismReference (com.evolveum.midpoint.prism.PrismReference)2 ReferenceDelta (com.evolveum.midpoint.prism.delta.ReferenceDelta)2 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)2 ObjectDeltaOperation (com.evolveum.midpoint.schema.ObjectDeltaOperation)2 ArrayList (java.util.ArrayList)2 LensFocusContext (com.evolveum.midpoint.model.impl.lens.LensFocusContext)1 LensProjectionContext (com.evolveum.midpoint.model.impl.lens.LensProjectionContext)1 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)1 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)1