Search in sources :

Example 11 with ObjectDeltaObject

use of com.evolveum.midpoint.repo.common.expression.ObjectDeltaObject in project midpoint by Evolveum.

the class TestAbstractAssignmentEvaluator method test170RoleManagerChangeCostCenter.

/**
     * jack has assigned role Manager.
     *
     * However, condition in job metarole for Manager is such that it needs "management"
     * to be present in user/costCenter in order to be active.
     */
@Test
public void test170RoleManagerChangeCostCenter() throws Exception {
    final String TEST_NAME = "test170RoleManagerChangeCostCenter";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestAssignmentEvaluator.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    PrismObject<UserType> user = userTypeJack.asPrismObject().clone();
    AssignmentType assignmentType = getAssignmentType(ASSIGNMENT_ROLE_MANAGER_FILE);
    AssignmentType assignmentForUser = assignmentType.clone();
    assignmentForUser.asPrismContainerValue().setParent(null);
    user.asObjectable().getAssignment().add(assignmentForUser);
    ObjectDelta<UserType> userDelta = ObjectDelta.createModificationReplaceProperty(UserType.class, USER_JACK_OID, UserType.F_COST_CENTER, prismContext, "management");
    ObjectDeltaObject<UserType> userOdo = new ObjectDeltaObject<>(user, userDelta, null);
    userOdo.recompute();
    AssignmentEvaluator<UserType> assignmentEvaluator = createAssignmentEvaluator(userOdo);
    PrismAsserts.assertParentConsistency(userTypeJack.asPrismObject());
    ItemDeltaItem<PrismContainerValue<AssignmentType>, PrismContainerDefinition<AssignmentType>> assignmentIdi = new ItemDeltaItem<>();
    assignmentIdi.setItemOld(LensUtil.createAssignmentSingleValueContainerClone(assignmentType));
    assignmentIdi.recompute();
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    EvaluatedAssignmentImpl<UserType> evaluatedAssignment = assignmentEvaluator.evaluate(assignmentIdi, PlusMinusZero.ZERO, false, userTypeJack, TEST_NAME, task, result);
    evaluatedAssignment.evaluateConstructions(userOdo, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    assertNotNull(evaluatedAssignment);
    display("Evaluated assignment", evaluatedAssignment.debugDump());
    assertEquals(4, evaluatedAssignment.getConstructionTriple().size());
    PrismAsserts.assertParentConsistency(userTypeJack.asPrismObject());
    // because Employee's job metarole is active even if Manager's is not
    assertConstruction(evaluatedAssignment, ZERO, "title", ZERO, "Employee");
    assertConstruction(evaluatedAssignment, ZERO, "title", PLUS);
    assertConstruction(evaluatedAssignment, ZERO, "title", MINUS);
    // because Manager's job metarole is originally not active
    assertConstruction(evaluatedAssignment, PLUS, "title", ZERO, "Manager");
    assertConstruction(evaluatedAssignment, PLUS, "title", PLUS);
    assertConstruction(evaluatedAssignment, PLUS, "title", MINUS);
    assertNoConstruction(evaluatedAssignment, MINUS, "title");
    // because Generic Metarole is active all the time
    assertConstruction(evaluatedAssignment, ZERO, "location", ZERO, "Caribbean");
    assertConstruction(evaluatedAssignment, ZERO, "location", PLUS);
    assertConstruction(evaluatedAssignment, ZERO, "location", MINUS);
    assertNoConstruction(evaluatedAssignment, PLUS, "location");
    assertNoConstruction(evaluatedAssignment, MINUS, "location");
}
Also used : Task(com.evolveum.midpoint.task.api.Task) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectDeltaObject(com.evolveum.midpoint.repo.common.expression.ObjectDeltaObject) ItemDeltaItem(com.evolveum.midpoint.repo.common.expression.ItemDeltaItem) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) PrismContainerDefinition(com.evolveum.midpoint.prism.PrismContainerDefinition) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test)

Example 12 with ObjectDeltaObject

use of com.evolveum.midpoint.repo.common.expression.ObjectDeltaObject in project midpoint by Evolveum.

the class TestAbstractAssignmentEvaluator method test200DisableEngineerEmployeeInducement.

/**
	 * Disable Engineer -> Employee inducement.
	 */
@Test(enabled = false)
public void test200DisableEngineerEmployeeInducement() throws Exception {
    final String TEST_NAME = "test200DisableEngineerEmployeeInducement";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestAssignmentEvaluator.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    // disable Engineer->Employee inducement
    ObjectDelta disableInducementDelta = DeltaBuilder.deltaFor(RoleType.class, prismContext).item(RoleType.F_INDUCEMENT, 3, F_ACTIVATION, F_ADMINISTRATIVE_STATUS).replace(ActivationStatusType.DISABLED).asObjectDelta(ROLE_CORP_ENGINEER_OID);
    modelService.executeChanges(Collections.singletonList(disableInducementDelta), null, task, result);
    AssignmentEvaluator<UserType> assignmentEvaluator = createAssignmentEvaluator();
    PrismAsserts.assertParentConsistency(userTypeJack.asPrismObject());
    AssignmentType assignmentType = getAssignmentType(ASSIGNMENT_ROLE_ENGINEER_FILE);
    ObjectDeltaObject<UserType> userOdo = new ObjectDeltaObject<>(userTypeJack.asPrismObject(), null, null);
    userOdo.recompute();
    ItemDeltaItem<PrismContainerValue<AssignmentType>, PrismContainerDefinition<AssignmentType>> assignmentIdi = new ItemDeltaItem<>();
    assignmentIdi.setItemOld(LensUtil.createAssignmentSingleValueContainerClone(assignmentType));
    assignmentIdi.recompute();
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    EvaluatedAssignmentImpl<UserType> evaluatedAssignment = assignmentEvaluator.evaluate(assignmentIdi, PlusMinusZero.ZERO, false, userTypeJack, "testRoleEngineer", task, result);
    evaluatedAssignment.evaluateConstructions(userOdo, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    assertNotNull(evaluatedAssignment);
    display("Evaluated assignment", evaluatedAssignment.debugDump());
// TODO
//		assertEquals(2, evaluatedAssignment.getConstructions().size());
//		PrismAsserts.assertParentConsistency(userTypeJack.asPrismObject());
//
//		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", 1, evaluatedAssignment.getAdminGuiConfigurations().size());
}
Also used : Task(com.evolveum.midpoint.task.api.Task) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) RoleType(com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectDeltaObject(com.evolveum.midpoint.repo.common.expression.ObjectDeltaObject) ItemDeltaItem(com.evolveum.midpoint.repo.common.expression.ItemDeltaItem) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) PrismContainerDefinition(com.evolveum.midpoint.prism.PrismContainerDefinition) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test)

Example 13 with ObjectDeltaObject

use of com.evolveum.midpoint.repo.common.expression.ObjectDeltaObject in project midpoint by Evolveum.

the class TestAbstractAssignmentEvaluator method test120DirectExpressionReplaceDescription.

@Test
public void test120DirectExpressionReplaceDescription() throws Exception {
    final String TEST_NAME = "test120DirectExpressionReplaceDescription";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestAssignmentEvaluator.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    PrismObject<UserType> user = userTypeJack.asPrismObject().clone();
    AssignmentType assignmentType = unmarshallValueFromFile(ASSIGNMENT_DIRECT_EXPRESSION_FILE, AssignmentType.class);
    user.asObjectable().getAssignment().add(assignmentType.clone());
    ItemPath path = new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(123L), new NameItemPathSegment(AssignmentType.F_DESCRIPTION));
    ObjectDelta<UserType> userDelta = ObjectDelta.createModificationReplaceProperty(UserType.class, USER_JACK_OID, path, prismContext, "captain");
    ObjectDeltaObject<UserType> userOdo = new ObjectDeltaObject<>(user, userDelta, null);
    userOdo.recompute();
    AssignmentEvaluator<UserType> assignmentEvaluator = createAssignmentEvaluator(userOdo);
    ItemDeltaItem<PrismContainerValue<AssignmentType>, PrismContainerDefinition<AssignmentType>> assignmentIdi = new ItemDeltaItem<>();
    assignmentIdi.setItemOld(LensUtil.createAssignmentSingleValueContainerClone(assignmentType));
    assignmentIdi.setSubItemDeltas(userDelta.getModifications());
    assignmentIdi.recompute();
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    EvaluatedAssignmentImpl<UserType> evaluatedAssignment = assignmentEvaluator.evaluate(assignmentIdi, PlusMinusZero.ZERO, false, userTypeJack, "testDirect", task, result);
    evaluatedAssignment.evaluateConstructions(userOdo, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    assertNotNull(evaluatedAssignment);
    display("Evaluated assignment", evaluatedAssignment);
    assertEquals(1, evaluatedAssignment.getConstructionTriple().size());
    PrismAsserts.assertParentConsistency(user);
    Construction<UserType> construction = evaluatedAssignment.getConstructionTriple().getZeroSet().iterator().next();
    assertNotNull("No object class definition in construction", construction.getRefinedObjectClassDefinition());
    assertEquals(1, construction.getAttributeMappings().size());
    Mapping<PrismPropertyValue<String>, PrismPropertyDefinition<String>> attributeMapping = (Mapping<PrismPropertyValue<String>, PrismPropertyDefinition<String>>) construction.getAttributeMappings().iterator().next();
    PrismValueDeltaSetTriple<PrismPropertyValue<String>> outputTriple = attributeMapping.getOutputTriple();
    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) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Mapping(com.evolveum.midpoint.model.common.mapping.Mapping) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) ItemDeltaItem(com.evolveum.midpoint.repo.common.expression.ItemDeltaItem) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) ObjectDeltaObject(com.evolveum.midpoint.repo.common.expression.ObjectDeltaObject) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) PrismContainerDefinition(com.evolveum.midpoint.prism.PrismContainerDefinition) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 14 with ObjectDeltaObject

use of com.evolveum.midpoint.repo.common.expression.ObjectDeltaObject in project midpoint by Evolveum.

the class TestAbstractAssignmentEvaluator method test180RoleManagerRemoveCostCenter.

/**
     * jack has assigned role Manager.
     *
     * However, condition in job metarole for Manager is such that it needs "management"
     * to be present in user/costCenter in order to be active.
     *
     * In this test we remove the value of "management" from jack.
     */
@Test
public void test180RoleManagerRemoveCostCenter() throws Exception {
    final String TEST_NAME = "test180RoleManagerRemoveCostCenter";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestAssignmentEvaluator.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    PrismObject<UserType> user = userTypeJack.asPrismObject().clone();
    user.asObjectable().setCostCenter("management");
    AssignmentType assignmentType = getAssignmentType(ASSIGNMENT_ROLE_MANAGER_FILE);
    AssignmentType assignmentForUser = assignmentType.clone();
    assignmentForUser.asPrismContainerValue().setParent(null);
    user.asObjectable().getAssignment().add(assignmentForUser);
    ObjectDelta<UserType> userDelta = ObjectDelta.createModificationReplaceProperty(UserType.class, USER_JACK_OID, UserType.F_COST_CENTER, prismContext);
    ObjectDeltaObject<UserType> userOdo = new ObjectDeltaObject<>(user, userDelta, null);
    userOdo.recompute();
    AssignmentEvaluator<UserType> assignmentEvaluator = createAssignmentEvaluator(userOdo);
    PrismAsserts.assertParentConsistency(userTypeJack.asPrismObject());
    ItemDeltaItem<PrismContainerValue<AssignmentType>, PrismContainerDefinition<AssignmentType>> assignmentIdi = new ItemDeltaItem<>();
    assignmentIdi.setItemOld(LensUtil.createAssignmentSingleValueContainerClone(assignmentType));
    assignmentIdi.recompute();
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    EvaluatedAssignmentImpl<UserType> evaluatedAssignment = assignmentEvaluator.evaluate(assignmentIdi, PlusMinusZero.ZERO, false, userTypeJack, TEST_NAME, task, result);
    evaluatedAssignment.evaluateConstructions(userOdo, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    assertNotNull(evaluatedAssignment);
    display("Evaluated assignment", evaluatedAssignment.debugDump());
    assertEquals(4, evaluatedAssignment.getConstructionTriple().size());
    PrismAsserts.assertParentConsistency(userTypeJack.asPrismObject());
    // because Employee's job metarole is active even if Manager's is not
    assertConstruction(evaluatedAssignment, ZERO, "title", ZERO, "Employee");
    assertConstruction(evaluatedAssignment, ZERO, "title", PLUS);
    assertConstruction(evaluatedAssignment, ZERO, "title", MINUS);
    // because Manager's job metarole is not active any more
    assertConstruction(evaluatedAssignment, MINUS, "title", ZERO, "Manager");
    assertConstruction(evaluatedAssignment, MINUS, "title", PLUS);
    assertConstruction(evaluatedAssignment, MINUS, "title", MINUS);
    assertNoConstruction(evaluatedAssignment, PLUS, "title");
    // because Generic Metarole is active all the time
    assertConstruction(evaluatedAssignment, ZERO, "location", ZERO, "Caribbean");
    assertConstruction(evaluatedAssignment, ZERO, "location", PLUS);
    assertConstruction(evaluatedAssignment, ZERO, "location", MINUS);
    assertNoConstruction(evaluatedAssignment, PLUS, "location");
    assertNoConstruction(evaluatedAssignment, MINUS, "location");
}
Also used : Task(com.evolveum.midpoint.task.api.Task) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectDeltaObject(com.evolveum.midpoint.repo.common.expression.ObjectDeltaObject) ItemDeltaItem(com.evolveum.midpoint.repo.common.expression.ItemDeltaItem) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) PrismContainerDefinition(com.evolveum.midpoint.prism.PrismContainerDefinition) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test)

Example 15 with ObjectDeltaObject

use of com.evolveum.midpoint.repo.common.expression.ObjectDeltaObject in project midpoint by Evolveum.

the class TestAbstractAssignmentEvaluator method test150RoleEngineer.

@Test
public void test150RoleEngineer() throws Exception {
    final String TEST_NAME = "test150RoleEngineer";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestAssignmentEvaluator.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    AssignmentEvaluator<UserType> assignmentEvaluator = createAssignmentEvaluator();
    PrismAsserts.assertParentConsistency(userTypeJack.asPrismObject());
    AssignmentType assignmentType = getAssignmentType(ASSIGNMENT_ROLE_ENGINEER_FILE);
    ObjectDeltaObject<UserType> userOdo = new ObjectDeltaObject<>(userTypeJack.asPrismObject(), null, null);
    userOdo.recompute();
    ItemDeltaItem<PrismContainerValue<AssignmentType>, PrismContainerDefinition<AssignmentType>> assignmentIdi = new ItemDeltaItem<>();
    assignmentIdi.setItemOld(LensUtil.createAssignmentSingleValueContainerClone(assignmentType));
    assignmentIdi.recompute();
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    EvaluatedAssignmentImpl<UserType> evaluatedAssignment = assignmentEvaluator.evaluate(assignmentIdi, PlusMinusZero.ZERO, false, userTypeJack, "testRoleEngineer", task, result);
    evaluatedAssignment.evaluateConstructions(userOdo, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    assertNotNull(evaluatedAssignment);
    display("Evaluated assignment", evaluatedAssignment.debugDump());
    assertEquals(4, evaluatedAssignment.getConstructionTriple().size());
    PrismAsserts.assertParentConsistency(userTypeJack.asPrismObject());
    assertConstruction(evaluatedAssignment, ZERO, "title", ZERO, "Employee", "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", 1, evaluatedAssignment.getAdminGuiConfigurations().size());
}
Also used : Task(com.evolveum.midpoint.task.api.Task) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectDeltaObject(com.evolveum.midpoint.repo.common.expression.ObjectDeltaObject) ItemDeltaItem(com.evolveum.midpoint.repo.common.expression.ItemDeltaItem) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) PrismContainerDefinition(com.evolveum.midpoint.prism.PrismContainerDefinition) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test)

Aggregations

ObjectDeltaObject (com.evolveum.midpoint.repo.common.expression.ObjectDeltaObject)16 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)15 ItemDeltaItem (com.evolveum.midpoint.repo.common.expression.ItemDeltaItem)14 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)14 PrismContainerDefinition (com.evolveum.midpoint.prism.PrismContainerDefinition)13 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)13 Task (com.evolveum.midpoint.task.api.Task)13 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)13 Test (org.testng.annotations.Test)13 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)5 ItemDefinition (com.evolveum.midpoint.prism.ItemDefinition)3 PrismPropertyDefinition (com.evolveum.midpoint.prism.PrismPropertyDefinition)3 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)3 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)3 StringPolicyResolver (com.evolveum.midpoint.repo.common.expression.StringPolicyResolver)3 RoleType (com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType)3 Mapping (com.evolveum.midpoint.model.common.mapping.Mapping)2 IdItemPathSegment (com.evolveum.midpoint.prism.path.IdItemPathSegment)2 NameItemPathSegment (com.evolveum.midpoint.prism.path.NameItemPathSegment)2 GenerateExpressionEvaluatorType (com.evolveum.midpoint.xml.ns._public.common.common_3.GenerateExpressionEvaluatorType)2