Search in sources :

Example 11 with ReferenceDelta

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

the class TestModelCrudService method test119ModifyUserDeleteAccount.

@Test
public void test119ModifyUserDeleteAccount() throws Exception {
    TestUtil.displayTestTile(this, "test119ModifyUserDeleteAccount");
    // GIVEN
    Task task = taskManager.createTaskInstance(TestModelCrudService.class.getName() + ".test119ModifyUserDeleteAccount");
    OperationResult result = task.getResult();
    assumeAssignmentPolicy(AssignmentPolicyEnforcementType.NONE);
    PrismObject<ShadowType> account = PrismTestUtil.parseObject(ACCOUNT_JACK_DUMMY_FILE);
    account.setOid(accountOid);
    Collection<ItemDelta<?, ?>> modifications = new ArrayList<>();
    PrismReferenceValue accountRefVal = new PrismReferenceValue();
    accountRefVal.setObject(account);
    ReferenceDelta accountDelta = ReferenceDelta.createModificationDelete(UserType.F_LINK_REF, getUserDefinition(), account);
    modifications.add(accountDelta);
    // WHEN
    modelCrudService.modifyObject(UserType.class, USER_JACK_OID, modifications, null, task, result);
    // THEN
    // Check accountRef
    PrismObject<UserType> userJack = modelService.getObject(UserType.class, USER_JACK_OID, null, task, result);
    assertUserJack(userJack);
    UserType userJackType = userJack.asObjectable();
    assertEquals("Unexpected number of accountRefs", 0, userJackType.getLinkRef().size());
    // Check is shadow is gone
    try {
        PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result);
        AssertJUnit.fail("Shadow " + accountOid + " still exists");
    } catch (ObjectNotFoundException e) {
    // This is OK
    }
    // Check if dummy resource account is gone
    assertNoDummyAccount("jack");
}
Also used : Task(com.evolveum.midpoint.task.api.Task) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) 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) Test(org.testng.annotations.Test)

Example 12 with ReferenceDelta

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

the class TestNotifications method test119ModifyUserDeleteAccount.

@Test
public void test119ModifyUserDeleteAccount() throws Exception {
    final String TEST_NAME = "test119ModifyUserDeleteAccount";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestNotifications.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    preTestCleanup(AssignmentPolicyEnforcementType.POSITIVE);
    PrismObject<ShadowType> account = PrismTestUtil.parseObject(ACCOUNT_JACK_DUMMY_FILE);
    account.setOid(accountJackOid);
    ObjectDelta<UserType> userDelta = ObjectDelta.createEmptyModifyDelta(UserType.class, USER_JACK_OID, prismContext);
    ReferenceDelta accountDelta = ReferenceDelta.createModificationDelete(UserType.F_LINK_REF, getUserDefinition(), account);
    userDelta.addModification(accountDelta);
    Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    modelService.executeChanges(deltas, null, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    TestUtil.assertSuccess("executeChanges result", result, 2);
    assertShadowFetchOperationCountIncrement(0);
    // Check accountRef
    PrismObject<UserType> userJack = modelService.getObject(UserType.class, USER_JACK_OID, null, task, result);
    assertUserJack(userJack);
    UserType userJackType = userJack.asObjectable();
    assertEquals("Unexpected number of linkRefs", 0, userJackType.getLinkRef().size());
    // Check is shadow is gone
    try {
        PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountJackOid, null, result);
        AssertJUnit.fail("Shadow " + accountJackOid + " still exists");
    } catch (ObjectNotFoundException e) {
    // This is OK
    }
    // Check if dummy resource account is gone
    assertNoDummyAccount("jack");
    assertDummyScriptsDelete();
    // Check notifications
    display("Notifications", dummyTransport);
    notificationManager.setDisabled(true);
    checkDummyTransportMessages("accountPasswordNotifier", 0);
    checkDummyTransportMessages("userPasswordNotifier", 0);
    checkDummyTransportMessages("simpleAccountNotifier-SUCCESS", 1);
    checkDummyTransportMessages("simpleAccountNotifier-FAILURE", 0);
    checkDummyTransportMessages("simpleAccountNotifier-ADD-SUCCESS", 0);
    checkDummyTransportMessages("simpleAccountNotifier-DELETE-SUCCESS", 1);
    checkDummyTransportMessages("simpleUserNotifier", 0);
    checkDummyTransportMessages("simpleUserNotifier-ADD", 0);
    String expected = "Notification about account-related operation\n" + "\n" + "Owner: Jack Sparrow (jack, oid c0c010c0-d34d-b33f-f00d-111111111111)\n" + "Resource: Dummy Resource (oid 10000000-0000-0000-0000-000000000004)\n" + "Account: jack\n" + "\n" + "The account has been successfully removed from the resource.\n" + "\n" + "Channel: ";
    assertEquals("Wrong message body", expected, dummyTransport.getMessages("dummy:simpleAccountNotifier-DELETE-SUCCESS").get(0).getBody());
    assertSteadyResources();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ReferenceDelta(com.evolveum.midpoint.prism.delta.ReferenceDelta) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) Test(org.testng.annotations.Test)

Example 13 with ReferenceDelta

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

the class TestRoleEntitlement method test108ModifyRoleAddEntitlementAgain.

@Test
public void test108ModifyRoleAddEntitlementAgain() throws Exception {
    final String TEST_NAME = "test108ModifyRoleAddEntitlementAgain";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestRoleEntitlement.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    assumeAssignmentPolicy(AssignmentPolicyEnforcementType.POSITIVE);
    PrismObject<ShadowType> group = PrismTestUtil.parseObject(GROUP_PIRATE_DUMMY_FILE);
    ObjectDelta<RoleType> roleDelta = ObjectDelta.createEmptyModifyDelta(RoleType.class, ROLE_PIRATE_OID, prismContext);
    PrismReferenceValue linkRefVal = new PrismReferenceValue();
    linkRefVal.setObject(group);
    ReferenceDelta groupDelta = ReferenceDelta.createModificationAdd(RoleType.F_LINK_REF, getRoleDefinition(), linkRefVal);
    roleDelta.addModification(groupDelta);
    Collection<ObjectDelta<? extends ObjectType>> deltas = (Collection) MiscUtil.createCollection(roleDelta);
    dummyAuditService.clear();
    try {
        // WHEN
        modelService.executeChanges(deltas, null, task, result);
        // THEN
        assert false : "Expected executeChanges operation to fail but it has obviously succeeded";
    } catch (SchemaException e) {
        // This is expected
        e.printStackTrace();
        // THEN
        String message = e.getMessage();
        assertMessageContains(message, "already contains entitlement");
        assertMessageContains(message, "group");
    }
    // Check audit
    display("Audit", dummyAuditService);
    dummyAuditService.assertSimpleRecordSanity();
    dummyAuditService.assertRecords(2);
    dummyAuditService.assertAnyRequestDeltas();
    dummyAuditService.assertTarget(ROLE_PIRATE_OID);
    dummyAuditService.assertExecutionOutcome(OperationResultStatus.FATAL_ERROR);
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Task(com.evolveum.midpoint.task.api.Task) ReferenceDelta(com.evolveum.midpoint.prism.delta.ReferenceDelta) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) Collection(java.util.Collection) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) Test(org.testng.annotations.Test)

Example 14 with ReferenceDelta

use of com.evolveum.midpoint.prism.delta.ReferenceDelta 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 15 with ReferenceDelta

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

the class AbstractModelIntegrationTest method createModifyUserUnlinkAccount.

protected ObjectDelta<UserType> createModifyUserUnlinkAccount(String userOid, PrismObject<ResourceType> resource) throws SchemaException, ObjectNotFoundException, SecurityViolationException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
    String accountOid = getLinkRefOid(userOid, resource.getOid());
    ObjectDelta<UserType> userDelta = ObjectDelta.createEmptyModifyDelta(UserType.class, userOid, prismContext);
    PrismReferenceValue accountRefVal = new PrismReferenceValue();
    accountRefVal.setOid(accountOid);
    ReferenceDelta accountDelta = ReferenceDelta.createModificationDelete(UserType.F_LINK_REF, getUserDefinition(), accountRefVal);
    userDelta.addModification(accountDelta);
    return userDelta;
}
Also used : PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) ReferenceDelta(com.evolveum.midpoint.prism.delta.ReferenceDelta) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)

Aggregations

ReferenceDelta (com.evolveum.midpoint.prism.delta.ReferenceDelta)71 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)49 Task (com.evolveum.midpoint.task.api.Task)44 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)42 Test (org.testng.annotations.Test)41 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)33 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)29 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)29 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)27 Collection (java.util.Collection)21 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)14 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)12 ArrayList (java.util.ArrayList)12 ShadowDiscriminatorObjectDelta (com.evolveum.midpoint.common.refinery.ShadowDiscriminatorObjectDelta)11 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)11 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)10 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)9 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)8 ModelExecuteOptions (com.evolveum.midpoint.model.api.ModelExecuteOptions)7 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)6