use of com.evolveum.midpoint.wf.impl.policy.ExpectedWorkItem in project midpoint by Evolveum.
the class AbstractTestAssignmentApproval method executeAssignRole1ToJack.
private void executeAssignRole1ToJack(String TEST_NAME, boolean immediate, boolean deputy, String approverOid, QName relation) throws Exception {
PrismObject<UserType> jack = getUser(userJackOid);
AssignmentType assignment = createAssignmentTo(getRoleOid(1), ObjectTypes.ROLE, prismContext);
assignment.getTargetRef().setRelation(relation);
ObjectDelta<UserType> addRole1Delta = (ObjectDelta<UserType>) DeltaBuilder.deltaFor(UserType.class, prismContext).item(UserType.F_ASSIGNMENT).add(assignment).asObjectDelta(userJackOid);
String realApproverOid = approverOid != null ? approverOid : userLead1Oid;
executeTest2(TEST_NAME, new TestDetails2<UserType>() {
@Override
protected PrismObject<UserType> getFocus(OperationResult result) throws Exception {
return jack.clone();
}
@Override
protected ObjectDelta<UserType> getFocusDelta() throws SchemaException {
return addRole1Delta.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(addRole1Delta.clone());
}
@Override
protected ObjectDelta<UserType> getExpectedDelta0() {
return ObjectDelta.createModifyDelta(jack.getOid(), Collections.emptyList(), UserType.class, prismContext);
}
@Override
protected String getObjectOid() {
return jack.getOid();
}
@Override
protected List<ExpectedTask> getExpectedTasks() {
return Collections.singletonList(new ExpectedTask(getRoleOid(1), "Assigning " + getRoleName(1) + " to jack"));
}
@Override
protected List<ExpectedWorkItem> getExpectedWorkItems() {
ExpectedTask etask = getExpectedTasks().get(0);
return Collections.singletonList(new ExpectedWorkItem(userLead1Oid, getRoleOid(1), etask));
}
@Override
protected void assertDeltaExecuted(int number, boolean yes, Task rootTask, OperationResult result) throws Exception {
if (number == 1) {
if (yes) {
assertAssignedRole(userJackOid, getRoleOid(1), rootTask, result);
checkWorkItemAuditRecords(createResultMap(getRoleOid(1), WorkflowResult.APPROVED));
checkUserApprovers(userJackOid, Collections.singletonList(realApproverOid), result);
} else {
assertNotAssignedRole(userJackOid, getRoleOid(1), rootTask, result);
}
}
}
@Override
protected Boolean decideOnApproval(String executionId, org.activiti.engine.task.Task task) throws Exception {
assertActiveWorkItems(userLead1Oid, 1);
assertActiveWorkItems(userLead1Deputy1Oid, deputy ? 1 : 0);
assertActiveWorkItems(userLead1Deputy2Oid, deputy ? 1 : 0);
checkTargetOid(executionId, getRoleOid(1));
login(getUser(realApproverOid));
return true;
}
}, 1, immediate);
}
use of com.evolveum.midpoint.wf.impl.policy.ExpectedWorkItem in project midpoint by Evolveum.
the class AbstractTestSoD method test030AssignRoleRespectable.
/**
* Assign Respectable to jack. This should trigger an approval as well (because it implies a Thief).
*/
@Test
public void test030AssignRoleRespectable() throws Exception {
final String TEST_NAME = "test030AssignRoleRespectable";
TestUtil.displayTestTile(this, TEST_NAME);
login(userAdministrator);
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
// GIVEN
unassignRole(userJackOid, rolePirateOid, task, result);
assertNotAssignedRole(userJackOid, rolePirateOid, task, result);
// WHEN+THEN
PrismObject<UserType> jack = getUser(userJackOid);
@SuppressWarnings("unchecked") ObjectDelta<UserType> addRespectableDelta = (ObjectDelta<UserType>) DeltaBuilder.deltaFor(UserType.class, prismContext).item(UserType.F_ASSIGNMENT).add(createAssignmentTo(roleRespectableOid, ObjectTypes.ROLE, prismContext)).asObjectDelta(userJackOid);
// WHEN+THEN
executeTest2(TEST_NAME, new TestDetails2<UserType>() {
@Override
protected PrismObject<UserType> getFocus(OperationResult result) throws Exception {
return jack.clone();
}
@Override
protected ObjectDelta<UserType> getFocusDelta() throws SchemaException {
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 ObjectDelta.createModifyDelta(jack.getOid(), Collections.emptyList(), UserType.class, prismContext);
}
@Override
protected String getObjectOid() {
return jack.getOid();
}
@Override
protected List<ExpectedTask> getExpectedTasks() {
return Collections.singletonList(new ExpectedTask(roleRespectableOid, "Assigning Respectable to jack"));
}
@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 rootTask, OperationResult result) throws Exception {
switch(number) {
case 1:
if (yes) {
assertAssignedRole(userJackOid, roleRespectableOid, rootTask, result);
} else {
assertNotAssignedRole(userJackOid, roleRespectableOid, rootTask, result);
}
break;
}
}
@Override
protected Boolean decideOnApproval(String executionId, org.activiti.engine.task.Task task) throws Exception {
login(getUser(userSodApproverOid));
return true;
}
}, 1, false);
// THEN
display("jack as a Judge + Respectable", getUser(userJackOid));
assertAssignedRole(userJackOid, roleJudgeOid, task, result);
assertAssignedRole(userJackOid, roleRespectableOid, task, result);
}
use of com.evolveum.midpoint.wf.impl.policy.ExpectedWorkItem in project midpoint by Evolveum.
the class TestAssignmentsWithDifferentMetaroles method executeUnassignRoles123ToJack.
private void executeUnassignRoles123ToJack(String TEST_NAME, boolean immediate, boolean approve, boolean byId, boolean has1and2) throws Exception {
PrismObject<UserType> jack = getUser(userJackOid);
AssignmentType a1 = has1and2 ? findAssignmentByTargetRequired(jack, roleRole21Oid) : null;
AssignmentType a2 = has1and2 ? findAssignmentByTargetRequired(jack, roleRole22Oid) : null;
AssignmentType a3 = findAssignmentByTargetRequired(jack, roleRole23Oid);
AssignmentType del1 = toDelete(a1, byId);
AssignmentType del2 = toDelete(a2, byId);
AssignmentType del3 = toDelete(a3, byId);
@SuppressWarnings("unchecked") ObjectDelta<UserType> deleteRole1Delta = has1and2 ? (ObjectDelta<UserType>) DeltaBuilder.deltaFor(UserType.class, prismContext).item(UserType.F_ASSIGNMENT).delete(del1).asObjectDelta(userJackOid) : null;
@SuppressWarnings("unchecked") ObjectDelta<UserType> deleteRole2Delta = has1and2 ? (ObjectDelta<UserType>) DeltaBuilder.deltaFor(UserType.class, prismContext).item(UserType.F_ASSIGNMENT).delete(del2).asObjectDelta(userJackOid) : null;
@SuppressWarnings("unchecked") ObjectDelta<UserType> deleteRole3Delta = (ObjectDelta<UserType>) DeltaBuilder.deltaFor(UserType.class, prismContext).item(UserType.F_ASSIGNMENT).delete(del3).asObjectDelta(userJackOid);
@SuppressWarnings("unchecked") ObjectDelta<UserType> changeDescriptionDelta = (ObjectDelta<UserType>) DeltaBuilder.deltaFor(UserType.class, prismContext).item(UserType.F_DESCRIPTION).replace(TEST_NAME).asObjectDelta(userJackOid);
ObjectDelta<UserType> primaryDelta = ObjectDelta.summarize(changeDescriptionDelta, deleteRole1Delta, deleteRole2Delta, deleteRole3Delta);
ObjectDelta<UserType> delta0 = ObjectDelta.summarize(changeDescriptionDelta, deleteRole1Delta, deleteRole2Delta);
String originalDescription = getUser(userJackOid).asObjectable().getDescription();
executeTest2(TEST_NAME, new TestDetails2<UserType>() {
@Override
protected PrismObject<UserType> getFocus(OperationResult result) throws Exception {
return jack.clone();
}
@Override
protected ObjectDelta<UserType> getFocusDelta() throws SchemaException {
return primaryDelta.clone();
}
@Override
protected int getNumberOfDeltasToApprove() {
return 1;
}
@Override
protected List<Boolean> getApprovals() {
return Arrays.asList(approve);
}
@Override
protected List<ObjectDelta<UserType>> getExpectedDeltasToApprove() {
return Arrays.asList(deleteRole3Delta.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(roleRole23Oid, "Unassigning Role23 from jack"));
}
// after first step
@Override
protected List<ExpectedWorkItem> getExpectedWorkItems() {
List<ExpectedTask> tasks = getExpectedTasks();
return Arrays.asList(new ExpectedWorkItem(userSecurityApproverOid, roleRole23Oid, tasks.get(0)));
}
@Override
protected void assertDeltaExecuted(int number, boolean yes, Task rootTask, OperationResult result) throws Exception {
switch(number) {
case 0:
if (yes) {
assertUserProperty(userJackOid, UserType.F_DESCRIPTION, TEST_NAME);
} else {
if (originalDescription != null) {
assertUserProperty(userJackOid, UserType.F_DESCRIPTION, originalDescription);
} else {
assertUserNoProperty(userJackOid, UserType.F_DESCRIPTION);
}
}
if (yes || !has1and2) {
assertNotAssignedRole(userJackOid, roleRole21Oid, rootTask, result);
assertNotAssignedRole(userJackOid, roleRole22Oid, rootTask, result);
} else {
assertAssignedRole(userJackOid, roleRole21Oid, rootTask, result);
assertAssignedRole(userJackOid, roleRole22Oid, rootTask, result);
}
break;
case 1:
if (yes) {
assertNotAssignedRole(userJackOid, roleRole23Oid, rootTask, result);
} else {
assertAssignedRole(userJackOid, roleRole23Oid, rootTask, result);
}
break;
default:
throw new IllegalArgumentException("Unexpected delta number: " + number);
}
}
@Override
protected Boolean decideOnApproval(String executionId, org.activiti.engine.task.Task task) throws Exception {
// 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(userSecurityApproverOid, roleRole23Oid, tasks.get(0)), approve, userSecurityApproverOid));
return instructions;
}
}, 1, immediate);
}
use of com.evolveum.midpoint.wf.impl.policy.ExpectedWorkItem in project midpoint by Evolveum.
the class TestAssignmentsWithDifferentMetaroles method executeAssignRoles123ToJack.
private void executeAssignRoles123ToJack(String TEST_NAME, boolean immediate, boolean approve1, boolean approve2, boolean approve3a, boolean approve3b, boolean securityDeputy) throws Exception {
Task task = createTask("executeAssignRoles123ToJack");
PrismObject<UserType> jack = getUser(userJackOid);
@SuppressWarnings("unchecked") ObjectDelta<UserType> addRole1Delta = (ObjectDelta<UserType>) DeltaBuilder.deltaFor(UserType.class, prismContext).item(UserType.F_ASSIGNMENT).add(createAssignmentTo(roleRole21Oid, ObjectTypes.ROLE, prismContext)).asObjectDelta(userJackOid);
@SuppressWarnings("unchecked") ObjectDelta<UserType> addRole2Delta = (ObjectDelta<UserType>) DeltaBuilder.deltaFor(UserType.class, prismContext).item(UserType.F_ASSIGNMENT).add(createAssignmentTo(roleRole22Oid, ObjectTypes.ROLE, prismContext)).asObjectDelta(userJackOid);
@SuppressWarnings("unchecked") ObjectDelta<UserType> addRole3Delta = (ObjectDelta<UserType>) DeltaBuilder.deltaFor(UserType.class, prismContext).item(UserType.F_ASSIGNMENT).add(createAssignmentTo(roleRole23Oid, ObjectTypes.ROLE, prismContext)).asObjectDelta(userJackOid);
@SuppressWarnings("unchecked") ObjectDelta<UserType> changeDescriptionDelta = (ObjectDelta<UserType>) DeltaBuilder.deltaFor(UserType.class, prismContext).item(UserType.F_DESCRIPTION).replace(TEST_NAME).asObjectDelta(userJackOid);
ObjectDelta<UserType> primaryDelta = ObjectDelta.summarize(addRole1Delta, addRole2Delta, addRole3Delta, changeDescriptionDelta);
ObjectDelta<UserType> delta0 = changeDescriptionDelta.clone();
String originalDescription = getUser(userJackOid).asObjectable().getDescription();
executeTest2(TEST_NAME, new TestDetails2<UserType>() {
@Override
protected PrismObject<UserType> getFocus(OperationResult result) throws Exception {
return jack.clone();
}
@Override
protected ObjectDelta<UserType> getFocusDelta() throws SchemaException {
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 Role21 to jack"), new ExpectedTask(roleRole22Oid, "Assigning Role22 to jack"), new ExpectedTask(roleRole23Oid, "Assigning Role23 to jack"));
}
// 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 rootTask, OperationResult result) throws Exception {
switch(number) {
case 0:
if (yes) {
assertUserProperty(userJackOid, UserType.F_DESCRIPTION, TEST_NAME);
} 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], rootTask, result);
} else {
assertNotAssignedRole(userJackOid, oids[number - 1], rootTask, result);
}
break;
}
}
@Override
protected Boolean decideOnApproval(String executionId, org.activiti.engine.task.Task task) throws Exception {
// 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));
instructions.add(new ApprovalInstruction(new ExpectedWorkItem(userLead22Oid, roleRole22Oid, tasks.get(1)), approve2, userLead22Oid));
instructions.add(new ApprovalInstruction(new ExpectedWorkItem(userLead23Oid, roleRole23Oid, tasks.get(2)), approve3a, userLead23Oid));
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, before, null));
}
return instructions;
}
}, 3, immediate);
}
use of com.evolveum.midpoint.wf.impl.policy.ExpectedWorkItem in project midpoint by Evolveum.
the class AbstractTestLifecycle method test200DeleteRolePirate.
@Test
public void test200DeleteRolePirate() throws Exception {
final String TEST_NAME = "test200DeleteRolePirate";
TestUtil.displayTestTile(this, TEST_NAME);
login(userAdministrator);
ExpectedTask expectedTask = new ExpectedTask(null, "Deletion of pirate");
ExpectedWorkItem expectedWorkItem = new ExpectedWorkItem(userPirateOwnerOid, null, expectedTask);
deleteObject(TEST_NAME, RoleType.class, rolePirateOid, false, true, userPirateOwnerOid, Collections.singletonList(expectedTask), Collections.singletonList(expectedWorkItem));
}
Aggregations