Search in sources :

Example 6 with ExpectedTask

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

the class AbstractTestLifecycle method test100ModifyRolePirateDescription.

@Test
public void test100ModifyRolePirateDescription() throws Exception {
    final String TEST_NAME = "test100ModifyRolePirateDescription";
    TestUtil.displayTestTile(this, TEST_NAME);
    login(userAdministrator);
    ObjectDelta<RoleType> descriptionDelta = (ObjectDelta<RoleType>) DeltaBuilder.deltaFor(RoleType.class, prismContext).item(RoleType.F_DESCRIPTION).replace("Bloody pirate").asObjectDelta(rolePirateOid);
    ObjectDelta<RoleType> delta0 = ObjectDelta.createModifyDelta(rolePirateOid, Collections.emptyList(), RoleType.class, prismContext);
    //noinspection UnnecessaryLocalVariable
    ObjectDelta<RoleType> delta1 = descriptionDelta;
    ExpectedTask expectedTask = new ExpectedTask(null, "Modification of pirate");
    ExpectedWorkItem expectedWorkItem = new ExpectedWorkItem(userPirateOwnerOid, null, expectedTask);
    modifyObject(TEST_NAME, descriptionDelta, delta0, delta1, false, true, userPirateOwnerOid, Collections.singletonList(expectedTask), Collections.singletonList(expectedWorkItem), () -> {
    }, () -> assertNull("Description is modified", getRoleSimple(rolePirateOid).getDescription()), () -> assertEquals("Description was NOT modified", "Bloody pirate", getRoleSimple(rolePirateOid).getDescription()));
}
Also used : RoleType(com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType) ExpectedWorkItem(com.evolveum.midpoint.wf.impl.policy.ExpectedWorkItem) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ExpectedTask(com.evolveum.midpoint.wf.impl.policy.ExpectedTask) Test(org.testng.annotations.Test)

Example 7 with ExpectedTask

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

the class AbstractTestSoD method test020AssignRolePirate.

/**
	 * Assign Pirate to jack. This should trigger an approval.
	 */
@Test
public void test020AssignRolePirate() throws Exception {
    final String TEST_NAME = "test020AssignRolePirate";
    TestUtil.displayTestTile(this, TEST_NAME);
    login(userAdministrator);
    Task task = createTask(TEST_NAME);
    OperationResult result = task.getResult();
    PrismObject<UserType> jack = getUser(userJackOid);
    String originalDescription = jack.asObjectable().getDescription();
    @SuppressWarnings("unchecked") ObjectDelta<UserType> addPirateDelta = (ObjectDelta<UserType>) DeltaBuilder.deltaFor(UserType.class, prismContext).item(UserType.F_ASSIGNMENT).add(createAssignmentTo(rolePirateOid, ObjectTypes.ROLE, prismContext)).asObjectDelta(userJackOid);
    @SuppressWarnings("unchecked") ObjectDelta<UserType> changeDescriptionDelta = (ObjectDelta<UserType>) DeltaBuilder.deltaFor(UserType.class, prismContext).item(UserType.F_DESCRIPTION).replace("Pirate Judge").asObjectDelta(userJackOid);
    ObjectDelta<UserType> primaryDelta = ObjectDelta.summarize(addPirateDelta, changeDescriptionDelta);
    // WHEN+THEN
    executeTest2(TEST_NAME, new TestDetails2<UserType>() {

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

        @Override
        protected ObjectDelta<UserType> getFocusDelta() throws SchemaException {
            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 Arrays.asList(addPirateDelta.clone());
        }

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

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

        @Override
        protected List<ExpectedTask> getExpectedTasks() {
            return Collections.singletonList(new ExpectedTask(rolePirateOid, "Assigning Pirate to jack"));
        }

        @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 rootTask, 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, rootTask, result);
                    } else {
                        assertNotAssignedRole(userJackOid, rolePirateOid, rootTask, result);
                    }
                    break;
            }
        }

        @Override
        protected Boolean decideOnApproval(String executionId, org.activiti.engine.task.Task task) throws Exception {
            login(getUser(userSodApproverOid));
            return true;
        }
    }, 1, false);
    // THEN
    display("jack as a Pirate + Judge", getUser(userJackOid));
    assertAssignedRole(userJackOid, roleJudgeOid, task, result);
    assertAssignedRole(userJackOid, rolePirateOid, task, result);
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpectedTask(com.evolveum.midpoint.wf.impl.policy.ExpectedTask) Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ExpectedWorkItem(com.evolveum.midpoint.wf.impl.policy.ExpectedWorkItem) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) 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.policy.ExpectedTask) Test(org.testng.annotations.Test)

Aggregations

ExpectedTask (com.evolveum.midpoint.wf.impl.policy.ExpectedTask)7 ExpectedWorkItem (com.evolveum.midpoint.wf.impl.policy.ExpectedWorkItem)7 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)6 PrismObject (com.evolveum.midpoint.prism.PrismObject)5 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)5 Task (com.evolveum.midpoint.task.api.Task)5 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)5 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)5 List (java.util.List)5 Test (org.testng.annotations.Test)4 ArrayList (java.util.ArrayList)3 ApprovalInstruction (com.evolveum.midpoint.wf.impl.policy.ApprovalInstruction)2 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)2 RoleType (com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType)1