5
5
import org .utplsql .api .reporter .DocumentationReporter ;
6
6
import org .utplsql .api .reporter .Reporter ;
7
7
import oracle .jdbc .OracleConnection ;
8
+ import org .utplsql .api .testRunner .AbstractTestRunnerStatement ;
9
+ import org .utplsql .api .testRunner .TestRunnerStatement ;
8
10
9
11
import java .sql .CallableStatement ;
10
12
import java .sql .Connection ;
18
20
*/
19
21
public class TestRunner {
20
22
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 ();
32
24
33
25
public TestRunner addPath (String path ) {
34
- this .pathList .add (path );
26
+ options .pathList .add (path );
35
27
return this ;
36
28
}
37
29
38
30
public TestRunner addPathList (List <String > paths ) {
39
- if (pathList != null ) this .pathList .addAll (paths );
31
+ if (options . pathList != null ) options .pathList .addAll (paths );
40
32
return this ;
41
33
}
42
34
43
35
public TestRunner addReporter (Reporter reporter ) {
44
- this .reporterList .add (reporter );
36
+ options .reporterList .add (reporter );
45
37
return this ;
46
38
}
47
39
48
40
public TestRunner colorConsole (boolean colorConsole ) {
49
- this .colorConsole = colorConsole ;
41
+ options .colorConsole = colorConsole ;
50
42
return this ;
51
43
}
52
44
53
45
public TestRunner addReporterList (List <Reporter > reporterList ) {
54
- if (reporterList != null ) this .reporterList .addAll (reporterList );
46
+ if (options . reporterList != null ) options .reporterList .addAll (reporterList );
55
47
return this ;
56
48
}
57
49
58
50
public TestRunner addCoverageScheme (String coverageScheme ) {
59
- this .coverageSchemes .add (coverageScheme );
51
+ options .coverageSchemes .add (coverageScheme );
60
52
return this ;
61
53
}
62
54
63
55
public TestRunner includeObject (String obj ) {
64
- this .includeObjects .add (obj );
56
+ options .includeObjects .add (obj );
65
57
return this ;
66
58
}
67
59
68
60
public TestRunner excludeObject (String obj ) {
69
- this .excludeObjects .add (obj );
61
+ options .excludeObjects .add (obj );
70
62
return this ;
71
63
}
72
64
73
65
public TestRunner sourceMappingOptions (FileMapperOptions mapperOptions ) {
74
- this .sourceMappingOptions = mapperOptions ;
66
+ options .sourceMappingOptions = mapperOptions ;
75
67
return this ;
76
68
}
77
69
78
70
public TestRunner testMappingOptions (FileMapperOptions mapperOptions ) {
79
- this .testMappingOptions = mapperOptions ;
71
+ options .testMappingOptions = mapperOptions ;
80
72
return this ;
81
73
}
82
74
83
75
public TestRunner failOnErrors (boolean failOnErrors ) {
84
- this .failOnErrors = failOnErrors ;
76
+ options .failOnErrors = failOnErrors ;
85
77
return this ;
86
78
}
87
79
@@ -90,97 +82,34 @@ public void run(Connection conn) throws SomeTestsFailedException, SQLException,
90
82
// First of all check version compatibility
91
83
DBHelper .failOnVersionCompatibilityCheckFailed (conn );
92
84
93
- for (Reporter r : this .reporterList )
85
+ for (Reporter r : options .reporterList )
94
86
validateReporter (conn , r );
95
87
96
- if (this .pathList .isEmpty ()) {
97
- this .pathList .add (DBHelper .getCurrentSchema (conn ));
88
+ if (options .pathList .isEmpty ()) {
89
+ options .pathList .add (DBHelper .getCurrentSchema (conn ));
98
90
}
99
91
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 ));
102
94
}
103
95
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 ;
107
97
108
- OracleConnection oraConn = conn .unwrap (OracleConnection .class );
109
- CallableStatement callableStatement = null ;
110
98
try {
111
99
DBHelper .enableDBMSOutput (conn );
112
100
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 );
173
102
174
- callableStatement .execute ();
103
+ testRunnerStatement .execute ();
175
104
} catch (SQLException e ) {
176
105
if (e .getErrorCode () == SomeTestsFailedException .ERROR_CODE ) {
177
106
throw new SomeTestsFailedException (e .getMessage (), e );
178
107
} else {
179
108
throw e ;
180
109
}
181
110
} finally {
182
- if (callableStatement != null ) {
183
- callableStatement .close ();
111
+ if (testRunnerStatement != null ) {
112
+ testRunnerStatement .close ();
184
113
}
185
114
186
115
DBHelper .disableDBMSOutput (conn );
0 commit comments