Search in sources :

Example 36 with ObjectModificationType

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;
}
Also used : ObjectModificationType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType) OrgType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType)

Example 37 with ObjectModificationType

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());
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) ObjectModificationType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType) QName(javax.xml.namespace.QName) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) File(java.io.File) ItemDeltaType(com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType) Test(org.testng.annotations.Test)

Example 38 with ObjectModificationType

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
}
Also used : ObjectModificationType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType) File(java.io.File) Test(org.testng.annotations.Test)

Example 39 with ObjectModificationType

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
}
Also used : ObjectModificationType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) PrismTestUtil.getPrismContext(com.evolveum.midpoint.prism.util.PrismTestUtil.getPrismContext) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 40 with ObjectModificationType

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();
}
Also used : ObjectModificationType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType) File(java.io.File) Test(org.testng.annotations.Test)

Aggregations

ObjectModificationType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType)45 Test (org.testng.annotations.Test)40 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)31 File (java.io.File)31 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)13 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)12 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)8 Task (com.evolveum.midpoint.task.api.Task)7 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)6 Session (org.hibernate.Session)6 ROrgClosure (com.evolveum.midpoint.repo.sql.data.common.ROrgClosure)5 OrgType (com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType)5 Entry (org.opends.server.types.Entry)4 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)3 ItemDeltaType (com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType)3 QName (javax.xml.namespace.QName)3 ReferenceDelta (com.evolveum.midpoint.prism.delta.ReferenceDelta)2 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)2 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)2 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)2