Search in sources :

Example 1 with ItemFactory

use of com.evolveum.midpoint.prism.ItemFactory in project midpoint by Evolveum.

the class TestUserTemplate method test160ModifyUserGivenNameAgain.

@Test
public void test160ModifyUserGivenNameAgain() throws Exception {
    // GIVEN
    Task task = getTestTask();
    OperationResult result = getTestOperationResult();
    dummyAuditService.clear();
    Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<>();
    ObjectDelta<UserType> userDelta = prismContext.deltaFactory().object().createModificationReplaceProperty(UserType.class, USER_JACK_OID, UserType.F_GIVEN_NAME, new PolyString("JACKIE"));
    deltas.add(userDelta);
    // WHEN
    modelService.executeChanges(deltas, null, task, result);
    // THEN
    assertSuccess(result);
    PrismObject<UserType> userJack = modelService.getObject(UserType.class, USER_JACK_OID, null, task, result);
    PrismAsserts.assertPropertyValue(userJack.findContainer(UserType.F_EXTENSION), PIRACY_BAD_LUCK, 123L);
    displayDumpable("Audit", dummyAuditService);
    dummyAuditService.assertRecords(2);
    dummyAuditService.assertSimpleRecordSanity();
    dummyAuditService.assertAnyRequestDeltas();
    dummyAuditService.assertExecutionDeltas(2);
    dummyAuditService.assertHasDelta(ChangeType.MODIFY, UserType.class);
    dummyAuditService.assertTarget(USER_JACK_OID);
    dummyAuditService.assertExecutionSuccess();
    ObjectDeltaOperation<?> objectDeltaOperation = dummyAuditService.getExecutionDelta(0, ChangeType.MODIFY, UserType.class);
    assertEquals("unexpected number of modifications in audited delta", 10, // givenName + badLuck + modifyTimestamp
    objectDeltaOperation.getObjectDelta().getModifications().size());
    PropertyDelta badLuckDelta = objectDeltaOperation.getObjectDelta().findPropertyDelta(ItemPath.create(UserType.F_EXTENSION, PIRACY_BAD_LUCK));
    assertNotNull("badLuck delta was not found", badLuckDelta);
    // noinspection unchecked
    List<PrismValue> oldValues = (List<PrismValue>) badLuckDelta.getEstimatedOldValues();
    assertNotNull("badLuck delta has null estimatedOldValues field", oldValues);
    ItemFactory factory = prismContext.itemFactory();
    PrismAsserts.assertEqualsCollectionUnordered("badLuck delta has wrong estimatedOldValues", oldValues, factory.createPropertyValue(123L), factory.createPropertyValue(456L));
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismValue(com.evolveum.midpoint.prism.PrismValue) ItemFactory(com.evolveum.midpoint.prism.ItemFactory) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) ArrayList(java.util.ArrayList) List(java.util.List) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) Test(org.testng.annotations.Test)

Aggregations

ItemFactory (com.evolveum.midpoint.prism.ItemFactory)1 PrismValue (com.evolveum.midpoint.prism.PrismValue)1 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)1 PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)1 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)1 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 Task (com.evolveum.midpoint.task.api.Task)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Test (org.testng.annotations.Test)1