Search in sources :

Example 31 with ResourceAttributeContainer

use of com.evolveum.midpoint.schema.processor.ResourceAttributeContainer 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 32 with ResourceAttributeContainer

use of com.evolveum.midpoint.schema.processor.ResourceAttributeContainer 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 33 with ResourceAttributeContainer

use of com.evolveum.midpoint.schema.processor.ResourceAttributeContainer in project midpoint by Evolveum.

the class ResourceObjectPattern method matches.

public boolean matches(PrismObject<ShadowType> shadowToMatch, MatchingRuleRegistry matchingRuleRegistry) throws SchemaException {
    if (objectFilter != null) {
        // we suppose references in shadowToMatch are normalized (on return from repo)
        ObjectTypeUtil.normalizeFilter(objectFilter);
        return ObjectQuery.match(shadowToMatch, objectFilter, matchingRuleRegistry);
    } else {
        // Deprecated method
        ResourceAttributeContainer attributesContainer = ShadowUtil.getAttributesContainer(shadowToMatch);
        if (attributesContainer == null) {
            return false;
        }
        Collection<ResourceAttribute<?>> attributesToMatch = attributesContainer.getAttributes();
        for (ResourceAttribute<?> identifier : identifiers) {
            if (!matches(identifier, attributesToMatch, matchingRuleRegistry)) {
                return false;
            }
        }
        return true;
    }
}
Also used : ResourceAttributeContainer(com.evolveum.midpoint.schema.processor.ResourceAttributeContainer) ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute)

Aggregations

ResourceAttributeContainer (com.evolveum.midpoint.schema.processor.ResourceAttributeContainer)33 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)20 ResourceAttribute (com.evolveum.midpoint.schema.processor.ResourceAttribute)16 QName (javax.xml.namespace.QName)16 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)13 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)11 Test (org.testng.annotations.Test)8 DummyAccount (com.evolveum.icf.dummy.resource.DummyAccount)6 ResourceObjectShadowChangeDescription (com.evolveum.midpoint.provisioning.api.ResourceObjectShadowChangeDescription)6 ResourceShadowDiscriminator (com.evolveum.midpoint.schema.ResourceShadowDiscriminator)6 PrismObject (com.evolveum.midpoint.prism.PrismObject)5 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)5 Task (com.evolveum.midpoint.task.api.Task)5 ShadowAssociationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAssociationType)5 RefinedAttributeDefinition (com.evolveum.midpoint.common.refinery.RefinedAttributeDefinition)4 RefinedObjectClassDefinition (com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition)4 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)4 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)3 PropertyModificationOperation (com.evolveum.midpoint.provisioning.ucf.api.PropertyModificationOperation)3 ObjectClassComplexTypeDefinition (com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition)3