Skip to content

Commit ec292cf

Browse files
committed
Add support for multiple reporters
1 parent e453df0 commit ec292cf

File tree

5 files changed

+60
-13
lines changed

5 files changed

+60
-13
lines changed

src/main/java/io/github/utplsql/api/TestRunner.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
package io.github.utplsql.api;
22

33
import io.github.utplsql.api.types.BaseReporter;
4+
import io.github.utplsql.api.types.CustomTypes;
5+
import oracle.jdbc.OracleConnection;
46

7+
import java.sql.Array;
58
import java.sql.CallableStatement;
69
import java.sql.Connection;
710
import java.sql.SQLException;
11+
import java.util.List;
812

913
/**
1014
* Created by Vinicius Avellar on 12/04/2017.
@@ -27,6 +31,26 @@ public void run(Connection conn, String path, BaseReporter reporter) throws SQLE
2731
}
2832
}
2933

34+
public void run(Connection conn, List<String> pathList, List<BaseReporter> reporterList) throws SQLException {
35+
for (BaseReporter r : reporterList)
36+
validateReporter(conn, r);
37+
38+
OracleConnection oraConn = conn.unwrap(OracleConnection.class);
39+
Array pathArray = oraConn.createARRAY(CustomTypes.UT_VARCHAR2_LIST, pathList.toArray());
40+
Array reporterArray = oraConn.createARRAY(CustomTypes.UT_REPORTERS, reporterList.toArray());
41+
42+
CallableStatement callableStatement = null;
43+
try {
44+
callableStatement = conn.prepareCall("BEGIN ut_runner.run(a_paths => ?, a_reporters => ?); END;");
45+
callableStatement.setArray(1, pathArray);
46+
callableStatement.setArray(2, reporterArray);
47+
callableStatement.execute();
48+
} finally {
49+
if (callableStatement != null)
50+
callableStatement.close();
51+
}
52+
}
53+
3054
/**
3155
* Check if the reporter was initialized, if not call reporter.init.
3256
* @param conn the database connection

src/main/java/io/github/utplsql/api/types/CoverageHTMLReporter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class CoverageHTMLReporter extends BaseReporter {
99

1010
@Override
1111
public String getSQLTypeName() throws SQLException {
12-
return CustomTypes.UT_COVERAGE_HTML_REPORTER.getName();
12+
return CustomTypes.UT_COVERAGE_HTML_REPORTER;
1313
}
1414

1515
}

src/main/java/io/github/utplsql/api/types/CustomTypes.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,22 @@
33
/**
44
* Database custom data types.
55
*/
6-
public enum CustomTypes {
7-
// Object names must be upper case.
8-
UT_DOCUMENTATION_REPORTER("UT_DOCUMENTATION_REPORTER"),
9-
UT_COVERAGE_HTML_REPORTER("UT_COVERAGE_HTML_REPORTER"),
10-
UT_VARCHAR2_LIST("UT_VARCHAR2_LIST");
6+
public final class CustomTypes {
117

12-
private String typeName;
8+
// Object names must be upper case.
9+
public static final String UT_REPORTERS = "UT_REPORTERS";
10+
public static final String UT_DOCUMENTATION_REPORTER = "UT_DOCUMENTATION_REPORTER";
11+
public static final String UT_COVERAGE_HTML_REPORTER = "UT_COVERAGE_HTML_REPORTER";
12+
public static final String UT_VARCHAR2_LIST = "UT_VARCHAR2_LIST";
1313

14-
CustomTypes(String typeName) {
15-
this.typeName = typeName;
16-
}
14+
private CustomTypes() {}
1715

18-
public String getName() {
19-
return this.typeName;
16+
public static BaseReporter createReporter(String reporterName) {
17+
switch (reporterName.toUpperCase()) {
18+
case UT_DOCUMENTATION_REPORTER: return new DocumentationReporter();
19+
case UT_COVERAGE_HTML_REPORTER: return new CoverageHTMLReporter();
20+
}
21+
throw new RuntimeException("Reporter " + reporterName + " not implemented.");
2022
}
2123

2224
}

src/main/java/io/github/utplsql/api/types/DocumentationReporter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class DocumentationReporter extends BaseReporter {
99

1010
@Override
1111
public String getSQLTypeName() throws SQLException {
12-
return CustomTypes.UT_DOCUMENTATION_REPORTER.getName();
12+
return CustomTypes.UT_DOCUMENTATION_REPORTER;
1313
}
1414

1515
}

src/test/java/io/github/utplsql/api/TestRunnerTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22

33
import io.github.utplsql.api.rules.DatabaseRule;
44
import io.github.utplsql.api.types.BaseReporter;
5+
import io.github.utplsql.api.types.CoverageHTMLReporter;
56
import io.github.utplsql.api.types.DocumentationReporter;
67
import org.junit.Assert;
78
import org.junit.Rule;
89
import org.junit.Test;
910

1011
import java.sql.Connection;
1112
import java.sql.SQLException;
13+
import java.util.ArrayList;
14+
import java.util.List;
1215

1316
/**
1417
* Created by Vinicius on 13/04/2017.
@@ -30,4 +33,22 @@ public void runWithDocumentationReporter() {
3033
}
3134
}
3235

36+
@Test
37+
public void runWithTwoReporters() {
38+
try {
39+
Connection conn = db.newConnection();
40+
41+
List<String> pathList = new ArrayList<>();
42+
pathList.add("app");
43+
44+
List<BaseReporter> reporterList = new ArrayList<>();
45+
reporterList.add(new DocumentationReporter().init(conn));
46+
reporterList.add(new CoverageHTMLReporter().init(conn));
47+
48+
new TestRunner().run(conn, pathList, reporterList);
49+
} catch (SQLException e) {
50+
Assert.fail(e.getMessage());
51+
}
52+
}
53+
3354
}

0 commit comments

Comments
 (0)