Search in sources :

Example 21 with ResourceObjectShadowChangeDescription

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

the class TestDummy method testLiveSyncAddDrake.

public void testLiveSyncAddDrake(final String TEST_NAME, DummySyncStyle syncStyle, QName objectClass) throws Exception {
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    OperationResult result = new OperationResult(TestDummy.class.getName() + "." + TEST_NAME);
    syncServiceMock.reset();
    dummyResource.setSyncStyle(syncStyle);
    DummyAccount newAccount = new DummyAccount(DRAKE_USERNAME);
    newAccount.addAttributeValues("fullname", "Sir Francis Drake");
    newAccount.setEnabled(true);
    newAccount.setPassword("avast!");
    dummyResource.addAccount(newAccount);
    drakeIcfUid = newAccount.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);
    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", 3, attributes.size());
    ResourceAttribute<?> fullnameAttribute = attributesContainer.findAttribute(new QName(ResourceTypeUtil.getResourceNamespace(resourceType), "fullname"));
    assertNotNull("No fullname attribute in current shadow", fullnameAttribute);
    assertEquals("Wrong value of fullname attribute in current shadow", "Sir Francis Drake", fullnameAttribute.getRealValue());
    drakeAccountOid = currentShadowType.getOid();
    PrismObject<ShadowType> repoShadow = repositoryService.getObject(ShadowType.class, drakeAccountOid, null, result);
    display("Drake repo shadow", repoShadow);
    PrismObject<ShadowType> accountRepo = findAccountShadowByUsername(getDrakeRepoIcfName(), resource, result);
    assertNotNull("Shadow was not created in the repository", accountRepo);
    display("Repository shadow", accountRepo);
    checkRepoAccountShadow(accountRepo);
    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) DummyAccount(com.evolveum.icf.dummy.resource.DummyAccount)

Example 22 with ResourceObjectShadowChangeDescription

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

the class TestDummy method test801LiveSyncAddBlackbeard.

@Test
public void test801LiveSyncAddBlackbeard() throws Exception {
    final String TEST_NAME = "test801LiveSyncAddBlackbeard";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestDummy.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    syncServiceMock.reset();
    dummyResource.setSyncStyle(DummySyncStyle.DUMB);
    DummyAccount newAccount = new DummyAccount(BLACKBEARD_USERNAME);
    newAccount.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME, "Edward Teach");
    newAccount.addAttributeValue(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_LOOT_NAME, 66666L);
    newAccount.setEnabled(true);
    newAccount.setPassword("shiverMEtimbers");
    dummyResource.addAccount(newAccount);
    blackbeardIcfUid = newAccount.getId();
    display("Resource before sync", dummyResource.debugDump());
    ResourceShadowDiscriminator coords = new ResourceShadowDiscriminator(RESOURCE_DUMMY_OID, ProvisioningTestUtil.getDefaultAccountObjectClass(resourceType));
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    provisioningService.synchronize(coords, syncTokenTask, result);
    // THEN
    result.computeStatus();
    display("Synchronization result", result);
    TestUtil.assertSuccess("Synchronization result is not OK", result);
    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());
    assertNull("Delta present when not expecting it", lastChange.getObjectDelta());
    PrismObject<ShadowType> currentShadow = lastChange.getCurrentShadow();
    assertNotNull("Current shadow missing", lastChange.getCurrentShadow());
    assertTrue("Wrong type of current shadow: " + currentShadow.getClass().getName(), currentShadow.canRepresent(ShadowType.class));
    ResourceAttributeContainer attributesContainer = ShadowUtil.getAttributesContainer(currentShadow);
    assertNotNull("No attributes container in current shadow", attributesContainer);
    Collection<ResourceAttribute<?>> attributes = attributesContainer.getAttributes();
    assertFalse("Attributes container is empty", attributes.isEmpty());
    assertAttribute(currentShadow, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME, "Edward Teach");
    assertAttribute(currentShadow, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_LOOT_NAME, 66666L);
    assertEquals("Unexpected number of attributes", 4, attributes.size());
    PrismObject<ShadowType> accountRepo = findAccountShadowByUsername(getBlackbeardRepoIcfName(), resource, result);
    assertNotNull("Shadow was not created in the repository", accountRepo);
    display("Repository shadow", accountRepo);
    checkRepoAccountShadow(accountRepo);
    checkAllShadows();
    assertSteadyResource();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) 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) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator) ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute) DummyAccount(com.evolveum.icf.dummy.resource.DummyAccount) Test(org.testng.annotations.Test)

Example 23 with ResourceObjectShadowChangeDescription

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

the class TestDummy method testLiveSyncModifyDrake.

public void testLiveSyncModifyDrake(final String TEST_NAME, DummySyncStyle syncStyle, QName objectClass) throws Exception {
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    OperationResult result = new OperationResult(TestDummy.class.getName() + "." + TEST_NAME);
    syncServiceMock.reset();
    dummyResource.setSyncStyle(syncStyle);
    DummyAccount dummyAccount = getDummyAccountAssert(DRAKE_USERNAME, drakeIcfUid);
    dummyAccount.replaceAttributeValue("fullname", "Captain Drake");
    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);
    syncServiceMock.assertNotifyChange();
    ResourceObjectShadowChangeDescription lastChange = syncServiceMock.getLastChange();
    display("The change", lastChange);
    PrismObject<? extends ShadowType> oldShadow = lastChange.getOldShadow();
    assertSyncOldShadow(oldShadow, getDrakeRepoIcfName());
    assertNull("Delta present when not expecting it", lastChange.getObjectDelta());
    PrismObject<ShadowType> currentShadow = lastChange.getCurrentShadow();
    assertNotNull("Current shadow missing", lastChange.getCurrentShadow());
    assertTrue("Wrong type of current shadow: " + currentShadow.getClass().getName(), currentShadow.canRepresent(ShadowType.class));
    ResourceAttributeContainer attributesContainer = ShadowUtil.getAttributesContainer(currentShadow);
    assertNotNull("No attributes container in current shadow", attributesContainer);
    Collection<ResourceAttribute<?>> attributes = attributesContainer.getAttributes();
    assertFalse("Attributes container is empty", attributes.isEmpty());
    assertAttribute(currentShadow, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME, "Captain Drake");
    assertEquals("Unexpected number of attributes", 3, attributes.size());
    PrismObject<ShadowType> accountRepo = findAccountShadowByUsername(getDrakeRepoIcfName(), resource, result);
    assertNotNull("Shadow was not created in the repository", accountRepo);
    display("Repository shadow", accountRepo);
    checkRepoAccountShadow(accountRepo);
    checkAllShadows();
    assertSteadyResource();
}
Also used : 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) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator) ResourceAttributeContainer(com.evolveum.midpoint.schema.processor.ResourceAttributeContainer) ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute) DummyAccount(com.evolveum.icf.dummy.resource.DummyAccount)

Example 24 with ResourceObjectShadowChangeDescription

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

the class TestDummy method testLiveSyncDeleteDrake.

public void testLiveSyncDeleteDrake(final String TEST_NAME, DummySyncStyle syncStyle, QName objectClass) throws Exception {
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    OperationResult result = new OperationResult(TestDummy.class.getName() + "." + TEST_NAME);
    syncServiceMock.reset();
    dummyResource.setSyncStyle(syncStyle);
    if (isNameUnique()) {
        dummyResource.deleteAccountByName(DRAKE_USERNAME);
    } else {
        dummyResource.deleteAccountById(drakeIcfUid);
    }
    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);
    syncServiceMock.assertNotifyChange();
    ResourceObjectShadowChangeDescription lastChange = syncServiceMock.getLastChange();
    display("The change", lastChange);
    PrismObject<? extends ShadowType> oldShadow = lastChange.getOldShadow();
    assertSyncOldShadow(oldShadow, getDrakeRepoIcfName());
    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, drakeAccountOid, null, result);
        AssertJUnit.fail("The shadow " + repoShadow + " is not gone from repo");
    } catch (ObjectNotFoundException e) {
    // This is expected
    }
    checkAllShadows();
    assertSteadyResource();
}
Also used : ResourceObjectShadowChangeDescription(com.evolveum.midpoint.provisioning.api.ResourceObjectShadowChangeDescription) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator)

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