Skip to content

Commit

Permalink
Merge pull request #991 from /issues/984-sql-action
Browse files Browse the repository at this point in the history
chore: remove automatic sql variable extraction
  • Loading branch information
bbortt authored Oct 6, 2023
2 parents a661992 + 44ba422 commit 82d985f
Show file tree
Hide file tree
Showing 7 changed files with 345 additions and 422 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@

package org.citrusframework.actions;

import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import javax.sql.DataSource;

import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.util.FileUtils;
Expand All @@ -32,6 +25,13 @@
import org.springframework.transaction.support.TransactionTemplate;
import org.springframework.util.StringUtils;

import javax.sql.DataSource;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

/**
* Class executes PLSQL statements either declared inline as PLSQL statements or given by an
* external file resource.
Expand Down Expand Up @@ -103,9 +103,13 @@ public String decorate(String line) {
* @param context
*/
protected void executeStatements(List<String> statements, TestContext context) {
for (String stmt : statements) {
if (getJdbcTemplate() == null) {
throw new CitrusRuntimeException("No JdbcTemplate configured for sql execution!");
}

for (String statement : statements) {
try {
final String toExecute = context.replaceDynamicContentInString(stmt.trim());
final String toExecute = context.replaceDynamicContentInString(statement.trim());

if (logger.isDebugEnabled()) {
logger.debug("Executing PLSQL statement: " + toExecute);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@

package org.citrusframework.actions;

import java.util.List;
import javax.sql.DataSource;

import org.citrusframework.context.TestContext;
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.springframework.transaction.support.TransactionTemplate;

import javax.sql.DataSource;
import java.util.List;

/**
* Test action execute SQL statements. Use this action when executing
* database altering statements like UPDATE, INSERT, ALTER, DELETE. Statements are either
Expand Down Expand Up @@ -80,14 +80,18 @@ public void doExecute(TestContext context) {
* @param context
*/
protected void executeStatements(List<String> statements, TestContext context) {
for (String stmt : statements) {
if (getJdbcTemplate() == null) {
throw new CitrusRuntimeException("No JdbcTemplate configured for sql execution!");
}

for (String statement : statements) {
try {
final String toExecute;

if (stmt.trim().endsWith(";")) {
toExecute = context.replaceDynamicContentInString(stmt.trim().substring(0, stmt.trim().length()-1));
if (statement.trim().endsWith(";")) {
toExecute = context.replaceDynamicContentInString(statement.trim().substring(0, statement.trim().length() - 1));
} else {
toExecute = context.replaceDynamicContentInString(stmt.trim());
toExecute = context.replaceDynamicContentInString(statement.trim());
}

if (logger.isDebugEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,6 @@

package org.citrusframework.actions;

import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import javax.sql.DataSource;

import org.apache.commons.codec.binary.Base64;
import org.citrusframework.CitrusSettings;
import org.citrusframework.context.TestContext;
Expand All @@ -45,6 +34,17 @@
import org.springframework.transaction.support.TransactionTemplate;
import org.springframework.util.CollectionUtils;

import javax.sql.DataSource;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

/**
* Action executes SQL queries and offers result set validation.
*
Expand Down Expand Up @@ -123,12 +123,6 @@ public void doExecute(TestContext context) {

// fill the request test context variables (extract tag)
fillContextVariables(columnValuesMap, context);

// legacy: save all columns as variables TODO: remove in major version upgrade
for (Entry<String, List<String>> column : columnValuesMap.entrySet()) {
List<String> columnValues = column.getValue();
context.setVariable(column.getKey().toUpperCase(), columnValues.get(0) == null ? NULL_VALUE : columnValues.get(0));
}
} catch (DataAccessException e) {
logger.error("Failed to execute SQL statement", e);
throw new CitrusRuntimeException(e);
Expand Down
Loading

0 comments on commit 82d985f

Please sign in to comment.