diff --git a/src/main/java/io/github/utplsql/api/CustomTypes.java b/src/main/java/io/github/utplsql/api/CustomTypes.java new file mode 100644 index 0000000..6dc6856 --- /dev/null +++ b/src/main/java/io/github/utplsql/api/CustomTypes.java @@ -0,0 +1,21 @@ +package io.github.utplsql.api; + +/** + * Database custom data reporter. + */ +public final class CustomTypes { + + // 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_TEAMCITY_REPORTER = "UT_TEAMCITY_REPORTER"; + public static final String UT_XUNIT_REPORTER = "UT_XUNIT_REPORTER"; + public static final String UT_COVERALLS_REPORTER = "UT_COVERALLS_REPORTER"; + public static final String UT_COVERAGE_SONAR_REPORTER = "UT_COVERAGE_SONAR_REPORTER"; + public static final String UT_SONAR_TEST_REPORTER = "UT_SONAR_TEST_REPORTER"; + public static final String UT_VARCHAR2_LIST = "UT_VARCHAR2_LIST"; + + private CustomTypes() {} + +} diff --git a/src/main/java/io/github/utplsql/api/DBHelper.java b/src/main/java/io/github/utplsql/api/DBHelper.java index 348472f..f3a880e 100644 --- a/src/main/java/io/github/utplsql/api/DBHelper.java +++ b/src/main/java/io/github/utplsql/api/DBHelper.java @@ -5,19 +5,47 @@ import java.sql.CallableStatement; import java.sql.Connection; import java.sql.SQLException; +import java.sql.Types; /** - * Created by Vinicius Avellar on 12/04/2017. + * Database utility functions. */ public final class DBHelper { + private DBHelper() {} + + /** + * Return a new sys_guid from database. + * @param conn the connection + * @return the new id string + * @throws SQLException any database error + */ public static String newSysGuid(Connection conn) throws SQLException { CallableStatement callableStatement = null; try { - callableStatement = conn.prepareCall("BEGIN :id := sys_guid(); END;"); - callableStatement.registerOutParameter(":id", OracleTypes.RAW); + callableStatement = conn.prepareCall("BEGIN ? := sys_guid(); END;"); + callableStatement.registerOutParameter(1, OracleTypes.RAW); + callableStatement.executeUpdate(); + return callableStatement.getString(1); + } finally { + if (callableStatement != null) + callableStatement.close(); + } + } + + /** + * Return the current schema name. + * @param conn the connection + * @return the schema name + * @throws SQLException any database error + */ + public static String getCurrentSchema(Connection conn) throws SQLException { + CallableStatement callableStatement = null; + try { + callableStatement = conn.prepareCall("BEGIN ? := sys_context('userenv', 'current_schema'); END;"); + callableStatement.registerOutParameter(1, Types.VARCHAR); callableStatement.executeUpdate(); - return callableStatement.getString(":id"); + return callableStatement.getString(1); } finally { if (callableStatement != null) callableStatement.close(); diff --git a/src/main/java/io/github/utplsql/api/OutputBuffer.java b/src/main/java/io/github/utplsql/api/OutputBuffer.java index be1e484..bc12010 100644 --- a/src/main/java/io/github/utplsql/api/OutputBuffer.java +++ b/src/main/java/io/github/utplsql/api/OutputBuffer.java @@ -1,6 +1,6 @@ package io.github.utplsql.api; -import io.github.utplsql.api.types.BaseReporter; +import io.github.utplsql.api.reporter.Reporter; import oracle.jdbc.OracleTypes; import java.io.PrintStream; @@ -13,13 +13,13 @@ */ public class OutputBuffer { - private BaseReporter reporter; + private Reporter reporter; /** * Creates a new OutputBuffer. * @param reporter the reporter to be used */ - public OutputBuffer(BaseReporter reporter) { + public OutputBuffer(Reporter reporter) { this.reporter = reporter; } @@ -27,7 +27,7 @@ public OutputBuffer(BaseReporter reporter) { * Returns the reporter used by this buffer. * @return the reporter instance */ - public BaseReporter getReporter() { + public Reporter getReporter() { return reporter; } @@ -66,7 +66,7 @@ public void fetchAvailable(Connection conn, Callback cb) throws SQLException { PreparedStatement preparedStatement = null; ResultSet resultSet = null; try { - preparedStatement = conn.prepareCall("SELECT * FROM table(ut_output_buffer.get_lines(?))"); + preparedStatement = conn.prepareStatement("SELECT * FROM table(ut_output_buffer.get_lines(?))"); preparedStatement.setString(1, getReporter().getReporterId()); resultSet = preparedStatement.executeQuery(); diff --git a/src/main/java/io/github/utplsql/api/TestRunner.java b/src/main/java/io/github/utplsql/api/TestRunner.java index 79423d7..1489fbf 100644 --- a/src/main/java/io/github/utplsql/api/TestRunner.java +++ b/src/main/java/io/github/utplsql/api/TestRunner.java @@ -1,25 +1,108 @@ package io.github.utplsql.api; -import io.github.utplsql.api.types.BaseReporter; +import io.github.utplsql.api.reporter.DocumentationReporter; +import io.github.utplsql.api.reporter.Reporter; +import oracle.jdbc.OracleConnection; -import java.sql.CallableStatement; -import java.sql.Connection; -import java.sql.SQLException; +import java.sql.*; +import java.util.ArrayList; +import java.util.List; /** * Created by Vinicius Avellar on 12/04/2017. */ public class TestRunner { - public TestRunner() {} + private List pathList = new ArrayList<>(); + private List reporterList = new ArrayList<>(); + private List coverageSchemes = new ArrayList<>(); + private List sourceFiles = new ArrayList<>(); + private List testFiles = new ArrayList<>(); + private List includeObjects = new ArrayList<>(); + private List excludeObjects = new ArrayList<>(); + + public TestRunner addPath(String path) { + this.pathList.add(path); + return this; + } + + public TestRunner addPathList(List paths) { + this.pathList.addAll(paths); + return this; + } + + public TestRunner addReporter(Reporter reporter) { + this.reporterList.add(reporter); + return this; + } + + public TestRunner addReporterList(List reporterList) { + this.reporterList.addAll(reporterList); + return this; + } + + public TestRunner addCoverageScheme(String coverageScheme) { + this.coverageSchemes.add(coverageScheme); + return this; + } + + public TestRunner withSourceFiles(List sourceFiles) { + this.sourceFiles.addAll(sourceFiles); + return this; + } + + public TestRunner withTestFiles(List testFiles) { + this.testFiles.addAll(testFiles); + return this; + } + + public TestRunner includeObject(String obj) { + this.includeObjects.add(obj); + return this; + } + + public TestRunner excludeObject(String obj) { + this.excludeObjects.add(obj); + return this; + } + + public void run(Connection conn) throws SQLException { + for (Reporter r : this.reporterList) + validateReporter(conn, r); + + if (this.pathList.isEmpty()) { + this.pathList.add(DBHelper.getCurrentSchema(conn)); + } + + if (this.reporterList.isEmpty()) { + this.reporterList.add(new DocumentationReporter().init(conn)); + } + + OracleConnection oraConn = conn.unwrap(OracleConnection.class); + Array pathArray = oraConn.createARRAY(CustomTypes.UT_VARCHAR2_LIST, this.pathList.toArray()); + Array reporterArray = oraConn.createARRAY(CustomTypes.UT_REPORTERS, this.reporterList.toArray()); + Array coverageSchemesArray = oraConn.createARRAY(CustomTypes.UT_VARCHAR2_LIST, this.coverageSchemes.toArray()); + Array sourceFilesArray = oraConn.createARRAY(CustomTypes.UT_VARCHAR2_LIST, this.sourceFiles.toArray()); + Array testFilesArray = oraConn.createARRAY(CustomTypes.UT_VARCHAR2_LIST, this.testFiles.toArray()); + Array includeObjectsArray = oraConn.createARRAY(CustomTypes.UT_VARCHAR2_LIST, this.includeObjects.toArray()); + Array excludeObjectsArray = oraConn.createARRAY(CustomTypes.UT_VARCHAR2_LIST, this.excludeObjects.toArray()); - public void run(Connection conn, String path, BaseReporter reporter) throws SQLException { - validateReporter(conn, reporter); CallableStatement callableStatement = null; try { - callableStatement = conn.prepareCall("BEGIN ut_runner.run(a_path => :path, a_reporter => :reporter); END;"); - callableStatement.setString(":path", path); - callableStatement.setObject(":reporter", reporter); + callableStatement = conn.prepareCall( + "BEGIN " + + "ut_runner.run(" + + "a_paths => ?, a_reporters => ?, a_coverage_schemes => ?," + + "a_source_files => ?, a_test_files => ?, " + + "a_include_objects => ?, a_exclude_objects => ?); " + + "END;"); + callableStatement.setArray(1, pathArray); + callableStatement.setArray(2, reporterArray); + callableStatement.setArray(3, coverageSchemesArray); + callableStatement.setArray(4, sourceFilesArray); + callableStatement.setArray(5, testFilesArray); + callableStatement.setArray(6, includeObjectsArray); + callableStatement.setArray(7, excludeObjectsArray); callableStatement.execute(); } finally { if (callableStatement != null) @@ -33,7 +116,7 @@ public void run(Connection conn, String path, BaseReporter reporter) throws SQLE * @param reporter the reporter * @throws SQLException any sql exception */ - private void validateReporter(Connection conn, BaseReporter reporter) throws SQLException { + private void validateReporter(Connection conn, Reporter reporter) throws SQLException { if (reporter.getReporterId() == null || reporter.getReporterId().isEmpty()) reporter.init(conn); } diff --git a/src/main/java/io/github/utplsql/api/reporter/CoverageHTMLReporter.java b/src/main/java/io/github/utplsql/api/reporter/CoverageHTMLReporter.java new file mode 100644 index 0000000..b0a61be --- /dev/null +++ b/src/main/java/io/github/utplsql/api/reporter/CoverageHTMLReporter.java @@ -0,0 +1,58 @@ +package io.github.utplsql.api.reporter; + +import io.github.utplsql.api.CustomTypes; + +import java.sql.SQLException; +import java.sql.SQLInput; +import java.sql.SQLOutput; + +public class CoverageHTMLReporter extends Reporter { + + private String projectName; + private String assetsPath; + + public CoverageHTMLReporter() { + + } + + public CoverageHTMLReporter(String projectName, String assetsPath) { + this.projectName = projectName; + this.assetsPath = assetsPath; + } + + @Override + public String getSQLTypeName() throws SQLException { + return CustomTypes.UT_COVERAGE_HTML_REPORTER; + } + + public String getProjectName() { + return projectName; + } + + public void setProjectName(String projectName) { + this.projectName = projectName; + } + + public String getAssetsPath() { + return assetsPath; + } + + public void setAssetsPath(String assetsPath) { + this.assetsPath = assetsPath; + } + + @Override + public void readSQL(SQLInput stream, String typeName) throws SQLException { + super.readSQL(stream, typeName); + setProjectName(stream.readString()); + setAssetsPath(stream.readString()); + } + + @Override + public void writeSQL(SQLOutput stream) throws SQLException { + super.writeSQL(stream); + stream.writeString(getProjectName()); + stream.writeString(getAssetsPath()); + } + +} diff --git a/src/main/java/io/github/utplsql/api/reporter/CoverageSonarReporter.java b/src/main/java/io/github/utplsql/api/reporter/CoverageSonarReporter.java new file mode 100644 index 0000000..4f20c49 --- /dev/null +++ b/src/main/java/io/github/utplsql/api/reporter/CoverageSonarReporter.java @@ -0,0 +1,14 @@ +package io.github.utplsql.api.reporter; + +import io.github.utplsql.api.CustomTypes; + +import java.sql.SQLException; + +public class CoverageSonarReporter extends Reporter { + + @Override + public String getSQLTypeName() throws SQLException { + return CustomTypes.UT_COVERAGE_SONAR_REPORTER; + } + +} diff --git a/src/main/java/io/github/utplsql/api/reporter/CoverallsReporter.java b/src/main/java/io/github/utplsql/api/reporter/CoverallsReporter.java new file mode 100644 index 0000000..4173eab --- /dev/null +++ b/src/main/java/io/github/utplsql/api/reporter/CoverallsReporter.java @@ -0,0 +1,14 @@ +package io.github.utplsql.api.reporter; + +import io.github.utplsql.api.CustomTypes; + +import java.sql.SQLException; + +public class CoverallsReporter extends Reporter { + + @Override + public String getSQLTypeName() throws SQLException { + return CustomTypes.UT_COVERALLS_REPORTER; + } + +} diff --git a/src/main/java/io/github/utplsql/api/reporter/DocumentationReporter.java b/src/main/java/io/github/utplsql/api/reporter/DocumentationReporter.java new file mode 100644 index 0000000..c574b04 --- /dev/null +++ b/src/main/java/io/github/utplsql/api/reporter/DocumentationReporter.java @@ -0,0 +1,14 @@ +package io.github.utplsql.api.reporter; + +import io.github.utplsql.api.CustomTypes; + +import java.sql.SQLException; + +public class DocumentationReporter extends Reporter { + + @Override + public String getSQLTypeName() throws SQLException { + return CustomTypes.UT_DOCUMENTATION_REPORTER; + } + +} diff --git a/src/main/java/io/github/utplsql/api/types/BaseReporter.java b/src/main/java/io/github/utplsql/api/reporter/Reporter.java similarity index 87% rename from src/main/java/io/github/utplsql/api/types/BaseReporter.java rename to src/main/java/io/github/utplsql/api/reporter/Reporter.java index 7d52a10..007ea63 100644 --- a/src/main/java/io/github/utplsql/api/types/BaseReporter.java +++ b/src/main/java/io/github/utplsql/api/reporter/Reporter.java @@ -1,4 +1,4 @@ -package io.github.utplsql.api.types; +package io.github.utplsql.api.reporter; import io.github.utplsql.api.DBHelper; @@ -8,15 +8,15 @@ /** * Created by Vinicius on 13/04/2017. */ -public abstract class BaseReporter implements SQLData { +public abstract class Reporter implements SQLData { private String selfType; private String reporterId; private java.sql.Date startDate; - public BaseReporter() {} + public Reporter() {} - public BaseReporter init(Connection conn) throws SQLException { + public Reporter init(Connection conn) throws SQLException { setStartDate(new java.sql.Date(Calendar.getInstance().getTimeInMillis())); setReporterId(DBHelper.newSysGuid(conn)); return this; diff --git a/src/main/java/io/github/utplsql/api/reporter/ReporterFactory.java b/src/main/java/io/github/utplsql/api/reporter/ReporterFactory.java new file mode 100644 index 0000000..2a4d27d --- /dev/null +++ b/src/main/java/io/github/utplsql/api/reporter/ReporterFactory.java @@ -0,0 +1,22 @@ +package io.github.utplsql.api.reporter; + +import io.github.utplsql.api.CustomTypes; + +public final class ReporterFactory { + + private ReporterFactory() {} + + public static Reporter createReporter(String reporterName) { + switch (reporterName.toUpperCase()) { + case CustomTypes.UT_DOCUMENTATION_REPORTER: return new DocumentationReporter(); + case CustomTypes.UT_COVERAGE_HTML_REPORTER: return new CoverageHTMLReporter(); + case CustomTypes.UT_TEAMCITY_REPORTER: return new TeamCityReporter(); + case CustomTypes.UT_XUNIT_REPORTER: return new XUnitReporter(); + case CustomTypes.UT_COVERALLS_REPORTER: return new CoverallsReporter(); + case CustomTypes.UT_COVERAGE_SONAR_REPORTER: return new CoverageSonarReporter(); + case CustomTypes.UT_SONAR_TEST_REPORTER: return new SonarTestReporter(); + default: throw new RuntimeException("Reporter " + reporterName + " not implemented."); + } + } + +} diff --git a/src/main/java/io/github/utplsql/api/reporter/SonarTestReporter.java b/src/main/java/io/github/utplsql/api/reporter/SonarTestReporter.java new file mode 100644 index 0000000..1544847 --- /dev/null +++ b/src/main/java/io/github/utplsql/api/reporter/SonarTestReporter.java @@ -0,0 +1,14 @@ +package io.github.utplsql.api.reporter; + +import io.github.utplsql.api.CustomTypes; + +import java.sql.SQLException; + +public class SonarTestReporter extends Reporter { + + @Override + public String getSQLTypeName() throws SQLException { + return CustomTypes.UT_SONAR_TEST_REPORTER; + } + +} diff --git a/src/main/java/io/github/utplsql/api/reporter/TeamCityReporter.java b/src/main/java/io/github/utplsql/api/reporter/TeamCityReporter.java new file mode 100644 index 0000000..ef7689d --- /dev/null +++ b/src/main/java/io/github/utplsql/api/reporter/TeamCityReporter.java @@ -0,0 +1,14 @@ +package io.github.utplsql.api.reporter; + +import io.github.utplsql.api.CustomTypes; + +import java.sql.SQLException; + +public class TeamCityReporter extends Reporter { + + @Override + public String getSQLTypeName() throws SQLException { + return CustomTypes.UT_TEAMCITY_REPORTER; + } + +} diff --git a/src/main/java/io/github/utplsql/api/reporter/XUnitReporter.java b/src/main/java/io/github/utplsql/api/reporter/XUnitReporter.java new file mode 100644 index 0000000..aca7d92 --- /dev/null +++ b/src/main/java/io/github/utplsql/api/reporter/XUnitReporter.java @@ -0,0 +1,14 @@ +package io.github.utplsql.api.reporter; + +import io.github.utplsql.api.CustomTypes; + +import java.sql.SQLException; + +public class XUnitReporter extends Reporter { + + @Override + public String getSQLTypeName() throws SQLException { + return CustomTypes.UT_XUNIT_REPORTER; + } + +} diff --git a/src/main/java/io/github/utplsql/api/types/CoverageHTMLReporter.java b/src/main/java/io/github/utplsql/api/types/CoverageHTMLReporter.java deleted file mode 100644 index 6bba1ee..0000000 --- a/src/main/java/io/github/utplsql/api/types/CoverageHTMLReporter.java +++ /dev/null @@ -1,15 +0,0 @@ -package io.github.utplsql.api.types; - -import java.sql.SQLException; - -/** - * Created by Vinicius on 13/04/2017. - */ -public class CoverageHTMLReporter extends BaseReporter { - - @Override - public String getSQLTypeName() throws SQLException { - return CustomTypes.UT_COVERAGE_HTML_REPORTER.getName(); - } - -} diff --git a/src/main/java/io/github/utplsql/api/types/CustomTypes.java b/src/main/java/io/github/utplsql/api/types/CustomTypes.java deleted file mode 100644 index 14f3893..0000000 --- a/src/main/java/io/github/utplsql/api/types/CustomTypes.java +++ /dev/null @@ -1,22 +0,0 @@ -package io.github.utplsql.api.types; - -/** - * 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"); - - private String typeName; - - CustomTypes(String typeName) { - this.typeName = typeName; - } - - public String getName() { - return this.typeName; - } - -} diff --git a/src/main/java/io/github/utplsql/api/types/DocumentationReporter.java b/src/main/java/io/github/utplsql/api/types/DocumentationReporter.java deleted file mode 100644 index 174842e..0000000 --- a/src/main/java/io/github/utplsql/api/types/DocumentationReporter.java +++ /dev/null @@ -1,15 +0,0 @@ -package io.github.utplsql.api.types; - -import java.sql.SQLException; - -/** - * Created by Vinicius on 13/04/2017. - */ -public class DocumentationReporter extends BaseReporter { - - @Override - public String getSQLTypeName() throws SQLException { - return CustomTypes.UT_DOCUMENTATION_REPORTER.getName(); - } - -} diff --git a/src/test/java/io/github/utplsql/api/OutputBufferTest.java b/src/test/java/io/github/utplsql/api/OutputBufferTest.java index c3fe2b0..eda4734 100644 --- a/src/test/java/io/github/utplsql/api/OutputBufferTest.java +++ b/src/test/java/io/github/utplsql/api/OutputBufferTest.java @@ -1,12 +1,13 @@ package io.github.utplsql.api; +import io.github.utplsql.api.reporter.DocumentationReporter; +import io.github.utplsql.api.reporter.Reporter; import io.github.utplsql.api.rules.DatabaseRule; -import io.github.utplsql.api.types.BaseReporter; -import io.github.utplsql.api.types.DocumentationReporter; import org.junit.Assert; import org.junit.Rule; import org.junit.Test; +import java.io.File; import java.io.FileOutputStream; import java.io.PrintStream; import java.sql.Connection; @@ -23,9 +24,9 @@ public class OutputBufferTest { @Rule public final DatabaseRule db = new DatabaseRule(); - public BaseReporter createReporter() throws SQLException { + public Reporter createReporter() throws SQLException { Connection conn = db.newConnection(); - BaseReporter reporter = new DocumentationReporter().init(conn); + Reporter reporter = new DocumentationReporter().init(conn); System.out.println("Reporter ID: " + reporter.getReporterId()); return reporter; } @@ -35,12 +36,15 @@ public void printAvailableLines() { ExecutorService executorService = Executors.newFixedThreadPool(2); try { - final BaseReporter reporter = createReporter(); + final Reporter reporter = createReporter(); Future task1 = executorService.submit(() -> { try { Connection conn = db.newConnection(); - new TestRunner().run(conn, "", reporter); + new TestRunner() + .addPath(db.getUser()) + .addReporter(reporter) + .run(conn); return Boolean.TRUE; } catch (SQLException e) { @@ -50,9 +54,10 @@ public void printAvailableLines() { Future task2 = executorService.submit(() -> { FileOutputStream fileOutStream = null; + File outFile = new File("output.txt"); try { Connection conn = db.newConnection(); - fileOutStream = new FileOutputStream("output.txt"); + fileOutStream = new FileOutputStream(outFile); List printStreams = new ArrayList<>(); printStreams.add(System.out); @@ -65,8 +70,10 @@ public void printAvailableLines() { } catch (SQLException e) { return e; } finally { - if (fileOutStream != null) + if (fileOutStream != null) { fileOutStream.close(); + outFile.delete(); + } } }); @@ -91,9 +98,12 @@ public void printAvailableLines() { @Test public void fetchAllLines() { try { - final BaseReporter reporter = createReporter(); + final Reporter reporter = createReporter(); Connection conn = db.newConnection(); - new TestRunner().run(conn, "", reporter); + new TestRunner() + .addPath(db.getUser()) + .addReporter(reporter) + .run(conn); List outputLines = new OutputBuffer(reporter) .fetchAll(conn); diff --git a/src/test/java/io/github/utplsql/api/ReporterNameTest.java b/src/test/java/io/github/utplsql/api/ReporterNameTest.java new file mode 100644 index 0000000..34f9118 --- /dev/null +++ b/src/test/java/io/github/utplsql/api/ReporterNameTest.java @@ -0,0 +1,40 @@ +package io.github.utplsql.api; + +import io.github.utplsql.api.reporter.*; +import org.junit.Assert; +import org.junit.Test; + +import java.sql.SQLException; + +public class ReporterNameTest { + + @Test + public void reporterSQLTypeName() throws SQLException { + Assert.assertEquals(CustomTypes.UT_COVERAGE_HTML_REPORTER, new CoverageHTMLReporter().getSQLTypeName()); + Assert.assertEquals(CustomTypes.UT_COVERAGE_SONAR_REPORTER, new CoverageSonarReporter().getSQLTypeName()); + Assert.assertEquals(CustomTypes.UT_COVERALLS_REPORTER, new CoverallsReporter().getSQLTypeName()); + Assert.assertEquals(CustomTypes.UT_DOCUMENTATION_REPORTER, new DocumentationReporter().getSQLTypeName()); + Assert.assertEquals(CustomTypes.UT_SONAR_TEST_REPORTER, new SonarTestReporter().getSQLTypeName()); + Assert.assertEquals(CustomTypes.UT_TEAMCITY_REPORTER, new TeamCityReporter().getSQLTypeName()); + Assert.assertEquals(CustomTypes.UT_XUNIT_REPORTER, new XUnitReporter().getSQLTypeName()); + } + + @Test + public void reporterFactory() { + Assert.assertTrue(ReporterFactory.createReporter(CustomTypes.UT_COVERAGE_HTML_REPORTER) + instanceof CoverageHTMLReporter); + Assert.assertTrue(ReporterFactory.createReporter(CustomTypes.UT_COVERAGE_SONAR_REPORTER) + instanceof CoverageSonarReporter); + Assert.assertTrue(ReporterFactory.createReporter(CustomTypes.UT_COVERALLS_REPORTER) + instanceof CoverallsReporter); + Assert.assertTrue(ReporterFactory.createReporter(CustomTypes.UT_DOCUMENTATION_REPORTER) + instanceof DocumentationReporter); + Assert.assertTrue(ReporterFactory.createReporter(CustomTypes.UT_SONAR_TEST_REPORTER) + instanceof SonarTestReporter); + Assert.assertTrue(ReporterFactory.createReporter(CustomTypes.UT_TEAMCITY_REPORTER) + instanceof TeamCityReporter); + Assert.assertTrue(ReporterFactory.createReporter(CustomTypes.UT_XUNIT_REPORTER) + instanceof XUnitReporter); + } + +} diff --git a/src/test/java/io/github/utplsql/api/TestRunnerTest.java b/src/test/java/io/github/utplsql/api/TestRunnerTest.java index f273589..f7f0600 100644 --- a/src/test/java/io/github/utplsql/api/TestRunnerTest.java +++ b/src/test/java/io/github/utplsql/api/TestRunnerTest.java @@ -1,8 +1,7 @@ package io.github.utplsql.api; +import io.github.utplsql.api.reporter.*; import io.github.utplsql.api.rules.DatabaseRule; -import io.github.utplsql.api.types.BaseReporter; -import io.github.utplsql.api.types.DocumentationReporter; import org.junit.Assert; import org.junit.Rule; import org.junit.Test; @@ -19,12 +18,30 @@ public class TestRunnerTest { public final DatabaseRule db = new DatabaseRule(); @Test - public void runWithDocumentationReporter() { + public void runWithDefaultParameters() { try { Connection conn = db.newConnection(); - BaseReporter reporter = new DocumentationReporter(); - new TestRunner().run(conn, "", reporter); - Assert.assertNotNull(reporter.getReporterId()); + new TestRunner().run(conn); + } catch (SQLException e) { + Assert.fail(e.getMessage()); + } + } + + @Test + public void runWithManyReporters() { + try { + Connection conn = db.newConnection(); + new TestRunner() + .addPath("ut3") + .addPath(db.getUser()) + .addReporter(new DocumentationReporter().init(conn)) + .addReporter(new CoverageHTMLReporter().init(conn)) + .addReporter(new CoverageSonarReporter().init(conn)) + .addReporter(new CoverallsReporter().init(conn)) + .addReporter(new SonarTestReporter().init(conn)) + .addReporter(new TeamCityReporter().init(conn)) + .addReporter(new XUnitReporter().init(conn)) + .run(conn); } catch (SQLException e) { Assert.fail(e.getMessage()); } diff --git a/src/test/java/io/github/utplsql/api/rules/DatabaseRule.java b/src/test/java/io/github/utplsql/api/rules/DatabaseRule.java index 7806c2c..da0c35a 100644 --- a/src/test/java/io/github/utplsql/api/rules/DatabaseRule.java +++ b/src/test/java/io/github/utplsql/api/rules/DatabaseRule.java @@ -29,6 +29,10 @@ public DatabaseRule() { connectionList = new ArrayList<>(); } + public String getUser() { + return sUser; + } + public synchronized Connection newConnection() throws SQLException { Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@" + sUrl, sUser, sPass); connectionList.add(conn);