Search in sources :

Example 76 with ObjectDelta

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

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

the class TestAssignmentErrors method test210UserSharptoothAssignAccountBrokenGeneric.

// PARTIAL_ERROR: Unable to get object from the resource. Probably it has not been created yet because of previous unavailability of the resource.
// TODO: timeout or explicit retry
//	@Test
//    public void test205UserLemonheadRecovery() throws Exception {
//		final String TEST_NAME = "test205UserLemonheadRecovery";
//        TestUtil.displayTestTile(this, TEST_NAME);
//
//        // GIVEN
//        Task task = taskManager.createTaskInstance(TestAssignmentErrors.class.getName() + "." + TEST_NAME);
//        OperationResult result = task.getResult();
//        assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);
//                
//        dummyResource.setBreakMode(BreakMode.NONE);
//        dummyAuditService.clear();
//                
//		// WHEN
//		//not expected that it fails, instead the error in the result is expected
//        modelService.recompute(UserType.class, userLemonheadOid, task, result);
//        
//        result.computeStatus();
//        
//        display(result);
//        // This has to be a partial error as some changes were executed (user) and others were not (account)
//        TestUtil.assertSuccess(result);
//        
//        // Check audit
//        display("Audit", dummyAuditService);
//        dummyAuditService.assertSimpleRecordSanity();
//        dummyAuditService.assertRecords(2);
//        dummyAuditService.assertAnyRequestDeltas();
//        dummyAuditService.assertTarget(userLemonheadOid);
//        dummyAuditService.assertExecutionOutcome(OperationResultStatus.HANDLED_ERROR);
//        dummyAuditService.assertExecutionMessage();
//		
//	}
@Test
public void test210UserSharptoothAssignAccountBrokenGeneric() throws Exception {
    final String TEST_NAME = "test210UserSharptoothAssignAccountBrokenGeneric";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestAssignmentErrors.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);
    PrismObject<UserType> user = createUser(USER_SHARPTOOTH_NAME, USER_SHARPTOOTH_FULLNAME);
    CredentialsType credentialsType = new CredentialsType();
    PasswordType passwordType = new PasswordType();
    ProtectedStringType passwordPs = new ProtectedStringType();
    passwordPs.setClearValue(USER_SHARPTOOTH_PASSWORD_1_CLEAR);
    passwordType.setValue(passwordPs);
    credentialsType.setPassword(passwordType);
    user.asObjectable().setCredentials(credentialsType);
    addObject(user);
    userSharptoothOid = user.getOid();
    Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<ObjectDelta<? extends ObjectType>>();
    ObjectDelta<UserType> accountAssignmentUserDelta = createAccountAssignmentUserDelta(user.getOid(), RESOURCE_DUMMY_OID, null, true);
    deltas.add(accountAssignmentUserDelta);
    getDummyResource().setBreakMode(BreakMode.GENERIC);
    dummyAuditService.clear();
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    //not expected that it fails, instead the error in the result is expected
    modelService.executeChanges(deltas, null, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    display(result);
    // This has to be a partial error as some changes were executed (user) and others were not (account)
    TestUtil.assertPartialError(result);
    // Check audit
    display("Audit", dummyAuditService);
    dummyAuditService.assertSimpleRecordSanity();
    dummyAuditService.assertRecords(2);
    dummyAuditService.assertAnyRequestDeltas();
    dummyAuditService.assertExecutionDeltas(2);
    dummyAuditService.assertHasDelta(ChangeType.MODIFY, UserType.class);
    dummyAuditService.assertHasDelta(ChangeType.ADD, ShadowType.class, OperationResultStatus.FATAL_ERROR);
    dummyAuditService.assertTarget(user.getOid());
    dummyAuditService.assertExecutionOutcome(OperationResultStatus.PARTIAL_ERROR);
    dummyAuditService.assertExecutionMessage();
    LensContext<UserType> lastLensContext = lensDebugListener.getLastLensContext();
    Collection<ObjectDeltaOperation<? extends ObjectType>> executedDeltas = lastLensContext.getExecutedDeltas();
    display("Executed deltas", executedDeltas);
    assertEquals("Unexpected number of execution deltas in context", 2, executedDeltas.size());
    Iterator<ObjectDeltaOperation<? extends ObjectType>> i = executedDeltas.iterator();
    ObjectDeltaOperation<? extends ObjectType> deltaop1 = i.next();
    assertEquals("Unexpected result of first executed deltas", OperationResultStatus.SUCCESS, deltaop1.getExecutionResult().getStatus());
    ObjectDeltaOperation<? extends ObjectType> deltaop2 = i.next();
    assertEquals("Unexpected result of second executed deltas", OperationResultStatus.FATAL_ERROR, deltaop2.getExecutionResult().getStatus());
}
Also used : Task(com.evolveum.midpoint.task.api.Task) CredentialsType(com.evolveum.midpoint.xml.ns._public.common.common_3.CredentialsType) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PasswordType(com.evolveum.midpoint.xml.ns._public.common.common_3.PasswordType) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) ObjectDeltaOperation(com.evolveum.midpoint.schema.ObjectDeltaOperation) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) Test(org.testng.annotations.Test) AbstractInitializedModelIntegrationTest(com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)

Example 78 with ObjectDelta

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

the class TestAssignmentErrors method test200UserLemonheadAssignAccountBrokenNetwork.

@Test
public void test200UserLemonheadAssignAccountBrokenNetwork() throws Exception {
    final String TEST_NAME = "test200UserLemonheadAssignAccountBrokenNetwork";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestAssignmentErrors.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);
    PrismObject<UserType> user = createUser(USER_LEMONHEAD_NAME, USER_LEMONHEAD_FULLNAME);
    addObject(user);
    userLemonheadOid = user.getOid();
    Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<ObjectDelta<? extends ObjectType>>();
    ObjectDelta<UserType> accountAssignmentUserDelta = createAccountAssignmentUserDelta(user.getOid(), RESOURCE_DUMMY_OID, null, true);
    deltas.add(accountAssignmentUserDelta);
    getDummyResource().setBreakMode(BreakMode.NETWORK);
    dummyAuditService.clear();
    // WHEN
    //not expected that it fails, instead the error in the result is expected
    modelService.executeChanges(deltas, null, task, result);
    result.computeStatus();
    display(result);
    // This has to be a partial error as some changes were executed (user) and others were not (account)
    TestUtil.assertResultStatus(result, OperationResultStatus.HANDLED_ERROR);
    // Check audit
    display("Audit", dummyAuditService);
    dummyAuditService.assertSimpleRecordSanity();
    dummyAuditService.assertRecords(2);
    dummyAuditService.assertAnyRequestDeltas();
    dummyAuditService.assertTarget(user.getOid());
    dummyAuditService.assertExecutionOutcome(OperationResultStatus.HANDLED_ERROR);
    dummyAuditService.assertExecutionMessage();
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) Task(com.evolveum.midpoint.task.api.Task) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) 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 79 with ObjectDelta

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

the class TestAssignmentErrors method test100UserJackAssignBlankAccount.

/**
	 * The "white" resource has no outbound mapping and there is also no mapping in the assignment. Therefore
	 * this results in account without any attributes. It should fail.
	 */
@Test
public void test100UserJackAssignBlankAccount() throws Exception {
    final String TEST_NAME = "test100UserJackAssignBlankAccount";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestAssignmentErrors.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);
    dummyAuditService.clear();
    Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<ObjectDelta<? extends ObjectType>>();
    ObjectDelta<UserType> accountAssignmentUserDelta = createAccountAssignmentUserDelta(USER_JACK_OID, RESOURCE_DUMMY_WHITE_OID, null, true);
    deltas.add(accountAssignmentUserDelta);
    dummyAuditService.clear();
    // WHEN
    //not expected that it fails, insted the fatal error in the result is excpected
    modelService.executeChanges(deltas, null, task, result);
    result.computeStatus();
    display(result);
    // This has to be a partial error as some changes were executed (user) and others were not (account)
    TestUtil.assertPartialError(result);
    // Check audit
    display("Audit", dummyAuditService);
    dummyAuditService.assertSimpleRecordSanity();
    dummyAuditService.assertRecords(2);
    dummyAuditService.assertAnyRequestDeltas();
    dummyAuditService.assertTarget(USER_JACK_OID);
    dummyAuditService.assertExecutionOutcome(OperationResultStatus.PARTIAL_ERROR);
    dummyAuditService.assertExecutionMessage();
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) Task(com.evolveum.midpoint.task.api.Task) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) 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 80 with ObjectDelta

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

the class TestBrokenResources method test360AddResourceNoConfiguration.

@Test
public void test360AddResourceNoConfiguration() throws Exception {
    final String TEST_NAME = "test360AddResourceNoConfiguration";
    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_NO_CONFIGURATION_FILE);
    PrismObject<ConnectorType> connectorDummy = findConnectorByTypeAndVersion(CONNECTOR_DUMMY_TYPE, CONNECTOR_DUMMY_VERSION, result);
    resource.asObjectable().getConnectorRef().setOid(connectorDummy.getOid());
    ObjectDelta<ResourceType> delta = ObjectDelta.createAddDelta(resource);
    Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(delta);
    // WHEN
    modelService.executeChanges(deltas, null, task, result);
    // THEN
    result.computeStatus();
    TestUtil.assertSuccess(result);
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) Task(com.evolveum.midpoint.task.api.Task) ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) 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)

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