Search in sources :

Example 1 with PrismObjectAsserter

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));
}
Also used : ExpectedTask(com.evolveum.midpoint.wf.impl.ExpectedTask) Task(com.evolveum.midpoint.task.api.Task) PrismObjectAsserter(com.evolveum.midpoint.test.asserter.prism.PrismObjectAsserter) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ExpectedWorkItem(com.evolveum.midpoint.wf.impl.ExpectedWorkItem) LensContext(com.evolveum.midpoint.model.impl.lens.LensContext) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) ExpectedTask(com.evolveum.midpoint.wf.impl.ExpectedTask) Test(org.testng.annotations.Test)

Aggregations

LensContext (com.evolveum.midpoint.model.impl.lens.LensContext)1 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)1 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 Task (com.evolveum.midpoint.task.api.Task)1 PrismObjectAsserter (com.evolveum.midpoint.test.asserter.prism.PrismObjectAsserter)1 PolicyViolationException (com.evolveum.midpoint.util.exception.PolicyViolationException)1 ExpectedTask (com.evolveum.midpoint.wf.impl.ExpectedTask)1 ExpectedWorkItem (com.evolveum.midpoint.wf.impl.ExpectedWorkItem)1 Test (org.testng.annotations.Test)1