use of com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType in project midpoint by Evolveum.
the class TestDeltaConverter method testModifyGivenName.
@Test
public void testModifyGivenName() throws Exception {
System.out.println("===[ testModifyGivenName ]====");
ObjectModificationType objectChange = PrismTestUtil.parseAtomicValue(new File(TEST_DIR, "user-modify-givenname.xml"), ObjectModificationType.COMPLEX_TYPE);
// WHEN
ObjectDelta<UserType> objectDelta = DeltaConvertor.createObjectDelta(objectChange, UserType.class, getPrismContext());
// THEN
assertNotNull("No object delta", objectDelta);
objectDelta.checkConsistence();
assertEquals("Wrong OID", "c0c010c0-d34d-b33f-f00d-111111111111", objectDelta.getOid());
PropertyDelta<String> givenNameDelta = objectDelta.findPropertyDelta(UserType.F_GIVEN_NAME);
assertNotNull("No givenName delta", givenNameDelta);
Collection<PrismPropertyValue<String>> valuesToReplace = givenNameDelta.getValuesToReplace();
assertEquals("Wrong number of values to replace", 0, valuesToReplace.size());
PrismObject<UserType> user = PrismTestUtil.parseObject(USER_JACK_FILE);
// apply to user
objectDelta.applyTo(user);
PrismProperty<String> protectedStringProperty = user.findProperty(UserType.F_GIVEN_NAME);
assertNull("givenName porperty sneaked in after delta was applied", protectedStringProperty);
objectDelta.assertDefinitions();
}
use of com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType in project midpoint by Evolveum.
the class DeltaConvertor method toObjectDeltaType.
public static ObjectDeltaType toObjectDeltaType(ObjectDelta<? extends ObjectType> objectDelta, DeltaConversionOptions options) throws SchemaException {
Validate.notNull(objectDelta.getPrismContext(), "ObjectDelta without prismContext cannot be converted to ObjectDeltaType");
ObjectDeltaType objectDeltaType = new ObjectDeltaType();
objectDeltaType.setChangeType(convertChangeType(objectDelta.getChangeType()));
Class<? extends Objectable> type = objectDelta.getObjectTypeClass();
PrismObjectDefinition<? extends Objectable> objDef = objectDelta.getPrismContext().getSchemaRegistry().findObjectDefinitionByCompileTimeClass(type);
if (objDef == null) {
throw new SchemaException("Unknown compile time class: " + type);
}
objectDeltaType.setObjectType(objDef.getTypeName());
objectDeltaType.setOid(objectDelta.getOid());
if (objectDelta.getChangeType() == ChangeType.ADD) {
PrismObject<? extends ObjectType> prismObject = objectDelta.getObjectToAdd();
if (prismObject != null) {
objectDeltaType.setObjectToAdd(prismObject.asObjectable());
}
} else if (objectDelta.getChangeType() == ChangeType.MODIFY) {
ObjectModificationType modType = new ObjectModificationType();
modType.setOid(objectDelta.getOid());
for (ItemDelta<?, ?> propDelta : objectDelta.getModifications()) {
Collection<ItemDeltaType> propPropModTypes;
try {
propPropModTypes = toItemDeltaTypes(propDelta, options);
} catch (SchemaException e) {
throw new SchemaException(e.getMessage() + " in " + objectDelta.toString(), e);
}
objectDeltaType.getItemDelta().addAll(propPropModTypes);
}
} else if (objectDelta.getChangeType() == ChangeType.DELETE) {
// Nothing to do
} else {
throw new SystemException("Unknown changetype " + objectDelta.getChangeType());
}
return objectDeltaType;
}
use of com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType in project midpoint by Evolveum.
the class AbstractBasicDummyTest method test105ApplyDefinitionModifyDelta.
@Test
public void test105ApplyDefinitionModifyDelta() throws Exception {
final String TEST_NAME = "test105ApplyDefinitionModifyDelta";
TestUtil.displayTestTile(TEST_NAME);
// GIVEN
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
ObjectModificationType changeAddRoleCaptain = PrismTestUtil.parseAtomicValue(MODIFY_ACCOUNT_FILE, ObjectModificationType.COMPLEX_TYPE);
ObjectDelta<ShadowType> accountDelta = DeltaConvertor.createObjectDelta(changeAddRoleCaptain, ShadowType.class, prismContext);
// WHEN
provisioningService.applyDefinition(accountDelta, task, result);
// THEN
result.computeStatus();
display("applyDefinition result", result);
TestUtil.assertSuccess(result);
accountDelta.checkConsistence(true, true, true);
TestUtil.assertSuccess("applyDefinition(modify delta) result", result);
assertSteadyResource();
}
use of com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType in project midpoint by Evolveum.
the class TestOpenDj method test140AddAndModifyAccountJack.
@Test
public void test140AddAndModifyAccountJack() throws Exception {
final String TEST_NAME = "test140AddAndModifyAccountJack";
TestUtil.displayTestTile(TEST_NAME);
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
ShadowType object = unmarshallValueFromFile(ACCOUNT_JACK_FILE, ShadowType.class);
System.out.println(SchemaDebugUtil.prettyPrint(object));
System.out.println(object.asPrismObject().debugDump());
String addedObjectOid = provisioningService.addObject(object.asPrismObject(), null, null, task, result);
assertEquals(ACCOUNT_JACK_OID, addedObjectOid);
ObjectModificationType objectChange = PrismTestUtil.parseAtomicValue(ACCOUNT_JACK_CHANGE_FILE, ObjectModificationType.COMPLEX_TYPE);
ObjectDelta<ShadowType> delta = DeltaConvertor.createObjectDelta(objectChange, object.asPrismObject().getDefinition());
ItemPath icfNamePath = new ItemPath(ShadowType.F_ATTRIBUTES, getSecondaryIdentifierQName());
PrismPropertyDefinition icfNameDef = object.asPrismObject().getDefinition().findPropertyDefinition(icfNamePath);
ItemDelta renameDelta = PropertyDelta.createModificationReplaceProperty(icfNamePath, icfNameDef, "uid=rename,ou=People,dc=example,dc=com");
((Collection) delta.getModifications()).add(renameDelta);
display("Object change", delta);
// WHEN
TestUtil.displayWhen(TEST_NAME);
provisioningService.modifyObject(ShadowType.class, objectChange.getOid(), delta.getModifications(), null, null, task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);
ShadowType accountType = provisioningService.getObject(ShadowType.class, ACCOUNT_JACK_OID, null, taskManager.createTaskInstance(), result).asObjectable();
display("Object after change", accountType);
String uid = ShadowUtil.getSingleStringAttributeValue(accountType, getPrimaryIdentifierQName());
List<Object> snValues = ShadowUtil.getAttributeValues(accountType, new QName(RESOURCE_NS, "sn"));
assertNotNull("No 'sn' attribute", snValues);
assertFalse("Surname attributes must not be empty", snValues.isEmpty());
assertEquals(1, snValues.size());
//check icf_name in the shadow object fetched only from the repository
ShadowType repoShadow = repositoryService.getObject(ShadowType.class, objectChange.getOid(), null, result).asObjectable();
String name = ShadowUtil.getSingleStringAttributeValue(repoShadow, getSecondaryIdentifierQName());
assertEquals("After rename, dn is not equal.", "uid=rename,ou=people,dc=example,dc=com", name);
assertEquals("shadow name not changed after rename", "uid=rename,ou=People,dc=example,dc=com", repoShadow.getName().getOrig());
String changedSn = (String) snValues.get(0);
assertNotNull(uid);
// Check if object was modified in LDAP
Entry response = openDJController.searchAndAssertByEntryUuid(uid);
display("LDAP account", response);
OpenDJController.assertAttribute(response, "sn", "First");
assertEquals("First", changedSn);
assertShadows(3);
}
use of com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType in project midpoint by Evolveum.
the class TestOpenDj method test170DisableAccount.
@Test
public void test170DisableAccount() throws Exception {
final String TEST_NAME = "test170DisableAccount";
TestUtil.displayTestTile(TEST_NAME);
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
ShadowType object = parseObjectType(ACCOUNT_DISABLE_SIMULATED_FILE, ShadowType.class);
System.out.println(SchemaDebugUtil.prettyPrint(object));
System.out.println(object.asPrismObject().debugDump());
String addedObjectOid = provisioningService.addObject(object.asPrismObject(), null, null, taskManager.createTaskInstance(), result);
assertEquals(ACCOUNT_DISABLE_SIMULATED_OID, addedObjectOid);
ObjectModificationType objectChange = PrismTestUtil.parseAtomicValue(REQUEST_DISABLE_ACCOUNT_SIMULATED_FILE, ObjectModificationType.COMPLEX_TYPE);
ObjectDelta<ShadowType> delta = DeltaConvertor.createObjectDelta(objectChange, object.asPrismObject().getDefinition());
display("Object change", delta);
// WHEN
TestUtil.displayWhen(TEST_NAME);
provisioningService.modifyObject(ShadowType.class, objectChange.getOid(), delta.getModifications(), null, null, task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
ShadowType accountType = provisioningService.getObject(ShadowType.class, ACCOUNT_DISABLE_SIMULATED_OID, null, taskManager.createTaskInstance(), result).asObjectable();
display("Object after change", accountType);
assertEquals("The account was not disabled in the shadow", ActivationStatusType.DISABLED, accountType.getActivation().getAdministrativeStatus());
String uid = ShadowUtil.getSingleStringAttributeValue(accountType, getPrimaryIdentifierQName());
assertNotNull(uid);
// Check if object was modified in LDAP
Entry response = openDJController.searchAndAssertByEntryUuid(uid);
display("LDAP account", response);
String disabled = openDJController.getAttributeValue(response, "ds-pwp-account-disabled");
assertNotNull("no ds-pwp-account-disabled attribute in account " + uid, disabled);
display("ds-pwp-account-disabled after change: " + disabled);
assertEquals("ds-pwp-account-disabled not set to \"TRUE\"", "TRUE", disabled);
PrismObject<ShadowType> repoShadow = repositoryService.getObject(ShadowType.class, ACCOUNT_DISABLE_SIMULATED_OID, null, result);
ActivationType repoActivation = repoShadow.asObjectable().getActivation();
assertNotNull("No activation in repo", repoActivation);
XMLGregorianCalendar repoDisableTimestamp = repoActivation.getDisableTimestamp();
assertNotNull("No activation disableTimestamp in repo", repoDisableTimestamp);
assertEquals("Wrong activation disableTimestamp in repo", XmlTypeConverter.createXMLGregorianCalendar(2001, 2, 3, 4, 5, 6), repoDisableTimestamp);
}
Aggregations