Skip to content

Commit

Permalink
Add prepared statement query for xml assertions (#34111)
Browse files Browse the repository at this point in the history
  • Loading branch information
FlyingZC authored Dec 20, 2024
1 parent c2e05d9 commit 3a9a490
Showing 1 changed file with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ private void assertExecuteQueryWithXmlExpected(final AssertionTestParameter test
|| "proxy".equals(testParam.getAdapter()) && "empty_storage_units".equalsIgnoreCase(testParam.getScenario())) {
return;
}
if (SQLExecuteType.LITERAL == context.getSqlExecuteType()) {
assertQueryForStatementWithXmlExpected(context);
} else {
assertQueryForPreparedStatementWithXmlExpected(context);
}
}

private void assertQueryForStatementWithXmlExpected(final E2ETestContext context) throws SQLException {
try (
Connection connection = getEnvironmentEngine().getTargetDataSource().getConnection();
Statement statement = connection.createStatement();
Expand All @@ -77,6 +85,19 @@ private void assertExecuteQueryWithXmlExpected(final AssertionTestParameter test
}
}

private void assertQueryForPreparedStatementWithXmlExpected(final E2ETestContext context) throws SQLException {
try (
Connection connection = getEnvironmentEngine().getTargetDataSource().getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(context.getSQL())) {
for (SQLValue each : context.getAssertion().getSQLValues()) {
preparedStatement.setObject(each.getIndex(), each.getValue());
}
try (ResultSet resultSet = preparedStatement.executeQuery()) {
assertResultSet(context, resultSet);
}
}
}

private void assertExecuteQueryWithExpectedDataSource(final AssertionTestParameter testParam, final E2ETestContext context) throws SQLException {
try (
Connection actualConnection = getEnvironmentEngine().getTargetDataSource().getConnection();
Expand Down Expand Up @@ -143,6 +164,14 @@ private void assertExecuteWithXmlExpected(final AssertionTestParameter testParam
if ("jdbc".equals(testParam.getAdapter())) {
return;
}
if (SQLExecuteType.LITERAL == context.getSqlExecuteType()) {
assertExecuteForStatementWithXmlExpected(context);
} else {
assertExecuteForPreparedStatementWithXmlExpected(context);
}
}

private void assertExecuteForStatementWithXmlExpected(final E2ETestContext context) throws SQLException {
try (
Connection connection = getEnvironmentEngine().getTargetDataSource().getConnection();
Statement statement = connection.createStatement()) {
Expand All @@ -152,6 +181,20 @@ private void assertExecuteWithXmlExpected(final AssertionTestParameter testParam
}
}

private void assertExecuteForPreparedStatementWithXmlExpected(final E2ETestContext context) throws SQLException {
try (
Connection connection = getEnvironmentEngine().getTargetDataSource().getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(context.getSQL())) {
for (SQLValue each : context.getAssertion().getSQLValues()) {
preparedStatement.setObject(each.getIndex(), each.getValue());
}
assertTrue(preparedStatement.execute(), "Not a query preparedStatement.");
try (ResultSet resultSet = preparedStatement.getResultSet()) {
assertResultSet(context, resultSet);
}
}
}

private void assertExecuteWithExpectedDataSource(final AssertionTestParameter testParam, final E2ETestContext context) throws SQLException {
try (
Connection actualConnection = getEnvironmentEngine().getTargetDataSource().getConnection();
Expand Down

0 comments on commit 3a9a490

Please sign in to comment.