use of com.evolveum.midpoint.wf.impl.ExpectedWorkItem 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.wf.impl.ExpectedWorkItem 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);
}
use of com.evolveum.midpoint.wf.impl.ExpectedWorkItem 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);
}
use of com.evolveum.midpoint.wf.impl.ExpectedWorkItem 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);
}
use of com.evolveum.midpoint.wf.impl.ExpectedWorkItem in project midpoint by Evolveum.
the class AbstractTestObjectLifecycleApproval method createObject.
private void createObject(ObjectType object, boolean immediate, boolean approve, String assigneeOid) throws Exception {
// noinspection unchecked
ObjectDelta<RoleType> addObjectDelta = DeltaFactory.Object.createAddDelta((PrismObject<RoleType>) object.asPrismObject());
executeTest(new TestDetails() {
@Override
protected LensContext createModelContext(OperationResult result) throws Exception {
// noinspection unchecked
LensContext<RoleType> lensContext = createLensContext((Class) object.getClass());
addFocusDeltaToContext(lensContext, addObjectDelta);
return lensContext;
}
@Override
protected void afterFirstClockworkRun(CaseType rootCase, CaseType case0, List<CaseType> subcases, List<CaseWorkItemType> workItems, Task opTask, OperationResult result) throws Exception {
if (!immediate) {
// ModelContext taskModelContext = temporaryHelper.getModelContext(rootCase, opTask, result);
// ObjectDelta realDelta0 = taskModelContext.getFocusContext().getPrimaryDelta();
// assertTrue("Non-empty primary focus delta: " + realDelta0.debugDump(), realDelta0.isEmpty());
assertNoObject(object);
ExpectedTask expectedTask = new ExpectedTask(null, "Adding role \"" + object.getName().getOrig() + "\"");
ExpectedWorkItem expectedWorkItem = new ExpectedWorkItem(assigneeOid, null, expectedTask);
assertWfContextAfterClockworkRun(rootCase, subcases, workItems, null, Collections.singletonList(expectedTask), Collections.singletonList(expectedWorkItem));
}
}
@Override
protected void afterCase0Finishes(CaseType rootCase, Task opTask, OperationResult result) throws Exception {
assertNoObject(object);
}
@Override
protected void afterRootCaseFinishes(CaseType rootCase, List<CaseType> subcases, Task opTask, OperationResult result) throws Exception {
if (approve) {
assertObject(object);
} else {
assertNoObject(object);
}
}
@Override
protected boolean executeImmediately() {
return immediate;
}
@Override
public List<ApprovalInstruction> getApprovalSequence() {
return singletonList(new ApprovalInstruction(null, true, USER_JUPITER_OID, "creation comment"));
}
}, 1);
}
Aggregations