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