|
16 | 16 |
|
17 | 17 | package org.springframework.r2dbc.connection; |
18 | 18 |
|
| 19 | +import java.util.List; |
| 20 | + |
19 | 21 | import io.r2dbc.spi.R2dbcBadGrammarException; |
20 | 22 | import io.r2dbc.spi.R2dbcDataIntegrityViolationException; |
21 | 23 | import io.r2dbc.spi.R2dbcException; |
|
27 | 29 | import org.junit.jupiter.api.Test; |
28 | 30 | import org.junit.jupiter.params.ParameterizedTest; |
29 | 31 | import org.junit.jupiter.params.provider.Arguments; |
30 | | -import org.junit.jupiter.params.provider.MethodSource; |
| 32 | +import org.junit.jupiter.params.provider.FieldSource; |
| 33 | + |
31 | 34 | import org.springframework.dao.CannotAcquireLockException; |
32 | 35 | import org.springframework.dao.DataAccessResourceFailureException; |
33 | 36 | import org.springframework.dao.DataIntegrityViolationException; |
|
39 | 42 | import org.springframework.r2dbc.BadSqlGrammarException; |
40 | 43 | import org.springframework.r2dbc.UncategorizedR2dbcException; |
41 | 44 |
|
42 | | -import java.util.stream.Stream; |
43 | | - |
44 | 45 | import static org.assertj.core.api.Assertions.assertThat; |
45 | | - |
46 | | - |
| 46 | +import static org.junit.jupiter.params.provider.Arguments.arguments; |
47 | 47 |
|
48 | 48 | /** |
49 | 49 | * Tests for {@link ConnectionFactoryUtils}. |
@@ -92,34 +92,32 @@ void shouldTranslateNonTransientResourceException() { |
92 | 92 | assertThat(exception).isExactlyInstanceOf(DataAccessResourceFailureException.class); |
93 | 93 | } |
94 | 94 |
|
95 | | - private static Stream<Arguments> duplicateKeyErrorCodes() { |
96 | | - return Stream.of( |
97 | | - Arguments.of("Oracle", "23505", 0), |
98 | | - Arguments.of("Oracle", "23000", 1), |
99 | | - Arguments.of("SAP HANA", "23000", 301), |
100 | | - Arguments.of("MySQL/MariaDB", "23000", 1062), |
101 | | - Arguments.of("MS SQL Server", "23000", 2601), |
102 | | - Arguments.of("MS SQL Server", "23000", 2627), |
103 | | - Arguments.of("Informix", "23000", -239), |
104 | | - Arguments.of("Informix", "23000", -268) |
105 | | - ); |
| 95 | + @Test |
| 96 | + void shouldTranslateIntegrityViolationException() { |
| 97 | + Exception exception = ConnectionFactoryUtils.convertR2dbcException("", "", |
| 98 | + new R2dbcDataIntegrityViolationException()); |
| 99 | + assertThat(exception).isExactlyInstanceOf(DataIntegrityViolationException.class); |
106 | 100 | } |
107 | 101 |
|
| 102 | + static final List<Arguments> duplicateKeyErrorCodes = List.of( |
| 103 | + arguments("Oracle", "23505", 0), |
| 104 | + arguments("Oracle", "23000", 1), |
| 105 | + arguments("SAP HANA", "23000", 301), |
| 106 | + arguments("MySQL/MariaDB", "23000", 1062), |
| 107 | + arguments("MS SQL Server", "23000", 2601), |
| 108 | + arguments("MS SQL Server", "23000", 2627), |
| 109 | + arguments("Informix", "23000", -239), |
| 110 | + arguments("Informix", "23000", -268) |
| 111 | + ); |
| 112 | + |
108 | 113 | @ParameterizedTest |
109 | | - @MethodSource("duplicateKeyErrorCodes") |
110 | | - void shouldTranslateIntegrityViolationException(final String db, String sqlState, final int errorCode) { |
| 114 | + @FieldSource("duplicateKeyErrorCodes") |
| 115 | + void shouldTranslateIntegrityViolationExceptionToDuplicateKeyException(String db, String sqlState, int errorCode) { |
111 | 116 | Exception exception = ConnectionFactoryUtils.convertR2dbcException("", "", |
112 | 117 | new R2dbcDataIntegrityViolationException("reason", sqlState, errorCode)); |
113 | 118 | assertThat(exception).as(db).isExactlyInstanceOf(DuplicateKeyException.class); |
114 | 119 | } |
115 | 120 |
|
116 | | - @Test |
117 | | - void shouldTranslateGenericIntegrityViolationException() { |
118 | | - Exception exception = ConnectionFactoryUtils.convertR2dbcException("", "", |
119 | | - new R2dbcDataIntegrityViolationException()); |
120 | | - assertThat(exception).isExactlyInstanceOf(DataIntegrityViolationException.class); |
121 | | - } |
122 | | - |
123 | 121 | @Test |
124 | 122 | void shouldTranslatePermissionDeniedException() { |
125 | 123 | Exception exception = ConnectionFactoryUtils.convertR2dbcException("", "", |
|
0 commit comments