Search in sources :

Example 16 with F_ASSIGNEE_REF

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

the class AbstractWfTestPolicy method executeTest.

protected <F extends FocusType> OperationResult executeTest(TestDetails testDetails, int expectedSubTaskCount) throws Exception {
    // GIVEN
    prepareNotifications();
    dummyAuditService.clear();
    Task opTask = getTestTask();
    boolean USE_FULL_TRACING = false;
    // noinspection ConstantConditions
    if (USE_FULL_TRACING) {
        setModelAndWorkflowLoggingTracing(opTask);
    } else {
        testDetails.setTracing(opTask);
    }
    opTask.setOwner(userAdministrator);
    OperationResult result = opTask.getResult();
    LensContext<F> modelContext = testDetails.createModelContext(result);
    displayDumpable("Model context at test start", modelContext);
    // this has problems with deleting assignments by ID
    // assertFocusModificationSanity(modelContext);
    // WHEN
    HookOperationMode mode;
    clockworkMedic.enterModelMethod(true);
    try {
        mode = clockwork.run(modelContext, opTask, result);
    } finally {
        clockworkMedic.exitModelMethod(true);
    }
    // THEN
    displayDumpable("Model context after first clockwork.run", modelContext);
    assertEquals("Unexpected state of the context", ModelState.PRIMARY, modelContext.getState());
    assertEquals("Wrong mode after clockwork.run in " + modelContext.getState(), HookOperationMode.BACKGROUND, mode);
    opTask.refresh(result);
    display("Model task after first clockwork.run", opTask);
    CaseType rootCase = testHelper.getRootCase(result);
    List<CaseType> subcases = miscHelper.getSubcases(rootCase, result);
    CaseType case0 = WfTestHelper.findAndRemoveCase0(subcases);
    assertEquals("Incorrect number of subtasks", expectedSubTaskCount, subcases.size());
    final Collection<SelectorOptions<GetOperationOptions>> options1 = schemaService.getOperationOptionsBuilder().item(T_PARENT, F_OBJECT_REF).resolve().item(T_PARENT, F_TARGET_REF).resolve().item(F_ASSIGNEE_REF).resolve().item(F_ORIGINAL_ASSIGNEE_REF).resolve().item(T_PARENT, F_REQUESTOR_REF).resolve().build();
    List<CaseWorkItemType> workItems = new // to assure modifiable result list
    ArrayList<>(modelService.searchContainers(CaseWorkItemType.class, getOpenItemsQuery(), options1, opTask, result));
    displayDumpable("changes by state after first clockwork run", approvalsManager.getChangesByState(rootCase, modelInteractionService, prismContext, opTask, result));
    testDetails.afterFirstClockworkRun(rootCase, case0, subcases, workItems, opTask, result);
    if (testDetails.executeImmediately()) {
        if (case0 != null) {
            testHelper.waitForCaseClose(case0, 20000);
        }
        displayDumpable("changes by state after case0 finishes", approvalsManager.getChangesByState(rootCase, modelInteractionService, prismContext, opTask, result));
        testDetails.afterCase0Finishes(rootCase, opTask, result);
    }
    for (int i = 0; i < subcases.size(); i++) {
        CaseType subcase = subcases.get(i);
        PrismProperty<ObjectTreeDeltasType> deltas = subcase.asPrismObject().findProperty(ItemPath.create(F_APPROVAL_CONTEXT, F_DELTAS_TO_APPROVE));
        assertNotNull("There are no modifications in subcase #" + i + ": " + subcase, deltas);
        assertEquals("Incorrect number of modifications in subcase #" + i + ": " + subcase, 1, deltas.getRealValues().size());
        // todo check correctness of the modification?
        // now check the workflow state
        String caseOid = subcase.getOid();
        List<CaseWorkItemType> caseWorkItems = getWorkItemsForCase(caseOid, null, result);
        assertFalse("work item not found", caseWorkItems.isEmpty());
        for (CaseWorkItemType caseWorkItem : caseWorkItems) {
            Boolean approve = testDetails.decideOnApproval(caseWorkItem);
            if (approve != null) {
                caseManager.completeWorkItem(WorkItemId.create(caseOid, caseWorkItem.getId()), new AbstractWorkItemOutputType(prismContext).outcome(ApprovalUtils.toUri(approve)), null, opTask, result);
                login(userAdministrator);
                break;
            }
        }
    }
    // alternative way of approvals executions
    if (CollectionUtils.isNotEmpty(testDetails.getApprovalSequence())) {
        List<ApprovalInstruction> instructions = new ArrayList<>(testDetails.getApprovalSequence());
        while (!instructions.isEmpty()) {
            List<CaseWorkItemType> currentWorkItems = modelService.searchContainers(CaseWorkItemType.class, getOpenItemsQuery(), options1, opTask, result);
            boolean matched = false;
            Collection<ApprovalInstruction> instructionsToConsider = testDetails.strictlySequentialApprovals() ? singleton(instructions.get(0)) : instructions;
            main: for (ApprovalInstruction approvalInstruction : instructionsToConsider) {
                for (CaseWorkItemType workItem : currentWorkItems) {
                    if (approvalInstruction.matches(workItem)) {
                        if (approvalInstruction.beforeApproval != null) {
                            approvalInstruction.beforeApproval.run();
                        }
                        login(getUserFromRepo(approvalInstruction.approverOid));
                        System.out.println("Completing work item " + WorkItemId.of(workItem) + " using " + approvalInstruction);
                        caseManager.completeWorkItem(WorkItemId.of(workItem), new AbstractWorkItemOutputType(prismContext).outcome(ApprovalUtils.toUri(approvalInstruction.approval)).comment(approvalInstruction.comment), null, opTask, result);
                        if (approvalInstruction.afterApproval != null) {
                            approvalInstruction.afterApproval.run();
                        }
                        login(userAdministrator);
                        matched = true;
                        instructions.remove(approvalInstruction);
                        break main;
                    }
                }
            }
            if (!matched) {
                fail("None of approval instructions " + instructionsToConsider + " matched any of current work items: " + currentWorkItems);
            }
        }
    }
    CaseType rootCaseAfter = testHelper.waitForCaseClose(rootCase, 60000);
    subcases = miscHelper.getSubcases(rootCaseAfter, result);
    WfTestHelper.findAndRemoveCase0(subcases);
    displayDumpable("changes by state after root case finishes", approvalsManager.getChangesByState(rootCaseAfter, modelInteractionService, prismContext, opTask, result));
    testDetails.afterRootCaseFinishes(rootCaseAfter, subcases, opTask, result);
    notificationManager.setDisabled(true);
    // Check audit
    displayDumpable("Audit", dummyAuditService);
    displayDumpable("Output context", modelContext);
    return result;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) F_ASSIGNEE_REF(com.evolveum.midpoint.xml.ns._public.common.common_3.CaseWorkItemType.F_ASSIGNEE_REF) F_ORIGINAL_ASSIGNEE_REF(com.evolveum.midpoint.xml.ns._public.common.common_3.CaseWorkItemType.F_ORIGINAL_ASSIGNEE_REF) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) HookOperationMode(com.evolveum.midpoint.model.api.hooks.HookOperationMode) CaseType(com.evolveum.midpoint.xml.ns._public.common.common_3.CaseType) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions)

Aggregations

Session (org.hibernate.Session)12 Test (org.testng.annotations.Test)12 AccessCertificationCaseType (com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType)10 SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)4 Task (com.evolveum.midpoint.task.api.Task)4 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)3 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)3 WorkItemType (com.evolveum.midpoint.xml.ns._public.common.common_3.WorkItemType)3 HookOperationMode (com.evolveum.midpoint.model.api.hooks.HookOperationMode)2 AccessCertificationWorkItemType (com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationWorkItemType)2 ModelContext (com.evolveum.midpoint.model.api.context.ModelContext)1 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)1 CaseType (com.evolveum.midpoint.xml.ns._public.common.common_3.CaseType)1 F_ASSIGNEE_REF (com.evolveum.midpoint.xml.ns._public.common.common_3.CaseWorkItemType.F_ASSIGNEE_REF)1 F_ORIGINAL_ASSIGNEE_REF (com.evolveum.midpoint.xml.ns._public.common.common_3.CaseWorkItemType.F_ORIGINAL_ASSIGNEE_REF)1