GeezerVison is showing github.com — New public interface for ReporterFactory and CoreReporters · utPLSQL/utPLSQL-java-api@fe22a70
File treeExpand file treeCollapse file tree Open diff view settings main/java/org/utplsql/api test/java/org/utplsql/api
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: src/main/java/org/utplsql/api/TestRunner.java +17-3Lines changed: 17 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 13 | 13 | import java.sql.CallableStatement; | 14 | 14 | import java.sql.Connection; | 15 | 15 | import java.sql.SQLException; | | 16 | +import java.util.ArrayList; | 16 | 17 | import java.util.List; | 17 | 18 |
| 18 | 19 | /** | @@ -25,7 +26,8 @@ public class TestRunner { | 25 | 26 |
| 26 | 27 | private TestRunnerOptions options = new TestRunnerOptions(); | 27 | 28 | private CompatibilityProxy compatibilityProxy; | 28 | | - private ReporterFactory reporterFactory = new ReporterFactory(); | | 29 | + private ReporterFactory reporterFactory; | | 30 | + private List<String> reporterNames = new ArrayList<>(); | 29 | 31 |
| 30 | 32 | public TestRunner addPath(String path) { | 31 | 33 | options.pathList.add(path); | @@ -43,7 +45,10 @@ public TestRunner addReporter(Reporter reporter) { | 43 | 45 | } | 44 | 46 |
| 45 | 47 | public TestRunner addReporter( String reporterName ) { | 46 | | - options.reporterList.add(reporterFactory.createReporter(reporterName)); | | 48 | + if ( reporterFactory != null ) | | 49 | + options.reporterList.add(reporterFactory.createReporter(reporterName)); | | 50 | + else | | 51 | + reporterNames.add(reporterName); | 47 | 52 | return this; | 48 | 53 | } | 49 | 54 |
| @@ -108,11 +113,20 @@ public TestRunner setReporterFactory( ReporterFactory reporterFactory ) { | 108 | 113 | return this; | 109 | 114 | } | 110 | 115 |
| | 116 | + private void delayedAddReporters() { | | 117 | + if ( reporterFactory != null ) | | 118 | + reporterNames.stream().forEach( this::addReporter ); | | 119 | + else | | 120 | + throw new IllegalStateException("ReporterFactory must be set to add delayed Reporters!"); | | 121 | + } | | 122 | + | 111 | 123 | public void run(Connection conn) throws SomeTestsFailedException, SQLException, DatabaseNotCompatibleException, UtPLSQLNotInstalledException { | 112 | 124 |
| 113 | 125 | compatibilityProxy = new CompatibilityProxy(conn, options.skipCompatibilityCheck); | 114 | 126 | if ( reporterFactory == null ) | 115 | | - reporterFactory = new ReporterFactory(); | | 127 | + reporterFactory = ReporterFactory.createDefault(compatibilityProxy); | | 128 | + | | 129 | + delayedAddReporters(); | 116 | 130 |
| 117 | 131 | // First of all check version compatibility | 118 | 132 | compatibilityProxy.failOnNotCompatible(); | |
Collapse file Copy file name to clipboard +39-25Lines changed: 39 additions & 25 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | package org.utplsql.api.reporter; | 2 | 2 |
| 3 | | -import java.util.function.BiFunction; | | 3 | +import org.utplsql.api.Version; | | 4 | +import org.utplsql.api.exception.InvalidVersionException; | 4 | 5 |
| 5 | | -/** This enum defines default reporters, added and maintained by the utPLSQL team, and their (default) factory method | | 6 | +/** This enum defines default reporters, added and maintained by the utPLSQL team, | | 7 | + * and information since (and maybe until) which version they exist | 6 | 8 | * | 7 | 9 | * @author pesse | 8 | 10 | */ | 9 | 11 | public enum CoreReporters { | 10 | 12 |
| 11 | | - UT_COVERAGE_HTML_REPORTER(CoverageHTMLReporter::new, "Generates a HTML coverage report with summary and line by line information on code coverage.\n" + | 12 | | - "Based on open-source simplecov-html coverage reporter for Ruby.\n" + | 13 | | - "Includes source code in the report."), | 14 | | - UT_DOCUMENTATION_REPORTER(DocumentationReporter::new, "A textual pretty-print of unit test results (usually use for console output)"), | 15 | | - UT_TEAMCITY_REPORTER(DefaultReporter::new, "For reporting live progress of test execution with Teamcity CI."), | 16 | | - UT_XUNIT_REPORTER(DefaultReporter::new, "Used for reporting test results with CI servers like Jenkins/Hudson/Teamcity."), | 17 | | - UT_COVERALLS_REPORTER(DefaultReporter::new, "Generates a JSON coverage report providing information on code coverage with line numbers.\n" + | 18 | | - "Designed for [Coveralls](https://coveralls.io/)."), | 19 | | - UT_COVERAGE_SONAR_REPORTER(DefaultReporter::new, "Generates a JSON coverage report providing information on code coverage with line numbers.\n" + | 20 | | - "Designed for [SonarQube](https://about.sonarqube.com/) to report coverage."), | 21 | | - UT_SONAR_TEST_REPORTER(DefaultReporter::new, "Generates a JSON report providing detailed information on test execution.\n" + | 22 | | - "Designed for [SonarQube](https://about.sonarqube.com/) to report test execution."); | 23 | | - | 24 | | - private BiFunction<String, Object[], ? extends Reporter> factoryMethod; | 25 | | - private String description; | 26 | | - | 27 | | - CoreReporters(BiFunction<String, Object[], ? extends Reporter> factoryMethod, String description ) { | 28 | | - this.factoryMethod = factoryMethod; | 29 | | - this.description = description; | | 13 | + UT_COVERAGE_HTML_REPORTER(new Version("3.0.0"), null), | | 14 | + UT_DOCUMENTATION_REPORTER(new Version("3.0.0"), null), | | 15 | + UT_TEAMCITY_REPORTER(new Version("3.0.0"), null), | | 16 | + UT_XUNIT_REPORTER(new Version("3.0.0"), null), | | 17 | + UT_COVERALLS_REPORTER(new Version("3.0.0"), null), | | 18 | + UT_COVERAGE_SONAR_REPORTER(new Version("3.0.0"), null), | | 19 | + UT_SONAR_TEST_REPORTER(new Version("3.0.0"), null), | | 20 | + UT_COVERAGE_COBERTURA_REPORTER(new Version("3.1.0"), null); | | 21 | + | | 22 | + private Version since; | | 23 | + private Version until; | | 24 | + | | 25 | + CoreReporters(Version since, Version until ) { | | 26 | + this.since = since; | | 27 | + this.until = until; | 30 | 28 | } | 31 | 29 |
| 32 | | - public BiFunction<String, Object[], ? extends Reporter> getFactoryMethod() { | 33 | | - return factoryMethod; | | 30 | + public Version getSince() { | | 31 | + return since; | 34 | 32 | } | 35 | 33 |
| 36 | | - public String getDescription() { | 37 | | - return description; | | 34 | + public Version getUntil() { | | 35 | + return until; | | 36 | + } | | 37 | + | | 38 | + /** Checks whether a CoreReporter is valid for the given databaseVersion | | 39 | + * | | 40 | + * @param databaseVersion Database-Version | | 41 | + * @return true or false | | 42 | + */ | | 43 | + public boolean isAvailableFor( Version databaseVersion ) { | | 44 | + try { | | 45 | + if ((since == null || databaseVersion.isGreaterOrEqualThan(since)) | | 46 | + && (until == null || databaseVersion.isLessOrEqualThan(until))) | | 47 | + return true; | | 48 | + } | | 49 | + catch ( InvalidVersionException e ) { } | | 50 | + | | 51 | + return false; | 38 | 52 | } | 39 | 53 | } |
Collapse file Copy file name to clipboardExpand all lines: src/main/java/org/utplsql/api/reporter/DefaultReporter.java -8Lines changed: 0 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | package org.utplsql.api.reporter; | 2 | 2 |
| 3 | | -import oracle.jdbc.OracleCallableStatement; | 4 | 3 | 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; | 10 | 4 | import org.utplsql.api.compatibility.CompatibilityProxy; | 11 | | -import org.utplsql.api.outputBuffer.OutputBuffer; | 12 | 5 |
| 13 | | -import java.sql.Connection; | 14 | 6 | import java.sql.SQLException; | 15 | 7 |
| 16 | 8 | /** This is a basic Reporter implementation, using ORAData interface | |
Collapse file Copy file name to clipboard +19Lines changed: 19 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +package org.utplsql.api.reporter; | | 2 | + | | 3 | +import org.utplsql.api.compatibility.CompatibilityProxy; | | 4 | + | | 5 | +/** Helper-class which registers default ReporterFactoryMethods based on the given databaseVersion | | 6 | + * | | 7 | + * @author pesse | | 8 | + */ | | 9 | +class DefaultReporterFactoryMethodRegistrator { | | 10 | + | | 11 | + public static void registerDefaultReporters(ReporterFactory reporterFactory, CompatibilityProxy compatibilityProxy ) { | | 12 | + | | 13 | + // At the moment we don't have version-specific reporters which need a special MethodFactory | | 14 | + reporterFactory.registerReporterFactoryMethod(CoreReporters.UT_DOCUMENTATION_REPORTER.name(), DocumentationReporter::new, "Provides additional properties lvl and failed"); | | 15 | + reporterFactory.registerReporterFactoryMethod(CoreReporters.UT_COVERAGE_HTML_REPORTER.name(), CoverageHTMLReporter::new, "Provides additional properties projectName and assetPath"); | | 16 | + } | | 17 | + | | 18 | + | | 19 | +} |
Collapse file Copy file name to clipboardExpand all lines: src/main/java/org/utplsql/api/reporter/ReporterFactory.java +24-8Lines changed: 24 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 4 | 4 | import oracle.sql.ORAData; | 5 | 5 | import oracle.sql.ORADataFactory; | 6 | 6 | import oracle.sql.STRUCT; | | 7 | +import org.utplsql.api.compatibility.CompatibilityProxy; | 7 | 8 |
| | 9 | +import java.sql.Connection; | 8 | 10 | import java.sql.SQLException; | 9 | 11 | import java.util.Arrays; | 10 | 12 | import java.util.HashMap; | @@ -29,15 +31,8 @@ public ReporterInfo(BiFunction<String, Object[], ? extends Reporter> factoryMeth | 29 | 31 |
| 30 | 32 | private Map<String, ReporterInfo> reportFactoryMethodMap = new HashMap<>(); | 31 | 33 |
| 32 | | - public ReporterFactory() { | 33 | | - registerDefaultReporters(); | 34 | | - } | | 34 | + ReporterFactory() { | 35 | 35 |
| 36 | | - /** Registers the default reporters, provided with utPLSQL core | 37 | | - */ | 38 | | - private void registerDefaultReporters() { | 39 | | - Arrays.stream(CoreReporters.values()) | 40 | | - .forEach(r -> registerReporterFactoryMethod(r.name(), r.getFactoryMethod(), r.getDescription())); | 41 | 36 | } | 42 | 37 |
| 43 | 38 | /** Registers a creation method for a specified reporter name. Overrides eventually existing creation method | @@ -126,4 +121,25 @@ public ORAData create(Datum d, int sqlType) throws SQLException { | 126 | 121 |
| 127 | 122 | return null; | 128 | 123 | } | | 124 | + | | 125 | + /** Returns a new instance of an empty ReporterFactory with no registered ReporterFactoryMethods | | 126 | + * Normally, you should be using createDefault-method instead. | | 127 | + * | | 128 | + * @return a new ReporterFactory instance | | 129 | + */ | | 130 | + public static ReporterFactory createEmpty() { | | 131 | + return new ReporterFactory(); | | 132 | + } | | 133 | + | | 134 | + /** Returns a new instance of a ReporterFactory with the default ReporterFactoryMethods registered. | | 135 | + * This can depend upon the version of utPLSQL, therefore you have to provide a CompatibilityProxy | | 136 | + * | | 137 | + * @param proxy Compatibility proxy | | 138 | + * @return a new ReporterFactory instance with all default ReporterFactoryMethods registered | | 139 | + */ | | 140 | + public static ReporterFactory createDefault(CompatibilityProxy proxy) { | | 141 | + ReporterFactory reporterFactory = new ReporterFactory(); | | 142 | + DefaultReporterFactoryMethodRegistrator.registerDefaultReporters(reporterFactory, proxy); | | 143 | + return reporterFactory; | | 144 | + } | 129 | 145 | } |
Collapse file Copy file name to clipboardExpand all lines: src/main/java/org/utplsql/api/reporter/core/CoreReporterProvider.java -5Lines changed: 0 additions & 5 deletions Collapse file Copy file name to clipboardExpand all lines: src/test/java/org/utplsql/api/RegisterCustomReporterTest.java +4-2Lines changed: 4 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | package org.utplsql.api; | 2 | 2 |
| 3 | 3 | import org.junit.jupiter.api.Test; | | 4 | +import org.utplsql.api.compatibility.CompatibilityProxy; | 4 | 5 | import org.utplsql.api.reporter.DefaultReporter; | 5 | 6 | import org.utplsql.api.reporter.Reporter; | 6 | 7 | import org.utplsql.api.reporter.ReporterFactory; | @@ -12,7 +13,7 @@ public class RegisterCustomReporterTest { | 12 | 13 | @Test | 13 | 14 | public void addCustomReporter() { | 14 | 15 |
| 15 | | - ReporterFactory reporterFactory = new ReporterFactory(); | | 16 | + ReporterFactory reporterFactory = ReporterFactory.createEmpty(); | 16 | 17 | reporterFactory.registerReporterFactoryMethod("ut_custom_reporter", | 17 | 18 | (type, attr) -> new DefaultReporter("UT_EXISTING_REPORTER", attr), | 18 | 19 | "My custom Reporter"); | @@ -24,9 +25,10 @@ public void addCustomReporter() { | 24 | 25 |
| 25 | 26 | @Test | 26 | 27 | public void createCustomDefaultReporter() { | 27 | | - ReporterFactory reporterFactory = new ReporterFactory(); | | 28 | + ReporterFactory reporterFactory = ReporterFactory.createEmpty(); | 28 | 29 | Reporter r = reporterFactory.createReporter("ut_custom_reporter"); | 29 | 30 |
| 30 | 31 | assertEquals(r.getTypeName(), "UT_CUSTOM_REPORTER"); | 31 | 32 | } | | 33 | + | 32 | 34 | } |
Collapse file Copy file name to clipboard +26Lines changed: 26 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +package org.utplsql.api; | | 2 | + | | 3 | +import org.junit.jupiter.api.Test; | | 4 | +import org.utplsql.api.compatibility.CompatibilityProxy; | | 5 | +import org.utplsql.api.reporter.CoreReporters; | | 6 | +import org.utplsql.api.reporter.CoverageHTMLReporter; | | 7 | +import org.utplsql.api.reporter.DocumentationReporter; | | 8 | +import org.utplsql.api.reporter.ReporterFactory; | | 9 | + | | 10 | +import java.sql.SQLException; | | 11 | + | | 12 | +import static org.junit.jupiter.api.Assertions.assertTrue; | | 13 | + | | 14 | +public class ReporterFactoryIT extends AbstractDatabaseTest { | | 15 | + | | 16 | + | | 17 | + @Test | | 18 | + public void createDefaultReporterFactoryMethod() throws SQLException { | | 19 | + CompatibilityProxy proxy = new CompatibilityProxy(getConnection()); | | 20 | + | | 21 | + ReporterFactory reporterFactory = ReporterFactory.createDefault(proxy); | | 22 | + | | 23 | + assertTrue( reporterFactory.createReporter(CoreReporters.UT_DOCUMENTATION_REPORTER.name()) instanceof DocumentationReporter ); | | 24 | + assertTrue( reporterFactory.createReporter(CoreReporters.UT_COVERAGE_HTML_REPORTER.name()) instanceof CoverageHTMLReporter); | | 25 | + } | | 26 | +} |
Collapse file Copy file name to clipboardExpand all lines: src/test/java/org/utplsql/api/ReporterNameTest.java -22Lines changed: 0 additions & 22 deletions
|