diff --git a/.travis.yml b/.travis.yml index b218a3d..29d7f41 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,20 +29,21 @@ env: - UTPLSQL_VERSION="v3.1.3" - UTPLSQL_VERSION="v3.1.6" - UTPLSQL_VERSION="v3.1.7" + - UTPLSQL_VERSION="v3.1.8" - UTPLSQL_VERSION="develop" UTPLSQL_FILE="utPLSQL" matrix: include: - - env: UTPLSQL_VERSION="v3.1.7" + - env: UTPLSQL_VERSION="v3.1.8" jdk: openjdk9 - - env: UTPLSQL_VERSION="v3.1.7" + - env: UTPLSQL_VERSION="v3.1.8" jdk: openjdk10 - - env: UTPLSQL_VERSION="v3.1.7" + - env: UTPLSQL_VERSION="v3.1.8" jdk: openjdk11 - - env: UTPLSQL_VERSION="v3.1.7" + - env: UTPLSQL_VERSION="v3.1.8" jdk: openjdk12 - - env: UTPLSQL_VERSION="v3.1.7" + - env: UTPLSQL_VERSION="v3.1.8" jdk: openjdk13 before_cache: diff --git a/.travis/maven_cfg.sh b/.travis/maven_cfg.sh deleted file mode 100644 index ebdf232..0000000 --- a/.travis/maven_cfg.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash -set -ev -cd $(dirname $(readlink -f $0)) - -# Download wagon-http recommended by Oracle. -# On maven latest version this is not needed, but travis doesn't have it. -if [ ! -f $CACHE_DIR/wagon-http-2.8-shaded.jar ]; then - curl -L -O "http://central.maven.org/maven2/org/apache/maven/wagon/wagon-http/2.8/wagon-http-2.8-shaded.jar" - mv wagon-http-2.8-shaded.jar $CACHE_DIR/ - sudo cp $CACHE_DIR/wagon-http-2.8-shaded.jar $MAVEN_HOME/lib/ext/ -else - echo "Using cached wagon-http..." - sudo cp $CACHE_DIR/wagon-http-2.8-shaded.jar $MAVEN_HOME/lib/ext/ -fi diff --git a/src/main/java/org/utplsql/api/Version.java b/src/main/java/org/utplsql/api/Version.java index 3dda076..bb336b6 100644 --- a/src/main/java/org/utplsql/api/Version.java +++ b/src/main/java/org/utplsql/api/Version.java @@ -24,18 +24,19 @@ public class Version implements Comparable { public final static Version V3_0_2 = new Version("3.0.2", 3, 0, 2, null, true); public final static Version V3_0_3 = new Version("3.0.3", 3, 0, 3, null, true); public final static Version V3_0_4 = new Version("3.0.4", 3, 0, 4, null, true); - public final static Version V3_1_0 = new Version("3.1.0", 3, 1, 0, null, true); - public final static Version V3_1_1 = new Version("3.1.1", 3, 1, 1, null, true); - public final static Version V3_1_2 = new Version("3.1.2", 3, 1, 2, null, true); - public final static Version V3_1_3 = new Version("3.1.3", 3, 1, 3, null, true); - public final static Version V3_1_4 = new Version("3.1.4", 3, 1, 4, null, true); - public final static Version V3_1_5 = new Version("3.1.5", 3, 1, 5, null, true); - public final static Version V3_1_6 = new Version("3.1.6", 3, 1, 6, null, true); - public final static Version V3_1_7 = new Version("3.1.7", 3, 1, 7, null, true); + public final static Version V3_1_0 = new Version("3.1.0", 3, 1, 0, 1847, true); + public final static Version V3_1_1 = new Version("3.1.1", 3, 1, 1, 1865, true); + public final static Version V3_1_2 = new Version("3.1.2", 3, 1, 2, 2130, true); + public final static Version V3_1_3 = new Version("3.1.3", 3, 1, 3, 2398, true); + public final static Version V3_1_4 = new Version("3.1.4", 3, 1, 4, 2223, true); + public final static Version V3_1_5 = new Version("3.1.5", 3, 1, 5, 2707, true); + public final static Version V3_1_6 = new Version("3.1.6", 3, 1, 6, 2729, true); + public final static Version V3_1_7 = new Version("3.1.7", 3, 1, 7, 3085, true); + public final static Version V3_1_8 = new Version("3.1.8", 3, 1, 8, 3188, true); private final static Map knownVersions = - Stream.of(V3_0_0, V3_0_1, V3_0_2, V3_0_3, V3_0_4, V3_1_0, V3_1_1, V3_1_2, V3_1_3, V3_1_4, V3_1_5, V3_1_6, V3_1_7) + Stream.of(V3_0_0, V3_0_1, V3_0_2, V3_0_3, V3_0_4, V3_1_0, V3_1_1, V3_1_2, V3_1_3, V3_1_4, V3_1_5, V3_1_6, V3_1_7, V3_1_8) .collect(toMap(Version::toString, Function.identity())); - public final static Version LATEST = V3_1_7; + public final static Version LATEST = V3_1_8; private final String origString; private final Integer major; @@ -167,10 +168,14 @@ public String getNormalizedString() { } private int compareToWithNulls(@Nullable Integer i1, @Nullable Integer i2) { + return compareToWithNulls(i1, i2, false); + } + + private int compareToWithNulls(@Nullable Integer i1, @Nullable Integer i2, boolean nullMeansEqual) { if (i1 == null && i2 == null) { return 0; } else if (i1 == null) { - return -1; + return nullMeansEqual ? 0 : -1; } else if (i2 == null) { return 1; } else { @@ -180,26 +185,30 @@ private int compareToWithNulls(@Nullable Integer i1, @Nullable Integer i2) { @Override public int compareTo(Version o) { + return compareTo(o, false); + } + + public int compareTo(Version o, boolean nullMeansEqual) { int curResult; if (isValid() && o.isValid()) { - curResult = compareToWithNulls(getMajor(), o.getMajor()); + curResult = compareToWithNulls(getMajor(), o.getMajor(), nullMeansEqual); if (curResult != 0) { return curResult; } - curResult = compareToWithNulls(getMinor(), o.getMinor()); + curResult = compareToWithNulls(getMinor(), o.getMinor(), nullMeansEqual); if (curResult != 0) { return curResult; } - curResult = compareToWithNulls(getBugfix(), o.getBugfix()); + curResult = compareToWithNulls(getBugfix(), o.getBugfix(), nullMeansEqual); if (curResult != 0) { return curResult; } - curResult = compareToWithNulls(getBuild(), o.getBuild()); + curResult = compareToWithNulls(getBuild(), o.getBuild(), nullMeansEqual); if (curResult != 0) { return curResult; } @@ -220,6 +229,7 @@ private void versionsAreValid(Version v) throws InvalidVersionException { /** * Compares this version to a given version and returns true if this version is greater or equal than the given one + * If one of the version parts of the base version is null, this level is assumed equal no matter the comparing level's version part * Throws an InvalidVersionException if either this or the given version are invalid * * @param v Version to compare with @@ -230,7 +240,7 @@ public boolean isGreaterOrEqualThan(Version v) throws InvalidVersionException { versionsAreValid(v); - return compareTo(v) >= 0; + return compareTo(v, true) >= 0; } @@ -240,11 +250,20 @@ public boolean isGreaterThan(Version v) throws InvalidVersionException { return compareTo(v) > 0; } + /** + * Compares this version to a given version and returns true if this version is less or equal than the given one + * If one of the version parts of the base version is null, this level is assumed equal no matter the comparing level's version part + * Throws an InvalidVersionException if either this or the given version are invalid + * + * @param v Version to compare with + * @return + * @throws InvalidVersionException + */ public boolean isLessOrEqualThan(Version v) throws InvalidVersionException { versionsAreValid(v); - return compareTo(v) <= 0; + return compareTo(v, true) <= 0; } public boolean isLessThan(Version v) throws InvalidVersionException { diff --git a/src/main/java/org/utplsql/api/db/DynamicParameterList.java b/src/main/java/org/utplsql/api/db/DynamicParameterList.java index 68f88a1..ac10159 100644 --- a/src/main/java/org/utplsql/api/db/DynamicParameterList.java +++ b/src/main/java/org/utplsql/api/db/DynamicParameterList.java @@ -20,6 +20,10 @@ public class DynamicParameterList { interface DynamicParameter { void setParam( CallableStatement statement, int index ) throws SQLException; + + default String getSql( String key ) { + return key + " => ?"; + } } private DynamicParameterList(LinkedHashMap params) { @@ -33,8 +37,8 @@ private DynamicParameterList(LinkedHashMap params) { * @return comma-separated list of parameter identifiers */ public String getSql() { - return params.keySet().stream() - .map(e -> e + " => ?") + return params.entrySet().stream() + .map(e -> e.getValue().getSql(e.getKey())) .collect(Collectors.joining(", ")); } @@ -115,6 +119,18 @@ public DynamicParameterListBuilder addIfNotEmpty(String identifier, Object[] val return this; } + public DynamicParameterListBuilder add(String identifier, Boolean value) { + params.put(identifier, new DynamicBoolParameter(value)); + return this; + } + + public DynamicParameterListBuilder addIfNotEmpty(String identifier, Boolean value) { + if ( value != null ) { + add(identifier, value); + } + return this; + } + public DynamicParameterList build() { return new DynamicParameterList(params); } @@ -155,6 +171,28 @@ public void setParam(CallableStatement statement, int index) throws SQLException } } + private static class DynamicBoolParameter implements DynamicParameter { + private final Boolean value; + + DynamicBoolParameter( Boolean value ) { + this.value = value; + } + + @Override + public void setParam(CallableStatement statement, int index) throws SQLException { + if ( value == null ) { + statement.setNull(index, Types.BOOLEAN); + } else { + statement.setInt(index, (value)?1:0); + } + } + + @Override + public String getSql(String key) { + return key + " => (case ? when 1 then true else false end)"; + } + } + private static class DynamicArrayParameter implements DynamicParameter { private final Object[] value; private final String customTypeName; @@ -172,7 +210,8 @@ public void setParam(CallableStatement statement, int index) throws SQLException statement.setNull(index, Types.ARRAY, customTypeName); } else { statement.setArray( - index, oraConnection.createOracleArray(customTypeName, value) + index, + oraConnection.createOracleArray(customTypeName, value) ); } } diff --git a/src/main/java/org/utplsql/api/testRunner/AbstractTestRunnerStatement.java b/src/main/java/org/utplsql/api/testRunner/AbstractTestRunnerStatement.java deleted file mode 100644 index d53863e..0000000 --- a/src/main/java/org/utplsql/api/testRunner/AbstractTestRunnerStatement.java +++ /dev/null @@ -1,101 +0,0 @@ -package org.utplsql.api.testRunner; - -import oracle.jdbc.OracleConnection; -import org.utplsql.api.CustomTypes; -import org.utplsql.api.FileMapping; -import org.utplsql.api.TestRunnerOptions; - -import java.sql.CallableStatement; -import java.sql.Connection; -import java.sql.SQLException; -import java.sql.Types; -import java.util.List; - -/** - * Abstract class which creates a callable statement for running tests - * The SQL to be used has to be implemented for there are differences between the Framework-versions - * - * @author pesse - */ -abstract class AbstractTestRunnerStatement implements TestRunnerStatement { - - protected final TestRunnerOptions options; - protected final CallableStatement callableStatement; - private final Connection conn; - - public AbstractTestRunnerStatement(TestRunnerOptions options, Connection conn) throws SQLException { - this.options = options; - this.conn = conn; - - callableStatement = conn.prepareCall(getSql()); - - createStatement(); - } - - protected abstract String getSql(); - - protected int createStatement() throws SQLException { - - OracleConnection oraConn = conn.unwrap(OracleConnection.class); - - int paramIdx = 0; - - callableStatement.setArray( - ++paramIdx, oraConn.createOracleArray(CustomTypes.UT_VARCHAR2_LIST, options.pathList.toArray())); - - callableStatement.setArray( - ++paramIdx, oraConn.createOracleArray(CustomTypes.UT_REPORTERS, options.reporterList.toArray())); - - if (options.coverageSchemes.isEmpty()) { - callableStatement.setNull(++paramIdx, Types.ARRAY, CustomTypes.UT_VARCHAR2_LIST); - } else { - callableStatement.setArray( - ++paramIdx, oraConn.createOracleArray(CustomTypes.UT_VARCHAR2_LIST, options.coverageSchemes.toArray())); - } - - if (options.sourceMappingOptions == null) { - callableStatement.setNull(++paramIdx, Types.ARRAY, CustomTypes.UT_FILE_MAPPINGS); - } else { - List sourceMappings = FileMapper.buildFileMappingList(conn, options.sourceMappingOptions); - - callableStatement.setArray( - ++paramIdx, oraConn.createOracleArray(CustomTypes.UT_FILE_MAPPINGS, sourceMappings.toArray())); - } - - if (options.testMappingOptions == null) { - callableStatement.setNull(++paramIdx, Types.ARRAY, CustomTypes.UT_FILE_MAPPINGS); - } else { - List sourceMappings = FileMapper.buildFileMappingList(conn, options.testMappingOptions); - - callableStatement.setArray( - ++paramIdx, oraConn.createOracleArray(CustomTypes.UT_FILE_MAPPINGS, sourceMappings.toArray())); - } - - if (options.includeObjects.isEmpty()) { - callableStatement.setNull(++paramIdx, Types.ARRAY, CustomTypes.UT_VARCHAR2_LIST); - } else { - callableStatement.setArray( - ++paramIdx, oraConn.createOracleArray(CustomTypes.UT_VARCHAR2_LIST, options.includeObjects.toArray())); - } - - if (options.excludeObjects.isEmpty()) { - callableStatement.setNull(++paramIdx, Types.ARRAY, CustomTypes.UT_VARCHAR2_LIST); - } else { - callableStatement.setArray( - ++paramIdx, oraConn.createOracleArray(CustomTypes.UT_VARCHAR2_LIST, options.excludeObjects.toArray())); - } - - return paramIdx; - } - - public void execute() throws SQLException { - callableStatement.execute(); - } - - @Override - public void close() throws SQLException { - if (callableStatement != null) { - callableStatement.close(); - } - } -} diff --git a/src/main/java/org/utplsql/api/testRunner/ActualTestRunnerStatement.java b/src/main/java/org/utplsql/api/testRunner/ActualTestRunnerStatement.java deleted file mode 100644 index c6a9326..0000000 --- a/src/main/java/org/utplsql/api/testRunner/ActualTestRunnerStatement.java +++ /dev/null @@ -1,67 +0,0 @@ -package org.utplsql.api.testRunner; - -import org.utplsql.api.TestRunnerOptions; - -import java.sql.Connection; -import java.sql.SQLException; -import java.sql.Types; - -/** - * Provides the call to run tests for the most actual Framework version. - * Includes fail on error - * - * @author pesse - */ -class ActualTestRunnerStatement extends AbstractTestRunnerStatement { - - public ActualTestRunnerStatement(TestRunnerOptions options, Connection connection) throws SQLException { - super(options, connection); - } - - @Override - protected String getSql() { - // Workaround because Oracle JDBC doesn't support passing boolean to stored procedures. - String colorConsoleStr = Boolean.toString(options.colorConsole); - String failOnErrors = Boolean.toString(options.failOnErrors); - String randomExecutionOrder = Boolean.toString(options.randomTestOrder); - - return - "BEGIN " + - "ut_runner.run(" + - "a_paths => ?, " + - "a_reporters => ?, " + - "a_color_console => " + colorConsoleStr + ", " + - "a_coverage_schemes => ?, " + - "a_source_file_mappings => ?, " + - "a_test_file_mappings => ?, " + - "a_include_objects => ?, " + - "a_exclude_objects => ?, " + - "a_fail_on_errors => " + failOnErrors + ", " + - "a_client_character_set => ?, " + - "a_random_test_order => " + randomExecutionOrder + ", " + - "a_random_test_order_seed => ?, "+ - "a_tags => ?"+ - "); " + - "END;"; - } - - @Override - protected int createStatement() throws SQLException { - int curParamIdx = super.createStatement(); - - callableStatement.setString(++curParamIdx, options.clientCharacterSet); - if ( options.randomTestOrderSeed == null ) { - callableStatement.setNull(++curParamIdx, Types.INTEGER); - } else { - callableStatement.setInt(++curParamIdx, options.randomTestOrderSeed); - } - - if ( options.tags.size() == 0 ) { - callableStatement.setNull(++curParamIdx, Types.VARCHAR); - } else { - callableStatement.setString(++curParamIdx, options.getTagsAsString()); - } - - return curParamIdx; - } -} diff --git a/src/main/java/org/utplsql/api/testRunner/DynamicTestRunnerStatement.java b/src/main/java/org/utplsql/api/testRunner/DynamicTestRunnerStatement.java new file mode 100644 index 0000000..aeccc8c --- /dev/null +++ b/src/main/java/org/utplsql/api/testRunner/DynamicTestRunnerStatement.java @@ -0,0 +1,103 @@ +package org.utplsql.api.testRunner; + +import oracle.jdbc.OracleConnection; +import org.utplsql.api.CustomTypes; +import org.utplsql.api.TestRunnerOptions; +import org.utplsql.api.Version; +import org.utplsql.api.compatibility.OptionalFeatures; +import org.utplsql.api.db.DynamicParameterList; + +import java.sql.CallableStatement; +import java.sql.Connection; +import java.sql.SQLException; + +public class DynamicTestRunnerStatement implements TestRunnerStatement { + + private CallableStatement stmt; + private final OracleConnection oracleConnection; + private final Version utPlSQlVersion; + private final TestRunnerOptions options; + private final DynamicParameterList dynamicParameterList; + + private DynamicTestRunnerStatement( Version utPlSQlVersion, OracleConnection connection, TestRunnerOptions options, CallableStatement statement ) throws SQLException { + this.utPlSQlVersion = utPlSQlVersion; + this.oracleConnection = connection; + this.options = options; + this.stmt = statement; + + this.dynamicParameterList = initParameterList(); + + prepareStatement(); + } + + private DynamicParameterList initParameterList() throws SQLException { + + Object[] sourceMappings = (options.sourceMappingOptions!=null) + ?FileMapper.buildFileMappingList(oracleConnection, options.sourceMappingOptions).toArray() + :null; + Object[] testMappings = (options.testMappingOptions!=null) + ?FileMapper.buildFileMappingList(oracleConnection, options.testMappingOptions).toArray() + :null; + + DynamicParameterList.DynamicParameterListBuilder builder = DynamicParameterList.builder() + .addIfNotEmpty("a_paths", options.pathList.toArray(), CustomTypes.UT_VARCHAR2_LIST, oracleConnection) + .addIfNotEmpty("a_reporters", options.reporterList.toArray(), CustomTypes.UT_REPORTERS, oracleConnection) + .addIfNotEmpty("a_color_console", options.colorConsole) + .addIfNotEmpty("a_coverage_schemes", options.coverageSchemes.toArray(), CustomTypes.UT_VARCHAR2_LIST, oracleConnection) + .addIfNotEmpty("a_source_file_mappings", sourceMappings, CustomTypes.UT_FILE_MAPPINGS, oracleConnection) + .addIfNotEmpty("a_test_file_mappings", testMappings, CustomTypes.UT_FILE_MAPPINGS, oracleConnection) + .addIfNotEmpty("a_include_objects", options.includeObjects.toArray(), CustomTypes.UT_VARCHAR2_LIST, oracleConnection) + .addIfNotEmpty("a_exclude_objects", options.excludeObjects.toArray(), CustomTypes.UT_VARCHAR2_LIST, oracleConnection); + + if (OptionalFeatures.FAIL_ON_ERROR.isAvailableFor(utPlSQlVersion)) { + builder.addIfNotEmpty("a_fail_on_errors", options.failOnErrors); + } + if (OptionalFeatures.CLIENT_CHARACTER_SET.isAvailableFor(utPlSQlVersion)) { + builder.addIfNotEmpty("a_client_character_set", options.clientCharacterSet); + } + if (OptionalFeatures.RANDOM_EXECUTION_ORDER.isAvailableFor(utPlSQlVersion)) { + builder.addIfNotEmpty("a_random_test_order", options.randomTestOrder) + .addIfNotEmpty("a_random_test_order_seed", options.randomTestOrderSeed); + } + if (OptionalFeatures.TAGS.isAvailableFor(utPlSQlVersion)) { + builder.addIfNotEmpty("a_tags", options.getTagsAsString()); + } + + return builder.build(); + } + + private void prepareStatement() throws SQLException { + if ( stmt == null ) { + String sql = "BEGIN " + + "ut_runner.run(" + + dynamicParameterList.getSql() + + ");" + + "END;"; + stmt = oracleConnection.prepareCall(sql); + } + + dynamicParameterList.setParamsStartWithIndex(stmt, 1); + } + + @Override + public void execute() throws SQLException { + stmt.execute(); + } + + @Override + public String getSql() { + return dynamicParameterList.getSql(); + } + + @Override + public void close() throws SQLException { + if (stmt != null) { + stmt.close(); + } + } + + public static DynamicTestRunnerStatement forVersion(Version version, Connection connection, TestRunnerOptions options, CallableStatement statement ) throws SQLException { + OracleConnection oraConn = connection.unwrap(OracleConnection.class); + return new DynamicTestRunnerStatement(version, oraConn, options, statement); + } +} diff --git a/src/main/java/org/utplsql/api/testRunner/Pre303TestRunnerStatement.java b/src/main/java/org/utplsql/api/testRunner/Pre303TestRunnerStatement.java deleted file mode 100644 index d2d53cb..0000000 --- a/src/main/java/org/utplsql/api/testRunner/Pre303TestRunnerStatement.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.utplsql.api.testRunner; - -import org.utplsql.api.TestRunnerOptions; - -import java.sql.Connection; -import java.sql.SQLException; - -/** - * TestRunner-Statement for Framework version before 3.0.3 - * Does not know about failOnErrors option - * - * @author pesse - */ -class Pre303TestRunnerStatement extends AbstractTestRunnerStatement { - - public Pre303TestRunnerStatement(TestRunnerOptions options, Connection conn) throws SQLException { - super(options, conn); - } - - @Override - protected String getSql() { - // Workaround because Oracle JDBC doesn't support passing boolean to stored procedures. - String colorConsoleStr = Boolean.toString(options.colorConsole); - - return "BEGIN " + - "ut_runner.run(" + - "a_paths => ?, " + - "a_reporters => ?, " + - "a_color_console => " + colorConsoleStr + ", " + - "a_coverage_schemes => ?, " + - "a_source_file_mappings => ?, " + - "a_test_file_mappings => ?, " + - "a_include_objects => ?, " + - "a_exclude_objects => ?); " + - "END;"; - } -} diff --git a/src/main/java/org/utplsql/api/testRunner/Pre312TestRunnerStatement.java b/src/main/java/org/utplsql/api/testRunner/Pre312TestRunnerStatement.java deleted file mode 100644 index 129413b..0000000 --- a/src/main/java/org/utplsql/api/testRunner/Pre312TestRunnerStatement.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.utplsql.api.testRunner; - -import org.utplsql.api.TestRunnerOptions; - -import java.sql.Connection; -import java.sql.SQLException; - -/** - * TestRunner-Statement for Framework version before 3.0.3 - * Does not know about client character set - * - * @author pesse - */ -class Pre312TestRunnerStatement extends AbstractTestRunnerStatement { - - public Pre312TestRunnerStatement(TestRunnerOptions options, Connection connection) throws SQLException { - super(options, connection); - } - - @Override - protected String getSql() { - // Workaround because Oracle JDBC doesn't support passing boolean to stored procedures. - String colorConsoleStr = Boolean.toString(options.colorConsole); - String failOnErrors = Boolean.toString(options.failOnErrors); - - return - "BEGIN " + - "ut_runner.run(" + - "a_paths => ?, " + - "a_reporters => ?, " + - "a_color_console => " + colorConsoleStr + ", " + - "a_coverage_schemes => ?, " + - "a_source_file_mappings => ?, " + - "a_test_file_mappings => ?, " + - "a_include_objects => ?, " + - "a_exclude_objects => ?, " + - "a_fail_on_errors => " + failOnErrors + "); " + - "END;"; - } -} diff --git a/src/main/java/org/utplsql/api/testRunner/Pre317TestRunnerStatement.java b/src/main/java/org/utplsql/api/testRunner/Pre317TestRunnerStatement.java deleted file mode 100644 index d2eefd7..0000000 --- a/src/main/java/org/utplsql/api/testRunner/Pre317TestRunnerStatement.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.utplsql.api.testRunner; - -import org.utplsql.api.TestRunnerOptions; - -import java.sql.Connection; -import java.sql.SQLException; - -/** - * Provides the call to run tests for the most actual Framework version. - * Includes fail on error - * - * @author pesse - */ -class Pre317TestRunnerStatement extends AbstractTestRunnerStatement { - - public Pre317TestRunnerStatement(TestRunnerOptions options, Connection connection) throws SQLException { - super(options, connection); - } - - @Override - protected String getSql() { - // Workaround because Oracle JDBC doesn't support passing boolean to stored procedures. - String colorConsoleStr = Boolean.toString(options.colorConsole); - String failOnErrors = Boolean.toString(options.failOnErrors); - - return - "BEGIN " + - "ut_runner.run(" + - "a_paths => ?, " + - "a_reporters => ?, " + - "a_color_console => " + colorConsoleStr + ", " + - "a_coverage_schemes => ?, " + - "a_source_file_mappings => ?, " + - "a_test_file_mappings => ?, " + - "a_include_objects => ?, " + - "a_exclude_objects => ?, " + - "a_fail_on_errors => " + failOnErrors + ", " + - "a_client_character_set => ?); " + - "END;"; - } - - @Override - protected int createStatement() throws SQLException { - int curParamIdx = super.createStatement(); - - callableStatement.setString(++curParamIdx, options.clientCharacterSet); - - return curParamIdx; - } -} diff --git a/src/main/java/org/utplsql/api/testRunner/TestRunnerStatement.java b/src/main/java/org/utplsql/api/testRunner/TestRunnerStatement.java index 9a0bb48..dbc5b71 100644 --- a/src/main/java/org/utplsql/api/testRunner/TestRunnerStatement.java +++ b/src/main/java/org/utplsql/api/testRunner/TestRunnerStatement.java @@ -11,6 +11,8 @@ public interface TestRunnerStatement extends AutoCloseable { void execute() throws SQLException; + String getSql(); + @Override void close() throws SQLException; } diff --git a/src/main/java/org/utplsql/api/testRunner/TestRunnerStatementProvider.java b/src/main/java/org/utplsql/api/testRunner/TestRunnerStatementProvider.java index 65f722c..b7c374d 100644 --- a/src/main/java/org/utplsql/api/testRunner/TestRunnerStatementProvider.java +++ b/src/main/java/org/utplsql/api/testRunner/TestRunnerStatementProvider.java @@ -2,7 +2,6 @@ import org.utplsql.api.TestRunnerOptions; import org.utplsql.api.Version; -import org.utplsql.api.exception.InvalidVersionException; import java.sql.Connection; import java.sql.SQLException; @@ -28,24 +27,6 @@ private TestRunnerStatementProvider() { * @throws SQLException */ public static TestRunnerStatement getCompatibleTestRunnerStatement(Version databaseVersion, TestRunnerOptions options, Connection conn) throws SQLException { - AbstractTestRunnerStatement stmt = null; - - try { - if (databaseVersion.isLessThan(Version.V3_0_3)) { - stmt = new Pre303TestRunnerStatement(options, conn); - } else if (databaseVersion.isLessThan(Version.V3_1_2)) { - stmt = new Pre312TestRunnerStatement(options, conn); - } else if (databaseVersion.isLessThan(Version.V3_1_7)) { - stmt = new Pre317TestRunnerStatement(options, conn); - } - - } catch (InvalidVersionException ignored) { - } - - if (stmt == null) { - stmt = new ActualTestRunnerStatement(options, conn); - } - - return stmt; + return DynamicTestRunnerStatement.forVersion(databaseVersion, conn, options, null); } } diff --git a/src/test/java/org/utplsql/api/VersionObjectTest.java b/src/test/java/org/utplsql/api/VersionObjectTest.java index 22dcd24..46cea83 100644 --- a/src/test/java/org/utplsql/api/VersionObjectTest.java +++ b/src/test/java/org/utplsql/api/VersionObjectTest.java @@ -78,6 +78,29 @@ void versionCompareTo() { assertEquals(0, base.compareTo(Version.create("2.3.4.5"))); } + @Test + void versionCompareToWithBaseNull() { + Version base = Version.create("2.3.4"); + + // Less than + assertEquals(-1, base.compareTo(Version.create("3"))); + assertEquals(-1, base.compareTo(Version.create("3.2"))); + assertEquals(-1, base.compareTo(Version.create("2.4.1"))); + assertEquals(-1, base.compareTo(Version.create("2.3.9.1"))); + assertEquals(-1, base.compareTo(Version.create("2.3.4.1"))); + assertEquals(-1, base.compareTo(Version.create("2.3.4.5"))); + assertEquals(-1, base.compareTo(Version.create("2.3.4.9"))); + + // Greater than + assertEquals(1, base.compareTo(Version.create("1"))); + assertEquals(1, base.compareTo(Version.create("1.6"))); + assertEquals(1, base.compareTo(Version.create("2.2.4"))); + assertEquals(1, base.compareTo(Version.create("2.3.3"))); + + // Equal + assertEquals(0, base.compareTo(Version.create("2.3.4"))); + } + @Test void isGreaterOrEqualThan() throws InvalidVersionException { Version base = Version.create("2.3.4.5"); @@ -98,6 +121,26 @@ void isGreaterOrEqualThan() throws InvalidVersionException { } + @Test + void isGreaterOrEqualThanWithBaseNull() throws InvalidVersionException { + Version base = Version.create("2.3.4"); + + assertTrue(base.isGreaterOrEqualThan(Version.create("1"))); + assertTrue(base.isGreaterOrEqualThan(Version.create("2"))); + assertTrue(base.isGreaterOrEqualThan(Version.create("2.3"))); + assertTrue(base.isGreaterOrEqualThan(Version.create("2.2"))); + assertTrue(base.isGreaterOrEqualThan(Version.create("2.3.4"))); + assertTrue(base.isGreaterOrEqualThan(Version.create("2.3.3"))); + assertTrue(base.isGreaterOrEqualThan(Version.create("2.3.4.5"))); + assertTrue(base.isGreaterOrEqualThan(Version.create("2.3.4.4"))); + assertTrue(base.isGreaterOrEqualThan(Version.create("2.3.4.6"))); + + assertFalse(base.isGreaterOrEqualThan(Version.create("2.3.5"))); + assertFalse(base.isGreaterOrEqualThan(Version.create("2.4"))); + assertFalse(base.isGreaterOrEqualThan(Version.create("3"))); + + } + @Test void isGreaterOrEqualThanFails() { // Given version is invalid diff --git a/src/test/java/org/utplsql/api/db/DynamicParameterListTest.java b/src/test/java/org/utplsql/api/db/DynamicParameterListTest.java index e2bd6b2..e3e9a17 100644 --- a/src/test/java/org/utplsql/api/db/DynamicParameterListTest.java +++ b/src/test/java/org/utplsql/api/db/DynamicParameterListTest.java @@ -1,6 +1,7 @@ package org.utplsql.api.db; import oracle.jdbc.OracleConnection; +import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import java.sql.CallableStatement; @@ -11,47 +12,133 @@ public class DynamicParameterListTest { - @Test - void call_with_three_different_types() throws SQLException { + @Nested + class single_parameters { + @Test + void can_add_string() throws SQLException { + CallableStatement stmt = mock(CallableStatement.class); - CallableStatement mockedStatement = mock(CallableStatement.class); - OracleConnection mockedConn = mock(OracleConnection.class); + DynamicParameterList paramList = DynamicParameterList.builder() + .add("a_param", "MyString") + .build(); - Object[] numArr = new Object[]{1, 2}; + assertEquals("a_param => ?", paramList.getSql()); - DynamicParameterList parameterList = DynamicParameterList.builder() - .add("a_object_owner", "MyOwner") - .add("a_num_param", 123) - .add("a_num_array", numArr, "MY_NUM_ARR", mockedConn) - .build(); + paramList.setParamsStartWithIndex(stmt, 5); + verify(stmt).setString(5, "MyString"); + } - assertEquals("a_object_owner => ?, a_num_param => ?, a_num_array => ?", parameterList.getSql()); + @Test + void can_add_int() throws SQLException { + CallableStatement stmt = mock(CallableStatement.class); - parameterList.setParamsStartWithIndex(mockedStatement, 5); + DynamicParameterList paramList = DynamicParameterList.builder() + .add("a_param", 1234) + .build(); - verify(mockedStatement).setString(5, "MyOwner"); - verify(mockedStatement).setInt(6, 123); - verify(mockedConn).createOracleArray("MY_NUM_ARR", numArr); - verify(mockedStatement).setArray(7, null); + assertEquals("a_param => ?", paramList.getSql()); + + paramList.setParamsStartWithIndex(stmt, 10); + verify(stmt).setInt(10, 1234); + } + + @Test + void can_add_array() throws SQLException { + CallableStatement stmt = mock(CallableStatement.class); + OracleConnection conn = mock(OracleConnection.class); + + Object[] numArr = new Object[]{1, 2}; + + DynamicParameterList paramList = DynamicParameterList.builder() + .add("a_param", numArr, "MY_TYPE", conn) + .build(); + + assertEquals("a_param => ?", paramList.getSql()); + + paramList.setParamsStartWithIndex(stmt, 3); + verify(conn).createOracleArray("MY_TYPE", numArr); + verify(stmt).setArray(3, null); + } + + @Test + void can_add_boolean() throws SQLException { + CallableStatement stmt = mock(CallableStatement.class); + + DynamicParameterList paramList = DynamicParameterList.builder() + .add("a_bool", true) + .build(); + + assertEquals("a_bool => (case ? when 1 then true else false end)", paramList.getSql()); + + paramList.setParamsStartWithIndex(stmt, 3); + verify(stmt).setInt(3, 1); + } } - @Test - void when_not_accept_empty_filter_empty_elements() throws SQLException { + @Nested + class mutliple_parameters { + + @Test + void several_parameters_are_issued_in_the_correct_order() throws SQLException { + CallableStatement mockedStatement = mock(CallableStatement.class); + + DynamicParameterList parameterList = DynamicParameterList.builder() + .add("a_param1", "Param1") + .add("a_param2", "Param2") + .add("a_param3", "Param3") + .build(); + + assertEquals("a_param1 => ?, a_param2 => ?, a_param3 => ?", parameterList.getSql()); + + parameterList.setParamsStartWithIndex(mockedStatement, 10); + + verify(mockedStatement).setString(10, "Param1"); + verify(mockedStatement).setString(11, "Param2"); + verify(mockedStatement).setString(12, "Param3"); + } + + @Test + void call_with_three_different_types() throws SQLException { + + CallableStatement mockedStatement = mock(CallableStatement.class); + OracleConnection mockedConn = mock(OracleConnection.class); + + Object[] numArr = new Object[]{1, 2}; + + DynamicParameterList parameterList = DynamicParameterList.builder() + .add("a_object_owner", "MyOwner") + .add("a_num_param", 123) + .add("a_num_array", numArr, "MY_NUM_ARR", mockedConn) + .build(); + + assertEquals("a_object_owner => ?, a_num_param => ?, a_num_array => ?", parameterList.getSql()); + + parameterList.setParamsStartWithIndex(mockedStatement, 5); + + verify(mockedStatement).setString(5, "MyOwner"); + verify(mockedStatement).setInt(6, 123); + verify(mockedConn).createOracleArray("MY_NUM_ARR", numArr); + verify(mockedStatement).setArray(7, null); + } + + @Test + void when_not_accept_empty_filter_empty_elements() throws SQLException { - CallableStatement mockedStatement = mock(CallableStatement.class); - OracleConnection mockedConn = mock(OracleConnection.class); + CallableStatement mockedStatement = mock(CallableStatement.class); + OracleConnection mockedConn = mock(OracleConnection.class); - DynamicParameterList parameterList = DynamicParameterList.builder() - .addIfNotEmpty("a_object_owner", (String)null) - .addIfNotEmpty("a_num_param", (Integer)null) - .addIfNotEmpty("a_num_array", new Object[]{}, "MY_NUM_ARR", mockedConn) - .build(); + DynamicParameterList parameterList = DynamicParameterList.builder() + .addIfNotEmpty("a_object_owner", (String) null) + .addIfNotEmpty("a_num_param", (Integer) null) + .addIfNotEmpty("a_num_array", new Object[]{}, "MY_NUM_ARR", mockedConn) + .build(); - assertEquals("", parameterList.getSql()); + assertEquals("", parameterList.getSql()); - parameterList.setParamsStartWithIndex(mockedStatement, 2); + parameterList.setParamsStartWithIndex(mockedStatement, 2); - verifyNoMoreInteractions(mockedStatement); - verifyNoMoreInteractions(mockedConn); + verifyNoMoreInteractions(mockedStatement); + verifyNoMoreInteractions(mockedConn); + } } } diff --git a/src/test/java/org/utplsql/api/testRunner/DynamicTestRunnerStatementTest.java b/src/test/java/org/utplsql/api/testRunner/DynamicTestRunnerStatementTest.java new file mode 100644 index 0000000..199bdb9 --- /dev/null +++ b/src/test/java/org/utplsql/api/testRunner/DynamicTestRunnerStatementTest.java @@ -0,0 +1,267 @@ +package org.utplsql.api.testRunner; + +import oracle.jdbc.OracleConnection; +import org.hamcrest.Matcher; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.verification.VerificationMode; +import org.utplsql.api.CustomTypes; +import org.utplsql.api.FileMapping; +import org.utplsql.api.TestRunnerOptions; +import org.utplsql.api.Version; + +import java.sql.Array; +import java.sql.CallableStatement; +import java.sql.SQLException; + +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.not; +import static org.mockito.Mockito.*; + +public class DynamicTestRunnerStatementTest { + + private DynamicTestRunnerStatement testRunnerStatement; + private CallableStatement callableStatement; + private OracleConnection oracleConnection; + private TestRunnerOptions options; + private Object[] expectedFileMapping; + + private OracleConnection getMockedOracleConnection( Object[] expectedFileMapping ) throws SQLException { + OracleConnection oracleConnection = mock(OracleConnection.class); + when(oracleConnection.unwrap(OracleConnection.class)) + .thenReturn(oracleConnection); + mockFileMapper(oracleConnection, expectedFileMapping); + return oracleConnection; + } + + private void mockFileMapper( OracleConnection mockedOracleConnection, Object[] expectedFileMapping ) throws SQLException { + Array fileMapperArray = mock(Array.class); + CallableStatement fileMapperStatement = mock(CallableStatement.class); + + when(fileMapperArray.getArray()) + .thenReturn(expectedFileMapping); + when(fileMapperStatement.getArray(1)) + .thenReturn(fileMapperArray); + when( + mockedOracleConnection.prepareCall(argThat( + a -> a.startsWith("BEGIN ? := ut_file_mapper.build_file_mappings(")) + )) + .thenReturn(fileMapperStatement); + } + + private Matcher doesOrDoesNotContainString( String string, boolean shouldBeThere ) { + return (shouldBeThere) + ? containsString(string) + : not(containsString(string)); + } + + private VerificationMode doesOrDoesNotGetCalled( boolean shouldBeThere ) { + return (shouldBeThere) + ? times(1) + : never(); + } + + private void initTestRunnerStatementForVersion( Version version ) throws SQLException { + testRunnerStatement = DynamicTestRunnerStatement + .forVersion(version, oracleConnection, options, callableStatement); + } + + private void checkBaseParameters() throws SQLException { + assertThat(testRunnerStatement.getSql(), containsString("a_paths => ?")); + verify(callableStatement).setArray(1, null); + verify(oracleConnection).createOracleArray(CustomTypes.UT_VARCHAR2_LIST, options.pathList.toArray()); + + assertThat(testRunnerStatement.getSql(), containsString("a_reporters => ?")); + verify(callableStatement).setArray(2, null); + verify(oracleConnection).createOracleArray(CustomTypes.UT_REPORTERS, options.reporterList.toArray()); + + assertThat(testRunnerStatement.getSql(), containsString("a_color_console => (case ? when 1 then true else false end)")); + verify(callableStatement).setInt(3, 0); + + assertThat(testRunnerStatement.getSql(), containsString("a_coverage_schemes => ?")); + verify(callableStatement).setArray(4, null); + verify(oracleConnection).createOracleArray(CustomTypes.UT_VARCHAR2_LIST, options.coverageSchemes.toArray()); + + assertThat(testRunnerStatement.getSql(), containsString("a_source_file_mappings => ?")); + verify(callableStatement).setArray(5, null); + + assertThat(testRunnerStatement.getSql(), containsString("a_test_file_mappings => ?")); + verify(callableStatement).setArray(6, null); + verify(oracleConnection, times(2)).createOracleArray(CustomTypes.UT_FILE_MAPPINGS, expectedFileMapping); + + assertThat(testRunnerStatement.getSql(), containsString("a_include_objects => ?")); + verify(callableStatement).setArray(7, null); + verify(oracleConnection).createOracleArray(CustomTypes.UT_VARCHAR2_LIST, options.includeObjects.toArray()); + + assertThat(testRunnerStatement.getSql(), containsString("a_exclude_objects => ?")); + verify(callableStatement).setArray(8, null); + verify(oracleConnection).createOracleArray(CustomTypes.UT_VARCHAR2_LIST, options.includeObjects.toArray()); + } + + private void checkFailOnError( boolean shouldBeThere ) throws SQLException { + assertThat(testRunnerStatement.getSql(), doesOrDoesNotContainString("a_fail_on_errors => (case ? when 1 then true else false end)", shouldBeThere)); + verify(callableStatement, doesOrDoesNotGetCalled(shouldBeThere)).setInt(9, 1); + } + + private void checkClientCharacterSet( boolean shouldBeThere ) throws SQLException { + assertThat(testRunnerStatement.getSql(), doesOrDoesNotContainString("a_client_character_set => ?", shouldBeThere)); + verify(callableStatement, doesOrDoesNotGetCalled(shouldBeThere)).setString(10, "UTF8"); + } + + private void checkRandomTestOrder( boolean shouldBeThere ) throws SQLException { + assertThat(testRunnerStatement.getSql(), doesOrDoesNotContainString("a_random_test_order => (case ? when 1 then true else false end)", shouldBeThere)); + verify(callableStatement, doesOrDoesNotGetCalled(shouldBeThere)).setInt(11, 1); + assertThat(testRunnerStatement.getSql(), doesOrDoesNotContainString("a_random_test_order_seed => ?", shouldBeThere)); + verify(callableStatement, doesOrDoesNotGetCalled(shouldBeThere)).setInt(12, 123); + } + + private void checkTags( boolean shouldBeThere ) throws SQLException { + assertThat(testRunnerStatement.getSql(), doesOrDoesNotContainString("a_tags => ?", shouldBeThere)); + verify(callableStatement, doesOrDoesNotGetCalled(shouldBeThere)).setString(13, "WIP,long_running"); + } + + @BeforeEach + void initParameters() throws SQLException { + expectedFileMapping = new Object[]{new FileMapping("someFile", "owner", "object", "PACKAGE")}; + + // Mock some internals. This is not pretty, but a first step + oracleConnection = getMockedOracleConnection(expectedFileMapping); + callableStatement = mock(CallableStatement.class); + + // Act + options = TestRunnerStatementProviderIT.getCompletelyFilledOptions(); + } + + @Test + void version_3_0_2_parameters() throws SQLException { + initTestRunnerStatementForVersion(Version.V3_0_2); + + checkBaseParameters(); + checkFailOnError(false); + checkClientCharacterSet(false); + checkRandomTestOrder(false); + checkTags(false); + } + + @Test + void version_3_0_3_parameters() throws SQLException { + initTestRunnerStatementForVersion(Version.V3_0_3); + + checkBaseParameters(); + checkFailOnError(true); + checkClientCharacterSet(false); + checkRandomTestOrder(false); + checkTags(false); + } + + @Test + void version_3_0_4_parameters() throws SQLException { + initTestRunnerStatementForVersion(Version.V3_0_4); + + checkBaseParameters(); + checkFailOnError(true); + checkClientCharacterSet(false); + checkRandomTestOrder(false); + checkTags(false); + } + + @Test + void version_3_1_0_parameters() throws SQLException { + initTestRunnerStatementForVersion(Version.V3_1_0); + + checkBaseParameters(); + checkFailOnError(true); + checkClientCharacterSet(false); + checkRandomTestOrder(false); + checkTags(false); + } + + @Test + void version_3_1_1_parameters() throws SQLException { + initTestRunnerStatementForVersion(Version.V3_1_1); + + checkBaseParameters(); + checkFailOnError(true); + checkClientCharacterSet(false); + checkRandomTestOrder(false); + checkTags(false); + } + + @Test + void version_3_1_2_parameters() throws SQLException { + initTestRunnerStatementForVersion(Version.V3_1_2); + + checkBaseParameters(); + checkFailOnError(true); + checkClientCharacterSet(true); + checkRandomTestOrder(false); + checkTags(false); + } + + @Test + void version_3_1_3_parameters() throws SQLException { + initTestRunnerStatementForVersion(Version.V3_1_3); + + checkBaseParameters(); + checkFailOnError(true); + checkClientCharacterSet(true); + checkRandomTestOrder(false); + checkTags(false); + } + + @Test + void version_3_1_4_parameters() throws SQLException { + initTestRunnerStatementForVersion(Version.V3_1_4); + + checkBaseParameters(); + checkFailOnError(true); + checkClientCharacterSet(true); + checkRandomTestOrder(false); + checkTags(false); + } + + @Test + void version_3_1_5_parameters() throws SQLException { + initTestRunnerStatementForVersion(Version.V3_1_5); + + checkBaseParameters(); + checkFailOnError(true); + checkClientCharacterSet(true); + checkRandomTestOrder(false); + checkTags(false); + } + + @Test + void version_3_1_6_parameters() throws SQLException { + initTestRunnerStatementForVersion(Version.V3_1_6); + + checkBaseParameters(); + checkFailOnError(true); + checkClientCharacterSet(true); + checkRandomTestOrder(false); + checkTags(false); + } + + @Test + void version_3_1_7_parameters() throws SQLException { + initTestRunnerStatementForVersion(Version.V3_1_7); + + checkBaseParameters(); + checkFailOnError(true); + checkClientCharacterSet(true); + checkRandomTestOrder(true); + checkTags(true); + } + + @Test + void version_3_1_8_parameters() throws SQLException { + initTestRunnerStatementForVersion(Version.V3_1_8); + + checkBaseParameters(); + checkFailOnError(true); + checkClientCharacterSet(true); + checkRandomTestOrder(true); + checkTags(true); + } +} diff --git a/src/test/java/org/utplsql/api/testRunner/TestRunnerStatementProviderIT.java b/src/test/java/org/utplsql/api/testRunner/TestRunnerStatementProviderIT.java index c1b2a08..bfe9234 100644 --- a/src/test/java/org/utplsql/api/testRunner/TestRunnerStatementProviderIT.java +++ b/src/test/java/org/utplsql/api/testRunner/TestRunnerStatementProviderIT.java @@ -2,10 +2,14 @@ import org.junit.jupiter.api.Test; import org.utplsql.api.AbstractDatabaseTest; +import org.utplsql.api.FileMapperOptions; import org.utplsql.api.TestRunnerOptions; import org.utplsql.api.Version; +import org.utplsql.api.reporter.CoreReporters; +import org.utplsql.api.reporter.ReporterFactory; import java.sql.SQLException; +import java.util.Arrays; import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.not; @@ -15,14 +19,31 @@ class TestRunnerStatementProviderIT extends AbstractDatabaseTest { - AbstractTestRunnerStatement getTestRunnerStatementForVersion( Version version ) throws SQLException { - return (AbstractTestRunnerStatement)TestRunnerStatementProvider.getCompatibleTestRunnerStatement(version, new TestRunnerOptions(), getConnection()); + public static TestRunnerOptions getCompletelyFilledOptions() { + TestRunnerOptions options = new TestRunnerOptions(); + options.pathList.add("path"); + options.reporterList.add(ReporterFactory.createEmpty().createReporter(CoreReporters.UT_DOCUMENTATION_REPORTER.name())); + options.coverageSchemes.add("APP"); + options.sourceMappingOptions = new FileMapperOptions(Arrays.asList("sourcePath")); + options.testMappingOptions = new FileMapperOptions(Arrays.asList("testPath")); + options.includeObjects.add("include1"); + options.excludeObjects.add("exclude1"); + options.failOnErrors = true; + options.clientCharacterSet = "UTF8"; + options.randomTestOrder = true; + options.randomTestOrderSeed = 123; + options.tags.add("WIP"); + options.tags.add("long_running"); + return options; + } + + TestRunnerStatement getTestRunnerStatementForVersion( Version version ) throws SQLException { + return TestRunnerStatementProvider.getCompatibleTestRunnerStatement(version, getCompletelyFilledOptions(), getConnection()); } @Test void testGettingPre303Version() throws SQLException { - AbstractTestRunnerStatement stmt = getTestRunnerStatementForVersion(Version.V3_0_2); - assertEquals(Pre303TestRunnerStatement.class, stmt.getClass()); + TestRunnerStatement stmt = getTestRunnerStatementForVersion(Version.V3_0_2); assertThat(stmt.getSql(), not(containsString("a_fail_on_errors"))); assertThat(stmt.getSql(), not(containsString("a_client_character_set"))); assertThat(stmt.getSql(), not(containsString("a_random_test_order"))); @@ -33,8 +54,7 @@ void testGettingPre303Version() throws SQLException { @Test void testGettingPre312Version_from_303() throws SQLException { - AbstractTestRunnerStatement stmt = getTestRunnerStatementForVersion(Version.V3_0_3); - assertEquals(Pre312TestRunnerStatement.class, stmt.getClass()); + TestRunnerStatement stmt = getTestRunnerStatementForVersion(Version.V3_0_3); assertThat(stmt.getSql(), containsString("a_fail_on_errors")); assertThat(stmt.getSql(), not(containsString("a_client_character_set"))); assertThat(stmt.getSql(), not(containsString("a_random_test_order"))); @@ -44,8 +64,7 @@ void testGettingPre312Version_from_303() throws SQLException { @Test void testGettingPre312Version_from_311() throws SQLException { - AbstractTestRunnerStatement stmt = getTestRunnerStatementForVersion(Version.V3_1_1); - assertThat(stmt, instanceOf(Pre312TestRunnerStatement.class)); + TestRunnerStatement stmt = getTestRunnerStatementForVersion(Version.V3_1_1); assertThat(stmt.getSql(), containsString("a_fail_on_errors")); assertThat(stmt.getSql(), not(containsString("a_client_character_set"))); assertThat(stmt.getSql(), not(containsString("a_random_test_order"))); @@ -55,8 +74,7 @@ void testGettingPre312Version_from_311() throws SQLException { @Test void testGettingPre317Version_from_312() throws SQLException { - AbstractTestRunnerStatement stmt = getTestRunnerStatementForVersion(Version.V3_1_2); - assertThat(stmt, instanceOf(Pre317TestRunnerStatement.class)); + TestRunnerStatement stmt = getTestRunnerStatementForVersion(Version.V3_1_2); assertThat(stmt.getSql(), containsString("a_fail_on_errors")); assertThat(stmt.getSql(), containsString("a_client_character_set")); assertThat(stmt.getSql(), not(containsString("a_random_test_order"))); @@ -66,8 +84,7 @@ void testGettingPre317Version_from_312() throws SQLException { @Test void testGettingPre317Version_from_316() throws SQLException { - AbstractTestRunnerStatement stmt = getTestRunnerStatementForVersion(Version.V3_1_6); - assertThat(stmt, instanceOf(Pre317TestRunnerStatement.class)); + TestRunnerStatement stmt = getTestRunnerStatementForVersion(Version.V3_1_6); assertThat(stmt.getSql(), containsString("a_fail_on_errors")); assertThat(stmt.getSql(), containsString("a_client_character_set")); assertThat(stmt.getSql(), not(containsString("a_random_test_order"))); @@ -77,8 +94,7 @@ void testGettingPre317Version_from_316() throws SQLException { @Test void testGettingActualVersion_from_latest() throws SQLException { - AbstractTestRunnerStatement stmt = getTestRunnerStatementForVersion(Version.LATEST); - assertThat(stmt, instanceOf(ActualTestRunnerStatement.class)); + TestRunnerStatement stmt = getTestRunnerStatementForVersion(Version.LATEST); assertThat(stmt.getSql(), containsString("a_fail_on_errors")); assertThat(stmt.getSql(), containsString("a_client_character_set")); assertThat(stmt.getSql(), containsString("a_random_test_order"));