From b8fa7f59ad80f946c4e9dc5bd40863476020f77f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacek=20G=C4=99bal?= Date: Mon, 20 Nov 2017 17:39:04 +0000 Subject: [PATCH 001/228] Update pom.xml --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 921bb7c..2dc4ed7 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.utplsql cli - 3.0.4-SNAPSHOT + 3.0.5-SNAPSHOT jar cli From e8293c4344abe9f12892817ec4253a46db5569b7 Mon Sep 17 00:00:00 2001 From: Eduard Vlasov Date: Thu, 21 Dec 2017 13:19:17 +0500 Subject: [PATCH 002/228] Added include and exclude params for coverage reports (issue #6) --- src/main/java/org/utplsql/cli/RunCommand.java | 48 +++++++++++++++++-- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/utplsql/cli/RunCommand.java b/src/main/java/org/utplsql/cli/RunCommand.java index 690a453..525a334 100644 --- a/src/main/java/org/utplsql/cli/RunCommand.java +++ b/src/main/java/org/utplsql/cli/RunCommand.java @@ -18,6 +18,7 @@ import java.sql.Connection; import java.sql.SQLException; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -83,6 +84,21 @@ public class RunCommand { "most actual. Use this if you use CLI with a development version of utPLSQL-framework") private boolean skipCompatibilityCheck = false; + @Parameter( + names = {"-include"}, + description = "Comma-separated object list to include in the coverage report. " + + "Format: [schema.]package[,[schema.]package ...]. See coverage reporting options in framework documentation" + ) + private String includeObjects = null; + + @Parameter( + names = {"-exclude"}, + description = "Comma-separated object list to exclude from the coverage report. " + + "Format: [schema.]package[,[schema.]package ...]. See coverage reporting options in framework documentation" + ) + private String excludeObjects = null; + + private CompatibilityProxy compatibilityProxy; public ConnectionInfo getConnectionInfo() { @@ -112,6 +128,24 @@ public int run() throws Exception { sourceMappingOptions[0] = getFileMapperOptionsByParamListItem(this.sourcePathParams, baseDir); testMappingOptions[0] = getFileMapperOptionsByParamListItem(this.testPathParams, baseDir); + ArrayList includeObjectsList; + ArrayList excludeObjectsList; + + if (includeObjects != null && !includeObjects.isEmpty()) { + includeObjectsList = new ArrayList<>(Arrays.asList(includeObjects.split(","))); + } else { + includeObjectsList = new ArrayList<>(); + } + + if (excludeObjects != null && !excludeObjects.isEmpty()) { + excludeObjectsList = new ArrayList<>(Arrays.asList(excludeObjects.split(","))); + } else { + excludeObjectsList = new ArrayList<>(); + } + + final ArrayList finalIncludeObjectsList = includeObjectsList; + final ArrayList finalExcludeObjectsList = excludeObjectsList; + // Do the reporters initialization, so we can use the id to run and gather results. try (Connection conn = ci.getConnection()) { @@ -143,15 +177,23 @@ public int run() throws Exception { // Run tests. executorService.submit(() -> { try (Connection conn = ci.getConnection()) { - new TestRunner() + TestRunner testRunner = new TestRunner() .addPathList(testPaths) .addReporterList(reporterList) .sourceMappingOptions(sourceMappingOptions[0]) .testMappingOptions(testMappingOptions[0]) .colorConsole(this.colorConsole) .failOnErrors(true) - .skipCompatibilityCheck(skipCompatibilityCheck) - .run(conn); + .skipCompatibilityCheck(skipCompatibilityCheck); + + for (String includeObject: finalIncludeObjectsList){ + testRunner.includeObject(includeObject); + } + for (String excludeObject: finalExcludeObjectsList){ + testRunner.excludeObject(excludeObject); + } + + testRunner.run(conn); } catch (SomeTestsFailedException e) { returnCode[0] = this.failureExitCode; } catch (SQLException e) { From daf939bdd1f67db72395665226a72d626d85821b Mon Sep 17 00:00:00 2001 From: Eduard Vlasov Date: Thu, 21 Dec 2017 13:50:54 +0500 Subject: [PATCH 003/228] Fixed readme --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index fd88eed..9c2a288 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,12 @@ For example CLI-3.0.4 is compatible with database framework 3.0.0-3.0.4 but not --failure-exit-code - Override the exit code on failure, defaults to 1. You can set it to 0 to always exit with a success status. -scc - If specified, skips the compatibility-check with the version of the database framework. If you skip compatibility-check, CLI will expect the most actual framework version +-include=package_list - Comma-separated object list to include in the coverage report. + Format: [schema.]package[,[schema.]package ...]. + See coverage reporting options in framework documentation. +-exclude=package_list - Comma-separated object list to exclude from the coverage report. + Format: [schema.]package[,[schema.]package ...]. + See coverage reporting options in framework documentation. ``` Parameters -f, -o, -s are correlated. That is parameters -o and -s are controlling outputs for reporter specified by the preceding -f parameter. From b7f99e2a0df25ee4543d6c0920ddfddd4cf09ba9 Mon Sep 17 00:00:00 2001 From: pesse Date: Sun, 31 Dec 2017 14:40:08 +0100 Subject: [PATCH 004/228] Added system-test for code coverage creation Also separated unit- and system-tests for RunCommand and refactored RunCommand a bit to use the fluent api provided --- pom.xml | 2 +- src/main/java/org/utplsql/cli/RunCommand.java | 11 +-- .../RunCommandCoverageReporterSystemTest.java | 91 +++++++++++++++++++ .../org/utplsql/cli/RunCommandSystemTest.java | 40 ++++++++ .../java/org/utplsql/cli/RunCommandTest.java | 56 +----------- .../org/utplsql/cli/RunCommandTestHelper.java | 30 ++++++ 6 files changed, 170 insertions(+), 60 deletions(-) create mode 100644 src/test/java/org/utplsql/cli/RunCommandCoverageReporterSystemTest.java create mode 100644 src/test/java/org/utplsql/cli/RunCommandSystemTest.java create mode 100644 src/test/java/org/utplsql/cli/RunCommandTestHelper.java diff --git a/pom.xml b/pom.xml index 2f5dd67..107d0aa 100644 --- a/pom.xml +++ b/pom.xml @@ -20,7 +20,7 @@ org.utplsql java-api - 3.0.4 + 3.0.4-SNAPSHOT compile diff --git a/src/main/java/org/utplsql/cli/RunCommand.java b/src/main/java/org/utplsql/cli/RunCommand.java index 525a334..4f41d02 100644 --- a/src/main/java/org/utplsql/cli/RunCommand.java +++ b/src/main/java/org/utplsql/cli/RunCommand.java @@ -184,14 +184,9 @@ public int run() throws Exception { .testMappingOptions(testMappingOptions[0]) .colorConsole(this.colorConsole) .failOnErrors(true) - .skipCompatibilityCheck(skipCompatibilityCheck); - - for (String includeObject: finalIncludeObjectsList){ - testRunner.includeObject(includeObject); - } - for (String excludeObject: finalExcludeObjectsList){ - testRunner.excludeObject(excludeObject); - } + .skipCompatibilityCheck(skipCompatibilityCheck) + .includeObjects(finalIncludeObjectsList) + .excludeObjects(finalExcludeObjectsList); testRunner.run(conn); } catch (SomeTestsFailedException e) { diff --git a/src/test/java/org/utplsql/cli/RunCommandCoverageReporterSystemTest.java b/src/test/java/org/utplsql/cli/RunCommandCoverageReporterSystemTest.java new file mode 100644 index 0000000..4ad03ca --- /dev/null +++ b/src/test/java/org/utplsql/cli/RunCommandCoverageReporterSystemTest.java @@ -0,0 +1,91 @@ +package org.utplsql.cli; + +import com.sun.org.apache.xerces.internal.impl.xpath.regex.Match; +import org.junit.Assert; +import org.junit.Test; +import org.utplsql.api.compatibility.OptionalFeatures; + +import java.io.File; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Scanner; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * System tests for Code Coverage Reporter + * + * @author pesse + */ +public class RunCommandCoverageReporterSystemTest { + + private static final Pattern REGEX_COVERAGE_TITLE = Pattern.compile("([a-zA-Z0-9\\._]+)<\\/a>"); + + private String getTempCoverageFileName(int counter) { + + return "tmpCoverage_" + String.valueOf(System.currentTimeMillis()) + "_" + String.valueOf(counter) + ".html"; + } + + /** + * Returns a random filename which does not yet exist on the local path + * + * @return + */ + private Path getTempCoverageFilePath() { + int i = 1; + Path p = Paths.get(getTempCoverageFileName(i)); + + while (Files.exists(p) && i < 100) + p = Paths.get(getTempCoverageFileName(i++)); + + if (i >= 100) + throw new IllegalStateException("Could not get temporary file for coverage output"); + + return p; + } + + /** Checks Coverage HTML Output if a given packageName is listed + * + * @param content + * @param packageName + * @return + */ + private boolean hasCoverageListed( String content, String packageName) { + Matcher m = REGEX_COVERAGE_TITLE.matcher(content); + + while ( m.find() ) { + if ( packageName.equals(m.group(1)) ) + return true; + } + + return false; + } + + @Test + public void run_CodeCoverageWithIncludeAndExclude() { + + try { + Path coveragePath = getTempCoverageFilePath(); + + RunCommand runCmd = RunCommandTestHelper.createRunCommand(RunCommandTestHelper.getConnectionString(), + "-f=ut_coverage_html_reporter", "-o=" + coveragePath, "-s", "-exclude=app.award_bonus,app.betwnstr"); + + try { + int result = runCmd.run(); + + String content = new Scanner(coveragePath).useDelimiter("\\Z").next(); + + Assert.assertEquals(true, hasCoverageListed(content, "app.remove_rooms_by_name")); + Assert.assertEquals(false, hasCoverageListed(content, "app.award_bonus")); + Assert.assertEquals(false, hasCoverageListed(content, "app.betwnstr")); + + } finally { + Files.delete(coveragePath); + } + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + + } +} diff --git a/src/test/java/org/utplsql/cli/RunCommandSystemTest.java b/src/test/java/org/utplsql/cli/RunCommandSystemTest.java new file mode 100644 index 0000000..19e5488 --- /dev/null +++ b/src/test/java/org/utplsql/cli/RunCommandSystemTest.java @@ -0,0 +1,40 @@ +package org.utplsql.cli; + +import com.beust.jcommander.JCommander; +import org.junit.Assert; +import org.junit.Test; +import org.utplsql.api.CustomTypes; +import org.utplsql.api.compatibility.OptionalFeatures; + +import java.util.List; + +/** + * System tests for run command. + */ +public class RunCommandSystemTest { + + + @Test + public void run_Default() { + RunCommand runCmd = RunCommandTestHelper.createRunCommand(RunCommandTestHelper.getConnectionString(), + "-f=ut_documentation_reporter", + "-c", + "--failure-exit-code=2"); + + try { + int result = runCmd.run(); + + // Only expect failure-exit-code to work on several framework versions + if (OptionalFeatures.FAIL_ON_ERROR.isAvailableFor(runCmd.getDatabaseVersion()) ) + Assert.assertEquals(2, result); + else + Assert.assertEquals(0, result); + } + catch ( Exception e ) { + Assert.fail(e.getMessage()); + } + } + + + +} diff --git a/src/test/java/org/utplsql/cli/RunCommandTest.java b/src/test/java/org/utplsql/cli/RunCommandTest.java index ff72b13..f8248f3 100644 --- a/src/test/java/org/utplsql/cli/RunCommandTest.java +++ b/src/test/java/org/utplsql/cli/RunCommandTest.java @@ -13,34 +13,9 @@ */ public class RunCommandTest { - private static String sUrl; - private static String sUser; - private static String sPass; - - static { - sUrl = System.getenv("DB_URL") != null ? System.getenv("DB_URL") : "192.168.99.100:1521:XE"; - sUser = System.getenv("DB_USER") != null ? System.getenv("DB_USER") : "app"; - sPass = System.getenv("DB_PASS") != null ? System.getenv("DB_PASS") : "app"; - } - - private RunCommand createRunCommand(String... args) { - RunCommand runCmd = new RunCommand(); - - JCommander.newBuilder() - .addObject(runCmd) - .args(args) - .build(); - - return runCmd; - } - - private String getConnectionString() { - return sUser + "/" + sPass + "@" + sUrl; - } - @Test public void reporterOptions_Default() { - RunCommand runCmd = createRunCommand(getConnectionString()); + RunCommand runCmd = RunCommandTestHelper.createRunCommand(RunCommandTestHelper.getConnectionString()); List reporterOptionsList = runCmd.getReporterOptionsList(); @@ -53,7 +28,7 @@ public void reporterOptions_Default() { @Test public void reporterOptions_OneReporter() { - RunCommand runCmd = createRunCommand(getConnectionString(), "-f=ut_documentation_reporter", "-o=output.txt"); + RunCommand runCmd = RunCommandTestHelper.createRunCommand(RunCommandTestHelper.getConnectionString(), "-f=ut_documentation_reporter", "-o=output.txt"); List reporterOptionsList = runCmd.getReporterOptionsList(); @@ -66,7 +41,7 @@ public void reporterOptions_OneReporter() { @Test public void reporterOptions_OneReporterForceScreen() { - RunCommand runCmd = createRunCommand(getConnectionString(), "-f=ut_documentation_reporter", "-o=output.txt", "-s"); + RunCommand runCmd = RunCommandTestHelper.createRunCommand(RunCommandTestHelper.getConnectionString(), "-f=ut_documentation_reporter", "-o=output.txt", "-s"); List reporterOptionsList = runCmd.getReporterOptionsList(); @@ -79,7 +54,7 @@ public void reporterOptions_OneReporterForceScreen() { @Test public void reporterOptions_OneReporterForceScreenInverse() { - RunCommand runCmd = createRunCommand(getConnectionString(), "-f=ut_documentation_reporter", "-s", "-o=output.txt"); + RunCommand runCmd = RunCommandTestHelper.createRunCommand(RunCommandTestHelper.getConnectionString(), "-f=ut_documentation_reporter", "-s", "-o=output.txt"); List reporterOptionsList = runCmd.getReporterOptionsList(); @@ -92,7 +67,7 @@ public void reporterOptions_OneReporterForceScreenInverse() { @Test public void reporterOptions_TwoReporters() { - RunCommand runCmd = createRunCommand(getConnectionString(), + RunCommand runCmd = RunCommandTestHelper.createRunCommand(RunCommandTestHelper.getConnectionString(), "-f=ut_documentation_reporter", "-f=ut_coverage_html_reporter", "-o=coverage.html", "-s"); @@ -111,25 +86,4 @@ public void reporterOptions_TwoReporters() { Assert.assertTrue(reporterOptions2.outputToScreen()); } - @Test - public void run_Default() { - RunCommand runCmd = createRunCommand(getConnectionString(), - "-f=ut_documentation_reporter", - "-c", - "--failure-exit-code=2"); - - try { - int result = runCmd.run(); - - // Only expect failure-exit-code to work on several framework versions - if (OptionalFeatures.FAIL_ON_ERROR.isAvailableFor(runCmd.getDatabaseVersion()) ) - Assert.assertEquals(2, result); - else - Assert.assertEquals(0, result); - } - catch ( Exception e ) { - Assert.fail(e.getMessage()); - } - } - } diff --git a/src/test/java/org/utplsql/cli/RunCommandTestHelper.java b/src/test/java/org/utplsql/cli/RunCommandTestHelper.java new file mode 100644 index 0000000..9f9cf4f --- /dev/null +++ b/src/test/java/org/utplsql/cli/RunCommandTestHelper.java @@ -0,0 +1,30 @@ +package org.utplsql.cli; + +import com.beust.jcommander.JCommander; + +class RunCommandTestHelper { + private static String sUrl; + private static String sUser; + private static String sPass; + + static { + sUrl = System.getenv("DB_URL") != null ? System.getenv("DB_URL") : "192.168.99.100:1521:XE"; + sUser = System.getenv("DB_USER") != null ? System.getenv("DB_USER") : "app"; + sPass = System.getenv("DB_PASS") != null ? System.getenv("DB_PASS") : "app"; + } + + static RunCommand createRunCommand(String... args) { + RunCommand runCmd = new RunCommand(); + + JCommander.newBuilder() + .addObject(runCmd) + .args(args) + .build(); + + return runCmd; + } + + static String getConnectionString() { + return sUser + "/" + sPass + "@" + sUrl; + } +} From ba4b5b9b10e34522156d26b51e446827606490b9 Mon Sep 17 00:00:00 2001 From: pesse Date: Mon, 15 Jan 2018 11:48:52 +0100 Subject: [PATCH 005/228] Added locale initialization from environment variables LC_ALL or LANG Fixes https://github.com/utPLSQL/utPLSQL-cli/issues/56 --- src/main/java/org/utplsql/cli/Cli.java | 9 ++- .../org/utplsql/cli/LocaleInitializer.java | 58 +++++++++++++++++++ 2 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 src/main/java/org/utplsql/cli/LocaleInitializer.java diff --git a/src/main/java/org/utplsql/cli/Cli.java b/src/main/java/org/utplsql/cli/Cli.java index bdfbac3..f2db442 100644 --- a/src/main/java/org/utplsql/cli/Cli.java +++ b/src/main/java/org/utplsql/cli/Cli.java @@ -9,12 +9,15 @@ public class Cli { - public static final int DEFAULT_ERROR_CODE = 1; + static final int DEFAULT_ERROR_CODE = 1; - public static final String HELP_CMD = "-h"; - public static final String RUN_CMD = "run"; + static final String HELP_CMD = "-h"; + private static final String RUN_CMD = "run"; public static void main(String[] args) { + + LocaleInitializer.initLocale(); + JCommander jc = new JCommander(); // jc.addCommand(HELP_CMD, new HelpCommand()); RunCommand runCmd = new RunCommand(); diff --git a/src/main/java/org/utplsql/cli/LocaleInitializer.java b/src/main/java/org/utplsql/cli/LocaleInitializer.java new file mode 100644 index 0000000..596207b --- /dev/null +++ b/src/main/java/org/utplsql/cli/LocaleInitializer.java @@ -0,0 +1,58 @@ +package org.utplsql.cli; + +import java.util.Locale; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** This class makes sure the java locale is set according to the environment variables LC_ALL and LANG + * We experienced that, in some cases, the locale was not set as expected, therefore this class implements some clear + * rules: + * 1. If environment variable LC_ALL is set, we try to parse its content and set locale according to its value if valid + * 2. If environment variable LANG is set, we try to parse its content and set locale according to its value if valid + * 3. Otherwise we use default locale + * + * @author pesse + */ +class LocaleInitializer { + + private static final Pattern REGEX_LOCALE = Pattern.compile("^([a-zA-Z]+)[_-]([a-zA-Z]+)"); // We only need the very first part and are pretty forgiving in parsing + + /** Sets the default locale according to the rules described above + * + */ + static void initLocale() { + if ( !setDefaultLocale(System.getenv("LC_ALL"))) + setDefaultLocale(System.getenv("LANG")); + } + + /** Set the default locale from a given string like LC_ALL or LANG environment variable + * + * @param localeString Locale-string from LC_ALL or LANG, e.g "en_US.utf-8" + * @return true if successful, false if not + */ + private static boolean setDefaultLocale( String localeString ) { + if ( localeString == null || localeString.isEmpty() ) + return false; + + try { + Matcher m = REGEX_LOCALE.matcher(localeString); + if (m.find()) { + StringBuilder sb = new StringBuilder(); + sb.append(m.group(1)); + if (m.group(2) != null) + sb.append("-").append(m.group(2)); + + Locale l = new Locale.Builder().setLanguageTag(sb.toString()).build(); + if ( l != null ) { + Locale.setDefault(l); + return true; + } + } + } + catch ( Exception e ) { + System.out.println("Could not get locale from " + localeString); + } + + return false; + } +} From f66087528d5aa215b1f84ad262bab0ae8c71e792 Mon Sep 17 00:00:00 2001 From: pesse Date: Tue, 16 Jan 2018 09:46:13 +0100 Subject: [PATCH 006/228] Update documentation to describe localization --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index 9c2a288..6359748 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,17 @@ You can also download all development versions from [Bintray](https://bintray.co The latest CLI is always compatible with all database frameworks of the same minor version. For example CLI-3.0.4 is compatible with database framework 3.0.0-3.0.4 but not with database framework 2.x and 3.1.x. +## Localization and NLS settings +utPLSQL-cli will use the environment variables "LC_ALL" or "LANG" to change the locale and therefore the NLS settings. +If neither environment variable is available, it will use the JVM default locale. + +Example: to change the NLS-settings to English American, you can do the following: +``` +export LC_ALL=en_US.utf-8 +``` + +The charset-part of LC_ALL is ignored. + ## Usage `utplsql run [-p=(ut_path|ut_paths)] [-f=format [-o=output_file] [-s] ...]` From 2e88a8c21c73977f7554ce20cd79ec1f303b5d17 Mon Sep 17 00:00:00 2001 From: pesse Date: Tue, 16 Jan 2018 14:19:13 +0100 Subject: [PATCH 007/228] Add NLS_LANG to the list of environment variables which can change the cli locale --- README.md | 2 +- .../java/org/utplsql/cli/LocaleInitializer.java | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 6359748..2e07e01 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ The latest CLI is always compatible with all database frameworks of the same min For example CLI-3.0.4 is compatible with database framework 3.0.0-3.0.4 but not with database framework 2.x and 3.1.x. ## Localization and NLS settings -utPLSQL-cli will use the environment variables "LC_ALL" or "LANG" to change the locale and therefore the NLS settings. +utPLSQL-cli will use the environment variables (in that order) "NLS_LANG", "LC_ALL" or "LANG" to change the locale and therefore the NLS settings. If neither environment variable is available, it will use the JVM default locale. Example: to change the NLS-settings to English American, you can do the following: diff --git a/src/main/java/org/utplsql/cli/LocaleInitializer.java b/src/main/java/org/utplsql/cli/LocaleInitializer.java index 596207b..830c742 100644 --- a/src/main/java/org/utplsql/cli/LocaleInitializer.java +++ b/src/main/java/org/utplsql/cli/LocaleInitializer.java @@ -7,9 +7,10 @@ /** This class makes sure the java locale is set according to the environment variables LC_ALL and LANG * We experienced that, in some cases, the locale was not set as expected, therefore this class implements some clear * rules: - * 1. If environment variable LC_ALL is set, we try to parse its content and set locale according to its value if valid - * 2. If environment variable LANG is set, we try to parse its content and set locale according to its value if valid - * 3. Otherwise we use default locale + * 1. If environment variable NLS_LANG is set, we try to parse its content and set locale according to its value if valid + * 2. If environment variable LC_ALL is set, we try to parse its content and set locale according to its value if valid + * 3. If environment variable LANG is set, we try to parse its content and set locale according to its value if valid + * 4. Otherwise we use default locale * * @author pesse */ @@ -21,7 +22,12 @@ class LocaleInitializer { * */ static void initLocale() { - if ( !setDefaultLocale(System.getenv("LC_ALL"))) + + boolean localeChanged = setDefaultLocale(System.getenv("NLS_LANG")); + + if ( !localeChanged ) + localeChanged = setDefaultLocale(System.getenv("LC_ALL")); + if ( !localeChanged ) setDefaultLocale(System.getenv("LANG")); } From 91d2f43c4f9ba05d4a2df9b12c58c7ef9788eef6 Mon Sep 17 00:00:00 2001 From: Samuel Nitsche Date: Tue, 6 Feb 2018 21:52:01 +0100 Subject: [PATCH 008/228] Refactored tests to use Surefire, Failsafe and JUnit 5 --- .travis.yml | 2 +- pom.xml | 87 ++++++++++++++++-- .../java/org/utplsql/cli/FileWalkerTest.java | 9 +- .../cli/RunCommandCoverageReporterIT.java | 86 ++++++++++++++++++ .../RunCommandCoverageReporterSystemTest.java | 91 ------------------- .../java/org/utplsql/cli/RunCommandIT.java | 30 ++++++ .../org/utplsql/cli/RunCommandSystemTest.java | 40 -------- .../java/org/utplsql/cli/RunCommandTest.java | 55 ++++++----- .../org/utplsql/cli/RunCommandTestHelper.java | 7 +- .../utplsql/cli/TestRunCommandChecker.java | 16 ++-- 10 files changed, 239 insertions(+), 184 deletions(-) create mode 100644 src/test/java/org/utplsql/cli/RunCommandCoverageReporterIT.java delete mode 100644 src/test/java/org/utplsql/cli/RunCommandCoverageReporterSystemTest.java create mode 100644 src/test/java/org/utplsql/cli/RunCommandIT.java delete mode 100644 src/test/java/org/utplsql/cli/RunCommandSystemTest.java diff --git a/.travis.yml b/.travis.yml index 5ef4630..8201fd0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,7 +34,7 @@ install: script: - mvn package -DskipTests - - mvn package jar:jar appassembler:assemble + - mvn package verify jar:jar appassembler:assemble before_deploy: - bash .travis/create_release.sh diff --git a/pom.xml b/pom.xml index 052f898..71f6616 100644 --- a/pom.xml +++ b/pom.xml @@ -10,17 +10,19 @@ cli http://maven.apache.org - - UTF-8 - 1.8 - 1.8 - + + UTF-8 + 1.8 + 1.8 + 1.0.3 + 5.0.3 + org.utplsql java-api - 3.0.4-SNAPSHOT + 3.0.5-SNAPSHOT compile @@ -48,11 +50,17 @@ compile - junit - junit - 4.12 + org.junit.jupiter + junit-jupiter-api + ${junit.jupiter.version} test - + + + org.junit.jupiter + junit-jupiter-engine + ${junit.jupiter.version} + test + @@ -75,6 +83,43 @@ + + org.apache.maven.plugins + maven-surefire-plugin + 2.19.1 + + + **/*IT.java + + + + + org.junit.platform + junit-platform-surefire-provider + ${junit.platform.version} + + + + + org.apache.maven.plugins + maven-failsafe-plugin + 2.19.1 + + + + integration-test + verify + + + + + + org.junit.platform + junit-platform-surefire-provider + ${junit.platform.version} + + + @@ -93,4 +138,26 @@ + + + utPLSQL-local + + + + + org.apache.maven.plugins + maven-failsafe-plugin + + + ${dbUrl} + ${dbUser} + ${dbPass} + + + + + + + + diff --git a/src/test/java/org/utplsql/cli/FileWalkerTest.java b/src/test/java/org/utplsql/cli/FileWalkerTest.java index b8e2738..9c00a8d 100644 --- a/src/test/java/org/utplsql/cli/FileWalkerTest.java +++ b/src/test/java/org/utplsql/cli/FileWalkerTest.java @@ -1,12 +1,13 @@ package org.utplsql.cli; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.File; import java.util.Collections; import java.util.List; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; + /** * Created by Vinicius on 18/06/2017. */ @@ -18,7 +19,7 @@ public class FileWalkerTest { public void fileWalker_Relative() { List fileList = new FileWalker().getFileList(BASE_DIR, "source"); Collections.sort(fileList); - Assert.assertArrayEquals(new Object[] { + assertArrayEquals(new Object[] { "source/packages/package.pkb".replace('/', File.separatorChar), "source/packages/package.pks".replace('/', File.separatorChar), "source/script.sql".replace('/', File.separatorChar), @@ -30,7 +31,7 @@ public void fileWalker_Relative() { public void fileWalker_Absolute() { List fileList = new FileWalker().getFileList(BASE_DIR, "source", false); Collections.sort(fileList); - Assert.assertArrayEquals(new Object[] { + assertArrayEquals(new Object[] { BASE_DIR.getAbsolutePath() + "/source/packages/package.pkb".replace('/', File.separatorChar), BASE_DIR.getAbsolutePath() + "/source/packages/package.pks".replace('/', File.separatorChar), BASE_DIR.getAbsolutePath() + "/source/script.sql".replace('/', File.separatorChar), diff --git a/src/test/java/org/utplsql/cli/RunCommandCoverageReporterIT.java b/src/test/java/org/utplsql/cli/RunCommandCoverageReporterIT.java new file mode 100644 index 0000000..c70b6e2 --- /dev/null +++ b/src/test/java/org/utplsql/cli/RunCommandCoverageReporterIT.java @@ -0,0 +1,86 @@ +package org.utplsql.cli; + +import org.junit.jupiter.api.Test; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Scanner; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * System tests for Code Coverage Reporter + * + * @author pesse + */ +public class RunCommandCoverageReporterIT { + + private static final Pattern REGEX_COVERAGE_TITLE = Pattern.compile("([a-zA-Z0-9\\._]+)<\\/a>"); + + private String getTempCoverageFileName(int counter) { + + return "tmpCoverage_" + String.valueOf(System.currentTimeMillis()) + "_" + String.valueOf(counter) + ".html"; + } + + /** + * Returns a random filename which does not yet exist on the local path + * + * @return + */ + private Path getTempCoverageFilePath() { + int i = 1; + Path p = Paths.get(getTempCoverageFileName(i)); + + while (Files.exists(p) && i < 100) + p = Paths.get(getTempCoverageFileName(i++)); + + if (i >= 100) + throw new IllegalStateException("Could not get temporary file for coverage output"); + + return p; + } + + /** + * Checks Coverage HTML Output if a given packageName is listed + * + * @param content + * @param packageName + * @return + */ + private boolean hasCoverageListed(String content, String packageName) { + Matcher m = REGEX_COVERAGE_TITLE.matcher(content); + + while (m.find()) { + if (packageName.equals(m.group(1))) + return true; + } + + return false; + } + + @Test + public void run_CodeCoverageWithIncludeAndExclude() throws Exception { + + Path coveragePath = getTempCoverageFilePath(); + + RunCommand runCmd = RunCommandTestHelper.createRunCommand(RunCommandTestHelper.getConnectionString(), + "-f=ut_coverage_html_reporter", "-o=" + coveragePath, "-s", "-exclude=app.award_bonus,app.betwnstr"); + + try { + int result = runCmd.run(); + + String content = new Scanner(coveragePath).useDelimiter("\\Z").next(); + + assertEquals(true, hasCoverageListed(content, "app.remove_rooms_by_name")); + assertEquals(false, hasCoverageListed(content, "app.award_bonus")); + assertEquals(false, hasCoverageListed(content, "app.betwnstr")); + + } finally { + Files.delete(coveragePath); + } + + } +} diff --git a/src/test/java/org/utplsql/cli/RunCommandCoverageReporterSystemTest.java b/src/test/java/org/utplsql/cli/RunCommandCoverageReporterSystemTest.java deleted file mode 100644 index 4ad03ca..0000000 --- a/src/test/java/org/utplsql/cli/RunCommandCoverageReporterSystemTest.java +++ /dev/null @@ -1,91 +0,0 @@ -package org.utplsql.cli; - -import com.sun.org.apache.xerces.internal.impl.xpath.regex.Match; -import org.junit.Assert; -import org.junit.Test; -import org.utplsql.api.compatibility.OptionalFeatures; - -import java.io.File; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Scanner; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * System tests for Code Coverage Reporter - * - * @author pesse - */ -public class RunCommandCoverageReporterSystemTest { - - private static final Pattern REGEX_COVERAGE_TITLE = Pattern.compile("([a-zA-Z0-9\\._]+)<\\/a>"); - - private String getTempCoverageFileName(int counter) { - - return "tmpCoverage_" + String.valueOf(System.currentTimeMillis()) + "_" + String.valueOf(counter) + ".html"; - } - - /** - * Returns a random filename which does not yet exist on the local path - * - * @return - */ - private Path getTempCoverageFilePath() { - int i = 1; - Path p = Paths.get(getTempCoverageFileName(i)); - - while (Files.exists(p) && i < 100) - p = Paths.get(getTempCoverageFileName(i++)); - - if (i >= 100) - throw new IllegalStateException("Could not get temporary file for coverage output"); - - return p; - } - - /** Checks Coverage HTML Output if a given packageName is listed - * - * @param content - * @param packageName - * @return - */ - private boolean hasCoverageListed( String content, String packageName) { - Matcher m = REGEX_COVERAGE_TITLE.matcher(content); - - while ( m.find() ) { - if ( packageName.equals(m.group(1)) ) - return true; - } - - return false; - } - - @Test - public void run_CodeCoverageWithIncludeAndExclude() { - - try { - Path coveragePath = getTempCoverageFilePath(); - - RunCommand runCmd = RunCommandTestHelper.createRunCommand(RunCommandTestHelper.getConnectionString(), - "-f=ut_coverage_html_reporter", "-o=" + coveragePath, "-s", "-exclude=app.award_bonus,app.betwnstr"); - - try { - int result = runCmd.run(); - - String content = new Scanner(coveragePath).useDelimiter("\\Z").next(); - - Assert.assertEquals(true, hasCoverageListed(content, "app.remove_rooms_by_name")); - Assert.assertEquals(false, hasCoverageListed(content, "app.award_bonus")); - Assert.assertEquals(false, hasCoverageListed(content, "app.betwnstr")); - - } finally { - Files.delete(coveragePath); - } - } catch (Exception e) { - Assert.fail(e.getMessage()); - } - - } -} diff --git a/src/test/java/org/utplsql/cli/RunCommandIT.java b/src/test/java/org/utplsql/cli/RunCommandIT.java new file mode 100644 index 0000000..6aadbda --- /dev/null +++ b/src/test/java/org/utplsql/cli/RunCommandIT.java @@ -0,0 +1,30 @@ +package org.utplsql.cli; + +import org.junit.jupiter.api.Test; +import org.utplsql.api.compatibility.OptionalFeatures; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * System tests for run command. + */ +public class RunCommandIT { + + @Test + public void run_Default() throws Exception { + RunCommand runCmd = RunCommandTestHelper.createRunCommand(RunCommandTestHelper.getConnectionString(), + "-f=ut_documentation_reporter", + "-c", + "--failure-exit-code=2"); + + int result = runCmd.run(); + + // Only expect failure-exit-code to work on several framework versions + if (OptionalFeatures.FAIL_ON_ERROR.isAvailableFor(runCmd.getDatabaseVersion())) + assertEquals(2, result); + else + assertEquals(0, result); + } + + +} diff --git a/src/test/java/org/utplsql/cli/RunCommandSystemTest.java b/src/test/java/org/utplsql/cli/RunCommandSystemTest.java deleted file mode 100644 index 19e5488..0000000 --- a/src/test/java/org/utplsql/cli/RunCommandSystemTest.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.utplsql.cli; - -import com.beust.jcommander.JCommander; -import org.junit.Assert; -import org.junit.Test; -import org.utplsql.api.CustomTypes; -import org.utplsql.api.compatibility.OptionalFeatures; - -import java.util.List; - -/** - * System tests for run command. - */ -public class RunCommandSystemTest { - - - @Test - public void run_Default() { - RunCommand runCmd = RunCommandTestHelper.createRunCommand(RunCommandTestHelper.getConnectionString(), - "-f=ut_documentation_reporter", - "-c", - "--failure-exit-code=2"); - - try { - int result = runCmd.run(); - - // Only expect failure-exit-code to work on several framework versions - if (OptionalFeatures.FAIL_ON_ERROR.isAvailableFor(runCmd.getDatabaseVersion()) ) - Assert.assertEquals(2, result); - else - Assert.assertEquals(0, result); - } - catch ( Exception e ) { - Assert.fail(e.getMessage()); - } - } - - - -} diff --git a/src/test/java/org/utplsql/cli/RunCommandTest.java b/src/test/java/org/utplsql/cli/RunCommandTest.java index f8248f3..775d506 100644 --- a/src/test/java/org/utplsql/cli/RunCommandTest.java +++ b/src/test/java/org/utplsql/cli/RunCommandTest.java @@ -1,13 +1,12 @@ package org.utplsql.cli; -import com.beust.jcommander.JCommander; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.utplsql.api.CustomTypes; -import org.utplsql.api.compatibility.OptionalFeatures; import java.util.List; +import static org.junit.jupiter.api.Assertions.*; + /** * Unit test for run command. */ @@ -20,10 +19,10 @@ public void reporterOptions_Default() { List reporterOptionsList = runCmd.getReporterOptionsList(); ReporterOptions reporterOptions1 = reporterOptionsList.get(0); - Assert.assertEquals(CustomTypes.UT_DOCUMENTATION_REPORTER, reporterOptions1.getReporterName()); - Assert.assertNull(reporterOptions1.getOutputFileName()); - Assert.assertFalse(reporterOptions1.outputToFile()); - Assert.assertTrue(reporterOptions1.outputToScreen()); + assertEquals(CustomTypes.UT_DOCUMENTATION_REPORTER, reporterOptions1.getReporterName()); + assertNull(reporterOptions1.getOutputFileName()); + assertFalse(reporterOptions1.outputToFile()); + assertTrue(reporterOptions1.outputToScreen()); } @Test @@ -33,10 +32,10 @@ public void reporterOptions_OneReporter() { List reporterOptionsList = runCmd.getReporterOptionsList(); ReporterOptions reporterOptions1 = reporterOptionsList.get(0); - Assert.assertEquals(CustomTypes.UT_DOCUMENTATION_REPORTER, reporterOptions1.getReporterName()); - Assert.assertEquals(reporterOptions1.getOutputFileName(), "output.txt"); - Assert.assertTrue(reporterOptions1.outputToFile()); - Assert.assertFalse(reporterOptions1.outputToScreen()); + assertEquals(CustomTypes.UT_DOCUMENTATION_REPORTER, reporterOptions1.getReporterName()); + assertEquals(reporterOptions1.getOutputFileName(), "output.txt"); + assertTrue(reporterOptions1.outputToFile()); + assertFalse(reporterOptions1.outputToScreen()); } @Test @@ -46,10 +45,10 @@ public void reporterOptions_OneReporterForceScreen() { List reporterOptionsList = runCmd.getReporterOptionsList(); ReporterOptions reporterOptions1 = reporterOptionsList.get(0); - Assert.assertEquals(CustomTypes.UT_DOCUMENTATION_REPORTER, reporterOptions1.getReporterName()); - Assert.assertEquals(reporterOptions1.getOutputFileName(), "output.txt"); - Assert.assertTrue(reporterOptions1.outputToFile()); - Assert.assertTrue(reporterOptions1.outputToScreen()); + assertEquals(CustomTypes.UT_DOCUMENTATION_REPORTER, reporterOptions1.getReporterName()); + assertEquals(reporterOptions1.getOutputFileName(), "output.txt"); + assertTrue(reporterOptions1.outputToFile()); + assertTrue(reporterOptions1.outputToScreen()); } @Test @@ -59,10 +58,10 @@ public void reporterOptions_OneReporterForceScreenInverse() { List reporterOptionsList = runCmd.getReporterOptionsList(); ReporterOptions reporterOptions1 = reporterOptionsList.get(0); - Assert.assertEquals(CustomTypes.UT_DOCUMENTATION_REPORTER, reporterOptions1.getReporterName()); - Assert.assertEquals(reporterOptions1.getOutputFileName(), "output.txt"); - Assert.assertTrue(reporterOptions1.outputToFile()); - Assert.assertTrue(reporterOptions1.outputToScreen()); + assertEquals(CustomTypes.UT_DOCUMENTATION_REPORTER, reporterOptions1.getReporterName()); + assertEquals(reporterOptions1.getOutputFileName(), "output.txt"); + assertTrue(reporterOptions1.outputToFile()); + assertTrue(reporterOptions1.outputToScreen()); } @Test @@ -74,16 +73,16 @@ public void reporterOptions_TwoReporters() { List reporterOptionsList = runCmd.getReporterOptionsList(); ReporterOptions reporterOptions1 = reporterOptionsList.get(0); - Assert.assertEquals(CustomTypes.UT_DOCUMENTATION_REPORTER, reporterOptions1.getReporterName()); - Assert.assertNull(reporterOptions1.getOutputFileName()); - Assert.assertFalse(reporterOptions1.outputToFile()); - Assert.assertTrue(reporterOptions1.outputToScreen()); + assertEquals(CustomTypes.UT_DOCUMENTATION_REPORTER, reporterOptions1.getReporterName()); + assertNull(reporterOptions1.getOutputFileName()); + assertFalse(reporterOptions1.outputToFile()); + assertTrue(reporterOptions1.outputToScreen()); ReporterOptions reporterOptions2 = reporterOptionsList.get(1); - Assert.assertEquals(CustomTypes.UT_COVERAGE_HTML_REPORTER, reporterOptions2.getReporterName()); - Assert.assertEquals(reporterOptions2.getOutputFileName(), "coverage.html"); - Assert.assertTrue(reporterOptions2.outputToFile()); - Assert.assertTrue(reporterOptions2.outputToScreen()); + assertEquals(CustomTypes.UT_COVERAGE_HTML_REPORTER, reporterOptions2.getReporterName()); + assertEquals(reporterOptions2.getOutputFileName(), "coverage.html"); + assertTrue(reporterOptions2.outputToFile()); + assertTrue(reporterOptions2.outputToScreen()); } } diff --git a/src/test/java/org/utplsql/cli/RunCommandTestHelper.java b/src/test/java/org/utplsql/cli/RunCommandTestHelper.java index 9f9cf4f..425659a 100644 --- a/src/test/java/org/utplsql/cli/RunCommandTestHelper.java +++ b/src/test/java/org/utplsql/cli/RunCommandTestHelper.java @@ -1,6 +1,7 @@ package org.utplsql.cli; import com.beust.jcommander.JCommander; +import org.utplsql.api.EnvironmentVariableUtil; class RunCommandTestHelper { private static String sUrl; @@ -8,9 +9,9 @@ class RunCommandTestHelper { private static String sPass; static { - sUrl = System.getenv("DB_URL") != null ? System.getenv("DB_URL") : "192.168.99.100:1521:XE"; - sUser = System.getenv("DB_USER") != null ? System.getenv("DB_USER") : "app"; - sPass = System.getenv("DB_PASS") != null ? System.getenv("DB_PASS") : "app"; + sUrl = EnvironmentVariableUtil.getEnvValue("DB_URL", "192.168.99.100:1521:XE"); + sUser = EnvironmentVariableUtil.getEnvValue("DB_USER", "app"); + sPass = EnvironmentVariableUtil.getEnvValue("DB_PASS", "app"); } static RunCommand createRunCommand(String... args) { diff --git a/src/test/java/org/utplsql/cli/TestRunCommandChecker.java b/src/test/java/org/utplsql/cli/TestRunCommandChecker.java index fe807de..fcf2d21 100644 --- a/src/test/java/org/utplsql/cli/TestRunCommandChecker.java +++ b/src/test/java/org/utplsql/cli/TestRunCommandChecker.java @@ -1,19 +1,21 @@ package org.utplsql.cli; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.utplsql.api.Version; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; + public class TestRunCommandChecker { @Test public void getCheckFailOnErrorMessage() { // FailOnError option should work since 3.0.3+ framework - Assert.assertNotNull(RunCommandChecker.getCheckFailOnErrorMessage(2, new Version("3.0.0"))); - Assert.assertNotNull(RunCommandChecker.getCheckFailOnErrorMessage(2, new Version("3.0.1"))); - Assert.assertNotNull(RunCommandChecker.getCheckFailOnErrorMessage(2, new Version("3.0.2"))); - Assert.assertNull(RunCommandChecker.getCheckFailOnErrorMessage(2, new Version("3.0.3"))); - Assert.assertNull(RunCommandChecker.getCheckFailOnErrorMessage(2, new Version("3.0.4"))); + assertNotNull(RunCommandChecker.getCheckFailOnErrorMessage(2, new Version("3.0.0"))); + assertNotNull(RunCommandChecker.getCheckFailOnErrorMessage(2, new Version("3.0.1"))); + assertNotNull(RunCommandChecker.getCheckFailOnErrorMessage(2, new Version("3.0.2"))); + assertNull(RunCommandChecker.getCheckFailOnErrorMessage(2, new Version("3.0.3"))); + assertNull(RunCommandChecker.getCheckFailOnErrorMessage(2, new Version("3.0.4"))); } } From 8f4a7e1b9a0e7b6ea98576ce9798b30209d3ce68 Mon Sep 17 00:00:00 2001 From: Samuel Nitsche Date: Wed, 7 Feb 2018 09:59:03 +0100 Subject: [PATCH 009/228] First simple implementation of copying necessary assets Needs lots of refactoring --- src/main/java/org/utplsql/cli/RunCommand.java | 11 +++++++-- .../cli/RunCommandCoverageReporterIT.java | 24 +++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/utplsql/cli/RunCommand.java b/src/main/java/org/utplsql/cli/RunCommand.java index 4f41d02..fbf5e3c 100644 --- a/src/main/java/org/utplsql/cli/RunCommand.java +++ b/src/main/java/org/utplsql/cli/RunCommand.java @@ -4,9 +4,8 @@ import com.beust.jcommander.Parameters; import org.utplsql.api.*; import org.utplsql.api.compatibility.CompatibilityProxy; -import org.utplsql.api.compatibility.OptionalFeatures; -import org.utplsql.api.exception.DatabaseNotCompatibleException; import org.utplsql.api.exception.SomeTestsFailedException; +import org.utplsql.api.reporter.CoverageHTMLReporter; import org.utplsql.api.reporter.Reporter; import org.utplsql.api.reporter.ReporterFactory; import org.utplsql.cli.exception.DatabaseConnectionFailed; @@ -15,6 +14,7 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.PrintStream; +import java.nio.file.Paths; import java.sql.Connection; import java.sql.SQLException; import java.util.ArrayList; @@ -219,6 +219,13 @@ private List initReporters( Connection conn, List rep for (ReporterOptions ro : reporterOptionsList) { Reporter reporter = ReporterFactory.createReporter(ro.getReporterName()); + + // Quick-hack for CoverageHTML Reporter + if ( reporter instanceof CoverageHTMLReporter && ro.outputToFile() ) { + ((CoverageHTMLReporter)reporter).setAssetsPath(ro.getOutputFileName()+"_assets/"); + CoverageHTMLReporter.writeReportAssetsTo(Paths.get(ro.getOutputFileName()+"_assets/")); + } + reporter.init(conn); ro.setReporterObj(reporter); reporterList.add(reporter); diff --git a/src/test/java/org/utplsql/cli/RunCommandCoverageReporterIT.java b/src/test/java/org/utplsql/cli/RunCommandCoverageReporterIT.java index c70b6e2..979af9e 100644 --- a/src/test/java/org/utplsql/cli/RunCommandCoverageReporterIT.java +++ b/src/test/java/org/utplsql/cli/RunCommandCoverageReporterIT.java @@ -2,14 +2,17 @@ import org.junit.jupiter.api.Test; +import java.io.File; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.List; import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * System tests for Code Coverage Reporter @@ -83,4 +86,25 @@ public void run_CodeCoverageWithIncludeAndExclude() throws Exception { } } + + @Test + public void coverageReporterWriteAssetsToOutput() throws Exception { + Path coveragePath = getTempCoverageFilePath(); + + RunCommand runCmd = RunCommandTestHelper.createRunCommand(RunCommandTestHelper.getConnectionString(), + "-f=ut_coverage_html_reporter", "-o=" + coveragePath, "-s"); + try { + int result = runCmd.run(); + + List reporterOptions = runCmd.getReporterOptionsList(); + File applicationJs = coveragePath.resolve(Paths.get("assets", "application.js")).toFile(); + + assertTrue(applicationJs.exists()); + + } finally { + if ( Files.exists(coveragePath)) + Files.delete(coveragePath); + } + + } } From 88c06885469b60dbc50593e4a57b71f7236c5bcb Mon Sep 17 00:00:00 2001 From: Samuel Nitsche Date: Fri, 9 Feb 2018 09:53:31 +0100 Subject: [PATCH 010/228] Fix and refactor CoverageHTMLTests --- .../cli/RunCommandCoverageReporterIT.java | 67 +++++++++++++------ 1 file changed, 47 insertions(+), 20 deletions(-) diff --git a/src/test/java/org/utplsql/cli/RunCommandCoverageReporterIT.java b/src/test/java/org/utplsql/cli/RunCommandCoverageReporterIT.java index 979af9e..cb7ce2e 100644 --- a/src/test/java/org/utplsql/cli/RunCommandCoverageReporterIT.java +++ b/src/test/java/org/utplsql/cli/RunCommandCoverageReporterIT.java @@ -1,13 +1,16 @@ package org.utplsql.cli; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.io.File; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.List; +import java.util.HashSet; import java.util.Scanner; +import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -23,6 +26,12 @@ public class RunCommandCoverageReporterIT { private static final Pattern REGEX_COVERAGE_TITLE = Pattern.compile("([a-zA-Z0-9\\._]+)<\\/a>"); + private Set tempPaths; + + private void addTempPath(Path path) { + tempPaths.add(path); + } + private String getTempCoverageFileName(int counter) { return "tmpCoverage_" + String.valueOf(System.currentTimeMillis()) + "_" + String.valueOf(counter) + ".html"; @@ -34,15 +43,19 @@ private String getTempCoverageFileName(int counter) { * @return */ private Path getTempCoverageFilePath() { + int i = 1; Path p = Paths.get(getTempCoverageFileName(i)); - while (Files.exists(p) && i < 100) + while ((Files.exists(p) || tempPaths.contains(p)) && i < 100) p = Paths.get(getTempCoverageFileName(i++)); if (i >= 100) throw new IllegalStateException("Could not get temporary file for coverage output"); + addTempPath(p); + addTempPath(Paths.get(p.toString()+"_assets")); + return p; } @@ -64,6 +77,11 @@ private boolean hasCoverageListed(String content, String packageName) { return false; } + @BeforeEach + public void setupTest() { + tempPaths = new HashSet<>(); + } + @Test public void run_CodeCoverageWithIncludeAndExclude() throws Exception { @@ -72,39 +90,48 @@ public void run_CodeCoverageWithIncludeAndExclude() throws Exception { RunCommand runCmd = RunCommandTestHelper.createRunCommand(RunCommandTestHelper.getConnectionString(), "-f=ut_coverage_html_reporter", "-o=" + coveragePath, "-s", "-exclude=app.award_bonus,app.betwnstr"); - try { - int result = runCmd.run(); - String content = new Scanner(coveragePath).useDelimiter("\\Z").next(); + int result = runCmd.run(); - assertEquals(true, hasCoverageListed(content, "app.remove_rooms_by_name")); - assertEquals(false, hasCoverageListed(content, "app.award_bonus")); - assertEquals(false, hasCoverageListed(content, "app.betwnstr")); + String content = new Scanner(coveragePath).useDelimiter("\\Z").next(); - } finally { - Files.delete(coveragePath); - } + assertEquals(true, hasCoverageListed(content, "app.remove_rooms_by_name")); + assertEquals(false, hasCoverageListed(content, "app.award_bonus")); + assertEquals(false, hasCoverageListed(content, "app.betwnstr")); } @Test public void coverageReporterWriteAssetsToOutput() throws Exception { Path coveragePath = getTempCoverageFilePath(); + Path coverageAssetsPath = Paths.get(coveragePath.toString() + "_assets"); RunCommand runCmd = RunCommandTestHelper.createRunCommand(RunCommandTestHelper.getConnectionString(), "-f=ut_coverage_html_reporter", "-o=" + coveragePath, "-s"); - try { - int result = runCmd.run(); - List reporterOptions = runCmd.getReporterOptionsList(); - File applicationJs = coveragePath.resolve(Paths.get("assets", "application.js")).toFile(); + runCmd.run(); - assertTrue(applicationJs.exists()); + File applicationJs = coverageAssetsPath.resolve(Paths.get("application.js")).toFile(); - } finally { - if ( Files.exists(coveragePath)) - Files.delete(coveragePath); - } + assertTrue(applicationJs.exists()); + + + } + @AfterEach + public void deleteTempFiles() { + tempPaths.forEach(p -> deleteDir(p.toFile())); + } + + void deleteDir(File file) { + if (file.exists()) { + File[] contents = file.listFiles(); + if (contents != null) { + for (File f : contents) { + deleteDir(f); + } + } + file.delete(); + } } } From 72659931eb064221b5ed3330c386a33fba7d2bc8 Mon Sep 17 00:00:00 2001 From: pesse Date: Sat, 10 Feb 2018 23:00:31 +0100 Subject: [PATCH 011/228] Add test to check HTML output, too --- .../java/org/utplsql/cli/RunCommandCoverageReporterIT.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/utplsql/cli/RunCommandCoverageReporterIT.java b/src/test/java/org/utplsql/cli/RunCommandCoverageReporterIT.java index cb7ce2e..52932bb 100644 --- a/src/test/java/org/utplsql/cli/RunCommandCoverageReporterIT.java +++ b/src/test/java/org/utplsql/cli/RunCommandCoverageReporterIT.java @@ -111,11 +111,13 @@ public void coverageReporterWriteAssetsToOutput() throws Exception { runCmd.run(); + // Check application file exists File applicationJs = coverageAssetsPath.resolve(Paths.get("application.js")).toFile(); - assertTrue(applicationJs.exists()); - + // Check correct script-part in HTML source exists + String content = new Scanner(coveragePath).useDelimiter("\\Z").next(); + assertTrue(content.contains("