|
1 | 1 | packageio.github.utplsql.api;
|
2 | 2 |
|
| 3 | +importio.github.utplsql.api.reporter.DocumentationReporter; |
3 | 4 | importio.github.utplsql.api.reporter.Reporter;
|
4 | 5 | importoracle.jdbc.OracleConnection;
|
5 | 6 |
|
6 |
| -importjava.sql.Array; |
7 |
| -importjava.sql.CallableStatement; |
8 |
| -importjava.sql.Connection; |
9 |
| -importjava.sql.SQLException; |
| 7 | +importjava.sql.*; |
| 8 | +importjava.util.ArrayList; |
10 | 9 | importjava.util.List;
|
11 | 10 |
|
12 | 11 | /**
|
13 | 12 | * Created by Vinicius Avellar on 12/04/2017.
|
14 | 13 | */
|
15 | 14 | publicclassTestRunner {
|
16 | 15 |
|
17 |
| -publicTestRunner() {} |
| 16 | +privateList<String>pathList =newArrayList<>(); |
| 17 | +privateList<Reporter>reporterList =newArrayList<>(); |
| 18 | +privateList<String>coverageSchemes =newArrayList<>(); |
| 19 | +privateList<String>sourceFiles =newArrayList<>(); |
| 20 | +privateList<String>testFiles =newArrayList<>(); |
| 21 | +privateList<String>includeObjects =newArrayList<>(); |
| 22 | +privateList<String>excludeObjects =newArrayList<>(); |
18 | 23 |
|
19 |
| -publicvoidrun(Connectionconn,Stringpath,Reporterreporter)throwsSQLException { |
20 |
| -validateReporter(conn,reporter); |
21 |
| -CallableStatementcallableStatement =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 | +publicTestRunner() { |
| 25 | + } |
| 26 | + |
| 27 | +publicTestRunneraddPath(Stringpath) { |
| 28 | +this.pathList.add(path); |
| 29 | +returnthis; |
| 30 | + } |
| 31 | + |
| 32 | +publicTestRunneraddPathList(List<String>paths) { |
| 33 | +this.pathList.addAll(paths); |
| 34 | +returnthis; |
| 35 | + } |
| 36 | + |
| 37 | +publicTestRunneraddReporter(Reporterreporter) { |
| 38 | +this.reporterList.add(reporter); |
| 39 | +returnthis; |
| 40 | + } |
| 41 | + |
| 42 | +publicTestRunneraddReporterList(List<Reporter>reporterList) { |
| 43 | +this.reporterList.addAll(reporterList); |
| 44 | +returnthis; |
31 | 45 | }
|
32 | 46 |
|
33 |
| -publicvoidrun(Connectionconn,List<String>pathList,List<Reporter>reporterList)throwsSQLException { |
34 |
| -for (Reporterr :reporterList) |
| 47 | +publicTestRunneraddCoverageScheme(StringcoverageScheme) { |
| 48 | +this.coverageSchemes.add(coverageScheme); |
| 49 | +returnthis; |
| 50 | + } |
| 51 | + |
| 52 | +publicTestRunnerwithSourceFiles(List<String>sourceFiles) { |
| 53 | +this.sourceFiles.addAll(sourceFiles); |
| 54 | +returnthis; |
| 55 | + } |
| 56 | + |
| 57 | +publicTestRunnerwithTestFiles(List<String>testFiles) { |
| 58 | +this.testFiles.addAll(testFiles); |
| 59 | +returnthis; |
| 60 | + } |
| 61 | + |
| 62 | +publicTestRunnerincludeObject(Stringobj) { |
| 63 | +this.includeObjects.add(obj); |
| 64 | +returnthis; |
| 65 | + } |
| 66 | + |
| 67 | +publicTestRunnerexcludeObject(Stringobj) { |
| 68 | +this.excludeObjects.add(obj); |
| 69 | +returnthis; |
| 70 | + } |
| 71 | + |
| 72 | +publicvoidrun(Connectionconn)throwsSQLException { |
| 73 | +for (Reporterr :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(newDocumentationReporter().init(conn)); |
| 82 | + } |
| 83 | + |
37 | 84 | OracleConnectionoraConn =conn.unwrap(OracleConnection.class);
|
38 |
| -ArraypathArray =oraConn.createARRAY(CustomTypes.UT_VARCHAR2_LIST,pathList.toArray()); |
39 |
| -ArrayreporterArray =oraConn.createARRAY(CustomTypes.UT_REPORTERS,reporterList.toArray()); |
| 85 | +ArraypathArray =oraConn.createARRAY(CustomTypes.UT_VARCHAR2_LIST,this.pathList.toArray()); |
| 86 | +ArrayreporterArray =oraConn.createARRAY(CustomTypes.UT_REPORTERS,this.reporterList.toArray()); |
| 87 | +ArraycoverageSchemes =oraConn.createARRAY(CustomTypes.UT_VARCHAR2_LIST,this.coverageSchemes.toArray()); |
| 88 | +ArraysourceFiles =oraConn.createARRAY(CustomTypes.UT_VARCHAR2_LIST,this.sourceFiles.toArray()); |
| 89 | +ArraytestFiles =oraConn.createARRAY(CustomTypes.UT_VARCHAR2_LIST,this.testFiles.toArray()); |
| 90 | +ArrayincludeObjects =oraConn.createARRAY(CustomTypes.UT_VARCHAR2_LIST,this.includeObjects.toArray()); |
| 91 | +ArrayexcludeObjects =oraConn.createARRAY(CustomTypes.UT_VARCHAR2_LIST,this.excludeObjects.toArray()); |
40 | 92 |
|
41 | 93 | CallableStatementcallableStatement =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)
|
|