use of com.evolveum.midpoint.prism.delta.ReferenceDelta in project midpoint by Evolveum.
the class ConsistencyTest method test124AddAccountDirectAlreadyExists.
//MID-1595, MID-1577
@Test
public void test124AddAccountDirectAlreadyExists() throws Exception {
final String TEST_NAME = "test124AddAccountDirectAlreadyExists";
TestUtil.displayTestTile(TEST_NAME);
OperationResult parentResult = new OperationResult(TEST_NAME);
Task task = taskManager.createTaskInstance();
SchemaHandlingType oldSchemaHandling = resourceTypeOpenDjrepo.getSchemaHandling();
SynchronizationType oldSynchronization = resourceTypeOpenDjrepo.getSynchronization();
try {
// we will reapply this schema handling after this test finish
ItemDefinition syncDef = resourceTypeOpenDjrepo.asPrismObject().getDefinition().findItemDefinition(ResourceType.F_SYNCHRONIZATION);
assertNotNull("null definition for sync delta", syncDef);
ObjectDeltaType omt = unmarshallValueFromFile(REQUEST_RESOURCE_MODIFY_SYNCHRONIZATION, ObjectDeltaType.class);
ObjectDelta objectDelta = DeltaConvertor.createObjectDelta(omt, prismContext);
repositoryService.modifyObject(ResourceType.class, RESOURCE_OPENDJ_OID, objectDelta.getModifications(), parentResult);
requestToExecuteChanges(REQUEST_RESOURCE_MODIFY_RESOURCE_SCHEMA, RESOURCE_OPENDJ_OID, ResourceType.class, task, null, parentResult);
PrismObject<ResourceType> res = repositoryService.getObject(ResourceType.class, RESOURCE_OPENDJ_OID, null, parentResult);
// LOGGER.trace("resource schema handling after modify: {}",
// prismContext.silentMarshalObject(res.asObjectable(), LOGGER));
repoAddObjectFromFile(USER_ABOMBA_FILENAME, parentResult);
requestToExecuteChanges(REQUEST_USER_MODIFY_ADD_ACCOUNT_DIRECTLY, USER_ABOMBA_OID, UserType.class, task, null, parentResult);
String abombaOid = assertUserOneAccountRef(USER_ABOMBA_OID);
ShadowType abombaShadow = repositoryService.getObject(ShadowType.class, abombaOid, null, parentResult).asObjectable();
assertShadowName(abombaShadow, "uid=abomba,OU=people,DC=example,DC=com");
repoAddObjectFromFile(USER_ABOM_FILENAME, parentResult);
requestToExecuteChanges(REQUEST_USER_MODIFY_ADD_ACCOUNT_DIRECTLY, USER_ABOM_OID, UserType.class, task, null, parentResult);
String abomOid = assertUserOneAccountRef(USER_ABOM_OID);
ShadowType abomShadow = repositoryService.getObject(ShadowType.class, abomOid, null, parentResult).asObjectable();
assertShadowName(abomShadow, "uid=abomba1,OU=people,DC=example,DC=com");
ReferenceDelta abombaDeleteAccDelta = ReferenceDelta.createModificationDelete(ShadowType.class, UserType.F_LINK_REF, prismContext, new PrismReferenceValue(abombaOid));
ObjectDelta d = ObjectDelta.createModifyDelta(USER_ABOMBA_OID, abombaDeleteAccDelta, UserType.class, prismContext);
modelService.executeChanges(MiscSchemaUtil.createCollection(d), null, task, parentResult);
assertUserNoAccountRef(USER_ABOMBA_OID, parentResult);
repositoryService.getObject(ShadowType.class, abombaOid, null, parentResult);
ReferenceDelta abomDeleteAccDelta = ReferenceDelta.createModificationDelete(ShadowType.class, UserType.F_LINK_REF, prismContext, abomShadow.asPrismObject());
ObjectDelta d2 = ObjectDelta.createModifyDelta(USER_ABOM_OID, abomDeleteAccDelta, UserType.class, prismContext);
modelService.executeChanges(MiscSchemaUtil.createCollection(d2), null, task, parentResult);
assertUserNoAccountRef(USER_ABOM_OID, parentResult);
try {
repositoryService.getObject(ShadowType.class, abomOid, null, parentResult);
fail("Expected that shadow abom does not exist, but it is");
} catch (ObjectNotFoundException ex) {
// this is expected
} catch (Exception ex) {
fail("Expected object not found exception but got " + ex);
}
LOGGER.info("starting second execution request for user abomba");
OperationResult result = new OperationResult("Add account already exist result.");
requestToExecuteChanges(REQUEST_USER_MODIFY_ADD_ACCOUNT_DIRECTLY, USER_ABOMBA_OID, UserType.class, task, null, result);
String abombaOid2 = assertUserOneAccountRef(USER_ABOMBA_OID);
ShadowType abombaShadow2 = repositoryService.getObject(ShadowType.class, abombaOid2, null, result).asObjectable();
assertShadowName(abombaShadow2, "uid=abomba,OU=people,DC=example,DC=com");
result.computeStatus();
LOGGER.info("Displaying execute changes result");
display(result);
// return the previous changes of resource back
Collection<? extends ItemDelta> schemaHandlingDelta = ContainerDelta.createModificationReplaceContainerCollection(ResourceType.F_SCHEMA_HANDLING, resourceTypeOpenDjrepo.asPrismObject().getDefinition(), oldSchemaHandling.asPrismContainerValue().clone());
PropertyDelta syncDelta = PropertyDelta.createModificationReplaceProperty(ResourceType.F_SYNCHRONIZATION, resourceTypeOpenDjrepo.asPrismObject().getDefinition(), oldSynchronization);
((Collection) schemaHandlingDelta).add(syncDelta);
repositoryService.modifyObject(ResourceType.class, RESOURCE_OPENDJ_OID, schemaHandlingDelta, parentResult);
} catch (Exception ex) {
LOGGER.info("error: " + ex.getMessage(), ex);
throw ex;
}
}
use of com.evolveum.midpoint.prism.delta.ReferenceDelta in project midpoint by Evolveum.
the class TestModelServiceContract method test099ModifyUserAddAccountFailing.
@Test(enabled = true)
public void test099ModifyUserAddAccountFailing() throws Exception {
TestUtil.displayTestTile(this, "test099ModifyUserAddAccountFailing");
// GIVEN
Task task = taskManager.createTaskInstance(TestModelServiceContract.class.getName() + ".test099ModifyUserAddAccountFailing");
OperationResult result = task.getResult();
preTestCleanup(AssignmentPolicyEnforcementType.POSITIVE);
PrismObject<ShadowType> account = PrismTestUtil.parseObject(ACCOUNT_JACK_DUMMY_FILE);
ObjectDelta<UserType> userDelta = ObjectDelta.createEmptyModifyDelta(UserType.class, USER_JACK_OID, prismContext);
PrismReferenceValue accountRefVal = new PrismReferenceValue();
accountRefVal.setObject(account);
ReferenceDelta accountDelta = ReferenceDelta.createModificationAdd(UserType.F_LINK_REF, getUserDefinition(), accountRefVal);
userDelta.addModification(accountDelta);
// the following modifies nothing but it is used to produce a user-level notification (LINK_REF by itself causes no such notification)
PropertyDelta<String> attributeDelta = PropertyDelta.createReplaceDeltaOrEmptyDelta(getUserDefinition(), UserType.F_TELEPHONE_NUMBER, "555-1234");
userDelta.addModification(attributeDelta);
Collection<ObjectDelta<? extends ObjectType>> deltas = (Collection) MiscUtil.createCollection(userDelta);
// hopefully this does not kick consistency mechanism
getDummyResource().setAddBreakMode(BreakMode.UNSUPPORTED);
// WHEN
modelService.executeChanges(deltas, null, task, result);
// THEN
result.computeStatus();
TestUtil.assertFailure(result);
assertShadowFetchOperationCountIncrement(0);
// Check accountRef
PrismObject<UserType> userJack = modelService.getObject(UserType.class, USER_JACK_OID, null, task, result);
assertUserJack(userJack);
UserType userJackType = userJack.asObjectable();
assertEquals("Unexpected number of accountRefs", 0, userJackType.getLinkRef().size());
// // Check audit
// display("Audit", dummyAuditService);
// dummyAuditService.assertRecords(2);
// dummyAuditService.assertSimpleRecordSanity();
// dummyAuditService.assertAnyRequestDeltas();
// dummyAuditService.assertExecutionDeltas(3);
// dummyAuditService.asserHasDelta(ChangeType.MODIFY, UserType.class);
// dummyAuditService.asserHasDelta(ChangeType.ADD, ShadowType.class);
// dummyAuditService.assertTarget(USER_JACK_OID);
// dummyAuditService.assertExecutionSuccess();
notificationManager.setDisabled(true);
getDummyResource().resetBreakMode();
// Check notifications
checkDummyTransportMessages("accountPasswordNotifier", 0);
checkDummyTransportMessages("userPasswordNotifier", 0);
checkDummyTransportMessages("simpleAccountNotifier-SUCCESS", 0);
// actually I don't know why provisioning does not report unsupported operation as a failure...
checkDummyTransportMessages("simpleAccountNotifier-FAILURE", 0);
checkDummyTransportMessages("simpleAccountNotifier-ADD-SUCCESS", 0);
checkDummyTransportMessages("simpleUserNotifier", 1);
checkDummyTransportMessages("simpleUserNotifier-ADD", 0);
checkDummyTransportMessages("simpleUserNotifier-FAILURE", 1);
assertSteadyResources();
}
use of com.evolveum.midpoint.prism.delta.ReferenceDelta in project midpoint by Evolveum.
the class TestModelServiceContract method test108ModifyUserAddAccountAgain.
@Test
public void test108ModifyUserAddAccountAgain() throws Exception {
TestUtil.displayTestTile(this, "test108ModifyUserAddAccountAgain");
// GIVEN
Task task = taskManager.createTaskInstance(TestModelServiceContract.class.getName() + ".test108ModifyUserAddAccountAgain");
OperationResult result = task.getResult();
preTestCleanup(AssignmentPolicyEnforcementType.POSITIVE);
PrismObject<ShadowType> account = PrismTestUtil.parseObject(ACCOUNT_JACK_DUMMY_FILE);
ObjectDelta<UserType> userDelta = ObjectDelta.createEmptyModifyDelta(UserType.class, USER_JACK_OID, prismContext);
PrismReferenceValue accountRefVal = new PrismReferenceValue();
accountRefVal.setObject(account);
ReferenceDelta accountDelta = ReferenceDelta.createModificationAdd(UserType.F_LINK_REF, getUserDefinition(), accountRefVal);
userDelta.addModification(accountDelta);
Collection<ObjectDelta<? extends ObjectType>> deltas = (Collection) MiscUtil.createCollection(userDelta);
try {
// WHEN
modelService.executeChanges(deltas, null, task, result);
// THEN
assert false : "Expected executeChanges operation to fail but it has obviously succeeded";
} catch (SchemaException e) {
// This is expected
e.printStackTrace();
// THEN
String message = e.getMessage();
assertMessageContains(message, "already contains account");
assertMessageContains(message, "default");
}
assertShadowFetchOperationCountIncrement(0);
// Check audit
display("Audit", dummyAuditService);
dummyAuditService.assertSimpleRecordSanity();
dummyAuditService.assertRecords(2);
dummyAuditService.assertAnyRequestDeltas();
dummyAuditService.assertTarget(USER_JACK_OID);
dummyAuditService.assertExecutionOutcome(OperationResultStatus.FATAL_ERROR);
assertSteadyResources();
}
use of com.evolveum.midpoint.prism.delta.ReferenceDelta in project midpoint by Evolveum.
the class TestStrangeCases method test100ModifyUserGuybrushAddAccountDummyRedNoAttributesConflict.
@Test
public void test100ModifyUserGuybrushAddAccountDummyRedNoAttributesConflict() throws Exception {
final String TEST_NAME = "test100ModifyUserGuybrushAddAccountDummyRedNoAttributesConflict";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestStrangeCases.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.NONE);
PrismObject<ShadowType> account = PrismTestUtil.parseObject(ACCOUNT_GUYBRUSH_DUMMY_RED_FILE);
// Remove the attributes. This will allow outbound mapping to take place instead.
account.removeContainer(ShadowType.F_ATTRIBUTES);
ObjectDelta<UserType> userDelta = ObjectDelta.createEmptyModifyDelta(UserType.class, USER_GUYBRUSH_OID, prismContext);
PrismReferenceValue accountRefVal = new PrismReferenceValue();
accountRefVal.setObject(account);
ReferenceDelta accountDelta = ReferenceDelta.createModificationAdd(UserType.F_LINK_REF, getUserDefinition(), accountRefVal);
userDelta.addModification(accountDelta);
Collection<ObjectDelta<? extends ObjectType>> deltas = (Collection) MiscUtil.createCollection(userDelta);
dummyAuditService.clear();
try {
// WHEN
modelService.executeChanges(deltas, null, task, getCheckingProgressListenerCollection(), result);
AssertJUnit.fail("Unexpected executeChanges success");
} catch (ObjectAlreadyExistsException e) {
// This is expected
display("Expected exception", e);
}
// Check accountRef
PrismObject<UserType> userGuybrush = modelService.getObject(UserType.class, USER_GUYBRUSH_OID, null, task, result);
UserType userGuybrushType = userGuybrush.asObjectable();
assertEquals("Unexpected number of accountRefs", 1, userGuybrushType.getLinkRef().size());
ObjectReferenceType accountRefType = userGuybrushType.getLinkRef().get(0);
String accountOid = accountRefType.getOid();
assertFalse("No accountRef oid", StringUtils.isBlank(accountOid));
PrismReferenceValue accountRefValue = accountRefType.asReferenceValue();
assertEquals("OID mismatch in accountRefValue", accountOid, accountRefValue.getOid());
assertNull("Unexpected object in accountRefValue", accountRefValue.getObject());
// Check shadow
PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result);
assertDummyAccountShadowRepo(accountShadow, accountOid, ACCOUNT_GUYBRUSH_DUMMY_USERNAME);
// Check account
PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountOid, null, task, result);
assertDummyAccountShadowModel(accountModel, accountOid, ACCOUNT_GUYBRUSH_DUMMY_USERNAME, "Guybrush Threepwood");
// Check account in dummy resource
assertDefaultDummyAccount(ACCOUNT_GUYBRUSH_DUMMY_USERNAME, "Guybrush Threepwood", true);
result.computeStatus();
display("executeChanges result", result);
TestUtil.assertFailure("executeChanges result", result);
// Check audit
display("Audit", dummyAuditService);
dummyAuditService.assertRecords(2);
dummyAuditService.assertSimpleRecordSanity();
dummyAuditService.assertAnyRequestDeltas();
Collection<ObjectDeltaOperation<? extends ObjectType>> auditExecution0Deltas = dummyAuditService.getExecutionDeltas(0);
assertEquals("Wrong number of execution deltas", 0, auditExecution0Deltas.size());
dummyAuditService.assertExecutionOutcome(OperationResultStatus.FATAL_ERROR);
}
use of com.evolveum.midpoint.prism.delta.ReferenceDelta in project midpoint by Evolveum.
the class TestTolerantAttributes method test100ModifyUserAddAccount.
@Test
public void test100ModifyUserAddAccount() throws Exception {
TestUtil.displayTestTile(this, "test100ModifyUserAddAccount");
// GIVEN
Task task = taskManager.createTaskInstance(TestTolerantAttributes.class.getName() + ".test100ModifyUserAddAccount");
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.POSITIVE);
PrismObject<ShadowType> account = PrismTestUtil.parseObject(new File(ACCOUNT_JACK_DUMMY_BLACK_FILENAME));
ObjectDelta<UserType> userDelta = ObjectDelta.createEmptyModifyDelta(UserType.class, USER_JACK_OID, prismContext);
PrismReferenceValue accountRefVal = new PrismReferenceValue();
accountRefVal.setObject(account);
ReferenceDelta accountDelta = ReferenceDelta.createModificationAdd(UserType.F_LINK_REF, getUserDefinition(), accountRefVal);
userDelta.addModification(accountDelta);
Collection<ObjectDelta<? extends ObjectType>> deltas = (Collection) MiscUtil.createCollection(userDelta);
getDummyResource().purgeScriptHistory();
dummyAuditService.clear();
dummyTransport.clearMessages();
notificationManager.setDisabled(false);
XMLGregorianCalendar startTime = clock.currentTimeXMLGregorianCalendar();
// WHEN
modelService.executeChanges(deltas, null, task, result);
// THEN
result.computeStatus();
TestUtil.assertSuccess(result);
XMLGregorianCalendar endTime = clock.currentTimeXMLGregorianCalendar();
// Check accountRef
PrismObject<UserType> userJack = modelService.getObject(UserType.class, USER_JACK_OID, null, task, result);
assertUserJack(userJack);
UserType userJackType = userJack.asObjectable();
assertEquals("Unexpected number of accountRefs", 1, userJackType.getLinkRef().size());
ObjectReferenceType accountRefType = userJackType.getLinkRef().get(0);
accountOid = accountRefType.getOid();
assertFalse("No accountRef oid", StringUtils.isBlank(accountOid));
PrismReferenceValue accountRefValue = accountRefType.asReferenceValue();
assertEquals("OID mismatch in accountRefValue", accountOid, accountRefValue.getOid());
assertNull("Unexpected object in accountRefValue", accountRefValue.getObject());
// Check shadow
PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result);
assertAccountShadowRepo(accountShadow, accountOid, "jack", getDummyResourceType(RESOURCE_DUMMY_BLACK_NAME));
assertEnableTimestampShadow(accountShadow, startTime, endTime);
// Check account
PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountOid, null, task, result);
assertAccountShadowModel(accountModel, accountOid, "jack", getDummyResourceType(RESOURCE_DUMMY_BLACK_NAME));
accountDefinition = accountModel.getDefinition();
// Check account in dummy resource
assertAccount(userJack, RESOURCE_DUMMY_BLACK_OID);
}
Aggregations