use of com.evolveum.midpoint.repo.api.ModificationPrecondition in project midpoint by Evolveum.
the class ModifyTest method test160ModifyWithPrecondition.
@Test
public void test160ModifyWithPrecondition() throws Exception {
OperationResult result = createOperationResult();
// GIVEN
String versionBefore = repositoryService.getVersion(RoleType.class, roleOid, result);
ModificationPrecondition<RoleType> precondition = o -> {
throw new PreconditionViolationException("hello");
};
// 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) {
assertEquals("Wrong exception message", "hello", e.getMessage());
}
String versionAfter = repositoryService.getVersion(RoleType.class, roleOid, result);
assertEquals("unexpected version change", versionBefore, versionAfter);
}
use of com.evolveum.midpoint.repo.api.ModificationPrecondition in project midpoint by Evolveum.
the class ModifyTest method test162ModifyWithPrecondition2.
@Test
public void test162ModifyWithPrecondition2() throws Exception {
OperationResult result = createOperationResult();
// GIVEN
String versionBefore = repositoryService.getVersion(RoleType.class, roleOid, result);
ModificationPrecondition<RoleType> precondition = o -> false;
// 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