HawkBitEclipseLinkJpaDialect extends EclipseLinkJpaDialect { @Override public DataAccessException translateExceptionIfPossible(final RuntimeException ex) { final DataAccessException dataAccessException = super.translateExceptionIfPossible(ex); if (dataAccessException == null) { return searchAndTranslateSqlException(ex); } return translateJpaSystemExceptionIfPossible(dataAccessException); }  @Override DataAccessException translateExceptionIfPossible(final RuntimeException ex);  }
@Test @Description("Use Case: PersistenceException that can be mapped by EclipseLinkJpaDialect into corresponding DataAccessException.") public void jpaOptimisticLockExceptionIsConcurrencyFailureException() { assertThat( hawkBitEclipseLinkJpaDialectUnderTest.translateExceptionIfPossible(mock(OptimisticLockException.class))) .isInstanceOf(ConcurrencyFailureException.class); }
@Test @Description("Use Case: PersistenceException that could not be mapped by EclipseLinkJpaDialect directly but " + "instead is wrapped into JpaSystemException. Cause of PersistenceException is an SQLException.") public void jpaSystemExceptionWithSqlDeadLockExceptionIsConcurrencyFailureException() { final PersistenceException persEception = mock(PersistenceException.class); when(persEception.getCause()).thenReturn(new SQLException("simulated transaction ER_LOCK_DEADLOCK", "40001")); assertThat(hawkBitEclipseLinkJpaDialectUnderTest.translateExceptionIfPossible(persEception)) .isInstanceOf(ConcurrencyFailureException.class); }
@Test @Description("Use Case: PersistenceException that could not be mapped by EclipseLinkJpaDialect directly but instead is wrapped" + " into JpaSystemException. Cause of PersistenceException is not an SQLException.") public void jpaSystemExceptionWithNumberFormatExceptionIsNull() { final PersistenceException persEception = mock(PersistenceException.class); when(persEception.getCause()).thenReturn(new NumberFormatException()); assertThat(hawkBitEclipseLinkJpaDialectUnderTest.translateExceptionIfPossible(persEception)) .isInstanceOf(UncategorizedDataAccessException.class); }
@Test @Description("Use Case: RuntimeException that could not be mapped by EclipseLinkJpaDialect directly. Cause of " + "RuntimeException is an SQLException.") public void runtimeExceptionWithSqlDeadLockExceptionIsConcurrencyFailureException() { final RuntimeException persEception = mock(RuntimeException.class); when(persEception.getCause()).thenReturn(new SQLException("simulated transaction ER_LOCK_DEADLOCK", "40001")); assertThat(hawkBitEclipseLinkJpaDialectUnderTest.translateExceptionIfPossible(persEception)) .isInstanceOf(ConcurrencyFailureException.class); }
@Test @Description("Use Case: RuntimeException that could not be mapped by EclipseLinkJpaDialect directly. Cause of " + "RuntimeException is not an SQLException.") public void runtimeExceptionWithNumberFormatExceptionIsNull() { final RuntimeException persEception = mock(RuntimeException.class); when(persEception.getCause()).thenReturn(new NumberFormatException()); assertThat(hawkBitEclipseLinkJpaDialectUnderTest.translateExceptionIfPossible(persEception)).isNull(); }