use of com.evolveum.midpoint.wf.impl.ExpectedWorkItem in project midpoint by Evolveum.
the class TestObjectLifecycleAdvanced method test010CreateRoleEmployee.
@Test
public void test010CreateRoleEmployee() throws Exception {
login(userAdministrator);
Task task = getTestTask();
OperationResult result = getTestOperationResult();
PrismObject<RoleType> employee = prismContext.parseObject(ROLE_EMPLOYEE_FILE);
executeTest(new TestDetails() {
@Override
protected LensContext createModelContext(OperationResult result) throws Exception {
LensContext<RoleType> lensContext = createLensContext(RoleType.class);
addFocusDeltaToContext(lensContext, DeltaFactory.Object.createAddDelta(employee));
return lensContext;
}
@Override
protected void afterFirstClockworkRun(CaseType rootCase, CaseType case0, List<CaseType> subcases, List<CaseWorkItemType> workItems, Task opTask, OperationResult result) throws Exception {
// ModelContext taskModelContext = temporaryHelper.getModelContext(rootCase, opTask, result);
// ObjectDelta realDelta0 = taskModelContext.getFocusContext().getPrimaryDelta();
// assertTrue("Non-empty primary focus delta: " + realDelta0.debugDump(), realDelta0.isEmpty());
assertNoObject(employee);
ExpectedTask expectedTask = new ExpectedTask(null, "Adding role \"" + employee.asObjectable().getName().getOrig() + "\"");
ExpectedWorkItem expectedWorkItem = new ExpectedWorkItem(userEmployeeOwnerOid, null, expectedTask);
assertWfContextAfterClockworkRun(rootCase, subcases, workItems, null, Collections.singletonList(expectedTask), Collections.singletonList(expectedWorkItem));
CaseType subcase = subcases.get(0);
ApprovalContextType wfc = subcase.getApprovalContext();
assertEquals("Wrong # of attached policy rules entries", 1, wfc.getPolicyRules().getEntry().size());
SchemaAttachedPolicyRuleType attachedRule = wfc.getPolicyRules().getEntry().get(0);
assertEquals(1, attachedRule.getStageMin().intValue());
assertEquals(1, attachedRule.getStageMax().intValue());
assertEquals("Wrong # of attached triggers", 1, attachedRule.getRule().getTrigger().size());
EvaluatedPolicyRuleTriggerType trigger = attachedRule.getRule().getTrigger().get(0);
assertEquals("Wrong constraintKind in trigger", PolicyConstraintKindType.OBJECT_MODIFICATION, trigger.getConstraintKind());
CaseWorkItemType workItem = subcases.get(0).getWorkItem().get(0);
assertEquals("Wrong # of additional information", 0, workItem.getAdditionalInformation().size());
}
@Override
protected void afterCase0Finishes(CaseType rootCase, Task opTask, OperationResult result) throws Exception {
assertNoObject(employee);
}
@Override
protected void afterRootCaseFinishes(CaseType rootCase, List<CaseType> subcases, Task opTask, OperationResult result) {
new PrismObjectAsserter<>(employee).assertSanity();
}
@Override
protected boolean executeImmediately() {
return false;
}
@Override
protected Boolean decideOnApproval(CaseWorkItemType caseWorkItem) throws Exception {
login(getUser(userEmployeeOwnerOid));
return true;
}
}, 1);
roleEmployeeOid = searchObjectByName(RoleType.class, "employee").getOid();
PrismReferenceValue employeeOwner = getPrismContext().itemFactory().createReferenceValue(roleEmployeeOid, RoleType.COMPLEX_TYPE).relation(SchemaConstants.ORG_OWNER);
executeChanges(prismContext.deltaFor(UserType.class).item(UserType.F_ASSIGNMENT).add(ObjectTypeUtil.createAssignmentTo(employeeOwner, prismContext)).asObjectDelta(userEmployeeOwnerOid), null, task, result);
display("Employee role", getRole(roleEmployeeOid));
display("Employee owner", getUser(userEmployeeOwnerOid));
}
use of com.evolveum.midpoint.wf.impl.ExpectedWorkItem in project midpoint by Evolveum.
the class AbstractTestObjectLifecycleApproval method test200DeleteRolePirate.
@Test
public void test200DeleteRolePirate() throws Exception {
login(userAdministrator);
ExpectedTask expectedTask = new ExpectedTask(null, "Deleting role \"pirate\"");
ExpectedWorkItem expectedWorkItem = new ExpectedWorkItem(USER_PIRATE_OWNER_OID, null, expectedTask);
deleteObject(RoleType.class, rolePirateOid, false, true, Collections.singletonList(expectedTask), Collections.singletonList(expectedWorkItem));
}
use of com.evolveum.midpoint.wf.impl.ExpectedWorkItem in project midpoint by Evolveum.
the class TestObjectLifecycleApprovalGlobal method test700CreateRoleThief.
@Test
public void test700CreateRoleThief() throws Exception {
login(userAdministrator);
RoleType thief = new RoleType(prismContext).name("thief").description("something").riskLevel("high").inducement(createAssignmentTo(OID1, ObjectTypes.ROLE, prismContext)).inducement(createAssignmentTo(OID2, ObjectTypes.ROLE, prismContext));
ObjectDelta<RoleType> addObjectDelta = DeltaFactory.Object.createAddDelta(thief.asPrismObject());
executeTest(new TestDetails() {
@Override
protected LensContext createModelContext(OperationResult result) throws Exception {
LensContext<RoleType> lensContext = createLensContext(RoleType.class);
addFocusDeltaToContext(lensContext, addObjectDelta);
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(thief);
}
@Override
protected void afterRootCaseFinishes(CaseType rootCase, List<CaseType> subcases, Task opTask, OperationResult result) throws Exception {
assertObject(thief);
}
@Override
protected boolean executeImmediately() {
return false;
}
@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 \"thief\"")), 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 \"thief\"")), true, USER_ADMINISTRATOR_OID, null));
return instructions;
}
}, 4);
// TODO some more asserts
PrismObject<RoleType> thiefAfter = searchObjectByName(RoleType.class, "thief");
roleThiefOid = thiefAfter.getOid();
display("Thief role", thiefAfter);
assertEquals("Wrong risk level", "high", thiefAfter.asObjectable().getRiskLevel());
assertInducedRoles(thiefAfter, OID1, OID2);
}
use of com.evolveum.midpoint.wf.impl.ExpectedWorkItem 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.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);
}
Aggregations