|
|
|
@ -42,6 +42,8 @@ import static org.mockito.Mockito.mock; |
|
|
|
import static org.mockito.Mockito.verify; |
|
|
|
import static org.mockito.Mockito.verify; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
|
|
|
|
* Tests for {@link SQLErrorCodeSQLExceptionTranslator}. |
|
|
|
|
|
|
|
* |
|
|
|
* @author Rod Johnson |
|
|
|
* @author Rod Johnson |
|
|
|
* @author Juergen Hoeller |
|
|
|
* @author Juergen Hoeller |
|
|
|
* @author Sam Brannen |
|
|
|
* @author Sam Brannen |
|
|
|
@ -128,11 +130,11 @@ class SQLErrorCodeSQLExceptionTranslatorTests { |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@SuppressWarnings("serial") |
|
|
|
@SuppressWarnings("serial") |
|
|
|
void customTranslateMethodTranslation() { |
|
|
|
void customTranslateMethodTranslation() { |
|
|
|
final String TASK = "TASK"; |
|
|
|
String TASK = "TASK"; |
|
|
|
final String SQL = "SQL SELECT *"; |
|
|
|
String SQL = "SQL SELECT *"; |
|
|
|
final DataAccessException customDex = new DataAccessException("") {}; |
|
|
|
DataAccessException customDex = new DataAccessException("") {}; |
|
|
|
|
|
|
|
|
|
|
|
final SQLException badSqlEx = new SQLException("", "", 1); |
|
|
|
SQLException badSqlEx = new SQLException("", "", 1); |
|
|
|
SQLException integrityViolationEx = new SQLException("", "", 6); |
|
|
|
SQLException integrityViolationEx = new SQLException("", "", 6); |
|
|
|
|
|
|
|
|
|
|
|
translator = new SQLErrorCodeSQLExceptionTranslator() { |
|
|
|
translator = new SQLErrorCodeSQLExceptionTranslator() { |
|
|
|
@ -150,18 +152,17 @@ class SQLErrorCodeSQLExceptionTranslatorTests { |
|
|
|
assertThat(translator.translate(TASK, SQL, badSqlEx)).isEqualTo(customDex); |
|
|
|
assertThat(translator.translate(TASK, SQL, badSqlEx)).isEqualTo(customDex); |
|
|
|
|
|
|
|
|
|
|
|
// Shouldn't custom translate this
|
|
|
|
// Shouldn't custom translate this
|
|
|
|
DataAccessException dataAccessException = translator.translate(TASK, SQL, integrityViolationEx); |
|
|
|
assertThat(translator.translate(TASK, SQL, integrityViolationEx)) |
|
|
|
assertThat(dataAccessException) |
|
|
|
|
|
|
|
.isInstanceOf(DataIntegrityViolationException.class) |
|
|
|
.isInstanceOf(DataIntegrityViolationException.class) |
|
|
|
.hasCause(integrityViolationEx); |
|
|
|
.hasCause(integrityViolationEx); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
void customExceptionTranslation() { |
|
|
|
void customExceptionTranslation() { |
|
|
|
final String TASK = "TASK"; |
|
|
|
String TASK = "TASK"; |
|
|
|
final String SQL = "SQL SELECT *"; |
|
|
|
String SQL = "SQL SELECT *"; |
|
|
|
final SQLErrorCodes customErrorCodes = new SQLErrorCodes(); |
|
|
|
SQLErrorCodes customErrorCodes = new SQLErrorCodes(); |
|
|
|
final CustomSQLErrorCodesTranslation customTranslation = new CustomSQLErrorCodesTranslation(); |
|
|
|
CustomSQLErrorCodesTranslation customTranslation = new CustomSQLErrorCodesTranslation(); |
|
|
|
|
|
|
|
|
|
|
|
customErrorCodes.setBadSqlGrammarCodes("1", "2"); |
|
|
|
customErrorCodes.setBadSqlGrammarCodes("1", "2"); |
|
|
|
customErrorCodes.setDataIntegrityViolationCodes("3", "4"); |
|
|
|
customErrorCodes.setDataIntegrityViolationCodes("3", "4"); |
|
|
|
@ -173,15 +174,13 @@ class SQLErrorCodeSQLExceptionTranslatorTests { |
|
|
|
|
|
|
|
|
|
|
|
// Should custom translate this
|
|
|
|
// Should custom translate this
|
|
|
|
SQLException badSqlEx = new SQLException("", "", 1); |
|
|
|
SQLException badSqlEx = new SQLException("", "", 1); |
|
|
|
DataAccessException dataAccessException = translator.translate(TASK, SQL, badSqlEx); |
|
|
|
assertThat(translator.translate(TASK, SQL, badSqlEx)) |
|
|
|
assertThat(dataAccessException) |
|
|
|
|
|
|
|
.isInstanceOf(CustomErrorCodeException.class) |
|
|
|
.isInstanceOf(CustomErrorCodeException.class) |
|
|
|
.hasCause(badSqlEx); |
|
|
|
.hasCause(badSqlEx); |
|
|
|
|
|
|
|
|
|
|
|
// Shouldn't custom translate this
|
|
|
|
// Shouldn't custom translate this
|
|
|
|
SQLException invResEx = new SQLException("", "", 3); |
|
|
|
SQLException invResEx = new SQLException("", "", 3); |
|
|
|
dataAccessException = translator.translate(TASK, SQL, invResEx); |
|
|
|
assertThat(translator.translate(TASK, SQL, invResEx)) |
|
|
|
assertThat(dataAccessException) |
|
|
|
|
|
|
|
.isInstanceOf(DataIntegrityViolationException.class) |
|
|
|
.isInstanceOf(DataIntegrityViolationException.class) |
|
|
|
.hasCause(invResEx); |
|
|
|
.hasCause(invResEx); |
|
|
|
|
|
|
|
|
|
|
|
|