use of com.evolveum.midpoint.wf.impl.ExpectedTask in project midpoint by Evolveum.
the class TestObjectLifecycleApprovalGlobal method test510AddInducementsToJudge.
@Test
public void test510AddInducementsToJudge() throws Exception {
login(userAdministrator);
ObjectDelta<RoleType> judgeDelta = prismContext.deltaFor(RoleType.class).item(RoleType.F_INDUCEMENT).add(createAssignmentTo(OID1, ObjectTypes.ROLE, prismContext), createAssignmentTo(OID2, ObjectTypes.ROLE, prismContext)).item(RoleType.F_DESCRIPTION).replace("hi").asObjectDeltaCast(roleJudgeOid);
executeTest(new TestDetails() {
@Override
protected LensContext createModelContext(OperationResult result) throws Exception {
LensContext<RoleType> lensContext = createLensContext(RoleType.class);
addFocusDeltaToContext(lensContext, judgeDelta);
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) {
// nothing here
}
@Override
protected void afterRootCaseFinishes(CaseType rootCase, List<CaseType> subcases, Task opTask, OperationResult result) {
// nothing here
}
@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 1 in 1st 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 1st 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 2nd 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 2nd 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 main part (owner)
instructions.add(new ApprovalInstruction(new ExpectedWorkItem(USER_JUDGE_OWNER_OID, null, new ExpectedTask(null, "Modifying role \"judge\"")), true, USER_ADMINISTRATOR_OID, null));
// this is step 2 in main part
instructions.add(new ApprovalInstruction(new ExpectedWorkItem(USER_ADMINISTRATOR_OID, null, new ExpectedTask(null, "Modifying role \"judge\"")), true, USER_ADMINISTRATOR_OID, null));
return instructions;
}
}, 3);
// TODO some more asserts
PrismObject<RoleType> judgeAfter = searchObjectByName(RoleType.class, "judge");
display("Judge role", judgeAfter);
assertEquals("Wrong risk level", "high", judgeAfter.asObjectable().getRiskLevel());
assertEquals("Wrong description", "hi", judgeAfter.asObjectable().getDescription());
assertInducedRoles(judgeAfter, OID1, OID2);
}
use of com.evolveum.midpoint.wf.impl.ExpectedTask in project midpoint by Evolveum.
the class TestObjectLifecycleApprovalGlobal method test520DeleteRoleJudge.
// MID-4372
@Test
public void test520DeleteRoleJudge() throws Exception {
login(userAdministrator);
deleteObject(UserType.class, USER_JUDGE_OWNER_OID);
ObjectDelta<RoleType> deleteDelta = prismContext.deltaFactory().object().createDeleteDelta(RoleType.class, roleJudgeOid);
executeTest(new TestDetails() {
@Override
protected LensContext createModelContext(OperationResult result) throws Exception {
LensContext<RoleType> lensContext = createLensContext(RoleType.class);
addFocusDeltaToContext(lensContext, deleteDelta);
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) {
assertObjectExists(RoleType.class, roleJudgeOid);
}
@Override
protected void afterRootCaseFinishes(CaseType rootCase, List<CaseType> subcases, Task opTask, OperationResult result) {
assertObjectDoesntExist(RoleType.class, roleJudgeOid);
}
@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 main part (first step is owner that is skipped as the owner was already deleted)
instructions.add(new ApprovalInstruction(new ExpectedWorkItem(USER_ADMINISTRATOR_OID, null, new ExpectedTask(null, "Deleting role \"judge\"")), true, USER_ADMINISTRATOR_OID, null));
return instructions;
}
}, 1);
}
use of com.evolveum.midpoint.wf.impl.ExpectedTask in project midpoint by Evolveum.
the class TestObjectLifecycleApprovalGlobal method test500CreateRoleJudge.
@Test
public void test500CreateRoleJudge() throws Exception {
login(userAdministrator);
Task task = getTestTask();
OperationResult result = getTestOperationResult();
RoleType judge = new RoleType(prismContext).name("judge").riskLevel("high");
ObjectDelta<RoleType> addObjectDelta = DeltaFactory.Object.createAddDelta(judge.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(judge);
}
@Override
protected void afterRootCaseFinishes(CaseType rootCase, List<CaseType> subcases, Task opTask, OperationResult result) throws Exception {
assertObject(judge);
}
@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 2 in main part
instructions.add(new ApprovalInstruction(new ExpectedWorkItem(USER_JUPITER_OID, null, new ExpectedTask(null, "Adding role \"judge\"")), 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 \"judge\"")), true, USER_ADMINISTRATOR_OID, null));
return instructions;
}
}, 2);
// TODO some more asserts
PrismObject<RoleType> judgeAfter = searchObjectByName(RoleType.class, "judge");
roleJudgeOid = judgeAfter.getOid();
PrismReferenceValue judgeOwner = getPrismContext().itemFactory().createReferenceValue(roleJudgeOid, RoleType.COMPLEX_TYPE);
judgeOwner.setRelation(SchemaConstants.ORG_OWNER);
executeChanges(prismContext.deltaFor(UserType.class).item(UserType.F_ASSIGNMENT).add(createAssignmentTo(judgeAfter, SchemaConstants.ORG_OWNER)).asObjectDeltaCast(USER_JUDGE_OWNER_OID), null, task, result);
display("Judge role", judgeAfter);
display("Judge owner", getUser(USER_JUDGE_OWNER_OID));
assertEquals("Wrong risk level", "high", judgeAfter.asObjectable().getRiskLevel());
}
use of com.evolveum.midpoint.wf.impl.ExpectedTask in project midpoint by Evolveum.
the class TestObjectLifecycleApprovalGlobal method test610DeleteInducementsFromCaptain.
@Test
public void test610DeleteInducementsFromCaptain() throws Exception {
login(userAdministrator);
PrismObject<RoleType> captainBefore = getRole(roleCaptainOid);
ObjectDelta<RoleType> captainDelta = prismContext.deltaFor(RoleType.class).item(RoleType.F_INDUCEMENT).delete(cloneCollectionMembers(captainBefore.findContainer(RoleType.F_INDUCEMENT).getValues())).asObjectDeltaCast(roleCaptainOid);
executeTest(new TestDetails() {
@Override
protected LensContext createModelContext(OperationResult result) throws Exception {
LensContext<RoleType> lensContext = createLensContext(RoleType.class);
addFocusDeltaToContext(lensContext, captainDelta);
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) {
// nothing here
}
@Override
protected void afterRootCaseFinishes(CaseType rootCase, List<CaseType> subcases, Task opTask, OperationResult result) {
// nothing here
}
@Override
protected boolean executeImmediately() {
return true;
}
@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> captainAfter = getRole(roleCaptainOid);
display("Captain role", captainAfter);
assertEquals("Wrong risk level", "high", captainAfter.asObjectable().getRiskLevel());
assertInducements(captainAfter, 0);
}
use of com.evolveum.midpoint.wf.impl.ExpectedTask in project midpoint by Evolveum.
the class TestAssignmentsAdvanced method executeAssignRoles123ToJack.
private void executeAssignRoles123ToJack(boolean immediate, boolean approve1, boolean approve2, boolean approve3a, boolean approve3b, boolean securityDeputy) throws Exception {
Task task = getTestTask();
String testName = getTestNameShort();
PrismObject<UserType> jack = getUser(userJackOid);
ObjectDelta<UserType> addRole1Delta = prismContext.deltaFor(UserType.class).item(UserType.F_ASSIGNMENT).add(createAssignmentTo(roleRole21Oid, ObjectTypes.ROLE, prismContext)).asObjectDelta(userJackOid);
ObjectDelta<UserType> addRole2Delta = prismContext.deltaFor(UserType.class).item(UserType.F_ASSIGNMENT).add(createAssignmentTo(roleRole22Oid, ObjectTypes.ROLE, prismContext)).asObjectDelta(userJackOid);
ObjectDelta<UserType> addRole3Delta = prismContext.deltaFor(UserType.class).item(UserType.F_ASSIGNMENT).add(createAssignmentTo(roleRole23Oid, ObjectTypes.ROLE, prismContext)).asObjectDelta(userJackOid);
ObjectDelta<UserType> changeDescriptionDelta = prismContext.deltaFor(UserType.class).item(UserType.F_DESCRIPTION).replace(testName).asObjectDelta(userJackOid);
ObjectDelta<UserType> primaryDelta = ObjectDeltaCollectionsUtil.summarize(addRole1Delta, addRole2Delta, addRole3Delta, changeDescriptionDelta);
ObjectDelta<UserType> delta0 = changeDescriptionDelta.clone();
String originalDescription = getUser(userJackOid).asObjectable().getDescription();
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 3;
}
@Override
protected List<Boolean> getApprovals() {
return Arrays.asList(approve1, approve2, approve3a && approve3b);
}
@Override
protected List<ObjectDelta<UserType>> getExpectedDeltasToApprove() {
return Arrays.asList(addRole1Delta.clone(), addRole2Delta.clone(), addRole3Delta.clone());
}
@Override
protected ObjectDelta<UserType> getExpectedDelta0() {
return delta0.clone();
}
@Override
protected String getObjectOid() {
return jack.getOid();
}
@Override
protected List<ExpectedTask> getExpectedTasks() {
return Arrays.asList(new ExpectedTask(roleRole21Oid, "Assigning role \"Role21\" to user \"Jack Sparrow\""), new ExpectedTask(roleRole22Oid, "Assigning role \"Role22\" to user \"Jack Sparrow\""), new ExpectedTask(roleRole23Oid, "Assigning role \"Role23\" to user \"Jack Sparrow\""));
}
// after first step
@Override
protected List<ExpectedWorkItem> getExpectedWorkItems() {
List<ExpectedTask> tasks = getExpectedTasks();
return Arrays.asList(new ExpectedWorkItem(userLead21Oid, roleRole21Oid, tasks.get(0)), new ExpectedWorkItem(userLead22Oid, roleRole22Oid, tasks.get(1)), new ExpectedWorkItem(userLead23Oid, roleRole23Oid, tasks.get(2)));
}
@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, testName);
} else {
if (originalDescription != null) {
assertUserProperty(userJackOid, UserType.F_DESCRIPTION, originalDescription);
} else {
assertUserNoProperty(userJackOid, UserType.F_DESCRIPTION);
}
}
break;
case 1:
case 2:
case 3:
String[] oids = { roleRole21Oid, roleRole22Oid, roleRole23Oid };
if (yes) {
assertAssignedRole(userJackOid, oids[number - 1], result);
} else {
assertNotAssignedRole(userJackOid, oids[number - 1], result);
}
break;
}
}
@Override
protected Boolean decideOnApproval(CaseWorkItemType caseWorkItem) {
// ignore this way of approving
return null;
}
@Override
public List<ApprovalInstruction> getApprovalSequence() {
List<ExpectedTask> tasks = getExpectedTasks();
List<ApprovalInstruction> instructions = new ArrayList<>();
instructions.add(new ApprovalInstruction(new ExpectedWorkItem(userLead21Oid, roleRole21Oid, tasks.get(0)), approve1, userLead21Oid, null));
instructions.add(new ApprovalInstruction(new ExpectedWorkItem(userLead22Oid, roleRole22Oid, tasks.get(1)), approve2, userLead22Oid, null));
instructions.add(new ApprovalInstruction(new ExpectedWorkItem(userLead23Oid, roleRole23Oid, tasks.get(2)), approve3a, userLead23Oid, null));
if (approve3a) {
ExpectedWorkItem expectedWorkItem = new ExpectedWorkItem(userSecurityApproverOid, roleRole23Oid, tasks.get(2));
ApprovalInstruction.CheckedRunnable before = () -> {
login(getUserFromRepo(userSecurityApproverOid));
checkVisibleWorkItem(expectedWorkItem, 1, task, task.getResult());
login(getUserFromRepo(userSecurityApproverDeputyOid));
checkVisibleWorkItem(expectedWorkItem, 1, task, task.getResult());
login(getUserFromRepo(userSecurityApproverDeputyLimitedOid));
checkVisibleWorkItem(null, 0, task, task.getResult());
};
instructions.add(new ApprovalInstruction(expectedWorkItem, approve3b, securityDeputy ? userSecurityApproverDeputyOid : userSecurityApproverOid, null, before, null));
}
return instructions;
}
}, 3, immediate);
}
Aggregations