use of com.evolveum.midpoint.wf.impl.policy.ExpectedTask in project midpoint by Evolveum.
the class AbstractTestLifecycle method test100ModifyRolePirateDescription.
@Test
public void test100ModifyRolePirateDescription() throws Exception {
final String TEST_NAME = "test100ModifyRolePirateDescription";
TestUtil.displayTestTile(this, TEST_NAME);
login(userAdministrator);
ObjectDelta<RoleType> descriptionDelta = (ObjectDelta<RoleType>) DeltaBuilder.deltaFor(RoleType.class, prismContext).item(RoleType.F_DESCRIPTION).replace("Bloody pirate").asObjectDelta(rolePirateOid);
ObjectDelta<RoleType> delta0 = ObjectDelta.createModifyDelta(rolePirateOid, Collections.emptyList(), RoleType.class, prismContext);
//noinspection UnnecessaryLocalVariable
ObjectDelta<RoleType> delta1 = descriptionDelta;
ExpectedTask expectedTask = new ExpectedTask(null, "Modification of pirate");
ExpectedWorkItem expectedWorkItem = new ExpectedWorkItem(userPirateOwnerOid, null, expectedTask);
modifyObject(TEST_NAME, descriptionDelta, delta0, delta1, false, true, userPirateOwnerOid, Collections.singletonList(expectedTask), Collections.singletonList(expectedWorkItem), () -> {
}, () -> assertNull("Description is modified", getRoleSimple(rolePirateOid).getDescription()), () -> assertEquals("Description was NOT modified", "Bloody pirate", getRoleSimple(rolePirateOid).getDescription()));
}
use of com.evolveum.midpoint.wf.impl.policy.ExpectedTask in project midpoint by Evolveum.
the class AbstractTestSoD method test020AssignRolePirate.
/**
* Assign Pirate to jack. This should trigger an approval.
*/
@Test
public void test020AssignRolePirate() throws Exception {
final String TEST_NAME = "test020AssignRolePirate";
TestUtil.displayTestTile(this, TEST_NAME);
login(userAdministrator);
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
PrismObject<UserType> jack = getUser(userJackOid);
String originalDescription = jack.asObjectable().getDescription();
@SuppressWarnings("unchecked") ObjectDelta<UserType> addPirateDelta = (ObjectDelta<UserType>) DeltaBuilder.deltaFor(UserType.class, prismContext).item(UserType.F_ASSIGNMENT).add(createAssignmentTo(rolePirateOid, ObjectTypes.ROLE, prismContext)).asObjectDelta(userJackOid);
@SuppressWarnings("unchecked") ObjectDelta<UserType> changeDescriptionDelta = (ObjectDelta<UserType>) DeltaBuilder.deltaFor(UserType.class, prismContext).item(UserType.F_DESCRIPTION).replace("Pirate Judge").asObjectDelta(userJackOid);
ObjectDelta<UserType> primaryDelta = ObjectDelta.summarize(addPirateDelta, changeDescriptionDelta);
// 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 primaryDelta.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(addPirateDelta.clone());
}
@Override
protected ObjectDelta<UserType> getExpectedDelta0() {
//return ObjectDelta.createModifyDelta(jack.getOid(), Collections.emptyList(), UserType.class, prismContext);
return changeDescriptionDelta.clone();
}
@Override
protected String getObjectOid() {
return jack.getOid();
}
@Override
protected List<ExpectedTask> getExpectedTasks() {
return Collections.singletonList(new ExpectedTask(rolePirateOid, "Assigning Pirate to jack"));
}
@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 rootTask, 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, rootTask, result);
} else {
assertNotAssignedRole(userJackOid, rolePirateOid, 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 Pirate + Judge", getUser(userJackOid));
assertAssignedRole(userJackOid, roleJudgeOid, task, result);
assertAssignedRole(userJackOid, rolePirateOid, task, result);
}
Aggregations