From a51ff7457f387a856867c3c08587917691263551 Mon Sep 17 00:00:00 2001 From: Vinicius Avellar Date: Wed, 3 Oct 2018 23:29:22 +0100 Subject: [PATCH 1/4] #7 Adding javadocs and sources in preparation for the release --- .gitignore | 5 +- pom.xml | 6 +- utplsql-maven-plugin/pom.xml | 346 ++++++----- .../maven/plugin/CustomTypeMapping.java | 29 +- .../org/utplsql/maven/plugin/UtPLSQLMojo.java | 570 +++++++++--------- .../maven/plugin/helper/PluginDefault.java | 104 ++-- .../maven/plugin/helper/ReporterDefault.java | 7 +- .../maven/plugin/helper/SQLScannerHelper.java | 51 +- .../maven/plugin/model/ReporterParameter.java | 159 ++--- .../maven/plugin/reporter/ReporterWriter.java | 204 +++---- .../maven/plugin/test/UtPLSQLMojoTest.java | 461 +++++++------- .../defaultConsoleOutputBehaviour/pom.xml | 140 ++--- .../invalidTestsSourcesDirectories/pom.xml | 127 ++-- .../missingDirectory/pom.xml | 133 ++-- .../missingIncludes/pom.xml | 113 ++-- .../directoryDoesNotExist/pom.xml | 118 ++-- .../directoryExists/pom.xml | 117 ++-- .../resources/testSourcesTestsParams/pom.xml | 200 +++--- 18 files changed, 1448 insertions(+), 1442 deletions(-) diff --git a/.gitignore b/.gitignore index 55f4354..334af0d 100644 --- a/.gitignore +++ b/.gitignore @@ -19,4 +19,7 @@ log/ target/ .mvn log.txt -**/pom.xml.versionsBackup \ No newline at end of file +**/pom.xml.versionsBackup + +# Docs +doc/ diff --git a/pom.xml b/pom.xml index 31f860a..9f57100 100644 --- a/pom.xml +++ b/pom.xml @@ -1,5 +1,6 @@ - + 4.0.0 org.utplsql @@ -20,5 +21,4 @@ utplsql-maven-plugin utplsql-maven-plugin-it - diff --git a/utplsql-maven-plugin/pom.xml b/utplsql-maven-plugin/pom.xml index 32c92a3..5bb82cb 100644 --- a/utplsql-maven-plugin/pom.xml +++ b/utplsql-maven-plugin/pom.xml @@ -1,160 +1,192 @@ - 4.0.0 - - org.utplsql - utplsql-maven-plugin-parent - 3.1.0-SNAPSHOT - - - utplsql-maven-plugin - maven-plugin - - - utplsql-maven-plugin Maven Plugin - - https://github.com/utPLSQL/utPLSQL-maven-plugin - - - UTF-8 - 1.8 - 1.7.4 - - - - - org.apache.maven - maven-core - 3.5.2 - - - - org.utplsql - java-api - 3.1.1 - - - - org.apache.maven - maven-model - 3.0.2 - - - - org.apache.maven - maven-plugin-api - 3.5.2 - - - - org.codehaus.plexus - plexus-utils - 3.0.8 - - - - org.apache.maven.plugin-tools - maven-plugin-annotations - 3.5 - provided - - - - - - org.powermock - powermock-module-junit4 - ${powermock.version} - test - - - - org.powermock - powermock-api-mockito2 - ${powermock.version} - test - - - - org.apache.maven.plugin-testing - maven-plugin-testing-harness - 3.3.0 - test - - - - org.apache.maven - maven-compat - 3.5.2 - test - - - - junit - junit - 4.12 - test - - - - org.assertj - assertj-core - 3.8.0 - test - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - ${java.version} - ${java.version} - ${project.build.sourceEncoding} - - - - org.apache.maven.plugins - maven-plugin-plugin - 3.5 - - utplsql - true - - - - mojo-descriptor - - descriptor - - - - help-goal - - helpmojo - - - - - - - - - - - utplsql-java-api - https://packagecloud.io/utplsql/utplsql-java-api/maven2 - - true - - - true - - - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + + + org.utplsql + utplsql-maven-plugin-parent + 3.1.0-SNAPSHOT + + + utplsql-maven-plugin + maven-plugin + + utplsql-maven-plugin Maven Plugin + + https://github.com/utPLSQL/utPLSQL-maven-plugin + + + + Apache License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + + + + + UTF-8 + 1.8 + 1.7.4 + + + + + org.utplsql + java-api + 3.1.1 + + + + org.apache.maven + maven-core + 3.5.2 + + + + org.apache.maven + maven-model + 3.0.2 + + + + org.apache.maven + maven-plugin-api + 3.5.2 + + + + org.codehaus.plexus + plexus-utils + 3.0.8 + + + + org.apache.maven.plugin-tools + maven-plugin-annotations + 3.5 + provided + + + + + org.apache.maven + maven-compat + 3.5.2 + test + + + + org.powermock + powermock-module-junit4 + ${powermock.version} + test + + + + org.powermock + powermock-api-mockito2 + ${powermock.version} + test + + + + org.apache.maven.plugin-testing + maven-plugin-testing-harness + 3.3.0 + test + + + + org.assertj + assertj-core + 3.8.0 + test + + + + junit + junit + 4.12 + test + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.7.0 + + ${java.version} + ${java.version} + ${project.build.sourceEncoding} + + + + org.apache.maven.plugins + maven-plugin-plugin + 3.5 + + utplsql + true + + + + mojo-descriptor + + descriptor + + + + help-goal + + helpmojo + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + + attach-javadocs + + jar + + + + + + org.apache.maven.plugins + maven-source-plugin + 3.0.1 + + + attach-sources + verify + + jar-no-fork + + + + + + + + + + utplsql-java-api + https://packagecloud.io/utplsql/utplsql-java-api/maven2 + + true + + + true + + + diff --git a/utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/CustomTypeMapping.java b/utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/CustomTypeMapping.java index 2ce9cf6..57d4080 100644 --- a/utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/CustomTypeMapping.java +++ b/utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/CustomTypeMapping.java @@ -1,48 +1,57 @@ package org.utplsql.maven.plugin; /** - * Bean used by maven to populate its model. - * + * Bean used by Maven to populate its model. + * {@code * - * ... - * ... + * ... + * ... * - * + * } */ public class CustomTypeMapping { + /** * Object type. */ private String type; - + /** * Custom mapping value. */ private String customMapping; /** - * @return The Object type. + * Returns the Object type. + * + * @return The Object type */ public String getType() { return type; } /** - * @param type The Object type. + * Sets the Object type + * + * @param type the Object type */ public void setType(final String type) { this.type = type; } /** - * @return Custom mapping value. + * Returns the custom mapping value. + * + * @return the custom mapping value */ public String getCustomMapping() { return customMapping; } /** - * @param mapping Custom mapping value. + * Sets the custom mapping value + * + * @param customMapping the custom mapping value */ public void setCustomMapping(final String customMapping) { this.customMapping = customMapping; diff --git a/utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/UtPLSQLMojo.java b/utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/UtPLSQLMojo.java index f0df3d0..b023f72 100644 --- a/utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/UtPLSQLMojo.java +++ b/utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/UtPLSQLMojo.java @@ -36,238 +36,219 @@ * This class expose the {@link TestRunner} interface to Maven. * * @author Alberto Hernández - * */ @Mojo(name = "test", defaultPhase = LifecyclePhase.TEST) public class UtPLSQLMojo extends AbstractMojo { - - @Parameter(readonly = true, defaultValue = "${project}") - private MavenProject project; - - @Parameter(property = "dbUrl") - protected String url; - @Parameter(property = "dbUser") - protected String user; + @Parameter(readonly = true, defaultValue = "${project}") + private MavenProject project; - @Parameter(property = "dbPass") - protected String password; + @Parameter(property = "dbUrl") + protected String url; - @Parameter - protected String includeObject; + @Parameter(property = "dbUser") + protected String user; - @Parameter - protected String excludeObject; + @Parameter(property = "dbPass") + protected String password; - @Parameter(defaultValue = "false") - protected boolean skipCompatibilityCheck; + @Parameter + protected String includeObject; - @Parameter - protected List reporters = new ArrayList<>(); + @Parameter + protected String excludeObject; - @Parameter - protected List paths = new ArrayList<>(); + @Parameter(defaultValue = "false") + protected boolean skipCompatibilityCheck; - // Sources Configuration - @Parameter - protected List sources = new ArrayList<>(); + @Parameter + protected List reporters = new ArrayList<>(); - @Parameter - private String sourcesOwner; + @Parameter + protected List paths = new ArrayList<>(); - @Parameter - private String sourcesRegexExpression; + // Sources Configuration + @Parameter + protected List sources = new ArrayList<>(); - @Parameter - private Integer sourcesOwnerSubexpression; + @Parameter + private String sourcesOwner; - @Parameter - private Integer sourcesNameSubexpression; + @Parameter + private String sourcesRegexExpression; - @Parameter - private Integer sourcesTypeSubexpression; + @Parameter + private Integer sourcesOwnerSubexpression; - @Parameter - private List sourcesCustomTypeMapping; + @Parameter + private Integer sourcesNameSubexpression; - // Tests Configuration + @Parameter + private Integer sourcesTypeSubexpression; - @Parameter - protected List tests = new ArrayList<>(); + @Parameter + private List sourcesCustomTypeMapping; - @Parameter - private String testsOwner; + // Tests Configuration + @Parameter + protected List tests = new ArrayList<>(); - @Parameter - private String testsRegexExpression; + @Parameter + private String testsOwner; - @Parameter - private Integer testsOwnerSubexpression; + @Parameter + private String testsRegexExpression; - @Parameter - private Integer testsNameSubexpression; + @Parameter + private Integer testsOwnerSubexpression; - @Parameter - private Integer testsTypeSubexpression; + @Parameter + private Integer testsNameSubexpression; - @Parameter - private List testsCustomTypeMapping; + @Parameter + private Integer testsTypeSubexpression; - @Parameter(defaultValue = "${project.build.directory}", readonly = true) - protected String targetDir; + @Parameter + private List testsCustomTypeMapping; - @Parameter(defaultValue = "${maven.test.failure.ignore}") - protected boolean ignoreFailure; + @Parameter(defaultValue = "${project.build.directory}", readonly = true) + protected String targetDir; - // Color in the console, bases on maven logging configuration - private boolean colorConsole = MessageUtils.isColorEnabled(); + @Parameter(defaultValue = "${maven.test.failure.ignore}") + protected boolean ignoreFailure; - // Reporter Writer - private ReporterWriter reporterWriter; + // Color in the console, bases on Maven logging configuration. + private boolean colorConsole = MessageUtils.isColorEnabled(); - /** - * - * Execute the plugin - * - */ - @Override - public void execute() throws MojoExecutionException { - getLog().debug("Java Api Version = " + JavaApiVersionInfo.getVersion()); - loadConfFromEnvironment(); + private ReporterWriter reporterWriter; - Connection connection = null; - try { - FileMapperOptions sourceMappingOptions = buildSourcesOptions(); - FileMapperOptions testMappingOptions = buildTestsOptions(); - - connection = DriverManager.getConnection(url, user, password); - - Version utlVersion = DBHelper.getDatabaseFrameworkVersion(connection); + /** + * Executes the plugin. + */ + @Override + public void execute() throws MojoExecutionException { + + getLog().debug("Java Api Version = " + JavaApiVersionInfo.getVersion()); + loadConfFromEnvironment(); + + Connection connection = null; + try { + FileMapperOptions sourceMappingOptions = buildSourcesOptions(); + FileMapperOptions testMappingOptions = buildTestsOptions(); + + connection = DriverManager.getConnection(url, user, password); + + Version utlVersion = DBHelper.getDatabaseFrameworkVersion(connection); getLog().info("utPLSQL Version = " + utlVersion); - + List reporterList = initReporters(connection, utlVersion, ReporterFactory.createEmpty()); - - logParameters(sourceMappingOptions, testMappingOptions, reporterList); - - TestRunner runner = new TestRunner() - .addPathList(paths) - .addReporterList(reporterList) - .sourceMappingOptions(sourceMappingOptions) - .testMappingOptions(testMappingOptions) - .skipCompatibilityCheck(skipCompatibilityCheck) - .colorConsole(colorConsole) - .failOnErrors(!ignoreFailure); - - if (StringUtils.isNotBlank(excludeObject)) { - runner.excludeObject(excludeObject); - } - if (StringUtils.isNotBlank(includeObject)) { - runner.includeObject(includeObject); - } - - runner.run(connection); - - } catch (SomeTestsFailedException e) { - getLog().error(e); - throw new MojoExecutionException(e.getMessage()); - } catch (SQLException e) { - getLog().error(e); - throw new MojoExecutionException(e.getMessage(), e); - } finally { - try { - if (null != connection) { - reporterWriter.writeReporters(connection); - } - } catch (Exception e) { - getLog().error(e.getMessage(), e); - } - } - } - - /** - * Load some configuration from env variables. - * - */ - private void loadConfFromEnvironment() { - if (StringUtils.isEmpty(url)) { - url = System.getProperty("dbUrl"); - } - - if (StringUtils.isEmpty(user)) { - user = System.getProperty("dbUser"); - } - - if (StringUtils.isEmpty(password)) { - password = System.getProperty("dbPass"); - } - } - - /** - * - * @param resources - * @return - * @throws MojoExecutionException - */ - private FileMapperOptions buildSourcesOptions() throws MojoExecutionException { - try { - if (sources.isEmpty()) { - File defaultSourceDirectory = new File(project.getBasedir(),PluginDefault.SOURCE_DIRECTORY); - if (defaultSourceDirectory.exists()) { - sources.add(PluginDefault.buildDefaultSource()); - } else { - return new FileMapperOptions(new ArrayList()); - } - } - - List scripts = SQLScannerHelper.findSQLs(project.getBasedir(),sources,PluginDefault.SOURCE_DIRECTORY, PluginDefault.SOURCE_FILE_PATTERN); - FileMapperOptions fileMapperOptions = new FileMapperOptions(scripts); - - if (StringUtils.isNotEmpty(sourcesOwner)) { - fileMapperOptions.setObjectOwner(sourcesOwner); - } - - if (StringUtils.isNotEmpty(sourcesRegexExpression)) { - fileMapperOptions.setRegexPattern(sourcesRegexExpression); - } - - if (sourcesOwnerSubexpression != null) { - fileMapperOptions.setOwnerSubExpression(sourcesOwnerSubexpression); - } - - if (sourcesNameSubexpression != null) { - fileMapperOptions.setNameSubExpression(sourcesNameSubexpression); - } - - if (sourcesTypeSubexpression != null) { - fileMapperOptions.setTypeSubExpression(sourcesTypeSubexpression); - } - - if (sourcesCustomTypeMapping != null && !sourcesCustomTypeMapping.isEmpty()) { - fileMapperOptions.setTypeMappings(new ArrayList()); - for (CustomTypeMapping typeMapping : sourcesCustomTypeMapping) { - fileMapperOptions.getTypeMappings() - .add(new KeyValuePair(typeMapping.getCustomMapping(), typeMapping.getType())); - } - } - - return fileMapperOptions; - - } catch (Exception e) { - throw new MojoExecutionException("Invalid in your pom.xml",e); - } - - } - - /** - * - * @param resources - * @return - * @throws MojoExecutionException - */ - private FileMapperOptions buildTestsOptions() throws MojoExecutionException { - try { - if (tests.isEmpty()) { - File defaultTestDirectory = new File(project.getBasedir(),PluginDefault.TEST_DIRECTORY); + + logParameters(sourceMappingOptions, testMappingOptions, reporterList); + + TestRunner runner = new TestRunner() + .addPathList(paths) + .addReporterList(reporterList) + .sourceMappingOptions(sourceMappingOptions) + .testMappingOptions(testMappingOptions) + .skipCompatibilityCheck(skipCompatibilityCheck) + .colorConsole(colorConsole) + .failOnErrors(!ignoreFailure); + + if (StringUtils.isNotBlank(excludeObject)) { + runner.excludeObject(excludeObject); + } + if (StringUtils.isNotBlank(includeObject)) { + runner.includeObject(includeObject); + } + + runner.run(connection); + + } catch (SomeTestsFailedException e) { + getLog().error(e); + throw new MojoExecutionException(e.getMessage()); + } catch (SQLException e) { + getLog().error(e); + throw new MojoExecutionException(e.getMessage(), e); + } finally { + try { + if (null != connection) { + reporterWriter.writeReporters(connection); + } + } catch (Exception e) { + getLog().error(e.getMessage(), e); + } + } + } + + private void loadConfFromEnvironment() { + if (StringUtils.isEmpty(url)) { + url = System.getProperty("dbUrl"); + } + + if (StringUtils.isEmpty(user)) { + user = System.getProperty("dbUser"); + } + + if (StringUtils.isEmpty(password)) { + password = System.getProperty("dbPass"); + } + } + + private FileMapperOptions buildSourcesOptions() throws MojoExecutionException { + try { + if (sources.isEmpty()) { + File defaultSourceDirectory = new File(project.getBasedir(), PluginDefault.SOURCE_DIRECTORY); + if (defaultSourceDirectory.exists()) { + sources.add(PluginDefault.buildDefaultSource()); + } else { + return new FileMapperOptions(new ArrayList()); + } + } + + List scripts = SQLScannerHelper.findSQLs(project.getBasedir(), sources, + PluginDefault.SOURCE_DIRECTORY, PluginDefault.SOURCE_FILE_PATTERN); + FileMapperOptions fileMapperOptions = new FileMapperOptions(scripts); + + if (StringUtils.isNotEmpty(sourcesOwner)) { + fileMapperOptions.setObjectOwner(sourcesOwner); + } + + if (StringUtils.isNotEmpty(sourcesRegexExpression)) { + fileMapperOptions.setRegexPattern(sourcesRegexExpression); + } + + if (sourcesOwnerSubexpression != null) { + fileMapperOptions.setOwnerSubExpression(sourcesOwnerSubexpression); + } + + if (sourcesNameSubexpression != null) { + fileMapperOptions.setNameSubExpression(sourcesNameSubexpression); + } + + if (sourcesTypeSubexpression != null) { + fileMapperOptions.setTypeSubExpression(sourcesTypeSubexpression); + } + + if (sourcesCustomTypeMapping != null && !sourcesCustomTypeMapping.isEmpty()) { + fileMapperOptions.setTypeMappings(new ArrayList()); + for (CustomTypeMapping typeMapping : sourcesCustomTypeMapping) { + fileMapperOptions.getTypeMappings() + .add(new KeyValuePair(typeMapping.getCustomMapping(), typeMapping.getType())); + } + } + + return fileMapperOptions; + + } catch (Exception e) { + throw new MojoExecutionException("Invalid in your pom.xml", e); + } + + } + + private FileMapperOptions buildTestsOptions() throws MojoExecutionException { + try { + if (tests.isEmpty()) { + File defaultTestDirectory = new File(project.getBasedir(), PluginDefault.TEST_DIRECTORY); if (defaultTestDirectory.exists()) { tests.add(PluginDefault.buildDefaultTest()); } else { @@ -275,105 +256,94 @@ private FileMapperOptions buildTestsOptions() throws MojoExecutionException { } } - List scripts = SQLScannerHelper.findSQLs(project.getBasedir(),tests,PluginDefault.TEST_DIRECTORY, PluginDefault.TEST_FILE_PATTERN); - FileMapperOptions fileMapperOptions = new FileMapperOptions(scripts); - - if (StringUtils.isNotEmpty(testsOwner)) { - fileMapperOptions.setObjectOwner(testsOwner); - } - - if (StringUtils.isNotEmpty(testsRegexExpression)) { - fileMapperOptions.setRegexPattern(testsRegexExpression); - } - - if (testsOwnerSubexpression != null) { - fileMapperOptions.setOwnerSubExpression(testsOwnerSubexpression); - } - - if (testsNameSubexpression != null) { - fileMapperOptions.setNameSubExpression(testsNameSubexpression); - } - - if (testsTypeSubexpression != null) { - fileMapperOptions.setTypeSubExpression(testsTypeSubexpression); - } - - if (testsCustomTypeMapping != null && !testsCustomTypeMapping.isEmpty()) { - fileMapperOptions.setTypeMappings(new ArrayList()); - for (CustomTypeMapping typeMapping : testsCustomTypeMapping) { - fileMapperOptions.getTypeMappings() - .add(new KeyValuePair(typeMapping.getCustomMapping(), typeMapping.getType())); - } - } - - return fileMapperOptions; - - } catch (Exception e) { - throw new MojoExecutionException("Invalid in your pom.xml: " + e.getMessage()); - } - - } - - /** - * Init all the reporters - * - * @param connection - * @return - * @throws SQLException - */ - private List initReporters( - Connection connection, Version utlVersion, ReporterFactory reporterFactory) throws SQLException { - - List reporterList = new ArrayList<>(); - reporterWriter = new ReporterWriter(targetDir, utlVersion); - - if (reporters.isEmpty()) { - ReporterParameter reporterParameter = new ReporterParameter(); - reporterParameter.setConsoleOutput(true); - reporterParameter.setName(CoreReporters.UT_DOCUMENTATION_REPORTER.name()); - reporters.add(reporterParameter); - } - - for (ReporterParameter reporterParameter : reporters) { - Reporter reporter = reporterFactory.createReporter(reporterParameter.getName()); - reporter.init(connection); - reporterList.add(reporter); - - // Turns the console output on by default if both file and console output are empty. - if (!reporterParameter.isFileOutput() && null == reporterParameter.getConsoleOutput()) { - reporterParameter.setConsoleOutput(true); - } - - // Only added the reporter if at least one of the output is required - if (StringUtils.isNotBlank(reporterParameter.getFileOutput()) || reporterParameter.isConsoleOutput()) { - reporterWriter.addReporter(reporterParameter, reporter); - } - } - - return reporterList; - } - - /** - * - * @param sourceMappingOptions - * @param testMappingOptions - * @param reporterList - */ - private void logParameters(FileMapperOptions sourceMappingOptions, FileMapperOptions testMappingOptions, - List reporterList) { - Log log = getLog(); - log.info("Invoking TestRunner with: " + targetDir); - - if (!log.isDebugEnabled()) { - return; - } - - log.debug("Invoking TestRunner with: "); - log.debug("reporters="); - reporterList.forEach((Reporter r) -> log.debug(r.getTypeName())); - log.debug("sources="); - sourceMappingOptions.getFilePaths().forEach(log::debug); - log.debug("tests="); - testMappingOptions.getFilePaths().forEach(log::debug); - } + List scripts = SQLScannerHelper.findSQLs(project.getBasedir(), tests, PluginDefault.TEST_DIRECTORY, + PluginDefault.TEST_FILE_PATTERN); + FileMapperOptions fileMapperOptions = new FileMapperOptions(scripts); + + if (StringUtils.isNotEmpty(testsOwner)) { + fileMapperOptions.setObjectOwner(testsOwner); + } + + if (StringUtils.isNotEmpty(testsRegexExpression)) { + fileMapperOptions.setRegexPattern(testsRegexExpression); + } + + if (testsOwnerSubexpression != null) { + fileMapperOptions.setOwnerSubExpression(testsOwnerSubexpression); + } + + if (testsNameSubexpression != null) { + fileMapperOptions.setNameSubExpression(testsNameSubexpression); + } + + if (testsTypeSubexpression != null) { + fileMapperOptions.setTypeSubExpression(testsTypeSubexpression); + } + + if (testsCustomTypeMapping != null && !testsCustomTypeMapping.isEmpty()) { + fileMapperOptions.setTypeMappings(new ArrayList()); + for (CustomTypeMapping typeMapping : testsCustomTypeMapping) { + fileMapperOptions.getTypeMappings() + .add(new KeyValuePair(typeMapping.getCustomMapping(), typeMapping.getType())); + } + } + + return fileMapperOptions; + + } catch (Exception e) { + throw new MojoExecutionException("Invalid in your pom.xml: " + e.getMessage()); + } + + } + + private List initReporters(Connection connection, Version utlVersion, ReporterFactory reporterFactory) + throws SQLException { + + List reporterList = new ArrayList<>(); + reporterWriter = new ReporterWriter(targetDir, utlVersion); + + if (reporters.isEmpty()) { + ReporterParameter reporterParameter = new ReporterParameter(); + reporterParameter.setConsoleOutput(true); + reporterParameter.setName(CoreReporters.UT_DOCUMENTATION_REPORTER.name()); + reporters.add(reporterParameter); + } + + for (ReporterParameter reporterParameter : reporters) { + Reporter reporter = reporterFactory.createReporter(reporterParameter.getName()); + reporter.init(connection); + reporterList.add(reporter); + + // Turns the console output on by default if both file and console output are + // empty. + if (!reporterParameter.isFileOutput() && null == reporterParameter.getConsoleOutput()) { + reporterParameter.setConsoleOutput(true); + } + + // Only added the reporter if at least one of the output is required + if (StringUtils.isNotBlank(reporterParameter.getFileOutput()) || reporterParameter.isConsoleOutput()) { + reporterWriter.addReporter(reporterParameter, reporter); + } + } + + return reporterList; + } + + private void logParameters(FileMapperOptions sourceMappingOptions, FileMapperOptions testMappingOptions, + List reporterList) { + Log log = getLog(); + log.info("Invoking TestRunner with: " + targetDir); + + if (!log.isDebugEnabled()) { + return; + } + + log.debug("Invoking TestRunner with: "); + log.debug("reporters="); + reporterList.forEach((Reporter r) -> log.debug(r.getTypeName())); + log.debug("sources="); + sourceMappingOptions.getFilePaths().forEach(log::debug); + log.debug("tests="); + testMappingOptions.getFilePaths().forEach(log::debug); + } } \ No newline at end of file diff --git a/utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/helper/PluginDefault.java b/utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/helper/PluginDefault.java index 869747f..a4c2ba4 100644 --- a/utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/helper/PluginDefault.java +++ b/utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/helper/PluginDefault.java @@ -5,59 +5,59 @@ import org.apache.maven.model.Resource; /** - * This class provides methods to retrieve the list of resources in the default and directories. + * This class provides methods to retrieve the list of resources in the default + * {@literal and } directories. * * @author Alberto Hernández - * */ -public class PluginDefault -{ - // Source Directory - public static final String SOURCE_DIRECTORY = "src/main/plsql"; - - // Test Directory - public static final String TEST_DIRECTORY = "src/test/plsql"; - - /** - * Default source file pattern. - */ - public static final String SOURCE_FILE_PATTERN = "**/*.*"; - - /** - * Default test file pattern. - */ - public static final String TEST_FILE_PATTERN = "**/*.pkg"; - - private PluginDefault() - { - // NA - } - - /** - * This method returns {@link Resource} for the default {@code source} directory - * - * @return a {@link Resource} - */ - public static Resource buildDefaultSource() - { - return buildDirectory(SOURCE_DIRECTORY, SOURCE_FILE_PATTERN); - } - - /** - * This method returns {@link Resource} for the default {@code test} directory - * - * @return a {@link Resource} - */ - public static Resource buildDefaultTest() - { - return buildDirectory(TEST_DIRECTORY, TEST_FILE_PATTERN); - } - - private static Resource buildDirectory(String directory, String includes) - { - Resource resource = new Resource(); - resource.setDirectory(directory); - resource.setIncludes(Arrays.asList(includes)); - return resource; - } +public class PluginDefault { + + /** + * Source directory. + */ + public static final String SOURCE_DIRECTORY = "src/main/plsql"; + + /** + * Test directory. + */ + public static final String TEST_DIRECTORY = "src/test/plsql"; + + /** + * Default source file pattern. + */ + public static final String SOURCE_FILE_PATTERN = "**/*.*"; + + /** + * Default test file pattern. + */ + public static final String TEST_FILE_PATTERN = "**/*.pkg"; + + private PluginDefault() { + // NA + } + + /** + * This method returns {@link Resource} for the default {@code source} directory + * + * @return a {@link Resource} + */ + public static Resource buildDefaultSource() { + return buildDirectory(SOURCE_DIRECTORY, SOURCE_FILE_PATTERN); + } + + /** + * This method returns {@link Resource} for the default {@code test} directory + * + * @return a {@link Resource} + */ + public static Resource buildDefaultTest() { + return buildDirectory(TEST_DIRECTORY, TEST_FILE_PATTERN); + } + + private static Resource buildDirectory(String directory, String includes) { + Resource resource = new Resource(); + resource.setDirectory(directory); + resource.setIncludes(Arrays.asList(includes)); + return resource; + } } diff --git a/utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/helper/ReporterDefault.java b/utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/helper/ReporterDefault.java index 840beac..208827f 100644 --- a/utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/helper/ReporterDefault.java +++ b/utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/helper/ReporterDefault.java @@ -3,11 +3,12 @@ import org.utplsql.api.reporter.Reporter; /** - * This class is an enumeration of all the known reporter in {@code utPLSQL}. It further more defines the default output - * file for each {@link Reporter}. In case the output file is set to {@code -}, it will mean the stdout of the process. + * This class is an enumeration of all the known reporter in {@code utPLSQL}. + * It further more defines the default output file for each {@link Reporter}. + * In case the output file is set to {@code -}, it will mean the stdout of the + * process. * * @author Alberto Hernández - * */ public enum ReporterDefault { diff --git a/utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/helper/SQLScannerHelper.java b/utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/helper/SQLScannerHelper.java index b73facf..07e16f9 100644 --- a/utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/helper/SQLScannerHelper.java +++ b/utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/helper/SQLScannerHelper.java @@ -11,10 +11,9 @@ import org.codehaus.plexus.util.DirectoryScanner; /** - * Utility to Scan all resources + * Utility to scan all resources * * @author Alberto Hernández - * */ public class SQLScannerHelper { @@ -23,46 +22,46 @@ private SQLScannerHelper() { } /** + * Scans a directory looking for the matching patterns. * - * @param resouces - * @return + * @param baseDir the base directory + * @param resources a list of resources + * @param defaultDirectory the default search directory + * @param defaultFilePattern the default file pattern + * @return a list of the files found */ - public static List findSQLs(File baseDir,List resources, String defaultDirectory, String defaultFilePattern) { + public static List findSQLs(File baseDir, List resources, String defaultDirectory, + String defaultFilePattern) { + List founds = new ArrayList(); for (Resource resource : resources) { - if (resource.getDirectory() == null) { - // use default directory if not set. - resource.setDirectory(defaultDirectory); - } - - if (resource.getIncludes().isEmpty()) { - // use default file pattern if not set. - resource.getIncludes().add(defaultFilePattern); - } - // Build Scanner - DirectoryScanner scanner = buildScanner(baseDir.getPath(),resource); + + if (resource.getDirectory() == null) { + resource.setDirectory(defaultDirectory); + } + + if (resource.getIncludes().isEmpty()) { + resource.getIncludes().add(defaultFilePattern); + } + + DirectoryScanner scanner = buildScanner(baseDir.getPath(), resource); scanner.scan(); + for (String basename : scanner.getIncludedFiles()) { founds.add(baseDir.toURI().relativize(new File(scanner.getBasedir(), basename).toURI()).getPath()); } - // Append all scanned objects founds.addAll(Arrays.asList()); } return founds; } - /** - * Build a scanner in forder to Find all Resource files - * - * @param resource - * @return - */ - private static DirectoryScanner buildScanner(String baseDir,Resource resource) { + private static DirectoryScanner buildScanner(String baseDir, Resource resource) { + if (resource != null) { - File fileBaseDir = new File(baseDir,resource.getDirectory()); + File fileBaseDir = new File(baseDir, resource.getDirectory()); if (!fileBaseDir.exists() || !fileBaseDir.isDirectory() || !fileBaseDir.canRead()) { throw new IllegalArgumentException( format("Invalid %s in resource. Check your pom.xml", resource.getDirectory())); @@ -74,7 +73,7 @@ private static DirectoryScanner buildScanner(String baseDir,Resource resource) { scanner.setExcludes(resource.getExcludes().toArray(new String[0])); return scanner; } + throw new IllegalArgumentException(); } - } diff --git a/utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/model/ReporterParameter.java b/utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/model/ReporterParameter.java index 019c0e0..4f04bde 100644 --- a/utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/model/ReporterParameter.java +++ b/utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/model/ReporterParameter.java @@ -2,87 +2,100 @@ import org.codehaus.plexus.util.StringUtils; -public class ReporterParameter -{ +/** + * Represents a reporter parameter in the pom file. + * {@code + * + * ... + * ... + * ... + * + * } + * + * @author Alberto Hernández + */ +public class ReporterParameter { - // Name of the registered reported in UtPLSQL - private String name; + private String name; + private String fileOutput; + private Boolean consoleOutput; - // File Output of the reporter - private String fileOutput; + /** + * Creates a new reporter parameter. + */ + public ReporterParameter() { + super(); + } - // Writes the report to console - private Boolean consoleOutput; + /** + * Returns the reporter name. + * + * @return the reporter name + */ + public String getName() { + return name; + } - /** - * - */ - public ReporterParameter() - { - super(); - } + /** + * Sets the reporter name. + * + * @param name the reporter name + */ + public void setName(String name) { + this.name = name; + } - /** - * @return the name - */ - public String getName() - { - return name; - } + /** + * Returns reporter output file. + * + * @return the output file name + */ + public String getFileOutput() { + return fileOutput; + } - /** - * @param name - * the name to set - */ - public void setName(String name) - { - this.name = name; - } + /** + * Returns whether the file output is enabled or not. + * + * @return true if the file output is enabled, false otherwise + */ + public boolean isFileOutput() { + return StringUtils.isNotBlank(fileOutput); + } - /** - * @return the fileOutput - */ - public String getFileOutput() - { - return fileOutput; - } + /** + * Sets the output file. + * + * @param fileOutput the output file name + */ + public void setFileOutput(String fileOutput) { + this.fileOutput = fileOutput; + } - /** - * @param fileOutput - * the fileOutput to set - */ - public void setFileOutput(String fileOutput) - { - this.fileOutput = fileOutput; - } - - public Boolean getConsoleOutput() { - return consoleOutput; - } + /** + * Returns the console output option. + * + * @return the console output option + */ + public Boolean getConsoleOutput() { + return consoleOutput; + } - /** - * @return the consoleOutput - */ - public Boolean isConsoleOutput() - { - return null != consoleOutput && consoleOutput; - } - - /** - * @param consoleOutput - * the consoleOutput to set - */ - public void setConsoleOutput(boolean consoleOutput) - { - this.consoleOutput = consoleOutput; - } - - /** - * @return the consoleOutput - */ - public boolean isFileOutput() - { - return StringUtils.isNotBlank(fileOutput); - } + /** + * Returns whether the console output should be enabled or not. + * + * @return true if console output is enable, false otherwise + */ + public Boolean isConsoleOutput() { + return null != consoleOutput && consoleOutput; + } + /** + * Sets the console output option. + * + * @param consoleOutput the console output option + */ + public void setConsoleOutput(boolean consoleOutput) { + this.consoleOutput = consoleOutput; + } } diff --git a/utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/reporter/ReporterWriter.java b/utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/reporter/ReporterWriter.java index a9732db..bc03ab7 100644 --- a/utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/reporter/ReporterWriter.java +++ b/utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/reporter/ReporterWriter.java @@ -20,118 +20,94 @@ import org.utplsql.api.reporter.Reporter; import org.utplsql.maven.plugin.model.ReporterParameter; -public class ReporterWriter -{ - private static final Log LOG = new SystemStreamLog(); - - // Reporter Parameters - private List> listReporters; - - // Output Directory - private String outputDirectory; - - // Database Version - private Version databaseVersion; - - - /** - * Constructor of the reporter writer - * @param outputDirectory - * @param databaseVersion - */ - public ReporterWriter(String outputDirectory, Version databaseVersion) - { - this.listReporters = new ArrayList<>(); - this.outputDirectory = outputDirectory; - this.databaseVersion = databaseVersion; - - } - - /** - * - * @param connection - * @throws MojoExecutionException - */ - public void writeReporters(Connection connection) throws MojoExecutionException - { - for (Pair pair : listReporters) - { - writeReports(connection, pair.getLeft(), pair.getRight()); - } - } - - /** - * - * @param id - * @throws MojoExecutionException - */ - private void writeReports(Connection connection, Reporter reporter, ReporterParameter reporterParameter) - throws MojoExecutionException - { - List printStreams = new ArrayList<>(); - FileOutputStream fout = null; - - // - try - { - OutputBuffer buffer = OutputBufferProvider.getCompatibleOutputBuffer(databaseVersion, reporter, connection); - - if (reporterParameter.isFileOutput()) - { - - File file = new File(reporterParameter.getFileOutput()); - if (!file.isAbsolute()) - { - file = new File(outputDirectory, reporterParameter.getFileOutput()); - } - - if (!file.getParentFile().exists()) - { - LOG.debug("Creating directory for reporter file " + file.getAbsolutePath()); - file.getParentFile().mkdirs(); - } - - fout = new FileOutputStream(file); - LOG.info(format("Writing report %s to %s", reporter.getTypeName(), file.getAbsolutePath())); - - // Added to the Report - printStreams.add(new PrintStream(fout)); - } - - if (reporterParameter.isConsoleOutput()) - { - LOG.info(format("Writing report %s to Console", reporter.getTypeName())); - printStreams.add(System.out); - } - buffer.printAvailable(connection, printStreams); - } - catch (Exception e) - { - throw new MojoExecutionException("Unexpected error opening file ouput ", e); - } - finally - { - if (fout != null) - { - try - { - fout.close(); - } - catch (IOException e) - { - LOG.info(format("Failed to closing the reporting %s", reporterParameter.getClass())); - } - } - } - - } - - /** - * - */ - public void addReporter(ReporterParameter parameter, Reporter reporter) - { - listReporters.add(Pair.of(reporter, parameter)); - } - +public class ReporterWriter { + + private static final Log LOG = new SystemStreamLog(); + + private List> listReporters; + + private String outputDirectory; + + private Version databaseVersion; + + /** + * Constructor of the reporter writer. + * + * @param outputDirectory the reporter output directory + * @param databaseVersion the utPLSQL framework version + */ + public ReporterWriter(String outputDirectory, Version databaseVersion) { + this.listReporters = new ArrayList<>(); + this.outputDirectory = outputDirectory; + this.databaseVersion = databaseVersion; + + } + + /** + * Adds a new reporter to the writter. + * + * @param parameter the reporter parameter + * @param reporter the reporter Object + */ + public void addReporter(ReporterParameter parameter, Reporter reporter) { + listReporters.add(Pair.of(reporter, parameter)); + } + + /** + * Writes the reporters to the output. + * + * @param connection the database connection + */ + public void writeReporters(Connection connection) throws MojoExecutionException { + for (Pair pair : listReporters) { + writeReports(connection, pair.getLeft(), pair.getRight()); + } + } + + private void writeReports(Connection connection, Reporter reporter, ReporterParameter reporterParameter) + throws MojoExecutionException { + List printStreams = new ArrayList<>(); + FileOutputStream fout = null; + + // + try { + OutputBuffer buffer = OutputBufferProvider.getCompatibleOutputBuffer(databaseVersion, reporter, connection); + + if (reporterParameter.isFileOutput()) { + + File file = new File(reporterParameter.getFileOutput()); + if (!file.isAbsolute()) { + file = new File(outputDirectory, reporterParameter.getFileOutput()); + } + + if (!file.getParentFile().exists()) { + LOG.debug("Creating directory for reporter file " + file.getAbsolutePath()); + file.getParentFile().mkdirs(); + } + + fout = new FileOutputStream(file); + LOG.info(format("Writing report %s to %s", reporter.getTypeName(), file.getAbsolutePath())); + + // Added to the Report + printStreams.add(new PrintStream(fout)); + } + + if (reporterParameter.isConsoleOutput()) { + LOG.info(format("Writing report %s to Console", reporter.getTypeName())); + printStreams.add(System.out); + } + buffer.printAvailable(connection, printStreams); + } catch (Exception e) { + throw new MojoExecutionException("Unexpected error opening file ouput ", e); + } finally { + if (fout != null) { + try { + fout.close(); + } catch (IOException e) { + LOG.info(format("Failed to closing the reporting %s", reporterParameter.getClass())); + } + } + } + + } } diff --git a/utplsql-maven-plugin/src/test/java/org/utplsql/maven/plugin/test/UtPLSQLMojoTest.java b/utplsql-maven-plugin/src/test/java/org/utplsql/maven/plugin/test/UtPLSQLMojoTest.java index be464b9..4c3f8f6 100644 --- a/utplsql-maven-plugin/src/test/java/org/utplsql/maven/plugin/test/UtPLSQLMojoTest.java +++ b/utplsql-maven-plugin/src/test/java/org/utplsql/maven/plugin/test/UtPLSQLMojoTest.java @@ -39,270 +39,274 @@ import org.utplsql.maven.plugin.reporter.ReporterWriter; @RunWith(PowerMockRunner.class) -@PrepareForTest({ - DBHelper.class, - ReporterFactory.class}) +@PrepareForTest({ DBHelper.class, ReporterFactory.class }) public class UtPLSQLMojoTest { - @Rule - public MojoRule rule = new MojoRule(); - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Mock - public Connection mockConnection; - - @Mock - public Version mockVersion; - - @Mock - public ReporterFactory mockReporterFactory; - - @Before - public void setUp() throws Exception { - mockStatic(DBHelper.class); - when(DBHelper.getDatabaseFrameworkVersion(mockConnection)).thenReturn(mockVersion); - - mockStatic(ReporterFactory.class); - when(ReporterFactory.createEmpty()).thenReturn(mockReporterFactory); - } - - /** - * testInvalidSourcesDirectory. - * - * Given : a pom.xml with invalid sources directory - * When : pom is read and buildSourcesOptions is run - * Then : it should throw a MojoExecutionException - */ - @Test - public void testInvalidSourcesDirectory() throws Exception { - UtPLSQLMojo utplsqlMojo = (UtPLSQLMojo) rule.lookupConfiguredMojo(new File("src/test/resources/invalidTestsSourcesDirectories/"), "test"); - Assert.assertNotNull(utplsqlMojo); - - // Expected exception + @Rule + public MojoRule rule = new MojoRule(); + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Mock + public Connection mockConnection; + + @Mock + public Version mockVersion; + + @Mock + public ReporterFactory mockReporterFactory; + + @Before + public void setUp() throws Exception { + mockStatic(DBHelper.class); + when(DBHelper.getDatabaseFrameworkVersion(mockConnection)).thenReturn(mockVersion); + + mockStatic(ReporterFactory.class); + when(ReporterFactory.createEmpty()).thenReturn(mockReporterFactory); + } + + /** + * testInvalidSourcesDirectory. + * + * Given : a pom.xml with invalid sources directory When : pom is read and + * buildSourcesOptions is run Then : it should throw a MojoExecutionException + */ + @Test + public void testInvalidSourcesDirectory() throws Exception { + UtPLSQLMojo utplsqlMojo = (UtPLSQLMojo) rule + .lookupConfiguredMojo(new File("src/test/resources/invalidTestsSourcesDirectories/"), "test"); + Assert.assertNotNull(utplsqlMojo); + + // Expected exception thrown.expect(MojoExecutionException.class); // Excepted message thrown.expectMessage("Invalid in your pom.xml"); - + Whitebox.invokeMethod(utplsqlMojo, "buildSourcesOptions"); - - } - - /** - * testInvalidTestsDirectory. - * - * Given : a pom.xml with invalid tests directory - * When : pom is read and buildTestsOptions is run - * Then : it should throw a MojoExecutionException - */ - @Test - public void testInvalidTestsDirectory() throws Exception { - UtPLSQLMojo utplsqlMojo = (UtPLSQLMojo) rule.lookupConfiguredMojo(new File("src/test/resources/invalidTestsSourcesDirectories/"), "test"); - Assert.assertNotNull(utplsqlMojo); - - // Expected exception + + } + + /** + * testInvalidTestsDirectory. + * + * Given : a pom.xml with invalid tests directory When : pom is read and + * buildTestsOptions is run Then : it should throw a MojoExecutionException + */ + @Test + public void testInvalidTestsDirectory() throws Exception { + UtPLSQLMojo utplsqlMojo = (UtPLSQLMojo) rule + .lookupConfiguredMojo(new File("src/test/resources/invalidTestsSourcesDirectories/"), "test"); + Assert.assertNotNull(utplsqlMojo); + + // Expected exception thrown.expect(MojoExecutionException.class); // Excepted message thrown.expectMessage("Invalid in your pom.xml"); - + Whitebox.invokeMethod(utplsqlMojo, "buildTestsOptions"); - } - - /** - * testSourcesTestsParameters. - * - * Given : a pom.xml with sources and tests with a lot of parameters - * When : pom is read and buildSourcesOptions / buildTestsOptions are run - * Then : it should fill all parameters correctly - */ - @Test - public void testSourcesTestsParameters() throws Exception { - UtPLSQLMojo utplsqlMojo = (UtPLSQLMojo) rule.lookupConfiguredMojo(new File("src/test/resources/testSourcesTestsParams/"), "test"); - Assert.assertNotNull(utplsqlMojo); - - // TODO : move to another test about reporters - List reporters = Whitebox.>getInternalState(utplsqlMojo, "reporters"); - assertEquals(reporters.size(), 2); - - // check sources - FileMapperOptions sources = Whitebox.invokeMethod(utplsqlMojo, "buildSourcesOptions"); - assertEquals(1, sources.getFilePaths().size()); - assertEquals("srcs/foo.sql", sources.getFilePaths().get(0)); - assertEquals("code_owner", sources.getObjectOwner() ); - assertEquals(".*/\\w+/(\\w+)/(\\w+)\\.\\w{3}", sources.getRegexPattern()); - assertEquals(new Integer(9), sources.getNameSubExpression()); - assertEquals(new Integer(1), sources.getTypeSubExpression()); - assertEquals(new Integer(4), sources.getOwnerSubExpression()); - assertEquals(1, sources.getTypeMappings().size()); - assertEquals("bar", sources.getTypeMappings().get(0).getKey()); - assertEquals("foo", sources.getTypeMappings().get(0).getValue()); - - // check tests - FileMapperOptions tests = Whitebox.invokeMethod(utplsqlMojo, "buildTestsOptions"); - assertEquals(2, tests.getFilePaths().size()); - assertTrue(tests.getFilePaths().contains("te/st/file.bdy")); - assertTrue(tests.getFilePaths().contains("te/st/spec.spc")); - assertEquals("tests_owner", tests.getObjectOwner() ); - assertEquals(".*/\\w+/(\\w+)/(\\w+)\\.\\w{3}", tests.getRegexPattern()); - assertEquals(new Integer(54), tests.getNameSubExpression()); - assertEquals(new Integer(21), tests.getTypeSubExpression()); - assertEquals(new Integer(24), tests.getOwnerSubExpression()); - assertEquals(1, tests.getTypeMappings().size()); - assertEquals("def", tests.getTypeMappings().get(0).getKey()); - assertEquals("abc", tests.getTypeMappings().get(0).getValue()); - - } - - /** - * testSourcesAndTestsParameterDoesNotExist. - * - * Given : a pom.xml with no sources / tests tags and default directory does not exist. - * When : pom is read and buildSourcesOptions / buildTestsOptions are run - * Then : it should not find any source files - */ - @Test - public void testSourcesAndTestsParameterDoesNotExist() throws Exception { - UtPLSQLMojo utplsqlMojo = (UtPLSQLMojo) rule.lookupConfiguredMojo(new File("src/test/resources/testNoSourcesTestsParams/directoryDoesNotExist/"), "test"); - Assert.assertNotNull(utplsqlMojo); - - - // check sources - FileMapperOptions sources = Whitebox.invokeMethod(utplsqlMojo, "buildSourcesOptions"); - assertEquals(0, sources.getFilePaths().size()); - - - // check tests - FileMapperOptions tests = Whitebox.invokeMethod(utplsqlMojo, "buildTestsOptions"); - assertEquals(0, tests.getFilePaths().size()); - } - - /** - * testSourcesAndTestsParameterDoesNotExistButDefaultDirectoryExists. - * - * Given : a pom.xml with no sources / tests tags but default directory exists. - * When : pom is read and buildSourcesOptions / buildTestsOptions are run - * Then : it should find all sources/tests files in default directories - */ - @Test - public void testSourcesAndTestsParameterDoesNotExistButDefaultDirectoryExists() throws Exception { - UtPLSQLMojo utplsqlMojo = (UtPLSQLMojo) rule.lookupConfiguredMojo(new File("src/test/resources/testNoSourcesTestsParams/directoryExists/"), "test"); - Assert.assertNotNull(utplsqlMojo); - - // check sources - FileMapperOptions sources = Whitebox.invokeMethod(utplsqlMojo, "buildSourcesOptions"); - assertEquals(2, sources.getFilePaths().size()); - assertTrue(sources.getFilePaths().contains("src/main/plsql/f1.sql")); - assertTrue(sources.getFilePaths().contains("src/main/plsql/f2.sql")); - - // check tests - FileMapperOptions tests = Whitebox.invokeMethod(utplsqlMojo, "buildTestsOptions"); - assertEquals(2, tests.getFilePaths().size()); - assertTrue(tests.getFilePaths().contains("src/test/plsql/foo/f1.pkg")); - assertTrue(tests.getFilePaths().contains("src/test/plsql/f2.pkg")); - - } - - /** - * testSourcesAndTestsParameterHaveNotDirectoryTag. - * - * Given : a pom.xml with source and test tag not containing a directory tag. - * When : pom is read and buildSourcesOptions / buildTestsOptions are run - * Then : it should find all sources/tests files in default directories - */ - @Test - public void testSourcesAndTestsParameterHaveNotDirectoryTag() throws Exception { - UtPLSQLMojo utplsqlMojo = (UtPLSQLMojo) rule.lookupConfiguredMojo(new File("src/test/resources/partialSourceAndTestTag/missingDirectory/"), "test"); - Assert.assertNotNull(utplsqlMojo); - - // check sources - FileMapperOptions sources = Whitebox.invokeMethod(utplsqlMojo, "buildSourcesOptions"); - assertEquals(2, sources.getFilePaths().size()); - assertTrue(sources.getFilePaths().contains("src/main/plsql/f1.sql")); - assertTrue(sources.getFilePaths().contains("src/main/plsql/foo/f2.sql")); - - // check tests - FileMapperOptions tests = Whitebox.invokeMethod(utplsqlMojo, "buildTestsOptions"); - assertEquals(3, tests.getFilePaths().size()); - assertTrue(tests.getFilePaths().contains("src/test/plsql/foo/f1.pkg")); - assertTrue(tests.getFilePaths().contains("src/test/plsql/f2.pkg")); - assertTrue(tests.getFilePaths().contains("src/test/plsql/foo/f1.sql")); - } - - /** - * testSourcesAndTestsParameterHaveNotDirectoryTag. - * - * Given : a pom.xml with source and test tag not containing a directory tag. - * When : pom is read and buildSourcesOptions / buildTestsOptions are run - * Then : it should find all sources/tests files in default directories - */ - @Test - public void testSourcesAndTestsParameterHaveNotIncludesTag() throws Exception { - UtPLSQLMojo utplsqlMojo = (UtPLSQLMojo) rule.lookupConfiguredMojo(new File("src/test/resources/partialSourceAndTestTag/missingIncludes/"), "test"); - Assert.assertNotNull(utplsqlMojo); - - // check sources - FileMapperOptions sources = Whitebox.invokeMethod(utplsqlMojo, "buildSourcesOptions"); - assertEquals(2, sources.getFilePaths().size()); - assertTrue(sources.getFilePaths().contains("src/main/foo/f1.sql")); - assertTrue(sources.getFilePaths().contains("src/main/foo/foo/f2.sql")); - - // check tests - FileMapperOptions tests = Whitebox.invokeMethod(utplsqlMojo, "buildTestsOptions"); - assertEquals(2, tests.getFilePaths().size()); - assertTrue(tests.getFilePaths().contains("src/test/bar/foo/f1.pkg")); - assertTrue(tests.getFilePaths().contains("src/test/bar/f2.pkg")); - } - - @Test - public void testDefaultConsoleBehaviour() throws Exception { - UtPLSQLMojo utplsqlMojo = (UtPLSQLMojo) rule.lookupConfiguredMojo(new File("src/test/resources/defaultConsoleOutputBehaviour/"), "test"); + } + + /** + * testSourcesTestsParameters. + * + * Given : a pom.xml with sources and tests with a lot of parameters When : pom + * is read and buildSourcesOptions / buildTestsOptions are run Then : it should + * fill all parameters correctly + */ + @Test + public void testSourcesTestsParameters() throws Exception { + UtPLSQLMojo utplsqlMojo = (UtPLSQLMojo) rule + .lookupConfiguredMojo(new File("src/test/resources/testSourcesTestsParams/"), "test"); + Assert.assertNotNull(utplsqlMojo); + + // TODO : move to another test about reporters + List reporters = Whitebox.>getInternalState(utplsqlMojo, "reporters"); + assertEquals(reporters.size(), 2); + + // check sources + FileMapperOptions sources = Whitebox.invokeMethod(utplsqlMojo, "buildSourcesOptions"); + assertEquals(1, sources.getFilePaths().size()); + assertEquals("srcs/foo.sql", sources.getFilePaths().get(0)); + assertEquals("code_owner", sources.getObjectOwner()); + assertEquals(".*/\\w+/(\\w+)/(\\w+)\\.\\w{3}", sources.getRegexPattern()); + assertEquals(new Integer(9), sources.getNameSubExpression()); + assertEquals(new Integer(1), sources.getTypeSubExpression()); + assertEquals(new Integer(4), sources.getOwnerSubExpression()); + assertEquals(1, sources.getTypeMappings().size()); + assertEquals("bar", sources.getTypeMappings().get(0).getKey()); + assertEquals("foo", sources.getTypeMappings().get(0).getValue()); + + // check tests + FileMapperOptions tests = Whitebox.invokeMethod(utplsqlMojo, "buildTestsOptions"); + assertEquals(2, tests.getFilePaths().size()); + assertTrue(tests.getFilePaths().contains("te/st/file.bdy")); + assertTrue(tests.getFilePaths().contains("te/st/spec.spc")); + assertEquals("tests_owner", tests.getObjectOwner()); + assertEquals(".*/\\w+/(\\w+)/(\\w+)\\.\\w{3}", tests.getRegexPattern()); + assertEquals(new Integer(54), tests.getNameSubExpression()); + assertEquals(new Integer(21), tests.getTypeSubExpression()); + assertEquals(new Integer(24), tests.getOwnerSubExpression()); + assertEquals(1, tests.getTypeMappings().size()); + assertEquals("def", tests.getTypeMappings().get(0).getKey()); + assertEquals("abc", tests.getTypeMappings().get(0).getValue()); + + } + + /** + * testSourcesAndTestsParameterDoesNotExist. + * + * Given : a pom.xml with no sources / tests tags and default directory does not + * exist. When : pom is read and buildSourcesOptions / buildTestsOptions are run + * Then : it should not find any source files + */ + @Test + public void testSourcesAndTestsParameterDoesNotExist() throws Exception { + UtPLSQLMojo utplsqlMojo = (UtPLSQLMojo) rule.lookupConfiguredMojo( + new File("src/test/resources/testNoSourcesTestsParams/directoryDoesNotExist/"), "test"); + Assert.assertNotNull(utplsqlMojo); + + // check sources + FileMapperOptions sources = Whitebox.invokeMethod(utplsqlMojo, "buildSourcesOptions"); + assertEquals(0, sources.getFilePaths().size()); + + // check tests + FileMapperOptions tests = Whitebox.invokeMethod(utplsqlMojo, "buildTestsOptions"); + assertEquals(0, tests.getFilePaths().size()); + } + + /** + * testSourcesAndTestsParameterDoesNotExistButDefaultDirectoryExists. + * + * Given : a pom.xml with no sources / tests tags but default directory exists. + * When : pom is read and buildSourcesOptions / buildTestsOptions are run Then : + * it should find all sources/tests files in default directories + */ + @Test + public void testSourcesAndTestsParameterDoesNotExistButDefaultDirectoryExists() throws Exception { + UtPLSQLMojo utplsqlMojo = (UtPLSQLMojo) rule + .lookupConfiguredMojo(new File("src/test/resources/testNoSourcesTestsParams/directoryExists/"), "test"); Assert.assertNotNull(utplsqlMojo); - + + // check sources + FileMapperOptions sources = Whitebox.invokeMethod(utplsqlMojo, "buildSourcesOptions"); + assertEquals(2, sources.getFilePaths().size()); + assertTrue(sources.getFilePaths().contains("src/main/plsql/f1.sql")); + assertTrue(sources.getFilePaths().contains("src/main/plsql/f2.sql")); + + // check tests + FileMapperOptions tests = Whitebox.invokeMethod(utplsqlMojo, "buildTestsOptions"); + assertEquals(2, tests.getFilePaths().size()); + assertTrue(tests.getFilePaths().contains("src/test/plsql/foo/f1.pkg")); + assertTrue(tests.getFilePaths().contains("src/test/plsql/f2.pkg")); + + } + + /** + * testSourcesAndTestsParameterHaveNotDirectoryTag. + * + * Given : a pom.xml with source and test tag not containing a directory tag. + * When : pom is read and buildSourcesOptions / buildTestsOptions are run Then : + * it should find all sources/tests files in default directories + */ + @Test + public void testSourcesAndTestsParameterHaveNotDirectoryTag() throws Exception { + UtPLSQLMojo utplsqlMojo = (UtPLSQLMojo) rule + .lookupConfiguredMojo(new File("src/test/resources/partialSourceAndTestTag/missingDirectory/"), "test"); + Assert.assertNotNull(utplsqlMojo); + + // check sources + FileMapperOptions sources = Whitebox.invokeMethod(utplsqlMojo, "buildSourcesOptions"); + assertEquals(2, sources.getFilePaths().size()); + assertTrue(sources.getFilePaths().contains("src/main/plsql/f1.sql")); + assertTrue(sources.getFilePaths().contains("src/main/plsql/foo/f2.sql")); + + // check tests + FileMapperOptions tests = Whitebox.invokeMethod(utplsqlMojo, "buildTestsOptions"); + assertEquals(3, tests.getFilePaths().size()); + assertTrue(tests.getFilePaths().contains("src/test/plsql/foo/f1.pkg")); + assertTrue(tests.getFilePaths().contains("src/test/plsql/f2.pkg")); + assertTrue(tests.getFilePaths().contains("src/test/plsql/foo/f1.sql")); + } + + /** + * testSourcesAndTestsParameterHaveNotDirectoryTag. + * + * Given : a pom.xml with source and test tag not containing a directory tag. + * When : pom is read and buildSourcesOptions / buildTestsOptions are run Then : + * it should find all sources/tests files in default directories + */ + @Test + public void testSourcesAndTestsParameterHaveNotIncludesTag() throws Exception { + UtPLSQLMojo utplsqlMojo = (UtPLSQLMojo) rule + .lookupConfiguredMojo(new File("src/test/resources/partialSourceAndTestTag/missingIncludes/"), "test"); + Assert.assertNotNull(utplsqlMojo); + + // check sources + FileMapperOptions sources = Whitebox.invokeMethod(utplsqlMojo, "buildSourcesOptions"); + assertEquals(2, sources.getFilePaths().size()); + assertTrue(sources.getFilePaths().contains("src/main/foo/f1.sql")); + assertTrue(sources.getFilePaths().contains("src/main/foo/foo/f2.sql")); + + // check tests + FileMapperOptions tests = Whitebox.invokeMethod(utplsqlMojo, "buildTestsOptions"); + assertEquals(2, tests.getFilePaths().size()); + assertTrue(tests.getFilePaths().contains("src/test/bar/foo/f1.pkg")); + assertTrue(tests.getFilePaths().contains("src/test/bar/f2.pkg")); + } + + @Test + public void testDefaultConsoleBehaviour() throws Exception { + UtPLSQLMojo utplsqlMojo = (UtPLSQLMojo) rule + .lookupConfiguredMojo(new File("src/test/resources/defaultConsoleOutputBehaviour/"), "test"); + Assert.assertNotNull(utplsqlMojo); + List reporterList = new ArrayList<>(); when(mockReporterFactory.createReporter(anyString())).thenAnswer(invocation -> { Reporter mockReporter = mock(Reporter.class); reporterList.add(mockReporter); return mockReporter; }); - + Whitebox.invokeMethod(utplsqlMojo, "initReporters", mockConnection, mockVersion, mockReporterFactory); - + // Assert that we called the create reporter with the correct parameters. verify(mockReporterFactory, times(2)).createReporter("UT_DOCUMENTATION_REPORTER"); verify(mockReporterFactory).createReporter("UT_COVERAGE_SONAR_REPORTER"); - verify(mockReporterFactory).createReporter("UT_SONAR_TEST_REPORTER"); + verify(mockReporterFactory).createReporter("UT_SONAR_TEST_REPORTER"); verifyNoMoreInteractions(mockReporterFactory); - + // Assert that all reporters have been initialized. for (Reporter mockReporter : reporterList) { verify(mockReporter).init(mockConnection); verifyNoMoreInteractions(mockReporter); } - + // Assert that we added only the necessary reporters to the writer. ReporterWriter reporterWritter = Whitebox.getInternalState(utplsqlMojo, "reporterWriter"); - List> listReporters = Whitebox.getInternalState(reporterWritter, "listReporters"); + List> listReporters = + Whitebox.getInternalState(reporterWritter, "listReporters"); assertEquals(3, listReporters.size()); - + ReporterParameter reporterParameter1 = listReporters.get(0).getRight(); assertTrue(reporterParameter1.isConsoleOutput()); assertFalse(reporterParameter1.isFileOutput()); - + ReporterParameter reporterParameter2 = listReporters.get(1).getRight(); assertFalse(reporterParameter2.isConsoleOutput()); assertTrue(reporterParameter2.isFileOutput()); - + ReporterParameter reporterParameter3 = listReporters.get(2).getRight(); assertTrue(reporterParameter3.isConsoleOutput()); assertTrue(reporterParameter3.isFileOutput()); - } - - @Test - public void testAddDefaultReporter() throws Exception { - UtPLSQLMojo utplsqlMojo = (UtPLSQLMojo) rule.lookupConfiguredMojo(new File("src/test/resources/defaultConsoleOutputBehaviour/"), "test"); + } + + @Test + public void testAddDefaultReporter() throws Exception { + UtPLSQLMojo utplsqlMojo = (UtPLSQLMojo) rule + .lookupConfiguredMojo(new File("src/test/resources/defaultConsoleOutputBehaviour/"), "test"); Assert.assertNotNull(utplsqlMojo); - + List reporterList = new ArrayList<>(); when(mockReporterFactory.createReporter(anyString())).thenAnswer(invocation -> { Reporter mockReporter = mock(Reporter.class); @@ -310,15 +314,14 @@ public void testAddDefaultReporter() throws Exception { reporterList.add(mockReporter); return mockReporter; }); - + List reporterParameters = Whitebox.getInternalState(utplsqlMojo, "reporters"); reporterParameters.clear(); - + Whitebox.invokeMethod(utplsqlMojo, "initReporters", mockConnection, mockVersion, mockReporterFactory); - + assertEquals(1, reporterList.size()); assertEquals("UT_DOCUMENTATION_REPORTER", reporterList.get(0).getTypeName()); verify(reporterList.get(0)).init(mockConnection); - } - + } } diff --git a/utplsql-maven-plugin/src/test/resources/defaultConsoleOutputBehaviour/pom.xml b/utplsql-maven-plugin/src/test/resources/defaultConsoleOutputBehaviour/pom.xml index 0bfc40f..2f23eba 100644 --- a/utplsql-maven-plugin/src/test/resources/defaultConsoleOutputBehaviour/pom.xml +++ b/utplsql-maven-plugin/src/test/resources/defaultConsoleOutputBehaviour/pom.xml @@ -1,84 +1,84 @@ - 4.0.0 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + org.utplsql + utplsql-maven-plugin-test + 3.1.0-SNAPSHOT - org.utplsql - utplsql-maven-plugin-test - 3.1.0-SNAPSHOT + pom - pom + utplsql-maven-plugin Maven Plugin Test - utplsql-maven-plugin Maven Plugin Test + http://utplsql.org - http://utplsql.org + + jdbc:oracle:thin:@180.129.3.101:1521:xe + ut3 + XNtxj8eEgA6X6b6f + - - jdbc:oracle:thin:@180.129.3.101:1521:xe - ut3 - XNtxj8eEgA6X6b6f - + - + ../../../target/ - ../../../target/ - - - org.utplsql - utplsql-maven-plugin - {project.version} - - test - - - + + + org.utplsql + utplsql-maven-plugin + {project.version} - false + + test + - - :plsql - + + false - - - UT_DOCUMENTATION_REPORTER - - - UT_DOCUMENTATION_REPORTER - false - - - UT_COVERAGE_SONAR_REPORTER - coverage-sonar-reporter.xml - - - UT_SONAR_TEST_REPORTER - utplsql/sonar-test-reporter.xml - true - - + + :plsql + - - - foo - - **/*sql - - - + + + UT_DOCUMENTATION_REPORTER + + + UT_DOCUMENTATION_REPORTER + false + + + UT_COVERAGE_SONAR_REPORTER + coverage-sonar-reporter.xml + + + UT_SONAR_TEST_REPORTER + utplsql/sonar-test-reporter.xml + true + + - - - bar - - **/*.spc - **/*.bdy - - - - - - - - \ No newline at end of file + + + foo + + **/*sql + + + + + + + bar + + **/*.spc + **/*.bdy + + + + + + + + diff --git a/utplsql-maven-plugin/src/test/resources/invalidTestsSourcesDirectories/pom.xml b/utplsql-maven-plugin/src/test/resources/invalidTestsSourcesDirectories/pom.xml index 1c5e6f0..5993111 100644 --- a/utplsql-maven-plugin/src/test/resources/invalidTestsSourcesDirectories/pom.xml +++ b/utplsql-maven-plugin/src/test/resources/invalidTestsSourcesDirectories/pom.xml @@ -1,78 +1,79 @@ - 4.0.0 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + org.utplsql + utplsql-maven-plugin-test + 3.1.0-SNAPSHOT - org.utplsql - utplsql-maven-plugin-test - 3.1.0-SNAPSHOT + pom - pom + utplsql-maven-plugin Maven Plugin Test - utplsql-maven-plugin Maven Plugin Test + http://utplsql.org - http://utplsql.org + + jdbc:oracle:thin:@180.129.3.101:1521:xe + ut3 + XNtxj8eEgA6X6b6f + - - jdbc:oracle:thin:@180.129.3.101:1521:xe - ut3 - XNtxj8eEgA6X6b6f - + - + ../../../target/ - ../../../target/ - - - org.utplsql - utplsql-maven-plugin - {project.version} - - test - - - + + + org.utplsql + utplsql-maven-plugin + {project.version} - false + + test + - - :plsql - + - - - UT_COVERAGE_SONAR_REPORTER - utplsql/coverage-sonar-reporter.xml - true - - - UT_SONAR_TEST_REPORTER - utplsql/sonar-test-reporter.xml - true - - + false - - - foo - - **/*sql - - - + + :plsql + - - - bar - - **/*.spc - **/*.bdy - - - - - - - + + + UT_COVERAGE_SONAR_REPORTER + utplsql/coverage-sonar-reporter.xml + true + + + UT_SONAR_TEST_REPORTER + utplsql/sonar-test-reporter.xml + true + + + + + + foo + + **/*sql + + + + + + + bar + + **/*.spc + **/*.bdy + + + + + + + \ No newline at end of file diff --git a/utplsql-maven-plugin/src/test/resources/partialSourceAndTestTag/missingDirectory/pom.xml b/utplsql-maven-plugin/src/test/resources/partialSourceAndTestTag/missingDirectory/pom.xml index 796dda3..06184eb 100644 --- a/utplsql-maven-plugin/src/test/resources/partialSourceAndTestTag/missingDirectory/pom.xml +++ b/utplsql-maven-plugin/src/test/resources/partialSourceAndTestTag/missingDirectory/pom.xml @@ -1,80 +1,81 @@ - 4.0.0 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + org.utplsql + utplsql-maven-plugin-test + 3.1.0-SNAPSHOT - org.utplsql - utplsql-maven-plugin-test - 3.1.0-SNAPSHOT + pom - pom + utplsql-maven-plugin Maven Plugin Test - utplsql-maven-plugin Maven Plugin Test + http://utplsql.org - http://utplsql.org + + jdbc:oracle:thin:@180.129.3.101:1521:xe + ut3 + XNtxj8eEgA6X6b6f + / + - - jdbc:oracle:thin:@180.129.3.101:1521:xe - ut3 - XNtxj8eEgA6X6b6f - / - + - + + + org.utplsql + utplsql-maven-plugin + {project.version} - - - org.utplsql - utplsql-maven-plugin - {project.version} - - test - - - + + test + - false + - - :plsql - + false - - - UT_COVERAGE_SONAR_REPORTER - utplsql/coverage-sonar-reporter.xml - true - - - UT_SONAR_TEST_REPORTER - utplsql/sonar-test-reporter.xml - true - - + + :plsql + - - - - **/*sql - - - - - - - **/*sql - - - - - - **/*.pkg - - - - - - - + + + UT_COVERAGE_SONAR_REPORTER + utplsql/coverage-sonar-reporter.xml + true + + + UT_SONAR_TEST_REPORTER + utplsql/sonar-test-reporter.xml + true + + + + + + + **/*sql + + + + + + + + **/*sql + + + + + + **/*.pkg + + + + + + + \ No newline at end of file diff --git a/utplsql-maven-plugin/src/test/resources/partialSourceAndTestTag/missingIncludes/pom.xml b/utplsql-maven-plugin/src/test/resources/partialSourceAndTestTag/missingIncludes/pom.xml index e6459bf..3f41158 100644 --- a/utplsql-maven-plugin/src/test/resources/partialSourceAndTestTag/missingIncludes/pom.xml +++ b/utplsql-maven-plugin/src/test/resources/partialSourceAndTestTag/missingIncludes/pom.xml @@ -1,70 +1,71 @@ - 4.0.0 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + org.utplsql + utplsql-maven-plugin-test + 3.1.0-SNAPSHOT - org.utplsql - utplsql-maven-plugin-test - 3.1.0-SNAPSHOT + pom - pom + utplsql-maven-plugin Maven Plugin Test - utplsql-maven-plugin Maven Plugin Test + http://utplsql.org - http://utplsql.org + + jdbc:oracle:thin:@180.129.3.101:1521:xe + ut3 + XNtxj8eEgA6X6b6f + / + - - jdbc:oracle:thin:@180.129.3.101:1521:xe - ut3 - XNtxj8eEgA6X6b6f - / - + - + + + org.utplsql + utplsql-maven-plugin + {project.version} - - - org.utplsql - utplsql-maven-plugin - {project.version} - - test - - - + + test + - false + - - :plsql - + false - - - UT_COVERAGE_SONAR_REPORTER - utplsql/coverage-sonar-reporter.xml - true - - - UT_SONAR_TEST_REPORTER - utplsql/sonar-test-reporter.xml - true - - + + :plsql + - - - src/main/foo - - - - - src/test/bar - - - - - - + + + UT_COVERAGE_SONAR_REPORTER + utplsql/coverage-sonar-reporter.xml + true + + + UT_SONAR_TEST_REPORTER + utplsql/sonar-test-reporter.xml + true + + + + + + src/main/foo + + + + + + src/test/bar + + + + + + \ No newline at end of file diff --git a/utplsql-maven-plugin/src/test/resources/testNoSourcesTestsParams/directoryDoesNotExist/pom.xml b/utplsql-maven-plugin/src/test/resources/testNoSourcesTestsParams/directoryDoesNotExist/pom.xml index 6606b00..75234c4 100644 --- a/utplsql-maven-plugin/src/test/resources/testNoSourcesTestsParams/directoryDoesNotExist/pom.xml +++ b/utplsql-maven-plugin/src/test/resources/testNoSourcesTestsParams/directoryDoesNotExist/pom.xml @@ -1,62 +1,60 @@ - 4.0.0 - - - org.utplsql - utplsql-maven-plugin-test - 3.1.0-SNAPSHOT - - pom - - utplsql-maven-plugin Maven Plugin Test - - http://utplsql.org - - - jdbc:oracle:thin:@180.129.3.101:1521:xe - ut3 - XNtxj8eEgA6X6b6f - - - - - ../../../target/ - - - org.utplsql - utplsql-maven-plugin - {project.version} - - test - - - - - false - - - :plsql - - - - - UT_COVERAGE_SONAR_REPORTER - utplsql/coverage-sonar-reporter.xml - true - - - UT_SONAR_TEST_REPORTER - utplsql/sonar-test-reporter.xml - true - - - - - - - - - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + + org.utplsql + utplsql-maven-plugin-test + 3.1.0-SNAPSHOT + + pom + + utplsql-maven-plugin Maven Plugin Test + + http://utplsql.org + + + jdbc:oracle:thin:@180.129.3.101:1521:xe + ut3 + XNtxj8eEgA6X6b6f + + + + + ../../../target/ + + + + org.utplsql + utplsql-maven-plugin + {project.version} + + + test + + + + + false + + + :plsql + + + + + UT_COVERAGE_SONAR_REPORTER + utplsql/coverage-sonar-reporter.xml + true + + + UT_SONAR_TEST_REPORTER + utplsql/sonar-test-reporter.xml + true + + + + + + \ No newline at end of file diff --git a/utplsql-maven-plugin/src/test/resources/testNoSourcesTestsParams/directoryExists/pom.xml b/utplsql-maven-plugin/src/test/resources/testNoSourcesTestsParams/directoryExists/pom.xml index 7f38f37..ba12beb 100644 --- a/utplsql-maven-plugin/src/test/resources/testNoSourcesTestsParams/directoryExists/pom.xml +++ b/utplsql-maven-plugin/src/test/resources/testNoSourcesTestsParams/directoryExists/pom.xml @@ -1,62 +1,59 @@ - 4.0.0 - - - org.utplsql - utplsql-maven-plugin-test - 3.1.0-SNAPSHOT - - pom - - utplsql-maven-plugin Maven Plugin Test - - http://utplsql.org - - - jdbc:oracle:thin:@180.129.3.101:1521:xe - ut3 - XNtxj8eEgA6X6b6f - / - - - - - - - org.utplsql - utplsql-maven-plugin - {project.version} - - test - - - - - false - - - :plsql - - - - - UT_COVERAGE_SONAR_REPORTER - utplsql/coverage-sonar-reporter.xml - true - - - UT_SONAR_TEST_REPORTER - utplsql/sonar-test-reporter.xml - true - - - - - - - - - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + + org.utplsql + utplsql-maven-plugin-test + 3.1.0-SNAPSHOT + + pom + + utplsql-maven-plugin Maven Plugin Test + + http://utplsql.org + + + jdbc:oracle:thin:@180.129.3.101:1521:xe + ut3 + XNtxj8eEgA6X6b6f + / + + + + + + + org.utplsql + utplsql-maven-plugin + {project.version} + + + test + + + + + false + + + :plsql + + + + + UT_COVERAGE_SONAR_REPORTER + utplsql/coverage-sonar-reporter.xml + true + + + UT_SONAR_TEST_REPORTER + utplsql/sonar-test-reporter.xml + true + + + + + + \ No newline at end of file diff --git a/utplsql-maven-plugin/src/test/resources/testSourcesTestsParams/pom.xml b/utplsql-maven-plugin/src/test/resources/testSourcesTestsParams/pom.xml index 21139f8..609a8a4 100644 --- a/utplsql-maven-plugin/src/test/resources/testSourcesTestsParams/pom.xml +++ b/utplsql-maven-plugin/src/test/resources/testSourcesTestsParams/pom.xml @@ -1,101 +1,103 @@ - 4.0.0 - - - org.utplsql - utplsql-maven-plugin-test - 3.1.0-SNAPSHOT - - pom - - utplsql-maven-plugin Maven Plugin Test - - http://utplsql.org - - - jdbc:oracle:thin:@180.129.3.101:1521:xe - ut3 - XNtxj8eEgA6X6b6f - - - - - ../../../target/ - - - org.utplsql - utplsql-maven-plugin - {project.version} - - test - - - - - false - - - :plsql - - - - - UT_COVERAGE_SONAR_REPORTER - utplsql/coverage-sonar-reporter.xml - true - - - UT_SONAR_TEST_REPORTER - utplsql/sonar-test-reporter.xml - true - - - - - - srcs - - **/*sql - - - - code_owner - .*/\w+/(\w+)/(\w+)\.\w{3} - 9 - 1 - 4 - - - foo - bar - - - - - - te/st - - **/*.spc - **/*.bdy - - - - tests_owner - .*/\w+/(\w+)/(\w+)\.\w{3} - 24 - 54 - 21 - - - abc - def - - - - - - - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + + org.utplsql + utplsql-maven-plugin-test + 3.1.0-SNAPSHOT + + pom + + utplsql-maven-plugin Maven Plugin Test + + http://utplsql.org + + + jdbc:oracle:thin:@180.129.3.101:1521:xe + ut3 + XNtxj8eEgA6X6b6f + + + + + ../../../target/ + + + + org.utplsql + utplsql-maven-plugin + {project.version} + + + test + + + + + false + + + :plsql + + + + + UT_COVERAGE_SONAR_REPORTER + utplsql/coverage-sonar-reporter.xml + true + + + UT_SONAR_TEST_REPORTER + utplsql/sonar-test-reporter.xml + true + + + + + + srcs + + **/*sql + + + + + code_owner + .*/\w+/(\w+)/(\w+)\.\w{3} + 9 + 1 + 4 + + + foo + bar + + + + + + te/st + + **/*.spc + **/*.bdy + + + + + tests_owner + .*/\w+/(\w+)/(\w+)\.\w{3} + 24 + 54 + 21 + + + abc + def + + + + + + \ No newline at end of file From f8ea81e6fc06c914d3609121fa2c49687e3295ca Mon Sep 17 00:00:00 2001 From: Vinicius Avellar Date: Mon, 8 Oct 2018 21:02:42 +0100 Subject: [PATCH 2/4] Added some missing information to the pom file --- utplsql-maven-plugin/pom.xml | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/utplsql-maven-plugin/pom.xml b/utplsql-maven-plugin/pom.xml index 5bb82cb..e3a6527 100644 --- a/utplsql-maven-plugin/pom.xml +++ b/utplsql-maven-plugin/pom.xml @@ -13,7 +13,7 @@ maven-plugin utplsql-maven-plugin Maven Plugin - + A maven plugin for running Unit Tests with utPLSQL v3+. https://github.com/utPLSQL/utPLSQL-maven-plugin @@ -24,6 +24,31 @@ + + + Vinicius Avellar Moreira + utPLSQL.org + http://utplsql.org + + + + + scm:git:git://github.com/utPLSQL/utPLSQL-maven-plugin.git + scm:git:ssh://github.com/utPLSQL/utPLSQL-maven-plugin.git + https://github.com/utPLSQL/utPLSQL-maven-plugin + + + + + ossrh + https://oss.sonatype.org/content/repositories/snapshots + + + ossrh + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + + UTF-8 1.8 From 5b842a7b8808e45a40d45d9af6e0dc6adc8fe0c6 Mon Sep 17 00:00:00 2001 From: Vinicius Avellar Date: Mon, 8 Oct 2018 21:56:49 +0100 Subject: [PATCH 3/4] More configuration tidy up --- utplsql-maven-plugin/pom.xml | 86 ++++++++++++++++++++++++------------ 1 file changed, 58 insertions(+), 28 deletions(-) diff --git a/utplsql-maven-plugin/pom.xml b/utplsql-maven-plugin/pom.xml index e3a6527..b90151e 100644 --- a/utplsql-maven-plugin/pom.xml +++ b/utplsql-maven-plugin/pom.xml @@ -33,8 +33,7 @@ - scm:git:git://github.com/utPLSQL/utPLSQL-maven-plugin.git - scm:git:ssh://github.com/utPLSQL/utPLSQL-maven-plugin.git + scm:git:https://github.com/utPLSQL/utPLSQL-maven-plugin.git https://github.com/utPLSQL/utPLSQL-maven-plugin @@ -172,35 +171,66 @@ - - org.apache.maven.plugins - maven-javadoc-plugin - - - attach-javadocs - - jar - - - - - - org.apache.maven.plugins - maven-source-plugin - 3.0.1 - - - attach-sources - verify - - jar-no-fork - - - - + + + release + + + + release + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + + attach-javadocs + + jar + + + + + + org.apache.maven.plugins + maven-source-plugin + 3.0.1 + + + attach-sources + verify + + jar-no-fork + + + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.6 + + + sign-artifacts + verify + + sign + + + + + + + + + utplsql-java-api From 407c4819aa5dd18f975744c2169e33bbb0bbbb1b Mon Sep 17 00:00:00 2001 From: Vinicius Avellar Date: Sat, 13 Oct 2018 12:05:50 +0100 Subject: [PATCH 4/4] README file update, code formatting --- .travis/settings.xml | 42 ++- README.md | 322 +++++++++-------- utplsql-maven-plugin-it/pom.xml | 255 ++++++------- .../maven/plugin/test/UtPLSQLMojoIT.java | 340 +++++++++--------- .../it/resources/minimalist-project/pom.xml | 54 +-- .../it/resources/owner-param-project/pom.xml | 162 ++++----- .../src/it/resources/regex-project/pom.xml | 145 ++++---- .../src/it/resources/simple-project/pom.xml | 127 +++---- .../it/resources/type-mapping-project/pom.xml | 165 ++++----- 9 files changed, 827 insertions(+), 785 deletions(-) diff --git a/.travis/settings.xml b/.travis/settings.xml index 731ef52..af585a9 100644 --- a/.travis/settings.xml +++ b/.travis/settings.xml @@ -1,29 +1,27 @@ - - - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> + + + + ossrh + + true + + + ${env.GPG_EXECUTABLE} + ${env.GPG_PASSPHRASE} + + + + + ossrh + ${env.SONATYPE_USERNAME} + ${env.SONATYPE_PASSWORD} + maven.oracle.com ${env.ORACLE_OTN_USER} diff --git a/README.md b/README.md index ce82511..76bd880 100644 --- a/README.md +++ b/README.md @@ -2,69 +2,192 @@ [![Quality Gate](https://sonarcloud.io/api/project_badges/measure?project=org.utplsql%3Autplsql-maven-plugin-parent&metric=alert_status)](https://sonarcloud.io/dashboard?id=org.utplsql%3Autplsql-maven-plugin-parent) # utPLSQL-maven-plugin -A maven plugin for running Unit Tests with utPLSQL v3+ +* A maven plugin for running Unit Tests with utPLSQL v3+. ### Compatibility - -This plugin is compatible with the Java-API 3.1.0. +* This plugin is compatible with the utPLSQL Java API 3.1.0. ### Prerequisites -You have to be a fully utPLSQL environment available compatible with the Java API. - - -### Plugin Parameters - -* `dbUrl` - * URL of the Connection to the database -* `dbUser` - * Credential of the connection to the database -* `dbPass` - * Password of the connection to the database -* `ignoreFailure` - * Ignore or continue when a test fail - * Default: `${maven.test.failure.ignore}` -* `skipCompatibilityCheck` - * Skip the Compatibility Checks - * `true` | `false` (default: `false`) -* `reporters` - * List of the Reporters (Check the example below). - * You can pass the name of the reporter and/or the output file of the reporter and/or if the report is logged to the console - * This is a current list of the names of the reporters (See UtPLSQL documentation in order to check the final list): `UT_DOCUMENTATION_REPORTER`, `UT_COVERAGE_HTML_REPORTER`, `UT_TEAMCITY_REPORTER`, `UT_XUNIT_REPORTER`, `UT_COVERALLS_REPORTER`, `UT_COVERAGE_SONAR_REPORTER`, `UT_SONAR_TEST_REPORTER` - * Check the example below - -* `paths` - * Paths of the resources - -* `sources` - * Path to project source files -* `sourcesOwner` - * Owner of the tested code -* `sourcesRegexExpression` - * utPLSQL will convert file paths into database objects using the following regular expression -* `sourcesOwnerSubexpression` - * Object owner is identified by the expression with the specified set of brackets -* `sourcesNameSubexpression` - * Object name is identified by the expression with the specified set of brackets -* `sourcesTypeSubexpression` - * Object Type is identified by the expression with the specified set of brackets -* `sourcesCustomTypeMapping` - * List of Custom Type Mappings - -* `tests` - * Path to project test files -* `testsOwner` - * Owner of the testing code -* `testsRegexExpression` - * utPLSQL will convert file paths into database objects using the following regular expression -* `testsOwnerSubexpression` - * Owner is identified by the expression with the specified set of brackets -* `testsNameSubexpression` - * Object name is identified by the expression with the specified set of brackets -* `testsTypeSubexpression` - * Object Type is identified by the expression with the specified set of brackets -* `testsCustomTypeMapping` - * List of Custom Type Mappings +* Java SE Runtime Environment 8 +* Maven Version 3.5+ +* You need to have a compatible version utPLSQL framework installed in the database. Please refer to the Java API documentation for compatibility checks. + +The plugin relies on the Java API for database operations, which has the OJDBC as a maven dependency. To be able to download the Oracle dependencies, you need to configure your access to Oracle's Maven Repository: + +http://docs.oracle.com/middleware/1213/core/MAVEN/config_maven_repo.htm#MAVEN9010 + +Sections 6.1 and 6.5 are the more important ones, and the only ones you need if you're using the latest Maven version. + +### Usage + +Please refer to the following usage example for the parameters descriptions. + +```xml + + 4.0.0 + + org.my_org + my-artifact-name + 1.0.0 + + + + + + url_of_connection + + + user + + + password + + + + + + org.utplsql + utplsql-maven-plugin + 3.1.0 + + + + test + + + + + + + + + + + + + + schema_name + + + + + + src/test/resources/scripts/sources + + + **/*pkg + **/*pkb + + + + + + + + src/test/resources/scripts/test + + + **/*pkg + **/*pkb + + + + + + + + + false + + + + false + + + + + app.test1,app.test2 + + + + + app.test1,app.test2 + + + + + + + + + + + + + + + + + UT_COVERAGE_SONAR_REPORTER + + utplsql/coverage-sonar-reporter.xml + + true + + + UT_SONAR_TEST_REPORTER + utplsql/sonar-test-reporter.xml + false + + + UT_TEAMCITY_REPORTER + + + + + + code_owner + .*/\w+/(\w+)/(\w+)\.\w{3} + app + 2 + 1 + + + package body + package_bodies + + + + + + tests_owner + .*/\w+/(\w+)/(\w+)\.\w{3} + test + 2 + 1 + + + package body + package_bodies + + + + + + + + + + +``` +More project samples are available in the src/test/resources directory: +* **simple-project:** minimalist test project with standard project directory structure. +* **regex-project:** overrides project directory structure and use additional parameters (sourcesRegexExpression, testsRegexExpression, ...), to tell utPLSQL how project files should be mapped into database objects. +* **type-mapping-project:** this project shows how to use regex and custom type parameters together. +* **owner-param-project:** this project demonstrates how to use sourcesOwner and testsOwner parameters. ### Comparaison with the CLI @@ -96,86 +219,3 @@ You have to be a fully utPLSQL environment available compatible with the Java AP | -owner_subexpression | | testsOwnerSubexpression | | -type_subexpression | | testsTypeSubexpression | | -name_subexpression | | testsNameSubexpression | - -### Sample of use -The next snippet is a sample of declaration of the pom -```xml - - 4.0.0 - - org.my_org - my-artifact-name - 1.0.0 - - - url_of_connection - user - password - - - - - - org.utplsql - utplsql-maven-plugin - 3.1.0 - - - - test - - - false - - schema_name - - - - UT_COVERAGE_SONAR_REPORTER - utplsql/coverage-sonar-reporter.xml - true - - - UT_SONAR_TEST_REPORTER - utplsql/sonar-test-reporter.xml - false - - - UT_TEAMCITY_REPORTER - - - - - src/test/resources/scripts/sources - - **/*pkg - **/*pkb - - - - - - src/test/resources/scripts/test - - **/*pkg - **/*pkb - - - - - - - - - - -``` - -More project samples are available in the src/test/resources directory : -* simple-project : minimalist test project with standard project directory structure -* regex-project : override project directory structure and use additional parameters (sourcesRegexExpression, testsRegexExpression, ...) to tell utPLSQL how the project files are to be mapped into database objects. -* type-mapping-project : This project shows how to use regex and custom type parameters togethers. -* owner-param-project : This project demonstrates how to use sourcesOwner and testsOwner parameters. - diff --git a/utplsql-maven-plugin-it/pom.xml b/utplsql-maven-plugin-it/pom.xml index 19a9e24..658fed4 100644 --- a/utplsql-maven-plugin-it/pom.xml +++ b/utplsql-maven-plugin-it/pom.xml @@ -1,134 +1,135 @@ - - 4.0.0 + + 4.0.0 - - org.utplsql - utplsql-maven-plugin-parent - 3.1.0-SNAPSHOT - - utplsql-maven-plugin Integration tests - utplsql-maven-plugin-it - jar + + org.utplsql + utplsql-maven-plugin-parent + 3.1.0-SNAPSHOT + + utplsql-maven-plugin Integration tests + utplsql-maven-plugin-it + jar - - UTF-8 - 1.8 - + + UTF-8 + 1.8 + - - - org.apache.maven - maven-model - 3.0.2 - - - commons-io - commons-io - 2.5 - - - org.apache.maven.shared - maven-verifier - 1.6 - - - junit - junit - 4.12 - test - - + + + org.apache.maven + maven-model + 3.0.2 + + + commons-io + commons-io + 2.5 + + + org.apache.maven.shared + maven-verifier + 1.6 + + + junit + junit + 4.12 + test + + - - - - org.apache.maven.plugins - maven-install-plugin - 2.5.2 - - true - - + + + + org.apache.maven.plugins + maven-install-plugin + 2.5.2 + + true + + - - org.apache.maven.plugins - maven-deploy-plugin - 2.8.2 - - true - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - ${java.version} - ${java.version} - ${project.build.sourceEncoding} - - - - org.codehaus.mojo - build-helper-maven-plugin - 3.0.0 - - - add-it-resource - process-resources - - add-test-resource - - - - - src/it/resources - - - - - - - - org.codehaus.mojo - build-helper-maven-plugin - 3.0.0 - - - add-it-source - process-resources - - add-test-source - - - - src/it/java - - - - - - - org.apache.maven.plugins - maven-failsafe-plugin - 2.22.0 - - - integration-test - - integration-test - - - - verify - - verify - - - - + + org.apache.maven.plugins + maven-deploy-plugin + 2.8.2 + + true + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.7.0 + + ${java.version} + ${java.version} + ${project.build.sourceEncoding} + + + + org.codehaus.mojo + build-helper-maven-plugin + 3.0.0 + + + add-it-resource + process-resources + + add-test-resource + + + + + src/it/resources + + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 3.0.0 + + + add-it-source + process-resources + + add-test-source + + + + src/it/java + + + + + + + org.apache.maven.plugins + maven-failsafe-plugin + 2.22.0 + + + integration-test + + integration-test + + + + verify + + verify + + + + - - + + \ No newline at end of file diff --git a/utplsql-maven-plugin-it/src/it/java/org/utpsql/maven/plugin/test/UtPLSQLMojoIT.java b/utplsql-maven-plugin-it/src/it/java/org/utpsql/maven/plugin/test/UtPLSQLMojoIT.java index 1c2a301..4978e01 100644 --- a/utplsql-maven-plugin-it/src/it/java/org/utpsql/maven/plugin/test/UtPLSQLMojoIT.java +++ b/utplsql-maven-plugin-it/src/it/java/org/utpsql/maven/plugin/test/UtPLSQLMojoIT.java @@ -21,174 +21,174 @@ public class UtPLSQLMojoIT { - private static String pluginVersion = null; - - @BeforeClass - public static void setUp() throws VerificationException, IOException, XmlPullParserException { - // Read plugin pom file - MavenXpp3Reader reader = new MavenXpp3Reader(); - Model model = reader.read(new FileReader("../pom.xml")); - - File pomFile = new File("../"); - Verifier verifier = new Verifier(pomFile.getAbsolutePath()); - - // install plugin - verifier.setAutoclean(false); - verifier.addCliOption("-Dmaven.skip.test=true"); - verifier.addCliOption("-DskipITs"); - verifier.executeGoal("install"); - - pluginVersion = model.getVersion(); - } - - @Test - public void testSimpleProject() throws Exception { - - try { - final String PROJECT_NAME = "simple-project"; - File testProject = ResourceExtractor.simpleExtractResources(getClass(), "/" + PROJECT_NAME); - - Verifier verifier; - verifier = new Verifier(testProject.getAbsolutePath()); - verifier.addCliOption("-N"); - verifier.addCliOption("-Dutplsql-maven-plugin-version=" + pluginVersion); - verifier.addCliOption("-DdbUrl=" + System.getProperty("dbUrl")); - verifier.addCliOption("-DdbUser=" + System.getProperty("dbUser")); - verifier.addCliOption("-DdbPass=" + System.getProperty("dbPass")); - - verifier.executeGoal("test"); - - checkReportsGenerated(PROJECT_NAME, "utplsql/sonar-test-reporter.xml", - "utplsql/coverage-sonar-reporter.xml"); - } catch (Exception e) { - e.printStackTrace(); - Assert.fail("Unexpected Exception running the test of Definition " + e.getMessage()); - } - } - - @Test - public void testRegexProject() throws Exception { - try { - final String PROJECT_NAME = "regex-project"; - File testProject = ResourceExtractor.simpleExtractResources(getClass(), "/" + PROJECT_NAME); - - Verifier verifier; - verifier = new Verifier(testProject.getAbsolutePath()); - verifier.addCliOption("-N"); - verifier.addCliOption("-Dutplsql-maven-plugin-version=" + pluginVersion); - verifier.addCliOption("-DdbUrl=" + System.getProperty("dbUrl")); - verifier.addCliOption("-DdbUser=" + System.getProperty("dbUser")); - verifier.addCliOption("-DdbPass=" + System.getProperty("dbPass")); - - verifier.executeGoal("test"); - - checkReportsGenerated(PROJECT_NAME, "utplsql/sonar-test-reporter.xml", - "utplsql/coverage-sonar-reporter.xml"); - } catch (Exception e) { - e.printStackTrace(); - Assert.fail("Unexpected Exception running the test : " + e.getMessage()); - } - } - - @Test - public void testTypeMappingProject() throws Exception { - try { - final String PROJECT_NAME = "type-mapping-project"; - File testProject = ResourceExtractor.simpleExtractResources(getClass(), "/" + PROJECT_NAME); - - Verifier verifier; - verifier = new Verifier(testProject.getAbsolutePath()); - verifier.addCliOption("-N"); - verifier.addCliOption("-Dutplsql-maven-plugin-version=" + pluginVersion); - verifier.addCliOption("-DdbUrl=" + System.getProperty("dbUrl")); - verifier.addCliOption("-DdbUser=" + System.getProperty("dbUser")); - verifier.addCliOption("-DdbPass=" + System.getProperty("dbPass")); - - verifier.executeGoal("test"); - - checkReportsGenerated(PROJECT_NAME, "utplsql/sonar-test-reporter.xml", - "utplsql/coverage-sonar-reporter.xml"); - } catch (Exception e) { - e.printStackTrace(); - Assert.fail("Unexpected Exception running the test : " + e.getMessage()); - } - } - - @Test - public void testOwnerParameterProject() throws Exception { - try { - final String PROJECT_NAME = "owner-param-project"; - File testProject = ResourceExtractor.simpleExtractResources(getClass(), "/" + PROJECT_NAME); - - Verifier verifier; - verifier = new Verifier(testProject.getAbsolutePath()); - verifier.addCliOption("-N"); - verifier.addCliOption("-Dutplsql-maven-plugin-version=" + pluginVersion); - verifier.addCliOption("-DdbUrl=" + System.getProperty("dbUrl")); - verifier.addCliOption("-DdbUser=" + System.getProperty("dbUser")); - verifier.addCliOption("-DdbPass=" + System.getProperty("dbPass")); - - verifier.executeGoal("test"); - - checkReportsGenerated(PROJECT_NAME, "utplsql/sonar-test-reporter.xml", - "utplsql/coverage-sonar-reporter.xml"); - } catch (Exception e) { - e.printStackTrace(); - Assert.fail("Unexpected Exception running the test : " + e.getMessage()); - } - } - - @Test - public void testMinimalistProject() throws Exception { - try { - final String PROJECT_NAME = "minimalist-project"; - File testProject = ResourceExtractor.simpleExtractResources(getClass(), "/" + PROJECT_NAME); - - Verifier verifier; - verifier = new Verifier(testProject.getAbsolutePath()); - verifier.addCliOption("-N"); - verifier.addCliOption("-Dutplsql-maven-plugin-version=" + pluginVersion); - verifier.addCliOption("-DdbUrl=" + System.getProperty("dbUrl")); - verifier.addCliOption("-DdbUser=" + System.getProperty("dbUser")); - verifier.addCliOption("-DdbPass=" + System.getProperty("dbPass")); - - verifier.executeGoal("test"); - } catch (Exception e) { - e.printStackTrace(); - Assert.fail("Unexpected Exception running the test : " + e.getMessage()); - } - } - - /** - * - * @param files - */ - private void checkReportsGenerated(String projectName, String... files) { - for (String filename : files) { - File outputFile = new File("target/test-classes/" + projectName + "/target", filename); - File expectedOutputFile = new File("target/test-classes/" + projectName + "/expected-output", filename); - - Assert.assertTrue("The reporter for " + filename + " was not generated", outputFile.exists()); - try { - // Duration is set to 1 before comparing contents as it is always different. - // Path separator is set to "/" to ensure windows / linux / mac compatibility - Stream stream = Files - .lines(Paths.get("target", "test-classes", projectName, "target", filename)); - - String outputContent = stream - .map(line -> line.replaceAll("(encoding=\"[^\"]*\")", "encoding=\"WINDOWS-1252\"")) - .map(line -> line.replaceAll("(duration=\"[0-9\\.]*\")", "duration=\"1\"")) - .map(line -> line.replaceAll("\\\\", "/")) - .map(line -> line.replaceAll("\r", "").replaceAll("\n", "")).collect(Collectors.joining("\n")); - - stream.close(); - Assert.assertEquals("The files differ!", - FileUtils.readFileToString(expectedOutputFile, "utf-8").replace("\r", ""), outputContent); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - Assert.fail("Unexpected Exception running the test : " + e.getMessage()); - } - } - } + private static String pluginVersion = null; + + @BeforeClass + public static void setUp() throws VerificationException, IOException, XmlPullParserException { + // Read plugin pom file + MavenXpp3Reader reader = new MavenXpp3Reader(); + Model model = reader.read(new FileReader("../pom.xml")); + + File pomFile = new File("../"); + Verifier verifier = new Verifier(pomFile.getAbsolutePath()); + + // install plugin + verifier.setAutoclean(false); + verifier.addCliOption("-Dmaven.skip.test=true"); + verifier.addCliOption("-DskipITs"); + verifier.executeGoal("install"); + + pluginVersion = model.getVersion(); + } + + @Test + public void testSimpleProject() throws Exception { + + try { + final String PROJECT_NAME = "simple-project"; + File testProject = ResourceExtractor.simpleExtractResources(getClass(), "/" + PROJECT_NAME); + + Verifier verifier; + verifier = new Verifier(testProject.getAbsolutePath()); + verifier.addCliOption("-N"); + verifier.addCliOption("-Dutplsql-maven-plugin-version=" + pluginVersion); + verifier.addCliOption("-DdbUrl=" + System.getProperty("dbUrl")); + verifier.addCliOption("-DdbUser=" + System.getProperty("dbUser")); + verifier.addCliOption("-DdbPass=" + System.getProperty("dbPass")); + + verifier.executeGoal("test"); + + checkReportsGenerated(PROJECT_NAME, "utplsql/sonar-test-reporter.xml", + "utplsql/coverage-sonar-reporter.xml"); + } catch (Exception e) { + e.printStackTrace(); + Assert.fail("Unexpected Exception running the test of Definition " + e.getMessage()); + } + } + + @Test + public void testRegexProject() throws Exception { + try { + final String PROJECT_NAME = "regex-project"; + File testProject = ResourceExtractor.simpleExtractResources(getClass(), "/" + PROJECT_NAME); + + Verifier verifier; + verifier = new Verifier(testProject.getAbsolutePath()); + verifier.addCliOption("-N"); + verifier.addCliOption("-Dutplsql-maven-plugin-version=" + pluginVersion); + verifier.addCliOption("-DdbUrl=" + System.getProperty("dbUrl")); + verifier.addCliOption("-DdbUser=" + System.getProperty("dbUser")); + verifier.addCliOption("-DdbPass=" + System.getProperty("dbPass")); + + verifier.executeGoal("test"); + + checkReportsGenerated(PROJECT_NAME, "utplsql/sonar-test-reporter.xml", + "utplsql/coverage-sonar-reporter.xml"); + } catch (Exception e) { + e.printStackTrace(); + Assert.fail("Unexpected Exception running the test : " + e.getMessage()); + } + } + + @Test + public void testTypeMappingProject() throws Exception { + try { + final String PROJECT_NAME = "type-mapping-project"; + File testProject = ResourceExtractor.simpleExtractResources(getClass(), "/" + PROJECT_NAME); + + Verifier verifier; + verifier = new Verifier(testProject.getAbsolutePath()); + verifier.addCliOption("-N"); + verifier.addCliOption("-Dutplsql-maven-plugin-version=" + pluginVersion); + verifier.addCliOption("-DdbUrl=" + System.getProperty("dbUrl")); + verifier.addCliOption("-DdbUser=" + System.getProperty("dbUser")); + verifier.addCliOption("-DdbPass=" + System.getProperty("dbPass")); + + verifier.executeGoal("test"); + + checkReportsGenerated(PROJECT_NAME, "utplsql/sonar-test-reporter.xml", + "utplsql/coverage-sonar-reporter.xml"); + } catch (Exception e) { + e.printStackTrace(); + Assert.fail("Unexpected Exception running the test : " + e.getMessage()); + } + } + + @Test + public void testOwnerParameterProject() throws Exception { + try { + final String PROJECT_NAME = "owner-param-project"; + File testProject = ResourceExtractor.simpleExtractResources(getClass(), "/" + PROJECT_NAME); + + Verifier verifier; + verifier = new Verifier(testProject.getAbsolutePath()); + verifier.addCliOption("-N"); + verifier.addCliOption("-Dutplsql-maven-plugin-version=" + pluginVersion); + verifier.addCliOption("-DdbUrl=" + System.getProperty("dbUrl")); + verifier.addCliOption("-DdbUser=" + System.getProperty("dbUser")); + verifier.addCliOption("-DdbPass=" + System.getProperty("dbPass")); + + verifier.executeGoal("test"); + + checkReportsGenerated(PROJECT_NAME, "utplsql/sonar-test-reporter.xml", + "utplsql/coverage-sonar-reporter.xml"); + } catch (Exception e) { + e.printStackTrace(); + Assert.fail("Unexpected Exception running the test : " + e.getMessage()); + } + } + + @Test + public void testMinimalistProject() throws Exception { + try { + final String PROJECT_NAME = "minimalist-project"; + File testProject = ResourceExtractor.simpleExtractResources(getClass(), "/" + PROJECT_NAME); + + Verifier verifier; + verifier = new Verifier(testProject.getAbsolutePath()); + verifier.addCliOption("-N"); + verifier.addCliOption("-Dutplsql-maven-plugin-version=" + pluginVersion); + verifier.addCliOption("-DdbUrl=" + System.getProperty("dbUrl")); + verifier.addCliOption("-DdbUser=" + System.getProperty("dbUser")); + verifier.addCliOption("-DdbPass=" + System.getProperty("dbPass")); + + verifier.executeGoal("test"); + } catch (Exception e) { + e.printStackTrace(); + Assert.fail("Unexpected Exception running the test : " + e.getMessage()); + } + } + + /** + * + * @param files + */ + private void checkReportsGenerated(String projectName, String... files) { + for (String filename : files) { + File outputFile = new File("target/test-classes/" + projectName + "/target", filename); + File expectedOutputFile = new File("target/test-classes/" + projectName + "/expected-output", filename); + + Assert.assertTrue("The reporter for " + filename + " was not generated", outputFile.exists()); + try { + // Duration is set to 1 before comparing contents as it is always different. + // Path separator is set to "/" to ensure windows / linux / mac compatibility + Stream stream = Files + .lines(Paths.get("target", "test-classes", projectName, "target", filename)); + + String outputContent = stream + .map(line -> line.replaceAll("(encoding=\"[^\"]*\")", "encoding=\"WINDOWS-1252\"")) + .map(line -> line.replaceAll("(duration=\"[0-9\\.]*\")", "duration=\"1\"")) + .map(line -> line.replaceAll("\\\\", "/")) + .map(line -> line.replaceAll("\r", "").replaceAll("\n", "")).collect(Collectors.joining("\n")); + + stream.close(); + Assert.assertEquals("The files differ!", + FileUtils.readFileToString(expectedOutputFile, "utf-8").replace("\r", ""), outputContent); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + Assert.fail("Unexpected Exception running the test : " + e.getMessage()); + } + } + } } diff --git a/utplsql-maven-plugin-it/src/it/resources/minimalist-project/pom.xml b/utplsql-maven-plugin-it/src/it/resources/minimalist-project/pom.xml index d410eff..2f80480 100644 --- a/utplsql-maven-plugin-it/src/it/resources/minimalist-project/pom.xml +++ b/utplsql-maven-plugin-it/src/it/resources/minimalist-project/pom.xml @@ -1,33 +1,33 @@ - 4.0.0 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 - org.utplsql - utplsql-maven-plugin-minimalist-test - 1.0.0 - pom + org.utplsql + utplsql-maven-plugin-minimalist-test + 1.0.0 + pom - utplsql-maven-plugin IT Minimalist - + utplsql-maven-plugin IT Minimalist + - + - - - - ${project.groupId} - utplsql-maven-plugin - ${utplsql-maven-plugin-version} - - - - test - - - + + + + ${project.groupId} + utplsql-maven-plugin + ${utplsql-maven-plugin-version} + + + + test + + + - - - - \ No newline at end of file + + + + diff --git a/utplsql-maven-plugin-it/src/it/resources/owner-param-project/pom.xml b/utplsql-maven-plugin-it/src/it/resources/owner-param-project/pom.xml index f11ba46..1cf170c 100644 --- a/utplsql-maven-plugin-it/src/it/resources/owner-param-project/pom.xml +++ b/utplsql-maven-plugin-it/src/it/resources/owner-param-project/pom.xml @@ -1,93 +1,93 @@ - 4.0.0 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 - org.utplsql - utplsql-maven-plugin-owner-parameter-test - 1.0.0 - pom + org.utplsql + utplsql-maven-plugin-owner-parameter-test + 1.0.0 + pom - utplsql-maven-plugin IT Owner Parameter - + utplsql-maven-plugin IT Owner Parameter + - + - + - - - ${project.groupId} - utplsql-maven-plugin - ${utplsql-maven-plugin-version} - - - - test - - + + + ${project.groupId} + utplsql-maven-plugin + ${utplsql-maven-plugin-version} + + + + test + + - false + false - - tests_owner - + + tests_owner + - - - UT_COVERAGE_SONAR_REPORTER - utplsql/coverage-sonar-reporter.xml - true - - - UT_SONAR_TEST_REPORTER - utplsql/sonar-test-reporter.xml - true - - + + + UT_COVERAGE_SONAR_REPORTER + utplsql/coverage-sonar-reporter.xml + true + + + UT_SONAR_TEST_REPORTER + utplsql/sonar-test-reporter.xml + true + + - - - scripts/sources - - **/*sql - - - - code_owner - .*/\w+/(\w+)/(\w+)\.\w{3} - 2 - 1 - - - package body - package_bodies - - + + + scripts/sources + + **/*sql + + + + code_owner + .*/\w+/(\w+)/(\w+)\.\w{3} + 2 + 1 + + + package body + package_bodies + + - - - scripts/test - - **/*sql - - - - tests_owner - .*/\w+/(\w+)/(\w+)\.\w{3} - 2 - 1 - - - package body - package_bodies - - - - - - - - - \ No newline at end of file + + + scripts/test + + **/*sql + + + + tests_owner + .*/\w+/(\w+)/(\w+)\.\w{3} + 2 + 1 + + + package body + package_bodies + + + + + + + + + diff --git a/utplsql-maven-plugin-it/src/it/resources/regex-project/pom.xml b/utplsql-maven-plugin-it/src/it/resources/regex-project/pom.xml index cc7e20e..0f1a41c 100644 --- a/utplsql-maven-plugin-it/src/it/resources/regex-project/pom.xml +++ b/utplsql-maven-plugin-it/src/it/resources/regex-project/pom.xml @@ -1,82 +1,83 @@ - - 4.0.0 - - org.utplsql - utplsql-maven-plugin-regex-test - 1.0.0 - pom + + 4.0.0 - utplsql-maven-plugin IT regex - + org.utplsql + utplsql-maven-plugin-regex-test + 1.0.0 + pom + + utplsql-maven-plugin IT regex + - + - - - - ${project.groupId} - utplsql-maven-plugin - ${utplsql-maven-plugin-version} - - - - test - - + + + + ${project.groupId} + utplsql-maven-plugin + ${utplsql-maven-plugin-version} + + + + test + + - false + false - - app - + + app + - - - UT_COVERAGE_SONAR_REPORTER - utplsql/coverage-sonar-reporter.xml - true - - - UT_SONAR_TEST_REPORTER - utplsql/sonar-test-reporter.xml - true - - + + + UT_COVERAGE_SONAR_REPORTER + utplsql/coverage-sonar-reporter.xml + true + + + UT_SONAR_TEST_REPORTER + utplsql/sonar-test-reporter.xml + true + + - - - scripts/sources - - **/*bdy - **/*spc - - - - .*(\\|\/)(\w+)(\\|\/)(\w+)(\\|\/)(\w+).(\w{3}) - 2 - 6 - 7 + + + scripts/sources + + **/*bdy + **/*spc + + + + .*(\\|\/)(\w+)(\\|\/)(\w+)(\\|\/)(\w+).(\w{3}) + 2 + 6 + 7 - - - scripts/test - - **/*bdy - **/*spc - - - - .*(\\|\/)(\w+)(\\|\/)(\w+)(\\|\/)(\w+).(\w{3}) - 2 - 6 - 7 + + + scripts/test + + **/*bdy + **/*spc + + + + .*(\\|\/)(\w+)(\\|\/)(\w+)(\\|\/)(\w+).(\w{3}) + 2 + 6 + 7 - - - - - - - \ No newline at end of file + + + + + + + diff --git a/utplsql-maven-plugin-it/src/it/resources/simple-project/pom.xml b/utplsql-maven-plugin-it/src/it/resources/simple-project/pom.xml index 2e51a04..ee05b0b 100644 --- a/utplsql-maven-plugin-it/src/it/resources/simple-project/pom.xml +++ b/utplsql-maven-plugin-it/src/it/resources/simple-project/pom.xml @@ -1,76 +1,77 @@ - - 4.0.0 + + 4.0.0 - org.utplsql - utplsql-maven-plugin-simple-test - 1.0.0 - pom + org.utplsql + utplsql-maven-plugin-simple-test + 1.0.0 + pom - utplsql-maven-plugin IT Simple - + utplsql-maven-plugin IT Simple + - + - - - - ${project.groupId} - utplsql-maven-plugin - ${utplsql-maven-plugin-version} - - - - test - - + + + + ${project.groupId} + utplsql-maven-plugin + ${utplsql-maven-plugin-version} + + + + test + + - false + false - - app - + + app + - - - UT_COVERAGE_SONAR_REPORTER - utplsql/coverage-sonar-reporter.xml - true - - - UT_SONAR_TEST_REPORTER - utplsql/sonar-test-reporter.xml - true - - + + + UT_COVERAGE_SONAR_REPORTER + utplsql/coverage-sonar-reporter.xml + true + + + UT_SONAR_TEST_REPORTER + utplsql/sonar-test-reporter.xml + true + + - - - scripts/sources - - **/*bdy - **/*spc - - - + + + scripts/sources + + **/*bdy + **/*spc + + + - - - scripts/tests - - **/*bdy - **/*spc - - - + + + scripts/tests + + **/*bdy + **/*spc + + + - + - - + + - - - - \ No newline at end of file + + + + diff --git a/utplsql-maven-plugin-it/src/it/resources/type-mapping-project/pom.xml b/utplsql-maven-plugin-it/src/it/resources/type-mapping-project/pom.xml index 92f4819..a4d3dde 100644 --- a/utplsql-maven-plugin-it/src/it/resources/type-mapping-project/pom.xml +++ b/utplsql-maven-plugin-it/src/it/resources/type-mapping-project/pom.xml @@ -1,92 +1,93 @@ - - 4.0.0 + + 4.0.0 - org.utplsql - utplsql-maven-plugin-type-mapping-test - 1.0.0 - - pom + org.utplsql + utplsql-maven-plugin-type-mapping-test + 1.0.0 - utplsql-maven-plugin IT Type Mapping - + pom + + utplsql-maven-plugin IT Type Mapping + - + - - - - ${project.groupId} - utplsql-maven-plugin - ${utplsql-maven-plugin-version} - - - - test - - + + + + ${project.groupId} + utplsql-maven-plugin + ${utplsql-maven-plugin-version} + + + + test + + - false + false - - app - + + app + - - - UT_COVERAGE_SONAR_REPORTER - utplsql/coverage-sonar-reporter.xml - true - - - UT_SONAR_TEST_REPORTER - utplsql/sonar-test-reporter.xml - true - - + + + UT_COVERAGE_SONAR_REPORTER + utplsql/coverage-sonar-reporter.xml + true + + + UT_SONAR_TEST_REPORTER + utplsql/sonar-test-reporter.xml + true + + - - - scripts/sources - - **/*sql - - - - .*/(\w+)/(\w+)/(\w+)\.\w{3} - 1 - 3 - 2 - - - package body - package_bodies - - + + + scripts/sources + + **/*sql + + + + .*/(\w+)/(\w+)/(\w+)\.\w{3} + 1 + 3 + 2 + + + package body + package_bodies + + - - - scripts/test - - **/*sql - - - - .*/(\w+)/(\w+)/(\w+)\.\w{3} - 1 - 3 - 2 - - - package body - package_bodies - - - - - - - - - \ No newline at end of file + + + scripts/test + + **/*sql + + + + .*/(\w+)/(\w+)/(\w+)\.\w{3} + 1 + 3 + 2 + + + package body + package_bodies + + + + + + + + +