Skip to content

Commit fdb940b

Browse files
committed
Started to rewrite the whole reporter API
so it works with the new core reporter objects.
1 parent aa83de6 commit fdb940b

17 files changed

+217
-200
lines changed

src/main/java/org/utplsql/api/OutputBuffer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void fetchAvailable(Connection conn, Callback cb) throws SQLException {
6767
ResultSet resultSet = null;
6868
try {
6969
preparedStatement = conn.prepareStatement("SELECT * FROM table(ut_output_buffer.get_lines(?))");
70-
preparedStatement.setString(1, getReporter().getReporterId());
70+
preparedStatement.setString(1, getReporter().getId());
7171
resultSet = preparedStatement.executeQuery();
7272

7373
while (resultSet.next())
@@ -92,7 +92,7 @@ public List<String> fetchAll(Connection conn) throws SQLException {
9292
try {
9393
callableStatement = conn.prepareCall("BEGIN ? := ut_output_buffer.get_lines_cursor(?); END;");
9494
callableStatement.registerOutParameter(1, OracleTypes.CURSOR);
95-
callableStatement.setString(2, getReporter().getReporterId());
95+
callableStatement.setString(2, getReporter().getId());
9696
callableStatement.execute();
9797

9898
resultSet = (ResultSet) callableStatement.getObject(1);

src/main/java/org/utplsql/api/TestRunner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ else if (e.getErrorCode() == UtPLSQLNotInstalledException.ERROR_CODE) {
156156
* @throws SQLException any sql exception
157157
*/
158158
private void validateReporter(Connection conn, Reporter reporter) throws SQLException {
159-
if (reporter.getReporterId() == null || reporter.getReporterId().isEmpty())
159+
if (reporter.getId() == null || reporter.getId().isEmpty())
160160
reporter.init(conn);
161161
}
162162

src/main/java/org/utplsql/api/reporter/CoverageHTMLReporter.java

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,11 @@ public class CoverageHTMLReporter extends Reporter {
2525
private String assetsPath;
2626

2727
public CoverageHTMLReporter() {
28-
this(null, DEFAULT_ASSETS_PATH);
28+
super(DefaultReporters.UT_COVERAGE_HTML_REPORTER.name(), null);
2929
}
3030

31-
public CoverageHTMLReporter(String projectName, String assetsPath) {
32-
this.projectName = projectName;
33-
this.assetsPath = assetsPath;
34-
}
35-
36-
@Override
37-
public String getSQLTypeName() throws SQLException {
38-
return DefaultReporters.UT_COVERAGE_HTML_REPORTER.name();
31+
public CoverageHTMLReporter(String selfType, Object[] attributes) {
32+
super(selfType, attributes);
3933
}
4034

4135
public String getProjectName() {
@@ -54,20 +48,6 @@ public void setAssetsPath(String assetsPath) {
5448
this.assetsPath = assetsPath;
5549
}
5650

57-
@Override
58-
public void readSQL(SQLInput stream, String typeName) throws SQLException {
59-
super.readSQL(stream, typeName);
60-
setProjectName(stream.readString());
61-
setAssetsPath(stream.readString());
62-
}
63-
64-
@Override
65-
public void writeSQL(SQLOutput stream) throws SQLException {
66-
super.writeSQL(stream);
67-
stream.writeString(getProjectName());
68-
stream.writeString(getAssetsPath());
69-
}
70-
7151
/** Copies files from Classpath to a target directory.
7252
* Can omit the first x folders of the asset-path when copying to the target directory
7353
*

src/main/java/org/utplsql/api/reporter/CoverageSonarReporter.java

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/main/java/org/utplsql/api/reporter/CoverallsReporter.java

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/main/java/org/utplsql/api/reporter/DefaultReporters.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.utplsql.api.reporter;
22

3+
import java.util.function.BiFunction;
34
import java.util.function.Supplier;
45

56
/** This enum defines default reporters, added and maintained by the utPLSQL team, and their (default) factory method
@@ -12,24 +13,24 @@ public enum DefaultReporters {
1213
"Based on open-source simplecov-html coverage reporter for Ruby.\n" +
1314
"Includes source code in the report."),
1415
UT_DOCUMENTATION_REPORTER(DocumentationReporter::new, "A textual pretty-print of unit test results (usually use for console output)"),
15-
UT_TEAMCITY_REPORTER(TeamCityReporter::new, "For reporting live progress of test execution with Teamcity CI."),
16-
UT_XUNIT_REPORTER(XUnitReporter::new, "Used for reporting test results with CI servers like Jenkins/Hudson/Teamcity."),
17-
UT_COVERALLS_REPORTER(CoverallsReporter::new, "Generates a JSON coverage report providing information on code coverage with line numbers.\n" +
16+
UT_TEAMCITY_REPORTER(ReporterFactory.getDefaultReporterFactoryMethod(), "For reporting live progress of test execution with Teamcity CI."),
17+
UT_XUNIT_REPORTER(ReporterFactory.getDefaultReporterFactoryMethod(), "Used for reporting test results with CI servers like Jenkins/Hudson/Teamcity."),
18+
UT_COVERALLS_REPORTER(ReporterFactory.getDefaultReporterFactoryMethod(), "Generates a JSON coverage report providing information on code coverage with line numbers.\n" +
1819
"Designed for [Coveralls](https://coveralls.io/)."),
19-
UT_COVERAGE_SONAR_REPORTER(CoverageSonarReporter::new, "Generates a JSON coverage report providing information on code coverage with line numbers.\n" +
20+
UT_COVERAGE_SONAR_REPORTER(ReporterFactory.getDefaultReporterFactoryMethod(), "Generates a JSON coverage report providing information on code coverage with line numbers.\n" +
2021
"Designed for [SonarQube](https://about.sonarqube.com/) to report coverage."),
21-
UT_SONAR_TEST_REPORTER(SonarTestReporter::new, "Generates a JSON report providing detailed information on test execution.\n" +
22+
UT_SONAR_TEST_REPORTER(ReporterFactory.getDefaultReporterFactoryMethod(), "Generates a JSON report providing detailed information on test execution.\n" +
2223
"Designed for [SonarQube](https://about.sonarqube.com/) to report test execution.");
2324

24-
private Supplier<? extends Reporter> factoryMethod;
25+
private BiFunction<String, Object[], ? extends Reporter> factoryMethod;
2526
private String description;
2627

27-
DefaultReporters(Supplier<? extends Reporter> factoryMethod, String description ) {
28+
DefaultReporters(BiFunction<String, Object[], ? extends Reporter> factoryMethod, String description ) {
2829
this.factoryMethod = factoryMethod;
2930
this.description = description;
3031
}
3132

32-
public Supplier<? extends Reporter> getFactoryMethod() {
33+
public BiFunction<String, Object[], ? extends Reporter> getFactoryMethod() {
3334
return factoryMethod;
3435
}
3536

src/main/java/org/utplsql/api/reporter/DocumentationReporter.java

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ public class DocumentationReporter extends Reporter {
1010
private int failed;
1111

1212
public DocumentationReporter() {
13-
this.lvl = 0;
14-
this.failed = 0;
13+
super( DefaultReporters.UT_DOCUMENTATION_REPORTER.name(), null );
14+
}
15+
16+
public DocumentationReporter(String selfType, Object[] attributes ) {
17+
super(selfType, attributes);
1518
}
1619

1720
public int getLvl() {
@@ -30,23 +33,4 @@ public void setFailed(int failed) {
3033
this.failed = failed;
3134
}
3235

33-
@Override
34-
public String getSQLTypeName() throws SQLException {
35-
return DefaultReporters.UT_DOCUMENTATION_REPORTER.name();
36-
}
37-
38-
@Override
39-
public void readSQL(SQLInput stream, String typeName) throws SQLException {
40-
super.readSQL(stream, typeName);
41-
setLvl(stream.readInt());
42-
setFailed(stream.readInt());
43-
}
44-
45-
@Override
46-
public void writeSQL(SQLOutput stream) throws SQLException {
47-
super.writeSQL(stream);
48-
stream.writeInt(getLvl());
49-
stream.writeInt(getFailed());
50-
}
51-
5236
}
Lines changed: 46 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
package org.utplsql.api.reporter;
22

3+
import oracle.jdbc.OracleCallableStatement;
4+
import oracle.jdbc.OracleConnection;
5+
import oracle.jdbc.OracleTypes;
6+
import oracle.sql.Datum;
7+
import oracle.sql.ORAData;
8+
import oracle.sql.STRUCT;
9+
import oracle.sql.StructDescriptor;
310
import org.utplsql.api.DBHelper;
411

512
import java.sql.*;
@@ -8,57 +15,62 @@
815
/**
916
* Created by Vinicius on 13/04/2017.
1017
*/
11-
public abstract class Reporter implements SQLData {
18+
public class Reporter implements ORAData {
1219

13-
private String selfType;
14-
private String reporterId;
15-
private java.sql.Date startDate;
20+
protected String selfType;
21+
protected String id;
22+
protected Object[] attributes;
1623

17-
public Reporter() {}
24+
public Reporter( String typeName, Object[] attributes ) {
25+
selfType = typeName;
1826

19-
public Reporter init(Connection conn) throws SQLException {
20-
setSelfType(getSQLTypeName());
21-
setStartDate(new java.sql.Date(Calendar.getInstance().getTimeInMillis()));
22-
setReporterId(DBHelper.newSysGuid(conn));
23-
return this;
27+
if ( attributes != null ) {
28+
this.id = String.valueOf(attributes[1]);
29+
}
30+
this.attributes = attributes;
2431
}
2532

26-
public String getSelfType() {
27-
return this.selfType;
33+
private void setTypeName( String typeName ) {
34+
this.selfType = typeName.replaceAll("[^0-9a-zA-Z_]", "");
2835
}
2936

30-
private void setSelfType(String selfType) {
31-
this.selfType = selfType;
37+
public void setParameters( Object[] parameters ) {
38+
// Empty method
3239
}
3340

34-
public String getReporterId() {
35-
return this.reporterId;
36-
}
41+
public Reporter init( Connection con ) throws SQLException {
3742

38-
private void setReporterId(String reporterId) {
39-
this.reporterId = reporterId;
40-
}
43+
OracleConnection oraConn = con.unwrap(OracleConnection.class);
44+
45+
OracleCallableStatement callableStatement = (OracleCallableStatement) oraConn.prepareCall("{? = call " + selfType + "()}");
46+
callableStatement.registerOutParameter(1, OracleTypes.STRUCT, "UT_REPORTER_BASE");
47+
callableStatement.execute();
48+
49+
Reporter obj = (Reporter) callableStatement.getORAData(1, ReporterFactory.getInstance());
4150

42-
public java.sql.Date getStartDate() {
43-
return this.startDate;
51+
// TODO: Really override things
52+
this.attributes = obj.attributes;
53+
54+
// Check whether we have output or not
55+
56+
57+
return this;
4458
}
4559

46-
private void setStartDate(java.sql.Date startDate) {
47-
this.startDate = startDate;
60+
public String getTypeName() {
61+
return this.selfType;
4862
}
4963

50-
@Override
51-
public void readSQL(SQLInput stream, String typeName) throws SQLException {
52-
setSelfType(stream.readString());
53-
setReporterId(stream.readString());
54-
setStartDate(stream.readDate());
64+
public String getId() {
65+
return this.id;
5566
}
5667

57-
@Override
58-
public void writeSQL(SQLOutput stream) throws SQLException {
59-
stream.writeString(getSelfType());
60-
stream.writeString(getReporterId());
61-
stream.writeDate(getStartDate());
68+
69+
public Datum toDatum(Connection c) throws SQLException
70+
{
71+
StructDescriptor sd =
72+
StructDescriptor.createDescriptor(selfType, c);
73+
return new STRUCT(sd, c, attributes);
6274
}
6375

6476
}

0 commit comments

Comments
 (0)