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);
}
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();
}
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();
}
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;
}
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);
}
Aggregations