From b0a8143d5538d77f32bd02c6ea5a63d97e5ebaf5 Mon Sep 17 00:00:00 2001 From: Vinicius Avellar Date: Wed, 19 Jul 2017 23:33:21 -0300 Subject: [PATCH 001/345] Add option to fail on errors --- README.md | 9 +++++---- src/main/java/io/github/utplsql/cli/Cli.java | 3 ++- .../java/io/github/utplsql/cli/RunCommand.java | 17 ++++++++++++++--- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index fdb7750..c227b75 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Provides an easy way of invoking utPLSQL from command-line. Main features: * Ability to run tests with multiple reporters simultaneously. * Ability to save output from every individual reporter to a separate output file. * Allows execution of selected suites, subset of suite. -* ~~Maps project and test files to database objects for reporting purposes.~~ (Comming Soon) +* Maps project and test files to database objects for reporting purposes. (Comming Soon) ## Downloading You can download development versions on [Bintray](https://bintray.com/viniciusam/utPLSQL-cli/utPLSQL-cli-develop#files). @@ -14,7 +14,7 @@ You can download development versions on [Bintray](https://bintray.com/viniciusa ## Requirements * [Java SE Runtime Environment 8](http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html) -* ~~When using reporters for Sonar or Coveralls client needs to be invoked from project's root directory.~~ +* When using reporters for Sonar or Coveralls client needs to be invoked from project's root directory. ## Usage utplsql run user/pass@[[host][:port]/]db [-p=(ut_path|ut_paths)] [-f=format [-o=output_file] [-s] ...] @@ -62,11 +62,12 @@ db - Database to connect to. -s - Forces putting output to to screen for a given -f parameter. -c - If specified, enables printing of test results in colors as defined by ANSICONSOLE standards. Works only on reporeters that support colors (ut_documentation_reporter). +--no-failure - By default, the client will exit with -1 if any test failed, override this behavior by providing this option. ``` Parameters -f, -o, -s are correlated. That is parameters -o and -s are controlling outputs for reporter specified by the preceding -f parameter. -~~Sonar and Coveralls reporter will only provide valid reports, when source_path and/or test_path are provided, and ut_run is executed from your project's root path.~~ +Sonar and Coveralls reporter will only provide valid reports, when source_path and/or test_path are provided, and ut_run is executed from your project's root path. Examples: @@ -77,7 +78,7 @@ utplsql run hr/hr@xe -p=hr_test -f=ut_documentation_reporter -o=run.log -s -f=ut Invokes all Unit tests from schema/package "hr_test" with two reporters: * ut_documentation_reporter - will output to screen and save output to file "run.log" -* ~~ut_coverage_html_reporter - will report only on database objects that are mapping to file structure from "source" folder and save output to file "coverage.html"~~ +* ut_coverage_html_reporter - will report only on database objects that are mapping to file structure from "source" folder and save output to file "coverage.html" ``` utplsql run hr/hr@xe diff --git a/src/main/java/io/github/utplsql/cli/Cli.java b/src/main/java/io/github/utplsql/cli/Cli.java index 19c4309..ae8851f 100644 --- a/src/main/java/io/github/utplsql/cli/Cli.java +++ b/src/main/java/io/github/utplsql/cli/Cli.java @@ -20,7 +20,8 @@ public static void main(String[] args) { boolean hasCmd = jc.getParsedCommand() != null; if (hasCmd && jc.getParsedCommand().equals(RUN_CMD)) { - runCmd.run(); + int status = runCmd.run(); + System.exit(status); } else { jc.usage(); } diff --git a/src/main/java/io/github/utplsql/cli/RunCommand.java b/src/main/java/io/github/utplsql/cli/RunCommand.java index 0e43150..2d4f2dc 100644 --- a/src/main/java/io/github/utplsql/cli/RunCommand.java +++ b/src/main/java/io/github/utplsql/cli/RunCommand.java @@ -5,6 +5,7 @@ import io.github.utplsql.api.CustomTypes; import io.github.utplsql.api.OutputBuffer; import io.github.utplsql.api.TestRunner; +import io.github.utplsql.api.exception.SomeTestsFailedException; import io.github.utplsql.api.reporter.Reporter; import io.github.utplsql.api.reporter.ReporterFactory; @@ -51,6 +52,11 @@ public class RunCommand { description = "enables printing of test results in colors as defined by ANSICONSOLE standards") private boolean colorConsole = false; + @Parameter( + names = {"--no-failure"}, + description = "will exit with 0 even if tests failed, default false") + private boolean noFailure = false; + @Parameter(names = {"-source_path"}, description = "path to project source files") private String sourcePath; @@ -92,7 +98,7 @@ public List getReporterOptionsList() { return reporterOptionsList; } - public void run() throws Exception { + public int run() throws Exception { final ConnectionInfo ci = getConnectionInfo(); final List reporterOptionsList = getReporterOptionsList(); @@ -111,6 +117,7 @@ public void run() throws Exception { final List sourceFiles = sourceFilesTmp; final List testFiles = testFilesTmp; + final int[] returnCode = {0}; if (testPaths.isEmpty()) testPaths.add(ci.getUser()); @@ -131,14 +138,17 @@ public void run() throws Exception { // Run tests. executorService.submit(() -> { - try (Connection conn = ci.getConnection()){ + try (Connection conn = ci.getConnection()) { new TestRunner() .addPathList(testPaths) .addReporterList(reporterList) .withSourceFiles(sourceFiles) .withTestFiles(testFiles) - .colorConsole(colorConsole) + .colorConsole(this.colorConsole) + .failOnErrors(!this.noFailure) .run(conn); + } catch (SomeTestsFailedException e) { + returnCode[0] = -1; } catch (SQLException e) { // TODO e.printStackTrace(); @@ -174,6 +184,7 @@ public void run() throws Exception { executorService.shutdown(); executorService.awaitTermination(60, TimeUnit.MINUTES); + return returnCode[0]; } } From 349cc53a68679af3c437dad63e831e6885bcea03 Mon Sep 17 00:00:00 2001 From: Vinicius Avellar Date: Thu, 20 Jul 2017 21:21:32 -0300 Subject: [PATCH 002/345] Change the failure error code parameter --- README.md | 86 +++++++++---------- .../io/github/utplsql/cli/RunCommand.java | 10 +-- 2 files changed, 48 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index c227b75..f4626ed 100644 --- a/README.md +++ b/README.md @@ -20,49 +20,49 @@ You can download development versions on [Bintray](https://bintray.com/viniciusa utplsql run user/pass@[[host][:port]/]db [-p=(ut_path|ut_paths)] [-f=format [-o=output_file] [-s] ...] ``` -user - Username to connect as. -password - Password of the user. -host - Server address, defaults to 127.0.0.1. -port - Server port, defaults to 1521. -db - Database to connect to. --p=suite_path(s) - A suite path or a comma separated list of suite paths for unit test to be executed. - The path(s) can be in one of the following formats: - schema[.package[.procedure]] - schema:suite[.suite[.suite][...]][.procedure] - Both formats can be mixed in the list. - If only schema is provided, then all suites owner by that schema are executed. - If -p is omitted, the current schema is used. --f=format - A reporter to be used for reporting. - If no -f option is provided, the default ut_documentation_reporter is used. - Available options: - -f=ut_documentation_reporter - A textual pretty-print of unit test results (usually use for console output) - -f=ut_teamcity_reporter - For reporting live progress of test execution with Teamcity CI. - -f=ut_xunit_reporter - Used for reporting test results with CI servers like Jenkins/Hudson/Teamcity. - -f=ut_coverage_html_reporter - Generates a HTML coverage report with summary and line by line information on code coverage. - Based on open-source simplecov-html coverage reporter for Ruby. - Includes source code in the report. - -f=ut_coveralls_reporter - Generates a JSON coverage report providing information on code coverage with line numbers. - Designed for [Coveralls](https://coveralls.io/). - -f=ut_coverage_sonar_reporter - Generates a JSON coverage report providing information on code coverage with line numbers. - Designed for [SonarQube](https://about.sonarqube.com/) to report coverage. - -f=ut_sonar_test_reporter - Generates a JSON report providing detailed information on test execution. - Designed for [SonarQube](https://about.sonarqube.com/) to report test execution. - --o=output - Defines file name to save the output from the specified reporter. - If defined, the output is not displayed on screen by default. This can be changed with the -s parameter. - If not defined, then output will be displayed on screen, even if the parameter -s is not specified. - If more than one -o parameter is specified for one -f parameter, the last one is taken into consideration. --s - Forces putting output to to screen for a given -f parameter. --c - If specified, enables printing of test results in colors as defined by ANSICONSOLE standards. - Works only on reporeters that support colors (ut_documentation_reporter). ---no-failure - By default, the client will exit with -1 if any test failed, override this behavior by providing this option. +user - Username to connect as. +password - Password of the user. +host - Server address, defaults to 127.0.0.1. +port - Server port, defaults to 1521. +db - Database to connect to. +-p=suite_path(s) - A suite path or a comma separated list of suite paths for unit test to be executed. + The path(s) can be in one of the following formats: + schema[.package[.procedure]] + schema:suite[.suite[.suite][...]][.procedure] + Both formats can be mixed in the list. + If only schema is provided, then all suites owner by that schema are executed. + If -p is omitted, the current schema is used. +-f=format - A reporter to be used for reporting. + If no -f option is provided, the default ut_documentation_reporter is used. + Available options: + -f=ut_documentation_reporter + A textual pretty-print of unit test results (usually use for console output) + -f=ut_teamcity_reporter + For reporting live progress of test execution with Teamcity CI. + -f=ut_xunit_reporter + Used for reporting test results with CI servers like Jenkins/Hudson/Teamcity. + -f=ut_coverage_html_reporter + Generates a HTML coverage report with summary and line by line information on code coverage. + Based on open-source simplecov-html coverage reporter for Ruby. + Includes source code in the report. + -f=ut_coveralls_reporter + Generates a JSON coverage report providing information on code coverage with line numbers. + Designed for [Coveralls](https://coveralls.io/). + -f=ut_coverage_sonar_reporter + Generates a JSON coverage report providing information on code coverage with line numbers. + Designed for [SonarQube](https://about.sonarqube.com/) to report coverage. + -f=ut_sonar_test_reporter + Generates a JSON report providing detailed information on test execution. + Designed for [SonarQube](https://about.sonarqube.com/) to report test execution. + +-o=output - Defines file name to save the output from the specified reporter. + If defined, the output is not displayed on screen by default. This can be changed with the -s parameter. + If not defined, then output will be displayed on screen, even if the parameter -s is not specified. + If more than one -o parameter is specified for one -f parameter, the last one is taken into consideration. +-s - Forces putting output to to screen for a given -f parameter. +-c - If specified, enables printing of test results in colors as defined by ANSICONSOLE standards. + Works only on reporeters that support colors (ut_documentation_reporter). +--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. ``` Parameters -f, -o, -s are correlated. That is parameters -o and -s are controlling outputs for reporter specified by the preceding -f parameter. diff --git a/src/main/java/io/github/utplsql/cli/RunCommand.java b/src/main/java/io/github/utplsql/cli/RunCommand.java index 2d4f2dc..6212610 100644 --- a/src/main/java/io/github/utplsql/cli/RunCommand.java +++ b/src/main/java/io/github/utplsql/cli/RunCommand.java @@ -53,9 +53,9 @@ public class RunCommand { private boolean colorConsole = false; @Parameter( - names = {"--no-failure"}, - description = "will exit with 0 even if tests failed, default false") - private boolean noFailure = false; + names = {"--failure-exit-code"}, + description = "override the exit code on failure, default = 1") + private int failureExitCode = 1; @Parameter(names = {"-source_path"}, description = "path to project source files") private String sourcePath; @@ -145,10 +145,10 @@ public int run() throws Exception { .withSourceFiles(sourceFiles) .withTestFiles(testFiles) .colorConsole(this.colorConsole) - .failOnErrors(!this.noFailure) + .failOnErrors(true) .run(conn); } catch (SomeTestsFailedException e) { - returnCode[0] = -1; + returnCode[0] = this.failureExitCode; } catch (SQLException e) { // TODO e.printStackTrace(); From 14d39c0295a435ed1ed32f18c7bc1991a9fb3046 Mon Sep 17 00:00:00 2001 From: Vinicius Avellar Date: Thu, 20 Jul 2017 21:51:49 -0300 Subject: [PATCH 003/345] Exit with error on client exceptions --- src/main/java/io/github/utplsql/cli/Cli.java | 14 +++++++++----- .../java/io/github/utplsql/cli/RunCommand.java | 12 ++++++------ 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/main/java/io/github/utplsql/cli/Cli.java b/src/main/java/io/github/utplsql/cli/Cli.java index ae8851f..0e79ce0 100644 --- a/src/main/java/io/github/utplsql/cli/Cli.java +++ b/src/main/java/io/github/utplsql/cli/Cli.java @@ -6,6 +6,8 @@ public class Cli { + public static final int DEFAULT_ERROR_CODE = 1; + public static final String HELP_CMD = "-h"; public static final String RUN_CMD = "run"; @@ -15,15 +17,15 @@ public static void main(String[] args) { RunCommand runCmd = new RunCommand(); jc.addCommand(RUN_CMD, runCmd); + int exitCode = DEFAULT_ERROR_CODE; + try { jc.parse(args); - boolean hasCmd = jc.getParsedCommand() != null; - if (hasCmd && jc.getParsedCommand().equals(RUN_CMD)) { - int status = runCmd.run(); - System.exit(status); + if (RUN_CMD.equals(jc.getParsedCommand())) { + exitCode = runCmd.run(); } else { - jc.usage(); + throw new ParameterException("Command not specified."); } } catch (ParameterException e) { if (jc.getParsedCommand() != null) { @@ -35,6 +37,8 @@ public static void main(String[] args) { } catch (Exception e) { e.printStackTrace(); } + + System.exit(exitCode); } private static class HelpCommand { diff --git a/src/main/java/io/github/utplsql/cli/RunCommand.java b/src/main/java/io/github/utplsql/cli/RunCommand.java index 6212610..69dfa89 100644 --- a/src/main/java/io/github/utplsql/cli/RunCommand.java +++ b/src/main/java/io/github/utplsql/cli/RunCommand.java @@ -130,8 +130,8 @@ public int run() throws Exception { reporterList.add(reporter); } } catch (SQLException e) { - // TODO - e.printStackTrace(); + System.out.println(e.getMessage()); + return Cli.DEFAULT_ERROR_CODE; } ExecutorService executorService = Executors.newFixedThreadPool(1 + reporterList.size()); @@ -150,8 +150,8 @@ public int run() throws Exception { } catch (SomeTestsFailedException e) { returnCode[0] = this.failureExitCode; } catch (SQLException e) { - // TODO - e.printStackTrace(); + System.out.println(e.getMessage()); + returnCode[0] = Cli.DEFAULT_ERROR_CODE; } }); @@ -173,8 +173,8 @@ public int run() throws Exception { new OutputBuffer(ro.getReporterObj()).printAvailable(conn, printStreams); } catch (SQLException | FileNotFoundException e) { - // TODO - e.printStackTrace(); + System.out.println(e.getMessage()); + returnCode[0] = Cli.DEFAULT_ERROR_CODE; } finally { if (fileOutStream != null) fileOutStream.close(); From 80ee1f0c4d541e0fd843872954630c548acf3dfd Mon Sep 17 00:00:00 2001 From: Vinicius Avellar Date: Sun, 23 Jul 2017 14:48:43 -0300 Subject: [PATCH 004/345] Custom file mapping support --- README.md | 18 ++- .../io/github/utplsql/cli/RunCommand.java | 145 +++++++++++++----- 2 files changed, 119 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index f4626ed..07addd8 100644 --- a/README.md +++ b/README.md @@ -55,11 +55,25 @@ db - Database to connect to. Generates a JSON report providing detailed information on test execution. Designed for [SonarQube](https://about.sonarqube.com/) to report test execution. --o=output - Defines file name to save the output from the specified reporter. + -o=output - Defines file name to save the output from the specified reporter. If defined, the output is not displayed on screen by default. This can be changed with the -s parameter. If not defined, then output will be displayed on screen, even if the parameter -s is not specified. If more than one -o parameter is specified for one -f parameter, the last one is taken into consideration. --s - Forces putting output to to screen for a given -f parameter. + -s - Forces putting output to to screen for a given -f parameter. +-source_path=source - path to project source files, use the following options to enable custom type mappings: + -owner="app" + -regex_expression="pattern" + -type_mapping="matched_string=TYPE[/matched_string=TYPE]*" + -owner_subexpression=subexpression_number + -type_subexpression=subexpression_number + -name_subexpression=subexpression_number +-test_path=test - path to project test files, use the following options to enable custom type mappings: + -owner="app" + -regex_expression="pattern" + -type_mapping="matched_string=TYPE[/matched_string=TYPE]*" + -owner_subexpression=subexpression_number + -type_subexpression=subexpression_number + -name_subexpression=subexpression_number -c - If specified, enables printing of test results in colors as defined by ANSICONSOLE standards. Works only on reporeters that support colors (ut_documentation_reporter). --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. diff --git a/src/main/java/io/github/utplsql/cli/RunCommand.java b/src/main/java/io/github/utplsql/cli/RunCommand.java index 69dfa89..c6472f2 100644 --- a/src/main/java/io/github/utplsql/cli/RunCommand.java +++ b/src/main/java/io/github/utplsql/cli/RunCommand.java @@ -2,9 +2,7 @@ import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; -import io.github.utplsql.api.CustomTypes; -import io.github.utplsql.api.OutputBuffer; -import io.github.utplsql.api.TestRunner; +import io.github.utplsql.api.*; import io.github.utplsql.api.exception.SomeTestsFailedException; import io.github.utplsql.api.reporter.Reporter; import io.github.utplsql.api.reporter.ReporterFactory; @@ -35,16 +33,15 @@ public class RunCommand { @Parameter( names = {"-p", "--path"}, - description = "run suites/tests by path, format: \n" + + description = "run suites/tests by path, format: " + "-p=[schema|schema:[suite ...][.test]|schema[.suite ...][.test]") private List testPaths = new ArrayList<>(); @Parameter( names = {"-f", "--format"}, variableArity = true, - description = "output reporter format: \n" + - "enables specified format reporting to specified output file (-o) and to screen (-s)\n" + - "-f=reporter_name [-o=output_file [-s]]") + description = "-f=reporter_name [-o=output_file [-s]] - enables specified format reporting to specified " + + "output file (-o) and to screen (-s)") private List reporterParams = new ArrayList<>(); @Parameter( @@ -57,11 +54,20 @@ public class RunCommand { description = "override the exit code on failure, default = 1") private int failureExitCode = 1; - @Parameter(names = {"-source_path"}, description = "path to project source files") - private String sourcePath; + @Parameter( + names = {"-source_path"}, + variableArity = true, + description = "-source_path [-owner=\"owner\" -regex_expression=\"pattern\" " + + "-type_mapping=\"matched_string=TYPE/matched_string=TYPE\" " + + "-owner_subexpression=0 -type_subexpression=0 -name_subexpression=0] - path to project source files") + private List sourcePathParams = new ArrayList<>(); - @Parameter(names = {"-test_path"}, description = "path to project test files") - private String testPath; + @Parameter( + names = {"-test_path"}, + variableArity = true, + description = "-test_path [-regex_expression=\"pattern\" -owner_subexpression=0 -type_subexpression=0 " + + "-name_subexpression=0] - path to project test files") + private List testPathParams = new ArrayList<>(); public ConnectionInfo getConnectionInfo() { return connectionInfoList.get(0); @@ -71,33 +77,6 @@ public List getTestPaths() { return testPaths; } - public List getReporterOptionsList() { - List reporterOptionsList = new ArrayList<>(); - ReporterOptions reporterOptions = null; - - for (String p : reporterParams) { - if (reporterOptions == null || !p.startsWith("-")) { - reporterOptions = new ReporterOptions(p); - reporterOptionsList.add(reporterOptions); - } - else - if (p.startsWith("-o=")) { - reporterOptions.setOutputFileName(p.substring(3)); - } - else - if (p.equals("-s")) { - reporterOptions.forceOutputToScreen(true); - } - } - - // If no reporter parameters were passed, use default reporter. - if (reporterOptionsList.isEmpty()) { - reporterOptionsList.add(new ReporterOptions(CustomTypes.UT_DOCUMENTATION_REPORTER)); - } - - return reporterOptionsList; - } - public int run() throws Exception { final ConnectionInfo ci = getConnectionInfo(); @@ -108,15 +87,25 @@ public int run() throws Exception { final File baseDir = new File("").getAbsoluteFile(); List sourceFilesTmp = null; List testFilesTmp = null; + FileMapperOptions sourceMappingOptionsTmp= null; + FileMapperOptions testMappingOptionsTmp = null; - if (this.sourcePath != null) - sourceFilesTmp = new FileWalker().getFileList(baseDir, this.sourcePath); + if (!this.sourcePathParams.isEmpty()) { + String sourcePath = this.sourcePathParams.get(0); + sourceFilesTmp = new FileWalker().getFileList(baseDir, sourcePath); + sourceMappingOptionsTmp = getMapperOptions(this.sourcePathParams); + } - if (this.testPath != null) - testFilesTmp = new FileWalker().getFileList(baseDir, this.testPath); + if (!this.testPathParams.isEmpty()) { + String testPath = this.testPathParams.get(0); + testFilesTmp = new FileWalker().getFileList(baseDir, testPath); + testMappingOptionsTmp = getMapperOptions(this.testPathParams); + } final List sourceFiles = sourceFilesTmp; final List testFiles = testFilesTmp; + final FileMapperOptions sourceMappingOptions = sourceMappingOptionsTmp; + final FileMapperOptions testMappingOptions = testMappingOptionsTmp; final int[] returnCode = {0}; if (testPaths.isEmpty()) testPaths.add(ci.getUser()); @@ -143,7 +132,9 @@ public int run() throws Exception { .addPathList(testPaths) .addReporterList(reporterList) .withSourceFiles(sourceFiles) + .sourceMappingOptions(sourceMappingOptions) .withTestFiles(testFiles) + .testMappingOptions(testMappingOptions) .colorConsole(this.colorConsole) .failOnErrors(true) .run(conn); @@ -187,4 +178,74 @@ public int run() throws Exception { return returnCode[0]; } + public List getReporterOptionsList() { + List reporterOptionsList = new ArrayList<>(); + ReporterOptions reporterOptions = null; + + for (String p : reporterParams) { + if (reporterOptions == null || !p.startsWith("-")) { + reporterOptions = new ReporterOptions(p); + reporterOptionsList.add(reporterOptions); + } + else + if (p.startsWith("-o=")) { + reporterOptions.setOutputFileName(p.substring(3)); + } + else + if (p.equals("-s")) { + reporterOptions.forceOutputToScreen(true); + } + } + + // If no reporter parameters were passed, use default reporter. + if (reporterOptionsList.isEmpty()) { + reporterOptionsList.add(new ReporterOptions(CustomTypes.UT_DOCUMENTATION_REPORTER)); + } + + return reporterOptionsList; + } + + public FileMapperOptions getMapperOptions(List mappingParams) { + FileMapperOptions mapperOptions = new FileMapperOptions(); + + for (String p : mappingParams) { + if (p.startsWith("-object_owner=")) { + mapperOptions.setObjectOwner(p.substring("-object_owner=".length())); + } + else + if (p.startsWith("-regex_pattern=")) { + mapperOptions.setRegexPattern(p.substring("-regex_pattern=".length())); + } + else + if (p.startsWith("-type_mapping=")) { + String typeMappingsParam = p.substring("-type_mapping=".length()); + + List typeMappings = new ArrayList<>(); + for (String mapping : typeMappingsParam.split("/")) { + String[] values = mapping.split("="); + typeMappings.add(new KeyValuePair(values[0], values[1])); + } + + mapperOptions.setTypeMappings(typeMappings); + } + else + if (p.startsWith("-owner_subexpression=")) { + mapperOptions.setOwnerSubExpression(Integer.parseInt(p.substring("-owner_subexpression=".length()))); + } + else + if (p.startsWith("-name_subexpression=")) { + mapperOptions.setNameSubExpression(Integer.parseInt(p.substring("-name_subexpression=".length()))); + } + else + if (p.startsWith("-type_subexpression=")) { + mapperOptions.setTypeSubExpression(Integer.parseInt(p.substring("-type_subexpression=".length()))); + } + } + + if (mapperOptions.getRegexPattern() == null || mapperOptions.getRegexPattern().isEmpty()) + return null; + else + return mapperOptions; + } + } From bb2c8515f2467ec3baa6fe1577af990804e96c22 Mon Sep 17 00:00:00 2001 From: Vinicius Avellar Date: Sun, 23 Jul 2017 20:10:26 -0300 Subject: [PATCH 005/345] Changes on FileMapper API --- .../io/github/utplsql/cli/RunCommand.java | 32 +++++++------------ 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/src/main/java/io/github/utplsql/cli/RunCommand.java b/src/main/java/io/github/utplsql/cli/RunCommand.java index c6472f2..72ec9fb 100644 --- a/src/main/java/io/github/utplsql/cli/RunCommand.java +++ b/src/main/java/io/github/utplsql/cli/RunCommand.java @@ -85,29 +85,23 @@ public int run() throws Exception { final List reporterList = new ArrayList<>(); final File baseDir = new File("").getAbsoluteFile(); - List sourceFilesTmp = null; - List testFilesTmp = null; - FileMapperOptions sourceMappingOptionsTmp= null; - FileMapperOptions testMappingOptionsTmp = null; + final FileMapperOptions[] sourceMappingOptions = {null}; + final FileMapperOptions[] testMappingOptions = {null}; + + final int[] returnCode = {0}; if (!this.sourcePathParams.isEmpty()) { String sourcePath = this.sourcePathParams.get(0); - sourceFilesTmp = new FileWalker().getFileList(baseDir, sourcePath); - sourceMappingOptionsTmp = getMapperOptions(this.sourcePathParams); + List sourceFiles = new FileWalker().getFileList(baseDir, sourcePath); + sourceMappingOptions[0] = getMapperOptions(this.sourcePathParams, sourceFiles); } if (!this.testPathParams.isEmpty()) { String testPath = this.testPathParams.get(0); - testFilesTmp = new FileWalker().getFileList(baseDir, testPath); - testMappingOptionsTmp = getMapperOptions(this.testPathParams); + List testFiles = new FileWalker().getFileList(baseDir, testPath); + testMappingOptions[0] = getMapperOptions(this.testPathParams, testFiles); } - final List sourceFiles = sourceFilesTmp; - final List testFiles = testFilesTmp; - final FileMapperOptions sourceMappingOptions = sourceMappingOptionsTmp; - final FileMapperOptions testMappingOptions = testMappingOptionsTmp; - final int[] returnCode = {0}; - if (testPaths.isEmpty()) testPaths.add(ci.getUser()); // Do the reporters initialization, so we can use the id to run and gather results. @@ -131,10 +125,8 @@ public int run() throws Exception { new TestRunner() .addPathList(testPaths) .addReporterList(reporterList) - .withSourceFiles(sourceFiles) - .sourceMappingOptions(sourceMappingOptions) - .withTestFiles(testFiles) - .testMappingOptions(testMappingOptions) + .sourceMappingOptions(sourceMappingOptions[0]) + .testMappingOptions(testMappingOptions[0]) .colorConsole(this.colorConsole) .failOnErrors(true) .run(conn); @@ -205,8 +197,8 @@ public List getReporterOptionsList() { return reporterOptionsList; } - public FileMapperOptions getMapperOptions(List mappingParams) { - FileMapperOptions mapperOptions = new FileMapperOptions(); + public FileMapperOptions getMapperOptions(List mappingParams, List filePaths) { + FileMapperOptions mapperOptions = new FileMapperOptions(filePaths); for (String p : mappingParams) { if (p.startsWith("-object_owner=")) { From 2cf7b661aa91d7aa2b2d2b225ee630147a4bccfa Mon Sep 17 00:00:00 2001 From: Vinicius Avellar Date: Thu, 3 Aug 2017 15:21:07 -0300 Subject: [PATCH 006/345] Halt client threads on database errors --- src/main/java/io/github/utplsql/cli/RunCommand.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/io/github/utplsql/cli/RunCommand.java b/src/main/java/io/github/utplsql/cli/RunCommand.java index 72ec9fb..c82fd1c 100644 --- a/src/main/java/io/github/utplsql/cli/RunCommand.java +++ b/src/main/java/io/github/utplsql/cli/RunCommand.java @@ -135,6 +135,7 @@ public int run() throws Exception { } catch (SQLException e) { System.out.println(e.getMessage()); returnCode[0] = Cli.DEFAULT_ERROR_CODE; + executorService.shutdownNow(); } }); @@ -158,6 +159,7 @@ public int run() throws Exception { } catch (SQLException | FileNotFoundException e) { System.out.println(e.getMessage()); returnCode[0] = Cli.DEFAULT_ERROR_CODE; + executorService.shutdownNow(); } finally { if (fileOutStream != null) fileOutStream.close(); From fde3e930499f26d8c263108a5176016f019bc301 Mon Sep 17 00:00:00 2001 From: Vinicius Avellar Date: Sat, 5 Aug 2017 23:53:44 -0300 Subject: [PATCH 007/345] Renaming base package to org.utplsql --- src/main/java/{io/github => org}/utplsql/cli/Cli.java | 0 src/main/java/{io/github => org}/utplsql/cli/ConnectionInfo.java | 0 .../{io/github => org}/utplsql/cli/ConnectionStringConverter.java | 0 src/main/java/{io/github => org}/utplsql/cli/FileWalker.java | 0 src/main/java/{io/github => org}/utplsql/cli/ReporterOptions.java | 0 src/main/java/{io/github => org}/utplsql/cli/RunCommand.java | 0 .../java/{io/github => org}/utplsql/cli/ConnectionInfoTest.java | 0 src/test/java/{io/github => org}/utplsql/cli/FileWalkerTest.java | 0 src/test/java/{io/github => org}/utplsql/cli/RunCommandTest.java | 0 9 files changed, 0 insertions(+), 0 deletions(-) rename src/main/java/{io/github => org}/utplsql/cli/Cli.java (100%) rename src/main/java/{io/github => org}/utplsql/cli/ConnectionInfo.java (100%) rename src/main/java/{io/github => org}/utplsql/cli/ConnectionStringConverter.java (100%) rename src/main/java/{io/github => org}/utplsql/cli/FileWalker.java (100%) rename src/main/java/{io/github => org}/utplsql/cli/ReporterOptions.java (100%) rename src/main/java/{io/github => org}/utplsql/cli/RunCommand.java (100%) rename src/test/java/{io/github => org}/utplsql/cli/ConnectionInfoTest.java (100%) rename src/test/java/{io/github => org}/utplsql/cli/FileWalkerTest.java (100%) rename src/test/java/{io/github => org}/utplsql/cli/RunCommandTest.java (100%) diff --git a/src/main/java/io/github/utplsql/cli/Cli.java b/src/main/java/org/utplsql/cli/Cli.java similarity index 100% rename from src/main/java/io/github/utplsql/cli/Cli.java rename to src/main/java/org/utplsql/cli/Cli.java diff --git a/src/main/java/io/github/utplsql/cli/ConnectionInfo.java b/src/main/java/org/utplsql/cli/ConnectionInfo.java similarity index 100% rename from src/main/java/io/github/utplsql/cli/ConnectionInfo.java rename to src/main/java/org/utplsql/cli/ConnectionInfo.java diff --git a/src/main/java/io/github/utplsql/cli/ConnectionStringConverter.java b/src/main/java/org/utplsql/cli/ConnectionStringConverter.java similarity index 100% rename from src/main/java/io/github/utplsql/cli/ConnectionStringConverter.java rename to src/main/java/org/utplsql/cli/ConnectionStringConverter.java diff --git a/src/main/java/io/github/utplsql/cli/FileWalker.java b/src/main/java/org/utplsql/cli/FileWalker.java similarity index 100% rename from src/main/java/io/github/utplsql/cli/FileWalker.java rename to src/main/java/org/utplsql/cli/FileWalker.java diff --git a/src/main/java/io/github/utplsql/cli/ReporterOptions.java b/src/main/java/org/utplsql/cli/ReporterOptions.java similarity index 100% rename from src/main/java/io/github/utplsql/cli/ReporterOptions.java rename to src/main/java/org/utplsql/cli/ReporterOptions.java diff --git a/src/main/java/io/github/utplsql/cli/RunCommand.java b/src/main/java/org/utplsql/cli/RunCommand.java similarity index 100% rename from src/main/java/io/github/utplsql/cli/RunCommand.java rename to src/main/java/org/utplsql/cli/RunCommand.java diff --git a/src/test/java/io/github/utplsql/cli/ConnectionInfoTest.java b/src/test/java/org/utplsql/cli/ConnectionInfoTest.java similarity index 100% rename from src/test/java/io/github/utplsql/cli/ConnectionInfoTest.java rename to src/test/java/org/utplsql/cli/ConnectionInfoTest.java diff --git a/src/test/java/io/github/utplsql/cli/FileWalkerTest.java b/src/test/java/org/utplsql/cli/FileWalkerTest.java similarity index 100% rename from src/test/java/io/github/utplsql/cli/FileWalkerTest.java rename to src/test/java/org/utplsql/cli/FileWalkerTest.java diff --git a/src/test/java/io/github/utplsql/cli/RunCommandTest.java b/src/test/java/org/utplsql/cli/RunCommandTest.java similarity index 100% rename from src/test/java/io/github/utplsql/cli/RunCommandTest.java rename to src/test/java/org/utplsql/cli/RunCommandTest.java From a56c5bb1358f0bd02ff0b98cbdd21b098d1573ee Mon Sep 17 00:00:00 2001 From: Vinicius Avellar Date: Sat, 5 Aug 2017 23:54:09 -0300 Subject: [PATCH 008/345] Updating references to base package --- pom.xml | 16 ++++++++-------- src/main/java/org/utplsql/cli/Cli.java | 2 +- .../java/org/utplsql/cli/ConnectionInfo.java | 2 +- .../utplsql/cli/ConnectionStringConverter.java | 2 +- src/main/java/org/utplsql/cli/FileWalker.java | 2 +- .../java/org/utplsql/cli/ReporterOptions.java | 4 ++-- src/main/java/org/utplsql/cli/RunCommand.java | 10 +++++----- .../java/org/utplsql/cli/ConnectionInfoTest.java | 2 +- .../java/org/utplsql/cli/FileWalkerTest.java | 2 +- .../java/org/utplsql/cli/RunCommandTest.java | 4 ++-- 10 files changed, 23 insertions(+), 23 deletions(-) diff --git a/pom.xml b/pom.xml index f0f5b41..84d8161 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - io.github.utplsql + org.utplsql cli 1.0-SNAPSHOT jar @@ -18,15 +18,15 @@ - com.beust - jcommander - 1.69 + org.utplsql + java-api + 1.0-Alpha1 compile - io.github.utplsql - java-api - 1.0-SNAPSHOT + com.beust + jcommander + 1.69 compile @@ -50,7 +50,7 @@ flat - io.github.utplsql.cli.Cli + org.utplsql.cli.Cli utplsql diff --git a/src/main/java/org/utplsql/cli/Cli.java b/src/main/java/org/utplsql/cli/Cli.java index 0e79ce0..4ea8652 100644 --- a/src/main/java/org/utplsql/cli/Cli.java +++ b/src/main/java/org/utplsql/cli/Cli.java @@ -1,4 +1,4 @@ -package io.github.utplsql.cli; +package org.utplsql.cli; import com.beust.jcommander.JCommander; import com.beust.jcommander.Parameter; diff --git a/src/main/java/org/utplsql/cli/ConnectionInfo.java b/src/main/java/org/utplsql/cli/ConnectionInfo.java index 5f8deac..cbdda73 100644 --- a/src/main/java/org/utplsql/cli/ConnectionInfo.java +++ b/src/main/java/org/utplsql/cli/ConnectionInfo.java @@ -1,4 +1,4 @@ -package io.github.utplsql.cli; +package org.utplsql.cli; import com.beust.jcommander.ParameterException; diff --git a/src/main/java/org/utplsql/cli/ConnectionStringConverter.java b/src/main/java/org/utplsql/cli/ConnectionStringConverter.java index 5caa362..ba8c82a 100644 --- a/src/main/java/org/utplsql/cli/ConnectionStringConverter.java +++ b/src/main/java/org/utplsql/cli/ConnectionStringConverter.java @@ -1,4 +1,4 @@ -package io.github.utplsql.cli; +package org.utplsql.cli; import com.beust.jcommander.IStringConverter; diff --git a/src/main/java/org/utplsql/cli/FileWalker.java b/src/main/java/org/utplsql/cli/FileWalker.java index 2fb108c..3fec655 100644 --- a/src/main/java/org/utplsql/cli/FileWalker.java +++ b/src/main/java/org/utplsql/cli/FileWalker.java @@ -1,4 +1,4 @@ -package io.github.utplsql.cli; +package org.utplsql.cli; import java.io.File; import java.util.ArrayList; diff --git a/src/main/java/org/utplsql/cli/ReporterOptions.java b/src/main/java/org/utplsql/cli/ReporterOptions.java index 61eb930..a20ae3d 100644 --- a/src/main/java/org/utplsql/cli/ReporterOptions.java +++ b/src/main/java/org/utplsql/cli/ReporterOptions.java @@ -1,6 +1,6 @@ -package io.github.utplsql.cli; +package org.utplsql.cli; -import io.github.utplsql.api.reporter.Reporter; +import org.utplsql.api.reporter.Reporter; /** * Created by Vinicius on 20/05/2017. diff --git a/src/main/java/org/utplsql/cli/RunCommand.java b/src/main/java/org/utplsql/cli/RunCommand.java index c82fd1c..f4bec06 100644 --- a/src/main/java/org/utplsql/cli/RunCommand.java +++ b/src/main/java/org/utplsql/cli/RunCommand.java @@ -1,11 +1,11 @@ -package io.github.utplsql.cli; +package org.utplsql.cli; import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; -import io.github.utplsql.api.*; -import io.github.utplsql.api.exception.SomeTestsFailedException; -import io.github.utplsql.api.reporter.Reporter; -import io.github.utplsql.api.reporter.ReporterFactory; +import org.utplsql.api.*; +import org.utplsql.api.exception.SomeTestsFailedException; +import org.utplsql.api.reporter.Reporter; +import org.utplsql.api.reporter.ReporterFactory; import java.io.File; import java.io.FileNotFoundException; diff --git a/src/test/java/org/utplsql/cli/ConnectionInfoTest.java b/src/test/java/org/utplsql/cli/ConnectionInfoTest.java index a48ef77..874de69 100644 --- a/src/test/java/org/utplsql/cli/ConnectionInfoTest.java +++ b/src/test/java/org/utplsql/cli/ConnectionInfoTest.java @@ -1,4 +1,4 @@ -package io.github.utplsql.cli; +package org.utplsql.cli; import com.beust.jcommander.ParameterException; import org.junit.Assert; diff --git a/src/test/java/org/utplsql/cli/FileWalkerTest.java b/src/test/java/org/utplsql/cli/FileWalkerTest.java index 4752df6..b8e2738 100644 --- a/src/test/java/org/utplsql/cli/FileWalkerTest.java +++ b/src/test/java/org/utplsql/cli/FileWalkerTest.java @@ -1,4 +1,4 @@ -package io.github.utplsql.cli; +package org.utplsql.cli; import org.junit.Assert; import org.junit.Test; diff --git a/src/test/java/org/utplsql/cli/RunCommandTest.java b/src/test/java/org/utplsql/cli/RunCommandTest.java index 9ae9a48..66a1e2b 100644 --- a/src/test/java/org/utplsql/cli/RunCommandTest.java +++ b/src/test/java/org/utplsql/cli/RunCommandTest.java @@ -1,9 +1,9 @@ -package io.github.utplsql.cli; +package org.utplsql.cli; import com.beust.jcommander.JCommander; -import io.github.utplsql.api.CustomTypes; import org.junit.Assert; import org.junit.Test; +import org.utplsql.api.CustomTypes; import java.util.List; From 5e3487bb5354a94a734b97f04a1a422626af38c6 Mon Sep 17 00:00:00 2001 From: Vinicius Avellar Date: Mon, 7 Aug 2017 12:39:21 -0300 Subject: [PATCH 009/345] Fix file mapping subparameters parsin --- pom.xml | 2 +- src/main/java/org/utplsql/cli/RunCommand.java | 34 +++++++++++-------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/pom.xml b/pom.xml index 84d8161..6acefac 100644 --- a/pom.xml +++ b/pom.xml @@ -20,7 +20,7 @@ org.utplsql java-api - 1.0-Alpha1 + 1.0-SNAPSHOT compile diff --git a/src/main/java/org/utplsql/cli/RunCommand.java b/src/main/java/org/utplsql/cli/RunCommand.java index f4bec06..dd77db5 100644 --- a/src/main/java/org/utplsql/cli/RunCommand.java +++ b/src/main/java/org/utplsql/cli/RunCommand.java @@ -202,17 +202,24 @@ public List getReporterOptionsList() { public FileMapperOptions getMapperOptions(List mappingParams, List filePaths) { FileMapperOptions mapperOptions = new FileMapperOptions(filePaths); + final String OPT_OWNER="-owner="; + final String OPT_REGEX="-regex_expression="; + final String OPT_TYPE_MAPPING="-type_mapping="; + final String OPT_OWNER_SUBEX="-owner_subexpression="; + final String OPT_NAME_SUBEX="-name_subexpression="; + final String OPT_TYPE_SUBEX="-type_subexpression="; + for (String p : mappingParams) { - if (p.startsWith("-object_owner=")) { - mapperOptions.setObjectOwner(p.substring("-object_owner=".length())); + if (p.startsWith(OPT_OWNER)) { + mapperOptions.setObjectOwner(p.substring(OPT_OWNER.length())); } else - if (p.startsWith("-regex_pattern=")) { - mapperOptions.setRegexPattern(p.substring("-regex_pattern=".length())); + if (p.startsWith(OPT_REGEX)) { + mapperOptions.setRegexPattern(p.substring(OPT_REGEX.length())); } else - if (p.startsWith("-type_mapping=")) { - String typeMappingsParam = p.substring("-type_mapping=".length()); + if (p.startsWith(OPT_TYPE_MAPPING)) { + String typeMappingsParam = p.substring(OPT_TYPE_MAPPING.length()); List typeMappings = new ArrayList<>(); for (String mapping : typeMappingsParam.split("/")) { @@ -223,23 +230,20 @@ public FileMapperOptions getMapperOptions(List mappingParams, List { - public String getConnectionUrl() { - return String.format("jdbc:oracle:thin:@//%s:%d/%s", getHost(), getPort(), getDatabase()); - } - - @Override - public String toString() { - return String.format("%s@%s:%d/%s", getUser(), getHost(), getPort(), getDatabase()); + @Override + public ConnectionInfo convert(String s) { + return new ConnectionInfo(s); + } } } diff --git a/src/main/java/org/utplsql/cli/ConnectionStringConverter.java b/src/main/java/org/utplsql/cli/ConnectionStringConverter.java deleted file mode 100644 index ba8c82a..0000000 --- a/src/main/java/org/utplsql/cli/ConnectionStringConverter.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.utplsql.cli; - -import com.beust.jcommander.IStringConverter; - -/** - * Created by Vinicius on 21/04/2017. - */ -public class ConnectionStringConverter implements IStringConverter { - - @Override - public ConnectionInfo convert(String s) { - return new ConnectionInfo().parseConnectionString(s); - } -} diff --git a/src/main/java/org/utplsql/cli/RunCommand.java b/src/main/java/org/utplsql/cli/RunCommand.java index dd77db5..c6a6ea5 100644 --- a/src/main/java/org/utplsql/cli/RunCommand.java +++ b/src/main/java/org/utplsql/cli/RunCommand.java @@ -26,9 +26,10 @@ public class RunCommand { @Parameter( - required = true, converter = ConnectionStringConverter.class, + required = true, + converter = ConnectionInfo.ConnectionStringConverter.class, arity = 1, - description = "user/pass@[[host][:port]/]db") + description = "/@//[:]/ OR /@ OR /@::") private List connectionInfoList = new ArrayList<>(); @Parameter( @@ -102,8 +103,6 @@ public int run() throws Exception { testMappingOptions[0] = getMapperOptions(this.testPathParams, testFiles); } - if (testPaths.isEmpty()) testPaths.add(ci.getUser()); - // Do the reporters initialization, so we can use the id to run and gather results. try (Connection conn = ci.getConnection()) { for (ReporterOptions ro : reporterOptionsList) { diff --git a/src/test/java/org/utplsql/cli/ConnectionInfoTest.java b/src/test/java/org/utplsql/cli/ConnectionInfoTest.java index 874de69..2fdc9c4 100644 --- a/src/test/java/org/utplsql/cli/ConnectionInfoTest.java +++ b/src/test/java/org/utplsql/cli/ConnectionInfoTest.java @@ -1,9 +1,5 @@ package org.utplsql.cli; -import com.beust.jcommander.ParameterException; -import org.junit.Assert; -import org.junit.Test; - /** * Created by Vinicius on 21/04/2017. */ @@ -16,119 +12,119 @@ public class ConnectionInfoTest { * user/pass@db */ - @Test - public void valid_Full() { - try { - ConnectionInfo ci = new ConnectionInfo() - .parseConnectionString("my_user/p@ss!@some.server.123-abc.com:3000/db_1.acme.com"); - Assert.assertEquals("my_user", ci.getUser()); - Assert.assertEquals("p@ss!", ci.getPassword()); - Assert.assertEquals("some.server.123-abc.com", ci.getHost()); - Assert.assertEquals(3000, ci.getPort()); - Assert.assertEquals("db_1.acme.com", ci.getDatabase()); - Assert.assertEquals("my_user@some.server.123-abc.com:3000/db_1.acme.com", ci.toString()); - Assert.assertEquals("jdbc:oracle:thin:@//some.server.123-abc.com:3000/db_1.acme.com", ci.getConnectionUrl()); - } catch (Exception e) { - Assert.fail(e.getMessage()); - } - } - - @Test - public void valid_WithoutPort() { - try { - ConnectionInfo ci = new ConnectionInfo() - .parseConnectionString("my_user/p@ss!@some.server.123-abc.com/db_1.acme.com"); - Assert.assertEquals("my_user", ci.getUser()); - Assert.assertEquals("p@ss!", ci.getPassword()); - Assert.assertEquals("some.server.123-abc.com", ci.getHost()); - Assert.assertEquals(1521, ci.getPort()); - Assert.assertEquals("db_1.acme.com", ci.getDatabase()); - Assert.assertEquals("my_user@some.server.123-abc.com:1521/db_1.acme.com", ci.toString()); - Assert.assertEquals("jdbc:oracle:thin:@//some.server.123-abc.com:1521/db_1.acme.com", ci.getConnectionUrl()); - } catch (Exception e) { - Assert.fail(e.getMessage()); - } - } - - @Test - public void valid_WithoutHostAndPort() { - try { - ConnectionInfo ci = new ConnectionInfo() - .parseConnectionString("my_user/p@ss!@127.0.0.1/db_1.acme.com"); - Assert.assertEquals("my_user", ci.getUser()); - Assert.assertEquals("p@ss!", ci.getPassword()); - Assert.assertEquals("127.0.0.1", ci.getHost()); - Assert.assertEquals(1521, ci.getPort()); - Assert.assertEquals("db_1.acme.com", ci.getDatabase()); - Assert.assertEquals("my_user@127.0.0.1:1521/db_1.acme.com", ci.toString()); - Assert.assertEquals("jdbc:oracle:thin:@//127.0.0.1:1521/db_1.acme.com", ci.getConnectionUrl()); - } catch (Exception e) { - Assert.fail(e.getMessage()); - } - } - - @Test - public void invalid_WithoutDatabase_1() { - try { - new ConnectionInfo().parseConnectionString("user/pass@"); - Assert.fail(); - } catch (ParameterException ignored) {} - } - - @Test - public void invalid_WithoutDatabase_2() { - try { - new ConnectionInfo().parseConnectionString("user/pass"); - Assert.fail(); - } catch (ParameterException ignored) {} - } - - @Test - public void invalid_WithoutDatabase_3() { - try { - new ConnectionInfo().parseConnectionString("user/pass@localhost:1521"); - Assert.fail(); - } catch (ParameterException ignored) {} - } - - @Test - public void invalid_WithoutHost() { - try { - new ConnectionInfo().parseConnectionString("user/pass@/db"); - Assert.fail(); - } catch (ParameterException ignored) {} - } - - @Test - public void invalid_WithoutPassword() { - try { - new ConnectionInfo().parseConnectionString("user/@db"); - Assert.fail(); - } catch (ParameterException ignored) {} - } - - @Test - public void invalid_WithoutUsername() { - try { - new ConnectionInfo().parseConnectionString("/pass@db"); - Assert.fail(); - } catch (ParameterException ignored) {} - } - - @Test - public void invalid_WithoutUserPassDb_1() { - try { - new ConnectionInfo().parseConnectionString("/@db"); - Assert.fail(); - } catch (ParameterException ignored) {} - } - - @Test - public void invalid_WithoutUserPass() { - try { - new ConnectionInfo().parseConnectionString("@db"); - Assert.fail(); - } catch (ParameterException ignored) {} - } +// @Test +// public void valid_Full() { +// try { +// ConnectionInfo ci = new ConnectionInfo() +// .parseConnectionString("my_user/p@ss!@some.server.123-abc.com:3000/db_1.acme.com"); +// Assert.assertEquals("my_user", ci.getUser()); +// Assert.assertEquals("p@ss!", ci.getPassword()); +// Assert.assertEquals("some.server.123-abc.com", ci.getHost()); +// Assert.assertEquals(3000, ci.getPort()); +// Assert.assertEquals("db_1.acme.com", ci.getDatabase()); +// Assert.assertEquals("my_user@some.server.123-abc.com:3000/db_1.acme.com", ci.toString()); +// Assert.assertEquals("jdbc:oracle:thin:@//some.server.123-abc.com:3000/db_1.acme.com", ci.getConnectionUrl()); +// } catch (Exception e) { +// Assert.fail(e.getMessage()); +// } +// } +// +// @Test +// public void valid_WithoutPort() { +// try { +// ConnectionInfo ci = new ConnectionInfo() +// .parseConnectionString("my_user/p@ss!@some.server.123-abc.com/db_1.acme.com"); +// Assert.assertEquals("my_user", ci.getUser()); +// Assert.assertEquals("p@ss!", ci.getPassword()); +// Assert.assertEquals("some.server.123-abc.com", ci.getHost()); +// Assert.assertEquals(1521, ci.getPort()); +// Assert.assertEquals("db_1.acme.com", ci.getDatabase()); +// Assert.assertEquals("my_user@some.server.123-abc.com:1521/db_1.acme.com", ci.toString()); +// Assert.assertEquals("jdbc:oracle:thin:@//some.server.123-abc.com:1521/db_1.acme.com", ci.getConnectionUrl()); +// } catch (Exception e) { +// Assert.fail(e.getMessage()); +// } +// } +// +// @Test +// public void valid_WithoutHostAndPort() { +// try { +// ConnectionInfo ci = new ConnectionInfo() +// .parseConnectionString("my_user/p@ss!@127.0.0.1/db_1.acme.com"); +// Assert.assertEquals("my_user", ci.getUser()); +// Assert.assertEquals("p@ss!", ci.getPassword()); +// Assert.assertEquals("127.0.0.1", ci.getHost()); +// Assert.assertEquals(1521, ci.getPort()); +// Assert.assertEquals("db_1.acme.com", ci.getDatabase()); +// Assert.assertEquals("my_user@127.0.0.1:1521/db_1.acme.com", ci.toString()); +// Assert.assertEquals("jdbc:oracle:thin:@//127.0.0.1:1521/db_1.acme.com", ci.getConnectionUrl()); +// } catch (Exception e) { +// Assert.fail(e.getMessage()); +// } +// } +// +// @Test +// public void invalid_WithoutDatabase_1() { +// try { +// new ConnectionInfo().parseConnectionString("user/pass@"); +// Assert.fail(); +// } catch (ParameterException ignored) {} +// } +// +// @Test +// public void invalid_WithoutDatabase_2() { +// try { +// new ConnectionInfo().parseConnectionString("user/pass"); +// Assert.fail(); +// } catch (ParameterException ignored) {} +// } +// +// @Test +// public void invalid_WithoutDatabase_3() { +// try { +// new ConnectionInfo().parseConnectionString("user/pass@localhost:1521"); +// Assert.fail(); +// } catch (ParameterException ignored) {} +// } +// +// @Test +// public void invalid_WithoutHost() { +// try { +// new ConnectionInfo().parseConnectionString("user/pass@/db"); +// Assert.fail(); +// } catch (ParameterException ignored) {} +// } +// +// @Test +// public void invalid_WithoutPassword() { +// try { +// new ConnectionInfo().parseConnectionString("user/@db"); +// Assert.fail(); +// } catch (ParameterException ignored) {} +// } +// +// @Test +// public void invalid_WithoutUsername() { +// try { +// new ConnectionInfo().parseConnectionString("/pass@db"); +// Assert.fail(); +// } catch (ParameterException ignored) {} +// } +// +// @Test +// public void invalid_WithoutUserPassDb_1() { +// try { +// new ConnectionInfo().parseConnectionString("/@db"); +// Assert.fail(); +// } catch (ParameterException ignored) {} +// } +// +// @Test +// public void invalid_WithoutUserPass() { +// try { +// new ConnectionInfo().parseConnectionString("@db"); +// Assert.fail(); +// } catch (ParameterException ignored) {} +// } } From 5e67253e99b9e566ceb4fd6963d5e905842f4e38 Mon Sep 17 00:00:00 2001 From: Vinicius Avellar Date: Tue, 26 Sep 2017 23:41:28 +0100 Subject: [PATCH 011/345] Using a PoolDataSource to get the connections --- src/main/java/org/utplsql/cli/ConnectionInfo.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/utplsql/cli/ConnectionInfo.java b/src/main/java/org/utplsql/cli/ConnectionInfo.java index 7f64955..287f989 100644 --- a/src/main/java/org/utplsql/cli/ConnectionInfo.java +++ b/src/main/java/org/utplsql/cli/ConnectionInfo.java @@ -1,10 +1,11 @@ package org.utplsql.cli; import com.beust.jcommander.IStringConverter; +import oracle.ucp.jdbc.PoolDataSource; +import oracle.ucp.jdbc.PoolDataSourceFactory; import java.io.File; import java.sql.Connection; -import java.sql.DriverManager; import java.sql.SQLException; public class ConnectionInfo { @@ -17,14 +18,20 @@ public class ConnectionInfo { } } - private String connectionInfo; + private PoolDataSource pds = PoolDataSourceFactory.getPoolDataSource(); public ConnectionInfo(String connectionInfo) { - this.connectionInfo = connectionInfo; + try { + this.pds.setConnectionFactoryClassName("oracle.jdbc.pool.OracleDataSource"); + this.pds.setURL("jdbc:oracle:thin:" + connectionInfo); + this.pds.setInitialPoolSize(2); + } catch (SQLException e) { + e.printStackTrace(); + } } public Connection getConnection() throws SQLException { - return DriverManager.getConnection("jdbc:oracle:thin:" + this.connectionInfo); + return pds.getConnection(); } public static class ConnectionStringConverter implements IStringConverter { From abf5256bd2a211a0ba506583ebc8cd65991842be Mon Sep 17 00:00:00 2001 From: pesse Date: Wed, 8 Nov 2017 23:08:02 +0100 Subject: [PATCH 012/345] Very simple fail-fast if DB framework is not compatible --- pom.xml | 4 ++-- src/main/java/org/utplsql/cli/RunCommand.java | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 6acefac..06d2aba 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.utplsql cli - 1.0-SNAPSHOT + 3.0.3-SNAPSHOT jar cli @@ -20,7 +20,7 @@ org.utplsql java-api - 1.0-SNAPSHOT + 3.0.3-SNAPSHOT compile diff --git a/src/main/java/org/utplsql/cli/RunCommand.java b/src/main/java/org/utplsql/cli/RunCommand.java index dd77db5..444c441 100644 --- a/src/main/java/org/utplsql/cli/RunCommand.java +++ b/src/main/java/org/utplsql/cli/RunCommand.java @@ -3,6 +3,7 @@ import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; import org.utplsql.api.*; +import org.utplsql.api.exception.DatabaseNotCompatibleException; import org.utplsql.api.exception.SomeTestsFailedException; import org.utplsql.api.reporter.Reporter; import org.utplsql.api.reporter.ReporterFactory; @@ -80,6 +81,9 @@ public List getTestPaths() { public int run() throws Exception { final ConnectionInfo ci = getConnectionInfo(); + // First of all do a compatibility check and fail-fast + checkFrameworkCompatibility(ci); + final List reporterOptionsList = getReporterOptionsList(); final List testPaths = getTestPaths(); final List reporterList = new ArrayList<>(); @@ -199,6 +203,19 @@ public List getReporterOptionsList() { return reporterOptionsList; } + private void checkFrameworkCompatibility(ConnectionInfo ci) throws SQLException { + try + { + DBHelper.failOnVersionCompatibilityCheckFailed(ci.getConnection()); + } + catch ( DatabaseNotCompatibleException e ) + { + System.out.println(e.getMessage()); + + throw e; + } + } + public FileMapperOptions getMapperOptions(List mappingParams, List filePaths) { FileMapperOptions mapperOptions = new FileMapperOptions(filePaths); From a51488198d445600db35813456edca0a64f08db5 Mon Sep 17 00:00:00 2001 From: pesse Date: Thu, 9 Nov 2017 12:04:03 +0100 Subject: [PATCH 013/345] Added -scc/--skip-compatibility-check option If option is on, cli expects the most actual framework version to be present --- pom.xml | 4 +-- src/main/java/org/utplsql/cli/RunCommand.java | 30 ++++++++++++++----- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index 06d2aba..cda5e7f 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.utplsql cli - 3.0.3-SNAPSHOT + 3.0.4-SNAPSHOT jar cli @@ -20,7 +20,7 @@ org.utplsql java-api - 3.0.3-SNAPSHOT + 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 444c441..1ac1dc1 100644 --- a/src/main/java/org/utplsql/cli/RunCommand.java +++ b/src/main/java/org/utplsql/cli/RunCommand.java @@ -22,6 +22,9 @@ /** * Created by vinicius.moreira on 19/04/2017. + * + * @author vinicious moreira + * @author pesse */ @Parameters(separators = "=", commandDescription = "run tests") public class RunCommand { @@ -70,6 +73,12 @@ public class RunCommand { "-name_subexpression=0] - path to project test files") private List testPathParams = new ArrayList<>(); + @Parameter( + names = {"-scc", "--skip-compatibility-check"}, + description = "Skips the check for compatibility with database framework. CLI expects the framework to be " + + "most actual. Use this if you use CLI with a development version of utPLSQL-framework") + private boolean skipCompatibilityCheck = false; + public ConnectionInfo getConnectionInfo() { return connectionInfoList.get(0); } @@ -133,6 +142,7 @@ public int run() throws Exception { .testMappingOptions(testMappingOptions[0]) .colorConsole(this.colorConsole) .failOnErrors(true) + .skipCompatibilityCheck(skipCompatibilityCheck) .run(conn); } catch (SomeTestsFailedException e) { returnCode[0] = this.failureExitCode; @@ -204,15 +214,19 @@ public List getReporterOptionsList() { } private void checkFrameworkCompatibility(ConnectionInfo ci) throws SQLException { - try - { - DBHelper.failOnVersionCompatibilityCheckFailed(ci.getConnection()); - } - catch ( DatabaseNotCompatibleException e ) - { - System.out.println(e.getMessage()); - throw e; + if ( !skipCompatibilityCheck ) { + try { + DBHelper.failOnVersionCompatibilityCheckFailed(ci.getConnection()); + } catch (DatabaseNotCompatibleException e) { + System.out.println(e.getMessage()); + + throw e; + } + } + else { + System.out.println("Skipping Compatibility check with framework version, expecting the latest version " + + "to be installed in database"); } } From d46bc3f61381011d234b0e596a6761237023b160 Mon Sep 17 00:00:00 2001 From: pesse Date: Thu, 9 Nov 2017 16:31:10 +0100 Subject: [PATCH 014/345] Update documentation --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 07addd8..759d528 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,10 @@ You can download development versions on [Bintray](https://bintray.com/viniciusa * [Java SE Runtime Environment 8](http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html) * When using reporters for Sonar or Coveralls client needs to be invoked from project's root directory. +## Compatibility +The latest CLI is always compatible with all database frameworks of the same major 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. + ## Usage utplsql run user/pass@[[host][:port]/]db [-p=(ut_path|ut_paths)] [-f=format [-o=output_file] [-s] ...] @@ -77,6 +81,8 @@ db - Database to connect to. -c - If specified, enables printing of test results in colors as defined by ANSICONSOLE standards. Works only on reporeters that support colors (ut_documentation_reporter). --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 ``` Parameters -f, -o, -s are correlated. That is parameters -o and -s are controlling outputs for reporter specified by the preceding -f parameter. From 5401f35cc3c70a8cf2f21e5fe25f42751a46c449 Mon Sep 17 00:00:00 2001 From: pesse Date: Fri, 10 Nov 2017 16:52:15 +0100 Subject: [PATCH 015/345] Removed Oracle libaries from release Included check for specific classes. Needs some refactoring for we only want to check for orai18n when database is 11g --- .travis/create_release.sh | 4 ++ .../org/utplsql/cli/OracleLibraryChecker.java | 39 +++++++++++++++++++ src/main/java/org/utplsql/cli/RunCommand.java | 26 +++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 src/main/java/org/utplsql/cli/OracleLibraryChecker.java diff --git a/.travis/create_release.sh b/.travis/create_release.sh index 8daebe9..78c9788 100644 --- a/.travis/create_release.sh +++ b/.travis/create_release.sh @@ -5,6 +5,10 @@ VERSION=`date +%Y%m%d%H%M` mkdir dist mv target/appassembler utPLSQL-cli +# Remove Oracle libraries du to licensing problems +rm utPLSQL-cli/lib/ojdbc8* +rm utPLSQL-cli/lib/orai18n* + zip -r -q dist/utPLSQL-cli-${TRAVIS_BRANCH}-${VERSION}.zip utPLSQL-cli cat > bintray.json < getTestPaths() { } public int run() throws Exception { + + checkOracleLibrariesExist(); + final ConnectionInfo ci = getConnectionInfo(); final List reporterOptionsList = getReporterOptionsList(); @@ -246,4 +249,27 @@ public FileMapperOptions getMapperOptions(List mappingParams, List Date: Sat, 11 Nov 2017 00:21:00 +0100 Subject: [PATCH 016/345] Little bit of refactoring we don't want to have another open connection, do we? --- src/main/java/org/utplsql/cli/RunCommand.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/utplsql/cli/RunCommand.java b/src/main/java/org/utplsql/cli/RunCommand.java index ede1ffc..9460225 100644 --- a/src/main/java/org/utplsql/cli/RunCommand.java +++ b/src/main/java/org/utplsql/cli/RunCommand.java @@ -91,8 +91,6 @@ public List getTestPaths() { public int run() throws Exception { final ConnectionInfo ci = getConnectionInfo(); - // First of all do a compatibility check and fail-fast - checkFrameworkCompatibility(ci); final List reporterOptionsList = getReporterOptionsList(); final List testPaths = getTestPaths(); @@ -118,6 +116,10 @@ public int run() throws Exception { // Do the reporters initialization, so we can use the id to run and gather results. try (Connection conn = ci.getConnection()) { + + // First of all do a compatibility check and fail-fast + checkFrameworkCompatibility(conn); + for (ReporterOptions ro : reporterOptionsList) { Reporter reporter = ReporterFactory.createReporter(ro.getReporterName()); reporter.init(conn); @@ -212,11 +214,16 @@ public List getReporterOptionsList() { return reporterOptionsList; } - private void checkFrameworkCompatibility(ConnectionInfo ci) throws SQLException { + /** Checks whether cli is compatible with the database framework + * + * @param conn Active Connection + * @throws SQLException + */ + private void checkFrameworkCompatibility(Connection conn) throws SQLException { if ( !skipCompatibilityCheck ) { try { - DBHelper.failOnVersionCompatibilityCheckFailed(ci.getConnection()); + DBHelper.failOnVersionCompatibilityCheckFailed(conn); } catch (DatabaseNotCompatibleException e) { System.out.println(e.getMessage()); From 7617e789f66b8dbf981e0a6bc3b774ce5f0d2782 Mon Sep 17 00:00:00 2001 From: pesse Date: Sat, 11 Nov 2017 00:59:34 +0100 Subject: [PATCH 017/345] Refactoring aiming for single-responsibility and IOSP Not yet there, but a bit cleaner. Also added run-Test --- src/main/java/org/utplsql/cli/RunCommand.java | 81 ++++++++++++++----- .../java/org/utplsql/cli/RunCommandTest.java | 23 ++++++ 2 files changed, 82 insertions(+), 22 deletions(-) diff --git a/src/main/java/org/utplsql/cli/RunCommand.java b/src/main/java/org/utplsql/cli/RunCommand.java index 9460225..a1b7035 100644 --- a/src/main/java/org/utplsql/cli/RunCommand.java +++ b/src/main/java/org/utplsql/cli/RunCommand.java @@ -91,10 +91,9 @@ public List getTestPaths() { public int run() throws Exception { final ConnectionInfo ci = getConnectionInfo(); - + final List reporterList; final List reporterOptionsList = getReporterOptionsList(); final List testPaths = getTestPaths(); - final List reporterList = new ArrayList<>(); final File baseDir = new File("").getAbsoluteFile(); final FileMapperOptions[] sourceMappingOptions = {null}; @@ -102,17 +101,8 @@ public int run() throws Exception { final int[] returnCode = {0}; - if (!this.sourcePathParams.isEmpty()) { - String sourcePath = this.sourcePathParams.get(0); - List sourceFiles = new FileWalker().getFileList(baseDir, sourcePath); - sourceMappingOptions[0] = getMapperOptions(this.sourcePathParams, sourceFiles); - } - - if (!this.testPathParams.isEmpty()) { - String testPath = this.testPathParams.get(0); - List testFiles = new FileWalker().getFileList(baseDir, testPath); - testMappingOptions[0] = getMapperOptions(this.testPathParams, testFiles); - } + sourceMappingOptions[0] = getFileMapperOptionsByParamListItem(this.sourcePathParams, baseDir); + testMappingOptions[0] = getFileMapperOptionsByParamListItem(this.testPathParams, baseDir); // Do the reporters initialization, so we can use the id to run and gather results. try (Connection conn = ci.getConnection()) { @@ -120,12 +110,8 @@ public int run() throws Exception { // First of all do a compatibility check and fail-fast checkFrameworkCompatibility(conn); - for (ReporterOptions ro : reporterOptionsList) { - Reporter reporter = ReporterFactory.createReporter(ro.getReporterName()); - reporter.init(conn); - ro.setReporterObj(reporter); - reporterList.add(reporter); - } + reporterList = initReporters(conn, reporterOptionsList); + } catch (SQLException e) { System.out.println(e.getMessage()); return Cli.DEFAULT_ERROR_CODE; @@ -154,6 +140,44 @@ public int run() throws Exception { } }); + // Gather each reporter results on a separate thread. + startReporterGatherers(reporterOptionsList, executorService, ci, returnCode); + + executorService.shutdown(); + executorService.awaitTermination(60, TimeUnit.MINUTES); + return returnCode[0]; + } + + /** Initializes the reporters so we can use the id to gather results + * + * @param conn Active Connection + * @param reporterOptionsList + * @return List of Reporters + * @throws SQLException + */ + private List initReporters( Connection conn, List reporterOptionsList ) throws SQLException + { + final List reporterList = new ArrayList<>(); + + for (ReporterOptions ro : reporterOptionsList) { + Reporter reporter = ReporterFactory.createReporter(ro.getReporterName()); + reporter.init(conn); + ro.setReporterObj(reporter); + reporterList.add(reporter); + } + + return reporterList; + } + + /** Starts a separate thread for each Reporter to gather its results + * + * @param reporterOptionsList + * @param executorService + * @param ci + * @param returnCode + */ + private void startReporterGatherers(List reporterOptionsList, ExecutorService executorService, final ConnectionInfo ci, final int[] returnCode) + { // Gather each reporter results on a separate thread. for (ReporterOptions ro : reporterOptionsList) { executorService.submit(() -> { @@ -181,10 +205,23 @@ public int run() throws Exception { } }); } + } - executorService.shutdown(); - executorService.awaitTermination(60, TimeUnit.MINUTES); - return returnCode[0]; + /** Returns FileMapperOptions for the first item of a given param list in a baseDir + * + * @param pathParams + * @param baseDir + * @return FileMapperOptions or null + */ + private FileMapperOptions getFileMapperOptionsByParamListItem(List pathParams, File baseDir ) + { + if (!pathParams.isEmpty()) { + String sourcePath = pathParams.get(0); + List files = new FileWalker().getFileList(baseDir, sourcePath); + return getMapperOptions(pathParams, files); + } + + return null; } public List getReporterOptionsList() { diff --git a/src/test/java/org/utplsql/cli/RunCommandTest.java b/src/test/java/org/utplsql/cli/RunCommandTest.java index 66a1e2b..7b039bb 100644 --- a/src/test/java/org/utplsql/cli/RunCommandTest.java +++ b/src/test/java/org/utplsql/cli/RunCommandTest.java @@ -12,6 +12,16 @@ */ 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(); @@ -96,4 +106,17 @@ public void reporterOptions_TwoReporters() { Assert.assertTrue(reporterOptions2.outputToScreen()); } + @Test + public void run_Default() { + RunCommand runCmd = createRunCommand(sUser + "/" + sPass + "@" + sUrl); + + try { + int result = runCmd.run(); + Assert.assertEquals(0, result); + } + catch ( Exception e ) { + Assert.fail(e.getMessage()); + } + } + } From e32a71dd56b468b16a1176964f2ff7c902029e7b Mon Sep 17 00:00:00 2001 From: pesse Date: Sat, 11 Nov 2017 13:47:48 +0100 Subject: [PATCH 018/345] Just copied the travis settings from api project don't understand them all yet, but let's see if it works --- .travis.yml | 20 ++++++++++++--- .travis/create_api_user.sh | 17 +++++++++++++ .travis/install_demo_project.sh | 44 +++++++++++++++++++++++++++++++++ .travis/install_utplsql.sh | 36 +++++++++++++++++++++++++++ .travis/start_db.sh | 14 +++++++++++ 5 files changed, 128 insertions(+), 3 deletions(-) create mode 100644 .travis/create_api_user.sh create mode 100644 .travis/install_demo_project.sh create mode 100644 .travis/install_utplsql.sh create mode 100644 .travis/start_db.sh diff --git a/.travis.yml b/.travis.yml index 5833ca6..f008bd6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,22 +1,36 @@ sudo: required language: java +services: + - docker + jdk: - oraclejdk8 env: global: - - CACHE_DIR=$HOME/.cache - - MAVEN_HOME=/usr/local/maven - - MAVEN_CFG=$HOME/.m2 + - DOCKER_CFG=$HOME/.docker + - DOCKER_REPO="viniciusam/oracledb" + - CACHE_DIR=$HOME/.cache + - MAVEN_HOME=/usr/local/maven + - MAVEN_CFG=$HOME/.m2 + - DB_URL="127.0.0.1:1521:XE" + - DB_USER=app + - DB_PASS=app + matrix: + - ORACLE_VERSION="11g-xe-r2" DOCKER_OPTIONS="--shm-size=1g" cache: directories: + - $DOCKER_CFG - $CACHE_DIR - $MAVEN_CFG install: - bash .travis/maven_cfg.sh + - bash .travis/start_db.sh + - bash .travis/install_utplsql.sh + - bash .travis/install_demo_project.sh script: - mvn package -DskipTests diff --git a/.travis/create_api_user.sh b/.travis/create_api_user.sh new file mode 100644 index 0000000..c898f15 --- /dev/null +++ b/.travis/create_api_user.sh @@ -0,0 +1,17 @@ +#!/bin/bash +set -ev + +sqlplus -S -L sys/oracle@//127.0.0.1:1521/xe AS SYSDBA < demo_project.sh.tmp < install.sh.tmp < Date: Sat, 11 Nov 2017 13:50:30 +0100 Subject: [PATCH 019/345] Trial and error. Something's not working yet --- .travis.yml | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index f008bd6..fa0e134 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,16 +9,16 @@ jdk: env: global: - - DOCKER_CFG=$HOME/.docker - - DOCKER_REPO="viniciusam/oracledb" - - CACHE_DIR=$HOME/.cache - - MAVEN_HOME=/usr/local/maven - - MAVEN_CFG=$HOME/.m2 - - DB_URL="127.0.0.1:1521:XE" - - DB_USER=app - - DB_PASS=app - matrix: - - ORACLE_VERSION="11g-xe-r2" DOCKER_OPTIONS="--shm-size=1g" + - DOCKER_CFG=$HOME/.docker + - DOCKER_REPO="viniciusam/oracledb" + - CACHE_DIR=$HOME/.cache + - MAVEN_HOME=/usr/local/maven + - MAVEN_CFG=$HOME/.m2 + - DB_URL="127.0.0.1:1521:XE" + - DB_USER=app + - DB_PASS=app + matrix: + - ORACLE_VERSION="11g-xe-r2" DOCKER_OPTIONS="--shm-size=1g" cache: directories: @@ -28,9 +28,9 @@ cache: install: - bash .travis/maven_cfg.sh - - bash .travis/start_db.sh - - bash .travis/install_utplsql.sh - - bash .travis/install_demo_project.sh + - bash .travis/start_db.sh + - bash .travis/install_utplsql.sh + - bash .travis/install_demo_project.sh script: - mvn package -DskipTests From 286cdba93d0f4e413dc3a6b300705b9c20ddd3f1 Mon Sep 17 00:00:00 2001 From: pesse Date: Sat, 11 Nov 2017 14:25:38 +0100 Subject: [PATCH 020/345] Adjusted default run-Test and refactoring --- .../java/org/utplsql/cli/RunCommandTest.java | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/test/java/org/utplsql/cli/RunCommandTest.java b/src/test/java/org/utplsql/cli/RunCommandTest.java index 7b039bb..7f976b0 100644 --- a/src/test/java/org/utplsql/cli/RunCommandTest.java +++ b/src/test/java/org/utplsql/cli/RunCommandTest.java @@ -33,9 +33,13 @@ private RunCommand createRunCommand(String... args) { return runCmd; } + private String getConnectionString() { + return sUser + "/" + sPass + "@" + sUrl; + } + @Test public void reporterOptions_Default() { - RunCommand runCmd = createRunCommand("app/app@xe"); + RunCommand runCmd = createRunCommand(getConnectionString()); List reporterOptionsList = runCmd.getReporterOptionsList(); @@ -48,7 +52,7 @@ public void reporterOptions_Default() { @Test public void reporterOptions_OneReporter() { - RunCommand runCmd = createRunCommand("app/app@xe", "-f=ut_documentation_reporter", "-o=output.txt"); + RunCommand runCmd = createRunCommand(getConnectionString(), "-f=ut_documentation_reporter", "-o=output.txt"); List reporterOptionsList = runCmd.getReporterOptionsList(); @@ -61,7 +65,7 @@ public void reporterOptions_OneReporter() { @Test public void reporterOptions_OneReporterForceScreen() { - RunCommand runCmd = createRunCommand("app/app@xe", "-f=ut_documentation_reporter", "-o=output.txt", "-s"); + RunCommand runCmd = createRunCommand(getConnectionString(), "-f=ut_documentation_reporter", "-o=output.txt", "-s"); List reporterOptionsList = runCmd.getReporterOptionsList(); @@ -74,7 +78,7 @@ public void reporterOptions_OneReporterForceScreen() { @Test public void reporterOptions_OneReporterForceScreenInverse() { - RunCommand runCmd = createRunCommand("app/app@xe", "-f=ut_documentation_reporter", "-s", "-o=output.txt"); + RunCommand runCmd = createRunCommand(getConnectionString(), "-f=ut_documentation_reporter", "-s", "-o=output.txt"); List reporterOptionsList = runCmd.getReporterOptionsList(); @@ -87,7 +91,7 @@ public void reporterOptions_OneReporterForceScreenInverse() { @Test public void reporterOptions_TwoReporters() { - RunCommand runCmd = createRunCommand("app/app@xe", + RunCommand runCmd = createRunCommand(getConnectionString(), "-f=ut_documentation_reporter", "-f=ut_coverage_html_reporter", "-o=coverage.html", "-s"); @@ -108,11 +112,14 @@ public void reporterOptions_TwoReporters() { @Test public void run_Default() { - RunCommand runCmd = createRunCommand(sUser + "/" + sPass + "@" + sUrl); + RunCommand runCmd = createRunCommand(getConnectionString(), + "-f=ut_documentation_reporter", + "-c", + "--failure-exit-code=2"); try { int result = runCmd.run(); - Assert.assertEquals(0, result); + Assert.assertEquals(2, result); } catch ( Exception e ) { Assert.fail(e.getMessage()); From b4ef181c979b6a241b07c08f503981c4214a3ecf Mon Sep 17 00:00:00 2001 From: pesse Date: Sat, 11 Nov 2017 14:33:50 +0100 Subject: [PATCH 021/345] Removed repo variable --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index fa0e134..d43cf3b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,6 @@ jdk: env: global: - DOCKER_CFG=$HOME/.docker - - DOCKER_REPO="viniciusam/oracledb" - CACHE_DIR=$HOME/.cache - MAVEN_HOME=/usr/local/maven - MAVEN_CFG=$HOME/.m2 From 22a560311bf02819e78f026dfcb4d46f37a71236 Mon Sep 17 00:00:00 2001 From: pesse Date: Sun, 12 Nov 2017 14:44:34 +0100 Subject: [PATCH 022/345] Only check for orai18n when we are on a 11g database the library is not needed for 12c --- .../java/org/utplsql/cli/ConnectionInfo.java | 40 +++++++++++++++++++ src/main/java/org/utplsql/cli/RunCommand.java | 21 +++++++--- 2 files changed, 55 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/utplsql/cli/ConnectionInfo.java b/src/main/java/org/utplsql/cli/ConnectionInfo.java index 287f989..4f76f81 100644 --- a/src/main/java/org/utplsql/cli/ConnectionInfo.java +++ b/src/main/java/org/utplsql/cli/ConnectionInfo.java @@ -6,10 +6,14 @@ import java.io.File; import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; import java.sql.SQLException; public class ConnectionInfo { + private String databaseVersion; + static { String oracleHome = System.getenv("ORACLE_HOME"); if (oracleHome != null) { @@ -42,4 +46,40 @@ public ConnectionInfo convert(String s) { } } + public String getOracleDatabaseVersion() throws SQLException + { + try ( Connection conn = getConnection() ) { + return getOracleDatabaseVersion(conn); + } + } + + public String getOracleDatabaseVersion( Connection conn ) throws SQLException + { + if ( databaseVersion == null ) { + databaseVersion = getOracleDatabaseVersionFromConnection( conn ); + } + + return databaseVersion; + } + + /** TODO: Outsource this to Java-API + * + * @param conn + * @return + * @throws SQLException + */ + public static String getOracleDatabaseVersionFromConnection( Connection conn ) throws SQLException { + assert conn != null; + String result = null; + try (PreparedStatement stmt = conn.prepareStatement("select version from product_component_version where product like 'Oracle Database%'")) + { + ResultSet rs = stmt.executeQuery(); + + if ( rs.next() ) + result = rs.getString(1); + } + + return result; + } + } diff --git a/src/main/java/org/utplsql/cli/RunCommand.java b/src/main/java/org/utplsql/cli/RunCommand.java index 6cc18ee..b81e189 100644 --- a/src/main/java/org/utplsql/cli/RunCommand.java +++ b/src/main/java/org/utplsql/cli/RunCommand.java @@ -90,7 +90,7 @@ public List getTestPaths() { public int run() throws Exception { - checkOracleLibrariesExist(); + checkOracleJDBCExists(); final ConnectionInfo ci = getConnectionInfo(); @@ -110,6 +110,9 @@ public int run() throws Exception { // Do the reporters initialization, so we can use the id to run and gather results. try (Connection conn = ci.getConnection()) { + // Check if orai18n exists if database version is 11g + checkOracleI18nExists(ci.getOracleDatabaseVersion(conn)); + // First of all do a compatibility check and fail-fast checkFrameworkCompatibility(conn); @@ -324,10 +327,10 @@ public FileMapperOptions getMapperOptions(List mappingParams, List Date: Sun, 12 Nov 2017 14:48:20 +0100 Subject: [PATCH 023/345] Updated documentation --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index a98c171..973b531 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,9 @@ You can download development versions on [Bintray](https://bintray.com/viniciusa ## Requirements * [Java SE Runtime Environment 8](http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html) * When using reporters for Sonar or Coveralls client needs to be invoked from project's root directory. +* Due to Oracle license we can't ship the necessary oracle libraries directly with utPLSQL-cli. Please download the libraries directly from oracle website and put the jars into the "lib" folder of your utPLSQL-cli installation + * Oracle JDBC driver: http://www.oracle.com/technetwork/database/features/jdbc/jdbc-ucp-122-3110062.html + * If you are on a 11g database you might need the orai18n library, too: http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-112010-090769.html ## Compatibility The latest CLI is always compatible with all database frameworks of the same major version. From 71f63874d7c2d2fe5eda3a2e9a56735cdd1d27d1 Mon Sep 17 00:00:00 2001 From: Jacek Date: Wed, 15 Nov 2017 07:07:32 +0000 Subject: [PATCH 024/345] Added github releases uploader --- .travis.yml | 18 ++++++++++++------ .travis/create_release.sh | 1 + 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5833ca6..a1888b9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,9 +26,15 @@ before_deploy: - bash .travis/create_release.sh deploy: - provider: bintray - file: bintray.json - user: $BINTRAY_USER - key: $BINTRAY_API_KEY - dry-run: false - on: develop + - provider: releases + api_key: $github_api_token + file: utPLSQL-cli.zip + skip_cleanup: true + on: + tags: true + - provider: bintray + file: bintray.json + user: $BINTRAY_USER + key: $BINTRAY_API_KEY + dry-run: false + on: develop diff --git a/.travis/create_release.sh b/.travis/create_release.sh index 8daebe9..b681e40 100644 --- a/.travis/create_release.sh +++ b/.travis/create_release.sh @@ -6,6 +6,7 @@ VERSION=`date +%Y%m%d%H%M` mkdir dist mv target/appassembler utPLSQL-cli zip -r -q dist/utPLSQL-cli-${TRAVIS_BRANCH}-${VERSION}.zip utPLSQL-cli +zip -r -q utPLSQL-cli.zip utPLSQL-cli cat > bintray.json < Date: Wed, 15 Nov 2017 07:15:08 +0000 Subject: [PATCH 025/345] Added github releases uploader --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a1888b9..46d779c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,7 +27,7 @@ before_deploy: deploy: - provider: releases - api_key: $github_api_token + api_key: $GITHUB_API_TOKEN file: utPLSQL-cli.zip skip_cleanup: true on: From 878ea272c59c2668a5a5e937d50190144994662b Mon Sep 17 00:00:00 2001 From: Jacek Date: Wed, 15 Nov 2017 23:51:27 +0000 Subject: [PATCH 026/345] Added missing DOCKER_REPO variable --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 34e30b6..eb7d563 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,7 @@ jdk: env: global: - DOCKER_CFG=$HOME/.docker + - DOCKER_REPO="utplsqlv3/oracledb" - CACHE_DIR=$HOME/.cache - MAVEN_HOME=/usr/local/maven - MAVEN_CFG=$HOME/.m2 From 864a06514cf5767fbb5460ce2b138d2370acecdc Mon Sep 17 00:00:00 2001 From: Jacek Date: Wed, 15 Nov 2017 23:52:27 +0000 Subject: [PATCH 027/345] Removed matrix as only one DB version is used. --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index eb7d563..785e83d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,8 +17,8 @@ env: - DB_URL="127.0.0.1:1521:XE" - DB_USER=app - DB_PASS=app - matrix: - - ORACLE_VERSION="11g-xe-r2" DOCKER_OPTIONS="--shm-size=1g" + - ORACLE_VERSION="11g-xe-r2" + - DOCKER_OPTIONS="--shm-size=1g" cache: directories: From 6c22ad05820c4ed0d6802cc9d00e0b301b82932e Mon Sep 17 00:00:00 2001 From: Jacek Date: Wed, 15 Nov 2017 23:58:28 +0000 Subject: [PATCH 028/345] Fixed oracle image name for utplsqlv3 repo --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 785e83d..9fca880 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,7 +17,7 @@ env: - DB_URL="127.0.0.1:1521:XE" - DB_USER=app - DB_PASS=app - - ORACLE_VERSION="11g-xe-r2" + - ORACLE_VERSION="11g-r2-xe" - DOCKER_OPTIONS="--shm-size=1g" cache: From b972be1cc7fe56b602fc9fa77f445292956b49f8 Mon Sep 17 00:00:00 2001 From: pesse Date: Thu, 16 Nov 2017 15:27:57 +0100 Subject: [PATCH 029/345] Using new API Compatibility check Let CLI exit gracefully when versions not compatible --- src/main/java/org/utplsql/cli/Cli.java | 3 +++ src/main/java/org/utplsql/cli/RunCommand.java | 11 ++++------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/utplsql/cli/Cli.java b/src/main/java/org/utplsql/cli/Cli.java index 4ea8652..c173ae3 100644 --- a/src/main/java/org/utplsql/cli/Cli.java +++ b/src/main/java/org/utplsql/cli/Cli.java @@ -3,6 +3,7 @@ import com.beust.jcommander.JCommander; import com.beust.jcommander.Parameter; import com.beust.jcommander.ParameterException; +import org.utplsql.api.exception.DatabaseNotCompatibleException; public class Cli { @@ -34,6 +35,8 @@ public static void main(String[] args) { } else { jc.usage(); } + } catch ( DatabaseNotCompatibleException e ) { + System.out.println(e.getMessage()); } catch (Exception e) { e.printStackTrace(); } diff --git a/src/main/java/org/utplsql/cli/RunCommand.java b/src/main/java/org/utplsql/cli/RunCommand.java index b81e189..3d7dd50 100644 --- a/src/main/java/org/utplsql/cli/RunCommand.java +++ b/src/main/java/org/utplsql/cli/RunCommand.java @@ -3,6 +3,7 @@ import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; import org.utplsql.api.*; +import org.utplsql.api.compatibility.CompatibilityProxy; import org.utplsql.api.exception.DatabaseNotCompatibleException; import org.utplsql.api.exception.SomeTestsFailedException; import org.utplsql.api.reporter.Reporter; @@ -264,14 +265,10 @@ public List getReporterOptionsList() { */ private void checkFrameworkCompatibility(Connection conn) throws SQLException { - if ( !skipCompatibilityCheck ) { - try { - DBHelper.failOnVersionCompatibilityCheckFailed(conn); - } catch (DatabaseNotCompatibleException e) { - System.out.println(e.getMessage()); + CompatibilityProxy proxy = new CompatibilityProxy(conn, skipCompatibilityCheck); - throw e; - } + if ( !skipCompatibilityCheck ) { + proxy.failOnNotCompatible(); } else { System.out.println("Skipping Compatibility check with framework version, expecting the latest version " + From c140c5e58e02b90689a91734d926df16586f0dc6 Mon Sep 17 00:00:00 2001 From: pesse Date: Fri, 17 Nov 2017 10:32:32 +0100 Subject: [PATCH 030/345] Shutdown cli gracefully when known exceptions occur Fixes #44 --- src/main/java/org/utplsql/cli/Cli.java | 4 +++- src/main/java/org/utplsql/cli/RunCommand.java | 9 +++++++-- .../cli/exception/DatabaseConnectionFailed.java | 10 ++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 src/main/java/org/utplsql/cli/exception/DatabaseConnectionFailed.java diff --git a/src/main/java/org/utplsql/cli/Cli.java b/src/main/java/org/utplsql/cli/Cli.java index c173ae3..bdfbac3 100644 --- a/src/main/java/org/utplsql/cli/Cli.java +++ b/src/main/java/org/utplsql/cli/Cli.java @@ -4,6 +4,8 @@ import com.beust.jcommander.Parameter; import com.beust.jcommander.ParameterException; import org.utplsql.api.exception.DatabaseNotCompatibleException; +import org.utplsql.api.exception.UtPLSQLNotInstalledException; +import org.utplsql.cli.exception.DatabaseConnectionFailed; public class Cli { @@ -35,7 +37,7 @@ public static void main(String[] args) { } else { jc.usage(); } - } catch ( DatabaseNotCompatibleException e ) { + } catch ( DatabaseNotCompatibleException | UtPLSQLNotInstalledException | DatabaseConnectionFailed e ) { System.out.println(e.getMessage()); } catch (Exception e) { e.printStackTrace(); diff --git a/src/main/java/org/utplsql/cli/RunCommand.java b/src/main/java/org/utplsql/cli/RunCommand.java index 3d7dd50..a03045c 100644 --- a/src/main/java/org/utplsql/cli/RunCommand.java +++ b/src/main/java/org/utplsql/cli/RunCommand.java @@ -8,6 +8,7 @@ import org.utplsql.api.exception.SomeTestsFailedException; import org.utplsql.api.reporter.Reporter; import org.utplsql.api.reporter.ReporterFactory; +import org.utplsql.cli.exception.DatabaseConnectionFailed; import java.io.File; import java.io.FileNotFoundException; @@ -120,8 +121,12 @@ public int run() throws Exception { reporterList = initReporters(conn, reporterOptionsList); } catch (SQLException e) { - System.out.println(e.getMessage()); - return Cli.DEFAULT_ERROR_CODE; + if ( e.getErrorCode() == 1017 || e.getErrorCode() == 12514 ) { + throw new DatabaseConnectionFailed(e); + } + else { + throw e; + } } ExecutorService executorService = Executors.newFixedThreadPool(1 + reporterList.size()); diff --git a/src/main/java/org/utplsql/cli/exception/DatabaseConnectionFailed.java b/src/main/java/org/utplsql/cli/exception/DatabaseConnectionFailed.java new file mode 100644 index 0000000..01b03db --- /dev/null +++ b/src/main/java/org/utplsql/cli/exception/DatabaseConnectionFailed.java @@ -0,0 +1,10 @@ +package org.utplsql.cli.exception; + +import java.sql.SQLException; + +public class DatabaseConnectionFailed extends SQLException { + + public DatabaseConnectionFailed(SQLException cause ) { + super( "Could not establish connection to database. Reason: " + cause.getMessage(), cause); + } +} From dd0dcdf2d67d6e61d920ab3e21d9e58632ba609b Mon Sep 17 00:00:00 2001 From: pesse Date: Fri, 17 Nov 2017 11:00:22 +0100 Subject: [PATCH 031/345] Output warning when --failureExitCode is set and framework is not compatible with that option also refactored some things and made run_Default-test work with framework versions < 3.0.3, too --- src/main/java/org/utplsql/cli/RunCommand.java | 50 ++++++++--------- .../org/utplsql/cli/RunCommandChecker.java | 54 +++++++++++++++++++ .../java/org/utplsql/cli/RunCommandTest.java | 8 ++- .../utplsql/cli/TestRunCommandChecker.java | 19 +++++++ 4 files changed, 101 insertions(+), 30 deletions(-) create mode 100644 src/main/java/org/utplsql/cli/RunCommandChecker.java create mode 100644 src/test/java/org/utplsql/cli/TestRunCommandChecker.java diff --git a/src/main/java/org/utplsql/cli/RunCommand.java b/src/main/java/org/utplsql/cli/RunCommand.java index a03045c..690a453 100644 --- a/src/main/java/org/utplsql/cli/RunCommand.java +++ b/src/main/java/org/utplsql/cli/RunCommand.java @@ -4,6 +4,7 @@ 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.Reporter; @@ -82,6 +83,8 @@ public class RunCommand { "most actual. Use this if you use CLI with a development version of utPLSQL-framework") private boolean skipCompatibilityCheck = false; + private CompatibilityProxy compatibilityProxy; + public ConnectionInfo getConnectionInfo() { return connectionInfoList.get(0); } @@ -92,7 +95,7 @@ public List getTestPaths() { public int run() throws Exception { - checkOracleJDBCExists(); + RunCommandChecker.checkOracleJDBCExists(); final ConnectionInfo ci = getConnectionInfo(); @@ -113,10 +116,10 @@ public int run() throws Exception { try (Connection conn = ci.getConnection()) { // Check if orai18n exists if database version is 11g - checkOracleI18nExists(ci.getOracleDatabaseVersion(conn)); + RunCommandChecker.checkOracleI18nExists(ci.getOracleDatabaseVersion(conn)); // First of all do a compatibility check and fail-fast - checkFrameworkCompatibility(conn); + compatibilityProxy = checkFrameworkCompatibility(conn); reporterList = initReporters(conn, reporterOptionsList); @@ -129,6 +132,12 @@ public int run() throws Exception { } } + // Output a message if --failureExitCode is set but database framework is not capable of + String msg = RunCommandChecker.getCheckFailOnErrorMessage(failureExitCode, compatibilityProxy.getDatabaseVersion()); + if ( msg != null ) { + System.out.println(msg); + } + ExecutorService executorService = Executors.newFixedThreadPool(1 + reporterList.size()); // Run tests. @@ -268,7 +277,7 @@ public List getReporterOptionsList() { * @param conn Active Connection * @throws SQLException */ - private void checkFrameworkCompatibility(Connection conn) throws SQLException { + private CompatibilityProxy checkFrameworkCompatibility(Connection conn) throws SQLException { CompatibilityProxy proxy = new CompatibilityProxy(conn, skipCompatibilityCheck); @@ -279,6 +288,8 @@ private void checkFrameworkCompatibility(Connection conn) throws SQLException { System.out.println("Skipping Compatibility check with framework version, expecting the latest version " + "to be installed in database"); } + + return proxy; } public FileMapperOptions getMapperOptions(List mappingParams, List filePaths) { @@ -328,33 +339,14 @@ public FileMapperOptions getMapperOptions(List mappingParams, List Date: Sun, 19 Nov 2017 20:28:50 +0000 Subject: [PATCH 032/345] Updated download info in readme. Added slack notifications from Travis. --- .travis.yml | 3 +++ README.md | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 9fca880..ae08343 100644 --- a/.travis.yml +++ b/.travis.yml @@ -52,3 +52,6 @@ deploy: key: $BINTRAY_API_KEY dry-run: false on: develop + +notifications: + slack: $SLACK_API_TOKEN diff --git a/README.md b/README.md index 973b531..88d2318 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,10 @@ Provides an easy way of invoking utPLSQL from command-line. Main features: * Maps project and test files to database objects for reporting purposes. (Comming Soon) ## Downloading -You can download development versions on [Bintray](https://bintray.com/viniciusam/utPLSQL-cli/utPLSQL-cli-develop#files). + +Published releases are available for download on the [utPLSQL-cli GitHub Releases Page.](https://github.com/utPLSQL/utPLSQL-cli/releases) + +You can also download all development versions from [Bintray](https://bintray.com/viniciusam/utPLSQL-cli/utPLSQL-cli-develop#files). ## Requirements From 5f5c82af853d7da16c24893519bf9cbfaf2e8eba Mon Sep 17 00:00:00 2001 From: Jacek Date: Sun, 19 Nov 2017 23:01:47 +0000 Subject: [PATCH 033/345] Adding downloads of utplsql-java-api from packagecloud.io --- .travis/maven_cfg.sh | 5 ----- pom.xml | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/.travis/maven_cfg.sh b/.travis/maven_cfg.sh index 6017b04..303ad00 100644 --- a/.travis/maven_cfg.sh +++ b/.travis/maven_cfg.sh @@ -22,8 +22,3 @@ else echo "Using cached maven settings..." fi -# The Java API is not available on a public repository yet, we need to download and install it locally. -# Always downloading the latest development version. -git clone https://github.com/utPLSQL/utPLSQL-java-api.git -cd utPLSQL-java-api -mvn package install -DskipTests diff --git a/pom.xml b/pom.xml index cda5e7f..370a7fb 100644 --- a/pom.xml +++ b/pom.xml @@ -59,4 +59,19 @@ + + + utplsql-java-api + + https://packagecloud.io/utplsql/utplsql-java-api/maven2 + + + true + + + true + + + + From 38d8eb82e5925edb1a7b6e8dccf5f37ff6ea0d01 Mon Sep 17 00:00:00 2001 From: Jacek Date: Mon, 20 Nov 2017 00:55:17 +0000 Subject: [PATCH 034/345] Switched to use released version `3.0.4` of API. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 370a7fb..921bb7c 100644 --- a/pom.xml +++ b/pom.xml @@ -20,7 +20,7 @@ org.utplsql java-api - 3.0.4-SNAPSHOT + 3.0.4 compile From e0e9b15da252db44466d5bb4840911bd29a6adff Mon Sep 17 00:00:00 2001 From: Jacek Date: Mon, 20 Nov 2017 01:44:49 +0000 Subject: [PATCH 035/345] Updated release process to take version from a tag name --- .travis.yml | 10 +++++++--- .travis/maven_cfg.sh | 9 +-------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9fca880..befa7e5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -38,6 +38,7 @@ script: before_deploy: - bash .travis/create_release.sh + - if [ ! -z "$TRAVIS_TAG" ]; then VERSION=$(tr -d "/v/" <<<$TRAVIS_TAG); mvn org.codehaus.mojo:versions-maven-plugin:2.1:set -DnewVersion=${VERSION}; fi deploy: - provider: releases @@ -45,10 +46,13 @@ deploy: file: utPLSQL-cli.zip skip_cleanup: true on: + repository: utPLSQL/utPLSQL-cli tags: true - provider: bintray file: bintray.json - user: $BINTRAY_USER - key: $BINTRAY_API_KEY + user: ${BINTRAY_USER} + key: ${BINTRAY_API_KEY} dry-run: false - on: develop + on: + repository: utPLSQL/utPLSQL-cli + branch: develop diff --git a/.travis/maven_cfg.sh b/.travis/maven_cfg.sh index 6017b04..2bacb83 100644 --- a/.travis/maven_cfg.sh +++ b/.travis/maven_cfg.sh @@ -13,14 +13,7 @@ else sudo cp $CACHE_DIR/wagon-http-2.8-shaded.jar $MAVEN_HOME/lib/ext/ fi -# Create the settings file with oracle server config. -# If file already exists, Oracle dependencies were cached on previous build. -if [ ! -f $MAVEN_CFG/.cached ]; then - cp settings.xml $MAVEN_CFG/settings.xml - touch $MAVEN_CFG/.cached -else - echo "Using cached maven settings..." -fi +cp settings.xml $MAVEN_CFG/settings.xml # The Java API is not available on a public repository yet, we need to download and install it locally. # Always downloading the latest development version. 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 036/345] 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 5ffd032d7848d3577db94c9a356542e6f80f336b Mon Sep 17 00:00:00 2001 From: Jacek Date: Tue, 21 Nov 2017 00:02:09 +0000 Subject: [PATCH 037/345] Removed `ucp.jar` from archive. Fixed CLASSPATH in generated runners. --- .travis/create_release.sh | 5 +++-- pom.xml | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.travis/create_release.sh b/.travis/create_release.sh index 739558a..1febb01 100644 --- a/.travis/create_release.sh +++ b/.travis/create_release.sh @@ -6,8 +6,9 @@ VERSION=`date +%Y%m%d%H%M` mkdir dist mv target/appassembler utPLSQL-cli # Remove Oracle libraries du to licensing problems -rm utPLSQL-cli/lib/ojdbc8* -rm utPLSQL-cli/lib/orai18n* +rm utPLSQL-cli/lib/ucp*.jar +rm utPLSQL-cli/lib/ojdbc8*.jar +rm utPLSQL-cli/lib/orai18n*.jar zip -r -q dist/utPLSQL-cli-${TRAVIS_BRANCH}-${VERSION}.zip utPLSQL-cli zip -r -q utPLSQL-cli.zip utPLSQL-cli diff --git a/pom.xml b/pom.xml index 921bb7c..eef3a59 100644 --- a/pom.xml +++ b/pom.xml @@ -45,6 +45,7 @@ 1.10 true + true etc lib flat From 8a07aa0b4bf7c167fba483a92fac893be3f99705 Mon Sep 17 00:00:00 2001 From: Jacek Date: Tue, 21 Nov 2017 00:13:08 +0000 Subject: [PATCH 038/345] Added `ucp.jar` download requirement to readme --- README.md | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 88d2318..945d052 100644 --- a/README.md +++ b/README.md @@ -19,19 +19,27 @@ You can also download all development versions from [Bintray](https://bintray.co * [Java SE Runtime Environment 8](http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html) * When using reporters for Sonar or Coveralls client needs to be invoked from project's root directory. * Due to Oracle license we can't ship the necessary oracle libraries directly with utPLSQL-cli. Please download the libraries directly from oracle website and put the jars into the "lib" folder of your utPLSQL-cli installation - * Oracle JDBC driver: http://www.oracle.com/technetwork/database/features/jdbc/jdbc-ucp-122-3110062.html - * If you are on a 11g database you might need the orai18n library, too: http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-112010-090769.html + * Oracle `ojdbc8` driver + * Oracle `ucp` library + * If you are on a 11g database with non0standard NLS settings, you will also need the `orai18n` library. + * All of the above can be downloaded from [Oracle download site](http://www.oracle.com/technetwork/database/features/jdbc/jdbc-ucp-122-3110062.html) ## Compatibility The latest CLI is always compatible with all database frameworks of the same major 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. ## Usage -utplsql run \ [-p=(ut_path|ut_paths)] [-f=format [-o=output_file] [-s] ...] + +`utplsql run [-p=(ut_path|ut_paths)] [-f=format [-o=output_file] [-s] ...]` ``` - - /@//[:]/ OR /@ OR /@:: - To connect using TNS, you need to have the ORACLE_HOME environment variable set. + - accepted formats: + /@//[:]/ + /@:: + /@ + To connect using TNS, you need to have the ORACLE_HOME environment variable set. + The file tnsnames.ora must exist in path %ORACLE_HOME%/network/admin + The file tnsnames.ora must contain valid TNS entries. -p=suite_path(s) - A suite path or a comma separated list of suite paths for unit test to be executed. The path(s) can be in one of the following formats: schema[.package[.procedure]] From ad4339d5bf49477b16fe055fc8c4d40500016c0c Mon Sep 17 00:00:00 2001 From: Jacek Date: Tue, 21 Nov 2017 00:17:57 +0000 Subject: [PATCH 039/345] Added Travis build build notifications for slack. --- .travis.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 4bb79d4..c1f85c2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -58,4 +58,8 @@ deploy: branch: develop notifications: - slack: $SLACK_API_TOKEN + slack: + rooms: + - secure: "jTPq4AcWQdWp1rB175c05ei/1lXZF1DBoqiKl9PPe7f8vqXS2QLPXMwGTEkZ1YnqL2MPZMB+50Gw5RhLKQ+t+9pN7ejLO0D8ULi1e96PDU5ZL5pNvRglH6U/lR5iT1CjELUuraDXDJ98Vu4gluLMiwTtFYQhNrOoA2V84L+8fF7rGjbGl4/zOXA9RQ4YAcOomJesb4vE7BCjhDjUuMW43xjNWg2s0WAiF+fC1HY/tsBMb1CGfpVULnO5ES5bKtUv/aGtySzH0vXilGDUvhZ/8mdaRn6uxpzcqrFdAyW8elSD28CypcYoxy6Myudw3SFiRPs0/Z02VXvm8DQtU/lcFEnaO7dMG+FpFhsWbrEjcRS6R7ve8uc7e/WuaQhtNVzSTOzRe+JFPGP9FOcYN+AcW2NJFILV9yT7+X/MPIB0OMxuwaPmVgtoyx0oec2nw05azmDr76P2e1XLnKtxa8ouwvPx8EMgApnXSR6VmLGu/w8nmtvIWjEAJ88cdGhwBagtyAsn2frzHq8aKpMziDRYvw4ivwGAeHJFsDtdRXzSbxhxmjl6+is3P0g0iAfojQ/Pzd4GugSYwqRQLLE7dUE0FAKXhKAAQAkjRZxik2+w6jgG8PuLuHdR4pm7C9srL+WAX8aFq/RQXE7BoIdqiZ5TMekw8d6eCRTjcRHsa3pPAd0=" + on_success: change + on_failure: always From d0fa80ced9b0db520c099023b94c459465f5093a Mon Sep 17 00:00:00 2001 From: pesse Date: Tue, 21 Nov 2017 17:11:06 +0100 Subject: [PATCH 040/345] Replace Oracle Connection Pool with HikariCP --- pom.xml | 26 ++++++++++++++++--- .../java/org/utplsql/cli/ConnectionInfo.java | 16 +++++------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/pom.xml b/pom.xml index eef3a59..2f5dd67 100644 --- a/pom.xml +++ b/pom.xml @@ -22,6 +22,12 @@ java-api 3.0.4 compile + + + com.oracle.jdbc + ucp + + com.beust @@ -30,10 +36,22 @@ compile - junit - junit - 4.12 - test + com.zaxxer + HikariCP + 2.7.2 + compile + + + org.slf4j + slf4j-nop + 1.7.25 + compile + + + junit + junit + 4.12 + test diff --git a/src/main/java/org/utplsql/cli/ConnectionInfo.java b/src/main/java/org/utplsql/cli/ConnectionInfo.java index 4f76f81..d96a67f 100644 --- a/src/main/java/org/utplsql/cli/ConnectionInfo.java +++ b/src/main/java/org/utplsql/cli/ConnectionInfo.java @@ -1,8 +1,7 @@ package org.utplsql.cli; import com.beust.jcommander.IStringConverter; -import oracle.ucp.jdbc.PoolDataSource; -import oracle.ucp.jdbc.PoolDataSourceFactory; +import com.zaxxer.hikari.HikariDataSource; import java.io.File; import java.sql.Connection; @@ -22,16 +21,13 @@ public class ConnectionInfo { } } - private PoolDataSource pds = PoolDataSourceFactory.getPoolDataSource(); + private HikariDataSource pds = new HikariDataSource(); public ConnectionInfo(String connectionInfo) { - try { - this.pds.setConnectionFactoryClassName("oracle.jdbc.pool.OracleDataSource"); - this.pds.setURL("jdbc:oracle:thin:" + connectionInfo); - this.pds.setInitialPoolSize(2); - } catch (SQLException e) { - e.printStackTrace(); - } + + pds.setJdbcUrl("jdbc:oracle:thin:" + connectionInfo); + pds.setAutoCommit(false); + } public Connection getConnection() throws SQLException { From 356e95b6d9931216d41bdc1f0f10d79d98ca8f9d Mon Sep 17 00:00:00 2001 From: pesse Date: Tue, 21 Nov 2017 17:16:37 +0100 Subject: [PATCH 041/345] Fix problem appassembler not packing cli-jar into assembly --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c1f85c2..5ef4630 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,7 +34,7 @@ install: script: - mvn package -DskipTests - - mvn package appassembler:assemble + - mvn package jar:jar appassembler:assemble before_deploy: - bash .travis/create_release.sh From 7735c6db93fc3630988daeb449743bd234e48695 Mon Sep 17 00:00:00 2001 From: pesse Date: Tue, 21 Nov 2017 17:20:09 +0100 Subject: [PATCH 042/345] Updated docs --- README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 945d052..fd88eed 100644 --- a/README.md +++ b/README.md @@ -20,13 +20,12 @@ You can also download all development versions from [Bintray](https://bintray.co * When using reporters for Sonar or Coveralls client needs to be invoked from project's root directory. * Due to Oracle license we can't ship the necessary oracle libraries directly with utPLSQL-cli. Please download the libraries directly from oracle website and put the jars into the "lib" folder of your utPLSQL-cli installation * Oracle `ojdbc8` driver - * Oracle `ucp` library - * If you are on a 11g database with non0standard NLS settings, you will also need the `orai18n` library. + * If you are on a 11g database with non standard NLS settings, you will also need the `orai18n` library. * All of the above can be downloaded from [Oracle download site](http://www.oracle.com/technetwork/database/features/jdbc/jdbc-ucp-122-3110062.html) ## Compatibility -The latest CLI is always compatible with all database frameworks of the same major 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. +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. ## Usage From 8b9cfed932937426607b52763b0a779e2775c7d9 Mon Sep 17 00:00:00 2001 From: Jacek Date: Tue, 21 Nov 2017 23:31:45 +0000 Subject: [PATCH 043/345] Added a patch for maven assemble issue --- .travis/create_release.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis/create_release.sh b/.travis/create_release.sh index 1febb01..54629db 100644 --- a/.travis/create_release.sh +++ b/.travis/create_release.sh @@ -3,6 +3,9 @@ set -ev VERSION=`date +%Y%m%d%H%M` +#overcome maven assemble issue: https://github.com/mojohaus/appassembler/issues/61 +sed -i '/CYGWIN\*) cygwin=true/c\ CYGWIN*|MINGW*) cygwin=true ;;' target/appassembler/bin/utplsql + mkdir dist mv target/appassembler utPLSQL-cli # Remove Oracle libraries du to licensing problems From 0ed3a318155298b92bc4127c0b31555203d4a4a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacek=20G=C4=99bal?= Date: Wed, 22 Nov 2017 00:03:52 +0000 Subject: [PATCH 044/345] Update create_release.sh Fixed removal of non-existing files. --- .travis/create_release.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis/create_release.sh b/.travis/create_release.sh index 54629db..d1f36ca 100644 --- a/.travis/create_release.sh +++ b/.travis/create_release.sh @@ -9,9 +9,9 @@ sed -i '/CYGWIN\*) cygwin=true/c\ CYGWIN*|MINGW*) cygwin=true ;;' target/appass mkdir dist mv target/appassembler utPLSQL-cli # Remove Oracle libraries du to licensing problems -rm utPLSQL-cli/lib/ucp*.jar -rm utPLSQL-cli/lib/ojdbc8*.jar -rm utPLSQL-cli/lib/orai18n*.jar +rm -f utPLSQL-cli/lib/ucp*.jar +rm -f utPLSQL-cli/lib/ojdbc8*.jar +rm -f utPLSQL-cli/lib/orai18n*.jar zip -r -q dist/utPLSQL-cli-${TRAVIS_BRANCH}-${VERSION}.zip utPLSQL-cli zip -r -q utPLSQL-cli.zip utPLSQL-cli From e8293c4344abe9f12892817ec4253a46db5569b7 Mon Sep 17 00:00:00 2001 From: Eduard Vlasov Date: Thu, 21 Dec 2017 13:19:17 +0500 Subject: [PATCH 045/345] 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 046/345] 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 047/345] 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 048/345] 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 049/345] 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 050/345] 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 051/345] 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 052/345] 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 053/345] 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 054/345] 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("