use of com.evolveum.midpoint.xml.ns._public.common.common_3.CaseWorkItemType 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;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.CaseWorkItemType in project midpoint by Evolveum.
the class AbstractWfTestPolicy method assertWfContextAfterClockworkRun.
protected void assertWfContextAfterClockworkRun(CaseType rootCase, List<CaseType> subcases, List<CaseWorkItemType> workItems, String objectOid, List<ExpectedTask> expectedTasks, List<ExpectedWorkItem> expectedWorkItems) {
// TODO: dead code, remove 2021
// final Collection<SelectorOptions<GetOperationOptions>> options =
// SelectorOptions.createCollection(prismContext.path(F_APPROVAL_CONTEXT, F_WORK_ITEM), createRetrieve());
display("rootCase", rootCase);
assertEquals("Wrong # of wf subcases (" + expectedTasks + ")", expectedTasks.size(), subcases.size());
int i = 0;
for (CaseType subcase : subcases) {
display("Subcase #" + (i + 1) + ": ", subcase);
checkCase(subcase, subcase.toString(), expectedTasks.get(i));
WfTestUtil.assertRef("requester ref", subcase.getRequestorRef(), USER_ADMINISTRATOR_OID, false, false);
i++;
}
assertEquals("Wrong # of work items", expectedWorkItems.size(), workItems.size());
i = 0;
for (CaseWorkItemType workItem : workItems) {
display("Work item #" + (i + 1) + ": ", workItem);
display("Case", CaseWorkItemUtil.getCase(workItem));
if (objectOid != null) {
WfTestUtil.assertRef("object reference", ApprovalContextUtil.getObjectRef(workItem), objectOid, true, true);
}
String targetOid = expectedWorkItems.get(i).targetOid;
if (targetOid != null) {
WfTestUtil.assertRef("target reference", ApprovalContextUtil.getTargetRef(workItem), targetOid, true, true);
}
WfTestUtil.assertRef("assignee reference", workItem.getOriginalAssigneeRef(), expectedWorkItems.get(i).assigneeOid, false, true);
// name is not known
// WfTestUtil.assertRef("task reference", workItem.getTaskRef(), null, false, true);
final CaseType subcase = CaseWorkItemUtil.getCaseRequired(workItem);
checkCase(subcase, "subcase in workItem", expectedWorkItems.get(i).task);
WfTestUtil.assertRef("requester ref", subcase.getRequestorRef(), USER_ADMINISTRATOR_OID, false, true);
i++;
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.CaseWorkItemType in project midpoint by Evolveum.
the class TestAssignmentApprovalGlobal method test300ApprovalAndEnforce.
/**
* MID-3836
*/
public void test300ApprovalAndEnforce() throws Exception {
login(userAdministrator);
Task task = getTestTask();
task.setOwner(userAdministrator);
OperationResult result = getTestOperationResult();
try {
assignRole(userJackOid, ROLE15.oid, task, result);
fail("Unexpected success");
} catch (PolicyViolationException e) {
System.out.println("Got expected exception: " + e);
}
List<CaseWorkItemType> currentWorkItems = modelService.searchContainers(CaseWorkItemType.class, getOpenItemsQuery(), null, task, result);
display("current work items", currentWorkItems);
assertEquals("Wrong # of current work items", 0, currentWorkItems.size());
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.CaseWorkItemType in project midpoint by Evolveum.
the class TestEvents method test100CreateTask.
@Test
public void test100CreateTask() throws Exception {
login(userAdministrator);
Task task = getTestTask();
OperationResult result = getTestOperationResult();
// should start approval process
assignRole(userJackOid, roleNoApproversOid, task, result);
assertNotAssignedRole(userJackOid, roleNoApproversOid, result);
CaseWorkItemType workItem = getWorkItem(task, result);
workItemId = WorkItemId.of(workItem);
display("work item", workItem);
display("Case", CaseWorkItemUtil.getCase(workItem));
// TODO check events
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.CaseWorkItemType in project midpoint by Evolveum.
the class TestParallelApprovals method approveAllWorkItems.
public void approveAllWorkItems(Task task, OperationResult result) throws Exception {
List<CaseWorkItemType> workItems = getWorkItems(task, result);
display("work items", workItems);
display("approving work items");
for (CaseWorkItemType workItem : workItems) {
caseManager.completeWorkItem(WorkItemId.of(workItem), ApprovalUtils.createApproveOutput(prismContext), null, task, result);
}
}
Aggregations