Search in sources :

Example 1 with EvaluatedAssignedResourceObjectConstructionImpl

use of com.evolveum.midpoint.model.impl.lens.construction.EvaluatedAssignedResourceObjectConstructionImpl in project midpoint by Evolveum.

the class AbstractAssignmentEvaluatorTest method test120DirectExpressionReplaceDescription.

@Test
public void test120DirectExpressionReplaceDescription() throws Exception {
    // GIVEN
    Task task = getTestTask();
    OperationResult result = task.getResult();
    PrismObject<UserType> user = userTypeJack.asPrismObject().clone();
    AssignmentType assignmentType = unmarshalValueFromFile(ASSIGNMENT_DIRECT_EXPRESSION_FILE);
    user.asObjectable().getAssignment().add(assignmentType.clone());
    ItemPath path = ItemPath.create(UserType.F_ASSIGNMENT, 123L, AssignmentType.F_DESCRIPTION);
    ObjectDelta<UserType> userDelta = prismContext.deltaFactory().object().createModificationReplaceProperty(UserType.class, USER_JACK_OID, path, "captain");
    ObjectDeltaObject<UserType> userOdo = createUserOdo(user, userDelta);
    AssignmentEvaluator<UserType> assignmentEvaluator = createAssignmentEvaluator(userOdo);
    display("Assignment old", assignmentType);
    ItemDeltaItem<PrismContainerValue<AssignmentType>, PrismContainerDefinition<AssignmentType>> assignmentIdi = createAssignmentIdi(assignmentType);
    assignmentIdi.setResolvePath(UserType.F_ASSIGNMENT);
    assignmentIdi.setSubItemDeltas(userDelta.getModifications());
    assignmentIdi.recompute();
    displayDumpable("Assignment IDI", assignmentIdi);
    // WHEN
    when();
    EvaluatedAssignmentImpl<UserType> evaluatedAssignment = assignmentEvaluator.evaluate(assignmentIdi, PlusMinusZero.ZERO, false, userTypeJack, "testDirect", AssignmentOrigin.createInObject(), task, result);
    evaluateConstructions(evaluatedAssignment, userOdo, task, result);
    // THEN
    then();
    assertSuccess(result);
    assertNotNull(evaluatedAssignment);
    displayDumpable("Evaluated assignment", evaluatedAssignment);
    assertEquals(1, evaluatedAssignment.getConstructionTriple().size());
    PrismAsserts.assertParentConsistency(user);
    ResourceObjectConstruction<UserType, EvaluatedAssignedResourceObjectConstructionImpl<UserType>> construction = evaluatedAssignment.getConstructionTriple().getZeroSet().iterator().next();
    assertNotNull("No object class definition in construction", construction.getResourceObjectDefinition());
    DeltaSetTriple<EvaluatedAssignedResourceObjectConstructionImpl<UserType>> evaluatedConstructionTriple = construction.getEvaluatedConstructionTriple();
    assertEquals(1, evaluatedConstructionTriple.size());
    EvaluatedAssignedResourceObjectConstructionImpl<UserType> evaluatedConstruction = evaluatedConstructionTriple.getZeroSet().iterator().next();
    assertEquals(1, evaluatedConstruction.getAttributeMappings().size());
    MappingImpl<PrismPropertyValue<String>, PrismPropertyDefinition<String>> attributeMapping = (MappingImpl<PrismPropertyValue<String>, PrismPropertyDefinition<String>>) evaluatedConstruction.getAttributeMappings().iterator().next();
    PrismValueDeltaSetTriple<PrismPropertyValue<String>> outputTriple = attributeMapping.getOutputTriple();
    displayDumpable("output triple", outputTriple);
    PrismAsserts.assertTripleNoZero(outputTriple);
    PrismAsserts.assertTriplePlus(outputTriple, "The best captain the world has ever seen");
    PrismAsserts.assertTripleMinus(outputTriple, "The best pirate the world has ever seen");
    // the same using other words
    assertConstruction(evaluatedAssignment, ZERO, "title", ZERO);
    assertConstruction(evaluatedAssignment, ZERO, "title", PLUS, "The best captain the world has ever seen");
    assertConstruction(evaluatedAssignment, ZERO, "title", MINUS, "The best pirate the world has ever seen");
    assertNoConstruction(evaluatedAssignment, PLUS, "title");
    assertNoConstruction(evaluatedAssignment, MINUS, "title");
    assertEquals("Wrong number of admin GUI configs", 0, evaluatedAssignment.getAdminGuiConfigurations().size());
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) MappingImpl(com.evolveum.midpoint.model.common.mapping.MappingImpl) EvaluatedAssignedResourceObjectConstructionImpl(com.evolveum.midpoint.model.impl.lens.construction.EvaluatedAssignedResourceObjectConstructionImpl) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 2 with EvaluatedAssignedResourceObjectConstructionImpl

use of com.evolveum.midpoint.model.impl.lens.construction.EvaluatedAssignedResourceObjectConstructionImpl in project midpoint by Evolveum.

the class AbstractAssignmentEvaluatorTest method test310DisableRoleEngineer.

@Test
public void test310DisableRoleEngineer() throws Exception {
    // GIVEN
    Task task = getTestTask();
    OperationResult result = task.getResult();
    // disable role Engineer
    ObjectDelta disableEngineerDelta = prismContext.deltaFor(RoleType.class).item(ACTIVATION_ADMINISTRATIVE_STATUS_PATH).replace(ActivationStatusType.DISABLED).asObjectDelta(ROLE_CORP_ENGINEER_OID);
    modelService.executeChanges(Collections.singletonList(disableEngineerDelta), null, task, result);
    AssignmentEvaluator<UserType> assignmentEvaluator = createAssignmentEvaluator();
    PrismAsserts.assertParentConsistency(userTypeJack.asPrismObject());
    AssignmentType assignmentType = getAssignmentType(ASSIGNMENT_ROLE_ENGINEER_FILE);
    ObjectDeltaObject<UserType> userOdo = createUserOdo(userTypeJack.asPrismObject());
    ItemDeltaItem<PrismContainerValue<AssignmentType>, PrismContainerDefinition<AssignmentType>> assignmentIdi = createAssignmentIdi(assignmentType);
    // WHEN
    when();
    EvaluatedAssignmentImpl<UserType> evaluatedAssignment = assignmentEvaluator.evaluate(assignmentIdi, PlusMinusZero.ZERO, false, userTypeJack, "testRoleEngineer", AssignmentOrigin.createInObject(), task, result);
    evaluateConstructions(evaluatedAssignment, userOdo, task, result);
    // THEN
    then();
    result.computeStatus();
    TestUtil.assertSuccess(result);
    assertNotNull(evaluatedAssignment);
    displayValue("Evaluated assignment", evaluatedAssignment.debugDump());
    assertEquals(2, evaluatedAssignment.getConstructionTriple().size());
    PrismAsserts.assertParentConsistency(userTypeJack.asPrismObject());
    for (ResourceObjectConstruction<UserType, EvaluatedAssignedResourceObjectConstructionImpl<UserType>> construction : evaluatedAssignment.getConstructionSet(ZERO)) {
        assertEquals("Wrong validity for " + construction, false, construction.isValid());
    }
    assertConstruction(evaluatedAssignment, ZERO, "title", ZERO, "Engineer");
    assertConstruction(evaluatedAssignment, ZERO, "title", PLUS);
    assertConstruction(evaluatedAssignment, ZERO, "title", MINUS);
    assertNoConstruction(evaluatedAssignment, PLUS, "title");
    assertNoConstruction(evaluatedAssignment, MINUS, "title");
    assertConstruction(evaluatedAssignment, ZERO, "location", ZERO, "Caribbean");
    assertConstruction(evaluatedAssignment, ZERO, "location", PLUS);
    assertConstruction(evaluatedAssignment, ZERO, "location", MINUS);
    assertNoConstruction(evaluatedAssignment, PLUS, "location");
    assertNoConstruction(evaluatedAssignment, MINUS, "location");
    assertEquals("Wrong number of admin GUI configs", 0, evaluatedAssignment.getAdminGuiConfigurations().size());
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) EvaluatedAssignedResourceObjectConstructionImpl(com.evolveum.midpoint.model.impl.lens.construction.EvaluatedAssignedResourceObjectConstructionImpl) Test(org.testng.annotations.Test)

Example 3 with EvaluatedAssignedResourceObjectConstructionImpl

use of com.evolveum.midpoint.model.impl.lens.construction.EvaluatedAssignedResourceObjectConstructionImpl in project midpoint by Evolveum.

the class TestAssignmentProcessor method test031DeleteAssignmentModifyAccount.

/**
 * Context: user barbossa (two assignments of dummy account) + dummy account projection
 *
 * Primary delta: delete assignment with "weapon: Undead Monkey" mapping
 */
@Test
public void test031DeleteAssignmentModifyAccount() throws Exception {
    given();
    Task task = getTestTask();
    OperationResult result = task.getResult();
    LensContext<UserType> context = createUserLensContext();
    fillContextWithUser(context, USER_BARBOSSA_OID, result);
    fillContextWithAccount(context, ACCOUNT_HBARBOSSA_DUMMY_OID, task, result);
    addFocusModificationToContext(context, REQ_USER_BARBOSSA_MODIFY_DELETE_ASSIGNMENT_ACCOUNT_DUMMY_ATTR);
    recompute(context);
    displayDumpable("Input context", context);
    PrismObject<UserType> userNew = context.getFocusContext().getObjectNew();
    assertEquals("Unexpected number of assignments in userNew after recompute", 1, userNew.asObjectable().getAssignment().size());
    assertFocusModificationSanity(context);
    when();
    processAssignments(task, result, context);
    then();
    displayValue("Output context", context.dump(true));
    display("result", result);
    assertSuccess(result);
    assertSame(context.getFocusContext().getPrimaryDelta().getChangeType(), ChangeType.MODIFY);
    assertNull("Unexpected user changes", context.getFocusContext().getSecondaryDelta());
    LensProjectionContext accContext = getSingleProjectionContext(context);
    assertNull(accContext.getPrimaryDelta());
    ObjectDelta<ShadowType> accountSecondaryDelta = accContext.getSecondaryDelta();
    assertNull("Account secondary delta sneaked in", accountSecondaryDelta);
    assertNoDecision(accContext);
    assertLegal(accContext);
    // assignmentProcessor.processAssignmentsAccountValues(accContext, result);
    DeltaSetTriple<EvaluatedAssignedResourceObjectConstructionImpl<UserType>> accountConstructionDeltaSetTriple = accContext.getEvaluatedAssignedConstructionDeltaSetTriple();
    PrismAsserts.assertTripleNoPlus(accountConstructionDeltaSetTriple);
    assertSetSize("zero", accountConstructionDeltaSetTriple.getZeroSet(), 1);
    EvaluatedAssignedResourceObjectConstructionImpl<UserType> zeroAccountConstruction = getZeroEvaluatedAccountConstruction(accountConstructionDeltaSetTriple);
    assertZeroAttributeValues(zeroAccountConstruction, getLocationAttributeName(), "Caribbean");
    assertNoPlusAttributeValues(zeroAccountConstruction, getLocationAttributeName());
    assertNoMinusAttributeValues(zeroAccountConstruction, getLocationAttributeName());
    assertZeroAttributeValues(zeroAccountConstruction, getShipAttributeName(), "Pirate Brethren, Inc.");
    assertNoPlusAttributeValues(zeroAccountConstruction, getShipAttributeName());
    assertNoMinusAttributeValues(zeroAccountConstruction, getShipAttributeName());
    assertSetSize("minus", accountConstructionDeltaSetTriple.getMinusSet(), 1);
    EvaluatedAssignedResourceObjectConstructionImpl<UserType> minusAccountConstruction = getMinusEvaluatedAccountConstruction(accountConstructionDeltaSetTriple);
    assertZeroAttributeValues(minusAccountConstruction, getWeaponAttributeName(), "Undead Monkey");
    assertNoPlusAttributeValues(minusAccountConstruction, getWeaponAttributeName());
    assertNoMinusAttributeValues(minusAccountConstruction, getWeaponAttributeName());
    assertSerializable(context);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) EvaluatedAssignedResourceObjectConstructionImpl(com.evolveum.midpoint.model.impl.lens.construction.EvaluatedAssignedResourceObjectConstructionImpl) Test(org.testng.annotations.Test)

Example 4 with EvaluatedAssignedResourceObjectConstructionImpl

use of com.evolveum.midpoint.model.impl.lens.construction.EvaluatedAssignedResourceObjectConstructionImpl in project midpoint by Evolveum.

the class TestAssignmentProcessor method test100AddAssignmentWithConditionalMetarole.

/**
 * Context: user jack (no assignments)
 *
 * Primary delta: add assignment to role engineer (has conditional metarole)
 *
 * MID-2190
 */
@Test
public void test100AddAssignmentWithConditionalMetarole() throws Exception {
    given();
    Task task = getTestTask();
    OperationResult result = task.getResult();
    LensContext<UserType> context = createUserLensContext();
    fillContextWithUser(context, USER_JACK_OID, result);
    addFocusModificationToContext(context, REQ_USER_JACK_MODIFY_ADD_ASSIGNMENT_ROLE_ENGINEER);
    recompute(context);
    displayDumpable("Input context", context);
    assertFocusModificationSanity(context);
    when();
    processAssignments(task, result, context);
    then();
    displayDumpable("Output context", context);
    display("outbound processor result", result);
    assertSuccess("Outbound processor failed (result)", result);
    assertSame(context.getFocusContext().getPrimaryDelta().getChangeType(), ChangeType.MODIFY);
    assertNull("Unexpected user changes", context.getFocusContext().getSecondaryDelta());
    LensProjectionContext accContext = getSingleProjectionContext(context);
    assertNull(accContext.getPrimaryDelta());
    ObjectDelta<ShadowType> accountSecondaryDelta = accContext.getSecondaryDelta();
    assertNull("Account secondary delta sneaked in", accountSecondaryDelta);
    assertNoDecision(accContext);
    assertLegal(accContext);
    // assignmentProcessor.processAssignmentsAccountValues(accContext, result);
    DeltaSetTriple<EvaluatedAssignedResourceObjectConstructionImpl<UserType>> constructionTriple = accContext.getEvaluatedAssignedConstructionDeltaSetTriple();
    PrismAsserts.assertTripleNoMinus(constructionTriple);
    PrismAsserts.assertTripleNoZero(constructionTriple);
    assertSetSize("plus", constructionTriple.getPlusSet(), 4);
    assertAttributeValues(constructionTriple.getPlusSet(), getTitleAttributeName(), ZERO, "Engineer", "Employee");
    assertAttributeValues(constructionTriple.getPlusSet(), getTitleAttributeName(), PLUS);
    assertAttributeValues(constructionTriple.getPlusSet(), getTitleAttributeName(), MINUS);
    assertAttributeValues(constructionTriple.getPlusSet(), getLocationAttributeName(), ZERO, "Caribbean");
    assertAttributeValues(constructionTriple.getPlusSet(), getLocationAttributeName(), PLUS);
    assertAttributeValues(constructionTriple.getPlusSet(), getLocationAttributeName(), MINUS);
    assertSerializable(context);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) EvaluatedAssignedResourceObjectConstructionImpl(com.evolveum.midpoint.model.impl.lens.construction.EvaluatedAssignedResourceObjectConstructionImpl) Test(org.testng.annotations.Test)

Example 5 with EvaluatedAssignedResourceObjectConstructionImpl

use of com.evolveum.midpoint.model.impl.lens.construction.EvaluatedAssignedResourceObjectConstructionImpl in project midpoint by Evolveum.

the class TestAssignmentProcessor method test102EnableConditionalMetarole.

/**
 * There is a conditional metarole that references 'costCenter' attribute.
 * Let us change the value of this attribute.
 */
@Test
public void test102EnableConditionalMetarole() throws Exception {
    given();
    Task task = getTestTask();
    OperationResult result = task.getResult();
    LensContext<UserType> context = createUserLensContext();
    PrismObject<UserType> user = getUser(USER_JACK_OID);
    AssignmentType assignmentType = getAssignmentType(ASSIGNMENT_ROLE_MANAGER_FILE);
    assignmentType.asPrismContainerValue().setParent(null);
    user.asObjectable().getAssignment().add(assignmentType);
    fillContextWithFocus(context, user);
    addFocusModificationToContext(context, REQ_USER_JACK_MODIFY_SET_COST_CENTER);
    recompute(context);
    displayDumpable("Input context", context);
    assertFocusModificationSanity(context);
    when();
    processAssignments(task, result, context);
    then();
    displayDumpable("Output context", context);
    display("outbound processor result", result);
    assertSuccess("Outbound processor failed (result)", result);
    assertSame(context.getFocusContext().getPrimaryDelta().getChangeType(), ChangeType.MODIFY);
    assertNull("Unexpected user changes", context.getFocusContext().getSecondaryDelta());
    LensProjectionContext accContext = getSingleProjectionContext(context);
    assertNull(accContext.getPrimaryDelta());
    ObjectDelta<ShadowType> accountSecondaryDelta = accContext.getSecondaryDelta();
    assertNull("Account secondary delta sneaked in", accountSecondaryDelta);
    assertNoDecision(accContext);
    assertLegal(accContext);
    // assignmentProcessor.processAssignmentsAccountValues(accContext, result);
    DeltaSetTriple<EvaluatedAssignedResourceObjectConstructionImpl<UserType>> accountConstructionDeltaSetTriple = accContext.getEvaluatedAssignedConstructionDeltaSetTriple();
    PrismAsserts.assertTripleNoMinus(accountConstructionDeltaSetTriple);
    assertSetSize("zero", accountConstructionDeltaSetTriple.getZeroSet(), 3);
    assertAttributeValues(accountConstructionDeltaSetTriple.getZeroSet(), getTitleAttributeName(), ZERO, "Employee");
    assertAttributeValues(accountConstructionDeltaSetTriple.getZeroSet(), getTitleAttributeName(), PLUS);
    assertAttributeValues(accountConstructionDeltaSetTriple.getZeroSet(), getTitleAttributeName(), MINUS);
    assertAttributeValues(accountConstructionDeltaSetTriple.getZeroSet(), getLocationAttributeName(), ZERO, "Caribbean");
    assertAttributeValues(accountConstructionDeltaSetTriple.getZeroSet(), getLocationAttributeName(), PLUS);
    assertAttributeValues(accountConstructionDeltaSetTriple.getZeroSet(), getLocationAttributeName(), MINUS);
    assertSetSize("plus", accountConstructionDeltaSetTriple.getPlusSet(), 1);
    assertAttributeValues(accountConstructionDeltaSetTriple.getPlusSet(), getTitleAttributeName(), ZERO, "Manager");
    assertAttributeValues(accountConstructionDeltaSetTriple.getPlusSet(), getTitleAttributeName(), PLUS);
    assertAttributeValues(accountConstructionDeltaSetTriple.getPlusSet(), getTitleAttributeName(), MINUS);
    assertAttributeValues(accountConstructionDeltaSetTriple.getPlusSet(), getLocationAttributeName(), ZERO);
    assertAttributeValues(accountConstructionDeltaSetTriple.getPlusSet(), getLocationAttributeName(), PLUS);
    assertAttributeValues(accountConstructionDeltaSetTriple.getPlusSet(), getLocationAttributeName(), MINUS);
    assertSerializable(context);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) EvaluatedAssignedResourceObjectConstructionImpl(com.evolveum.midpoint.model.impl.lens.construction.EvaluatedAssignedResourceObjectConstructionImpl) Test(org.testng.annotations.Test)

Aggregations

EvaluatedAssignedResourceObjectConstructionImpl (com.evolveum.midpoint.model.impl.lens.construction.EvaluatedAssignedResourceObjectConstructionImpl)12 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)12 Task (com.evolveum.midpoint.task.api.Task)11 Test (org.testng.annotations.Test)11 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)2 MappingImpl (com.evolveum.midpoint.model.common.mapping.MappingImpl)1 PrismValueDeltaSetTripleProducer (com.evolveum.midpoint.model.common.mapping.PrismValueDeltaSetTripleProducer)1 LensProjectionContext (com.evolveum.midpoint.model.impl.lens.LensProjectionContext)1 EvaluatedAssignmentImpl (com.evolveum.midpoint.model.impl.lens.assignments.EvaluatedAssignmentImpl)1 ComplexConstructionConsumer (com.evolveum.midpoint.model.impl.lens.projector.ComplexConstructionConsumer)1 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)1 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)1 ResourceShadowDiscriminator (com.evolveum.midpoint.schema.ResourceShadowDiscriminator)1