Skip to content

Commit 4ec2b90

Browse files
author
Samuel Nitsche
committed
Started with compatibility support
had to restructure current code a bit to support different implementations of TestRunner calls
1 parent f0d6916 commit 4ec2b90

File tree

5 files changed

+199
-95
lines changed

5 files changed

+199
-95
lines changed

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

Lines changed: 24 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import org.utplsql.api.reporter.DocumentationReporter;
66
import org.utplsql.api.reporter.Reporter;
77
import oracle.jdbc.OracleConnection;
8+
import org.utplsql.api.testRunner.AbstractTestRunnerStatement;
9+
import org.utplsql.api.testRunner.TestRunnerStatement;
810

911
import java.sql.CallableStatement;
1012
import java.sql.Connection;
@@ -18,70 +20,60 @@
1820
*/
1921
public class TestRunner {
2022

21-
private List<String> pathList = new ArrayList<>();
22-
private List<Reporter> reporterList = new ArrayList<>();
23-
private boolean colorConsole = false;
24-
private List<String> coverageSchemes = new ArrayList<>();
25-
private List<String> sourceFiles = new ArrayList<>();
26-
private List<String> testFiles = new ArrayList<>();
27-
private List<String> includeObjects = new ArrayList<>();
28-
private List<String> excludeObjects = new ArrayList<>();
29-
private FileMapperOptions sourceMappingOptions;
30-
private FileMapperOptions testMappingOptions;
31-
private boolean failOnErrors = false;
23+
private TestRunnerOptions options = new TestRunnerOptions();
3224

3325
public TestRunner addPath(String path) {
34-
this.pathList.add(path);
26+
options.pathList.add(path);
3527
return this;
3628
}
3729

3830
public TestRunner addPathList(List<String> paths) {
39-
if (pathList != null) this.pathList.addAll(paths);
31+
if (options.pathList != null) options.pathList.addAll(paths);
4032
return this;
4133
}
4234

4335
public TestRunner addReporter(Reporter reporter) {
44-
this.reporterList.add(reporter);
36+
options.reporterList.add(reporter);
4537
return this;
4638
}
4739

4840
public TestRunner colorConsole(boolean colorConsole) {
49-
this.colorConsole = colorConsole;
41+
options.colorConsole = colorConsole;
5042
return this;
5143
}
5244

5345
public TestRunner addReporterList(List<Reporter> reporterList) {
54-
if (reporterList != null) this.reporterList.addAll(reporterList);
46+
if (options.reporterList != null) options.reporterList.addAll(reporterList);
5547
return this;
5648
}
5749

5850
public TestRunner addCoverageScheme(String coverageScheme) {
59-
this.coverageSchemes.add(coverageScheme);
51+
options.coverageSchemes.add(coverageScheme);
6052
return this;
6153
}
6254

6355
public TestRunner includeObject(String obj) {
64-
this.includeObjects.add(obj);
56+
options.includeObjects.add(obj);
6557
return this;
6658
}
6759

6860
public TestRunner excludeObject(String obj) {
69-
this.excludeObjects.add(obj);
61+
options.excludeObjects.add(obj);
7062
return this;
7163
}
7264

7365
public TestRunner sourceMappingOptions(FileMapperOptions mapperOptions) {
74-
this.sourceMappingOptions = mapperOptions;
66+
options.sourceMappingOptions = mapperOptions;
7567
return this;
7668
}
7769

7870
public TestRunner testMappingOptions(FileMapperOptions mapperOptions) {
79-
this.testMappingOptions = mapperOptions;
71+
options.testMappingOptions = mapperOptions;
8072
return this;
8173
}
8274

8375
public TestRunner failOnErrors(boolean failOnErrors) {
84-
this.failOnErrors = failOnErrors;
76+
options.failOnErrors = failOnErrors;
8577
return this;
8678
}
8779

@@ -90,97 +82,34 @@ public void run(Connection conn) throws SomeTestsFailedException, SQLException,
9082
// First of all check version compatibility
9183
DBHelper.failOnVersionCompatibilityCheckFailed(conn);
9284

93-
for (Reporter r : this.reporterList)
85+
for (Reporter r : options.reporterList)
9486
validateReporter(conn, r);
9587

96-
if (this.pathList.isEmpty()) {
97-
this.pathList.add(DBHelper.getCurrentSchema(conn));
88+
if (options.pathList.isEmpty()) {
89+
options.pathList.add(DBHelper.getCurrentSchema(conn));
9890
}
9991

100-
if (this.reporterList.isEmpty()) {
101-
this.reporterList.add(new DocumentationReporter().init(conn));
92+
if (options.reporterList.isEmpty()) {
93+
options.reporterList.add(new DocumentationReporter().init(conn));
10294
}
10395

104-
// Workaround because Oracle JDBC doesn't support passing boolean to stored procedures.
105-
String colorConsoleStr = Boolean.toString(this.colorConsole);
106-
String failOnErrors = Boolean.toString(this.failOnErrors);
96+
AbstractTestRunnerStatement testRunnerStatement = null;
10797

108-
OracleConnection oraConn = conn.unwrap(OracleConnection.class);
109-
CallableStatement callableStatement = null;
11098
try {
11199
DBHelper.enableDBMSOutput(conn);
112100

113-
callableStatement = conn.prepareCall(
114-
"BEGIN " +
115-
"ut_runner.run(" +
116-
"a_paths => ?, " +
117-
"a_reporters => ?, " +
118-
"a_color_console => " + colorConsoleStr + ", " +
119-
"a_coverage_schemes => ?, " +
120-
"a_source_file_mappings => ?, " +
121-
"a_test_file_mappings => ?, " +
122-
"a_include_objects => ?, " +
123-
"a_exclude_objects => ?, " +
124-
"a_fail_on_errors => " + failOnErrors + "); " +
125-
"END;");
126-
127-
int paramIdx = 0;
128-
129-
callableStatement.setArray(
130-
++paramIdx, oraConn.createOracleArray(CustomTypes.UT_VARCHAR2_LIST, this.pathList.toArray()));
131-
132-
callableStatement.setArray(
133-
++paramIdx, oraConn.createOracleArray(CustomTypes.UT_REPORTERS, this.reporterList.toArray()));
134-
135-
if (this.coverageSchemes.isEmpty()) {
136-
callableStatement.setNull(++paramIdx, Types.ARRAY, CustomTypes.UT_VARCHAR2_LIST);
137-
} else {
138-
callableStatement.setArray(
139-
++paramIdx, oraConn.createOracleArray(CustomTypes.UT_VARCHAR2_LIST, this.coverageSchemes.toArray()));
140-
}
141-
142-
if (this.sourceMappingOptions == null) {
143-
callableStatement.setNull(++paramIdx, Types.ARRAY, CustomTypes.UT_FILE_MAPPINGS);
144-
} else {
145-
List<FileMapping> sourceMappings = FileMapper.buildFileMappingList(conn, this.sourceMappingOptions);
146-
147-
callableStatement.setArray(
148-
++paramIdx, oraConn.createOracleArray(CustomTypes.UT_FILE_MAPPINGS, sourceMappings.toArray()));
149-
}
150-
151-
if (this.testMappingOptions == null) {
152-
callableStatement.setNull(++paramIdx, Types.ARRAY, CustomTypes.UT_FILE_MAPPINGS);
153-
} else {
154-
List<FileMapping> sourceMappings = FileMapper.buildFileMappingList(conn, this.testMappingOptions);
155-
156-
callableStatement.setArray(
157-
++paramIdx, oraConn.createOracleArray(CustomTypes.UT_FILE_MAPPINGS, sourceMappings.toArray()));
158-
}
159-
160-
if (this.includeObjects.isEmpty()) {
161-
callableStatement.setNull(++paramIdx, Types.ARRAY, CustomTypes.UT_VARCHAR2_LIST);
162-
} else {
163-
callableStatement.setArray(
164-
++paramIdx, oraConn.createOracleArray(CustomTypes.UT_VARCHAR2_LIST, this.includeObjects.toArray()));
165-
}
166-
167-
if (this.excludeObjects.isEmpty()) {
168-
callableStatement.setNull(++paramIdx, Types.ARRAY, CustomTypes.UT_VARCHAR2_LIST);
169-
} else {
170-
callableStatement.setArray(
171-
++paramIdx, oraConn.createOracleArray(CustomTypes.UT_VARCHAR2_LIST, this.excludeObjects.toArray()));
172-
}
101+
testRunnerStatement = new TestRunnerStatement(options, conn);
173102

174-
callableStatement.execute();
103+
testRunnerStatement.execute();
175104
} catch (SQLException e) {
176105
if (e.getErrorCode() == SomeTestsFailedException.ERROR_CODE) {
177106
throw new SomeTestsFailedException(e.getMessage(), e);
178107
} else {
179108
throw e;
180109
}
181110
} finally {
182-
if (callableStatement != null) {
183-
callableStatement.close();
111+
if (testRunnerStatement != null) {
112+
testRunnerStatement.close();
184113
}
185114

186115
DBHelper.disableDBMSOutput(conn);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package org.utplsql.api;
2+
3+
import org.utplsql.api.reporter.Reporter;
4+
5+
import java.util.ArrayList;
6+
import java.util.List;
7+
8+
public class TestRunnerOptions {
9+
public List<String> pathList = new ArrayList<>();
10+
public List<Reporter> reporterList = new ArrayList<>();
11+
public boolean colorConsole = false;
12+
public List<String> coverageSchemes = new ArrayList<>();
13+
public List<String> sourceFiles = new ArrayList<>();
14+
public List<String> testFiles = new ArrayList<>();
15+
public List<String> includeObjects = new ArrayList<>();
16+
public List<String> excludeObjects = new ArrayList<>();
17+
public FileMapperOptions sourceMappingOptions;
18+
public FileMapperOptions testMappingOptions;
19+
public boolean failOnErrors = false;
20+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package org.utplsql.api.testRunner;
2+
3+
import oracle.jdbc.OracleConnection;
4+
import org.utplsql.api.*;
5+
import org.utplsql.api.exception.SomeTestsFailedException;
6+
7+
import java.sql.CallableStatement;
8+
import java.sql.Connection;
9+
import java.sql.SQLException;
10+
import java.sql.Types;
11+
import java.util.List;
12+
13+
public abstract class AbstractTestRunnerStatement {
14+
15+
protected TestRunnerOptions options;
16+
protected Connection conn;
17+
protected CallableStatement callableStatement;
18+
19+
public AbstractTestRunnerStatement(TestRunnerOptions options, Connection conn) throws SQLException {
20+
this.options = options;
21+
this.conn = conn;
22+
23+
createStatement();
24+
}
25+
26+
protected abstract String getSql();
27+
28+
protected void createStatement() throws SQLException {
29+
30+
OracleConnection oraConn = conn.unwrap(OracleConnection.class);
31+
32+
callableStatement = conn.prepareCall(getSql());
33+
34+
int paramIdx = 0;
35+
36+
callableStatement.setArray(
37+
++paramIdx, oraConn.createOracleArray(CustomTypes.UT_VARCHAR2_LIST, options.pathList.toArray()));
38+
39+
callableStatement.setArray(
40+
++paramIdx, oraConn.createOracleArray(CustomTypes.UT_REPORTERS, options.reporterList.toArray()));
41+
42+
if (options.coverageSchemes.isEmpty()) {
43+
callableStatement.setNull(++paramIdx, Types.ARRAY, CustomTypes.UT_VARCHAR2_LIST);
44+
} else {
45+
callableStatement.setArray(
46+
++paramIdx, oraConn.createOracleArray(CustomTypes.UT_VARCHAR2_LIST, options.coverageSchemes.toArray()));
47+
}
48+
49+
if (options.sourceMappingOptions == null) {
50+
callableStatement.setNull(++paramIdx, Types.ARRAY, CustomTypes.UT_FILE_MAPPINGS);
51+
} else {
52+
List<FileMapping> sourceMappings = FileMapper.buildFileMappingList(conn, options.sourceMappingOptions);
53+
54+
callableStatement.setArray(
55+
++paramIdx, oraConn.createOracleArray(CustomTypes.UT_FILE_MAPPINGS, sourceMappings.toArray()));
56+
}
57+
58+
if (options.testMappingOptions == null) {
59+
callableStatement.setNull(++paramIdx, Types.ARRAY, CustomTypes.UT_FILE_MAPPINGS);
60+
} else {
61+
List<FileMapping> sourceMappings = FileMapper.buildFileMappingList(conn, options.testMappingOptions);
62+
63+
callableStatement.setArray(
64+
++paramIdx, oraConn.createOracleArray(CustomTypes.UT_FILE_MAPPINGS, sourceMappings.toArray()));
65+
}
66+
67+
if (options.includeObjects.isEmpty()) {
68+
callableStatement.setNull(++paramIdx, Types.ARRAY, CustomTypes.UT_VARCHAR2_LIST);
69+
} else {
70+
callableStatement.setArray(
71+
++paramIdx, oraConn.createOracleArray(CustomTypes.UT_VARCHAR2_LIST, options.includeObjects.toArray()));
72+
}
73+
74+
if (options.excludeObjects.isEmpty()) {
75+
callableStatement.setNull(++paramIdx, Types.ARRAY, CustomTypes.UT_VARCHAR2_LIST);
76+
} else {
77+
callableStatement.setArray(
78+
++paramIdx, oraConn.createOracleArray(CustomTypes.UT_VARCHAR2_LIST, options.excludeObjects.toArray()));
79+
}
80+
}
81+
82+
public void execute() throws SQLException {
83+
callableStatement.execute();
84+
}
85+
86+
public void close() throws SQLException {
87+
if (callableStatement != null)
88+
callableStatement.close();
89+
}
90+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
public class Pre303TestRunnerStatement extends AbstractTestRunnerStatement {
9+
10+
public Pre303TestRunnerStatement(TestRunnerOptions options, Connection conn) throws SQLException {
11+
super(options, conn);
12+
}
13+
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+
19+
return "BEGIN " +
20+
"ut_runner.run(" +
21+
"a_paths => ?, " +
22+
"a_reporters => ?, " +
23+
"a_color_console => " + colorConsoleStr + ", " +
24+
"a_coverage_schemes => ?, " +
25+
"a_source_files => ?, " +
26+
"a_test_files => ?, " +
27+
"a_include_objects => ?, " +
28+
"a_exclude_objects => ?); " +
29+
"END;";
30+
}
31+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
public class TestRunnerStatement extends AbstractTestRunnerStatement {
9+
10+
public TestRunnerStatement(TestRunnerOptions options, Connection connection ) throws SQLException {
11+
super( options, connection);
12+
}
13+
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);
19+
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+
}
34+
}

0 commit comments

Comments
 (0)