|
32 | 32 | import java.sql.Types; |
33 | 33 | import java.time.OffsetDateTime; |
34 | 34 |
|
| 35 | +import org.dbunit.AbstractDatabaseIT; |
35 | 36 | import org.dbunit.DatabaseEnvironment; |
| 37 | +import org.dbunit.TestFeature; |
36 | 38 | import org.dbunit.database.IDatabaseConnection; |
37 | 39 | import org.junit.jupiter.api.AfterEach; |
38 | 40 | import org.junit.jupiter.api.BeforeEach; |
|
45 | 47 | * in-memory driver used by {@link TimestampDataTypeTest}. |
46 | 48 | * |
47 | 49 | * <p> |
48 | | - * The zoned-column test skips itself (rather than failing) when the active profile's SQL dialect |
49 | | - * rejects {@code TIMESTAMP WITH TIME ZONE} column syntax, or when its JDBC driver cannot report |
50 | | - * {@link Types#TIMESTAMP_WITH_TIMEZONE} from {@link java.sql.ParameterMetaData} for such a |
51 | | - * column, whether by returning a different constant or by throwing {@link java.sql.SQLException} |
52 | | - * (as Oracle's driver does); the fix falls back safely from both, so neither is a code defect. |
53 | | - * The plain-TIMESTAMP fallback test needs no such gating since every supported database accepts |
54 | | - * that syntax, though it substitutes {@code DATETIME2} on SQL Server, whose {@code TIMESTAMP} type |
55 | | - * is an unrelated, non-nullable row-versioning type rather than a date/time type. |
| 50 | + * The zoned-column test skips itself (rather than failing) on any profile declaring |
| 51 | + * {@link TestFeature#TIMESTAMP_WITH_TIMEZONE} unsupported via |
| 52 | + * {@code dbunit.profile.unsupportedFeatures} - either because the SQL dialect rejects |
| 53 | + * {@code TIMESTAMP WITH TIME ZONE} column syntax outright (e.g. Derby, MySQL, SQL Server, which |
| 54 | + * has no equivalent type), or because the JDBC driver cannot reliably report |
| 55 | + * {@link Types#TIMESTAMP_WITH_TIMEZONE} from {@link java.sql.ParameterMetaData} for such a column |
| 56 | + * even though the database itself supports the type (a known limitation of Oracle's driver, not a |
| 57 | + * dbunit defect). Declaring the gap in the profile up front - rather than discovering it by |
| 58 | + * catching whatever exception a given driver happens to throw - means any other failure during |
| 59 | + * setup surfaces as a real test error instead of being silently treated as unsupported. The |
| 60 | + * plain-TIMESTAMP fallback test needs no such gating since every supported database accepts that |
| 61 | + * syntax, though it substitutes {@code DATETIME2} on SQL Server, whose {@code TIMESTAMP} type is |
| 62 | + * an unrelated, non-nullable row-versioning type rather than a date/time type. |
56 | 63 | * |
57 | 64 | * @since 3.4.0 |
58 | 65 | */ |
@@ -101,33 +108,22 @@ private void dropTableQuietly(final String tableName) |
101 | 108 | void testSetSqlValue_withOffsetDifferentFromLocalZone_writesCorrectInstantToTimestampWithTimeZoneColumn() |
102 | 109 | throws Exception |
103 | 110 | { |
| 111 | + assumeTrue(AbstractDatabaseIT.environmentHasFeature(TestFeature.TIMESTAMP_WITH_TIMEZONE), |
| 112 | + "Skipping: active database profile declares TIMESTAMP_WITH_TIMEZONE unsupported " |
| 113 | + + "(see dbunit.profile.unsupportedFeatures)."); |
| 114 | + |
104 | 115 | final Connection jdbcConnection = connection.getConnection(); |
105 | 116 | dropTableQuietly(ZONED_TABLE); |
106 | 117 | try (Statement statement = jdbcConnection.createStatement()) |
107 | 118 | { |
108 | 119 | statement.execute("CREATE TABLE " + ZONED_TABLE |
109 | 120 | + " (ID INTEGER NOT NULL PRIMARY KEY, TIM TIMESTAMP WITH TIME ZONE)"); |
110 | | - } catch (final SQLException e) |
111 | | - { |
112 | | - assumeTrue(false, |
113 | | - "Skipping: active database profile does not support TIMESTAMP WITH TIME ZONE columns: " |
114 | | - + e.getMessage()); |
115 | 121 | } |
116 | 122 |
|
117 | 123 | try (PreparedStatement insert = jdbcConnection |
118 | 124 | .prepareStatement("INSERT INTO " + ZONED_TABLE + " VALUES (1, ?)")) |
119 | 125 | { |
120 | | - final int parameterType; |
121 | | - try |
122 | | - { |
123 | | - parameterType = insert.getParameterMetaData().getParameterType(1); |
124 | | - } catch (final SQLException e) |
125 | | - { |
126 | | - assumeTrue(false, |
127 | | - "Skipping: active database driver cannot report parameter metadata for a " |
128 | | - + "TIMESTAMP WITH TIME ZONE column: " + e.getMessage()); |
129 | | - return; |
130 | | - } |
| 126 | + final int parameterType = insert.getParameterMetaData().getParameterType(1); |
131 | 127 | assumeTrue(parameterType == Types.TIMESTAMP_WITH_TIMEZONE, |
132 | 128 | "Skipping: active database driver does not report TIMESTAMP_WITH_TIMEZONE " |
133 | 129 | + "parameter metadata for this column."); |
|
0 commit comments