Skip to content

Tests for BOOLEAN #148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading