Search in sources :

Example 1 with RecordingProgressListener

use of com.evolveum.midpoint.model.impl.util.RecordingProgressListener in project midpoint by Evolveum.

the class TestPolicyRules method test300DrakeChangeEmployeeType.

/**
 * MID-4132
 *
 * Drake changes employeeType null to T. There's a global notification policy rule applicable to users with employeeType != T.
 * Should we get the notification?
 *
 * Yes and no. The condition is checked on objectCurrent. So, in primary state the rule is applied (employeeType is null
 * at that moment). But in final state (when notification actions are evaluated) the condition should be already false.
 * So we should not get the notification.
 */
@Test
public void test300DrakeChangeEmployeeType() throws Exception {
    Task task = getTestTask();
    OperationResult result = getTestOperationResult();
    // GIVEN
    // WHEN
    when();
    ObjectDelta<? extends ObjectType> delta = deltaFor(UserType.class).item(UserType.F_ASSIGNMENT).add(ObjectTypeUtil.createAssignmentTo(ROLE_JUDGE_OID, ObjectTypes.ROLE, prismContext)).item(UserType.F_EMPLOYEE_NUMBER).replace("T").asObjectDelta(USER_DRAKE_OID);
    RecordingProgressListener recordingListener = new RecordingProgressListener();
    modelService.executeChanges(Collections.singletonList(delta), null, task, Collections.singleton(recordingListener), result);
    // THEN
    then();
    result.computeStatus();
    TestUtil.assertSuccess(result);
    PrismObject<UserType> userAfter = getUser(USER_DRAKE_OID);
    display("User after", userAfter);
    assertAssignedRole(userAfter, ROLE_JUDGE_OID);
    LensFocusContext<?> focusContext = ((LensContext<?>) recordingListener.getModelContext()).getFocusContext();
    displayDumpable("focusContext", focusContext);
    assertEquals("Wrong # of focus policy rules", 0, focusContext.getObjectPolicyRules().size());
}
Also used : Task(com.evolveum.midpoint.task.api.Task) RecordingProgressListener(com.evolveum.midpoint.model.impl.util.RecordingProgressListener) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test)

Example 2 with RecordingProgressListener

use of com.evolveum.midpoint.model.impl.util.RecordingProgressListener in project midpoint by Evolveum.

the class TestObjectLifecycleAdvanced method test030ActivateIncompleteRoleAgain.

/**
 * This time let's fill-in the description as well.
 */
@Test
public void test030ActivateIncompleteRoleAgain() throws Exception {
    login(userAdministrator);
    Task task = getTestTask();
    OperationResult result = getTestOperationResult();
    @SuppressWarnings({ "raw" }) ObjectDelta<RoleType> activateRoleDelta = prismContext.deltaFor(RoleType.class).item(RoleType.F_LIFECYCLE_STATE).replace(SchemaConstants.LIFECYCLE_ACTIVE).item(RoleType.F_DESCRIPTION).replace("hi").asObjectDelta(roleEmployeeOid);
    RecordingProgressListener recordingListener = new RecordingProgressListener();
    try {
        modelService.executeChanges(Collections.singleton(activateRoleDelta), null, task, Collections.singleton(recordingListener), result);
        fail("unexpected success");
    } catch (PolicyViolationException e) {
        System.out.println("Got expected exception: " + e.getMessage());
    }
    // noinspection unchecked
    LensContext<RoleType> context = (LensContext<RoleType>) recordingListener.getModelContext();
    System.out.println(context.dumpFocusPolicyRules(0));
    EvaluatedPolicyRule incompleteActivationRule = context.getFocusContext().getObjectPolicyRules().stream().filter(rule -> "disallow-incomplete-role-activation".equals(rule.getName())).findFirst().orElseThrow(() -> new AssertionError("rule not found"));
    assertEquals("Wrong # of triggers in incompleteActivationRule", 2, incompleteActivationRule.getTriggers().size());
}
Also used : EvaluatedPolicyRule(com.evolveum.midpoint.model.api.context.EvaluatedPolicyRule) ExpectedTask(com.evolveum.midpoint.wf.impl.ExpectedTask) Task(com.evolveum.midpoint.task.api.Task) RecordingProgressListener(com.evolveum.midpoint.model.impl.util.RecordingProgressListener) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException) LensContext(com.evolveum.midpoint.model.impl.lens.LensContext) Test(org.testng.annotations.Test)

Example 3 with RecordingProgressListener

use of com.evolveum.midpoint.model.impl.util.RecordingProgressListener in project midpoint by Evolveum.

the class TestPolicyDrivenRoleLifecycle method activateRole.

private void activateRole(String oid, Holder<LensContext<?>> contextHolder, Task task, OperationResult result) throws SchemaException, CommunicationException, ObjectAlreadyExistsException, ExpressionEvaluationException, PolicyViolationException, SecurityViolationException, ConfigurationException, ObjectNotFoundException {
    ObjectDelta<RoleType> delta = prismContext.deltaFor(RoleType.class).item(RoleType.F_LIFECYCLE_STATE).replace(SchemaConstants.LIFECYCLE_ACTIVE).asObjectDeltaCast(oid);
    RecordingProgressListener listener = new RecordingProgressListener();
    try {
        modelService.executeChanges(singleton(delta), null, task, singleton(listener), result);
    } finally {
        if (contextHolder != null) {
            contextHolder.setValue((LensContext<?>) listener.getModelContext());
        }
    }
}
Also used : RecordingProgressListener(com.evolveum.midpoint.model.impl.util.RecordingProgressListener)

Example 4 with RecordingProgressListener

use of com.evolveum.midpoint.model.impl.util.RecordingProgressListener in project midpoint by Evolveum.

the class TestObjectLifecycleAdvanced method test020ActivateIncompleteRole.

@Test
public void test020ActivateIncompleteRole() throws Exception {
    login(userAdministrator);
    Task task = getTestTask();
    OperationResult result = getTestOperationResult();
    @SuppressWarnings({ "raw" }) ObjectDelta<RoleType> activateRoleDelta = prismContext.deltaFor(RoleType.class).item(RoleType.F_LIFECYCLE_STATE).replace(SchemaConstants.LIFECYCLE_ACTIVE).asObjectDelta(roleEmployeeOid);
    RecordingProgressListener recordingListener = new RecordingProgressListener();
    try {
        modelService.executeChanges(Collections.singleton(activateRoleDelta), null, task, Collections.singleton(recordingListener), result);
        fail("unexpected success");
    } catch (PolicyViolationException e) {
        System.out.println("Got expected exception: " + e.getMessage());
    }
    // noinspection unchecked
    LensContext<RoleType> context = (LensContext<RoleType>) recordingListener.getModelContext();
    System.out.println(context.dumpFocusPolicyRules(0));
    EvaluatedPolicyRule incompleteActivationRule = context.getFocusContext().getObjectPolicyRules().stream().filter(rule -> "disallow-incomplete-role-activation".equals(rule.getName())).findFirst().orElseThrow(() -> new AssertionError("rule not found"));
    // objectState + or
    assertEquals("Wrong # of triggers in incompleteActivationRule", 2, incompleteActivationRule.getTriggers().size());
}
Also used : EvaluatedPolicyRule(com.evolveum.midpoint.model.api.context.EvaluatedPolicyRule) ExpectedTask(com.evolveum.midpoint.wf.impl.ExpectedTask) Task(com.evolveum.midpoint.task.api.Task) RecordingProgressListener(com.evolveum.midpoint.model.impl.util.RecordingProgressListener) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException) LensContext(com.evolveum.midpoint.model.impl.lens.LensContext) Test(org.testng.annotations.Test)

Aggregations

RecordingProgressListener (com.evolveum.midpoint.model.impl.util.RecordingProgressListener)4 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)3 Task (com.evolveum.midpoint.task.api.Task)3 Test (org.testng.annotations.Test)3 EvaluatedPolicyRule (com.evolveum.midpoint.model.api.context.EvaluatedPolicyRule)2 LensContext (com.evolveum.midpoint.model.impl.lens.LensContext)2 PolicyViolationException (com.evolveum.midpoint.util.exception.PolicyViolationException)2 ExpectedTask (com.evolveum.midpoint.wf.impl.ExpectedTask)2