From bb26e3ee2b720d00b76cccee051d377b29af2d4b Mon Sep 17 00:00:00 2001 From: Michael McMahon Date: Fri, 31 May 2024 13:35:58 -0700 Subject: [PATCH] Added BOOLEAN tests --- .../impl/OracleReadableMetadataImplTest.java | 26 ++++++++++- .../oracle/r2dbc/impl/TypeMappingTest.java | 46 ++++++++++++++++--- 2 files changed, 65 insertions(+), 7 deletions(-) diff --git a/src/test/java/oracle/r2dbc/impl/OracleReadableMetadataImplTest.java b/src/test/java/oracle/r2dbc/impl/OracleReadableMetadataImplTest.java index c242994..85b1d3a 100644 --- a/src/test/java/oracle/r2dbc/impl/OracleReadableMetadataImplTest.java +++ b/src/test/java/oracle/r2dbc/impl/OracleReadableMetadataImplTest.java @@ -532,7 +532,8 @@ public void testObjectTypes() { */ @Test public void testVectorType() throws SQLException { - Assumptions.assumeTrue(databaseVersion() >= 23); + Assumptions.assumeTrue(databaseVersion() >= 23, + "VECTOR requires Oracle Database 23ai or newer"); Connection connection = Mono.from(sharedConnection()).block(connectTimeout()); @@ -552,7 +553,30 @@ public void testVectorType() throws SQLException { finally { tryAwaitNone(connection.close()); } + } + + /** + * Verifies the implementation of {@link OracleReadableMetadataImpl} for + * BOOLEAN type columns. When the test database is older than version 23ai, + * this test is ignored; The BOOLEAN type was added in 23ai. + */ + @Test + public void testBooleanType() throws SQLException { + Assumptions.assumeTrue(databaseVersion() >= 23, + "BOOLEAN requires Oracle Database 23ai or newer"); + Connection connection = + Mono.from(sharedConnection()).block(connectTimeout()); + try { + // Expect BOOLEAN and Boolean to map. + verifyColumnMetadata( + connection, "BOOLEAN", JDBCType.BOOLEAN, R2dbcType.BOOLEAN, + null, null, + Boolean.class, true); + } + finally { + tryAwaitNone(connection.close()); + } } /** diff --git a/src/test/java/oracle/r2dbc/impl/TypeMappingTest.java b/src/test/java/oracle/r2dbc/impl/TypeMappingTest.java index 17574c8..82a9c5a 100644 --- a/src/test/java/oracle/r2dbc/impl/TypeMappingTest.java +++ b/src/test/java/oracle/r2dbc/impl/TypeMappingTest.java @@ -436,16 +436,15 @@ public void testJsonMapping() { tryAwaitNone(connection.close()); } } - /** *

* Verifies the implementation of Java to SQL and SQL to Java type mappings * where the Java type is {@link Boolean} and the SQL type is a numeric type. - * The R2DBC 0.9.0 Specification only requires that Java {@code Boolean} be - * mapped to the SQL BOOLEAN type, however Oracle Database does not support a - * BOOLEAN column type. To allow the use of the {@code Boolean} bind - * values, Oracle JDBC supports binding the Boolean as a NUMBER. Oracle - * R2DBC is expected to expose this functionality as well. + * The R2DBC 1.0.0 Specification only requires that Java {@code Boolean} be + * mapped to the SQL BOOLEAN type, however Oracle Database did not support a + * BOOLEAN column type until the 23ai release. To allow the use of the + * {@code Boolean} bind values, Oracle JDBC supports binding the Boolean as a + * NUMBER. Oracle R2DBC is expected to expose this functionality as well. *

*/ @Test @@ -474,6 +473,41 @@ public void testBooleanNumericMapping() { } } + /** + *

+ * Verifies the implementation of Java to SQL and SQL to Java type mappings + * where the Java type is {@link Boolean} and the SQL type is BOOLEAN. Oracle + * Database added support for a BOOLEAN column type in the 23ai release. + *

+ */ + @Test + public void testBooleanMapping() { + assumeTrue(databaseVersion() >= 23, + "BOOLEAN requires Oracle Database 23ai or newer"); + + Connection connection = + Mono.from(sharedConnection()).block(connectTimeout()); + try { + // Expect BOOLEAN and Boolean to map + verifyTypeMapping(connection, true, "BOOLEAN", + (expected, actual) -> assertEquals(Boolean.TRUE, actual)); + verifyTypeMapping(connection, false, "BOOLEAN", + (expected, actual) -> assertEquals(Boolean.FALSE, actual)); + + // Expect NUMBER and Boolean to map, with Row.get(..., Boolean.class) + // mapping the NUMBER column value to Boolean + verifyTypeMapping(connection, true, "BOOLEAN", + row -> row.get(0, Boolean.class), + (expected, actual) -> assertTrue(actual)); + verifyTypeMapping(connection, false, "BOOLEAN", + row -> row.get(0, Boolean.class), + (expected, actual) -> assertFalse(actual)); + } + finally { + tryAwaitNone(connection.close()); + } + } + /** *

* Verifies the implementation of Java to SQL and SQL to Java type mappings