Skip to content
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

Refactor AdditionalDMLE2EIT test logic #28473

Merged
merged 1 commit into from
Sep 20, 2023
Merged
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 @@ -51,7 +51,7 @@ void assertExecuteUpdateWithAutoGeneratedKeys(final AssertionTestParameter testP
if (null == testParam.getTestCaseContext()) {
return;
}
if (isPostgreSQLOrOpenGauss(testParam.getDatabaseType().getType())) {
if (isPostgreSQLOrOpenGauss(testParam.getDatabaseType().getType()) || isOracleInsertStatement(testParam.getDatabaseType().getType(), testParam.getTestCaseContext().getTestCase().getSql())) {
return;
}
SingleE2EContainerComposer containerComposer = new SingleE2EContainerComposer(testParam);
Expand All @@ -65,14 +65,19 @@ void assertExecuteUpdateWithAutoGeneratedKeys(final AssertionTestParameter testP
assertDataSet(testParam, containerComposer, actualUpdateCount);
}

// TODO support oracle insert statement return auto generated keys
private boolean isOracleInsertStatement(final String databaseType, final String sql) {
return "Oracle".equals(databaseType) && sql.toUpperCase().startsWith("INSERT");
}

private boolean isPostgreSQLOrOpenGauss(final String databaseType) {
return "PostgreSQL".equals(databaseType) || "openGauss".equals(databaseType);
}

private int executeUpdateForStatementWithAutoGeneratedKeys(final AssertionTestParameter testParam,
final SingleE2EContainerComposer containerComposer, final Connection connection) throws SQLException {
try (Statement statement = connection.createStatement()) {
int result = statement.executeUpdate(String.format(containerComposer.getSQL(), containerComposer.getAssertion().getSQLValues().toArray()), Statement.RETURN_GENERATED_KEYS);
int result = statement.executeUpdate(containerComposer.getSQL(), Statement.RETURN_GENERATED_KEYS);
assertGeneratedKeys(testParam, containerComposer, statement.getGeneratedKeys());
return result;
}
Expand Down Expand Up @@ -112,7 +117,7 @@ void assertExecuteUpdateWithColumnIndexes(final AssertionTestParameter testParam

private int executeUpdateForStatementWithColumnIndexes(final SingleE2EContainerComposer containerComposer, final Connection connection) throws SQLException {
try (Statement statement = connection.createStatement()) {
return statement.executeUpdate(String.format(containerComposer.getSQL(), containerComposer.getAssertion().getSQLValues().toArray()), new int[]{1});
return statement.executeUpdate(containerComposer.getSQL(), new int[]{1});
}
}

Expand Down Expand Up @@ -147,7 +152,7 @@ void assertExecuteUpdateWithColumnNames(final AssertionTestParameter testParam)

private int executeUpdateForStatementWithColumnNames(final SingleE2EContainerComposer containerComposer, final Connection connection) throws SQLException {
try (Statement statement = connection.createStatement()) {
return statement.executeUpdate(String.format(containerComposer.getSQL(), containerComposer.getAssertion().getSQLValues().toArray()));
return statement.executeUpdate(containerComposer.getSQL());
}
}

Expand Down Expand Up @@ -184,7 +189,7 @@ void assertExecuteWithoutAutoGeneratedKeys(final AssertionTestParameter testPara

private int executeForStatementWithoutAutoGeneratedKeys(final SingleE2EContainerComposer containerComposer, final Connection connection) throws SQLException {
try (Statement statement = connection.createStatement()) {
assertFalse(statement.execute(String.format(containerComposer.getSQL(), containerComposer.getAssertion().getSQLValues().toArray()), Statement.NO_GENERATED_KEYS), "Not a DML statement.");
assertFalse(statement.execute(containerComposer.getSQL(), Statement.NO_GENERATED_KEYS), "Not a DML statement.");
return statement.getUpdateCount();
}
}
Expand All @@ -207,7 +212,7 @@ void assertExecuteWithAutoGeneratedKeys(final AssertionTestParameter testParam)
if (null == testParam.getTestCaseContext()) {
return;
}
if (isPostgreSQLOrOpenGauss(testParam.getDatabaseType().getType())) {
if (isPostgreSQLOrOpenGauss(testParam.getDatabaseType().getType()) || isOracleInsertStatement(testParam.getDatabaseType().getType(), testParam.getTestCaseContext().getTestCase().getSql())) {
return;
}
SingleE2EContainerComposer containerComposer = new SingleE2EContainerComposer(testParam);
Expand All @@ -224,8 +229,7 @@ void assertExecuteWithAutoGeneratedKeys(final AssertionTestParameter testParam)
private int executeForStatementWithAutoGeneratedKeys(final AssertionTestParameter testParam,
final SingleE2EContainerComposer containerComposer, final Connection connection) throws SQLException {
try (Statement statement = connection.createStatement()) {
assertFalse(statement.execute(
String.format(containerComposer.getSQL(), containerComposer.getAssertion().getSQLValues().toArray()), Statement.RETURN_GENERATED_KEYS), "Not a DML statement.");
assertFalse(statement.execute(containerComposer.getSQL(), Statement.RETURN_GENERATED_KEYS), "Not a DML statement.");
assertGeneratedKeys(testParam, containerComposer, statement.getGeneratedKeys());
return statement.getUpdateCount();
}
Expand Down Expand Up @@ -265,7 +269,7 @@ void assertExecuteWithColumnIndexes(final AssertionTestParameter testParam) thro

private int executeForStatementWithColumnIndexes(final SingleE2EContainerComposer containerComposer, final Connection connection) throws SQLException {
try (Statement statement = connection.createStatement()) {
assertFalse(statement.execute(String.format(containerComposer.getSQL(), containerComposer.getAssertion().getSQLValues().toArray()), new int[]{1}), "Not a DML statement.");
assertFalse(statement.execute(containerComposer.getSQL(), new int[]{1}), "Not a DML statement.");
return statement.getUpdateCount();
}
}
Expand Down Expand Up @@ -302,7 +306,7 @@ void assertExecuteWithColumnNames(final AssertionTestParameter testParam) throws

private int executeForStatementWithColumnNames(final SingleE2EContainerComposer containerComposer, final Connection connection) throws SQLException {
try (Statement statement = connection.createStatement()) {
assertFalse(statement.execute(String.format(containerComposer.getSQL(), containerComposer.getAssertion().getSQLValues().toArray()), new String[]{"TODO"}), "Not a DML statement.");
assertFalse(statement.execute(containerComposer.getSQL(), new String[]{"TODO"}), "Not a DML statement.");
return statement.getUpdateCount();
}
}
Expand Down