use of com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType in project midpoint by Evolveum.
the class OrgPhotoTest method parseDelta.
protected ObjectDelta<OrgType> parseDelta(String oid, File file) throws SchemaException, IOException {
ObjectModificationType modification = PrismTestUtil.parseAtomicValue(file, ObjectModificationType.COMPLEX_TYPE);
ObjectDelta<OrgType> delta = DeltaConvertor.createObjectDelta(modification, OrgType.class, prismContext);
delta.setOid(oid);
return delta;
}
use of com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType in project midpoint by Evolveum.
the class TestParseDiffPatch method testUser.
@Test
public void testUser() throws SchemaException, SAXException, IOException, JAXBException {
System.out.println("===[ testUser ]===");
PrismObject<UserType> userBefore = PrismTestUtil.parseObject(new File(TEST_DIR, "user-jack-before.xml"));
userBefore.checkConsistence();
PrismObject<UserType> userAfter = PrismTestUtil.parseObject(new File(TEST_DIR, "user-jack-after.xml"));
userAfter.checkConsistence();
// sanity
assertFalse("Equals does not work", userBefore.equals(userAfter));
// WHEN
ObjectDelta<UserType> userDelta = userBefore.diff(userAfter);
// THEN
System.out.println("DELTA:");
System.out.println(userDelta.debugDump());
userBefore.checkConsistence();
userAfter.checkConsistence();
userDelta.checkConsistence();
userDelta.assertDefinitions();
assertEquals("Wrong delta OID", userBefore.getOid(), userDelta.getOid());
assertEquals("Wrong change type", ChangeType.MODIFY, userDelta.getChangeType());
Collection<? extends ItemDelta> modifications = userDelta.getModifications();
assertEquals("Unexpected number of modifications", 3, modifications.size());
PrismAsserts.assertPropertyReplace(userDelta, new QName(SchemaConstants.NS_C, "fullName"), new PolyString("Cpt. Jack Sparrow", "cpt jack sparrow"));
PrismAsserts.assertPropertyAdd(userDelta, new QName(SchemaConstants.NS_C, "honorificPrefix"), new PolyString("Cpt.", "cpt"));
PrismAsserts.assertPropertyAdd(userDelta, new QName(SchemaConstants.NS_C, "locality"), new PolyString("Tortuga", "tortuga"));
ObjectModificationType objectModificationType = DeltaConvertor.toObjectModificationType(userDelta);
System.out.println("Modification XML:");
System.out.println(PrismTestUtil.serializeAnyDataWrapped(objectModificationType));
assertEquals("Wrong delta OID", userBefore.getOid(), objectModificationType.getOid());
List<ItemDeltaType> propertyModifications = objectModificationType.getItemDelta();
assertEquals("Unexpected number of modifications", 3, propertyModifications.size());
PolyStringType polyString = new PolyStringType();
polyString.setOrig("Cpt. Jack Sparrow");
polyString.setNorm("cpt jack sparrow");
assertXmlPolyMod(objectModificationType, new QName(SchemaConstants.NS_C, "fullName"), ModificationTypeType.REPLACE, polyString);
polyString = new PolyStringType();
polyString.setOrig("Cpt.");
polyString.setNorm("cpt");
assertXmlPolyMod(objectModificationType, new QName(SchemaConstants.NS_C, "honorificPrefix"), ModificationTypeType.ADD, polyString);
polyString = new PolyStringType();
polyString.setOrig("Tortuga");
polyString.setNorm("tortuga");
assertXmlPolyMod(objectModificationType, new QName(SchemaConstants.NS_C, "locality"), ModificationTypeType.ADD, polyString);
userBefore.checkConsistence();
userAfter.checkConsistence();
userDelta.checkConsistence();
// ROUNDTRIP
userDelta.applyTo(userBefore);
userBefore.checkConsistence();
userAfter.checkConsistence();
userDelta.checkConsistence();
//assertEquals("Round trip failed", userAfter, userBefore);
assertTrue("Not equivalent", userBefore.equivalent(userAfter));
ObjectDelta<UserType> roundTripDelta = DiffUtil.diff(userBefore, userAfter);
System.out.println("roundtrip DELTA:");
System.out.println(roundTripDelta.debugDump());
assertTrue("Roundtrip delta is not empty", roundTripDelta.isEmpty());
}
use of com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType in project midpoint by Evolveum.
the class TestDeltaConverter method testAddAssignment.
@Test
public void testAddAssignment() throws Exception {
System.out.println("===[ testAddAssignment ]====");
ObjectModificationType objectChange = PrismTestUtil.parseAtomicValue(new File(TEST_DIR, "user-modify-add-role-pirate.xml"), ObjectModificationType.COMPLEX_TYPE);
// WHEN
ObjectDelta<UserType> objectDelta = DeltaConvertor.createObjectDelta(objectChange, UserType.class, getPrismContext());
System.out.println("Delta:");
System.out.println(objectDelta.debugDump());
// THEN
assertNotNull("No object delta", objectDelta);
objectDelta.checkConsistence();
assertEquals("Wrong OID", "c0c010c0-d34d-b33f-f00d-111111111111", objectDelta.getOid());
ContainerDelta<AssignmentType> assignmentDelta = objectDelta.findContainerDelta(UserType.F_ASSIGNMENT);
assertNotNull("No assignment delta", assignmentDelta);
Collection<PrismContainerValue<AssignmentType>> valuesToAdd = assignmentDelta.getValuesToAdd();
assertEquals("Wrong number of values to add", 1, valuesToAdd.size());
PrismContainerValue<AssignmentType> assignmentVal = valuesToAdd.iterator().next();
assertNotNull("Null value in protectedStringDelta", assignmentVal);
PrismReference targetRef = assignmentVal.findReference(AssignmentType.F_TARGET_REF);
assertNotNull("No targetRef in assignment", targetRef);
PrismReferenceValue targetRefVal = targetRef.getValue();
assertNotNull("No targetRef value in assignment", targetRefVal);
assertEquals("Wrong OID in targetRef value", "12345678-d34d-b33f-f00d-987987987988", targetRefVal.getOid());
assertEquals("Wrong type in targetRef value", RoleType.COMPLEX_TYPE, targetRefVal.getTargetType());
PrismObject<UserType> user = PrismTestUtil.parseObject(USER_JACK_FILE);
objectDelta.assertDefinitions("delta before test");
user.assertDefinitions("user before test");
// apply to user
objectDelta.applyTo(user);
objectDelta.assertDefinitions("delta after test");
user.assertDefinitions("user after test");
// TODO
}
use of com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType in project midpoint by Evolveum.
the class TestDeltaConverter method testAccountRefDelta.
@Test
public void testAccountRefDelta() throws Exception {
System.out.println("===[ testAccountRefDelta ]====");
// GIVEN
ObjectModificationType objectChange = new ObjectModificationType();
objectChange.setOid("12345");
ItemDeltaType modificationDeleteAccountRef = new ItemDeltaType();
modificationDeleteAccountRef.setModificationType(ModificationTypeType.DELETE);
ObjectReferenceType accountRefToDelete = new ObjectReferenceType();
accountRefToDelete.setOid("54321");
PrismContext prismContext = getPrismContext();
RawType modificationValue = new RawType(((PrismContextImpl) prismContext).getBeanMarshaller().marshall(accountRefToDelete), prismContext);
modificationDeleteAccountRef.getValue().add(modificationValue);
objectChange.getItemDelta().add(modificationDeleteAccountRef);
ItemPathType itemPathType = new ItemPathType(new ItemPath(UserType.F_LINK_REF));
modificationDeleteAccountRef.setPath(itemPathType);
PrismObjectDefinition<UserType> objDef = PrismTestUtil.getObjectDefinition(UserType.class);
// WHEN
Collection<? extends ItemDelta> modifications = DeltaConvertor.toModifications(objectChange, objDef);
// THEN
assertNotNull("Null modifications", modifications);
assertFalse("Empty modifications", modifications.isEmpty());
// TODO: more asserts
}
use of com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType in project midpoint by Evolveum.
the class TestDeltaConverter method testPasswordChange.
@Test
public void testPasswordChange() throws Exception {
System.out.println("===[ testPasswordChange ]====");
ObjectModificationType objectChange = PrismTestUtil.parseAtomicValue(new File(TEST_DIR, "user-modify-password.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<ProtectedStringType> protectedStringDelta = objectDelta.findPropertyDelta(CREDENTIALS_PASSWORD_VALUE_PATH);
assertNotNull("No protectedString delta", protectedStringDelta);
Collection<PrismPropertyValue<ProtectedStringType>> valuesToReplace = protectedStringDelta.getValuesToReplace();
assertEquals("Wrong number of values to replace", 1, valuesToReplace.size());
PrismPropertyValue<ProtectedStringType> protectedStringVal = valuesToReplace.iterator().next();
assertNotNull("Null value in protectedStringDelta", protectedStringVal);
PrismObject<UserType> user = PrismTestUtil.parseObject(USER_JACK_FILE);
// apply to user
objectDelta.applyTo(user);
PrismProperty<ProtectedStringType> protectedStringProperty = user.findProperty(CREDENTIALS_PASSWORD_VALUE_PATH);
PrismPropertyValue<ProtectedStringType> protectedStringPropertyValue = protectedStringProperty.getValue();
assertTrue("protectedString not equivalent", protectedStringPropertyValue.equalsRealValue(protectedStringVal));
objectDelta.assertDefinitions();
}
Aggregations