use of com.evolveum.midpoint.test.asserter.prism.PrismObjectAsserter 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));
}
Aggregations