Search in sources :

Example 71 with ResourceShadowDiscriminator

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

the class TestPreviewChanges method test610ModifyElaineUserAccountDummyReplace.

/**
	 * Changing USER fullName (replace delta), change account fullname (replace delta).
	 */
@Test
public void test610ModifyElaineUserAccountDummyReplace() throws Exception {
    final String TEST_NAME = "test610ModifyElaineUserAccountDummyReplace";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestPreviewChanges.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    assumeAssignmentPolicy(AssignmentPolicyEnforcementType.NONE);
    ObjectDelta<UserType> userDelta = createModifyUserReplaceDelta(USER_ELAINE_OID, UserType.F_FULL_NAME, PrismTestUtil.createPolyString("Elaine Threepwood"));
    ObjectDelta<ShadowType> accountDelta = createModifyAccountShadowReplaceAttributeDelta(ACCOUNT_SHADOW_ELAINE_DUMMY_OID, getDummyResourceObject(), DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME, "Elaine LeChuck");
    // Cannot change the attribute on RED resource. It would conflict with the strong mapping and therefore fail.
    //        ObjectDelta<ResourceObjectShadowType> accountDeltaRed = createModifyAccountShadowReplaceAttributeDelta(
    //        		ACCOUNT_SHADOW_ELAINE_DUMMY_RED_OID, resourceDummyRed, 
    //        		DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME, "Elaine LeChuck");
    ObjectDelta<ShadowType> accountDeltaBlue = createModifyAccountShadowReplaceAttributeDelta(ACCOUNT_SHADOW_ELAINE_DUMMY_BLUE_OID, resourceDummyBlue, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME, "Elaine LeChuck");
    Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta, accountDelta, accountDeltaBlue);
    display("Input deltas: ", deltas);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    ModelContext<UserType> modelContext = modelInteractionService.previewChanges(deltas, new ModelExecuteOptions(), task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    display("Preview context", modelContext);
    assertNotNull("Null model context", modelContext);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    ModelElementContext<UserType> focusContext = modelContext.getFocusContext();
    assertNotNull("Null model focus context", focusContext);
    ObjectDelta<UserType> userPrimaryDelta = focusContext.getPrimaryDelta();
    assertNotNull("No focus primary delta: " + userPrimaryDelta, userPrimaryDelta);
    PrismAsserts.assertModifications(userPrimaryDelta, 1);
    PrismAsserts.assertPropertyReplace(userPrimaryDelta, UserType.F_FULL_NAME, PrismTestUtil.createPolyString("Elaine Threepwood"));
    ObjectDelta<UserType> userSecondaryDelta = focusContext.getSecondaryDelta();
    assertSideEffectiveDeltasOnly("focus secondary delta", userSecondaryDelta);
    Collection<? extends ModelProjectionContext> projectionContexts = modelContext.getProjectionContexts();
    assertNotNull("Null model projection context list", projectionContexts);
    assertEquals("Unexpected number of projection contexts", 3, projectionContexts.size());
    // DEFAULT dummy resource: normal mappings
    ModelProjectionContext accContext = modelContext.findProjectionContext(new ResourceShadowDiscriminator(RESOURCE_DUMMY_OID, ShadowKindType.ACCOUNT, null));
    assertNotNull("Null model projection context (default)", accContext);
    assertEquals("Wrong policy decision (default)", SynchronizationPolicyDecision.KEEP, accContext.getSynchronizationPolicyDecision());
    ObjectDelta<ShadowType> accountPrimaryDelta = accContext.getPrimaryDelta();
    assertNotNull("No account primary delta (default)", accountPrimaryDelta);
    PrismAsserts.assertModifications(accountPrimaryDelta, 1);
    PrismAsserts.assertPropertyReplace(accountPrimaryDelta, getAttributePath(getDummyResourceObject(), DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME), "Elaine LeChuck");
    ObjectDelta<ShadowType> accountSecondaryDelta = accContext.getSecondaryDelta();
    assertEquals("Unexpected size of account secondary delta (default): " + accountSecondaryDelta, 2, accountSecondaryDelta.getModifications().size());
    PrismAsserts.assertPropertyAdd(accountSecondaryDelta, dummyResourceCtl.getAttributePath(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_DRINK_NAME), "rum");
    PrismAsserts.assertPropertyAdd(accountSecondaryDelta, dummyResourceCtl.getAttributePath(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_QUOTE_NAME), "Arr!");
    // RED dummy resource: strong mappings
    accContext = modelContext.findProjectionContext(new ResourceShadowDiscriminator(RESOURCE_DUMMY_RED_OID, ShadowKindType.ACCOUNT, null));
    assertNotNull("Null model projection context (red)", accContext);
    assertEquals("Wrong policy decision", SynchronizationPolicyDecision.KEEP, accContext.getSynchronizationPolicyDecision());
    accountPrimaryDelta = accContext.getPrimaryDelta();
    assertNull("Unexpected account primary delta (red)", accountPrimaryDelta);
    accountSecondaryDelta = accContext.getSecondaryDelta();
    assertNotNull("No account secondary delta (red)", accountSecondaryDelta);
    PrismAsserts.assertModifications(accountSecondaryDelta, 2);
    PrismAsserts.assertPropertyReplace(accountSecondaryDelta, getAttributePath(getDummyResourceObject(RESOURCE_DUMMY_RED_NAME), DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME), "Elaine Threepwood");
    PrismAsserts.assertPropertyAdd(accountSecondaryDelta, getAttributePath(getDummyResourceObject(RESOURCE_DUMMY_RED_NAME), DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_QUOTE_NAME), "null -- red resource");
    // BLUE dummy resource: weak mappings
    accContext = modelContext.findProjectionContext(new ResourceShadowDiscriminator(RESOURCE_DUMMY_BLUE_OID, ShadowKindType.ACCOUNT, null));
    assertNotNull("Null model projection context (blue)", accContext);
    assertEquals("Wrong policy decision", SynchronizationPolicyDecision.KEEP, accContext.getSynchronizationPolicyDecision());
    accountPrimaryDelta = accContext.getPrimaryDelta();
    assertNotNull("No account primary delta (blue)", accountPrimaryDelta);
    PrismAsserts.assertModifications(accountPrimaryDelta, 1);
    PrismAsserts.assertPropertyReplace(accountPrimaryDelta, getAttributePath(resourceDummyBlue, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME), "Elaine LeChuck");
    accountSecondaryDelta = accContext.getSecondaryDelta();
    PrismAsserts.assertModifications("account secondary delta (blue)", accountSecondaryDelta, 3);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ModelExecuteOptions(com.evolveum.midpoint.model.api.ModelExecuteOptions) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator) ModelProjectionContext(com.evolveum.midpoint.model.api.context.ModelProjectionContext) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test)

Example 72 with ResourceShadowDiscriminator

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

the class TestDummy method test890LiveSyncModifyProtectedAccount.

@Test
public void test890LiveSyncModifyProtectedAccount() throws Exception {
    final String TEST_NAME = "test890LiveSyncModifyProtectedAccount";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    Task syncTask = taskManager.createTaskInstance(TestDummy.class.getName() + "." + TEST_NAME);
    OperationResult result = syncTask.getResult();
    syncServiceMock.reset();
    DummyAccount dummyAccount = getDummyAccountAssert(ACCOUNT_DAEMON_USERNAME, daemonIcfUid);
    dummyAccount.replaceAttributeValue("fullname", "Maxwell deamon");
    ResourceShadowDiscriminator coords = new ResourceShadowDiscriminator(RESOURCE_DUMMY_OID, ProvisioningTestUtil.getDefaultAccountObjectClass(resourceType));
    // 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);
    ResourceObjectShadowChangeDescription lastChange = syncServiceMock.getLastChange();
    display("The change", lastChange);
    syncServiceMock.assertNoNotifyChange();
    checkAllShadows();
    assertSteadyResource();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ResourceObjectShadowChangeDescription(com.evolveum.midpoint.provisioning.api.ResourceObjectShadowChangeDescription) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator) DummyAccount(com.evolveum.icf.dummy.resource.DummyAccount) Test(org.testng.annotations.Test)

Example 73 with ResourceShadowDiscriminator

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

the class TestDummy method test802LiveSyncModifyBlackbeard.

@Test
public void test802LiveSyncModifyBlackbeard() throws Exception {
    final String TEST_NAME = "test802LiveSyncModifyBlackbeard";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    OperationResult result = new OperationResult(TestDummy.class.getName() + "." + TEST_NAME);
    syncServiceMock.reset();
    DummyAccount dummyAccount = getDummyAccountAssert(BLACKBEARD_USERNAME, blackbeardIcfUid);
    dummyAccount.replaceAttributeValue("fullname", "Captain Blackbeard");
    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();
    assertSyncOldShadow(oldShadow, getBlackbeardRepoIcfName());
    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 Blackbeard");
    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 : 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) Test(org.testng.annotations.Test)

Example 74 with ResourceShadowDiscriminator

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

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

the class TestDummy method test800LiveSyncInit.

@Test
public void test800LiveSyncInit() throws Exception {
    final String TEST_NAME = "test800LiveSyncInit";
    TestUtil.displayTestTile(TEST_NAME);
    syncTokenTask = taskManager.createTaskInstance(TestDummy.class.getName() + ".syncTask");
    dummyResource.setSyncStyle(DummySyncStyle.DUMB);
    syncServiceMock.reset();
    OperationResult result = new OperationResult(TestDummy.class.getName() + ".test800LiveSyncInit");
    // Dry run to remember the current sync token in the task instance.
    // Otherwise a last sync token whould be used and
    // no change would be detected
    ResourceShadowDiscriminator coords = new ResourceShadowDiscriminator(RESOURCE_DUMMY_OID, ProvisioningTestUtil.getDefaultAccountObjectClass(resourceType));
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    provisioningService.synchronize(coords, syncTokenTask, result);
    // THEN
    result.computeStatus();
    display("modifyObject result", result);
    TestUtil.assertSuccess(result);
    // No change, no fun
    syncServiceMock.assertNoNotifyChange();
    checkAllShadows();
    assertSteadyResource();
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator) 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