55import org .utplsql .api .reporter .DocumentationReporter ;
66import org .utplsql .api .reporter .Reporter ;
77import oracle .jdbc .OracleConnection ;
8+ import org .utplsql .api .testRunner .AbstractTestRunnerStatement ;
9+ import org .utplsql .api .testRunner .TestRunnerStatement ;
810
911import java .sql .CallableStatement ;
1012import java .sql .Connection ;
1820 */
1921public 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 );
0 commit comments