Search in sources :

Example 6 with ExpectedTask

use of com.evolveum.midpoint.wf.impl.ExpectedTask in project midpoint by Evolveum.

the class TestAssignmentsAdvanced method executeUnassignRoles123ToJack.

@SuppressWarnings("SameParameterValue")
private void executeUnassignRoles123ToJack(boolean immediate, boolean approve, boolean byId, boolean has1and2) throws Exception {
    String testName = getTestNameShort();
    PrismObject<UserType> jack = getUser(userJackOid);
    AssignmentType a1 = has1and2 ? findAssignmentByTargetRequired(jack, roleRole21Oid) : null;
    AssignmentType a2 = has1and2 ? findAssignmentByTargetRequired(jack, roleRole22Oid) : null;
    AssignmentType a3 = findAssignmentByTargetRequired(jack, roleRole23Oid);
    AssignmentType del1 = toDelete(a1, byId);
    AssignmentType del2 = toDelete(a2, byId);
    AssignmentType del3 = toDelete(a3, byId);
    ObjectDelta<UserType> deleteRole1Delta = has1and2 ? prismContext.deltaFor(UserType.class).item(UserType.F_ASSIGNMENT).delete(del1).asObjectDelta(userJackOid) : null;
    ObjectDelta<UserType> deleteRole2Delta = has1and2 ? prismContext.deltaFor(UserType.class).item(UserType.F_ASSIGNMENT).delete(del2).asObjectDelta(userJackOid) : null;
    ObjectDelta<UserType> deleteRole3Delta = prismContext.deltaFor(UserType.class).item(UserType.F_ASSIGNMENT).delete(del3).asObjectDelta(userJackOid);
    ObjectDelta<UserType> changeDescriptionDelta = prismContext.deltaFor(UserType.class).item(UserType.F_DESCRIPTION).replace(testName).asObjectDelta(userJackOid);
    ObjectDelta<UserType> primaryDelta = ObjectDeltaCollectionsUtil.summarize(changeDescriptionDelta, deleteRole1Delta, deleteRole2Delta, deleteRole3Delta);
    ObjectDelta<UserType> delta0 = ObjectDeltaCollectionsUtil.summarize(changeDescriptionDelta, deleteRole1Delta, deleteRole2Delta);
    String originalDescription = getUser(userJackOid).asObjectable().getDescription();
    executeTest2(new TestDetails2<UserType>() {

        @Override
        protected PrismObject<UserType> getFocus(OperationResult result) {
            return jack.clone();
        }

        @Override
        protected ObjectDelta<UserType> getFocusDelta() {
            return primaryDelta.clone();
        }

        @Override
        protected int getNumberOfDeltasToApprove() {
            return 1;
        }

        @Override
        protected List<Boolean> getApprovals() {
            return singletonList(approve);
        }

        @Override
        protected List<ObjectDelta<UserType>> getExpectedDeltasToApprove() {
            return singletonList(deleteRole3Delta.clone());
        }

        @Override
        protected ObjectDelta<UserType> getExpectedDelta0() {
            return delta0.clone();
        }

        @Override
        protected String getObjectOid() {
            return jack.getOid();
        }

        @Override
        protected List<ExpectedTask> getExpectedTasks() {
            return singletonList(new ExpectedTask(roleRole23Oid, "Unassigning role \"Role23\" from user \"Jack Sparrow\""));
        }

        // after first step
        @Override
        protected List<ExpectedWorkItem> getExpectedWorkItems() {
            List<ExpectedTask> tasks = getExpectedTasks();
            return singletonList(new ExpectedWorkItem(userSecurityApproverOid, roleRole23Oid, tasks.get(0)));
        }

        @Override
        protected void assertDeltaExecuted(int number, boolean yes, Task opTask, OperationResult result) throws Exception {
            switch(number) {
                case 0:
                    if (yes) {
                        assertUserProperty(userJackOid, UserType.F_DESCRIPTION, testName);
                    } else {
                        if (originalDescription != null) {
                            assertUserProperty(userJackOid, UserType.F_DESCRIPTION, originalDescription);
                        } else {
                            assertUserNoProperty(userJackOid, UserType.F_DESCRIPTION);
                        }
                    }
                    if (yes || !has1and2) {
                        assertNotAssignedRole(userJackOid, roleRole21Oid, result);
                        assertNotAssignedRole(userJackOid, roleRole22Oid, result);
                    } else {
                        assertAssignedRole(userJackOid, roleRole21Oid, result);
                        assertAssignedRole(userJackOid, roleRole22Oid, result);
                    }
                    break;
                case 1:
                    if (yes) {
                        assertNotAssignedRole(userJackOid, roleRole23Oid, result);
                    } else {
                        assertAssignedRole(userJackOid, roleRole23Oid, result);
                    }
                    break;
                default:
                    throw new IllegalArgumentException("Unexpected delta number: " + number);
            }
        }

        @Override
        protected Boolean decideOnApproval(CaseWorkItemType caseWorkItem) {
            // ignore this way of approving
            return null;
        }

        @Override
        public List<ApprovalInstruction> getApprovalSequence() {
            List<ExpectedTask> tasks = getExpectedTasks();
            List<ApprovalInstruction> instructions = new ArrayList<>();
            instructions.add(new ApprovalInstruction(new ExpectedWorkItem(userSecurityApproverOid, roleRole23Oid, tasks.get(0)), approve, userSecurityApproverOid, null));
            return instructions;
        }
    }, 1, immediate);
}
Also used : ExpectedTask(com.evolveum.midpoint.wf.impl.ExpectedTask) Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ExpectedWorkItem(com.evolveum.midpoint.wf.impl.ExpectedWorkItem) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException) PrismObject(com.evolveum.midpoint.prism.PrismObject) ApprovalInstruction(com.evolveum.midpoint.wf.impl.ApprovalInstruction) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ExpectedTask(com.evolveum.midpoint.wf.impl.ExpectedTask)

Example 7 with ExpectedTask

use of com.evolveum.midpoint.wf.impl.ExpectedTask in project midpoint by Evolveum.

the class TestSoD method test030AssignRoleRespectable.

/**
 * Assign Respectable to jack. This should trigger an approval as well (because it implies a Thief).
 */
@Test
public void test030AssignRoleRespectable() throws Exception {
    login(userAdministrator);
    Task task = getTestTask();
    OperationResult result = getTestOperationResult();
    // GIVEN
    unassignRole(userJackOid, rolePirateOid, task, result);
    assertNotAssignedRole(userJackOid, rolePirateOid, result);
    // WHEN+THEN
    PrismObject<UserType> jack = getUser(userJackOid);
    ObjectDelta<UserType> addRespectableDelta = prismContext.deltaFor(UserType.class).item(UserType.F_ASSIGNMENT).add(createAssignmentTo(roleRespectableOid, ObjectTypes.ROLE, prismContext)).asObjectDelta(userJackOid);
    // WHEN+THEN
    executeTest2(new TestDetails2<UserType>() {

        @Override
        protected PrismObject<UserType> getFocus(OperationResult result) {
            return jack.clone();
        }

        @Override
        protected ObjectDelta<UserType> getFocusDelta() {
            return addRespectableDelta.clone();
        }

        @Override
        protected int getNumberOfDeltasToApprove() {
            return 1;
        }

        @Override
        protected List<Boolean> getApprovals() {
            return Collections.singletonList(true);
        }

        @Override
        protected List<ObjectDelta<UserType>> getExpectedDeltasToApprove() {
            return Arrays.asList(addRespectableDelta.clone());
        }

        @Override
        protected ObjectDelta<UserType> getExpectedDelta0() {
            // return ObjectDelta.createEmptyModifyDelta(UserType.class, jack.getOid(), prismContext);
            return prismContext.deltaFactory().object().createModifyDelta(jack.getOid(), Collections.emptyList(), UserType.class);
        }

        @Override
        protected String getObjectOid() {
            return jack.getOid();
        }

        @Override
        protected List<ExpectedTask> getExpectedTasks() {
            return Collections.singletonList(new ExpectedTask(roleRespectableOid, "Role \"Thief\" (Respectable -> Thief) excludes role \"Judge\""));
        }

        @Override
        protected List<ExpectedWorkItem> getExpectedWorkItems() {
            List<ExpectedTask> etasks = getExpectedTasks();
            return Collections.singletonList(new ExpectedWorkItem(userSodApproverOid, roleRespectableOid, etasks.get(0)));
        }

        @Override
        protected void assertDeltaExecuted(int number, boolean yes, Task opTask, OperationResult result) throws Exception {
            switch(number) {
                case 1:
                    if (yes) {
                        assertAssignedRole(userJackOid, roleRespectableOid, result);
                    } else {
                        assertNotAssignedRole(userJackOid, roleRespectableOid, result);
                    }
                    break;
            }
        }

        @Override
        protected Boolean decideOnApproval(CaseWorkItemType caseWorkItem) throws Exception {
            login(getUser(userSodApproverOid));
            return true;
        }
    }, 1, false);
    // THEN
    display("jack as a Judge + Respectable", getUser(userJackOid));
    assertAssignedRole(userJackOid, roleJudgeOid, result);
    assertAssignedRole(userJackOid, roleRespectableOid, result);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ExpectedTask(com.evolveum.midpoint.wf.impl.ExpectedTask) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ExpectedWorkItem(com.evolveum.midpoint.wf.impl.ExpectedWorkItem) CaseWorkItemType(com.evolveum.midpoint.xml.ns._public.common.common_3.CaseWorkItemType) PrismObject(com.evolveum.midpoint.prism.PrismObject) List(java.util.List) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ExpectedTask(com.evolveum.midpoint.wf.impl.ExpectedTask) Test(org.testng.annotations.Test)

Example 8 with ExpectedTask

use of com.evolveum.midpoint.wf.impl.ExpectedTask in project midpoint by Evolveum.

the class TestSoD method test020AssignRolePirate.

/**
 * Assign Pirate to jack. This should trigger an approval.
 */
@Test
public void test020AssignRolePirate() throws Exception {
    given();
    login(userAdministrator);
    OperationResult result = getTestOperationResult();
    PrismObject<UserType> jack = getUser(userJackOid);
    String originalDescription = jack.asObjectable().getDescription();
    ObjectDelta<UserType> addPirateDelta = prismContext.deltaFor(UserType.class).item(UserType.F_ASSIGNMENT).add(createAssignmentTo(rolePirateOid, ObjectTypes.ROLE, prismContext)).asObjectDelta(userJackOid);
    ObjectDelta<UserType> changeDescriptionDelta = prismContext.deltaFor(UserType.class).item(UserType.F_DESCRIPTION).replace("Pirate Judge").asObjectDelta(userJackOid);
    ObjectDelta<UserType> primaryDelta = ObjectDeltaCollectionsUtil.summarize(addPirateDelta, changeDescriptionDelta);
    when();
    executeTest2(new TestDetails2<UserType>() {

        @Override
        protected PrismObject<UserType> getFocus(OperationResult result) {
            return jack.clone();
        }

        @Override
        protected ObjectDelta<UserType> getFocusDelta() {
            return primaryDelta.clone();
        }

        @Override
        protected int getNumberOfDeltasToApprove() {
            return 1;
        }

        @Override
        protected List<Boolean> getApprovals() {
            return Collections.singletonList(true);
        }

        @Override
        protected List<ObjectDelta<UserType>> getExpectedDeltasToApprove() {
            return Collections.singletonList(addPirateDelta.clone());
        }

        @Override
        protected ObjectDelta<UserType> getExpectedDelta0() {
            return changeDescriptionDelta.clone();
        }

        @Override
        protected String getObjectOid() {
            return jack.getOid();
        }

        @Override
        protected List<ExpectedTask> getExpectedTasks() {
            return Collections.singletonList(new ExpectedTask(rolePirateOid, "Role \"Pirate\" excludes role \"Judge\""));
        }

        @Override
        protected List<ExpectedWorkItem> getExpectedWorkItems() {
            List<ExpectedTask> etasks = getExpectedTasks();
            return Collections.singletonList(new ExpectedWorkItem(userSodApproverOid, rolePirateOid, etasks.get(0)));
        }

        @Override
        protected void assertDeltaExecuted(int number, boolean yes, Task opTask, OperationResult result) throws Exception {
            switch(number) {
                case 0:
                    if (yes) {
                        assertUserProperty(userJackOid, UserType.F_DESCRIPTION, "Pirate Judge");
                    } else {
                        if (originalDescription != null) {
                            assertUserProperty(userJackOid, UserType.F_DESCRIPTION, originalDescription);
                        } else {
                            assertUserNoProperty(userJackOid, UserType.F_DESCRIPTION);
                        }
                    }
                    break;
                case 1:
                    if (yes) {
                        assertAssignedRole(userJackOid, rolePirateOid, result);
                    } else {
                        assertNotAssignedRole(userJackOid, rolePirateOid, result);
                    }
                    break;
            }
        }

        @Override
        protected Boolean decideOnApproval(CaseWorkItemType caseWorkItem) throws Exception {
            login(getUser(userSodApproverOid));
            return true;
        }
    }, 1, false);
    then();
    display("jack as a Pirate + Judge", getUser(userJackOid));
    AssignmentType judgeAssignment = assertAssignedRole(userJackOid, roleJudgeOid, result);
    assertExclusionViolationSituation(judgeAssignment);
    AssignmentType pirateAssignment = assertAssignedRole(userJackOid, rolePirateOid, result);
    assertExclusionViolationSituation(pirateAssignment);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ExpectedTask(com.evolveum.midpoint.wf.impl.ExpectedTask) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ExpectedWorkItem(com.evolveum.midpoint.wf.impl.ExpectedWorkItem) CaseWorkItemType(com.evolveum.midpoint.xml.ns._public.common.common_3.CaseWorkItemType) PrismObject(com.evolveum.midpoint.prism.PrismObject) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) List(java.util.List) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ExpectedTask(com.evolveum.midpoint.wf.impl.ExpectedTask) Test(org.testng.annotations.Test)

Example 9 with ExpectedTask

use of com.evolveum.midpoint.wf.impl.ExpectedTask in project midpoint by Evolveum.

the class AbstractTestObjectLifecycleApproval method test100ModifyRolePirateDescription.

@Test
public void test100ModifyRolePirateDescription() throws Exception {
    login(userAdministrator);
    ObjectDelta<RoleType> descriptionDelta = prismContext.deltaFor(RoleType.class).item(RoleType.F_DESCRIPTION).replace("Bloody pirate").asObjectDelta(rolePirateOid);
    prismContext.deltaFactory().object().createModifyDelta(rolePirateOid, Collections.emptyList(), RoleType.class);
    ExpectedTask expectedTask = new ExpectedTask(null, "Modifying role \"pirate\"");
    ExpectedWorkItem expectedWorkItem = new ExpectedWorkItem(USER_PIRATE_OWNER_OID, null, expectedTask);
    modifyObject(descriptionDelta, false, true, USER_PIRATE_OWNER_OID, Collections.singletonList(expectedTask), Collections.singletonList(expectedWorkItem), () -> {
    }, () -> assertNull("Description is modified", getRoleSimple(rolePirateOid).getDescription()), () -> assertEquals("Description was NOT modified", "Bloody pirate", getRoleSimple(rolePirateOid).getDescription()));
    PrismObject<RoleType> roleAfter = getRole(rolePirateOid);
    display("pirate after", roleAfter);
    MetadataType metadata = roleAfter.asObjectable().getMetadata();
    assertEquals("Wrong modify approver ref", singleton(ObjectTypeUtil.createObjectRef(USER_PIRATE_OWNER_OID, ObjectTypes.USER).relation(SchemaConstants.ORG_DEFAULT)), new HashSet<>(metadata.getModifyApproverRef()));
    assertEquals("Wrong modify approval comments", singleton("pirate-owner :: modification comment"), new HashSet<>(metadata.getModifyApprovalComment()));
}
Also used : ExpectedWorkItem(com.evolveum.midpoint.wf.impl.ExpectedWorkItem) ExpectedTask(com.evolveum.midpoint.wf.impl.ExpectedTask) Test(org.testng.annotations.Test)

Example 10 with ExpectedTask

use of com.evolveum.midpoint.wf.impl.ExpectedTask in project midpoint by Evolveum.

the class AbstractTestObjectLifecycleApproval method createObject.

private void createObject(ObjectType object, boolean immediate, boolean approve, String assigneeOid) throws Exception {
    // noinspection unchecked
    ObjectDelta<RoleType> addObjectDelta = DeltaFactory.Object.createAddDelta((PrismObject<RoleType>) object.asPrismObject());
    executeTest(new TestDetails() {

        @Override
        protected LensContext createModelContext(OperationResult result) throws Exception {
            // noinspection unchecked
            LensContext<RoleType> lensContext = createLensContext((Class) object.getClass());
            addFocusDeltaToContext(lensContext, addObjectDelta);
            return lensContext;
        }

        @Override
        protected void afterFirstClockworkRun(CaseType rootCase, CaseType case0, List<CaseType> subcases, List<CaseWorkItemType> workItems, Task opTask, OperationResult result) throws Exception {
            if (!immediate) {
                // ModelContext taskModelContext = temporaryHelper.getModelContext(rootCase, opTask, result);
                // ObjectDelta realDelta0 = taskModelContext.getFocusContext().getPrimaryDelta();
                // assertTrue("Non-empty primary focus delta: " + realDelta0.debugDump(), realDelta0.isEmpty());
                assertNoObject(object);
                ExpectedTask expectedTask = new ExpectedTask(null, "Adding role \"" + object.getName().getOrig() + "\"");
                ExpectedWorkItem expectedWorkItem = new ExpectedWorkItem(assigneeOid, null, expectedTask);
                assertWfContextAfterClockworkRun(rootCase, subcases, workItems, null, Collections.singletonList(expectedTask), Collections.singletonList(expectedWorkItem));
            }
        }

        @Override
        protected void afterCase0Finishes(CaseType rootCase, Task opTask, OperationResult result) throws Exception {
            assertNoObject(object);
        }

        @Override
        protected void afterRootCaseFinishes(CaseType rootCase, List<CaseType> subcases, Task opTask, OperationResult result) throws Exception {
            if (approve) {
                assertObject(object);
            } else {
                assertNoObject(object);
            }
        }

        @Override
        protected boolean executeImmediately() {
            return immediate;
        }

        @Override
        public List<ApprovalInstruction> getApprovalSequence() {
            return singletonList(new ApprovalInstruction(null, true, USER_JUPITER_OID, "creation comment"));
        }
    }, 1);
}
Also used : ExpectedTask(com.evolveum.midpoint.wf.impl.ExpectedTask) Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ExpectedWorkItem(com.evolveum.midpoint.wf.impl.ExpectedWorkItem) LensContext(com.evolveum.midpoint.model.impl.lens.LensContext) ApprovalInstruction(com.evolveum.midpoint.wf.impl.ApprovalInstruction) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) ExpectedTask(com.evolveum.midpoint.wf.impl.ExpectedTask)

Aggregations

ExpectedTask (com.evolveum.midpoint.wf.impl.ExpectedTask)16 ExpectedWorkItem (com.evolveum.midpoint.wf.impl.ExpectedWorkItem)16 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)14 Task (com.evolveum.midpoint.task.api.Task)14 Test (org.testng.annotations.Test)13 LensContext (com.evolveum.midpoint.model.impl.lens.LensContext)10 ApprovalInstruction (com.evolveum.midpoint.wf.impl.ApprovalInstruction)10 List (java.util.List)10 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)7 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)7 PrismObject (com.evolveum.midpoint.prism.PrismObject)4 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)4 PolicyViolationException (com.evolveum.midpoint.util.exception.PolicyViolationException)4 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)2 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)2 CaseWorkItemType (com.evolveum.midpoint.xml.ns._public.common.common_3.CaseWorkItemType)2 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)2 PrismObjectAsserter (com.evolveum.midpoint.test.asserter.prism.PrismObjectAsserter)1 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)1