Search in sources :

Example 1 with VersionPrecondition

use of com.evolveum.midpoint.repo.api.VersionPrecondition in project midpoint by Evolveum.

the class ModifyTest method test166ModifyWithVersionPreconditionTrue.

@Test
public void test166ModifyWithVersionPreconditionTrue() throws Exception {
    OperationResult result = createOperationResult();
    // GIVEN
    String versionBefore = repositoryService.getVersion(RoleType.class, roleOid, result);
    ModificationPrecondition<RoleType> precondition = new VersionPrecondition<>(versionBefore);
    // WHEN
    List<ItemDelta<?, ?>> itemDeltas = prismContext.deltaFor(RoleType.class).item(RoleType.F_DESCRIPTION).replace("123456").asItemDeltas();
    repositoryService.modifyObject(RoleType.class, roleOid, itemDeltas, precondition, getModifyOptions(), result);
    String versionAfter = repositoryService.getVersion(RoleType.class, roleOid, result);
    assertEquals("unexpected version change", Integer.parseInt(versionBefore) + 1, Integer.parseInt(versionAfter));
    String description = repositoryService.getObject(RoleType.class, roleOid, null, result).asObjectable().getDescription();
    assertEquals("description was not set", "123456", description);
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) VersionPrecondition(com.evolveum.midpoint.repo.api.VersionPrecondition) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) Test(org.testng.annotations.Test)

Example 2 with VersionPrecondition

use of com.evolveum.midpoint.repo.api.VersionPrecondition in project midpoint by Evolveum.

the class ModifyTest method test164ModifyWithVersionPreconditionFalse.

@Test
public void test164ModifyWithVersionPreconditionFalse() throws Exception {
    OperationResult result = createOperationResult();
    // GIVEN
    String versionBefore = repositoryService.getVersion(RoleType.class, roleOid, result);
    ModificationPrecondition<RoleType> precondition = new VersionPrecondition<>("9999");
    // WHEN
    List<ItemDelta<?, ?>> itemDeltas = prismContext.deltaFor(RoleType.class).item(RoleType.F_DESCRIPTION).replace("123456").asItemDeltas();
    try {
        repositoryService.modifyObject(RoleType.class, roleOid, itemDeltas, precondition, getModifyOptions(), result);
        // THEN
        fail("unexpected success");
    } catch (PreconditionViolationException e) {
        // ok
        System.out.println("got expected exception: " + e.getMessage());
    }
    String versionAfter = repositoryService.getVersion(RoleType.class, roleOid, result);
    assertEquals("unexpected version change", versionBefore, versionAfter);
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) VersionPrecondition(com.evolveum.midpoint.repo.api.VersionPrecondition) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PreconditionViolationException(com.evolveum.midpoint.repo.api.PreconditionViolationException) Test(org.testng.annotations.Test)

Aggregations

PolyString (com.evolveum.midpoint.prism.polystring.PolyString)2 VersionPrecondition (com.evolveum.midpoint.repo.api.VersionPrecondition)2 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)2 Test (org.testng.annotations.Test)2 PreconditionViolationException (com.evolveum.midpoint.repo.api.PreconditionViolationException)1