From de3311cfadeaf050f5f957ecc046879c51442450 Mon Sep 17 00:00:00 2001 From: pesse Date: Fri, 19 Jul 2019 10:38:43 +0200 Subject: [PATCH 01/24] Add some more unit-tests --- .../api/db/DynamicParameterListTest.java | 131 ++++++++++++++---- 1 file changed, 102 insertions(+), 29 deletions(-) diff --git a/src/test/java/org/utplsql/api/db/DynamicParameterListTest.java b/src/test/java/org/utplsql/api/db/DynamicParameterListTest.java index e2bd6b2..f0ec158 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,119 @@ 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 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); + } } } From 7f52a3349570f6978022dbcae0d2bd0f84010778 Mon Sep 17 00:00:00 2001 From: pesse Date: Fri, 19 Jul 2019 17:09:55 +0200 Subject: [PATCH 02/24] completely filled TestRunnerOptions for testing purposes --- .../TestRunnerStatementProviderIT.java | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/utplsql/api/testRunner/TestRunnerStatementProviderIT.java b/src/test/java/org/utplsql/api/testRunner/TestRunnerStatementProviderIT.java index c1b2a08..1f347f3 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,8 +19,25 @@ class TestRunnerStatementProviderIT extends AbstractDatabaseTest { + 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"); + return options; + } + AbstractTestRunnerStatement getTestRunnerStatementForVersion( Version version ) throws SQLException { - return (AbstractTestRunnerStatement)TestRunnerStatementProvider.getCompatibleTestRunnerStatement(version, new TestRunnerOptions(), getConnection()); + return (AbstractTestRunnerStatement)TestRunnerStatementProvider.getCompatibleTestRunnerStatement(version, getCompletelyFilledOptions(), getConnection()); } @Test From 156f2d9cb354a60b7ba2ba02145c6164fe0a734a Mon Sep 17 00:00:00 2001 From: pesse Date: Fri, 19 Jul 2019 17:35:56 +0200 Subject: [PATCH 03/24] Start exploring possibilities for a dynamic TestRunner-Statement --- .../DynamicTestRunnerStatement.java | 35 +++++++++++++++++++ .../DynamicTestRunnerStatementTest.java | 12 +++++++ 2 files changed, 47 insertions(+) create mode 100644 src/main/java/org/utplsql/api/testRunner/DynamicTestRunnerStatement.java create mode 100644 src/test/java/org/utplsql/api/testRunner/DynamicTestRunnerStatementTest.java 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..6ad9c0f --- /dev/null +++ b/src/main/java/org/utplsql/api/testRunner/DynamicTestRunnerStatement.java @@ -0,0 +1,35 @@ +package org.utplsql.api.testRunner; + +import org.utplsql.api.Version; + +import java.sql.CallableStatement; +import java.sql.Connection; +import java.sql.SQLException; + +public class DynamicTestRunnerStatement implements TestRunnerStatement { + + private CallableStatement callableStatement; + private final Connection connection; + private final Version utPlSQlVersion; + + private DynamicTestRunnerStatement( Version utPlSQlVersion, Connection connection ) { + this.utPlSQlVersion = utPlSQlVersion; + this.connection = connection; + } + + @Override + public void execute() throws SQLException { + // Implement + } + + @Override + public void close() throws SQLException { + if (callableStatement != null) { + callableStatement.close(); + } + } + + public static DynamicTestRunnerStatement forVersion(Version version, Connection connection) { + return new DynamicTestRunnerStatement(version, connection); + } +} 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..2290650 --- /dev/null +++ b/src/test/java/org/utplsql/api/testRunner/DynamicTestRunnerStatementTest.java @@ -0,0 +1,12 @@ +package org.utplsql.api.testRunner; + +import org.junit.jupiter.api.Test; +import org.utplsql.api.Version; + +public class DynamicTestRunnerStatementTest { + + @Test + void explore() { + DynamicTestRunnerStatement testRunnerStatement = DynamicTestRunnerStatement.forVersion(Version.V3_1_7, null); + } +} From 166720b2843470ce4402847f8b399337efdb5977 Mon Sep 17 00:00:00 2001 From: pesse Date: Mon, 22 Jul 2019 22:12:53 +0200 Subject: [PATCH 04/24] Make getSql public for better testability --- .../org/utplsql/api/testRunner/AbstractTestRunnerStatement.java | 2 +- .../org/utplsql/api/testRunner/ActualTestRunnerStatement.java | 2 +- .../org/utplsql/api/testRunner/Pre303TestRunnerStatement.java | 2 +- .../org/utplsql/api/testRunner/Pre312TestRunnerStatement.java | 2 +- .../org/utplsql/api/testRunner/Pre317TestRunnerStatement.java | 2 +- .../java/org/utplsql/api/testRunner/TestRunnerStatement.java | 2 ++ .../utplsql/api/testRunner/TestRunnerStatementProviderIT.java | 2 +- 7 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/utplsql/api/testRunner/AbstractTestRunnerStatement.java b/src/main/java/org/utplsql/api/testRunner/AbstractTestRunnerStatement.java index d53863e..3f959c9 100644 --- a/src/main/java/org/utplsql/api/testRunner/AbstractTestRunnerStatement.java +++ b/src/main/java/org/utplsql/api/testRunner/AbstractTestRunnerStatement.java @@ -32,7 +32,7 @@ public AbstractTestRunnerStatement(TestRunnerOptions options, Connection conn) t createStatement(); } - protected abstract String getSql(); + public abstract String getSql(); protected int createStatement() throws SQLException { diff --git a/src/main/java/org/utplsql/api/testRunner/ActualTestRunnerStatement.java b/src/main/java/org/utplsql/api/testRunner/ActualTestRunnerStatement.java index c6a9326..fbdfcfe 100644 --- a/src/main/java/org/utplsql/api/testRunner/ActualTestRunnerStatement.java +++ b/src/main/java/org/utplsql/api/testRunner/ActualTestRunnerStatement.java @@ -19,7 +19,7 @@ public ActualTestRunnerStatement(TestRunnerOptions options, Connection connectio } @Override - protected String getSql() { + public 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); diff --git a/src/main/java/org/utplsql/api/testRunner/Pre303TestRunnerStatement.java b/src/main/java/org/utplsql/api/testRunner/Pre303TestRunnerStatement.java index d2d53cb..81dc5fb 100644 --- a/src/main/java/org/utplsql/api/testRunner/Pre303TestRunnerStatement.java +++ b/src/main/java/org/utplsql/api/testRunner/Pre303TestRunnerStatement.java @@ -18,7 +18,7 @@ public Pre303TestRunnerStatement(TestRunnerOptions options, Connection conn) thr } @Override - protected String getSql() { + public String getSql() { // Workaround because Oracle JDBC doesn't support passing boolean to stored procedures. String colorConsoleStr = Boolean.toString(options.colorConsole); diff --git a/src/main/java/org/utplsql/api/testRunner/Pre312TestRunnerStatement.java b/src/main/java/org/utplsql/api/testRunner/Pre312TestRunnerStatement.java index 129413b..2fa8f91 100644 --- a/src/main/java/org/utplsql/api/testRunner/Pre312TestRunnerStatement.java +++ b/src/main/java/org/utplsql/api/testRunner/Pre312TestRunnerStatement.java @@ -18,7 +18,7 @@ public Pre312TestRunnerStatement(TestRunnerOptions options, Connection connectio } @Override - protected String getSql() { + public 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); diff --git a/src/main/java/org/utplsql/api/testRunner/Pre317TestRunnerStatement.java b/src/main/java/org/utplsql/api/testRunner/Pre317TestRunnerStatement.java index d2eefd7..f465948 100644 --- a/src/main/java/org/utplsql/api/testRunner/Pre317TestRunnerStatement.java +++ b/src/main/java/org/utplsql/api/testRunner/Pre317TestRunnerStatement.java @@ -18,7 +18,7 @@ public Pre317TestRunnerStatement(TestRunnerOptions options, Connection connectio } @Override - protected String getSql() { + public 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); 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/test/java/org/utplsql/api/testRunner/TestRunnerStatementProviderIT.java b/src/test/java/org/utplsql/api/testRunner/TestRunnerStatementProviderIT.java index 1f347f3..663e6a6 100644 --- a/src/test/java/org/utplsql/api/testRunner/TestRunnerStatementProviderIT.java +++ b/src/test/java/org/utplsql/api/testRunner/TestRunnerStatementProviderIT.java @@ -19,7 +19,7 @@ class TestRunnerStatementProviderIT extends AbstractDatabaseTest { - TestRunnerOptions getCompletelyFilledOptions() { + public static TestRunnerOptions getCompletelyFilledOptions() { TestRunnerOptions options = new TestRunnerOptions(); options.pathList.add("path"); options.reporterList.add(ReporterFactory.createEmpty().createReporter(CoreReporters.UT_DOCUMENTATION_REPORTER.name())); From 2ce1e79d304d068c1ace1af03592e9f641e3ae4f Mon Sep 17 00:00:00 2001 From: pesse Date: Mon, 22 Jul 2019 22:13:46 +0200 Subject: [PATCH 05/24] Test against interface --- .../TestRunnerStatementProviderIT.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/test/java/org/utplsql/api/testRunner/TestRunnerStatementProviderIT.java b/src/test/java/org/utplsql/api/testRunner/TestRunnerStatementProviderIT.java index 663e6a6..483536a 100644 --- a/src/test/java/org/utplsql/api/testRunner/TestRunnerStatementProviderIT.java +++ b/src/test/java/org/utplsql/api/testRunner/TestRunnerStatementProviderIT.java @@ -36,13 +36,13 @@ public static TestRunnerOptions getCompletelyFilledOptions() { return options; } - AbstractTestRunnerStatement getTestRunnerStatementForVersion( Version version ) throws SQLException { - return (AbstractTestRunnerStatement)TestRunnerStatementProvider.getCompatibleTestRunnerStatement(version, getCompletelyFilledOptions(), getConnection()); + TestRunnerStatement getTestRunnerStatementForVersion( Version version ) throws SQLException { + return TestRunnerStatementProvider.getCompatibleTestRunnerStatement(version, getCompletelyFilledOptions(), getConnection()); } @Test void testGettingPre303Version() throws SQLException { - AbstractTestRunnerStatement stmt = getTestRunnerStatementForVersion(Version.V3_0_2); + TestRunnerStatement stmt = getTestRunnerStatementForVersion(Version.V3_0_2); assertEquals(Pre303TestRunnerStatement.class, stmt.getClass()); assertThat(stmt.getSql(), not(containsString("a_fail_on_errors"))); assertThat(stmt.getSql(), not(containsString("a_client_character_set"))); @@ -54,7 +54,7 @@ void testGettingPre303Version() throws SQLException { @Test void testGettingPre312Version_from_303() throws SQLException { - AbstractTestRunnerStatement stmt = getTestRunnerStatementForVersion(Version.V3_0_3); + TestRunnerStatement stmt = getTestRunnerStatementForVersion(Version.V3_0_3); assertEquals(Pre312TestRunnerStatement.class, stmt.getClass()); assertThat(stmt.getSql(), containsString("a_fail_on_errors")); assertThat(stmt.getSql(), not(containsString("a_client_character_set"))); @@ -65,7 +65,7 @@ void testGettingPre312Version_from_303() throws SQLException { @Test void testGettingPre312Version_from_311() throws SQLException { - AbstractTestRunnerStatement stmt = getTestRunnerStatementForVersion(Version.V3_1_1); + TestRunnerStatement stmt = getTestRunnerStatementForVersion(Version.V3_1_1); assertThat(stmt, instanceOf(Pre312TestRunnerStatement.class)); assertThat(stmt.getSql(), containsString("a_fail_on_errors")); assertThat(stmt.getSql(), not(containsString("a_client_character_set"))); @@ -76,7 +76,7 @@ void testGettingPre312Version_from_311() throws SQLException { @Test void testGettingPre317Version_from_312() throws SQLException { - AbstractTestRunnerStatement stmt = getTestRunnerStatementForVersion(Version.V3_1_2); + TestRunnerStatement stmt = getTestRunnerStatementForVersion(Version.V3_1_2); assertThat(stmt, instanceOf(Pre317TestRunnerStatement.class)); assertThat(stmt.getSql(), containsString("a_fail_on_errors")); assertThat(stmt.getSql(), containsString("a_client_character_set")); @@ -87,7 +87,7 @@ void testGettingPre317Version_from_312() throws SQLException { @Test void testGettingPre317Version_from_316() throws SQLException { - AbstractTestRunnerStatement stmt = getTestRunnerStatementForVersion(Version.V3_1_6); + TestRunnerStatement stmt = getTestRunnerStatementForVersion(Version.V3_1_6); assertThat(stmt, instanceOf(Pre317TestRunnerStatement.class)); assertThat(stmt.getSql(), containsString("a_fail_on_errors")); assertThat(stmt.getSql(), containsString("a_client_character_set")); @@ -98,7 +98,7 @@ void testGettingPre317Version_from_316() throws SQLException { @Test void testGettingActualVersion_from_latest() throws SQLException { - AbstractTestRunnerStatement stmt = getTestRunnerStatementForVersion(Version.LATEST); + TestRunnerStatement stmt = getTestRunnerStatementForVersion(Version.LATEST); assertThat(stmt, instanceOf(ActualTestRunnerStatement.class)); assertThat(stmt.getSql(), containsString("a_fail_on_errors")); assertThat(stmt.getSql(), containsString("a_client_character_set")); From 6100f3c3f88779f7e537baf7c7d51b271c86cf83 Mon Sep 17 00:00:00 2001 From: pesse Date: Mon, 22 Jul 2019 22:56:47 +0200 Subject: [PATCH 06/24] Slow approach towards new DynamicTestRunner-Statement --- .../DynamicTestRunnerStatement.java | 66 ++++++++++++++++--- .../DynamicTestRunnerStatementTest.java | 28 +++++++- 2 files changed, 84 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/utplsql/api/testRunner/DynamicTestRunnerStatement.java b/src/main/java/org/utplsql/api/testRunner/DynamicTestRunnerStatement.java index 6ad9c0f..29757ec 100644 --- a/src/main/java/org/utplsql/api/testRunner/DynamicTestRunnerStatement.java +++ b/src/main/java/org/utplsql/api/testRunner/DynamicTestRunnerStatement.java @@ -1,6 +1,10 @@ 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.db.DynamicParameterList; import java.sql.CallableStatement; import java.sql.Connection; @@ -8,28 +12,74 @@ public class DynamicTestRunnerStatement implements TestRunnerStatement { - private CallableStatement callableStatement; - private final Connection connection; + private CallableStatement stmt; + private final OracleConnection oracleConnection; private final Version utPlSQlVersion; + private final TestRunnerOptions options; + private final DynamicParameterList dynamicParameterList; - private DynamicTestRunnerStatement( Version utPlSQlVersion, Connection connection ) { + private DynamicTestRunnerStatement( Version utPlSQlVersion, OracleConnection connection, TestRunnerOptions options, CallableStatement statement ) throws SQLException { this.utPlSQlVersion = utPlSQlVersion; - this.connection = connection; + this.oracleConnection = connection; + this.options = options; + this.stmt = statement; + + this.dynamicParameterList = initParameterList(); + + prepareStatement(); + } + + private DynamicParameterList initParameterList() throws SQLException { + /* + "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;"; + */ + return DynamicParameterList.builder() + .addIfNotEmpty("a_paths", options.pathList.toArray(), CustomTypes.UT_VARCHAR2_LIST, oracleConnection) + .build(); + } + + private void prepareStatement() throws SQLException { + if ( stmt == null ) + oracleConnection.prepareCall(dynamicParameterList.getSql()); + + dynamicParameterList.setParamsStartWithIndex(stmt, 1); } @Override public void execute() throws SQLException { + // Implement } + @Override + public String getSql() { + return dynamicParameterList.getSql(); + } + @Override public void close() throws SQLException { - if (callableStatement != null) { - callableStatement.close(); + if (stmt != null) { + stmt.close(); } } - public static DynamicTestRunnerStatement forVersion(Version version, Connection connection) { - return new DynamicTestRunnerStatement(version, connection); + public static DynamicTestRunnerStatement forVersion(Version version, OracleConnection connection, TestRunnerOptions options, CallableStatement statement ) throws SQLException { + return new DynamicTestRunnerStatement(version, connection, options, statement); } } diff --git a/src/test/java/org/utplsql/api/testRunner/DynamicTestRunnerStatementTest.java b/src/test/java/org/utplsql/api/testRunner/DynamicTestRunnerStatementTest.java index 2290650..5e65bb4 100644 --- a/src/test/java/org/utplsql/api/testRunner/DynamicTestRunnerStatementTest.java +++ b/src/test/java/org/utplsql/api/testRunner/DynamicTestRunnerStatementTest.java @@ -1,12 +1,36 @@ package org.utplsql.api.testRunner; +import oracle.jdbc.OracleConnection; import org.junit.jupiter.api.Test; +import org.utplsql.api.CustomTypes; +import org.utplsql.api.TestRunnerOptions; import org.utplsql.api.Version; +import java.sql.CallableStatement; +import java.sql.SQLException; +import java.util.concurrent.Callable; + +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + public class DynamicTestRunnerStatementTest { @Test - void explore() { - DynamicTestRunnerStatement testRunnerStatement = DynamicTestRunnerStatement.forVersion(Version.V3_1_7, null); + void explore() throws SQLException { + + OracleConnection oracleConnection = mock(OracleConnection.class); + CallableStatement callableStatement = mock(CallableStatement.class); + + TestRunnerOptions options = TestRunnerStatementProviderIT.getCompletelyFilledOptions(); + + DynamicTestRunnerStatement testRunnerStatement = DynamicTestRunnerStatement + .forVersion(Version.V3_1_7, oracleConnection, options, callableStatement); + + assertThat(testRunnerStatement.getSql(), containsString("a_paths => ?")); + + verify(callableStatement).setArray(1, null); + verify(oracleConnection).createOracleArray(CustomTypes.UT_VARCHAR2_LIST, options.pathList.toArray()); } } From 4f591ef4214eae5b963991932d4036094382990d Mon Sep 17 00:00:00 2001 From: pesse Date: Mon, 22 Jul 2019 23:05:45 +0200 Subject: [PATCH 07/24] Add failing test for Boolean support of DynamicParameterList --- .../org/utplsql/api/db/DynamicParameterList.java | 12 ++++++++++++ .../utplsql/api/db/DynamicParameterListTest.java | 14 ++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/main/java/org/utplsql/api/db/DynamicParameterList.java b/src/main/java/org/utplsql/api/db/DynamicParameterList.java index 68f88a1..2d9ebb0 100644 --- a/src/main/java/org/utplsql/api/db/DynamicParameterList.java +++ b/src/main/java/org/utplsql/api/db/DynamicParameterList.java @@ -115,6 +115,18 @@ public DynamicParameterListBuilder addIfNotEmpty(String identifier, Object[] val return this; } + public DynamicParameterListBuilder add(String identifier, Boolean value) { + params.put(identifier, null); + return this; + } + + public DynamicParameterListBuilder addIfNotEmpty(String identifier, Boolean value) { + if ( value != null ) { + add(identifier, value); + } + return this; + } + public DynamicParameterList build() { return new DynamicParameterList(params); } diff --git a/src/test/java/org/utplsql/api/db/DynamicParameterListTest.java b/src/test/java/org/utplsql/api/db/DynamicParameterListTest.java index f0ec158..31c3931 100644 --- a/src/test/java/org/utplsql/api/db/DynamicParameterListTest.java +++ b/src/test/java/org/utplsql/api/db/DynamicParameterListTest.java @@ -59,6 +59,20 @@ void can_add_array() throws SQLException { 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_param => (case ? when 1 then true else false)", paramList.getSql()); + + paramList.setParamsStartWithIndex(stmt, 3); + verify(stmt).setInt(3, 1); + } } @Nested From 4aba26534d98484025f3e8c58234b09bd61b6748 Mon Sep 17 00:00:00 2001 From: pesse Date: Mon, 22 Jul 2019 23:06:05 +0200 Subject: [PATCH 08/24] Some more params of TestRunner handeled --- .../DynamicTestRunnerStatement.java | 1 + .../DynamicTestRunnerStatementTest.java | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/main/java/org/utplsql/api/testRunner/DynamicTestRunnerStatement.java b/src/main/java/org/utplsql/api/testRunner/DynamicTestRunnerStatement.java index 29757ec..0f052c3 100644 --- a/src/main/java/org/utplsql/api/testRunner/DynamicTestRunnerStatement.java +++ b/src/main/java/org/utplsql/api/testRunner/DynamicTestRunnerStatement.java @@ -51,6 +51,7 @@ private DynamicParameterList initParameterList() throws SQLException { */ return DynamicParameterList.builder() .addIfNotEmpty("a_paths", options.pathList.toArray(), CustomTypes.UT_VARCHAR2_LIST, oracleConnection) + .addIfNotEmpty("a_reporters", options.reporterList.toArray(), CustomTypes.UT_REPORTERS, oracleConnection) .build(); } diff --git a/src/test/java/org/utplsql/api/testRunner/DynamicTestRunnerStatementTest.java b/src/test/java/org/utplsql/api/testRunner/DynamicTestRunnerStatementTest.java index 5e65bb4..546ca8c 100644 --- a/src/test/java/org/utplsql/api/testRunner/DynamicTestRunnerStatementTest.java +++ b/src/test/java/org/utplsql/api/testRunner/DynamicTestRunnerStatementTest.java @@ -28,8 +28,33 @@ void explore() throws SQLException { DynamicTestRunnerStatement testRunnerStatement = DynamicTestRunnerStatement .forVersion(Version.V3_1_7, oracleConnection, options, callableStatement); + /* + "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;"; + */ 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)")); verify(callableStatement).setArray(1, null); verify(oracleConnection).createOracleArray(CustomTypes.UT_VARCHAR2_LIST, options.pathList.toArray()); } From b3d57796a3dc48d6aaf6f60726ab204a08f825f4 Mon Sep 17 00:00:00 2001 From: pesse Date: Sun, 20 Oct 2019 17:38:06 +0200 Subject: [PATCH 09/24] We can add booleans now Responsibility to build SQL fragment now also lies in the DynamicParameter --- .../utplsql/api/db/DynamicParameterList.java | 32 +++++++++++++++++-- .../api/db/DynamicParameterListTest.java | 2 +- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/utplsql/api/db/DynamicParameterList.java b/src/main/java/org/utplsql/api/db/DynamicParameterList.java index 2d9ebb0..d39defa 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(", ")); } @@ -116,7 +120,7 @@ public DynamicParameterListBuilder addIfNotEmpty(String identifier, Object[] val } public DynamicParameterListBuilder add(String identifier, Boolean value) { - params.put(identifier, null); + params.put(identifier, new DynamicBoolParameter(value)); return this; } @@ -167,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)"; + } + } + private static class DynamicArrayParameter implements DynamicParameter { private final Object[] value; private final String customTypeName; diff --git a/src/test/java/org/utplsql/api/db/DynamicParameterListTest.java b/src/test/java/org/utplsql/api/db/DynamicParameterListTest.java index 31c3931..2aa9523 100644 --- a/src/test/java/org/utplsql/api/db/DynamicParameterListTest.java +++ b/src/test/java/org/utplsql/api/db/DynamicParameterListTest.java @@ -68,7 +68,7 @@ void can_add_boolean() throws SQLException { .add("a_bool", true) .build(); - assertEquals("a_param => (case ? when 1 then true else false)", paramList.getSql()); + assertEquals("a_bool => (case ? when 1 then true else false)", paramList.getSql()); paramList.setParamsStartWithIndex(stmt, 3); verify(stmt).setInt(3, 1); From f2e1e01fd4a3194a82184d704351cf90d675f84e Mon Sep 17 00:00:00 2001 From: pesse Date: Sun, 20 Oct 2019 18:04:56 +0200 Subject: [PATCH 10/24] Two more parameters in the new DynamicStatement --- .../api/testRunner/DynamicTestRunnerStatement.java | 2 ++ .../api/testRunner/DynamicTestRunnerStatementTest.java | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/utplsql/api/testRunner/DynamicTestRunnerStatement.java b/src/main/java/org/utplsql/api/testRunner/DynamicTestRunnerStatement.java index 0f052c3..8272f26 100644 --- a/src/main/java/org/utplsql/api/testRunner/DynamicTestRunnerStatement.java +++ b/src/main/java/org/utplsql/api/testRunner/DynamicTestRunnerStatement.java @@ -52,6 +52,8 @@ private DynamicParameterList initParameterList() throws SQLException { return 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) .build(); } diff --git a/src/test/java/org/utplsql/api/testRunner/DynamicTestRunnerStatementTest.java b/src/test/java/org/utplsql/api/testRunner/DynamicTestRunnerStatementTest.java index 546ca8c..870d848 100644 --- a/src/test/java/org/utplsql/api/testRunner/DynamicTestRunnerStatementTest.java +++ b/src/test/java/org/utplsql/api/testRunner/DynamicTestRunnerStatementTest.java @@ -55,7 +55,12 @@ void explore() throws SQLException { verify(oracleConnection).createOracleArray(CustomTypes.UT_REPORTERS, options.reporterList.toArray()); assertThat(testRunnerStatement.getSql(), containsString("a_color_console => (case ? when 1 then true else false)")); - verify(callableStatement).setArray(1, null); - verify(oracleConnection).createOracleArray(CustomTypes.UT_VARCHAR2_LIST, options.pathList.toArray()); + 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()); + + } } From 5ff0ee29915f9ef1311f5cd751043f0a56c34bc9 Mon Sep 17 00:00:00 2001 From: pesse Date: Sun, 20 Oct 2019 18:21:27 +0200 Subject: [PATCH 11/24] FileMappings are more complicated to pass around Needed some ugly mocking, probably something to refactor in future --- .../utplsql/api/db/DynamicParameterList.java | 3 +- .../DynamicTestRunnerStatement.java | 7 +++++ .../DynamicTestRunnerStatementTest.java | 30 +++++++++++++++++-- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/utplsql/api/db/DynamicParameterList.java b/src/main/java/org/utplsql/api/db/DynamicParameterList.java index d39defa..4896e40 100644 --- a/src/main/java/org/utplsql/api/db/DynamicParameterList.java +++ b/src/main/java/org/utplsql/api/db/DynamicParameterList.java @@ -210,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/DynamicTestRunnerStatement.java b/src/main/java/org/utplsql/api/testRunner/DynamicTestRunnerStatement.java index 8272f26..01397a3 100644 --- a/src/main/java/org/utplsql/api/testRunner/DynamicTestRunnerStatement.java +++ b/src/main/java/org/utplsql/api/testRunner/DynamicTestRunnerStatement.java @@ -2,6 +2,7 @@ import oracle.jdbc.OracleConnection; import org.utplsql.api.CustomTypes; +import org.utplsql.api.FileMapping; import org.utplsql.api.TestRunnerOptions; import org.utplsql.api.Version; import org.utplsql.api.db.DynamicParameterList; @@ -9,6 +10,7 @@ import java.sql.CallableStatement; import java.sql.Connection; import java.sql.SQLException; +import java.util.List; public class DynamicTestRunnerStatement implements TestRunnerStatement { @@ -49,11 +51,16 @@ private DynamicParameterList initParameterList() throws SQLException { "); " + "END;"; */ + + Object[] sourceMappings = (options.sourceMappingOptions!=null) + ?FileMapper.buildFileMappingList(oracleConnection, options.sourceMappingOptions).toArray() + :null; return 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) .build(); } diff --git a/src/test/java/org/utplsql/api/testRunner/DynamicTestRunnerStatementTest.java b/src/test/java/org/utplsql/api/testRunner/DynamicTestRunnerStatementTest.java index 870d848..807ea87 100644 --- a/src/test/java/org/utplsql/api/testRunner/DynamicTestRunnerStatementTest.java +++ b/src/test/java/org/utplsql/api/testRunner/DynamicTestRunnerStatementTest.java @@ -3,26 +3,48 @@ import oracle.jdbc.OracleConnection; import org.junit.jupiter.api.Test; 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 java.util.List; import java.util.concurrent.Callable; import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.MatcherAssert.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.*; public class DynamicTestRunnerStatementTest { @Test void explore() throws SQLException { + // Expectation objects + Object[] expectedSourceFileMapping = new Object[]{new FileMapping("source", "owner", "source", "PACKAGE")}; + Object[] expectedTestFileMapping = new Object[]{new FileMapping("test", "owner", "test", "PACKAGE")}; + // Mock some internals. This is not pretty, but a first step OracleConnection oracleConnection = mock(OracleConnection.class); + when(oracleConnection.unwrap(OracleConnection.class)) + .thenReturn(oracleConnection); CallableStatement callableStatement = mock(CallableStatement.class); + // FileMapper mocks + CallableStatement fileMapperStatement = mock(CallableStatement.class); + when( + oracleConnection.prepareCall(argThat( + a -> a.startsWith("BEGIN ? := ut_file_mapper.build_file_mappings(")) + )) + .thenReturn(fileMapperStatement); + Array fileMapperArray = mock(Array.class); + when(fileMapperStatement.getArray(1)) + .thenReturn(fileMapperArray); + when(fileMapperArray.getArray()) + .thenReturn(expectedSourceFileMapping); + + // Act TestRunnerOptions options = TestRunnerStatementProviderIT.getCompletelyFilledOptions(); DynamicTestRunnerStatement testRunnerStatement = DynamicTestRunnerStatement @@ -61,6 +83,10 @@ void explore() throws SQLException { 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); + verify(oracleConnection).createOracleArray(CustomTypes.UT_FILE_MAPPINGS, expectedSourceFileMapping); + } } From a7b8266a59f3775e47c8353f3317491b7e748e48 Mon Sep 17 00:00:00 2001 From: pesse Date: Mon, 21 Oct 2019 12:33:21 +0200 Subject: [PATCH 12/24] Adding TestFileMappings --- .../api/testRunner/DynamicTestRunnerStatement.java | 4 ++++ .../testRunner/DynamicTestRunnerStatementTest.java | 12 ++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/utplsql/api/testRunner/DynamicTestRunnerStatement.java b/src/main/java/org/utplsql/api/testRunner/DynamicTestRunnerStatement.java index 01397a3..32635cb 100644 --- a/src/main/java/org/utplsql/api/testRunner/DynamicTestRunnerStatement.java +++ b/src/main/java/org/utplsql/api/testRunner/DynamicTestRunnerStatement.java @@ -55,12 +55,16 @@ 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; return 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) .build(); } diff --git a/src/test/java/org/utplsql/api/testRunner/DynamicTestRunnerStatementTest.java b/src/test/java/org/utplsql/api/testRunner/DynamicTestRunnerStatementTest.java index 807ea87..d662188 100644 --- a/src/test/java/org/utplsql/api/testRunner/DynamicTestRunnerStatementTest.java +++ b/src/test/java/org/utplsql/api/testRunner/DynamicTestRunnerStatementTest.java @@ -10,8 +10,6 @@ import java.sql.Array; import java.sql.CallableStatement; import java.sql.SQLException; -import java.util.List; -import java.util.concurrent.Callable; import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.MatcherAssert.assertThat; @@ -22,8 +20,7 @@ public class DynamicTestRunnerStatementTest { @Test void explore() throws SQLException { // Expectation objects - Object[] expectedSourceFileMapping = new Object[]{new FileMapping("source", "owner", "source", "PACKAGE")}; - Object[] expectedTestFileMapping = new Object[]{new FileMapping("test", "owner", "test", "PACKAGE")}; + Object[] expectedFileMapping = new Object[]{new FileMapping("someFile", "owner", "object", "PACKAGE")}; // Mock some internals. This is not pretty, but a first step OracleConnection oracleConnection = mock(OracleConnection.class); @@ -42,7 +39,7 @@ void explore() throws SQLException { when(fileMapperStatement.getArray(1)) .thenReturn(fileMapperArray); when(fileMapperArray.getArray()) - .thenReturn(expectedSourceFileMapping); + .thenReturn(expectedFileMapping); // Act TestRunnerOptions options = TestRunnerStatementProviderIT.getCompletelyFilledOptions(); @@ -85,7 +82,10 @@ void explore() throws SQLException { assertThat(testRunnerStatement.getSql(), containsString("a_source_file_mappings => ?")); verify(callableStatement).setArray(5, null); - verify(oracleConnection).createOracleArray(CustomTypes.UT_FILE_MAPPINGS, expectedSourceFileMapping); + + assertThat(testRunnerStatement.getSql(), containsString("a_test_file_mappings => ?")); + verify(callableStatement).setArray(6, null); + verify(oracleConnection, times(2)).createOracleArray(CustomTypes.UT_FILE_MAPPINGS, expectedFileMapping); } From e1b7dd30b0f2b1f59a22e686c577f4a32d01fac2 Mon Sep 17 00:00:00 2001 From: pesse Date: Mon, 21 Oct 2019 14:57:35 +0200 Subject: [PATCH 13/24] Implement remaining dynamic parameters --- .../DynamicTestRunnerStatement.java | 7 ++++++ .../DynamicTestRunnerStatementTest.java | 23 +++++++++++++++++++ .../TestRunnerStatementProviderIT.java | 1 + 3 files changed, 31 insertions(+) diff --git a/src/main/java/org/utplsql/api/testRunner/DynamicTestRunnerStatement.java b/src/main/java/org/utplsql/api/testRunner/DynamicTestRunnerStatement.java index 32635cb..24ef8e7 100644 --- a/src/main/java/org/utplsql/api/testRunner/DynamicTestRunnerStatement.java +++ b/src/main/java/org/utplsql/api/testRunner/DynamicTestRunnerStatement.java @@ -65,6 +65,13 @@ private DynamicParameterList initParameterList() throws SQLException { .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) + .addIfNotEmpty("a_fail_on_errors", options.failOnErrors) + .addIfNotEmpty("a_client_character_set", options.clientCharacterSet) + .addIfNotEmpty("a_random_test_order", options.randomTestOrder) + .addIfNotEmpty("a_random_test_order_seed", options.randomTestOrderSeed) + .addIfNotEmpty("a_tags", options.getTagsAsString()) .build(); } diff --git a/src/test/java/org/utplsql/api/testRunner/DynamicTestRunnerStatementTest.java b/src/test/java/org/utplsql/api/testRunner/DynamicTestRunnerStatementTest.java index d662188..2f96075 100644 --- a/src/test/java/org/utplsql/api/testRunner/DynamicTestRunnerStatementTest.java +++ b/src/test/java/org/utplsql/api/testRunner/DynamicTestRunnerStatementTest.java @@ -87,6 +87,29 @@ void explore() throws SQLException { 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()); + + assertThat(testRunnerStatement.getSql(), containsString("a_fail_on_errors => (case ? when 1 then true else false)")); + verify(callableStatement).setInt(9, 1); + + assertThat(testRunnerStatement.getSql(), containsString("a_client_character_set => ?")); + verify(callableStatement).setString(10, "UTF8"); + + assertThat(testRunnerStatement.getSql(), containsString("a_random_test_order => (case ? when 1 then true else false)")); + verify(callableStatement).setInt(11, 1); + + assertThat(testRunnerStatement.getSql(), containsString("a_random_test_order_seed => ?")); + verify(callableStatement).setInt(12, 123); + + assertThat(testRunnerStatement.getSql(), containsString("a_tags => ?")); + verify(callableStatement).setString(13, "WIP,long_running"); + } } diff --git a/src/test/java/org/utplsql/api/testRunner/TestRunnerStatementProviderIT.java b/src/test/java/org/utplsql/api/testRunner/TestRunnerStatementProviderIT.java index 483536a..6dfa432 100644 --- a/src/test/java/org/utplsql/api/testRunner/TestRunnerStatementProviderIT.java +++ b/src/test/java/org/utplsql/api/testRunner/TestRunnerStatementProviderIT.java @@ -33,6 +33,7 @@ public static TestRunnerOptions getCompletelyFilledOptions() { options.randomTestOrder = true; options.randomTestOrderSeed = 123; options.tags.add("WIP"); + options.tags.add("long_running"); return options; } From c0ca8cd9fc866fbc71d1bbc942e1cf6cc88539f6 Mon Sep 17 00:00:00 2001 From: pesse Date: Mon, 21 Oct 2019 15:00:02 +0200 Subject: [PATCH 14/24] Remove helper comments --- .../DynamicTestRunnerStatement.java | 20 +----------------- .../DynamicTestRunnerStatementTest.java | 21 +------------------ 2 files changed, 2 insertions(+), 39 deletions(-) diff --git a/src/main/java/org/utplsql/api/testRunner/DynamicTestRunnerStatement.java b/src/main/java/org/utplsql/api/testRunner/DynamicTestRunnerStatement.java index 24ef8e7..1993f9d 100644 --- a/src/main/java/org/utplsql/api/testRunner/DynamicTestRunnerStatement.java +++ b/src/main/java/org/utplsql/api/testRunner/DynamicTestRunnerStatement.java @@ -32,25 +32,6 @@ private DynamicTestRunnerStatement( Version utPlSQlVersion, OracleConnection con } private DynamicParameterList initParameterList() throws SQLException { - /* - "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;"; - */ Object[] sourceMappings = (options.sourceMappingOptions!=null) ?FileMapper.buildFileMappingList(oracleConnection, options.sourceMappingOptions).toArray() @@ -58,6 +39,7 @@ private DynamicParameterList initParameterList() throws SQLException { Object[] testMappings = (options.testMappingOptions!=null) ?FileMapper.buildFileMappingList(oracleConnection, options.testMappingOptions).toArray() :null; + return DynamicParameterList.builder() .addIfNotEmpty("a_paths", options.pathList.toArray(), CustomTypes.UT_VARCHAR2_LIST, oracleConnection) .addIfNotEmpty("a_reporters", options.reporterList.toArray(), CustomTypes.UT_REPORTERS, oracleConnection) diff --git a/src/test/java/org/utplsql/api/testRunner/DynamicTestRunnerStatementTest.java b/src/test/java/org/utplsql/api/testRunner/DynamicTestRunnerStatementTest.java index 2f96075..3c84a41 100644 --- a/src/test/java/org/utplsql/api/testRunner/DynamicTestRunnerStatementTest.java +++ b/src/test/java/org/utplsql/api/testRunner/DynamicTestRunnerStatementTest.java @@ -47,24 +47,7 @@ void explore() throws SQLException { DynamicTestRunnerStatement testRunnerStatement = DynamicTestRunnerStatement .forVersion(Version.V3_1_7, oracleConnection, options, callableStatement); - /* - "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;"; - */ + // Assert all parameters are set appropriately assertThat(testRunnerStatement.getSql(), containsString("a_paths => ?")); verify(callableStatement).setArray(1, null); verify(oracleConnection).createOracleArray(CustomTypes.UT_VARCHAR2_LIST, options.pathList.toArray()); @@ -109,7 +92,5 @@ void explore() throws SQLException { assertThat(testRunnerStatement.getSql(), containsString("a_tags => ?")); verify(callableStatement).setString(13, "WIP,long_running"); - - } } From 4afca5f7ade5a3d37bf165cab800f73c741ee89a Mon Sep 17 00:00:00 2001 From: pesse Date: Mon, 21 Oct 2019 16:09:05 +0200 Subject: [PATCH 15/24] Add version Bugfix-numbers --- src/main/java/org/utplsql/api/Version.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/utplsql/api/Version.java b/src/main/java/org/utplsql/api/Version.java index 3dda076..9b7ca75 100644 --- a/src/main/java/org/utplsql/api/Version.java +++ b/src/main/java/org/utplsql/api/Version.java @@ -24,14 +24,14 @@ 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); 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) .collect(toMap(Version::toString, Function.identity())); From 32b7d568522f30f474d413be4b1abb9ac32b3186 Mon Sep 17 00:00:00 2001 From: pesse Date: Mon, 21 Oct 2019 16:23:05 +0200 Subject: [PATCH 16/24] Version isGreaterThanOrEqual and isLessOrEqual treat NULL in base version as being equal to anything in comparing version --- src/main/java/org/utplsql/api/Version.java | 32 +++++++++++--- .../org/utplsql/api/VersionObjectTest.java | 43 +++++++++++++++++++ 2 files changed, 68 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/utplsql/api/Version.java b/src/main/java/org/utplsql/api/Version.java index 9b7ca75..1e80f03 100644 --- a/src/main/java/org/utplsql/api/Version.java +++ b/src/main/java/org/utplsql/api/Version.java @@ -167,10 +167,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 +184,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 +228,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 +239,7 @@ public boolean isGreaterOrEqualThan(Version v) throws InvalidVersionException { versionsAreValid(v); - return compareTo(v) >= 0; + return compareTo(v, true) >= 0; } @@ -240,11 +249,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/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 From 1b9e0b2fb72558d91156a0753a2c89fc08f52998 Mon Sep 17 00:00:00 2001 From: pesse Date: Mon, 21 Oct 2019 17:22:53 +0200 Subject: [PATCH 17/24] Add tests for all utPLSQL versions --- .../DynamicTestRunnerStatement.java | 30 ++- .../DynamicTestRunnerStatementTest.java | 216 +++++++++++++++--- 2 files changed, 207 insertions(+), 39 deletions(-) diff --git a/src/main/java/org/utplsql/api/testRunner/DynamicTestRunnerStatement.java b/src/main/java/org/utplsql/api/testRunner/DynamicTestRunnerStatement.java index 1993f9d..48a9150 100644 --- a/src/main/java/org/utplsql/api/testRunner/DynamicTestRunnerStatement.java +++ b/src/main/java/org/utplsql/api/testRunner/DynamicTestRunnerStatement.java @@ -2,15 +2,13 @@ import oracle.jdbc.OracleConnection; import org.utplsql.api.CustomTypes; -import org.utplsql.api.FileMapping; 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; -import java.util.List; public class DynamicTestRunnerStatement implements TestRunnerStatement { @@ -40,7 +38,7 @@ private DynamicParameterList initParameterList() throws SQLException { ?FileMapper.buildFileMappingList(oracleConnection, options.testMappingOptions).toArray() :null; - return DynamicParameterList.builder() + 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) @@ -48,13 +46,23 @@ private DynamicParameterList initParameterList() throws SQLException { .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) - .addIfNotEmpty("a_fail_on_errors", options.failOnErrors) - .addIfNotEmpty("a_client_character_set", options.clientCharacterSet) - .addIfNotEmpty("a_random_test_order", options.randomTestOrder) - .addIfNotEmpty("a_random_test_order_seed", options.randomTestOrderSeed) - .addIfNotEmpty("a_tags", options.getTagsAsString()) - .build(); + .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 { diff --git a/src/test/java/org/utplsql/api/testRunner/DynamicTestRunnerStatementTest.java b/src/test/java/org/utplsql/api/testRunner/DynamicTestRunnerStatementTest.java index 3c84a41..7eb985f 100644 --- a/src/test/java/org/utplsql/api/testRunner/DynamicTestRunnerStatementTest.java +++ b/src/test/java/org/utplsql/api/testRunner/DynamicTestRunnerStatementTest.java @@ -1,7 +1,10 @@ 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; @@ -13,41 +16,58 @@ 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 { - @Test - void explore() throws SQLException { - // Expectation objects - Object[] expectedFileMapping = new Object[]{new FileMapping("someFile", "owner", "object", "PACKAGE")}; + private DynamicTestRunnerStatement testRunnerStatement; + private CallableStatement callableStatement; + private OracleConnection oracleConnection; + private TestRunnerOptions options; + private Object[] expectedFileMapping; - // Mock some internals. This is not pretty, but a first step + private OracleConnection getMockedOracleConnection( Object[] expectedFileMapping ) throws SQLException { OracleConnection oracleConnection = mock(OracleConnection.class); when(oracleConnection.unwrap(OracleConnection.class)) .thenReturn(oracleConnection); - CallableStatement callableStatement = mock(CallableStatement.class); + mockFileMapper(oracleConnection, expectedFileMapping); + return oracleConnection; + } - // FileMapper mocks + 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( - oracleConnection.prepareCall(argThat( + mockedOracleConnection.prepareCall(argThat( a -> a.startsWith("BEGIN ? := ut_file_mapper.build_file_mappings(")) )) .thenReturn(fileMapperStatement); - Array fileMapperArray = mock(Array.class); - when(fileMapperStatement.getArray(1)) - .thenReturn(fileMapperArray); - when(fileMapperArray.getArray()) - .thenReturn(expectedFileMapping); + } - // Act - TestRunnerOptions options = TestRunnerStatementProviderIT.getCompletelyFilledOptions(); + private Matcher doesOrDoesNotContainString( String string, boolean shouldBeThere ) { + return (shouldBeThere) + ? containsString(string) + : not(containsString(string)); + } - DynamicTestRunnerStatement testRunnerStatement = DynamicTestRunnerStatement - .forVersion(Version.V3_1_7, oracleConnection, options, callableStatement); + private VerificationMode doesOrDoesNotGetCalled( boolean shouldBeThere ) { + return (shouldBeThere) + ? times(1) + : never(); + } - // Assert all parameters are set appropriately + 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()); @@ -77,20 +97,160 @@ void explore() throws SQLException { 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)", 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)", 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"); + } - assertThat(testRunnerStatement.getSql(), containsString("a_fail_on_errors => (case ? when 1 then true else false)")); - verify(callableStatement).setInt(9, 1); + @BeforeEach + void initParameters() throws SQLException { + expectedFileMapping = new Object[]{new FileMapping("someFile", "owner", "object", "PACKAGE")}; - assertThat(testRunnerStatement.getSql(), containsString("a_client_character_set => ?")); - verify(callableStatement).setString(10, "UTF8"); + // Mock some internals. This is not pretty, but a first step + oracleConnection = getMockedOracleConnection(expectedFileMapping); + callableStatement = mock(CallableStatement.class); - assertThat(testRunnerStatement.getSql(), containsString("a_random_test_order => (case ? when 1 then true else false)")); - verify(callableStatement).setInt(11, 1); + // Act + options = TestRunnerStatementProviderIT.getCompletelyFilledOptions(); + } - assertThat(testRunnerStatement.getSql(), containsString("a_random_test_order_seed => ?")); - verify(callableStatement).setInt(12, 123); + @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); - assertThat(testRunnerStatement.getSql(), containsString("a_tags => ?")); - verify(callableStatement).setString(13, "WIP,long_running"); + checkBaseParameters(); + checkFailOnError(true); + checkClientCharacterSet(true); + checkRandomTestOrder(true); + checkTags(true); } } From 2a3d9df36f3d10d15e09acb932c6b81ef3b73172 Mon Sep 17 00:00:00 2001 From: pesse Date: Mon, 21 Oct 2019 21:22:27 +0200 Subject: [PATCH 18/24] Added "end case" part --- src/main/java/org/utplsql/api/db/DynamicParameterList.java | 2 +- src/test/java/org/utplsql/api/db/DynamicParameterListTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/utplsql/api/db/DynamicParameterList.java b/src/main/java/org/utplsql/api/db/DynamicParameterList.java index 4896e40..ac10159 100644 --- a/src/main/java/org/utplsql/api/db/DynamicParameterList.java +++ b/src/main/java/org/utplsql/api/db/DynamicParameterList.java @@ -189,7 +189,7 @@ public void setParam(CallableStatement statement, int index) throws SQLException @Override public String getSql(String key) { - return key + " => (case ? when 1 then true else false)"; + return key + " => (case ? when 1 then true else false end)"; } } diff --git a/src/test/java/org/utplsql/api/db/DynamicParameterListTest.java b/src/test/java/org/utplsql/api/db/DynamicParameterListTest.java index 2aa9523..e3e9a17 100644 --- a/src/test/java/org/utplsql/api/db/DynamicParameterListTest.java +++ b/src/test/java/org/utplsql/api/db/DynamicParameterListTest.java @@ -68,7 +68,7 @@ void can_add_boolean() throws SQLException { .add("a_bool", true) .build(); - assertEquals("a_bool => (case ? when 1 then true else false)", paramList.getSql()); + assertEquals("a_bool => (case ? when 1 then true else false end)", paramList.getSql()); paramList.setParamsStartWithIndex(stmt, 3); verify(stmt).setInt(3, 1); From 19a9037105fd0edd0342f806353ec9b4b5d8c7e7 Mon Sep 17 00:00:00 2001 From: pesse Date: Mon, 21 Oct 2019 22:19:58 +0200 Subject: [PATCH 19/24] Replace old TestRunnerStatements with the new DynamicTestRunnerStatement --- .../AbstractTestRunnerStatement.java | 101 ------------------ .../testRunner/ActualTestRunnerStatement.java | 67 ------------ .../DynamicTestRunnerStatement.java | 19 ++-- .../testRunner/Pre303TestRunnerStatement.java | 37 ------- .../testRunner/Pre312TestRunnerStatement.java | 40 ------- .../testRunner/Pre317TestRunnerStatement.java | 50 --------- .../TestRunnerStatementProvider.java | 21 +--- .../DynamicTestRunnerStatementTest.java | 6 +- .../TestRunnerStatementProviderIT.java | 6 -- 9 files changed, 17 insertions(+), 330 deletions(-) delete mode 100644 src/main/java/org/utplsql/api/testRunner/AbstractTestRunnerStatement.java delete mode 100644 src/main/java/org/utplsql/api/testRunner/ActualTestRunnerStatement.java delete mode 100644 src/main/java/org/utplsql/api/testRunner/Pre303TestRunnerStatement.java delete mode 100644 src/main/java/org/utplsql/api/testRunner/Pre312TestRunnerStatement.java delete mode 100644 src/main/java/org/utplsql/api/testRunner/Pre317TestRunnerStatement.java 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 3f959c9..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(); - } - - public 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 fbdfcfe..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 - public 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 index 48a9150..aeccc8c 100644 --- a/src/main/java/org/utplsql/api/testRunner/DynamicTestRunnerStatement.java +++ b/src/main/java/org/utplsql/api/testRunner/DynamicTestRunnerStatement.java @@ -8,6 +8,7 @@ import org.utplsql.api.db.DynamicParameterList; import java.sql.CallableStatement; +import java.sql.Connection; import java.sql.SQLException; public class DynamicTestRunnerStatement implements TestRunnerStatement { @@ -66,16 +67,21 @@ private DynamicParameterList initParameterList() throws SQLException { } private void prepareStatement() throws SQLException { - if ( stmt == null ) - oracleConnection.prepareCall(dynamicParameterList.getSql()); + 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 { - - // Implement + stmt.execute(); } @Override @@ -90,7 +96,8 @@ public void close() throws SQLException { } } - public static DynamicTestRunnerStatement forVersion(Version version, OracleConnection connection, TestRunnerOptions options, CallableStatement statement ) throws SQLException { - return new DynamicTestRunnerStatement(version, connection, options, statement); + 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 81dc5fb..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 - public 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 2fa8f91..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 - public 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 f465948..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 - public 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/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/testRunner/DynamicTestRunnerStatementTest.java b/src/test/java/org/utplsql/api/testRunner/DynamicTestRunnerStatementTest.java index 7eb985f..de58620 100644 --- a/src/test/java/org/utplsql/api/testRunner/DynamicTestRunnerStatementTest.java +++ b/src/test/java/org/utplsql/api/testRunner/DynamicTestRunnerStatementTest.java @@ -76,7 +76,7 @@ private void checkBaseParameters() throws SQLException { 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)")); + 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 => ?")); @@ -100,7 +100,7 @@ private void checkBaseParameters() throws SQLException { } private void checkFailOnError( boolean shouldBeThere ) throws SQLException { - assertThat(testRunnerStatement.getSql(), doesOrDoesNotContainString("a_fail_on_errors => (case ? when 1 then true else false)", shouldBeThere)); + assertThat(testRunnerStatement.getSql(), doesOrDoesNotContainString("a_fail_on_errors => (case ? when 1 then true else false end)", shouldBeThere)); verify(callableStatement, doesOrDoesNotGetCalled(shouldBeThere)).setInt(9, 1); } @@ -110,7 +110,7 @@ private void checkClientCharacterSet( boolean shouldBeThere ) throws SQLExceptio } private void checkRandomTestOrder( boolean shouldBeThere ) throws SQLException { - assertThat(testRunnerStatement.getSql(), doesOrDoesNotContainString("a_random_test_order => (case ? when 1 then true else false)", shouldBeThere)); + 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); diff --git a/src/test/java/org/utplsql/api/testRunner/TestRunnerStatementProviderIT.java b/src/test/java/org/utplsql/api/testRunner/TestRunnerStatementProviderIT.java index 6dfa432..bfe9234 100644 --- a/src/test/java/org/utplsql/api/testRunner/TestRunnerStatementProviderIT.java +++ b/src/test/java/org/utplsql/api/testRunner/TestRunnerStatementProviderIT.java @@ -44,7 +44,6 @@ TestRunnerStatement getTestRunnerStatementForVersion( Version version ) throws S @Test void testGettingPre303Version() throws SQLException { TestRunnerStatement stmt = getTestRunnerStatementForVersion(Version.V3_0_2); - assertEquals(Pre303TestRunnerStatement.class, stmt.getClass()); 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"))); @@ -56,7 +55,6 @@ void testGettingPre303Version() throws SQLException { @Test void testGettingPre312Version_from_303() throws SQLException { TestRunnerStatement stmt = getTestRunnerStatementForVersion(Version.V3_0_3); - assertEquals(Pre312TestRunnerStatement.class, stmt.getClass()); 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"))); @@ -67,7 +65,6 @@ void testGettingPre312Version_from_303() throws SQLException { @Test void testGettingPre312Version_from_311() throws SQLException { TestRunnerStatement stmt = getTestRunnerStatementForVersion(Version.V3_1_1); - assertThat(stmt, instanceOf(Pre312TestRunnerStatement.class)); 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"))); @@ -78,7 +75,6 @@ void testGettingPre312Version_from_311() throws SQLException { @Test void testGettingPre317Version_from_312() throws SQLException { TestRunnerStatement stmt = getTestRunnerStatementForVersion(Version.V3_1_2); - assertThat(stmt, instanceOf(Pre317TestRunnerStatement.class)); 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"))); @@ -89,7 +85,6 @@ void testGettingPre317Version_from_312() throws SQLException { @Test void testGettingPre317Version_from_316() throws SQLException { TestRunnerStatement stmt = getTestRunnerStatementForVersion(Version.V3_1_6); - assertThat(stmt, instanceOf(Pre317TestRunnerStatement.class)); 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"))); @@ -100,7 +95,6 @@ void testGettingPre317Version_from_316() throws SQLException { @Test void testGettingActualVersion_from_latest() throws SQLException { TestRunnerStatement stmt = getTestRunnerStatementForVersion(Version.LATEST); - assertThat(stmt, instanceOf(ActualTestRunnerStatement.class)); assertThat(stmt.getSql(), containsString("a_fail_on_errors")); assertThat(stmt.getSql(), containsString("a_client_character_set")); assertThat(stmt.getSql(), containsString("a_random_test_order")); From 1751d68f728171a16c9e07c5df3ec111d6b70a49 Mon Sep 17 00:00:00 2001 From: pesse Date: Mon, 21 Oct 2019 22:40:26 +0200 Subject: [PATCH 20/24] Switch to OpenJDK 8 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 44ad3ea..2eeab3f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ services: - docker jdk: - - oraclejdk8 + - openjdk8 env: global: From 02114aebaa7da63afca901812422f518802f3a40 Mon Sep 17 00:00:00 2001 From: pesse Date: Mon, 21 Oct 2019 23:31:29 +0200 Subject: [PATCH 21/24] Add utPLSQL 3.1.8 version --- .travis.yml | 9 +++++---- src/main/java/org/utplsql/api/Version.java | 5 +++-- .../testRunner/DynamicTestRunnerStatementTest.java | 11 +++++++++++ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2eeab3f..24021f8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,18 +29,19 @@ 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 before_cache: diff --git a/src/main/java/org/utplsql/api/Version.java b/src/main/java/org/utplsql/api/Version.java index 1e80f03..45493b7 100644 --- a/src/main/java/org/utplsql/api/Version.java +++ b/src/main/java/org/utplsql/api/Version.java @@ -32,10 +32,11 @@ public class Version implements Comparable { 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.7", 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; diff --git a/src/test/java/org/utplsql/api/testRunner/DynamicTestRunnerStatementTest.java b/src/test/java/org/utplsql/api/testRunner/DynamicTestRunnerStatementTest.java index de58620..199bdb9 100644 --- a/src/test/java/org/utplsql/api/testRunner/DynamicTestRunnerStatementTest.java +++ b/src/test/java/org/utplsql/api/testRunner/DynamicTestRunnerStatementTest.java @@ -253,4 +253,15 @@ void version_3_1_7_parameters() throws SQLException { 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); + } } From 6a0723a5127672af4984716476b3193a9403bd5c Mon Sep 17 00:00:00 2001 From: pesse Date: Tue, 22 Oct 2019 07:52:39 +0200 Subject: [PATCH 22/24] Fix Version-String --- src/main/java/org/utplsql/api/Version.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/utplsql/api/Version.java b/src/main/java/org/utplsql/api/Version.java index 45493b7..bb336b6 100644 --- a/src/main/java/org/utplsql/api/Version.java +++ b/src/main/java/org/utplsql/api/Version.java @@ -32,7 +32,7 @@ public class Version implements Comparable { 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.7", 3, 1, 8, 3188, 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, V3_1_8) .collect(toMap(Version::toString, Function.identity())); From 6ffa5762e71400b0af7c370a31e26b764f580583 Mon Sep 17 00:00:00 2001 From: pesse Date: Tue, 22 Oct 2019 08:29:39 +0200 Subject: [PATCH 23/24] Test JDK13 also with version 3.1.8 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 12c6068..29d7f41 100644 --- a/.travis.yml +++ b/.travis.yml @@ -43,7 +43,7 @@ matrix: jdk: openjdk11 - env: UTPLSQL_VERSION="v3.1.8" jdk: openjdk12 - - env: UTPLSQL_VERSION="v3.1.7" + - env: UTPLSQL_VERSION="v3.1.8" jdk: openjdk13 before_cache: From 97be74d3ea10fd2717e89866cf7f94e80c9acc9f Mon Sep 17 00:00:00 2001 From: pesse Date: Tue, 22 Oct 2019 08:31:14 +0200 Subject: [PATCH 24/24] We don't need Maven CFG anymore --- .travis/maven_cfg.sh | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 .travis/maven_cfg.sh 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