Skip to content

Commit

Permalink
merge getString getBytes and getObject test into one method to reuse …
Browse files Browse the repository at this point in the history
…queried resultSet
  • Loading branch information
sfc-gh-mkubik committed Nov 26, 2024
1 parent 9e97ba7 commit 2b9636d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.snowflake.client.jdbc.structuredtypes;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
Expand All @@ -23,6 +24,7 @@ public class StructuredTypesArrowJsonCompatibilityLatestIT extends StructuredTyp
private final String expectedStructureTypeRepresentation;
private final String selectSql;
private static Map<ResultSetFormatType, Connection> connections = new HashMap<>();
private static Map<ResultSetFormatType, Map<String, ResultSet>> resultSets = new HashMap<>();

public StructuredTypesArrowJsonCompatibilityLatestIT(
ResultSetFormatType queryResultFormat,
Expand Down Expand Up @@ -51,27 +53,11 @@ public static void closeConnections() throws SQLException {
}

@Test
public void testRunAsGetString() throws SQLException {
public void testArrowJsonCompatibility() throws SQLException {
withFirstRow(
connections.get(queryResultFormat),
selectSql,
(resultSet) -> assertGetStringIsCompatible(resultSet, expectedStructureTypeRepresentation));
}

@Test
public void testRunAsGetObject() throws SQLException {
withFirstRow(
connections.get(queryResultFormat),
selectSql,
(resultSet) -> assertGetObjectIsCompatible(resultSet, expectedStructureTypeRepresentation));
}

@Test
public void testRunAsGetBytes() throws SQLException {
withFirstRow(
connections.get(queryResultFormat),
selectSql,
(resultSet) -> assertGetBytesIsCompatible(resultSet, expectedStructureTypeRepresentation));
(resultSet) -> assertResultSetIsCompatible(resultSet, expectedStructureTypeRepresentation));
}

@Parameterized.Parameters(name = "format={0},sql={1}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,21 @@ protected static Connection initConnection(ResultSetFormatType queryResultFormat
return conn;
}

protected void assertGetStringIsCompatible(ResultSet resultSet, String expected)
throws SQLException {
protected void assertResultSetIsCompatible(ResultSet resultSet, String expected)
throws SQLException {
// Test getString
String result = resultSet.getString(1);
TestUtil.assertEqualsIgnoringWhitespace(expected, result);
}

protected void assertGetObjectIsCompatible(ResultSet resultSet, String expected)
throws SQLException {
String result = resultSet.getObject(1, String.class);
// Test getObject
result = resultSet.getObject(1, String.class);
String resultCasted = (String) resultSet.getObject(1);
TestUtil.assertEqualsIgnoringWhitespace(expected, result);
TestUtil.assertEqualsIgnoringWhitespace(expected, resultCasted);
}

protected void assertGetBytesIsCompatible(ResultSet resultSet, String expected)
throws SQLException {
// Test getBytes
TestUtil.assertEqualsIgnoringWhitespace(
expected, new String(resultSet.getBytes(1), StandardCharsets.UTF_8));
expected, new String(resultSet.getBytes(1), StandardCharsets.UTF_8));
}

protected void withFirstRow(
Expand Down

0 comments on commit 2b9636d

Please sign in to comment.