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);
}
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);
}
Aggregations