Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add support for multiple reporters
  • Loading branch information
viniciusam committed May 20, 2017
commit ec292cf39d61e6ff8a7806aeba598c65e7b88248
24 changes: 24 additions & 0 deletions src/main/java/io/github/utplsql/api/TestRunner.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package io.github.utplsql.api;

import io.github.utplsql.api.types.BaseReporter;
import io.github.utplsql.api.types.CustomTypes;
import oracle.jdbc.OracleConnection;

import java.sql.Array;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

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

public void run(Connection conn, List<String> pathList, List<BaseReporter> reporterList) throws SQLException {
for (BaseReporter r : reporterList)
validateReporter(conn, r);

OracleConnection oraConn = conn.unwrap(OracleConnection.class);
Array pathArray = oraConn.createARRAY(CustomTypes.UT_VARCHAR2_LIST, pathList.toArray());
Array reporterArray = oraConn.createARRAY(CustomTypes.UT_REPORTERS, reporterList.toArray());

CallableStatement callableStatement = null;
try {
callableStatement = conn.prepareCall("BEGIN ut_runner.run(a_paths => ?, a_reporters => ?); END;");
callableStatement.setArray(1, pathArray);
callableStatement.setArray(2, reporterArray);
callableStatement.execute();
} finally {
if (callableStatement != null)
callableStatement.close();
}
}

/**
* Check if the reporter was initialized, if not call reporter.init.
* @param conn the database connection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class CoverageHTMLReporter extends BaseReporter {

@Override
public String getSQLTypeName() throws SQLException {
return CustomTypes.UT_COVERAGE_HTML_REPORTER.getName();
return CustomTypes.UT_COVERAGE_HTML_REPORTER;
}

}
24 changes: 13 additions & 11 deletions src/main/java/io/github/utplsql/api/types/CustomTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@
/**
* Database custom data types.
*/
public enum CustomTypes {
// Object names must be upper case.
UT_DOCUMENTATION_REPORTER("UT_DOCUMENTATION_REPORTER"),
UT_COVERAGE_HTML_REPORTER("UT_COVERAGE_HTML_REPORTER"),
UT_VARCHAR2_LIST("UT_VARCHAR2_LIST");
public final class CustomTypes {

private String typeName;
// Object names must be upper case.
public static final String UT_REPORTERS = "UT_REPORTERS";
public static final String UT_DOCUMENTATION_REPORTER = "UT_DOCUMENTATION_REPORTER";
public static final String UT_COVERAGE_HTML_REPORTER = "UT_COVERAGE_HTML_REPORTER";
public static final String UT_VARCHAR2_LIST = "UT_VARCHAR2_LIST";

CustomTypes(String typeName) {
this.typeName = typeName;
}
private CustomTypes() {}

public String getName() {
return this.typeName;
public static BaseReporter createReporter(String reporterName) {
switch (reporterName.toUpperCase()) {
case UT_DOCUMENTATION_REPORTER: return new DocumentationReporter();
case UT_COVERAGE_HTML_REPORTER: return new CoverageHTMLReporter();
}
throw new RuntimeException("Reporter " + reporterName + " not implemented.");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class DocumentationReporter extends BaseReporter {

@Override
public String getSQLTypeName() throws SQLException {
return CustomTypes.UT_DOCUMENTATION_REPORTER.getName();
return CustomTypes.UT_DOCUMENTATION_REPORTER;
}

}
21 changes: 21 additions & 0 deletions src/test/java/io/github/utplsql/api/TestRunnerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

import io.github.utplsql.api.rules.DatabaseRule;
import io.github.utplsql.api.types.BaseReporter;
import io.github.utplsql.api.types.CoverageHTMLReporter;
import io.github.utplsql.api.types.DocumentationReporter;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
* Created by Vinicius on 13/04/2017.
Expand All @@ -30,4 +33,22 @@ public void runWithDocumentationReporter() {
}
}

@Test
public void runWithTwoReporters() {
try {
Connection conn = db.newConnection();

List<String> pathList = new ArrayList<>();
pathList.add("app");

List<BaseReporter> reporterList = new ArrayList<>();
reporterList.add(new DocumentationReporter().init(conn));
reporterList.add(new CoverageHTMLReporter().init(conn));

new TestRunner().run(conn, pathList, reporterList);
} catch (SQLException e) {
Assert.fail(e.getMessage());
}
}

}