Skip to content

Commit

Permalink
Added BOOLEAN tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael-A-McMahon committed May 31, 2024
1 parent 17adf49 commit bb26e3e
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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());
}
}

/**
Expand Down
46 changes: 40 additions & 6 deletions src/test/java/oracle/r2dbc/impl/TypeMappingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -436,16 +436,15 @@ public void testJsonMapping() {
tryAwaitNone(connection.close());
}
}

/**
* <p>
* 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.
*</p>
*/
@Test
Expand Down Expand Up @@ -474,6 +473,41 @@ public void testBooleanNumericMapping() {
}
}

/**
* <p>
* 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.
*</p>
*/
@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());
}
}

/**
* <p>
* Verifies the implementation of Java to SQL and SQL to Java type mappings
Expand Down

0 comments on commit bb26e3e

Please sign in to comment.