Search in sources :

Example 11 with ExpectedWorkItem

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

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

the class TestObjectLifecycleAdvanced method test045ActivateCompleteRole.

@Test
public void test045ActivateCompleteRole() throws Exception {
    login(userAdministrator);
    ObjectDelta<RoleType> activateRoleDelta = prismContext.deltaFor(RoleType.class).item(RoleType.F_LIFECYCLE_STATE).replace(SchemaConstants.LIFECYCLE_ACTIVE).item(RoleType.F_DESCRIPTION).replace("hi").asObjectDelta(roleEmployeeOid);
    executeTest(new TestDetails() {

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

        @Override
        protected void afterFirstClockworkRun(CaseType rootCase, CaseType case0, List<CaseType> subcases, List<CaseWorkItemType> workItems, Task opTask, OperationResult result) throws Exception {
            ExpectedTask expectedTask = new ExpectedTask(null, "Matching state: after operation (\"active lifecycleState\")");
            ExpectedWorkItem expectedWorkItem = new ExpectedWorkItem(userEmployeeOwnerOid, null, expectedTask);
            assertWfContextAfterClockworkRun(rootCase, subcases, workItems, null, Collections.singletonList(expectedTask), Collections.singletonList(expectedWorkItem));
            ApprovalContextType wfc = subcases.get(0).getApprovalContext();
            assertEquals("Wrong # of attached policy rules entries", 1, wfc.getPolicyRules().getEntry().size());
            SchemaAttachedPolicyRuleType attachedRule = wfc.getPolicyRules().getEntry().get(0);
            assertEquals(1, attachedRule.getStageMin().intValue());
            assertEquals(1, attachedRule.getStageMax().intValue());
            assertEquals("Wrong # of attached triggers", 1, attachedRule.getRule().getTrigger().size());
            EvaluatedPolicyRuleTriggerType trigger = attachedRule.getRule().getTrigger().get(0);
            assertEquals("Wrong constraintKind in trigger", PolicyConstraintKindType.TRANSITION, trigger.getConstraintKind());
            CaseWorkItemType workItem = subcases.get(0).getWorkItem().get(0);
            assertEquals("Wrong # of additional information", 0, workItem.getAdditionalInformation().size());
        }

        @Override
        protected void afterCase0Finishes(CaseType rootCase, Task opTask, OperationResult result) {
        // assertNoObject(employee);
        }

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

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

        @Override
        protected Boolean decideOnApproval(CaseWorkItemType caseWorkItem) throws Exception {
            login(getUser(userEmployeeOwnerOid));
            return true;
        }
    }, 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) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException) ExpectedTask(com.evolveum.midpoint.wf.impl.ExpectedTask) Test(org.testng.annotations.Test)

Example 13 with ExpectedWorkItem

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

the class TestObjectLifecycleApprovalGlobal method test510AddInducementsToJudge.

@Test
public void test510AddInducementsToJudge() throws Exception {
    login(userAdministrator);
    ObjectDelta<RoleType> judgeDelta = prismContext.deltaFor(RoleType.class).item(RoleType.F_INDUCEMENT).add(createAssignmentTo(OID1, ObjectTypes.ROLE, prismContext), createAssignmentTo(OID2, ObjectTypes.ROLE, prismContext)).item(RoleType.F_DESCRIPTION).replace("hi").asObjectDeltaCast(roleJudgeOid);
    executeTest(new TestDetails() {

        @Override
        protected LensContext createModelContext(OperationResult result) throws Exception {
            LensContext<RoleType> lensContext = createLensContext(RoleType.class);
            addFocusDeltaToContext(lensContext, judgeDelta);
            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) {
        // nothing here
        }

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

        @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 1 in 1st 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 1st 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 2nd 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 2nd 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 main part (owner)
            instructions.add(new ApprovalInstruction(new ExpectedWorkItem(USER_JUDGE_OWNER_OID, null, new ExpectedTask(null, "Modifying role \"judge\"")), true, USER_ADMINISTRATOR_OID, null));
            // this is step 2 in main part
            instructions.add(new ApprovalInstruction(new ExpectedWorkItem(USER_ADMINISTRATOR_OID, null, new ExpectedTask(null, "Modifying role \"judge\"")), true, USER_ADMINISTRATOR_OID, null));
            return instructions;
        }
    }, 3);
    // TODO some more asserts
    PrismObject<RoleType> judgeAfter = searchObjectByName(RoleType.class, "judge");
    display("Judge role", judgeAfter);
    assertEquals("Wrong risk level", "high", judgeAfter.asObjectable().getRiskLevel());
    assertEquals("Wrong description", "hi", judgeAfter.asObjectable().getDescription());
    assertInducedRoles(judgeAfter, 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 14 with ExpectedWorkItem

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

the class TestObjectLifecycleApprovalGlobal method test520DeleteRoleJudge.

// MID-4372
@Test
public void test520DeleteRoleJudge() throws Exception {
    login(userAdministrator);
    deleteObject(UserType.class, USER_JUDGE_OWNER_OID);
    ObjectDelta<RoleType> deleteDelta = prismContext.deltaFactory().object().createDeleteDelta(RoleType.class, roleJudgeOid);
    executeTest(new TestDetails() {

        @Override
        protected LensContext createModelContext(OperationResult result) throws Exception {
            LensContext<RoleType> lensContext = createLensContext(RoleType.class);
            addFocusDeltaToContext(lensContext, deleteDelta);
            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) {
            assertObjectExists(RoleType.class, roleJudgeOid);
        }

        @Override
        protected void afterRootCaseFinishes(CaseType rootCase, List<CaseType> subcases, Task opTask, OperationResult result) {
            assertObjectDoesntExist(RoleType.class, roleJudgeOid);
        }

        @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 main part (first step is owner that is skipped as the owner was already deleted)
            instructions.add(new ApprovalInstruction(new ExpectedWorkItem(USER_ADMINISTRATOR_OID, null, new ExpectedTask(null, "Deleting role \"judge\"")), true, USER_ADMINISTRATOR_OID, null));
            return instructions;
        }
    }, 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) 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 15 with ExpectedWorkItem

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

the class TestObjectLifecycleApprovalGlobal method test500CreateRoleJudge.

@Test
public void test500CreateRoleJudge() throws Exception {
    login(userAdministrator);
    Task task = getTestTask();
    OperationResult result = getTestOperationResult();
    RoleType judge = new RoleType(prismContext).name("judge").riskLevel("high");
    ObjectDelta<RoleType> addObjectDelta = DeltaFactory.Object.createAddDelta(judge.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(judge);
        }

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

        @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 2 in main part
            instructions.add(new ApprovalInstruction(new ExpectedWorkItem(USER_JUPITER_OID, null, new ExpectedTask(null, "Adding role \"judge\"")), 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 \"judge\"")), true, USER_ADMINISTRATOR_OID, null));
            return instructions;
        }
    }, 2);
    // TODO some more asserts
    PrismObject<RoleType> judgeAfter = searchObjectByName(RoleType.class, "judge");
    roleJudgeOid = judgeAfter.getOid();
    PrismReferenceValue judgeOwner = getPrismContext().itemFactory().createReferenceValue(roleJudgeOid, RoleType.COMPLEX_TYPE);
    judgeOwner.setRelation(SchemaConstants.ORG_OWNER);
    executeChanges(prismContext.deltaFor(UserType.class).item(UserType.F_ASSIGNMENT).add(createAssignmentTo(judgeAfter, SchemaConstants.ORG_OWNER)).asObjectDeltaCast(USER_JUDGE_OWNER_OID), null, task, result);
    display("Judge role", judgeAfter);
    display("Judge owner", getUser(USER_JUDGE_OWNER_OID));
    assertEquals("Wrong risk level", "high", judgeAfter.asObjectable().getRiskLevel());
}
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) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) 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)

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