|
1 | 1 | package io.github.utplsql.api;
|
2 | 2 |
|
| 3 | +import io.github.utplsql.api.reporter.DocumentationReporter; |
3 | 4 | import io.github.utplsql.api.reporter.Reporter;
|
4 | 5 | import oracle.jdbc.OracleConnection;
|
5 | 6 |
|
6 |
| -import java.sql.Array; |
7 |
| -import java.sql.CallableStatement; |
8 |
| -import java.sql.Connection; |
9 |
| -import java.sql.SQLException; |
| 7 | +import java.sql.*; |
| 8 | +import java.util.ArrayList; |
10 | 9 | import java.util.List;
|
11 | 10 |
|
12 | 11 | /**
|
13 | 12 | * Created by Vinicius Avellar on 12/04/2017.
|
14 | 13 | */
|
15 | 14 | public class TestRunner {
|
16 | 15 |
|
17 |
| - public TestRunner() {} |
| 16 | + private List<String> pathList = new ArrayList<>(); |
| 17 | + private List<Reporter> reporterList = new ArrayList<>(); |
| 18 | + private List<String> coverageSchemes = new ArrayList<>(); |
| 19 | + private List<String> sourceFiles = new ArrayList<>(); |
| 20 | + private List<String> testFiles = new ArrayList<>(); |
| 21 | + private List<String> includeObjects = new ArrayList<>(); |
| 22 | + private List<String> excludeObjects = new ArrayList<>(); |
18 | 23 |
|
19 |
| - public void run(Connection conn, String path, Reporter reporter) throws SQLException { |
20 |
| - validateReporter(conn, reporter); |
21 |
| - CallableStatement callableStatement = null; |
22 |
| - try { |
23 |
| - callableStatement = conn.prepareCall("BEGIN ut_runner.run(a_path => :path, a_reporter => :reporter); END;"); |
24 |
| - callableStatement.setString(":path", path); |
25 |
| - callableStatement.setObject(":reporter", reporter); |
26 |
| - callableStatement.execute(); |
27 |
| - } finally { |
28 |
| - if (callableStatement != null) |
29 |
| - callableStatement.close(); |
30 |
| - } |
| 24 | + public TestRunner() { |
| 25 | + } |
| 26 | + |
| 27 | + public TestRunner addPath(String path) { |
| 28 | + this.pathList.add(path); |
| 29 | + return this; |
| 30 | + } |
| 31 | + |
| 32 | + public TestRunner addPathList(List<String> paths) { |
| 33 | + this.pathList.addAll(paths); |
| 34 | + return this; |
| 35 | + } |
| 36 | + |
| 37 | + public TestRunner addReporter(Reporter reporter) { |
| 38 | + this.reporterList.add(reporter); |
| 39 | + return this; |
| 40 | + } |
| 41 | + |
| 42 | + public TestRunner addReporterList(List<Reporter> reporterList) { |
| 43 | + this.reporterList.addAll(reporterList); |
| 44 | + return this; |
31 | 45 | }
|
32 | 46 |
|
33 |
| - public void run(Connection conn, List<String> pathList, List<Reporter> reporterList) throws SQLException { |
34 |
| - for (Reporter r : reporterList) |
| 47 | + public TestRunner addCoverageScheme(String coverageScheme) { |
| 48 | + this.coverageSchemes.add(coverageScheme); |
| 49 | + return this; |
| 50 | + } |
| 51 | + |
| 52 | + public TestRunner withSourceFiles(List<String> sourceFiles) { |
| 53 | + this.sourceFiles.addAll(sourceFiles); |
| 54 | + return this; |
| 55 | + } |
| 56 | + |
| 57 | + public TestRunner withTestFiles(List<String> testFiles) { |
| 58 | + this.testFiles.addAll(testFiles); |
| 59 | + return this; |
| 60 | + } |
| 61 | + |
| 62 | + public TestRunner includeObject(String obj) { |
| 63 | + this.includeObjects.add(obj); |
| 64 | + return this; |
| 65 | + } |
| 66 | + |
| 67 | + public TestRunner excludeObject(String obj) { |
| 68 | + this.excludeObjects.add(obj); |
| 69 | + return this; |
| 70 | + } |
| 71 | + |
| 72 | + public void run(Connection conn) throws SQLException { |
| 73 | + for (Reporter r : this.reporterList) |
35 | 74 | validateReporter(conn, r);
|
36 | 75 |
|
| 76 | + if (this.pathList.isEmpty()) { |
| 77 | + this.pathList.add(DBHelper.getCurrentSchema(conn)); |
| 78 | + } |
| 79 | + |
| 80 | + if (this.reporterList.isEmpty()) { |
| 81 | + this.reporterList.add(new DocumentationReporter().init(conn)); |
| 82 | + } |
| 83 | + |
37 | 84 | OracleConnection oraConn = conn.unwrap(OracleConnection.class);
|
38 |
| - Array pathArray = oraConn.createARRAY(CustomTypes.UT_VARCHAR2_LIST, pathList.toArray()); |
39 |
| - Array reporterArray = oraConn.createARRAY(CustomTypes.UT_REPORTERS, reporterList.toArray()); |
| 85 | + Array pathArray = oraConn.createARRAY(CustomTypes.UT_VARCHAR2_LIST, this.pathList.toArray()); |
| 86 | + Array reporterArray = oraConn.createARRAY(CustomTypes.UT_REPORTERS, this.reporterList.toArray()); |
| 87 | + Array coverageSchemes = oraConn.createARRAY(CustomTypes.UT_VARCHAR2_LIST, this.coverageSchemes.toArray()); |
| 88 | + Array sourceFiles = oraConn.createARRAY(CustomTypes.UT_VARCHAR2_LIST, this.sourceFiles.toArray()); |
| 89 | + Array testFiles = oraConn.createARRAY(CustomTypes.UT_VARCHAR2_LIST, this.testFiles.toArray()); |
| 90 | + Array includeObjects = oraConn.createARRAY(CustomTypes.UT_VARCHAR2_LIST, this.includeObjects.toArray()); |
| 91 | + Array excludeObjects = oraConn.createARRAY(CustomTypes.UT_VARCHAR2_LIST, this.excludeObjects.toArray()); |
40 | 92 |
|
41 | 93 | CallableStatement callableStatement = null;
|
42 | 94 | try {
|
43 |
| - callableStatement = conn.prepareCall("BEGIN ut_runner.run(a_paths => ?, a_reporters => ?); END;"); |
| 95 | + callableStatement = conn.prepareCall( |
| 96 | + "BEGIN " + |
| 97 | + "ut_runner.run(" + |
| 98 | + "a_paths => ?, a_reporters => ?, a_coverage_schemes => ?," + |
| 99 | + "a_source_files => ?, a_test_files => ?, " + |
| 100 | + "a_include_objects => ?, a_exclude_objects => ?); " + |
| 101 | + "END;"); |
44 | 102 | callableStatement.setArray(1, pathArray);
|
45 | 103 | callableStatement.setArray(2, reporterArray);
|
| 104 | + callableStatement.setArray(3, coverageSchemes); |
| 105 | + callableStatement.setArray(4, sourceFiles); |
| 106 | + callableStatement.setArray(5, testFiles); |
| 107 | + callableStatement.setArray(6, includeObjects); |
| 108 | + callableStatement.setArray(7, excludeObjects); |
46 | 109 | callableStatement.execute();
|
47 | 110 | } finally {
|
48 | 111 | if (callableStatement != null)
|
|
0 commit comments