@ -25,7 +25,9 @@ import io.r2dbc.spi.R2dbcRollbackException;
@@ -25,7 +25,9 @@ import io.r2dbc.spi.R2dbcRollbackException;
import io.r2dbc.spi.R2dbcTimeoutException ;
import io.r2dbc.spi.R2dbcTransientResourceException ;
import org.junit.jupiter.api.Test ;
import org.junit.jupiter.params.ParameterizedTest ;
import org.junit.jupiter.params.provider.Arguments ;
import org.junit.jupiter.params.provider.MethodSource ;
import org.springframework.dao.CannotAcquireLockException ;
import org.springframework.dao.DataAccessResourceFailureException ;
import org.springframework.dao.DataIntegrityViolationException ;
@ -37,8 +39,12 @@ import org.springframework.dao.TransientDataAccessResourceException;
@@ -37,8 +39,12 @@ import org.springframework.dao.TransientDataAccessResourceException;
import org.springframework.r2dbc.BadSqlGrammarException ;
import org.springframework.r2dbc.UncategorizedR2dbcException ;
import java.util.stream.Stream ;
import static org.assertj.core.api.Assertions.assertThat ;
/ * *
* Tests for { @link ConnectionFactoryUtils } .
*
@ -86,35 +92,32 @@ class ConnectionFactoryUtilsTests {
@@ -86,35 +92,32 @@ class ConnectionFactoryUtilsTests {
assertThat ( exception ) . isExactlyInstanceOf ( DataAccessResourceFailureException . class ) ;
}
private static Stream < Arguments > duplicateKeyErrorCodes ( ) {
return Stream . of (
Arguments . of ( "Oracle" , "23505" , 0 ) ,
Arguments . of ( "Oracle" , "23000" , 1 ) ,
Arguments . of ( "SAP HANA" , "23000" , 301 ) ,
Arguments . of ( "MySQL/MariaDB" , "23000" , 1062 ) ,
Arguments . of ( "MS SQL Server" , "23000" , 2601 ) ,
Arguments . of ( "MS SQL Server" , "23000" , 2627 ) ,
Arguments . of ( "Informix" , "23000" , - 239 ) ,
Arguments . of ( "Informix" , "23000" , - 268 )
) ;
}
@ParameterizedTest
@MethodSource ( "duplicateKeyErrorCodes" )
void shouldTranslateIntegrityViolationException ( final String db , String sqlState , final int errorCode ) {
Exception exception = ConnectionFactoryUtils . convertR2dbcException ( "" , "" ,
new R2dbcDataIntegrityViolationException ( "reason" , sqlState , errorCode ) ) ;
assertThat ( exception ) . as ( db ) . isExactlyInstanceOf ( DuplicateKeyException . class ) ;
}
@Test
void shouldTranslateIntegrityViolationException ( ) {
void shouldTranslateGeneric IntegrityViolationException ( ) {
Exception exception = ConnectionFactoryUtils . convertR2dbcException ( "" , "" ,
new R2dbcDataIntegrityViolationException ( ) ) ;
assertThat ( exception ) . isExactlyInstanceOf ( DataIntegrityViolationException . class ) ;
exception = ConnectionFactoryUtils . convertR2dbcException ( "" , "" ,
new R2dbcDataIntegrityViolationException ( "reason" , "23505" ) ) ;
assertThat ( exception ) . isExactlyInstanceOf ( DuplicateKeyException . class ) ;
exception = ConnectionFactoryUtils . convertR2dbcException ( "" , "" ,
new R2dbcDataIntegrityViolationException ( "reason" , "23000" , 1 ) ) ;
assertThat ( exception ) . as ( "Oracle" ) . isExactlyInstanceOf ( DuplicateKeyException . class ) ;
exception = ConnectionFactoryUtils . convertR2dbcException ( "" , "" ,
new R2dbcDataIntegrityViolationException ( "reason" , "23000" , 301 ) ) ;
assertThat ( exception ) . as ( "SAP HANA" ) . isExactlyInstanceOf ( DuplicateKeyException . class ) ;
exception = ConnectionFactoryUtils . convertR2dbcException ( "" , "" ,
new R2dbcDataIntegrityViolationException ( "reason" , "23000" , 1062 ) ) ;
assertThat ( exception ) . as ( "MySQL/MariaDB" ) . isExactlyInstanceOf ( DuplicateKeyException . class ) ;
exception = ConnectionFactoryUtils . convertR2dbcException ( "" , "" ,
new R2dbcDataIntegrityViolationException ( "reason" , "23000" , 2601 ) ) ;
assertThat ( exception ) . as ( "MS SQL Server" ) . isExactlyInstanceOf ( DuplicateKeyException . class ) ;
exception = ConnectionFactoryUtils . convertR2dbcException ( "" , "" ,
new R2dbcDataIntegrityViolationException ( "reason" , "23000" , 2627 ) ) ;
assertThat ( exception ) . as ( "MS SQL Server" ) . isExactlyInstanceOf ( DuplicateKeyException . class ) ;
}
@Test