Polishing

This commit is contained in:
Sam Brannen 2023-11-06 15:29:48 +01:00
parent dc26d3b0ec
commit 5752e03d97
4 changed files with 130 additions and 136 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -16,7 +16,6 @@
package org.springframework.core;
import java.util.Arrays;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
@ -82,10 +81,7 @@ class AttributeAccessorSupportTests {
void attributeNames() {
this.attributeAccessor.setAttribute(NAME, VALUE);
this.attributeAccessor.setAttribute("abc", "123");
String[] attributeNames = this.attributeAccessor.attributeNames();
Arrays.sort(attributeNames);
assertThat(Arrays.binarySearch(attributeNames, "abc")).isEqualTo(0);
assertThat(Arrays.binarySearch(attributeNames, NAME)).isEqualTo(1);
assertThat(this.attributeAccessor.attributeNames()).contains("abc", NAME);
}
@SuppressWarnings("serial")

View File

@ -19,7 +19,6 @@ package org.springframework.jdbc.support;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import java.util.Arrays;
import javax.sql.DataSource;
@ -41,108 +40,108 @@ import static org.mockito.Mockito.verify;
* @author Thomas Risberg
* @author Stephane Nicoll
* @author Juergen Hoeller
* @author Sam Brannen
*/
public class SQLErrorCodesFactoryTests {
class SQLErrorCodesFactoryTests {
/**
* Check that a default instance returns empty error codes for an unknown database.
*/
@Test
public void testDefaultInstanceWithNoSuchDatabase() {
void defaultInstanceWithNoSuchDatabase() {
SQLErrorCodes sec = SQLErrorCodesFactory.getInstance().getErrorCodes("xx");
assertThat(sec.getBadSqlGrammarCodes().length).isEqualTo(0);
assertThat(sec.getDataIntegrityViolationCodes().length).isEqualTo(0);
assertThat(sec.getBadSqlGrammarCodes()).isEmpty();
assertThat(sec.getDataIntegrityViolationCodes()).isEmpty();
}
/**
* Check that a known database produces recognizable codes.
*/
@Test
public void testDefaultInstanceWithOracle() {
void defaultInstanceWithOracle() {
SQLErrorCodes sec = SQLErrorCodesFactory.getInstance().getErrorCodes("Oracle");
assertIsOracle(sec);
}
private void assertIsOracle(SQLErrorCodes sec) {
assertThat(sec.getBadSqlGrammarCodes().length).isGreaterThan(0);
assertThat(sec.getDataIntegrityViolationCodes().length).isGreaterThan(0);
assertThat(sec.getBadSqlGrammarCodes()).isNotEmpty();
assertThat(sec.getDataIntegrityViolationCodes()).isNotEmpty();
// These had better be a Bad SQL Grammar code
assertThat(Arrays.binarySearch(sec.getBadSqlGrammarCodes(), "942")).isGreaterThanOrEqualTo(0);
assertThat(Arrays.binarySearch(sec.getBadSqlGrammarCodes(), "6550")).isGreaterThanOrEqualTo(0);
assertThat(sec.getBadSqlGrammarCodes()).contains("942");
assertThat(sec.getBadSqlGrammarCodes()).contains("6550");
// This had better NOT be
assertThat(Arrays.binarySearch(sec.getBadSqlGrammarCodes(), "9xx42")).isLessThan(0);
assertThat(sec.getBadSqlGrammarCodes()).doesNotContain("9xx42");
}
private void assertIsSQLServer(SQLErrorCodes sec) {
assertThat(sec.getDatabaseProductName()).isEqualTo("Microsoft SQL Server");
assertThat(sec.getBadSqlGrammarCodes().length).isGreaterThan(0);
assertThat(sec.getBadSqlGrammarCodes()).isNotEmpty();
assertThat(Arrays.binarySearch(sec.getBadSqlGrammarCodes(), "156")).isGreaterThanOrEqualTo(0);
assertThat(Arrays.binarySearch(sec.getBadSqlGrammarCodes(), "170")).isGreaterThanOrEqualTo(0);
assertThat(Arrays.binarySearch(sec.getBadSqlGrammarCodes(), "207")).isGreaterThanOrEqualTo(0);
assertThat(Arrays.binarySearch(sec.getBadSqlGrammarCodes(), "208")).isGreaterThanOrEqualTo(0);
assertThat(Arrays.binarySearch(sec.getBadSqlGrammarCodes(), "209")).isGreaterThanOrEqualTo(0);
assertThat(Arrays.binarySearch(sec.getBadSqlGrammarCodes(), "9xx42")).isLessThan(0);
assertThat(sec.getBadSqlGrammarCodes()).contains("156");
assertThat(sec.getBadSqlGrammarCodes()).contains("170");
assertThat(sec.getBadSqlGrammarCodes()).contains("207");
assertThat(sec.getBadSqlGrammarCodes()).contains("208");
assertThat(sec.getBadSqlGrammarCodes()).contains("209");
assertThat(sec.getBadSqlGrammarCodes()).doesNotContain("9xx42");
assertThat(sec.getPermissionDeniedCodes().length).isGreaterThan(0);
assertThat(Arrays.binarySearch(sec.getPermissionDeniedCodes(), "229")).isGreaterThanOrEqualTo(0);
assertThat(sec.getPermissionDeniedCodes()).isNotEmpty();
assertThat(sec.getPermissionDeniedCodes()).contains("229");
assertThat(sec.getDuplicateKeyCodes().length).isGreaterThan(0);
assertThat(Arrays.binarySearch(sec.getDuplicateKeyCodes(), "2601")).isGreaterThanOrEqualTo(0);
assertThat(Arrays.binarySearch(sec.getDuplicateKeyCodes(), "2627")).isGreaterThanOrEqualTo(0);
assertThat(sec.getDuplicateKeyCodes()).isNotEmpty();
assertThat(sec.getDuplicateKeyCodes()).contains("2601");
assertThat(sec.getDuplicateKeyCodes()).contains("2627");
assertThat(sec.getDataIntegrityViolationCodes().length).isGreaterThan(0);
assertThat(Arrays.binarySearch(sec.getDataIntegrityViolationCodes(), "544")).isGreaterThanOrEqualTo(0);
assertThat(Arrays.binarySearch(sec.getDataIntegrityViolationCodes(), "8114")).isGreaterThanOrEqualTo(0);
assertThat(Arrays.binarySearch(sec.getDataIntegrityViolationCodes(), "8115")).isGreaterThanOrEqualTo(0);
assertThat(sec.getDataIntegrityViolationCodes()).isNotEmpty();
assertThat(sec.getDataIntegrityViolationCodes()).contains("544");
assertThat(sec.getDataIntegrityViolationCodes()).contains("8114");
assertThat(sec.getDataIntegrityViolationCodes()).contains("8115");
assertThat(sec.getDataAccessResourceFailureCodes().length).isGreaterThan(0);
assertThat(Arrays.binarySearch(sec.getDataAccessResourceFailureCodes(), "4060")).isGreaterThanOrEqualTo(0);
assertThat(sec.getDataAccessResourceFailureCodes()).isNotEmpty();
assertThat(sec.getDataAccessResourceFailureCodes()).contains("4060");
assertThat(sec.getCannotAcquireLockCodes().length).isGreaterThan(0);
assertThat(Arrays.binarySearch(sec.getCannotAcquireLockCodes(), "1222")).isGreaterThanOrEqualTo(0);
assertThat(sec.getCannotAcquireLockCodes()).isNotEmpty();
assertThat(sec.getCannotAcquireLockCodes()).contains("1222");
assertThat(sec.getDeadlockLoserCodes().length).isGreaterThan(0);
assertThat(Arrays.binarySearch(sec.getDeadlockLoserCodes(), "1205")).isGreaterThanOrEqualTo(0);
assertThat(sec.getDeadlockLoserCodes()).isNotEmpty();
assertThat(sec.getDeadlockLoserCodes()).contains("1205");
}
private void assertIsHsql(SQLErrorCodes sec) {
assertThat(sec.getBadSqlGrammarCodes().length).isGreaterThan(0);
assertThat(sec.getDataIntegrityViolationCodes().length).isGreaterThan(0);
assertThat(sec.getBadSqlGrammarCodes()).isNotEmpty();
assertThat(sec.getDataIntegrityViolationCodes()).isNotEmpty();
// This had better be a Bad SQL Grammar code
assertThat(Arrays.binarySearch(sec.getBadSqlGrammarCodes(), "-22")).isGreaterThanOrEqualTo(0);
assertThat(sec.getBadSqlGrammarCodes()).contains("-22");
// This had better NOT be
assertThat(Arrays.binarySearch(sec.getBadSqlGrammarCodes(), "-9")).isLessThan(0);
assertThat(sec.getBadSqlGrammarCodes()).doesNotContain("-9");
}
private void assertIsDB2(SQLErrorCodes sec) {
assertThat(sec.getBadSqlGrammarCodes().length).isGreaterThan(0);
assertThat(sec.getDataIntegrityViolationCodes().length).isGreaterThan(0);
assertThat(sec.getBadSqlGrammarCodes()).isNotEmpty();
assertThat(sec.getDataIntegrityViolationCodes()).isNotEmpty();
assertThat(Arrays.binarySearch(sec.getBadSqlGrammarCodes(), "942")).isLessThan(0);
assertThat(sec.getBadSqlGrammarCodes()).doesNotContain("942");
// This had better NOT be
assertThat(Arrays.binarySearch(sec.getBadSqlGrammarCodes(), "-204")).isGreaterThanOrEqualTo(0);
assertThat(sec.getBadSqlGrammarCodes()).contains("-204");
}
private void assertIsHana(SQLErrorCodes sec) {
assertThat(sec.getBadSqlGrammarCodes().length).isGreaterThan(0);
assertThat(sec.getDataIntegrityViolationCodes().length).isGreaterThan(0);
assertThat(Arrays.binarySearch(sec.getBadSqlGrammarCodes(), "368")).isGreaterThanOrEqualTo(0);
assertThat(Arrays.binarySearch(sec.getPermissionDeniedCodes(), "10")).isGreaterThanOrEqualTo(0);
assertThat(Arrays.binarySearch(sec.getDuplicateKeyCodes(), "301")).isGreaterThanOrEqualTo(0);
assertThat(Arrays.binarySearch(sec.getDataIntegrityViolationCodes(), "461")).isGreaterThanOrEqualTo(0);
assertThat(Arrays.binarySearch(sec.getDataAccessResourceFailureCodes(), "-813")).isGreaterThanOrEqualTo(0);
assertThat(Arrays.binarySearch(sec.getInvalidResultSetAccessCodes(), "582")).isGreaterThanOrEqualTo(0);
assertThat(Arrays.binarySearch(sec.getCannotAcquireLockCodes(), "131")).isGreaterThanOrEqualTo(0);
assertThat(Arrays.binarySearch(sec.getCannotSerializeTransactionCodes(), "138")).isGreaterThanOrEqualTo(0);
assertThat(Arrays.binarySearch(sec.getDeadlockLoserCodes(), "133")).isGreaterThanOrEqualTo(0);
assertThat(sec.getBadSqlGrammarCodes()).isNotEmpty();
assertThat(sec.getDataIntegrityViolationCodes()).isNotEmpty();
assertThat(sec.getBadSqlGrammarCodes()).contains("368");
assertThat(sec.getPermissionDeniedCodes()).contains("10");
assertThat(sec.getDuplicateKeyCodes()).contains("301");
assertThat(sec.getDataIntegrityViolationCodes()).contains("461");
assertThat(sec.getDataAccessResourceFailureCodes()).contains("-813");
assertThat(sec.getInvalidResultSetAccessCodes()).contains("582");
assertThat(sec.getCannotAcquireLockCodes()).contains("131");
assertThat(sec.getCannotSerializeTransactionCodes()).contains("138");
assertThat(sec.getDeadlockLoserCodes()).contains("133");
}
@Test
public void testLookupOrder() {
void lookupOrder() {
class TestSQLErrorCodesFactory extends SQLErrorCodesFactory {
private int lookups = 0;
@Override
@ -163,15 +162,15 @@ public class SQLErrorCodesFactoryTests {
// Should have failed to load without error
TestSQLErrorCodesFactory sf = new TestSQLErrorCodesFactory();
assertThat(sf.getErrorCodes("XX").getBadSqlGrammarCodes().length).isEqualTo(0);
assertThat(sf.getErrorCodes("Oracle").getDataIntegrityViolationCodes().length).isEqualTo(0);
assertThat(sf.getErrorCodes("XX").getBadSqlGrammarCodes()).isEmpty();
assertThat(sf.getErrorCodes("Oracle").getDataIntegrityViolationCodes()).isEmpty();
}
/**
* Check that user defined error codes take precedence.
*/
@Test
public void testFindUserDefinedCodes() {
void findUserDefinedCodes() {
class TestSQLErrorCodesFactory extends SQLErrorCodesFactory {
@Override
protected Resource loadResource(String path) {
@ -184,14 +183,12 @@ public class SQLErrorCodesFactoryTests {
// Should have loaded without error
TestSQLErrorCodesFactory sf = new TestSQLErrorCodesFactory();
assertThat(sf.getErrorCodes("XX").getBadSqlGrammarCodes().length).isEqualTo(0);
assertThat(sf.getErrorCodes("Oracle").getBadSqlGrammarCodes()).hasSize(2);
assertThat(sf.getErrorCodes("Oracle").getBadSqlGrammarCodes()[0]).isEqualTo("1");
assertThat(sf.getErrorCodes("Oracle").getBadSqlGrammarCodes()[1]).isEqualTo("2");
assertThat(sf.getErrorCodes("XX").getBadSqlGrammarCodes()).isEmpty();
assertThat(sf.getErrorCodes("Oracle").getBadSqlGrammarCodes()).containsExactly("1", "2");
}
@Test
public void testInvalidUserDefinedCodeFormat() {
void invalidUserDefinedCodeFormat() {
class TestSQLErrorCodesFactory extends SQLErrorCodesFactory {
@Override
protected Resource loadResource(String path) {
@ -205,7 +202,7 @@ public class SQLErrorCodesFactoryTests {
// Should have failed to load without error
TestSQLErrorCodesFactory sf = new TestSQLErrorCodesFactory();
assertThat(sf.getErrorCodes("XX").getBadSqlGrammarCodes().length).isEqualTo(0);
assertThat(sf.getErrorCodes("XX").getBadSqlGrammarCodes()).isEmpty();
assertThat(sf.getErrorCodes("Oracle").getBadSqlGrammarCodes()).isEmpty();
}
@ -213,7 +210,7 @@ public class SQLErrorCodesFactoryTests {
* Check that custom error codes take precedence.
*/
@Test
public void testFindCustomCodes() {
void findCustomCodes() {
class TestSQLErrorCodesFactory extends SQLErrorCodesFactory {
@Override
protected Resource loadResource(String path) {
@ -227,14 +224,13 @@ public class SQLErrorCodesFactoryTests {
// Should have loaded without error
TestSQLErrorCodesFactory sf = new TestSQLErrorCodesFactory();
assertThat(sf.getErrorCodes("Oracle").getCustomTranslations()).hasSize(1);
CustomSQLErrorCodesTranslation translation =
sf.getErrorCodes("Oracle").getCustomTranslations()[0];
CustomSQLErrorCodesTranslation translation = sf.getErrorCodes("Oracle").getCustomTranslations()[0];
assertThat(translation.getExceptionClass()).isEqualTo(CustomErrorCodeException.class);
assertThat(translation.getErrorCodes()).hasSize(1);
}
@Test
public void testDataSourceWithNullMetadata() throws Exception {
void dataSourceWithNullMetadata() throws Exception {
Connection connection = mock();
DataSource dataSource = mock();
given(dataSource.getConnection()).willReturn(connection);
@ -250,7 +246,7 @@ public class SQLErrorCodesFactoryTests {
}
@Test
public void testGetFromDataSourceWithSQLException() throws Exception {
void getFromDataSourceWithSQLException() throws Exception {
SQLException expectedSQLException = new SQLException();
DataSource dataSource = mock();
@ -284,25 +280,25 @@ public class SQLErrorCodesFactoryTests {
}
@Test
public void testSQLServerRecognizedFromMetadata() throws Exception {
void sqlServerRecognizedFromMetadata() throws Exception {
SQLErrorCodes sec = getErrorCodesFromDataSource("MS-SQL", null);
assertIsSQLServer(sec);
}
@Test
public void testOracleRecognizedFromMetadata() throws Exception {
void oracleRecognizedFromMetadata() throws Exception {
SQLErrorCodes sec = getErrorCodesFromDataSource("Oracle", null);
assertIsOracle(sec);
}
@Test
public void testHsqlRecognizedFromMetadata() throws Exception {
void hsqlRecognizedFromMetadata() throws Exception {
SQLErrorCodes sec = getErrorCodesFromDataSource("HSQL Database Engine", null);
assertIsHsql(sec);
}
@Test
public void testDB2RecognizedFromMetadata() throws Exception {
void dB2RecognizedFromMetadata() throws Exception {
SQLErrorCodes sec = getErrorCodesFromDataSource("DB2", null);
assertIsDB2(sec);
sec = getErrorCodesFromDataSource("DB2/", null);
@ -312,7 +308,7 @@ public class SQLErrorCodesFactoryTests {
}
@Test
public void testHanaIsRecognizedFromMetadata() throws Exception {
void hanaIsRecognizedFromMetadata() throws Exception {
SQLErrorCodes sec = getErrorCodesFromDataSource("SAP DB", null);
assertIsHana(sec);
}
@ -321,7 +317,7 @@ public class SQLErrorCodesFactoryTests {
* Check that wild card database name works.
*/
@Test
public void testWildCardNameRecognized() throws Exception {
void wildCardNameRecognized() throws Exception {
class WildcardSQLErrorCodesFactory extends SQLErrorCodesFactory {
@Override
protected Resource loadResource(String path) {

View File

@ -34,86 +34,89 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
/**
* Tests for {@link SQLStateSQLExceptionTranslator}.
*
* @author Rick Evans
* @author Juergen Hoeller
* @author Chris Beams
*/
public class SQLStateSQLExceptionTranslatorTests {
class SQLStateSQLExceptionTranslatorTests {
private final SQLExceptionTranslator translator = new SQLStateSQLExceptionTranslator();
@Test
public void translateNullException() {
assertThatIllegalArgumentException().isThrownBy(() ->
new SQLStateSQLExceptionTranslator().translate("", "", null));
void translateNullException() {
assertThatIllegalArgumentException().isThrownBy(() -> translator.translate("", "", null));
}
@Test
public void translateBadSqlGrammar() {
doTest("07", BadSqlGrammarException.class);
void translateBadSqlGrammar() {
assertTranslation("07", BadSqlGrammarException.class);
}
@Test
public void translateDataIntegrityViolation() {
doTest("23", DataIntegrityViolationException.class);
void translateDataIntegrityViolation() {
assertTranslation("23", DataIntegrityViolationException.class);
}
@Test
public void translateDuplicateKey() {
doTest("23505", DuplicateKeyException.class);
void translateDuplicateKey() {
assertTranslation("23505", DuplicateKeyException.class);
}
@Test
public void translateDuplicateKeyOracle() {
doTest("23000", 1, DuplicateKeyException.class);
void translateDuplicateKeyOracle() {
assertTranslation("23000", 1, DuplicateKeyException.class);
}
@Test
public void translateDuplicateKeyMySQL() {
doTest("23000", 1062, DuplicateKeyException.class);
void translateDuplicateKeyMySQL() {
assertTranslation("23000", 1062, DuplicateKeyException.class);
}
@Test
public void translateDuplicateKeyMSSQL1() {
doTest("23000", 2601, DuplicateKeyException.class);
void translateDuplicateKeyMSSQL1() {
assertTranslation("23000", 2601, DuplicateKeyException.class);
}
@Test
public void translateDuplicateKeyMSSQL2() {
doTest("23000", 2627, DuplicateKeyException.class);
void translateDuplicateKeyMSSQL2() {
assertTranslation("23000", 2627, DuplicateKeyException.class);
}
@Test
public void translateDuplicateKeySapHana() {
doTest("23000", 301, DuplicateKeyException.class);
void translateDuplicateKeySapHana() {
assertTranslation("23000", 301, DuplicateKeyException.class);
}
@Test
public void translateDataAccessResourceFailure() {
doTest("53", DataAccessResourceFailureException.class);
void translateDataAccessResourceFailure() {
assertTranslation("53", DataAccessResourceFailureException.class);
}
@Test
public void translateTransientDataAccessResourceFailure() {
doTest("S1", TransientDataAccessResourceException.class);
void translateTransientDataAccessResourceFailure() {
assertTranslation("S1", TransientDataAccessResourceException.class);
}
@Test
public void translatePessimisticLockingFailure() {
doTest("40", PessimisticLockingFailureException.class);
void translatePessimisticLockingFailure() {
assertTranslation("40", PessimisticLockingFailureException.class);
}
@Test
public void translateCannotAcquireLock() {
doTest("40001", CannotAcquireLockException.class);
void translateCannotAcquireLock() {
assertTranslation("40001", CannotAcquireLockException.class);
}
@Test
public void translateUncategorized() {
doTest("00000000", null);
void translateUncategorized() {
assertTranslation("00000000", null);
}
@Test
public void invalidSqlStateCode() {
doTest("NO SUCH CODE", null);
void invalidSqlStateCode() {
assertTranslation("NO SUCH CODE", null);
}
/**
@ -122,19 +125,18 @@ public class SQLStateSQLExceptionTranslatorTests {
* Bug 729170
*/
@Test
public void malformedSqlStateCodes() {
doTest(null, null);
doTest("", null);
doTest("I", null);
void malformedSqlStateCodes() {
assertTranslation(null, null);
assertTranslation("", null);
assertTranslation("I", null);
}
private void doTest(@Nullable String sqlState, @Nullable Class<?> dataAccessExceptionType) {
doTest(sqlState, 0, dataAccessExceptionType);
private void assertTranslation(@Nullable String sqlState, @Nullable Class<?> dataAccessExceptionType) {
assertTranslation(sqlState, 0, dataAccessExceptionType);
}
private void doTest(@Nullable String sqlState, int errorCode, @Nullable Class<?> dataAccessExceptionType) {
SQLExceptionTranslator translator = new SQLStateSQLExceptionTranslator();
private void assertTranslation(@Nullable String sqlState, int errorCode, @Nullable Class<?> dataAccessExceptionType) {
SQLException ex = new SQLException("reason", sqlState, errorCode);
DataAccessException dax = translator.translate("task", "SQL", ex);

View File

@ -45,17 +45,17 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Mark Paluch
* @author Juergen Hoeller
*/
public class ConnectionFactoryUtilsUnitTests {
class ConnectionFactoryUtilsUnitTests {
@Test
public void shouldTranslateTransientResourceException() {
void shouldTranslateTransientResourceException() {
Exception exception = ConnectionFactoryUtils.convertR2dbcException("", "",
new R2dbcTransientResourceException(""));
assertThat(exception).isExactlyInstanceOf(TransientDataAccessResourceException.class);
}
@Test
public void shouldTranslateRollbackException() {
void shouldTranslateRollbackException() {
Exception exception = ConnectionFactoryUtils.convertR2dbcException("", "",
new R2dbcRollbackException());
assertThat(exception).isExactlyInstanceOf(PessimisticLockingFailureException.class);
@ -66,28 +66,28 @@ public class ConnectionFactoryUtilsUnitTests {
}
@Test
public void shouldTranslateTimeoutException() {
void shouldTranslateTimeoutException() {
Exception exception = ConnectionFactoryUtils.convertR2dbcException("", "",
new R2dbcTimeoutException());
assertThat(exception).isExactlyInstanceOf(QueryTimeoutException.class);
}
@Test
public void shouldNotTranslateUnknownExceptions() {
void shouldNotTranslateUnknownExceptions() {
Exception exception = ConnectionFactoryUtils.convertR2dbcException("", "",
new MyTransientException());
assertThat(exception).isExactlyInstanceOf(UncategorizedR2dbcException.class);
}
@Test
public void shouldTranslateNonTransientResourceException() {
void shouldTranslateNonTransientResourceException() {
Exception exception = ConnectionFactoryUtils.convertR2dbcException("", "",
new R2dbcNonTransientResourceException());
assertThat(exception).isExactlyInstanceOf(DataAccessResourceFailureException.class);
}
@Test
public void shouldTranslateIntegrityViolationException() {
void shouldTranslateIntegrityViolationException() {
Exception exception = ConnectionFactoryUtils.convertR2dbcException("", "",
new R2dbcDataIntegrityViolationException());
assertThat(exception).isExactlyInstanceOf(DataIntegrityViolationException.class);
@ -98,7 +98,7 @@ public class ConnectionFactoryUtilsUnitTests {
exception = ConnectionFactoryUtils.convertR2dbcException("", "",
new R2dbcDataIntegrityViolationException("reason", "23000", 1));
assertThat(exception).isExactlyInstanceOf(DuplicateKeyException.class);
assertThat(exception).as("Oracle").isExactlyInstanceOf(DuplicateKeyException.class);
exception = ConnectionFactoryUtils.convertR2dbcException("", "",
new R2dbcDataIntegrityViolationException("reason", "23000", 301));
@ -106,33 +106,33 @@ public class ConnectionFactoryUtilsUnitTests {
exception = ConnectionFactoryUtils.convertR2dbcException("", "",
new R2dbcDataIntegrityViolationException("reason", "23000", 1062));
assertThat(exception).isExactlyInstanceOf(DuplicateKeyException.class);
assertThat(exception).as("MySQL/MariaDB").isExactlyInstanceOf(DuplicateKeyException.class);
exception = ConnectionFactoryUtils.convertR2dbcException("", "",
new R2dbcDataIntegrityViolationException("reason", "23000", 2601));
assertThat(exception).isExactlyInstanceOf(DuplicateKeyException.class);
assertThat(exception).as("MS SQL Server").isExactlyInstanceOf(DuplicateKeyException.class);
exception = ConnectionFactoryUtils.convertR2dbcException("", "",
new R2dbcDataIntegrityViolationException("reason", "23000", 2627));
assertThat(exception).isExactlyInstanceOf(DuplicateKeyException.class);
assertThat(exception).as("MS SQL Server").isExactlyInstanceOf(DuplicateKeyException.class);
}
@Test
public void shouldTranslatePermissionDeniedException() {
void shouldTranslatePermissionDeniedException() {
Exception exception = ConnectionFactoryUtils.convertR2dbcException("", "",
new R2dbcPermissionDeniedException());
assertThat(exception).isExactlyInstanceOf(PermissionDeniedDataAccessException.class);
}
@Test
public void shouldTranslateBadSqlGrammarException() {
void shouldTranslateBadSqlGrammarException() {
Exception exception = ConnectionFactoryUtils.convertR2dbcException("", "",
new R2dbcBadGrammarException());
assertThat(exception).isExactlyInstanceOf(BadSqlGrammarException.class);
}
@Test
public void messageGeneration() {
void messageGeneration() {
Exception exception = ConnectionFactoryUtils.convertR2dbcException("TASK",
"SOME-SQL", new R2dbcTransientResourceException("MESSAGE"));
assertThat(exception).isExactlyInstanceOf(
@ -140,7 +140,7 @@ public class ConnectionFactoryUtilsUnitTests {
}
@Test
public void messageGenerationNullSQL() {
void messageGenerationNullSQL() {
Exception exception = ConnectionFactoryUtils.convertR2dbcException("TASK", null,
new R2dbcTransientResourceException("MESSAGE"));
assertThat(exception).isExactlyInstanceOf(
@ -148,7 +148,7 @@ public class ConnectionFactoryUtilsUnitTests {
}
@Test
public void messageGenerationNullMessage() {
void messageGenerationNullMessage() {
Exception exception = ConnectionFactoryUtils.convertR2dbcException("TASK",
"SOME-SQL", new R2dbcTransientResourceException());
assertThat(exception).isExactlyInstanceOf(