use of com.evolveum.midpoint.model.impl.lens.LensContext in project midpoint by Evolveum.
the class TestObjectLifecycleApprovalGlobal method test710DeleteInducementsFromThief.
@Test
public void test710DeleteInducementsFromThief() throws Exception {
login(userAdministrator);
PrismObject<RoleType> thiefBefore = getRole(roleThiefOid);
ObjectDelta<RoleType> captainDelta = prismContext.deltaFor(RoleType.class).item(RoleType.F_INDUCEMENT).delete(cloneCollectionMembers(thiefBefore.findContainer(RoleType.F_INDUCEMENT).getValues())).asObjectDeltaCast(roleThiefOid);
executeTest(new TestDetails() {
@Override
protected LensContext createModelContext(OperationResult result) throws Exception {
LensContext<RoleType> lensContext = createLensContext(RoleType.class);
addFocusDeltaToContext(lensContext, captainDelta);
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 false;
}
@Override
public boolean strictlySequentialApprovals() {
return true;
}
@SuppressWarnings("Duplicates")
@Override
public List<ApprovalInstruction> getApprovalSequence() {
List<ApprovalInstruction> instructions = new ArrayList<>();
// this is step 1 in 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 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 inducement part (2nd)
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 inducement part (2nd)
instructions.add(new ApprovalInstruction(new ExpectedWorkItem(USER_BOB_OID, null, new ExpectedTask(null, "Changing inducement")), true, USER_ADMINISTRATOR_OID, null));
return instructions;
}
}, 2);
// TODO some more asserts
PrismObject<RoleType> thiefAfter = getRole(roleThiefOid);
display("Thief role", thiefAfter);
assertEquals("Wrong risk level", "high", thiefAfter.asObjectable().getRiskLevel());
assertInducements(thiefAfter, 0);
}
use of com.evolveum.midpoint.model.impl.lens.LensContext in project midpoint by Evolveum.
the class TestObjectLifecycleApprovalGlobal method test600CreateRoleCaptain.
@Test
public void test600CreateRoleCaptain() throws Exception {
login(userAdministrator);
RoleType captain = new RoleType(prismContext).name("captain").description("something").riskLevel("high").inducement(createAssignmentTo(OID1, ObjectTypes.ROLE, prismContext)).inducement(createAssignmentTo(OID2, ObjectTypes.ROLE, prismContext));
ObjectDelta<RoleType> addObjectDelta = DeltaFactory.Object.createAddDelta(captain.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(captain);
}
@Override
protected void afterRootCaseFinishes(CaseType rootCase, List<CaseType> subcases, Task opTask, OperationResult result) throws Exception {
assertObject(captain);
}
@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 1 in 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 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 inducement part (2nd)
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 inducement part (2nd)
instructions.add(new ApprovalInstruction(new ExpectedWorkItem(USER_BOB_OID, null, new ExpectedTask(null, "Changing inducement")), true, USER_ADMINISTRATOR_OID, null));
// this is step 2 in main part (first step is owner that is skipped)
instructions.add(new ApprovalInstruction(new ExpectedWorkItem(USER_JUPITER_OID, null, new ExpectedTask(null, "Adding role \"captain\"")), 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 \"captain\"")), true, USER_ADMINISTRATOR_OID, null));
return instructions;
}
}, 4);
// TODO some more asserts
PrismObject<RoleType> captainAfter = searchObjectByName(RoleType.class, "captain");
roleCaptainOid = captainAfter.getOid();
display("Captain role", captainAfter);
assertEquals("Wrong risk level", "high", captainAfter.asObjectable().getRiskLevel());
assertInducedRoles(captainAfter, OID1, OID2);
}
use of com.evolveum.midpoint.model.impl.lens.LensContext in project midpoint by Evolveum.
the class AbstractWfTestLegacy method executeTest.
protected void executeTest(String testName, String oid, TestDetails testDetails) throws Exception {
// GIVEN
prepareNotifications();
dummyAuditService.clear();
Task modelTask = taskManager.createTaskInstance(AbstractWfTestLegacy.class.getName() + "." + testName);
OperationResult result = new OperationResult("execution");
modelTask.setOwner(repositoryService.getObject(UserType.class, USER_ADMINISTRATOR_OID, null, result));
if (oid != null && testDetails.removeAssignmentsBeforeTest()) {
removeAllAssignments(oid, result);
}
LensContext<UserType> context = (LensContext<UserType>) testDetails.createModelContext(modelTask, result);
display("Input context", context);
assertFocusModificationSanity(context);
// WHEN
HookOperationMode mode = clockwork.run(context, modelTask, result);
// THEN
assertEquals("Unexpected state of the context", ModelState.PRIMARY, context.getState());
assertEquals("Wrong mode after clockwork.run in " + context.getState(), HookOperationMode.BACKGROUND, mode);
modelTask.refresh(result);
String rootTaskOid = wfTaskUtil.getRootTaskOid(modelTask);
assertNotNull("Root task OID is not set in model task", rootTaskOid);
Task rootTask = taskManager.getTask(rootTaskOid, result);
// trivial ;)
assertTrue("Root task is not persistent", rootTask.isPersistent());
if (!testDetails.approvedAutomatically()) {
UriStack uriStack = rootTask.getOtherHandlersUriStack();
if (!testDetails.immediate()) {
assertEquals("Invalid handler at stack position 0", ModelOperationTaskHandler.MODEL_OPERATION_TASK_URI, uriStack.getUriStackEntry().get(0).getHandlerUri());
} else {
assertTrue("There should be no handlers for root tasks with immediate execution mode", uriStack == null || uriStack.getUriStackEntry().isEmpty());
}
ModelContext taskModelContext = testDetails.immediate() ? null : wfTaskUtil.getModelContext(rootTask, result);
if (!testDetails.immediate()) {
assertNotNull("Model context is not present in root task", taskModelContext);
} else {
assertFalse("Model context is present in root task (execution mode = immediate)", wfTaskUtil.hasModelContext(rootTask));
}
List<Task> subtasks = rootTask.listSubtasks(result);
assertEquals("Incorrect number of subtasks", testDetails.subtaskCount(), subtasks.size());
Task task0 = extractTask0(subtasks, testDetails);
testDetails.assertsAfterClockworkRun(rootTask, subtasks, result);
if (testDetails.immediate()) {
waitForTaskClose(task0, 20000);
//TestUtil.assertSuccess(task0.getResult()); // todo enable this
testDetails.assertsAfterImmediateExecutionFinished(rootTask, result);
}
for (int i = 0; i < subtasks.size(); i++) {
Task subtask = subtasks.get(i);
//assertEquals("Subtask #" + i + " is not recurring: " + subtask, TaskRecurrence.RECURRING, subtask.getRecurrenceStatus());
//assertEquals("Incorrect execution status of subtask #" + i + ": " + subtask, TaskExecutionStatus.RUNNABLE, subtask.getExecutionStatus());
PrismProperty<ObjectTreeDeltasType> deltas = subtask.getTaskPrismObject().findProperty(new ItemPath(F_WORKFLOW_CONTEXT, F_PROCESSOR_SPECIFIC_STATE, F_DELTAS_TO_PROCESS));
assertNotNull("There are no modifications in subtask #" + i + ": " + subtask, deltas);
assertEquals("Incorrect number of modifications in subtask #" + i + ": " + subtask, 1, deltas.getRealValues().size());
// todo check correctness of the modification?
// now check the workflow state
String pid = wfTaskUtil.getProcessId(subtask);
assertNotNull("Workflow process instance id not present in subtask " + subtask, pid);
// WfProcessInstanceType processInstance = workflowServiceImpl.getProcessInstanceById(pid, false, true, result);
// assertNotNull("Process instance information cannot be retrieved", processInstance);
// assertEquals("Incorrect number of work items", 1, processInstance.getWorkItems().size());
//String taskId = processInstance.getWorkItems().get(0).getWorkItemId();
//WorkItemDetailed workItemDetailed = wfDataAccessor.getWorkItemDetailsById(taskId, result);
org.activiti.engine.task.Task t = activitiEngine.getTaskService().createTaskQuery().processInstanceId(pid).singleResult();
assertNotNull("activiti task not found", t);
String executionId = t.getExecutionId();
LOGGER.trace("Execution id = {}", executionId);
boolean approve = testDetails.decideOnApproval(executionId);
workflowManager.completeWorkItem(t.getId(), approve, null, null, null, result);
login(userAdministrator);
}
}
waitForTaskClose(rootTask, 60000);
List<Task> subtasks = rootTask.listSubtasks(result);
extractTask0(subtasks, testDetails);
//TestUtil.assertSuccess(rootTask.getResult());
testDetails.assertsRootTaskFinishes(rootTask, subtasks, result);
if (oid == null) {
oid = testDetails.getObjectOid(rootTask, result);
}
assertNotNull("object oid is null after operation", oid);
if (!oid.equals(DONT_CHECK)) {
assertObjectInTaskTree(rootTask, oid, testDetails.checkObjectOnSubtasks(), result);
}
if (!testDetails.approvedAutomatically()) {
// ZZZ temporarily disabled
// checkDummyTransportMessages("simpleWorkflowNotifier-Processes", workflowSubtaskCount * 2);
// checkDummyTransportMessages("simpleWorkflowNotifier-WorkItems", workflowSubtaskCount * 2);
}
notificationManager.setDisabled(true);
// Check audit
display("Audit", dummyAuditService);
display("Output context", context);
}
use of com.evolveum.midpoint.model.impl.lens.LensContext in project midpoint by Evolveum.
the class TestUserChangeApprovalLegacy method test040UserModifyPasswordChangeBlocked.
@Test(enabled = true)
public void test040UserModifyPasswordChangeBlocked() throws Exception {
TestUtil.displayTestTile(this, "test040UserModifyPasswordChangeBlocked");
login(userAdministrator);
PrismObject<UserType> jack = getUser(USER_JACK_OID);
final ProtectedStringType originalPasswordValue = jack.asObjectable().getCredentials().getPassword().getValue();
LOGGER.trace("password before test = " + originalPasswordValue);
executeTest("test040UserModifyPasswordChangeBlocked", USER_JACK_OID, new TestDetails() {
@Override
int subtaskCount() {
return 1;
}
@Override
boolean immediate() {
return false;
}
@Override
boolean checkObjectOnSubtasks() {
return true;
}
@Override
public LensContext createModelContext(Task task, OperationResult result) throws Exception {
LensContext<UserType> context = createUserLensContext();
fillContextWithUser(context, USER_JACK_OID, result);
encryptAndAddFocusModificationToContext(context, REQ_USER_JACK_MODIFY_CHANGE_PASSWORD);
//context.setOptions(ModelExecuteOptions.createNoCrypt());
return context;
}
@Override
public void assertsAfterClockworkRun(Task rootTask, List<Task> wfSubtasks, OperationResult result) throws Exception {
ModelContext taskModelContext = wfTaskUtil.getModelContext(rootTask, result);
assertEquals("There are modifications left in primary focus delta", 0, taskModelContext.getFocusContext().getPrimaryDelta().getModifications().size());
}
@Override
void assertsRootTaskFinishes(Task task, List<Task> subtasks, OperationResult result) throws Exception {
PrismObject<UserType> jack = getUser(USER_JACK_OID);
ProtectedStringType afterTestPasswordValue = jack.asObjectable().getCredentials().getPassword().getValue();
LOGGER.trace("password after test = " + afterTestPasswordValue);
//assertNotNull("password was not set", afterTestPasswordValue.getEncryptedData());
assertTrue("password was changed", originalPasswordValue.getEncryptedDataType().equals(afterTestPasswordValue.getEncryptedDataType()));
checkDummyTransportMessages("simpleUserNotifier", 0);
// we don't check for modifyApproverRef because in this test the value was not changed (no change was executed)
}
@Override
boolean decideOnApproval(String executionId) throws Exception {
login(getUser(USER_ADMINISTRATOR_OID));
return false;
}
});
}
use of com.evolveum.midpoint.model.impl.lens.LensContext in project midpoint by Evolveum.
the class TestUserChangeApprovalLegacy method test095UserModifyModifyResourceAssignmentConstruction.
/**
* User modification: modifying attribute of single security-sensitive resource assignment.
*
* User primary delta:
* ObjectDelta<UserType>(UserType:377205db-33d1-47e5-bf96-bbe2a7d1222e,MODIFY):
* assignment/[1]/construction/attribute
* ADD: ResourceAttributeDefinitionType(ref=ItemPathType{itemPath=lastname}...)
* DELETE: ResourceAttributeDefinitionType(ref=ItemPathType{itemPath=lastname}...)
*
*/
@Test(enabled = true)
public void test095UserModifyModifyResourceAssignmentConstruction() throws Exception {
final String TEST_NAME = "test095UserModifyModifyResourceAssignmentConstruction";
TestUtil.displayTestTile(this, TEST_NAME);
login(userAdministrator);
executeTest(TEST_NAME, USER_JACK_OID, new TestDetails() {
@Override
int subtaskCount() {
return 1;
}
@Override
boolean immediate() {
return false;
}
@Override
boolean checkObjectOnSubtasks() {
return true;
}
@Override
boolean removeAssignmentsBeforeTest() {
return false;
}
@Override
public LensContext createModelContext(Task task, OperationResult result) throws Exception {
LensContext<UserType> context = createUserLensContext();
fillContextWithUser(context, USER_JACK_OID, result);
UserType jack = context.getFocusContext().getObjectOld().asObjectable();
modifyAssignmentConstruction(context, jack, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_DRINK_NAME, "water", true);
return context;
}
@Override
public void assertsAfterClockworkRun(Task rootTask, List<Task> wfSubtasks, OperationResult result) throws Exception {
ModelContext taskModelContext = wfTaskUtil.getModelContext(rootTask, result);
assertEquals("There are modifications left in primary focus delta", 0, taskModelContext.getFocusContext().getPrimaryDelta().getModifications().size());
UserType jack = getUser(USER_JACK_OID).asObjectable();
checkNoAssignmentConstruction(jack, "drink");
}
@Override
void assertsRootTaskFinishes(Task task, List<Task> subtasks, OperationResult result) throws Exception {
assertAssignedResource(USER_JACK_OID, RESOURCE_DUMMY_OID, task, result);
UserType jack = getUser(USER_JACK_OID).asObjectable();
checkAssignmentConstruction(jack, "drink", "water");
checkDummyTransportMessages("simpleUserNotifier", 1);
//checkWorkItemAuditRecords(createResultMap(ROLE_R1_OID, WorkflowResult.APPROVED));
checkUserApprovers(USER_JACK_OID, Arrays.asList(DUMMYBOSS_OID), result);
}
@Override
boolean decideOnApproval(String executionId) throws Exception {
login(getUser(DUMMYBOSS_OID));
return true;
}
});
}
Aggregations