Search in sources :

Example 1 with ApprovalInstruction

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

the class TestObjectLifecycleApprovalGlobal method test700CreateRoleThief.

@Test
public void test700CreateRoleThief() throws Exception {
    login(userAdministrator);
    RoleType thief = new RoleType(prismContext).name("thief").description("something").riskLevel("high").inducement(createAssignmentTo(OID1, ObjectTypes.ROLE, prismContext)).inducement(createAssignmentTo(OID2, ObjectTypes.ROLE, prismContext));
    ObjectDelta<RoleType> addObjectDelta = DeltaFactory.Object.createAddDelta(thief.asPrismObject());
    executeTest(new TestDetails() {

        @Override
        protected LensContext createModelContext(OperationResult result) throws Exception {
            LensContext<RoleType> lensContext = createLensContext(RoleType.class);
            addFocusDeltaToContext(lensContext, addObjectDelta);
            return lensContext;
        }

        @Override
        protected void afterFirstClockworkRun(CaseType rootCase, CaseType case0, List<CaseType> subcases, List<CaseWorkItemType> workItems, Task opTask, OperationResult result) {
            display("subtasks", subcases);
            display("work items", workItems);
        // todo some asserts here
        }

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

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

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

        @Override
        public boolean strictlySequentialApprovals() {
            return true;
        }

        @Override
        public List<ApprovalInstruction> getApprovalSequence() {
            List<ApprovalInstruction> instructions = new ArrayList<>();
            // this is step 2 in riskLevel part (first step is owner that is skipped)
            instructions.add(new ApprovalInstruction(new ExpectedWorkItem(USER_ADMINISTRATOR_OID, null, new ExpectedTask(null, "Setting riskLevel")), true, USER_ADMINISTRATOR_OID, null));
            // this is step 3 in riskLevel part
            instructions.add(new ApprovalInstruction(new ExpectedWorkItem(USER_PETER_OID, null, new ExpectedTask(null, "Setting riskLevel")), true, USER_ADMINISTRATOR_OID, null));
            // this is step 1 in inducement part
            instructions.add(new ApprovalInstruction(new ExpectedWorkItem(USER_ADMINISTRATOR_OID, null, new ExpectedTask(null, "Changing inducement")), true, USER_ADMINISTRATOR_OID, null));
            // this is step 2 in inducement part
            instructions.add(new ApprovalInstruction(new ExpectedWorkItem(USER_BOB_OID, null, new ExpectedTask(null, "Changing inducement")), true, USER_ADMINISTRATOR_OID, null));
            // this is step 1 in inducement part (2nd)
            instructions.add(new ApprovalInstruction(new ExpectedWorkItem(USER_ADMINISTRATOR_OID, null, new ExpectedTask(null, "Changing inducement")), true, USER_ADMINISTRATOR_OID, null));
            // this is step 2 in inducement part (2nd)
            instructions.add(new ApprovalInstruction(new ExpectedWorkItem(USER_BOB_OID, null, new ExpectedTask(null, "Changing inducement")), true, USER_ADMINISTRATOR_OID, null));
            // this is step 2 in main part (first step is owner that is skipped)
            instructions.add(new ApprovalInstruction(new ExpectedWorkItem(USER_JUPITER_OID, null, new ExpectedTask(null, "Adding role \"thief\"")), true, USER_ADMINISTRATOR_OID, null));
            // this is step 3 in main part
            instructions.add(new ApprovalInstruction(new ExpectedWorkItem(USER_ADMINISTRATOR_OID, null, new ExpectedTask(null, "Adding role \"thief\"")), true, USER_ADMINISTRATOR_OID, null));
            return instructions;
        }
    }, 4);
    // TODO some more asserts
    PrismObject<RoleType> thiefAfter = searchObjectByName(RoleType.class, "thief");
    roleThiefOid = thiefAfter.getOid();
    display("Thief role", thiefAfter);
    assertEquals("Wrong risk level", "high", thiefAfter.asObjectable().getRiskLevel());
    assertInducedRoles(thiefAfter, OID1, OID2);
}
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) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) IOException(java.io.IOException) ApprovalInstruction(com.evolveum.midpoint.wf.impl.ApprovalInstruction) ArrayList(java.util.ArrayList) List(java.util.List) ExpectedTask(com.evolveum.midpoint.wf.impl.ExpectedTask) Test(org.testng.annotations.Test)

Example 2 with ApprovalInstruction

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

the class TestObjectLifecycleApprovalGlobal method test710DeleteInducementsFromThief.

@Test
public void test710DeleteInducementsFromThief() throws Exception {
    login(userAdministrator);
    PrismObject<RoleType> thiefBefore = getRole(roleThiefOid);
    ObjectDelta<RoleType> captainDelta = prismContext.deltaFor(RoleType.class).item(RoleType.F_INDUCEMENT).delete(cloneCollectionMembers(thiefBefore.findContainer(RoleType.F_INDUCEMENT).getValues())).asObjectDeltaCast(roleThiefOid);
    executeTest(new TestDetails() {

        @Override
        protected LensContext createModelContext(OperationResult result) throws Exception {
            LensContext<RoleType> lensContext = createLensContext(RoleType.class);
            addFocusDeltaToContext(lensContext, captainDelta);
            return lensContext;
        }

        @Override
        protected void afterFirstClockworkRun(CaseType rootCase, CaseType case0, List<CaseType> subcases, List<CaseWorkItemType> workItems, Task opTask, OperationResult result) {
            display("subtasks", subcases);
            display("work items", workItems);
        // todo some asserts here
        }

        @Override
        protected void afterCase0Finishes(CaseType rootCase, Task opTask, OperationResult result) {
        // nothing here
        }

        @Override
        protected void afterRootCaseFinishes(CaseType rootCase, List<CaseType> subcases, Task opTask, OperationResult result) {
        // nothing here
        }

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

        @Override
        public boolean strictlySequentialApprovals() {
            return true;
        }

        @SuppressWarnings("Duplicates")
        @Override
        public List<ApprovalInstruction> getApprovalSequence() {
            List<ApprovalInstruction> instructions = new ArrayList<>();
            // this is step 1 in inducement part
            instructions.add(new ApprovalInstruction(new ExpectedWorkItem(USER_ADMINISTRATOR_OID, null, new ExpectedTask(null, "Changing inducement")), true, USER_ADMINISTRATOR_OID, null));
            // this is step 2 in inducement part
            instructions.add(new ApprovalInstruction(new ExpectedWorkItem(USER_BOB_OID, null, new ExpectedTask(null, "Changing inducement")), true, USER_ADMINISTRATOR_OID, null));
            // this is step 1 in inducement part (2nd)
            instructions.add(new ApprovalInstruction(new ExpectedWorkItem(USER_ADMINISTRATOR_OID, null, new ExpectedTask(null, "Changing inducement")), true, USER_ADMINISTRATOR_OID, null));
            // this is step 2 in inducement part (2nd)
            instructions.add(new ApprovalInstruction(new ExpectedWorkItem(USER_BOB_OID, null, new ExpectedTask(null, "Changing inducement")), true, USER_ADMINISTRATOR_OID, null));
            return instructions;
        }
    }, 2);
    // TODO some more asserts
    PrismObject<RoleType> thiefAfter = getRole(roleThiefOid);
    display("Thief role", thiefAfter);
    assertEquals("Wrong risk level", "high", thiefAfter.asObjectable().getRiskLevel());
    assertInducements(thiefAfter, 0);
}
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) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) IOException(java.io.IOException) ApprovalInstruction(com.evolveum.midpoint.wf.impl.ApprovalInstruction) ArrayList(java.util.ArrayList) List(java.util.List) ExpectedTask(com.evolveum.midpoint.wf.impl.ExpectedTask) Test(org.testng.annotations.Test)

Example 3 with ApprovalInstruction

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

the class TestObjectLifecycleApprovalGlobal method test600CreateRoleCaptain.

@Test
public void test600CreateRoleCaptain() throws Exception {
    login(userAdministrator);
    RoleType captain = new RoleType(prismContext).name("captain").description("something").riskLevel("high").inducement(createAssignmentTo(OID1, ObjectTypes.ROLE, prismContext)).inducement(createAssignmentTo(OID2, ObjectTypes.ROLE, prismContext));
    ObjectDelta<RoleType> addObjectDelta = DeltaFactory.Object.createAddDelta(captain.asPrismObject());
    executeTest(new TestDetails() {

        @Override
        protected LensContext createModelContext(OperationResult result) throws Exception {
            LensContext<RoleType> lensContext = createLensContext(RoleType.class);
            addFocusDeltaToContext(lensContext, addObjectDelta);
            lensContext.setOptions(executeOptions().executeImmediatelyAfterApproval());
            return lensContext;
        }

        @Override
        protected void afterFirstClockworkRun(CaseType rootCase, CaseType case0, List<CaseType> subcases, List<CaseWorkItemType> workItems, Task opTask, OperationResult result) {
            display("subtasks", subcases);
            display("work items", workItems);
        // todo some asserts here
        }

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

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

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

        @Override
        public boolean strictlySequentialApprovals() {
            return true;
        }

        @Override
        public List<ApprovalInstruction> getApprovalSequence() {
            List<ApprovalInstruction> instructions = new ArrayList<>();
            // this is step 2 in riskLevel part (first step is owner that is skipped)
            instructions.add(new ApprovalInstruction(new ExpectedWorkItem(USER_ADMINISTRATOR_OID, null, new ExpectedTask(null, "Setting riskLevel")), true, USER_ADMINISTRATOR_OID, null));
            // this is step 3 in riskLevel part
            instructions.add(new ApprovalInstruction(new ExpectedWorkItem(USER_PETER_OID, null, new ExpectedTask(null, "Setting riskLevel")), true, USER_ADMINISTRATOR_OID, null));
            // this is step 1 in inducement part
            instructions.add(new ApprovalInstruction(new ExpectedWorkItem(USER_ADMINISTRATOR_OID, null, new ExpectedTask(null, "Changing inducement")), true, USER_ADMINISTRATOR_OID, null));
            // this is step 2 in inducement part
            instructions.add(new ApprovalInstruction(new ExpectedWorkItem(USER_BOB_OID, null, new ExpectedTask(null, "Changing inducement")), true, USER_ADMINISTRATOR_OID, null));
            // this is step 1 in inducement part (2nd)
            instructions.add(new ApprovalInstruction(new ExpectedWorkItem(USER_ADMINISTRATOR_OID, null, new ExpectedTask(null, "Changing inducement")), true, USER_ADMINISTRATOR_OID, null));
            // this is step 2 in inducement part (2nd)
            instructions.add(new ApprovalInstruction(new ExpectedWorkItem(USER_BOB_OID, null, new ExpectedTask(null, "Changing inducement")), true, USER_ADMINISTRATOR_OID, null));
            // this is step 2 in main part (first step is owner that is skipped)
            instructions.add(new ApprovalInstruction(new ExpectedWorkItem(USER_JUPITER_OID, null, new ExpectedTask(null, "Adding role \"captain\"")), true, USER_ADMINISTRATOR_OID, null));
            // this is step 3 in main part
            instructions.add(new ApprovalInstruction(new ExpectedWorkItem(USER_ADMINISTRATOR_OID, null, new ExpectedTask(null, "Adding role \"captain\"")), true, USER_ADMINISTRATOR_OID, null));
            return instructions;
        }
    }, 4);
    // TODO some more asserts
    PrismObject<RoleType> captainAfter = searchObjectByName(RoleType.class, "captain");
    roleCaptainOid = captainAfter.getOid();
    display("Captain role", captainAfter);
    assertEquals("Wrong risk level", "high", captainAfter.asObjectable().getRiskLevel());
    assertInducedRoles(captainAfter, OID1, OID2);
}
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) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) IOException(java.io.IOException) ApprovalInstruction(com.evolveum.midpoint.wf.impl.ApprovalInstruction) ArrayList(java.util.ArrayList) List(java.util.List) ExpectedTask(com.evolveum.midpoint.wf.impl.ExpectedTask) Test(org.testng.annotations.Test)

Example 4 with ApprovalInstruction

use of com.evolveum.midpoint.wf.impl.ApprovalInstruction 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 5 with ApprovalInstruction

use of com.evolveum.midpoint.wf.impl.ApprovalInstruction 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

OperationResult (com.evolveum.midpoint.schema.result.OperationResult)10 Task (com.evolveum.midpoint.task.api.Task)10 ApprovalInstruction (com.evolveum.midpoint.wf.impl.ApprovalInstruction)10 ExpectedTask (com.evolveum.midpoint.wf.impl.ExpectedTask)10 ExpectedWorkItem (com.evolveum.midpoint.wf.impl.ExpectedWorkItem)10 LensContext (com.evolveum.midpoint.model.impl.lens.LensContext)8 List (java.util.List)8 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)7 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)7 Test (org.testng.annotations.Test)7 PrismObject (com.evolveum.midpoint.prism.PrismObject)2 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)2 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)2 PolicyViolationException (com.evolveum.midpoint.util.exception.PolicyViolationException)2 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)1 Collections.singletonList (java.util.Collections.singletonList)1