|
25 | 25 | import io.r2dbc.spi.R2dbcTimeoutException;
|
26 | 26 | import io.r2dbc.spi.R2dbcTransientResourceException;
|
27 | 27 | import org.junit.jupiter.api.Test;
|
28 |
| - |
| 28 | +import org.junit.jupiter.params.ParameterizedTest; |
| 29 | +import org.junit.jupiter.params.provider.Arguments; |
| 30 | +import org.junit.jupiter.params.provider.MethodSource; |
29 | 31 | import org.springframework.dao.CannotAcquireLockException;
|
30 | 32 | import org.springframework.dao.DataAccessResourceFailureException;
|
31 | 33 | import org.springframework.dao.DataIntegrityViolationException;
|
|
37 | 39 | import org.springframework.r2dbc.BadSqlGrammarException;
|
38 | 40 | import org.springframework.r2dbc.UncategorizedR2dbcException;
|
39 | 41 |
|
| 42 | +import java.util.stream.Stream; |
| 43 | + |
40 | 44 | import static org.assertj.core.api.Assertions.assertThat;
|
41 | 45 |
|
| 46 | + |
| 47 | + |
42 | 48 | /**
|
43 | 49 | * Tests for {@link ConnectionFactoryUtils}.
|
44 | 50 | *
|
@@ -86,35 +92,32 @@ void shouldTranslateNonTransientResourceException() {
|
86 | 92 | assertThat(exception).isExactlyInstanceOf(DataAccessResourceFailureException.class);
|
87 | 93 | }
|
88 | 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 | + ); |
| 106 | + } |
| 107 | + |
| 108 | + @ParameterizedTest |
| 109 | + @MethodSource("duplicateKeyErrorCodes") |
| 110 | + void shouldTranslateIntegrityViolationException(final String db, String sqlState, final int errorCode) { |
| 111 | + Exception exception = ConnectionFactoryUtils.convertR2dbcException("", "", |
| 112 | + new R2dbcDataIntegrityViolationException("reason", sqlState, errorCode)); |
| 113 | + assertThat(exception).as(db).isExactlyInstanceOf(DuplicateKeyException.class); |
| 114 | + } |
| 115 | + |
89 | 116 | @Test
|
90 |
| - void shouldTranslateIntegrityViolationException() { |
| 117 | + void shouldTranslateGenericIntegrityViolationException() { |
91 | 118 | Exception exception = ConnectionFactoryUtils.convertR2dbcException("", "",
|
92 | 119 | new R2dbcDataIntegrityViolationException());
|
93 | 120 | assertThat(exception).isExactlyInstanceOf(DataIntegrityViolationException.class);
|
94 |
| - |
95 |
| - exception = ConnectionFactoryUtils.convertR2dbcException("", "", |
96 |
| - new R2dbcDataIntegrityViolationException("reason", "23505")); |
97 |
| - assertThat(exception).isExactlyInstanceOf(DuplicateKeyException.class); |
98 |
| - |
99 |
| - exception = ConnectionFactoryUtils.convertR2dbcException("", "", |
100 |
| - new R2dbcDataIntegrityViolationException("reason", "23000", 1)); |
101 |
| - assertThat(exception).as("Oracle").isExactlyInstanceOf(DuplicateKeyException.class); |
102 |
| - |
103 |
| - exception = ConnectionFactoryUtils.convertR2dbcException("", "", |
104 |
| - new R2dbcDataIntegrityViolationException("reason", "23000", 301)); |
105 |
| - assertThat(exception).as("SAP HANA").isExactlyInstanceOf(DuplicateKeyException.class); |
106 |
| - |
107 |
| - exception = ConnectionFactoryUtils.convertR2dbcException("", "", |
108 |
| - new R2dbcDataIntegrityViolationException("reason", "23000", 1062)); |
109 |
| - assertThat(exception).as("MySQL/MariaDB").isExactlyInstanceOf(DuplicateKeyException.class); |
110 |
| - |
111 |
| - exception = ConnectionFactoryUtils.convertR2dbcException("", "", |
112 |
| - new R2dbcDataIntegrityViolationException("reason", "23000", 2601)); |
113 |
| - assertThat(exception).as("MS SQL Server").isExactlyInstanceOf(DuplicateKeyException.class); |
114 |
| - |
115 |
| - exception = ConnectionFactoryUtils.convertR2dbcException("", "", |
116 |
| - new R2dbcDataIntegrityViolationException("reason", "23000", 2627)); |
117 |
| - assertThat(exception).as("MS SQL Server").isExactlyInstanceOf(DuplicateKeyException.class); |
118 | 121 | }
|
119 | 122 |
|
120 | 123 | @Test
|
|
0 commit comments