Search in sources :

Example 86 with ObjectDelta

use of com.evolveum.midpoint.prism.delta.ObjectDelta in project midpoint by Evolveum.

the class TestOrgStruct method test305JackConflictZeroAndMinus.

/**
     * Conflict: removing the role assignment (that should remove org assignment), while keeping explicit org assignment present
     */
@Test
public void test305JackConflictZeroAndMinus() throws Exception {
    final String TEST_NAME = "test305JackConflictZeroAndMinus";
    TestUtil.displayTestTile(this, TEST_NAME);
    Task task = taskManager.createTaskInstance(TestOrgStruct.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    Collection<ItemDelta<?, ?>> modifications = new ArrayList<>();
    modifications.add((createAssignmentModification(ROLE_DEFENDER_OID, RoleType.COMPLEX_TYPE, null, null, null, false)));
    ObjectDelta<UserType> userDelta = ObjectDelta.createModifyDelta(USER_JACK_OID, modifications, UserType.class, prismContext);
    Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta);
    // WHEN
    modelService.executeChanges(deltas, null, task, result);
    // THEN
    PrismObject<UserType> userJack = getUser(USER_JACK_OID);
    display("User jack after", userJack);
    assertUserOrg(userJack, ORG_MINISTRY_OF_DEFENSE_OID, ORG_MINISTRY_OF_DEFENSE_OID);
    assertAssignedOrg(userJack, ORG_MINISTRY_OF_DEFENSE_OID, SchemaConstants.ORG_MANAGER);
    assertHasOrg(userJack, ORG_MINISTRY_OF_DEFENSE_OID, SchemaConstants.ORG_MANAGER);
    assertHasOrg(userJack, ORG_MINISTRY_OF_DEFENSE_OID, null);
    // Postcondition
    assertMonkeyIslandOrgSanity();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test) AbstractInitializedModelIntegrationTest(com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)

Example 87 with ObjectDelta

use of com.evolveum.midpoint.prism.delta.ObjectDelta in project midpoint by Evolveum.

the class TestOrgStruct method test412JackChangeMinistryOfOffenseMemberToManagerByModifyingAssignment.

// this test should generate a SchemaException (modifying targetRef in assignment should be prohibited)
@Test
public void test412JackChangeMinistryOfOffenseMemberToManagerByModifyingAssignment() throws Exception {
    final String TEST_NAME = "test412JackChangeMinistryOfOffenseMemberToManagerByModifyingAssignment";
    TestUtil.displayTestTile(this, TEST_NAME);
    Task task = taskManager.createTaskInstance(TestOrgStruct.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    PrismObject<UserType> jack = getUser(USER_JACK_OID);
    Long id = findAssignmentIdForTarget(jack, ORG_MINISTRY_OF_OFFENSE_OID);
    Collection<ItemDelta<?, ?>> modifications = new ArrayList<>();
    PrismReferenceDefinition referenceDefinition = getUserDefinition().findItemDefinition(new ItemPath(UserType.F_ASSIGNMENT, AssignmentType.F_TARGET_REF), PrismReferenceDefinition.class);
    ReferenceDelta referenceDelta = new ReferenceDelta(new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(id), new NameItemPathSegment(AssignmentType.F_TARGET_REF)), referenceDefinition, prismContext);
    PrismReferenceValue oldValue = new PrismReferenceValue(ORG_MINISTRY_OF_OFFENSE_OID, OrgType.COMPLEX_TYPE);
    PrismReferenceValue newValue = new PrismReferenceValue(ORG_MINISTRY_OF_OFFENSE_OID, OrgType.COMPLEX_TYPE);
    newValue.setRelation(SchemaConstants.ORG_MANAGER);
    referenceDelta.addValueToDelete(oldValue);
    referenceDelta.addValueToAdd(newValue);
    modifications.add(referenceDelta);
    ObjectDelta<UserType> userDelta = ObjectDelta.createModifyDelta(USER_JACK_OID, modifications, UserType.class, prismContext);
    Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta);
    // WHEN
    try {
        modelService.executeChanges(deltas, null, task, result);
        AssertJUnit.fail("executeChanges should fail but it did not.");
    } catch (SchemaException e) {
    // ok!
    } catch (Exception e) {
        AssertJUnit.fail("executeChanges failed in the wrong way (expected SchemaException): " + e);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Task(com.evolveum.midpoint.task.api.Task) ArrayList(java.util.ArrayList) ReferenceDelta(com.evolveum.midpoint.prism.delta.ReferenceDelta) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) PrismReferenceDefinition(com.evolveum.midpoint.prism.PrismReferenceDefinition) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test) AbstractInitializedModelIntegrationTest(com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)

Example 88 with ObjectDelta

use of com.evolveum.midpoint.prism.delta.ObjectDelta in project midpoint by Evolveum.

the class TestBrokenResources method test350AddResourceWrongConnectorOid.

@Test
public void test350AddResourceWrongConnectorOid() throws Exception {
    final String TEST_NAME = "test350AddResourceWrongConnectorOid";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestBrokenResources.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    PrismObject<ResourceType> resource = PrismTestUtil.parseObject(RESOURCE_DUMMY_WRONG_CONNECTOR_OID_FILE);
    ObjectDelta<ResourceType> delta = ObjectDelta.createAddDelta(resource);
    Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(delta);
    try {
        // WHEN
        modelService.executeChanges(deltas, null, task, result);
        AssertJUnit.fail("Unexpected success");
    } catch (ObjectNotFoundException e) {
    // This is expected
    }
    // THEN
    result.computeStatus();
    display(result);
    TestUtil.assertFailure(result);
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) Task(com.evolveum.midpoint.task.api.Task) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) Test(org.testng.annotations.Test) AbstractConfiguredModelIntegrationTest(com.evolveum.midpoint.model.intest.AbstractConfiguredModelIntegrationTest)

Example 89 with ObjectDelta

use of com.evolveum.midpoint.prism.delta.ObjectDelta in project midpoint by Evolveum.

the class TestBrokenResources method test359DeleteResourceWrongConnectorOid.

@Test
public void test359DeleteResourceWrongConnectorOid() throws Exception {
    final String TEST_NAME = "test359DeleteResourceWrongConnectorOid";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestBrokenResources.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    ObjectDelta<ResourceType> delta = ObjectDelta.createDeleteDelta(ResourceType.class, RESOURCE_DUMMY_WRONG_CONNECTOR_OID_OID, prismContext);
    Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(delta);
    // WHEN
    modelService.executeChanges(deltas, null, task, result);
    // THEN
    result.computeStatus();
    display("getObject result", result);
    assertEquals("Expected partial errror in result", OperationResultStatus.PARTIAL_ERROR, result.getStatus());
    assertNoObject(ResourceType.class, RESOURCE_DUMMY_WRONG_CONNECTOR_OID_OID, task, result);
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) Test(org.testng.annotations.Test) AbstractConfiguredModelIntegrationTest(com.evolveum.midpoint.model.intest.AbstractConfiguredModelIntegrationTest)

Example 90 with ObjectDelta

use of com.evolveum.midpoint.prism.delta.ObjectDelta in project midpoint by Evolveum.

the class AbstractModelIntegrationTest method unassignAllRoles.

protected void unassignAllRoles(String userOid, boolean useRawPlusRecompute) throws ObjectNotFoundException, SchemaException, ExpressionEvaluationException, CommunicationException, ConfigurationException, ObjectAlreadyExistsException, PolicyViolationException, SecurityViolationException {
    Task task = taskManager.createTaskInstance(AbstractModelIntegrationTest.class + ".unassignAllRoles");
    OperationResult result = task.getResult();
    PrismObject<UserType> user = modelService.getObject(UserType.class, userOid, null, task, result);
    Collection<ItemDelta<?, ?>> modifications = new ArrayList<>();
    for (AssignmentType assignment : user.asObjectable().getAssignment()) {
        ObjectReferenceType targetRef = assignment.getTargetRef();
        if (targetRef != null) {
            if (targetRef.getType().equals(RoleType.COMPLEX_TYPE)) {
                ContainerDelta<AssignmentType> assignmentDelta = ContainerDelta.createDelta(UserType.F_ASSIGNMENT, getUserDefinition());
                PrismContainerValue<AssignmentType> cval = new PrismContainerValue<>(prismContext);
                cval.setId(assignment.getId());
                assignmentDelta.addValueToDelete(cval);
                modifications.add(assignmentDelta);
            }
        }
    }
    if (modifications.isEmpty()) {
        return;
    }
    ObjectDelta<UserType> userDelta = ObjectDelta.createModifyDelta(userOid, modifications, UserType.class, prismContext);
    Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta);
    modelService.executeChanges(deltas, useRawPlusRecompute ? ModelExecuteOptions.createRaw() : null, task, result);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    if (useRawPlusRecompute) {
        recomputeUser(userOid, task, result);
        result.computeStatus();
        TestUtil.assertSuccess(result);
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)

Aggregations

ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)445 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)363 Task (com.evolveum.midpoint.task.api.Task)326 Test (org.testng.annotations.Test)303 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)242 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)218 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)148 ArrayList (java.util.ArrayList)126 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)103 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)55 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)47 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)42 ReferenceDelta (com.evolveum.midpoint.prism.delta.ReferenceDelta)41 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)38 ShadowDiscriminatorObjectDelta (com.evolveum.midpoint.common.refinery.ShadowDiscriminatorObjectDelta)32 ModelExecuteOptions (com.evolveum.midpoint.model.api.ModelExecuteOptions)31 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)31 Collection (java.util.Collection)31 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)31 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)26