Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 09eeff4

Browse files
author
Samuel Nitsche
committed
Very simple compatibility implementation
API should now be able to work for Framework-version 3.0.0 - 3.0.3
1 parent 4ec2b90 commit 09eeff4

7 files changed

Lines changed: 103 additions & 34 deletions

File tree

src/main/java/org/utplsql/api/TestRunner.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
package org.utplsql.api;
22

3+
import org.utplsql.api.compatibility.CompatibilityProvider;
34
import org.utplsql.api.exception.DatabaseNotCompatibleException;
45
import org.utplsql.api.exception.SomeTestsFailedException;
56
import org.utplsql.api.reporter.DocumentationReporter;
67
import org.utplsql.api.reporter.Reporter;
7-
import oracle.jdbc.OracleConnection;
88
import org.utplsql.api.testRunner.AbstractTestRunnerStatement;
99
import org.utplsql.api.testRunner.TestRunnerStatement;
1010

11-
import java.sql.CallableStatement;
1211
import java.sql.Connection;
1312
import java.sql.SQLException;
14-
import java.sql.Types;
15-
import java.util.ArrayList;
1613
import java.util.List;
1714

1815
/**
1916
* Created by Vinicius Avellar on 12/04/2017.
17+
*
18+
* @author Vinicius Avellar
19+
* @author pesse
2020
*/
2121
public class TestRunner {
2222

@@ -93,12 +93,12 @@ public void run(Connection conn) throws SomeTestsFailedException, SQLException,
9393
options.reporterList.add(new DocumentationReporter().init(conn));
9494
}
9595

96-
AbstractTestRunnerStatement testRunnerStatement = null;
96+
TestRunnerStatement testRunnerStatement = null;
9797

9898
try {
9999
DBHelper.enableDBMSOutput(conn);
100100

101-
testRunnerStatement = new TestRunnerStatement(options, conn);
101+
testRunnerStatement = CompatibilityProvider.getTestRunnerStatement(options, conn);
102102

103103
testRunnerStatement.execute();
104104
} catch (SQLException e) {

src/main/java/org/utplsql/api/TestRunnerOptions.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
import java.util.ArrayList;
66
import java.util.List;
77

8+
/** Holds the various possible options of TestRunner
9+
*
10+
* @author pesse
11+
*/
812
public class TestRunnerOptions {
913
public List<String> pathList = new ArrayList<>();
1014
public List<Reporter> reporterList = new ArrayList<>();
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package org.utplsql.api.compatibility;
2+
3+
import org.utplsql.api.DBHelper;
4+
import org.utplsql.api.TestRunnerOptions;
5+
import org.utplsql.api.Version;
6+
import org.utplsql.api.testRunner.AbstractTestRunnerStatement;
7+
import org.utplsql.api.testRunner.Pre303TestRunnerStatement;
8+
import org.utplsql.api.testRunner.ActualTestRunnerStatement;
9+
import org.utplsql.api.testRunner.TestRunnerStatement;
10+
11+
import java.sql.Connection;
12+
import java.sql.SQLException;
13+
14+
/** Very simple and basic class to provide different implementations of classes based on Database Framework version
15+
* If compatibility-issues get more intense we might have to introduce some more lose coupling, but for the moment
16+
* this very basic approach should do what we want.
17+
* Putting the compatibility checks to the concrete classes might be worth a refactoring, too
18+
*
19+
* @author pesse
20+
*/
21+
public class CompatibilityProvider {
22+
23+
public static TestRunnerStatement getTestRunnerStatement(TestRunnerOptions options, Connection conn) throws SQLException
24+
{
25+
Version version = DBHelper.getDatabaseFrameworkVersion(conn);
26+
27+
AbstractTestRunnerStatement stmt = null;
28+
29+
if ( version.getMajor() == 3 && version.getMinor() == 0 && version.getBugfix() <= 2 )
30+
stmt = new Pre303TestRunnerStatement(options, conn);
31+
else
32+
stmt = new ActualTestRunnerStatement(options, conn);
33+
34+
return stmt;
35+
}
36+
}

src/main/java/org/utplsql/api/testRunner/AbstractTestRunnerStatement.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010
import java.sql.Types;
1111
import java.util.List;
1212

13-
public abstract class AbstractTestRunnerStatement {
13+
/** Abstract class which creates a callable statement for running tests
14+
* The SQL to be used has to be implemented for there are differences between the Framework-versions
15+
*
16+
* @author pesse
17+
*/
18+
public abstract class AbstractTestRunnerStatement implements TestRunnerStatement {
1419

1520
protected TestRunnerOptions options;
1621
protected Connection conn;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package org.utplsql.api.testRunner;
2+
3+
import org.utplsql.api.TestRunnerOptions;
4+
5+
import java.sql.Connection;
6+
import java.sql.SQLException;
7+
8+
/** Provides the call to run tests for the most actual Framework version.
9+
* Includes fail on error
10+
*
11+
* @author pesse
12+
*/
13+
public class ActualTestRunnerStatement extends AbstractTestRunnerStatement {
14+
15+
public ActualTestRunnerStatement(TestRunnerOptions options, Connection connection ) throws SQLException {
16+
super( options, connection);
17+
}
18+
19+
@Override
20+
protected String getSql() {
21+
// Workaround because Oracle JDBC doesn't support passing boolean to stored procedures.
22+
String colorConsoleStr = Boolean.toString(options.colorConsole);
23+
String failOnErrors = Boolean.toString(options.failOnErrors);
24+
25+
return
26+
"BEGIN " +
27+
"ut_runner.run(" +
28+
"a_paths => ?, " +
29+
"a_reporters => ?, " +
30+
"a_color_console => " + colorConsoleStr + ", " +
31+
"a_coverage_schemes => ?, " +
32+
"a_source_file_mappings => ?, " +
33+
"a_test_file_mappings => ?, " +
34+
"a_include_objects => ?, " +
35+
"a_exclude_objects => ?, " +
36+
"a_fail_on_errors => " + failOnErrors + "); " +
37+
"END;";
38+
}
39+
}

src/main/java/org/utplsql/api/testRunner/Pre303TestRunnerStatement.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
import java.sql.Connection;
66
import java.sql.SQLException;
77

8+
/** TestRunner-Statement for Framework version before 3.0.3
9+
* Does not know about failOnErrors option
10+
*
11+
* @author pesse
12+
*/
813
public class Pre303TestRunnerStatement extends AbstractTestRunnerStatement {
914

1015
public Pre303TestRunnerStatement(TestRunnerOptions options, Connection conn) throws SQLException {
Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,14 @@
11
package org.utplsql.api.testRunner;
22

3-
import org.utplsql.api.TestRunnerOptions;
4-
5-
import java.sql.Connection;
63
import java.sql.SQLException;
74

8-
public class TestRunnerStatement extends AbstractTestRunnerStatement {
9-
10-
public TestRunnerStatement(TestRunnerOptions options, Connection connection ) throws SQLException {
11-
super( options, connection);
12-
}
5+
/** Interface to hide the concrete Statement-implementations of TestRunner
6+
*
7+
* @author pesse
8+
*/
9+
public interface TestRunnerStatement {
1310

14-
@Override
15-
protected String getSql() {
16-
// Workaround because Oracle JDBC doesn't support passing boolean to stored procedures.
17-
String colorConsoleStr = Boolean.toString(options.colorConsole);
18-
String failOnErrors = Boolean.toString(options.failOnErrors);
11+
void execute() throws SQLException;
1912

20-
return
21-
"BEGIN " +
22-
"ut_runner.run(" +
23-
"a_paths => ?, " +
24-
"a_reporters => ?, " +
25-
"a_color_console => " + colorConsoleStr + ", " +
26-
"a_coverage_schemes => ?, " +
27-
"a_source_file_mappings => ?, " +
28-
"a_test_file_mappings => ?, " +
29-
"a_include_objects => ?, " +
30-
"a_exclude_objects => ?, " +
31-
"a_fail_on_errors => " + failOnErrors + "); " +
32-
"END;";
33-
}
13+
void close() throws SQLException;
3414
}

0 commit comments

Comments
 (0)