Search in sources :

Example 1 with ResourceObjectShadowChangeDescription

use of com.evolveum.midpoint.provisioning.api.ResourceObjectShadowChangeDescription in project midpoint by Evolveum.

the class TestSynchronizationService method test100AddedAccountJack.

@Test
public void test100AddedAccountJack() throws Exception {
    final String TEST_NAME = "test100AddedAccountJack";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestSynchronizationService.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    PrismObject<UserType> userBefore = getUser(USER_JACK_OID);
    assertLinks(userBefore, 0);
    MockLensDebugListener mockListener = new MockLensDebugListener();
    clockwork.setDebugListener(mockListener);
    PrismObject<ShadowType> accountShadowJack = repoAddObjectFromFile(ACCOUNT_SHADOW_JACK_DUMMY_FILE, result);
    accountShadowJackDummyOid = accountShadowJack.getOid();
    provisioningService.applyDefinition(accountShadowJack, task, result);
    assertNotNull("No oid in shadow", accountShadowJack.getOid());
    DummyAccount dummyAccount = new DummyAccount();
    dummyAccount.setName(ACCOUNT_JACK_DUMMY_USERNAME);
    dummyAccount.setPassword("deadMenTellNoTales");
    dummyAccount.setEnabled(true);
    dummyAccount.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME, "Jack Sparrow");
    getDummyResource().addAccount(dummyAccount);
    display("Dummy resource before", getDummyResource());
    ResourceObjectShadowChangeDescription change = new ResourceObjectShadowChangeDescription();
    change.setCurrentShadow(accountShadowJack);
    change.setResource(getDummyResourceObject());
    // WHEN
    synchronizationService.notifyChange(change, task, result);
    // THEN
    LensContext<UserType> context = mockListener.getLastSyncContext();
    display("Resulting context (as seen by debug listener)", context);
    assertNotNull("No resulting context (as seen by debug listener)", context);
    assertNull("Unexpected user primary delta", context.getFocusContext().getPrimaryDelta());
    assertSideEffectiveDeltasOnly(context.getFocusContext().getSecondaryDelta(), "user secondary delta", ActivationStatusType.ENABLED);
    ResourceShadowDiscriminator rat = new ResourceShadowDiscriminator(getDummyResourceObject().getOid(), ShadowKindType.ACCOUNT, null);
    LensProjectionContext accCtx = context.findProjectionContext(rat);
    assertNotNull("No account sync context for " + rat, accCtx);
    assertEquals("Wrong detected situation in context", SynchronizationSituationType.UNLINKED, accCtx.getSynchronizationSituationDetected());
    assertEquals("Wrong resolved situation in context", SynchronizationSituationType.LINKED, accCtx.getSynchronizationSituationResolved());
    PrismAsserts.assertNoDelta("Unexpected account primary delta", accCtx.getPrimaryDelta());
    //it this really expected?? delta was already executed, should we expect it in the secondary delta?
    //		assertNotNull("Missing account secondary delta", accCtx.getSecondaryDelta());
    //		assertIterationDelta(accCtx.getSecondaryDelta(), 0, "");
    assertLinked(context.getFocusContext().getObjectOld().getOid(), accountShadowJack.getOid());
    PrismObject<ShadowType> shadow = getShadowModelNoFetch(accountShadowJackDummyOid);
    assertIteration(shadow, 0, "");
    assertSituation(shadow, SynchronizationSituationType.LINKED);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
    assertLinks(userAfter, 1);
    assertLinked(userAfter, shadow);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) LensProjectionContext(com.evolveum.midpoint.model.impl.lens.LensProjectionContext) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) MockLensDebugListener(com.evolveum.midpoint.model.impl.util.mock.MockLensDebugListener) ResourceObjectShadowChangeDescription(com.evolveum.midpoint.provisioning.api.ResourceObjectShadowChangeDescription) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) DummyAccount(com.evolveum.icf.dummy.resource.DummyAccount) Test(org.testng.annotations.Test) AbstractInternalModelIntegrationTest(com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)

Example 2 with ResourceObjectShadowChangeDescription

use of com.evolveum.midpoint.provisioning.api.ResourceObjectShadowChangeDescription in project midpoint by Evolveum.

the class TestDummy method testLiveSyncDeleteCorsairs.

public void testLiveSyncDeleteCorsairs(final String TEST_NAME, DummySyncStyle syncStyle, QName objectClass, boolean expectReaction) throws Exception {
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    OperationResult result = new OperationResult(TestDummy.class.getName() + "." + TEST_NAME);
    syncServiceMock.reset();
    dummyResource.setSyncStyle(syncStyle);
    if (isNameUnique()) {
        dummyResource.deleteGroupByName(GROUP_CORSAIRS_NAME);
    } else {
        dummyResource.deleteGroupById(corsairsIcfUid);
    }
    display("Resource before sync", dummyResource.debugDump());
    ResourceShadowDiscriminator coords = new ResourceShadowDiscriminator(RESOURCE_DUMMY_OID, objectClass);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    provisioningService.synchronize(coords, syncTokenTask, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    display("Synchronization result", result);
    TestUtil.assertSuccess("Synchronization result is not OK", result);
    if (expectReaction) {
        syncServiceMock.assertNotifyChange();
        ResourceObjectShadowChangeDescription lastChange = syncServiceMock.getLastChange();
        display("The change", lastChange);
        PrismObject<? extends ShadowType> oldShadow = lastChange.getOldShadow();
        assertNotNull("Old shadow missing", oldShadow);
        assertNotNull("Old shadow does not have an OID", oldShadow.getOid());
        PrismAsserts.assertClass("old shadow", ShadowType.class, oldShadow);
        ShadowType oldShadowType = oldShadow.asObjectable();
        ResourceAttributeContainer attributesContainer = ShadowUtil.getAttributesContainer(oldShadowType);
        assertNotNull("No attributes container in old shadow", attributesContainer);
        Collection<ResourceAttribute<?>> attributes = attributesContainer.getAttributes();
        assertFalse("Attributes container is empty", attributes.isEmpty());
        assertEquals("Unexpected number of attributes", 2, attributes.size());
        ResourceAttribute<?> icfsNameAttribute = attributesContainer.findAttribute(SchemaConstants.ICFS_NAME);
        assertNotNull("No ICF name attribute in old  shadow", icfsNameAttribute);
        assertEquals("Wrong value of ICF name attribute in old  shadow", GROUP_CORSAIRS_NAME, icfsNameAttribute.getRealValue());
        ObjectDelta<? extends ShadowType> objectDelta = lastChange.getObjectDelta();
        assertNotNull("Delta missing", objectDelta);
        assertEquals("Wrong delta changetype", ChangeType.DELETE, objectDelta.getChangeType());
        PrismAsserts.assertClass("delta", ShadowType.class, objectDelta);
        assertNotNull("No OID in delta", objectDelta.getOid());
        assertNull("Unexpected current shadow", lastChange.getCurrentShadow());
        try {
            // The shadow should be gone
            PrismObject<ShadowType> repoShadow = repositoryService.getObject(ShadowType.class, corsairsShadowOid, null, result);
            AssertJUnit.fail("The shadow " + repoShadow + " is not gone from repo");
        } catch (ObjectNotFoundException e) {
        // This is expected
        }
    } else {
        syncServiceMock.assertNoNotifyChange();
    }
    checkAllShadows();
    assertSteadyResource();
}
Also used : ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceAttributeContainer(com.evolveum.midpoint.schema.processor.ResourceAttributeContainer) ResourceObjectShadowChangeDescription(com.evolveum.midpoint.provisioning.api.ResourceObjectShadowChangeDescription) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator) ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute)

Example 3 with ResourceObjectShadowChangeDescription

use of com.evolveum.midpoint.provisioning.api.ResourceObjectShadowChangeDescription in project midpoint by Evolveum.

the class TestDummy method testLiveSyncAddCorsairs.

public void testLiveSyncAddCorsairs(final String TEST_NAME, DummySyncStyle syncStyle, QName objectClass, boolean expectReaction) throws Exception {
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    OperationResult result = new OperationResult(TestDummy.class.getName() + "." + TEST_NAME);
    syncServiceMock.reset();
    dummyResource.setSyncStyle(syncStyle);
    DummyGroup newGroup = new DummyGroup(GROUP_CORSAIRS_NAME);
    newGroup.setEnabled(true);
    dummyResource.addGroup(newGroup);
    corsairsIcfUid = newGroup.getId();
    display("Resource before sync", dummyResource.debugDump());
    ResourceShadowDiscriminator coords = new ResourceShadowDiscriminator(RESOURCE_DUMMY_OID, objectClass);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    provisioningService.synchronize(coords, syncTokenTask, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    display("Synchronization result", result);
    TestUtil.assertSuccess("Synchronization result is not OK", result);
    if (expectReaction) {
        syncServiceMock.assertNotifyChange();
        ResourceObjectShadowChangeDescription lastChange = syncServiceMock.getLastChange();
        display("The change", lastChange);
        PrismObject<? extends ShadowType> oldShadow = lastChange.getOldShadow();
        assertNotNull("Old shadow missing", oldShadow);
        assertNotNull("Old shadow does not have an OID", oldShadow.getOid());
        if (syncStyle == DummySyncStyle.DUMB) {
            assertNull("Delta present when not expecting it", lastChange.getObjectDelta());
        } else {
            ObjectDelta<? extends ShadowType> objectDelta = lastChange.getObjectDelta();
            assertNotNull("Delta present when not expecting it", objectDelta);
            assertTrue("Delta is not add: " + objectDelta, objectDelta.isAdd());
        }
        ShadowType currentShadowType = lastChange.getCurrentShadow().asObjectable();
        assertNotNull("Current shadow missing", lastChange.getCurrentShadow());
        PrismAsserts.assertClass("current shadow", ShadowType.class, currentShadowType);
        ResourceAttributeContainer attributesContainer = ShadowUtil.getAttributesContainer(currentShadowType);
        assertNotNull("No attributes container in current shadow", attributesContainer);
        Collection<ResourceAttribute<?>> attributes = attributesContainer.getAttributes();
        assertFalse("Attributes container is empty", attributes.isEmpty());
        assertEquals("Unexpected number of attributes", 2, attributes.size());
        corsairsShadowOid = currentShadowType.getOid();
        PrismObject<ShadowType> repoShadow = repositoryService.getObject(ShadowType.class, corsairsShadowOid, null, result);
        display("Corsairs repo shadow", repoShadow);
        PrismObject<ShadowType> accountRepo = findShadowByName(new QName(RESOURCE_DUMMY_NS, SchemaConstants.GROUP_OBJECT_CLASS_LOCAL_NAME), GROUP_CORSAIRS_NAME, resource, result);
        assertNotNull("Shadow was not created in the repository", accountRepo);
        display("Repository shadow", accountRepo);
        ProvisioningTestUtil.checkRepoShadow(repoShadow, ShadowKindType.ENTITLEMENT);
    } else {
        syncServiceMock.assertNoNotifyChange();
    }
    checkAllShadows();
    assertSteadyResource();
}
Also used : ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) QName(javax.xml.namespace.QName) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceAttributeContainer(com.evolveum.midpoint.schema.processor.ResourceAttributeContainer) ResourceObjectShadowChangeDescription(com.evolveum.midpoint.provisioning.api.ResourceObjectShadowChangeDescription) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator) ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute) DummyGroup(com.evolveum.icf.dummy.resource.DummyGroup)

Example 4 with ResourceObjectShadowChangeDescription

use of com.evolveum.midpoint.provisioning.api.ResourceObjectShadowChangeDescription in project midpoint by Evolveum.

the class ObjectAlreadyExistHandler method handleError.

@Override
public <T extends ShadowType> T handleError(T shadow, FailedOperation op, Exception ex, boolean doDiscovery, boolean compensate, Task task, OperationResult parentResult) throws SchemaException, GenericFrameworkException, CommunicationException, ObjectNotFoundException, ObjectAlreadyExistsException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
    if (!doDiscovery) {
        parentResult.recordFatalError(ex);
        if (ex instanceof ObjectAlreadyExistsException) {
            throw (ObjectAlreadyExistsException) ex;
        } else {
            throw new ObjectAlreadyExistsException(ex.getMessage(), ex);
        }
    }
    LOGGER.trace("Start to hanlde ObjectAlreadyExitsException.");
    OperationResult operationResult = parentResult.createSubresult("com.evolveum.midpoint.provisioning.consistency.impl.ObjectAlreadyExistHandler.handleError." + op.name());
    operationResult.addParam("shadow", shadow);
    operationResult.addParam("currentOperation", op);
    operationResult.addParam("exception", ex.getMessage());
    ResourceObjectShadowChangeDescription change = new ResourceObjectShadowChangeDescription();
    change.setResource(shadow.getResource().asPrismObject());
    change.setSourceChannel(QNameUtil.qNameToUri(SchemaConstants.CHANGE_CHANNEL_DISCOVERY));
    ObjectQuery query = createQueryByIcfName(shadow);
    final List<PrismObject<ShadowType>> foundAccount = getExistingAccount(query, task, operationResult);
    PrismObject<ShadowType> resourceAccount = null;
    if (!foundAccount.isEmpty() && foundAccount.size() == 1) {
        resourceAccount = foundAccount.get(0);
    }
    LOGGER.trace("Found conflicting resource object: {}", resourceAccount);
    try {
        if (resourceAccount != null) {
            // Original object and found object share the same object class, therefore they must
            // also share a kind. We can use this short-cut.
            resourceAccount.asObjectable().setKind(shadow.getKind());
            change.setCurrentShadow(resourceAccount);
            // TODO: task initialization
            //			Task task = taskManager.createTaskInstance();
            changeNotificationDispatcher.notifyChange(change, task, operationResult);
        }
    } finally {
        operationResult.computeStatus();
    }
    if (operationResult.isSuccess()) {
        parentResult.recordSuccess();
        parentResult.muteLastSubresultError();
    }
    if (compensate) {
        throw new ObjectAlreadyExistsException(ex.getMessage(), ex);
    }
    return shadow;
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) ResourceObjectShadowChangeDescription(com.evolveum.midpoint.provisioning.api.ResourceObjectShadowChangeDescription) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Example 5 with ResourceObjectShadowChangeDescription

use of com.evolveum.midpoint.provisioning.api.ResourceObjectShadowChangeDescription in project midpoint by Evolveum.

the class TestSynchronizationService method test010AddedAccountJack.

@Test
public void test010AddedAccountJack() throws Exception {
    final String TEST_NAME = "test010AddedAccountJack";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestSynchronizationService.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    MockLensDebugListener mockListener = new MockLensDebugListener();
    clockwork.setDebugListener(mockListener);
    PrismObject<ShadowType> accountShadowJack = repoAddObjectFromFile(ACCOUNT_SHADOW_JACK_DUMMY_FILE, result);
    accountShadowJackDummyOid = accountShadowJack.getOid();
    provisioningService.applyDefinition(accountShadowJack, task, result);
    assertNotNull("No oid in shadow", accountShadowJack.getOid());
    DummyAccount dummyAccount = new DummyAccount();
    dummyAccount.setName(ACCOUNT_JACK_DUMMY_USERNAME);
    dummyAccount.setPassword("deadMenTellNoTales");
    dummyAccount.setEnabled(true);
    dummyAccount.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME, "Jack Sparrow");
    getDummyResource().addAccount(dummyAccount);
    ResourceObjectShadowChangeDescription change = new ResourceObjectShadowChangeDescription();
    change.setCurrentShadow(accountShadowJack);
    change.setResource(getDummyResourceObject());
    // WHEN
    synchronizationService.notifyChange(change, task, result);
    // THEN
    LensContext<UserType> context = mockListener.getLastSyncContext();
    display("Resulting context (as seen by debug listener)", context);
    assertNotNull("No resulting context (as seen by debug listener)", context);
    assertNull("Unexpected user primary delta", context.getFocusContext().getPrimaryDelta());
    assertSideEffectiveDeltasOnly(context.getFocusContext().getSecondaryDelta(), "user secondary delta", ActivationStatusType.ENABLED);
    ResourceShadowDiscriminator rat = new ResourceShadowDiscriminator(getDummyResourceObject().getOid(), ShadowKindType.ACCOUNT, null);
    LensProjectionContext accCtx = context.findProjectionContext(rat);
    assertNotNull("No account sync context for " + rat, accCtx);
    assertEquals("Wrong detected situation in context", SynchronizationSituationType.UNLINKED, accCtx.getSynchronizationSituationDetected());
    assertEquals("Wrong resolved situation in context", SynchronizationSituationType.LINKED, accCtx.getSynchronizationSituationResolved());
    PrismAsserts.assertNoDelta("Unexpected account primary delta", accCtx.getPrimaryDelta());
    //it this really expected?? delta was already executed, should we expect it in the secondary delta?
    //		assertNotNull("Missing account secondary delta", accCtx.getSecondaryDelta());
    //		assertIterationDelta(accCtx.getSecondaryDelta(), 0, "");
    assertLinked(context.getFocusContext().getObjectOld().getOid(), accountShadowJack.getOid());
    PrismObject<ShadowType> shadow = getShadowModelNoFetch(accountShadowJackDummyOid);
    assertIteration(shadow, 0, "");
    assertSituation(shadow, SynchronizationSituationType.LINKED);
    result.computeStatus();
    TestUtil.assertSuccess(result);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) LensProjectionContext(com.evolveum.midpoint.model.impl.lens.LensProjectionContext) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) MockLensDebugListener(com.evolveum.midpoint.model.impl.util.mock.MockLensDebugListener) ResourceObjectShadowChangeDescription(com.evolveum.midpoint.provisioning.api.ResourceObjectShadowChangeDescription) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator) DummyAccount(com.evolveum.icf.dummy.resource.DummyAccount) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test) AbstractInternalModelIntegrationTest(com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)

Aggregations

ResourceObjectShadowChangeDescription (com.evolveum.midpoint.provisioning.api.ResourceObjectShadowChangeDescription)24 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)21 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)21 ResourceShadowDiscriminator (com.evolveum.midpoint.schema.ResourceShadowDiscriminator)17 Test (org.testng.annotations.Test)14 Task (com.evolveum.midpoint.task.api.Task)13 DummyAccount (com.evolveum.icf.dummy.resource.DummyAccount)10 AbstractInternalModelIntegrationTest (com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)10 MockLensDebugListener (com.evolveum.midpoint.model.impl.util.mock.MockLensDebugListener)10 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)10 LensProjectionContext (com.evolveum.midpoint.model.impl.lens.LensProjectionContext)8 ResourceAttribute (com.evolveum.midpoint.schema.processor.ResourceAttribute)6 ResourceAttributeContainer (com.evolveum.midpoint.schema.processor.ResourceAttributeContainer)6 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)4 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)3 DummyGroup (com.evolveum.icf.dummy.resource.DummyGroup)2 PrismObject (com.evolveum.midpoint.prism.PrismObject)2 QName (javax.xml.namespace.QName)2 RefinedObjectClassDefinition (com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition)1 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)1