- @SuppressWarnings({ "checkstyle:IllegalThrows", "checkstyle:avoidHidingCauseException" })
- @Test(expected = OptimisticLockFailedException.class)
- public void canCommitTestWithOptimisticLockFailedException() throws Throwable {
- doThrow(new ConflictingModificationAppliedException(YangInstanceIdentifier.empty(), "testException"))
- .when(IN_MEMORY_DOM_DATA_STORE).validate(any());
- try {
- inMemoryDOMStoreThreePhaseCommitCohort.canCommit().get();
- fail("Expected exception");
- } catch (ExecutionException e) {
- assertTrue(e.getCause() instanceof OptimisticLockFailedException);
- throw e.getCause();
- }
+ @Test
+ public void canCommitTestWithOptimisticLockFailedException() throws Exception {
+ final var cause = new ConflictingModificationAppliedException(YangInstanceIdentifier.empty(), "testException");
+ doThrow(cause).when(dataStore).validate(any());
+
+ final var ex = assertFailsCanCommit(prepareSimpleCohort());
+ assertThat(ex, instanceOf(OptimisticLockFailedException.class));
+ assertSame(cause, ex.getCause());
+ final var errors = ((OptimisticLockFailedException) ex).getErrorList();
+ assertEquals(1, errors.size());
+ final var error = errors.get(0);
+ assertEquals(ErrorSeverity.ERROR, error.getSeverity());
+ assertEquals(ErrorType.APPLICATION, error.getErrorType());
+ assertEquals(ErrorTag.RESOURCE_DENIED, error.getTag());