Search in sources :

Example 6 with CaseWorkItemType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.CaseWorkItemType in project midpoint by Evolveum.

the class ManualResourceTest method test110CloseCaseAndRecomputeWill.

/**
 * Case is closed. The operation is complete.
 */
@Test
public void test110CloseCaseAndRecomputeWill() throws Exception {
    // GIVEN
    Task task = getTestTask();
    OperationResult result = getTestOperationResult();
    dummyAuditService.clear();
    dummyTransport.clearMessages();
    // WHEN
    when();
    CaseType caseBefore = getCase(willLastCaseOid);
    display("Case before work item completion", caseBefore);
    List<CaseWorkItemType> workItems = caseBefore.getWorkItem();
    assertEquals("Wrong # of work items", 2, workItems.size());
    assertEquals("Wrong assignees", new HashSet<>(Arrays.asList(USER_ADMINISTRATOR_OID, userJackOid)), workItems.stream().map(wi -> wi.getOriginalAssigneeRef().getOid()).collect(Collectors.toSet()));
    Optional<CaseWorkItemType> adminWorkItem = workItems.stream().filter(wi -> USER_ADMINISTRATOR_OID.equals(wi.getOriginalAssigneeRef().getOid())).findAny();
    assertTrue("no admin work item", adminWorkItem.isPresent());
    caseManager.completeWorkItem(WorkItemId.of(adminWorkItem.get()), new AbstractWorkItemOutputType(prismContext).outcome(OperationResultStatusType.SUCCESS.value()), null, task, result);
    accountWillCompletionTimestampStart = clock.currentTimeXMLGregorianCalendar();
    // We need reconcile and not recompute here. We need to fetch the updated case status.
    reconcileUser(userWillOid, task, result);
    // THEN
    then();
    assertSuccess(result);
    CaseType caseAfter = getCase(willLastCaseOid);
    display("Case after work item completion", caseAfter);
    accountWillCompletionTimestampEnd = clock.currentTimeXMLGregorianCalendar();
    assertWillAfterCreateCaseClosed();
    displayDumpable("dummy audit", dummyAuditService);
    displayDumpable("dummy transport", dummyTransport);
}
Also used : DirtiesContext(org.springframework.test.annotation.DirtiesContext) AssertJUnit(org.testng.AssertJUnit) Arrays(java.util.Arrays) Listeners(org.testng.annotations.Listeners) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Test(org.testng.annotations.Test) ShadowAsserter(com.evolveum.midpoint.test.asserter.ShadowAsserter) InternalsConfig(com.evolveum.midpoint.schema.internals.InternalsConfig) AbstractWfTest(com.evolveum.midpoint.wf.impl.AbstractWfTest) HashSet(java.util.HashSet) IntegrationTestTools(com.evolveum.midpoint.test.IntegrationTestTools) TestUtil(com.evolveum.midpoint.test.util.TestUtil) ClassMode(org.springframework.test.annotation.DirtiesContext.ClassMode) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) PrismObject(com.evolveum.midpoint.prism.PrismObject) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Task(com.evolveum.midpoint.task.api.Task) Collectors(java.util.stream.Collectors) File(java.io.File) WorkItemId(com.evolveum.midpoint.schema.util.WorkItemId) List(java.util.List) MidPointConstants(com.evolveum.midpoint.schema.constants.MidPointConstants) ContextConfiguration(org.springframework.test.context.ContextConfiguration) Optional(java.util.Optional) QName(javax.xml.namespace.QName) Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test) AbstractWfTest(com.evolveum.midpoint.wf.impl.AbstractWfTest)

Example 7 with CaseWorkItemType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.CaseWorkItemType 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 CaseWorkItemType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.CaseWorkItemType 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 CaseWorkItemType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.CaseWorkItemType in project midpoint by Evolveum.

the class RCase method copyFromJAXB.

// dynamically called
public static void copyFromJAXB(CaseType jaxb, RCase repo, RepositoryContext context, IdGeneratorResult generatorResult) throws DtoTranslationException {
    copyAssignmentHolderInformationFromJAXB(jaxb, repo, context, generatorResult);
    repo.setNameCopy(RPolyString.copyFromJAXB(jaxb.getName()));
    repo.setParentRef(RUtil.jaxbRefToEmbeddedRepoRef(jaxb.getParentRef(), context.relationRegistry));
    repo.setObjectRef(RUtil.jaxbRefToEmbeddedRepoRef(jaxb.getObjectRef(), context.relationRegistry));
    repo.setTargetRef(RUtil.jaxbRefToEmbeddedRepoRef(jaxb.getTargetRef(), context.relationRegistry));
    repo.setRequestorRef(RUtil.jaxbRefToEmbeddedRepoRef(jaxb.getRequestorRef(), context.relationRegistry));
    repo.setCloseTimestamp(jaxb.getCloseTimestamp());
    repo.setState(jaxb.getState());
    for (CaseWorkItemType workItem : jaxb.getWorkItem()) {
        repo.getWorkItems().add(RCaseWorkItem.toRepo(repo, workItem, context));
    }
}
Also used : CaseWorkItemType(com.evolveum.midpoint.xml.ns._public.common.common_3.CaseWorkItemType)

Example 10 with CaseWorkItemType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.CaseWorkItemType in project midpoint by Evolveum.

the class AbstractManualResourceTest method test231CaseHasExpectedNumbersOfWorkItemsWithExpectedAssignees.

// This no longer works as the work item creation is now done in cases-impl module
@Test(enabled = false)
public void test231CaseHasExpectedNumbersOfWorkItemsWithExpectedAssignees() throws Exception {
    // GIVEN
    Task task = getTestTask();
    OperationResult result = task.getResult();
    syncServiceMock.reset();
    int expectedNumberOfWorkItems = 3;
    List<String> expectedWorkItemsAssigneesOids = Stream.of(USER_OPERATOR_ROLE_MEMBER_OID, USER_OPERATOR_OID, USER_OPERATOR_ORG_MEMBER_OID).sorted(String::compareToIgnoreCase).collect(Collectors.toList());
    CaseType caseType = repositoryService.getObject(CaseType.class, willLastCaseOid, null, result).asObjectable();
    List<String> actualWorkItemsAssigneesOids = caseType.getWorkItem().stream().flatMap(caseWorkItemType -> caseWorkItemType.getAssigneeRef().stream()).map(ObjectReferenceType::getOid).sorted(String::compareToIgnoreCase).collect(Collectors.toList());
    int actualNumberOfWorkItems = caseType.getWorkItem().size();
    assertEquals(expectedNumberOfWorkItems, actualNumberOfWorkItems);
    assertEquals(expectedWorkItemsAssigneesOids, actualWorkItemsAssigneesOids);
}
Also used : DirtiesContext(org.springframework.test.annotation.DirtiesContext) ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) AssertJUnit(org.testng.AssertJUnit) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) ActivationCapabilityType(com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ActivationCapabilityType) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test) ShadowAsserter(com.evolveum.midpoint.test.asserter.ShadowAsserter) InternalsConfig(com.evolveum.midpoint.schema.internals.InternalsConfig) PrismTestUtil(com.evolveum.midpoint.prism.util.PrismTestUtil) ObjectTypeUtil(com.evolveum.midpoint.schema.util.ObjectTypeUtil) CapabilityUtil(com.evolveum.midpoint.schema.CapabilityUtil) IntegrationTestTools(com.evolveum.midpoint.test.IntegrationTestTools) TestUtil(com.evolveum.midpoint.test.util.TestUtil) AbstractProvisioningIntegrationTest(com.evolveum.midpoint.provisioning.impl.AbstractProvisioningIntegrationTest) ItemDeltaType(com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType) com.evolveum.midpoint.prism(com.evolveum.midpoint.prism) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) Collection(java.util.Collection) IOException(java.io.IOException) ResourceTypeUtil(com.evolveum.midpoint.schema.util.ResourceTypeUtil) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Task(com.evolveum.midpoint.task.api.Task) Collectors(java.util.stream.Collectors) File(java.io.File) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) List(java.util.List) Stream(java.util.stream.Stream) com.evolveum.midpoint.schema.processor(com.evolveum.midpoint.schema.processor) Element(org.w3c.dom.Element) ItemName(com.evolveum.midpoint.prism.path.ItemName) PrismObjectAsserter(com.evolveum.midpoint.test.asserter.prism.PrismObjectAsserter) ReadCapabilityType(com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ReadCapabilityType) MidPointConstants(com.evolveum.midpoint.schema.constants.MidPointConstants) ContextConfiguration(org.springframework.test.context.ContextConfiguration) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) AbstractWriteCapabilityType(com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.AbstractWriteCapabilityType) QName(javax.xml.namespace.QName) PointInTimeType(com.evolveum.midpoint.schema.PointInTimeType) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) CreateCapabilityType(com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.CreateCapabilityType) Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test) AbstractProvisioningIntegrationTest(com.evolveum.midpoint.provisioning.impl.AbstractProvisioningIntegrationTest)

Aggregations

CaseWorkItemType (com.evolveum.midpoint.xml.ns._public.common.common_3.CaseWorkItemType)16 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)13 Task (com.evolveum.midpoint.task.api.Task)11 List (java.util.List)8 Test (org.testng.annotations.Test)8 PrismObject (com.evolveum.midpoint.prism.PrismObject)7 com.evolveum.midpoint.xml.ns._public.common.common_3 (com.evolveum.midpoint.xml.ns._public.common.common_3)6 CaseType (com.evolveum.midpoint.xml.ns._public.common.common_3.CaseType)6 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)5 SchemaConstants (com.evolveum.midpoint.schema.constants.SchemaConstants)5 Collectors (java.util.stream.Collectors)5 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)5 QName (javax.xml.namespace.QName)4 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)3 File (java.io.File)3 Collection (java.util.Collection)3 NotNull (org.jetbrains.annotations.NotNull)3 DirtiesContext (org.springframework.test.annotation.DirtiesContext)3 ContextConfiguration (org.springframework.test.context.ContextConfiguration)3 CaseEngineOperation (com.evolveum.midpoint.cases.api.CaseEngineOperation)2