Search in sources :

Example 21 with ResourceShadowDiscriminator

use of com.evolveum.midpoint.schema.ResourceShadowDiscriminator in project midpoint by Evolveum.

the class AbstractBasicDummyTest method test080TestAttributesToReturn.

// The account must exist to test this with modify delta. So we postpone the
// test when the account actually exists
@Test
public void test080TestAttributesToReturn() throws Exception {
    final String TEST_NAME = "test080TestAttributesToReturn";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance();
    OperationResult result = task.getResult();
    ResourceShadowDiscriminator coords = new ResourceShadowDiscriminator(RESOURCE_DUMMY_OID, ShadowKindType.ENTITLEMENT, RESOURCE_DUMMY_INTENT_GROUP);
    ProvisioningContext ctx = provisioningContextFactory.create(coords, task, result);
    // WHEN
    AttributesToReturn attributesToReturn = ProvisioningUtil.createAttributesToReturn(ctx);
    // THEN
    display("attributesToReturn", attributesToReturn);
    assertFalse("wrong isReturnDefaultAttributes", attributesToReturn.isReturnDefaultAttributes());
    Collection<String> attrs = new ArrayList<>();
    for (ResourceAttributeDefinition attributeToReturnDef : attributesToReturn.getAttributesToReturn()) {
        attrs.add(attributeToReturnDef.getName().getLocalPart());
    }
    // No "memebers" attribute here
    PrismAsserts.assertSets("Wrong attribute to return", attrs, "uid", "name", "description", "cc");
    assertSteadyResource();
}
Also used : ProvisioningContext(com.evolveum.midpoint.provisioning.impl.ProvisioningContext) AttributesToReturn(com.evolveum.midpoint.provisioning.ucf.api.AttributesToReturn) Task(com.evolveum.midpoint.task.api.Task) ResourceAttributeDefinition(com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator) Test(org.testng.annotations.Test)

Example 22 with ResourceShadowDiscriminator

use of com.evolveum.midpoint.schema.ResourceShadowDiscriminator 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 23 with ResourceShadowDiscriminator

use of com.evolveum.midpoint.schema.ResourceShadowDiscriminator 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 24 with ResourceShadowDiscriminator

use of com.evolveum.midpoint.schema.ResourceShadowDiscriminator in project midpoint by Evolveum.

the class TestEditSchema method test263EditShadowSchemaEmpty.

@Test
public void test263EditShadowSchemaEmpty() throws Exception {
    final String TEST_NAME = "test263EditShadowSchemaEmpty";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestEditSchema.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    ResourceShadowDiscriminator discr = new ResourceShadowDiscriminator(null, null);
    IntegrationTestTools.display("Discr", discr);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    PrismObjectDefinition<ShadowType> editDef = modelInteractionService.getEditShadowDefinition(discr, AuthorizationPhaseType.REQUEST, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    PrismPropertyDefinition<PolyString> nameDef = editDef.findPropertyDefinition(ShadowType.F_NAME);
    assertNotNull("No definition for name in shadow", nameDef);
    assertEquals("Wrong shadow name displayName", "ObjectType.name", nameDef.getDisplayName());
    assertTrue("additionalName not readable", nameDef.canRead());
    PrismPropertyDefinition<Object> attrFullNameDef = editDef.findPropertyDefinition(dummyResourceCtl.getAttributeFullnamePath());
    assertNull("Unexpected definition for fullname attribute in shadow", attrFullNameDef);
    assertSteadyResources();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator) PrismObject(com.evolveum.midpoint.prism.PrismObject) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) Test(org.testng.annotations.Test)

Example 25 with ResourceShadowDiscriminator

use of com.evolveum.midpoint.schema.ResourceShadowDiscriminator in project midpoint by Evolveum.

the class TestEditSchema method test261EditShadowSchemaObjectclass.

@Test
public void test261EditShadowSchemaObjectclass() throws Exception {
    final String TEST_NAME = "test261EditShadowSchemaObjectclass";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestEditSchema.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    ResourceShadowDiscriminator discr = new ResourceShadowDiscriminator(RESOURCE_DUMMY_OID, dummyResourceCtl.getAccountObjectClassQName());
    IntegrationTestTools.display("Discr", discr);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    PrismObjectDefinition<ShadowType> editDef = modelInteractionService.getEditShadowDefinition(discr, AuthorizationPhaseType.REQUEST, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    PrismPropertyDefinition<PolyString> nameDef = editDef.findPropertyDefinition(ShadowType.F_NAME);
    assertNotNull("No definition for name in shadow", nameDef);
    assertEquals("Wrong shadow name displayName", "ObjectType.name", nameDef.getDisplayName());
    assertTrue("additionalName not readable", nameDef.canRead());
    PrismPropertyDefinition<Object> attrFullNameDef = editDef.findPropertyDefinition(dummyResourceCtl.getAttributeFullnamePath());
    assertNotNull("No definition for fullname attribute in shadow", attrFullNameDef);
    assertEquals("Wrong shadow fullname attribute displayName", "Full Name", attrFullNameDef.getDisplayName());
    assertTrue("additionalName not readable", attrFullNameDef.canRead());
    assertSteadyResources();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator) PrismObject(com.evolveum.midpoint.prism.PrismObject) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) Test(org.testng.annotations.Test)

Aggregations

ResourceShadowDiscriminator (com.evolveum.midpoint.schema.ResourceShadowDiscriminator)78 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)41 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)34 Task (com.evolveum.midpoint.task.api.Task)30 Test (org.testng.annotations.Test)30 LensProjectionContext (com.evolveum.midpoint.model.impl.lens.LensProjectionContext)28 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)18 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)17 ResourceObjectShadowChangeDescription (com.evolveum.midpoint.provisioning.api.ResourceObjectShadowChangeDescription)17 ModelProjectionContext (com.evolveum.midpoint.model.api.context.ModelProjectionContext)11 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)10 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)10 DummyAccount (com.evolveum.icf.dummy.resource.DummyAccount)9 ModelExecuteOptions (com.evolveum.midpoint.model.api.ModelExecuteOptions)9 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)9 AbstractInternalModelIntegrationTest (com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)8 MockLensDebugListener (com.evolveum.midpoint.model.impl.util.mock.MockLensDebugListener)8 PrismObject (com.evolveum.midpoint.prism.PrismObject)8 QName (javax.xml.namespace.QName)7 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)6