-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathTestRunner.java
More file actions
130 lines (103 loc) · 3.84 KB
/
TestRunner.java
File metadata and controls
130 lines (103 loc) · 3.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package org.utplsql.api;
import org.utplsql.api.exception.DatabaseNotCompatibleException;
import org.utplsql.api.exception.SomeTestsFailedException;
import org.utplsql.api.reporter.DocumentationReporter;
import org.utplsql.api.reporter.Reporter;
import oracle.jdbc.OracleConnection;
import org.utplsql.api.testRunner.AbstractTestRunnerStatement;
import org.utplsql.api.testRunner.TestRunnerStatement;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Types;
import java.util.ArrayList;
import java.util.List;
/**
* Created by Vinicius Avellar on 12/04/2017.
*/
public class TestRunner {
private TestRunnerOptions options = new TestRunnerOptions();
public TestRunner addPath(String path) {
options.pathList.add(path);
return this;
}
public TestRunner addPathList(List<String> paths) {
if (options.pathList != null) options.pathList.addAll(paths);
return this;
}
public TestRunner addReporter(Reporter reporter) {
options.reporterList.add(reporter);
return this;
}
public TestRunner colorConsole(boolean colorConsole) {
options.colorConsole = colorConsole;
return this;
}
public TestRunner addReporterList(List<Reporter> reporterList) {
if (options.reporterList != null) options.reporterList.addAll(reporterList);
return this;
}
public TestRunner addCoverageScheme(String coverageScheme) {
options.coverageSchemes.add(coverageScheme);
return this;
}
public TestRunner includeObject(String obj) {
options.includeObjects.add(obj);
return this;
}
public TestRunner excludeObject(String obj) {
options.excludeObjects.add(obj);
return this;
}
public TestRunner sourceMappingOptions(FileMapperOptions mapperOptions) {
options.sourceMappingOptions = mapperOptions;
return this;
}
public TestRunner testMappingOptions(FileMapperOptions mapperOptions) {
options.testMappingOptions = mapperOptions;
return this;
}
public TestRunner failOnErrors(boolean failOnErrors) {
options.failOnErrors = failOnErrors;
return this;
}
public void run(Connection conn) throws SomeTestsFailedException, SQLException, DatabaseNotCompatibleException {
// First of all check version compatibility
DBHelper.failOnVersionCompatibilityCheckFailed(conn);
for (Reporter r : options.reporterList)
validateReporter(conn, r);
if (options.pathList.isEmpty()) {
options.pathList.add(DBHelper.getCurrentSchema(conn));
}
if (options.reporterList.isEmpty()) {
options.reporterList.add(new DocumentationReporter().init(conn));
}
AbstractTestRunnerStatement testRunnerStatement = null;
try {
DBHelper.enableDBMSOutput(conn);
testRunnerStatement = new TestRunnerStatement(options, conn);
testRunnerStatement.execute();
} catch (SQLException e) {
if (e.getErrorCode() == SomeTestsFailedException.ERROR_CODE) {
throw new SomeTestsFailedException(e.getMessage(), e);
} else {
throw e;
}
} finally {
if (testRunnerStatement != null) {
testRunnerStatement.close();
}
DBHelper.disableDBMSOutput(conn);
}
}
/**
* Check if the reporter was initialized, if not call reporter.init.
* @param conn the database connection
* @param reporter the reporter
* @throws SQLException any sql exception
*/
private void validateReporter(Connection conn, Reporter reporter) throws SQLException {
if (reporter.getReporterId() == null || reporter.getReporterId().isEmpty())
reporter.init(conn);
}
}