Skip to content

Commit 3099403

Browse files
jeffjensenclaude
andcommitted
fixup! fix(dataset): Stop TimestampDataType double-shifting TIMESTAMP WITH TIME ZONE writes
Replace TimestampDataTypeIT's exception-driven skip logic with a declarative TestFeature.TIMESTAMP_WITH_TIMEZONE flag, per CodeRabbit feedback that catching any SQLException from the CREATE TABLE step could mask genuine setup failures (permissions, connections, malformed DDL) as "unsupported dialect". The zoned-column test now checks the flag up front, before touching the database; any other SQLException during setup now propagates as a real test failure instead of being swallowed. Verified empirically which of the 9 profiles need the flag by running TimestampDataTypeIT locally (scoped via -Dit.test) against each database: * Derby, MySQL, MSSQL, DB2 reject the CREATE TABLE syntax outright (SQLSyntaxErrorException/equivalent) - a genuine dialect gap. * Oracle 18/23's driver throws SQLFeatureNotSupportedException from getParameterMetaData() itself rather than reporting a mismatched type - a known ojdbc limitation, not a dialect gap, but no other driver exhibits it, so it shares the one flag rather than getting a dedicated one. * H2, HSQLDB, and PostgreSQL all still need no properties change: H2/HSQLDB run the full assertion for real, and PostgreSQL already self-skips cleanly via the pre-existing plain assumeTrue(parameterType == ...) check (pgjdbc reports a different constant without throwing). Refs: 831 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011fr791v2SnTRnyb1eU7LNB
1 parent 4180980 commit 3099403

9 files changed

Lines changed: 29 additions & 31 deletions

src/test/java/org/dbunit/TestFeature.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ public class TestFeature
4141
public static final TestFeature SDO_GEOMETRY =
4242
new TestFeature("SDO_GEOMETRY");
4343
public static final TestFeature XML_TYPE = new TestFeature("XML_TYPE");
44+
public static final TestFeature TIMESTAMP_WITH_TIMEZONE =
45+
new TestFeature("TIMESTAMP_WITH_TIMEZONE");
4446

4547
private final String _name;
4648

src/test/java/org/dbunit/dataset/datatype/TimestampDataTypeIT.java

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
import java.sql.Types;
3333
import java.time.OffsetDateTime;
3434

35+
import org.dbunit.AbstractDatabaseIT;
3536
import org.dbunit.DatabaseEnvironment;
37+
import org.dbunit.TestFeature;
3638
import org.dbunit.database.IDatabaseConnection;
3739
import org.junit.jupiter.api.AfterEach;
3840
import org.junit.jupiter.api.BeforeEach;
@@ -45,14 +47,19 @@
4547
* in-memory driver used by {@link TimestampDataTypeTest}.
4648
*
4749
* <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.
5663
*
5764
* @since 3.4.0
5865
*/
@@ -101,33 +108,22 @@ private void dropTableQuietly(final String tableName)
101108
void testSetSqlValue_withOffsetDifferentFromLocalZone_writesCorrectInstantToTimestampWithTimeZoneColumn()
102109
throws Exception
103110
{
111+
assumeTrue(AbstractDatabaseIT.environmentHasFeature(TestFeature.TIMESTAMP_WITH_TIMEZONE),
112+
"Skipping: active database profile declares TIMESTAMP_WITH_TIMEZONE unsupported "
113+
+ "(see dbunit.profile.unsupportedFeatures).");
114+
104115
final Connection jdbcConnection = connection.getConnection();
105116
dropTableQuietly(ZONED_TABLE);
106117
try (Statement statement = jdbcConnection.createStatement())
107118
{
108119
statement.execute("CREATE TABLE " + ZONED_TABLE
109120
+ " (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());
115121
}
116122

117123
try (PreparedStatement insert = jdbcConnection
118124
.prepareStatement("INSERT INTO " + ZONED_TABLE + " VALUES (1, ?)"))
119125
{
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);
131127
assumeTrue(parameterType == Types.TIMESTAMP_WITH_TIMEZONE,
132128
"Skipping: active database driver does not report TIMESTAMP_WITH_TIMEZONE "
133129
+ "parameter metadata for this column.");

src/test/resources/db2-dbunit.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ dbunit.profile.schema=DBUNIT
55
dbunit.profile.user=dbunit
66
dbunit.profile.password=dbunit
77
dbunit.profile.ddl=db2xml.sql
8-
dbunit.profile.unsupportedFeatures=BLOB,CLOB,INSERT_IDENTITY,SDO_GEOMETRY,XML_TYPE
8+
dbunit.profile.unsupportedFeatures=BLOB,CLOB,INSERT_IDENTITY,SDO_GEOMETRY,XML_TYPE,TIMESTAMP_WITH_TIMEZONE
99
dbunit.profile.multiLineSupport=false

src/test/resources/derby-dbunit.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ dbunit.profile.schema=APP
55
dbunit.profile.user=APP
66
dbunit.profile.password=APP
77
dbunit.profile.ddl=derby.sql
8-
dbunit.profile.unsupportedFeatures=VARBINARY,BLOB,CLOB,INSERT_IDENTITY,SDO_GEOMETRY,XML_TYPE
8+
dbunit.profile.unsupportedFeatures=VARBINARY,BLOB,CLOB,INSERT_IDENTITY,SDO_GEOMETRY,XML_TYPE,TIMESTAMP_WITH_TIMEZONE
99
dbunit.profile.multiLineSupport=false

src/test/resources/mssql2022-dbunit.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ dbunit.profile.schema=dbo
55
dbunit.profile.user=sa
66
dbunit.profile.password=theSaPassword1234
77
dbunit.profile.ddl=mssql.sql
8-
dbunit.profile.unsupportedFeatures=BLOB,CLOB,SCROLLABLE_RESULTSET,SDO_GEOMETRY,XML_TYPE
8+
dbunit.profile.unsupportedFeatures=BLOB,CLOB,SCROLLABLE_RESULTSET,SDO_GEOMETRY,XML_TYPE,TIMESTAMP_WITH_TIMEZONE
99
dbunit.profile.multiLineSupport=false

src/test/resources/mssql41-dbunit.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ dbunit.profile.schema=dbo
55
dbunit.profile.user=dbunit
66
dbunit.profile.password=dbunit
77
dbunit.profile.ddl=mssql.sql
8-
dbunit.profile.unsupportedFeatures=BLOB,CLOB,SCROLLABLE_RESULTSET,SDO_GEOMETRY,XML_TYPE
8+
dbunit.profile.unsupportedFeatures=BLOB,CLOB,SCROLLABLE_RESULTSET,SDO_GEOMETRY,XML_TYPE,TIMESTAMP_WITH_TIMEZONE
99
dbunit.profile.multiLineSupport=false

src/test/resources/mysql-dbunit.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ dbunit.profile.schema=
55
dbunit.profile.user=dbunit
66
dbunit.profile.password=dbunit
77
dbunit.profile.ddl=mysql.sql
8-
dbunit.profile.unsupportedFeatures=BLOB,CLOB,SCROLLABLE_RESULTSET,INSERT_IDENTITY,SDO_GEOMETRY,XML_TYPE
8+
dbunit.profile.unsupportedFeatures=BLOB,CLOB,SCROLLABLE_RESULTSET,INSERT_IDENTITY,SDO_GEOMETRY,XML_TYPE,TIMESTAMP_WITH_TIMEZONE
99
dbunit.profile.multiLineSupport=false

src/test/resources/oracle-free-dbunit.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ dbunit.profile.schema=DBUNIT
55
dbunit.profile.user=dbunit
66
dbunit.profile.password=dbunit
77
dbunit.profile.ddl=oracle.sql
8-
dbunit.profile.unsupportedFeatures=INSERT_IDENTITY
8+
dbunit.profile.unsupportedFeatures=INSERT_IDENTITY,TIMESTAMP_WITH_TIMEZONE
99
dbunit.profile.multiLineSupport=false

src/test/resources/oracle-xe-dbunit.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ dbunit.profile.schema=DBUNIT
55
dbunit.profile.user=dbunit
66
dbunit.profile.password=dbunit
77
dbunit.profile.ddl=oracle.sql
8-
dbunit.profile.unsupportedFeatures=INSERT_IDENTITY
8+
dbunit.profile.unsupportedFeatures=INSERT_IDENTITY,TIMESTAMP_WITH_TIMEZONE
99
dbunit.profile.multiLineSupport=false

0 commit comments

Comments
 (0)