From 6dd94d17c1f2fbabe59323cae5190348eaab962c Mon Sep 17 00:00:00 2001 From: "kamil.berdychowski" Date: Mon, 20 Nov 2017 21:02:45 +0100 Subject: [PATCH 01/71] Start of utPlSql maven plugin --- .gitignore | 20 ++ mvnw | 227 ++++++++++++++++++ mvnw.cmd | 143 +++++++++++ pom.xml | 24 ++ utplsql-maven-plugin/pom.xml | 110 +++++++++ .../main/java/org/utplsql/UtPLSQLMojo.java | 104 ++++++++ .../java/org/utplsql/tools/FileWalker.java | 48 ++++ .../src/test/java/UtPLSQLMojoTest.java | 58 +++++ .../src/test/resources/pom.xml | 39 +++ 9 files changed, 773 insertions(+) create mode 100644 .gitignore create mode 100755 mvnw create mode 100755 mvnw.cmd create mode 100644 pom.xml create mode 100644 utplsql-maven-plugin/pom.xml create mode 100644 utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java create mode 100644 utplsql-maven-plugin/src/main/java/org/utplsql/tools/FileWalker.java create mode 100644 utplsql-maven-plugin/src/test/java/UtPLSQLMojoTest.java create mode 100644 utplsql-maven-plugin/src/test/resources/pom.xml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bb57f02 --- /dev/null +++ b/.gitignore @@ -0,0 +1,20 @@ +# Eclipse +.classpath +.project +.settings/ + +# Intellij +.idea/ +*.iml +*.iws + +# Mac +.DS_Store + +# Bash +*.swp + +# Maven +log/ +target/ +.mvn diff --git a/mvnw b/mvnw new file mode 100755 index 0000000..e96ccd5 --- /dev/null +++ b/mvnw @@ -0,0 +1,227 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven2 Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Mingw, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" + # TODO classpath? +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`which java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=`find_maven_basedir "$(pwd)"` +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +if [ "$MVNW_VERBOSE" = true ]; then + echo $MAVEN_PROJECTBASEDIR +fi +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/mvnw.cmd b/mvnw.cmd new file mode 100755 index 0000000..019bd74 --- /dev/null +++ b/mvnw.cmd @@ -0,0 +1,143 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Maven2 Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" +if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" + +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" +if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%" == "on" pause + +if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% + +exit /B %ERROR_CODE% diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..e16cf20 --- /dev/null +++ b/pom.xml @@ -0,0 +1,24 @@ + + 4.0.0 + + org.utplsql + utplsql-maven-plugin-build + 1.0-SNAPSHOT + pom + + utplsql-maven-plugin Maven Plugin Build + + + http://maven.apache.org + + + UTF-8 + 3.5.0 + + + + utplsql-maven-plugin + + + diff --git a/utplsql-maven-plugin/pom.xml b/utplsql-maven-plugin/pom.xml new file mode 100644 index 0000000..4354875 --- /dev/null +++ b/utplsql-maven-plugin/pom.xml @@ -0,0 +1,110 @@ + + 4.0.0 + + + org.utplsql + utplsql-maven-plugin-build + 1.0-SNAPSHOT + + + utplsql-maven-plugin + maven-plugin + + utplsql-maven-plugin Maven Plugin + + + http://maven.apache.org + + + + + + + org.utplsql + java-api + 1.0-SNAPSHOT + compile + + + + org.apache.maven + maven-plugin-api + ${maven.version} + + + + org.apache.maven + maven-core + ${maven.version} + + + + org.apache.maven.plugin-tools + maven-plugin-annotations + 3.5 + provided + + + + + + org.apache.maven.plugin-testing + maven-plugin-testing-harness + 3.3.0 + test + + + + org.apache.maven + maven-compat + ${maven.version} + test + + + + junit + junit + 4.12 + test + + + + org.assertj + assertj-core + 3.8.0 + test + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.7.0 + + 1.8 + 1.8 + + + + org.apache.maven.plugins + maven-plugin-plugin + 3.5 + + + default-descriptor + process-classes + + + help-goal + + helpmojo + + + + + + + diff --git a/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java b/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java new file mode 100644 index 0000000..f49ac79 --- /dev/null +++ b/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java @@ -0,0 +1,104 @@ +package org.utplsql; + +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.utplsql.api.FileMapperOptions; +import org.utplsql.api.OutputBuffer; +import org.utplsql.api.TestRunner; +import org.utplsql.api.exception.SomeTestsFailedException; +import org.utplsql.api.reporter.Reporter; +import org.utplsql.api.reporter.ReporterFactory; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import static org.utplsql.api.CustomTypes.UT_DOCUMENTATION_REPORTER; + +@Mojo(name = "test") +public class UtPLSQLMojo extends AbstractMojo { + + + /** + * List of paths with test suites. + */ + @Parameter(name = "suitePaths", required = true, property = "utplsql.suite_paths") + private List suitePaths; + + /** + * List of paths with source files. + */ + @Parameter(name = "sourcePaths", required = true, property = "utplsql.source_paths") + private List sourcePaths; + + /** + * List of paths with test files. + */ + @Parameter(name = "testPaths", required = true, property = "utplsql.test_paths") + private List testPaths; + + public void execute() throws MojoExecutionException, MojoFailureException { + + List reporterList = new ArrayList<>(); + reporterList.add(ReporterFactory.createReporter(UT_DOCUMENTATION_REPORTER)); + List testPaths = listOfStrings("tests"); + FileMapperOptions sourceMappingOptions = new FileMapperOptions(listOfStrings( + "source/award_bonus/award_bonus.prc" +// "/Users/kamil.berdychowski/workspaces/utPLSQL/utPLSQL-demo-project/source/between_string/betwnstr.fnc" + )); + FileMapperOptions testMappingOptions = new FileMapperOptions(listOfStrings( + "/Users/kamil.berdychowski/workspaces/utPLSQL/utPLSQL-demo-project/test/award_bonus/test_award_bonus.pkb", + "/Users/kamil.berdychowski/workspaces/utPLSQL/utPLSQL-demo-project/test/award_bonus/test_award_bonus.pks" +// "/Users/kamil.berdychowski/workspaces/utPLSQL/utPLSQL-demo-project/test/between_string/test_betwnstr.pkb", +// "/Users/kamil.berdychowski/workspaces/utPLSQL/utPLSQL-demo-project/test/between_string/test_betwnstr.pks" + )); + + Connection connection = null; + + try { + connection = DriverManager.getConnection("jdbc:oracle:thin:@//localhost:1521/XE", "tests", "tests"); + + for (Reporter reporter : reporterList) { + reporter.init(connection); + } + + new TestRunner() + .addPathList(testPaths) + .addReporterList(reporterList) + .sourceMappingOptions(sourceMappingOptions) + .testMappingOptions(testMappingOptions) + .colorConsole(true) + .failOnErrors(true) + .run(connection); + } catch (SomeTestsFailedException e) { + getLog().error(e); + throw new MojoExecutionException("Tests failed", e); + } catch (SQLException e) { + getLog().error(e); + throw new MojoFailureException("SQL error occured", e); + } finally { + //TODO: add more security checking, what happens when connection is broken + try { + new OutputBuffer(reporterList.get(0)).printAvailable(connection, System.out); + if (connection != null) { + connection.close(); + } + } catch (SQLException e) { + getLog().error("Error", e); + } + } + + } + + private List listOfStrings(String... values) { + List result = new ArrayList<>(); + Collections.addAll(result, values); + return result; + } +} \ No newline at end of file diff --git a/utplsql-maven-plugin/src/main/java/org/utplsql/tools/FileWalker.java b/utplsql-maven-plugin/src/main/java/org/utplsql/tools/FileWalker.java new file mode 100644 index 0000000..bc57c45 --- /dev/null +++ b/utplsql-maven-plugin/src/main/java/org/utplsql/tools/FileWalker.java @@ -0,0 +1,48 @@ +package org.utplsql.tools; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +/** + * Created by Vinicius on 18/06/2017. - taken from API + */ +public class FileWalker { + + public static List getFileList(File baseDir, String inspectPath) { + return getFileList(baseDir, inspectPath, true); + } + + public static List getFileList(File baseDir, String inspectPath, boolean relative) { + File inspectDir = new File(baseDir, inspectPath); + + if (!inspectDir.isDirectory()) + throw new IllegalArgumentException(inspectPath + " is not a directory."); + + List fileList = new ArrayList<>(); + listDirFiles(baseDir, inspectDir, fileList, relative); + + return fileList; + } + + private static void listDirFiles(File baseDir, File directory, List fileList, boolean relative) { + File[] directoryFiles = directory.listFiles(); + + if (directoryFiles == null) + return; + + for (File file : directoryFiles) { + if (file.isFile()) { + String absolutePath = file.getAbsolutePath(); + + if (relative) + absolutePath = absolutePath.substring(baseDir.getAbsolutePath().length() + 1); + + fileList.add(absolutePath); + } else { + listDirFiles(baseDir, file, fileList, relative); + } + } + } + +} diff --git a/utplsql-maven-plugin/src/test/java/UtPLSQLMojoTest.java b/utplsql-maven-plugin/src/test/java/UtPLSQLMojoTest.java new file mode 100644 index 0000000..e79de39 --- /dev/null +++ b/utplsql-maven-plugin/src/test/java/UtPLSQLMojoTest.java @@ -0,0 +1,58 @@ +import org.apache.maven.plugin.Mojo; +import org.apache.maven.plugin.testing.AbstractMojoTestCase; +import org.assertj.core.api.Assertions; + +import java.io.File; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +public class UtPLSQLMojoTest extends AbstractMojoTestCase { + + public static final String POM_PATH = "src/test/resources/pom.xml"; + + @Override + public void setUp() throws Exception { + super.setUp(); + } + + @Override + public void tearDown() throws Exception { + super.tearDown(); + } + + public void test_mojo_definition() throws Exception { + File pom = getTestFile(POM_PATH); + assertThat(pom.exists()).isTrue(); + + Mojo testMojo = lookupMojo("test", pom); + assertThat(testMojo).isNotNull(); + } + + public void test_mapping_suite_paths() throws Exception { + File pom = getTestFile("src/test/resources/pom.xml"); + Mojo testMojo = lookupMojo("test", pom); + + List paths = (List) getVariableValueFromObject(testMojo, "suitePaths"); + + assertThat(paths).containsExactly("suite_path1", "suite_path2"); + } + + public void test_mapping_source_paths() throws Exception { + File pom = getTestFile("src/test/resources/pom.xml"); + Mojo testMojo = lookupMojo("test", pom); + + List paths = (List) getVariableValueFromObject(testMojo, "sourcePaths"); + + assertThat(paths).containsExactly("source_path1", "source_path2", "source_path3"); + } + + public void test_mapping_test_paths() throws Exception { + File pom = getTestFile("src/test/resources/pom.xml"); + Mojo testMojo = lookupMojo("test", pom); + + List paths = (List) getVariableValueFromObject(testMojo, "testPaths"); + + assertThat(paths).containsExactly("test_path1", "test_path2"); + } +} diff --git a/utplsql-maven-plugin/src/test/resources/pom.xml b/utplsql-maven-plugin/src/test/resources/pom.xml new file mode 100644 index 0000000..41a1498 --- /dev/null +++ b/utplsql-maven-plugin/src/test/resources/pom.xml @@ -0,0 +1,39 @@ + + 4.0.0 + + org.utplsql + utplsql-maven-plugin-test + 1.0-SNAPSHOT + maven-plugin + + utplsql-maven-plugin Maven Plugin Test + + + + + ${pom.groupId} + utplsql-maven-plugin + ${pom.version} + + test + + + + suite_path1 + suite_path2 + + + source_path1 + source_path2 + source_path3 + + + test_path1 + test_path2 + + + + + + \ No newline at end of file From 5938316a66772a9c77e8d54564f6c5298bca2182 Mon Sep 17 00:00:00 2001 From: Alberto Hernandez Date: Fri, 26 Jan 2018 12:38:28 +0100 Subject: [PATCH 02/71] Rebuild the Mojo Plugin in order to add parameters the the Java UtPLSQL plugin --- utplsql-maven-plugin/pom.xml | 232 ++++++++++-------- .../main/java/org/utplsql/UtPLSQLMojo.java | 226 ++++++++++------- .../org/utplsql/helper/PluginDefault.java | 60 +++++ .../org/utplsql/helper/SQLScannerHelper.java | 59 +++++ .../java/org/utplsql/tools/FileWalker.java | 48 ---- .../src/test/java/UtPLSQLMojoTest.java | 58 ----- .../java/org/utpsql/test/UtPLSQLMojoTest.java | 35 +++ .../src/test/resources/pom.xml | 55 +++-- 8 files changed, 452 insertions(+), 321 deletions(-) create mode 100644 utplsql-maven-plugin/src/main/java/org/utplsql/helper/PluginDefault.java create mode 100644 utplsql-maven-plugin/src/main/java/org/utplsql/helper/SQLScannerHelper.java delete mode 100644 utplsql-maven-plugin/src/main/java/org/utplsql/tools/FileWalker.java delete mode 100644 utplsql-maven-plugin/src/test/java/UtPLSQLMojoTest.java create mode 100644 utplsql-maven-plugin/src/test/java/org/utpsql/test/UtPLSQLMojoTest.java diff --git a/utplsql-maven-plugin/pom.xml b/utplsql-maven-plugin/pom.xml index 4354875..c11545f 100644 --- a/utplsql-maven-plugin/pom.xml +++ b/utplsql-maven-plugin/pom.xml @@ -1,110 +1,126 @@ - 4.0.0 - - - org.utplsql - utplsql-maven-plugin-build - 1.0-SNAPSHOT - - - utplsql-maven-plugin - maven-plugin - - utplsql-maven-plugin Maven Plugin - - - http://maven.apache.org - - - - - - - org.utplsql - java-api - 1.0-SNAPSHOT - compile - - - - org.apache.maven - maven-plugin-api - ${maven.version} - - - - org.apache.maven - maven-core - ${maven.version} - - - - org.apache.maven.plugin-tools - maven-plugin-annotations - 3.5 - provided - - - - - - org.apache.maven.plugin-testing - maven-plugin-testing-harness - 3.3.0 - test - - - - org.apache.maven - maven-compat - ${maven.version} - test - - - - junit - junit - 4.12 - test - - - - org.assertj - assertj-core - 3.8.0 - test - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - - org.apache.maven.plugins - maven-plugin-plugin - 3.5 - - - default-descriptor - process-classes - - - help-goal - - helpmojo - - - - - - + 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 + maven-plugin + + 1.0.0-SNAPSHOT + + utplsql-maven-plugin Maven Plugin + + + http://maven.apache.org + + + UTF-8 + 1.8 + + + + + + org.utplsql + java-api + 3.0.4 + + + + 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.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 + + + + + + + + diff --git a/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java b/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java index f49ac79..bd578e4 100644 --- a/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java +++ b/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java @@ -1,104 +1,144 @@ package org.utplsql; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.apache.maven.model.Resource; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.utplsql.api.FileMapperOptions; -import org.utplsql.api.OutputBuffer; import org.utplsql.api.TestRunner; -import org.utplsql.api.exception.SomeTestsFailedException; import org.utplsql.api.reporter.Reporter; import org.utplsql.api.reporter.ReporterFactory; - -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import static org.utplsql.api.CustomTypes.UT_DOCUMENTATION_REPORTER; - -@Mojo(name = "test") -public class UtPLSQLMojo extends AbstractMojo { - - - /** - * List of paths with test suites. - */ - @Parameter(name = "suitePaths", required = true, property = "utplsql.suite_paths") - private List suitePaths; - - /** - * List of paths with source files. - */ - @Parameter(name = "sourcePaths", required = true, property = "utplsql.source_paths") - private List sourcePaths; - - /** - * List of paths with test files. - */ - @Parameter(name = "testPaths", required = true, property = "utplsql.test_paths") - private List testPaths; - - public void execute() throws MojoExecutionException, MojoFailureException { - - List reporterList = new ArrayList<>(); - reporterList.add(ReporterFactory.createReporter(UT_DOCUMENTATION_REPORTER)); - List testPaths = listOfStrings("tests"); - FileMapperOptions sourceMappingOptions = new FileMapperOptions(listOfStrings( - "source/award_bonus/award_bonus.prc" -// "/Users/kamil.berdychowski/workspaces/utPLSQL/utPLSQL-demo-project/source/between_string/betwnstr.fnc" - )); - FileMapperOptions testMappingOptions = new FileMapperOptions(listOfStrings( - "/Users/kamil.berdychowski/workspaces/utPLSQL/utPLSQL-demo-project/test/award_bonus/test_award_bonus.pkb", - "/Users/kamil.berdychowski/workspaces/utPLSQL/utPLSQL-demo-project/test/award_bonus/test_award_bonus.pks" -// "/Users/kamil.berdychowski/workspaces/utPLSQL/utPLSQL-demo-project/test/between_string/test_betwnstr.pkb", -// "/Users/kamil.berdychowski/workspaces/utPLSQL/utPLSQL-demo-project/test/between_string/test_betwnstr.pks" - )); - - Connection connection = null; - - try { - connection = DriverManager.getConnection("jdbc:oracle:thin:@//localhost:1521/XE", "tests", "tests"); - - for (Reporter reporter : reporterList) { - reporter.init(connection); - } - - new TestRunner() - .addPathList(testPaths) - .addReporterList(reporterList) - .sourceMappingOptions(sourceMappingOptions) - .testMappingOptions(testMappingOptions) - .colorConsole(true) - .failOnErrors(true) - .run(connection); - } catch (SomeTestsFailedException e) { - getLog().error(e); - throw new MojoExecutionException("Tests failed", e); - } catch (SQLException e) { - getLog().error(e); - throw new MojoFailureException("SQL error occured", e); - } finally { - //TODO: add more security checking, what happens when connection is broken - try { - new OutputBuffer(reporterList.get(0)).printAvailable(connection, System.out); - if (connection != null) { - connection.close(); - } - } catch (SQLException e) { - getLog().error("Error", e); - } - } - - } - - private List listOfStrings(String... values) { - List result = new ArrayList<>(); - Collections.addAll(result, values); - return result; - } +import org.utplsql.helper.PluginDefault; +import org.utplsql.helper.SQLScannerHelper; + +@Mojo(name = "test", defaultPhase = LifecyclePhase.TEST) +public class UtPLSQLMojo extends AbstractMojo +{ + + @Parameter(required = true) + private String url; + + @Parameter(required = true) + private String user; + + @Parameter(required = true) + private String password; + + @Parameter + private boolean failOnErrors; + + @Parameter + private boolean colorConsole; + + @Parameter + private List reporters; + + // Configuration of Sources, Testing + + @Parameter + private List sources = new ArrayList(); + + @Parameter + private List tests = new ArrayList(); + + /** + * + * Execute the plugin + * + */ + @Override + public void execute() throws MojoExecutionException + { + List testPaths = Arrays.asList(new String[] { "tests" }); + + FileMapperOptions sourceMappingOptions = buildOptions(sources, PluginDefault.buildDefaultSource()); + FileMapperOptions testMappingOptions = buildOptions(tests, PluginDefault.buildDefaultTest()); + + Connection connection = null; + List reporterList = null; + + try + { + connection = DriverManager.getConnection(url, user, password); + + // Init Reporters + reporterList = initReporters(connection); + + TestRunner runner = new TestRunner() + .addPathList(testPaths) + .addReporterList(reporterList) + .sourceMappingOptions(sourceMappingOptions) + .testMappingOptions(testMappingOptions) + .colorConsole(colorConsole) + .failOnErrors(failOnErrors); + + runner.run(connection); + + } + catch (Exception e) + { + getLog().error(e); + throw new MojoExecutionException("Unexpected error executing plugin " + e.getMessage()); + } + finally + { + try + { + if (connection != null) + connection.close(); + } + catch (SQLException e) + { + getLog().error("Error", e); + } + } + } + + /** + * + * @param resources + * @return + */ + private FileMapperOptions buildOptions(List resources, Resource defaultResource) + { + // Check if this element is empty + if (resources.isEmpty()) + { + resources.add(defaultResource); + } + + List scripts = SQLScannerHelper.findSQLs(resources); + return new FileMapperOptions(scripts); + } + + /** + * Init all the reports + * + * @param connection + * @return + * @throws SQLException + */ + private List initReporters(Connection connection) throws SQLException + { + List reporterList = new ArrayList(); + + for (String reporterId : reporters) + { + Reporter reporter = ReporterFactory.createReporter(reporterId); + reporter.init(connection); + + reporterList.add(reporter); + } + + return reporterList; + } } \ No newline at end of file diff --git a/utplsql-maven-plugin/src/main/java/org/utplsql/helper/PluginDefault.java b/utplsql-maven-plugin/src/main/java/org/utplsql/helper/PluginDefault.java new file mode 100644 index 0000000..7dc1d60 --- /dev/null +++ b/utplsql-maven-plugin/src/main/java/org/utplsql/helper/PluginDefault.java @@ -0,0 +1,60 @@ +package org.utplsql.helper; + +import java.util.Arrays; + +import org.apache.maven.model.Resource; + +/** + * + * @author Alberto Hernández + * + */ +public class PluginDefault +{ + + // Source Directory + private static final String SOURCE_DIRECTORY = "src/main/plsql"; + + // Test Directory + private static final String TEST_DIRECTORY = "src/test/plsql"; + + // Default Extension for Package HEAD + private static final String PACKAGE_HEAD = "**/*.pkg"; + + // Default Extension for Package HEAD + private static final String PACKAGE_BODY = "**/*.pkb"; + + /** + * + * @return + */ + private static Resource buildDirectory(String directory) + { + Resource resource = new Resource(); + + // Configure Resources + resource.setDirectory(directory); + resource.setIncludes(Arrays.asList(PACKAGE_BODY, PACKAGE_HEAD)); + + return resource; + } + + /** + * + * @return + */ + public static Resource buildDefaultSource() + { + return buildDirectory(SOURCE_DIRECTORY); + } + + /** + * + * @return + */ + public static Resource buildDefaultTest() + { + return buildDirectory(TEST_DIRECTORY); + } + +} diff --git a/utplsql-maven-plugin/src/main/java/org/utplsql/helper/SQLScannerHelper.java b/utplsql-maven-plugin/src/main/java/org/utplsql/helper/SQLScannerHelper.java new file mode 100644 index 0000000..2a1794c --- /dev/null +++ b/utplsql-maven-plugin/src/main/java/org/utplsql/helper/SQLScannerHelper.java @@ -0,0 +1,59 @@ +package org.utplsql.helper; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.apache.maven.model.Resource; +import org.codehaus.plexus.util.DirectoryScanner; + +/** + * Utility to Scan all resources + * + * @author Alberto Hernández + * + */ +public class SQLScannerHelper +{ + + /** + * + * @param resouces + * @return + */ + public static List findSQLs(List resources) + { + List founds = new ArrayList(); + + for (Resource resource: resources) + { + // Build Scanner + DirectoryScanner scanner = buildScanner(resource); + scanner.scan(); + + // Append all scanned objects + founds.addAll(Arrays.asList(scanner.getIncludedFiles())); + } + + + return founds; + } + + /** + * Build a scanner in forder to Find all Resource files + * @param resource + * @return + */ + private static DirectoryScanner buildScanner(Resource resource) + { + DirectoryScanner scanner = new DirectoryScanner(); + + scanner.setBasedir(resource.getDirectory()); + scanner.setIncludes(resource.getIncludes().toArray(new String[0])); + scanner.setExcludes(resource.getExcludes().toArray(new String[0])); + + + return scanner; + } + +} diff --git a/utplsql-maven-plugin/src/main/java/org/utplsql/tools/FileWalker.java b/utplsql-maven-plugin/src/main/java/org/utplsql/tools/FileWalker.java deleted file mode 100644 index bc57c45..0000000 --- a/utplsql-maven-plugin/src/main/java/org/utplsql/tools/FileWalker.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.utplsql.tools; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; - -/** - * Created by Vinicius on 18/06/2017. - taken from API - */ -public class FileWalker { - - public static List getFileList(File baseDir, String inspectPath) { - return getFileList(baseDir, inspectPath, true); - } - - public static List getFileList(File baseDir, String inspectPath, boolean relative) { - File inspectDir = new File(baseDir, inspectPath); - - if (!inspectDir.isDirectory()) - throw new IllegalArgumentException(inspectPath + " is not a directory."); - - List fileList = new ArrayList<>(); - listDirFiles(baseDir, inspectDir, fileList, relative); - - return fileList; - } - - private static void listDirFiles(File baseDir, File directory, List fileList, boolean relative) { - File[] directoryFiles = directory.listFiles(); - - if (directoryFiles == null) - return; - - for (File file : directoryFiles) { - if (file.isFile()) { - String absolutePath = file.getAbsolutePath(); - - if (relative) - absolutePath = absolutePath.substring(baseDir.getAbsolutePath().length() + 1); - - fileList.add(absolutePath); - } else { - listDirFiles(baseDir, file, fileList, relative); - } - } - } - -} diff --git a/utplsql-maven-plugin/src/test/java/UtPLSQLMojoTest.java b/utplsql-maven-plugin/src/test/java/UtPLSQLMojoTest.java deleted file mode 100644 index e79de39..0000000 --- a/utplsql-maven-plugin/src/test/java/UtPLSQLMojoTest.java +++ /dev/null @@ -1,58 +0,0 @@ -import org.apache.maven.plugin.Mojo; -import org.apache.maven.plugin.testing.AbstractMojoTestCase; -import org.assertj.core.api.Assertions; - -import java.io.File; -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; - -public class UtPLSQLMojoTest extends AbstractMojoTestCase { - - public static final String POM_PATH = "src/test/resources/pom.xml"; - - @Override - public void setUp() throws Exception { - super.setUp(); - } - - @Override - public void tearDown() throws Exception { - super.tearDown(); - } - - public void test_mojo_definition() throws Exception { - File pom = getTestFile(POM_PATH); - assertThat(pom.exists()).isTrue(); - - Mojo testMojo = lookupMojo("test", pom); - assertThat(testMojo).isNotNull(); - } - - public void test_mapping_suite_paths() throws Exception { - File pom = getTestFile("src/test/resources/pom.xml"); - Mojo testMojo = lookupMojo("test", pom); - - List paths = (List) getVariableValueFromObject(testMojo, "suitePaths"); - - assertThat(paths).containsExactly("suite_path1", "suite_path2"); - } - - public void test_mapping_source_paths() throws Exception { - File pom = getTestFile("src/test/resources/pom.xml"); - Mojo testMojo = lookupMojo("test", pom); - - List paths = (List) getVariableValueFromObject(testMojo, "sourcePaths"); - - assertThat(paths).containsExactly("source_path1", "source_path2", "source_path3"); - } - - public void test_mapping_test_paths() throws Exception { - File pom = getTestFile("src/test/resources/pom.xml"); - Mojo testMojo = lookupMojo("test", pom); - - List paths = (List) getVariableValueFromObject(testMojo, "testPaths"); - - assertThat(paths).containsExactly("test_path1", "test_path2"); - } -} diff --git a/utplsql-maven-plugin/src/test/java/org/utpsql/test/UtPLSQLMojoTest.java b/utplsql-maven-plugin/src/test/java/org/utpsql/test/UtPLSQLMojoTest.java new file mode 100644 index 0000000..eac56cc --- /dev/null +++ b/utplsql-maven-plugin/src/test/java/org/utpsql/test/UtPLSQLMojoTest.java @@ -0,0 +1,35 @@ +package org.utpsql.test; + +import org.apache.maven.plugin.testing.MojoRule; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.utplsql.UtPLSQLMojo; + +public class UtPLSQLMojoTest +{ + public static final String POM_PATH = "src/test/resources/pom.xml"; + + @Rule + public MojoRule rule = new MojoRule() + { + @Override + protected void before() throws Throwable + { + } + + @Override + protected void after() + { + } + }; + + @Test + public void testDefinition() throws Exception + { + UtPLSQLMojo myMojo = (UtPLSQLMojo) rule.lookupMojo("test", POM_PATH); + Assert.assertNotNull(myMojo); + myMojo.execute(); + } + +} diff --git a/utplsql-maven-plugin/src/test/resources/pom.xml b/utplsql-maven-plugin/src/test/resources/pom.xml index 41a1498..5f91cad 100644 --- a/utplsql-maven-plugin/src/test/resources/pom.xml +++ b/utplsql-maven-plugin/src/test/resources/pom.xml @@ -4,7 +4,7 @@ org.utplsql utplsql-maven-plugin-test - 1.0-SNAPSHOT + 1.0.0-SNAPSHOT maven-plugin utplsql-maven-plugin Maven Plugin Test @@ -19,19 +19,46 @@ test - - suite_path1 - suite_path2 - - - source_path1 - source_path2 - source_path3 - - - test_path1 - test_path2 - + + + url_of_connection + user + password + + + false + true + + + UT_COVERAGE_SONAR_REPORTER + UT_SONAR_TEST_REPORTER + + + + + SampleDirectory + + **/*pkg + **/*pkb + + + + SampleDirectory2 + + **/*pkb + + + + + + + src/main/test/test1 + + **/*pkg + + + + From e612ad285639223116f3860e27c1712e7c53fdae Mon Sep 17 00:00:00 2001 From: rostskadat Date: Fri, 26 Jan 2018 17:17:26 +0100 Subject: [PATCH 03/71] Adding report handling --- .../main/java/org/utplsql/UtPLSQLMojo.java | 69 +++++++++++++++---- .../org/utplsql/helper/SQLScannerHelper.java | 11 +-- 2 files changed, 63 insertions(+), 17 deletions(-) diff --git a/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java b/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java index bd578e4..3fc3850 100644 --- a/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java +++ b/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java @@ -4,8 +4,8 @@ import java.sql.DriverManager; import java.sql.SQLException; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; +import java.util.function.Consumer; import org.apache.maven.model.Resource; import org.apache.maven.plugin.AbstractMojo; @@ -14,6 +14,7 @@ import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.utplsql.api.FileMapperOptions; +import org.utplsql.api.OutputBuffer; import org.utplsql.api.TestRunner; import org.utplsql.api.reporter.Reporter; import org.utplsql.api.reporter.ReporterFactory; @@ -45,10 +46,13 @@ public class UtPLSQLMojo extends AbstractMojo // Configuration of Sources, Testing @Parameter - private List sources = new ArrayList(); + private List sources = new ArrayList<>(); @Parameter - private List tests = new ArrayList(); + private List tests = new ArrayList<>(); + + @Parameter + private List reports = new ArrayList<>(); /** * @@ -58,10 +62,11 @@ public class UtPLSQLMojo extends AbstractMojo @Override public void execute() throws MojoExecutionException { - List testPaths = Arrays.asList(new String[] { "tests" }); + // List testPaths = Arrays.asList(new String[] { "tests" }); - FileMapperOptions sourceMappingOptions = buildOptions(sources, PluginDefault.buildDefaultSource()); - FileMapperOptions testMappingOptions = buildOptions(tests, PluginDefault.buildDefaultTest()); + FileMapperOptions sourceMappingOptions = buildOptions(sources, + PluginDefault.buildDefaultSource()); + FileMapperOptions testMappingOptions = buildOptions(tests, PluginDefault.buildDefaultTest()); Connection connection = null; List reporterList = null; @@ -72,10 +77,44 @@ public void execute() throws MojoExecutionException // Init Reporters reporterList = initReporters(connection); + if (getLog().isDebugEnabled()) { + StringBuilder msg = new StringBuilder(); + msg.append("Invoking TestRunner with: ").append('\n'); + msg.append("reporters="); + reporterList.forEach(new Consumer() { + @Override + public void accept(Reporter t) { + try { + msg.append(t.getSQLTypeName()).append(", "); + } catch (Exception e) { + // NA + } + } + + }); + msg.append('\n'); + msg.append("sources="); + sourceMappingOptions.getFilePaths().forEach(new Consumer() { + @Override + public void accept(String t) { + msg.append(t).append(", "); + } + }); + msg.append('\n'); + msg.append("tests="); + testMappingOptions.getFilePaths().forEach(new Consumer() { + @Override + public void accept(String t) { + msg.append(t).append(", "); + } + }); + msg.append('\n'); + getLog().debug(msg.toString()); + } TestRunner runner = new TestRunner() - .addPathList(testPaths) - .addReporterList(reporterList) + // .addPathList(testPaths) + .addReporterList(reporterList) .sourceMappingOptions(sourceMappingOptions) .testMappingOptions(testMappingOptions) .colorConsole(colorConsole) @@ -92,11 +131,15 @@ public void execute() throws MojoExecutionException finally { try - { - if (connection != null) + { + for (Reporter reporter : reporterList) { + new OutputBuffer(reporter).printAvailable(connection, reporter.outputFile()); + } + if (connection != null) { connection.close(); + } } - catch (SQLException e) + catch (Exception e) { getLog().error("Error", e); } @@ -108,7 +151,7 @@ public void execute() throws MojoExecutionException * @param resources * @return */ - private FileMapperOptions buildOptions(List resources, Resource defaultResource) + private FileMapperOptions buildOptions(List resources, Resource defaultResource) { // Check if this element is empty if (resources.isEmpty()) @@ -129,7 +172,7 @@ private FileMapperOptions buildOptions(List resources, Resource defaul */ private List initReporters(Connection connection) throws SQLException { - List reporterList = new ArrayList(); + List reporterList = new ArrayList<>(); for (String reporterId : reporters) { diff --git a/utplsql-maven-plugin/src/main/java/org/utplsql/helper/SQLScannerHelper.java b/utplsql-maven-plugin/src/main/java/org/utplsql/helper/SQLScannerHelper.java index 2a1794c..1863ac1 100644 --- a/utplsql-maven-plugin/src/main/java/org/utplsql/helper/SQLScannerHelper.java +++ b/utplsql-maven-plugin/src/main/java/org/utplsql/helper/SQLScannerHelper.java @@ -1,5 +1,6 @@ package org.utplsql.helper; +import java.io.File; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -23,19 +24,21 @@ public class SQLScannerHelper */ public static List findSQLs(List resources) { - List founds = new ArrayList(); + List founds = new ArrayList<>(); for (Resource resource: resources) { // Build Scanner DirectoryScanner scanner = buildScanner(resource); scanner.scan(); - + for (String basename : scanner.getIncludedFiles()) { + founds.add(new File(scanner.getBasedir(), basename).getAbsolutePath()); + } + // Append all scanned objects - founds.addAll(Arrays.asList(scanner.getIncludedFiles())); + founds.addAll(Arrays.asList()); } - return founds; } From 3cb6beeee909b581b46725850f8ecb12b6b5c200 Mon Sep 17 00:00:00 2001 From: rostskadat Date: Fri, 26 Jan 2018 18:33:36 +0100 Subject: [PATCH 04/71] Adding handling of --- .../main/java/org/utplsql/UtPLSQLMojo.java | 37 +++++++++---------- .../org/utplsql/helper/PluginDefault.java | 14 ++----- 2 files changed, 21 insertions(+), 30 deletions(-) diff --git a/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java b/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java index 3fc3850..4f8af2c 100644 --- a/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java +++ b/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java @@ -18,41 +18,38 @@ import org.utplsql.api.TestRunner; import org.utplsql.api.reporter.Reporter; import org.utplsql.api.reporter.ReporterFactory; -import org.utplsql.helper.PluginDefault; import org.utplsql.helper.SQLScannerHelper; @Mojo(name = "test", defaultPhase = LifecyclePhase.TEST) public class UtPLSQLMojo extends AbstractMojo { - - @Parameter(required = true) + @Parameter(defaultValue = "jdbc:oracle:thin:@localhost:1521:ut3") private String url; - @Parameter(required = true) + @Parameter(defaultValue = "ut3") private String user; - @Parameter(required = true) + @Parameter(defaultValue = "XNtxj8eEgA6X6b6f") private String password; - @Parameter + // This parameter should honor the -Dmaven.test.failure.ignore=false + @Parameter(defaultValue = "false") private boolean failOnErrors; - @Parameter + @Parameter(defaultValue = "false") private boolean colorConsole; - @Parameter + @Parameter(defaultValue = "UT_DOCUMENTATION_REPORTER") private List reporters; - // Configuration of Sources, Testing + @Parameter + private List paths; - @Parameter + @Parameter private List sources = new ArrayList<>(); - @Parameter - private List tests = new ArrayList<>(); - @Parameter - private List reports = new ArrayList<>(); + private List tests = new ArrayList<>(); /** * @@ -64,9 +61,9 @@ public void execute() throws MojoExecutionException { // List testPaths = Arrays.asList(new String[] { "tests" }); - FileMapperOptions sourceMappingOptions = buildOptions(sources, - PluginDefault.buildDefaultSource()); - FileMapperOptions testMappingOptions = buildOptions(tests, PluginDefault.buildDefaultTest()); + FileMapperOptions sourceMappingOptions = new FileMapperOptions(new ArrayList<>()); + FileMapperOptions testMappingOptions = new FileMapperOptions(new ArrayList<>()); // buildOptions(tests, + // PluginDefault.buildDefaultTest()); Connection connection = null; List reporterList = null; @@ -113,7 +110,7 @@ public void accept(String t) { } TestRunner runner = new TestRunner() - // .addPathList(testPaths) + .addPathList(paths) .addReporterList(reporterList) .sourceMappingOptions(sourceMappingOptions) .testMappingOptions(testMappingOptions) @@ -133,7 +130,7 @@ public void accept(String t) { try { for (Reporter reporter : reporterList) { - new OutputBuffer(reporter).printAvailable(connection, reporter.outputFile()); + new OutputBuffer(reporter).printAvailable(connection, System.out); } if (connection != null) { connection.close(); @@ -160,7 +157,7 @@ private FileMapperOptions buildOptions(List resources, Resource defaul } List scripts = SQLScannerHelper.findSQLs(resources); - return new FileMapperOptions(scripts); + return new FileMapperOptions(scripts); } /** diff --git a/utplsql-maven-plugin/src/main/java/org/utplsql/helper/PluginDefault.java b/utplsql-maven-plugin/src/main/java/org/utplsql/helper/PluginDefault.java index 7dc1d60..b4a9ce6 100644 --- a/utplsql-maven-plugin/src/main/java/org/utplsql/helper/PluginDefault.java +++ b/utplsql-maven-plugin/src/main/java/org/utplsql/helper/PluginDefault.java @@ -18,23 +18,17 @@ public class PluginDefault // Test Directory private static final String TEST_DIRECTORY = "src/test/plsql"; - // Default Extension for Package HEAD - private static final String PACKAGE_HEAD = "**/*.pkg"; - - // Default Extension for Package HEAD - private static final String PACKAGE_BODY = "**/*.pkb"; - /** * * @return */ - private static Resource buildDirectory(String directory) + private static Resource buildDirectory(String directory, String includes) { Resource resource = new Resource(); // Configure Resources resource.setDirectory(directory); - resource.setIncludes(Arrays.asList(PACKAGE_BODY, PACKAGE_HEAD)); + resource.setIncludes(Arrays.asList(includes)); return resource; } @@ -45,7 +39,7 @@ private static Resource buildDirectory(String directory) */ public static Resource buildDefaultSource() { - return buildDirectory(SOURCE_DIRECTORY); + return buildDirectory(SOURCE_DIRECTORY, "**/*.*"); } /** @@ -54,7 +48,7 @@ public static Resource buildDefaultSource() */ public static Resource buildDefaultTest() { - return buildDirectory(TEST_DIRECTORY); + return buildDirectory(TEST_DIRECTORY, "**/*.pkg"); } } From 21937556d76e9519e25203a75487d9780a86488f Mon Sep 17 00:00:00 2001 From: rostskadat Date: Mon, 29 Jan 2018 12:02:36 +0100 Subject: [PATCH 05/71] Exposing more parameters --- .../main/java/org/utplsql/UtPLSQLMojo.java | 309 ++++++++++-------- .../org/utplsql/helper/ReporterDefault.java | 22 ++ .../utplsql/model/ReporterConfiguration.java | 24 ++ .../org/utplsql/model/ReporterParameter.java | 28 ++ 4 files changed, 250 insertions(+), 133 deletions(-) create mode 100644 utplsql-maven-plugin/src/main/java/org/utplsql/helper/ReporterDefault.java create mode 100644 utplsql-maven-plugin/src/main/java/org/utplsql/model/ReporterConfiguration.java create mode 100644 utplsql-maven-plugin/src/main/java/org/utplsql/model/ReporterParameter.java diff --git a/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java b/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java index 4f8af2c..e022d32 100644 --- a/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java +++ b/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java @@ -1,12 +1,21 @@ package org.utplsql; +import static java.lang.String.format; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.PrintStream; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.function.Consumer; +import org.apache.commons.lang3.StringUtils; import org.apache.maven.model.Resource; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; @@ -16,169 +25,203 @@ import org.utplsql.api.FileMapperOptions; import org.utplsql.api.OutputBuffer; import org.utplsql.api.TestRunner; +import org.utplsql.api.exception.SomeTestsFailedException; import org.utplsql.api.reporter.Reporter; import org.utplsql.api.reporter.ReporterFactory; +import org.utplsql.helper.PluginDefault; import org.utplsql.helper.SQLScannerHelper; +import org.utplsql.model.ReporterConfiguration; +import org.utplsql.model.ReporterParameter; + @Mojo(name = "test", defaultPhase = LifecyclePhase.TEST) -public class UtPLSQLMojo extends AbstractMojo -{ +public class UtPLSQLMojo extends AbstractMojo { @Parameter(defaultValue = "jdbc:oracle:thin:@localhost:1521:ut3") - private String url; + private String url; @Parameter(defaultValue = "ut3") - private String user; + private String user; @Parameter(defaultValue = "XNtxj8eEgA6X6b6f") - private String password; + private String password; + + @Parameter + private String includeObject; + + @Parameter + private String excludeObject; + + @Parameter(defaultValue = "${maven.test.failure.ignore}") + private boolean ignoreFailure; - // This parameter should honor the -Dmaven.test.failure.ignore=false @Parameter(defaultValue = "false") - private boolean failOnErrors; + private boolean colorConsole; @Parameter(defaultValue = "false") - private boolean colorConsole; + private boolean skipCompatibilityCheck; - @Parameter(defaultValue = "UT_DOCUMENTATION_REPORTER") - private List reporters; + @Parameter + private List reporters; + private Map mapReporters = new HashMap<>(); @Parameter private List paths; @Parameter - private List sources = new ArrayList<>(); + private List sources = new ArrayList<>(); @Parameter - private List tests = new ArrayList<>(); - - /** - * - * Execute the plugin - * - */ - @Override - public void execute() throws MojoExecutionException - { - // List testPaths = Arrays.asList(new String[] { "tests" }); - - FileMapperOptions sourceMappingOptions = new FileMapperOptions(new ArrayList<>()); - FileMapperOptions testMappingOptions = new FileMapperOptions(new ArrayList<>()); // buildOptions(tests, - // PluginDefault.buildDefaultTest()); - - Connection connection = null; - List reporterList = null; - - try - { - connection = DriverManager.getConnection(url, user, password); - - // Init Reporters - reporterList = initReporters(connection); + private List tests = new ArrayList<>(); + + @Parameter(defaultValue = "${project.build.directory}", readonly = true) + private String targetDir; + + /** + * + * Execute the plugin + * + */ + @Override + public void execute() throws MojoExecutionException { + FileMapperOptions sourceMappingOptions = buildOptions(sources, PluginDefault.buildDefaultSource()); + FileMapperOptions testMappingOptions = buildOptions(tests, PluginDefault.buildDefaultTest()); + + Connection connection = null; + List reporterList = null; + try { + connection = DriverManager.getConnection(url, user, password); + reporterList = initReporters(connection); + if (getLog().isDebugEnabled()) { - StringBuilder msg = new StringBuilder(); - msg.append("Invoking TestRunner with: ").append('\n'); - msg.append("reporters="); - reporterList.forEach(new Consumer() { - @Override - public void accept(Reporter t) { - try { - msg.append(t.getSQLTypeName()).append(", "); - } catch (Exception e) { - // NA - } - } - - }); - msg.append('\n'); - msg.append("sources="); - sourceMappingOptions.getFilePaths().forEach(new Consumer() { - @Override - public void accept(String t) { - msg.append(t).append(", "); - } - }); - msg.append('\n'); - msg.append("tests="); - testMappingOptions.getFilePaths().forEach(new Consumer() { - @Override - public void accept(String t) { - msg.append(t).append(", "); - } - }); - msg.append('\n'); - getLog().debug(msg.toString()); + dumpParameters(sourceMappingOptions, testMappingOptions, reporterList); } - TestRunner runner = new TestRunner() + TestRunner runner = new TestRunner() .addPathList(paths) .addReporterList(reporterList) - .sourceMappingOptions(sourceMappingOptions) - .testMappingOptions(testMappingOptions) - .colorConsole(colorConsole) - .failOnErrors(failOnErrors); - - runner.run(connection); - - } - catch (Exception e) - { - getLog().error(e); - throw new MojoExecutionException("Unexpected error executing plugin " + e.getMessage()); - } - finally - { - try - { + .sourceMappingOptions(sourceMappingOptions) + .testMappingOptions(testMappingOptions) + // .excludeObject(excludeObject) + .includeObject(includeObject) + .skipCompatibilityCheck(skipCompatibilityCheck) + .colorConsole(colorConsole) + .failOnErrors(!ignoreFailure); + + 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 { for (Reporter reporter : reporterList) { - new OutputBuffer(reporter).printAvailable(connection, System.out); + writeReporter(connection, reporter); } if (connection != null) { - connection.close(); + connection.close(); } - } - catch (Exception e) - { - getLog().error("Error", e); - } - } - } - - /** - * - * @param resources - * @return - */ - private FileMapperOptions buildOptions(List resources, Resource defaultResource) - { - // Check if this element is empty - if (resources.isEmpty()) - { - resources.add(defaultResource); - } - - List scripts = SQLScannerHelper.findSQLs(resources); + } catch (Exception e) { + getLog().error(e.getMessage(), e); + } + } + } + + private void writeReporter(Connection connection, Reporter reporter) throws SQLException, IOException { + String outputFile = mapReporters.get(reporter.getReporterId()).getConfiguration().getOutputFile(); + if (StringUtils.isNotBlank(outputFile)) { + File file = new File(outputFile); + if (!file.isAbsolute()) { + file = new File(targetDir, outputFile); + } + if (!file.getParentFile().exists()) { + file.getParentFile().mkdirs(); + } + try (FileOutputStream fout = new FileOutputStream(file)) { + getLog().info(format("Writing report to %s", file.getAbsolutePath())); + new OutputBuffer(reporter).printAvailable(connection, new PrintStream(fout)); + } + } else { + new OutputBuffer(reporter).printAvailable(connection, System.out); + } + } + + /** + * + * @param resources + * @return + */ + private FileMapperOptions buildOptions(List resources, Resource defaultResource) { + // Check if this element is empty + if (resources.isEmpty()) { + resources.add(defaultResource); + } + + List scripts = SQLScannerHelper.findSQLs(resources); return new FileMapperOptions(scripts); - } - - /** - * Init all the reports - * - * @param connection - * @return - * @throws SQLException - */ - private List initReporters(Connection connection) throws SQLException - { - List reporterList = new ArrayList<>(); - - for (String reporterId : reporters) - { - Reporter reporter = ReporterFactory.createReporter(reporterId); - reporter.init(connection); - - reporterList.add(reporter); - } - - return reporterList; - } + } + + /** + * Init all the reports + * + * @param connection + * @return + * @throws SQLException + */ + private List initReporters(Connection connection) throws SQLException { + List reporterList = new ArrayList<>(); + + for (ReporterParameter reporterParameter : reporters) { + String reporterName = reporterParameter.getId().name(); + Reporter reporter = ReporterFactory.createReporter(reporterName); + reporter.init(connection); + reporterList.add(reporter); + if (reporterParameter.getConfiguration() == null + || StringUtils.isEmpty(reporterParameter.getConfiguration().getOutputFile())) { + reporterParameter + .setConfiguration(new ReporterConfiguration(reporterParameter.getId().getOutputFile())); + } + mapReporters.put(reporter.getReporterId(), reporterParameter); + } + + return reporterList; + } + + private void dumpParameters(FileMapperOptions sourceMappingOptions, FileMapperOptions testMappingOptions, + List reporterList) { + StringBuilder msg = new StringBuilder(); + msg.append("Invoking TestRunner with: ").append('\n'); + msg.append("reporters="); + reporterList.forEach(new Consumer() { + @Override + public void accept(Reporter t) { + try { + msg.append(t.getSQLTypeName()).append(", "); + } catch (Exception e) { + // NA + } + } + + }); + msg.append('\n'); + msg.append("sources="); + sourceMappingOptions.getFilePaths().forEach(new Consumer() { + @Override + public void accept(String t) { + msg.append(t).append(", "); + } + }); + msg.append('\n'); + msg.append("tests="); + testMappingOptions.getFilePaths().forEach(new Consumer() { + @Override + public void accept(String t) { + msg.append(t).append(", "); + } + }); + msg.append('\n'); + getLog().debug(msg.toString()); + } } \ No newline at end of file diff --git a/utplsql-maven-plugin/src/main/java/org/utplsql/helper/ReporterDefault.java b/utplsql-maven-plugin/src/main/java/org/utplsql/helper/ReporterDefault.java new file mode 100644 index 0000000..7fcd203 --- /dev/null +++ b/utplsql-maven-plugin/src/main/java/org/utplsql/helper/ReporterDefault.java @@ -0,0 +1,22 @@ +package org.utplsql.helper; + +public enum ReporterDefault { + + UT_DOCUMENTATION_REPORTER(""), + UT_COVERAGE_HTML_REPORTER("utplsql/coverage-html-reporter.html"), + UT_TEAMCITY_REPORTER("utplsql/teamcity-reporter.txt"), + UT_XUNIT_REPORTER("utplsql/xunit-reporter.xml"), + UT_COVERALLS_REPORTER("utplsql/coveralls-reporter.json"), + UT_COVERAGE_SONAR_REPORTER("utplsql/coverage-sonar-reporter.xml"), + UT_SONAR_TEST_REPORTER("utplsql/sonar-test-reporter.xml"); + + private String outputFile; + + private ReporterDefault(String outputFile) { + this.outputFile = outputFile; + } + + public String getOutputFile() { + return outputFile; + } +} diff --git a/utplsql-maven-plugin/src/main/java/org/utplsql/model/ReporterConfiguration.java b/utplsql-maven-plugin/src/main/java/org/utplsql/model/ReporterConfiguration.java new file mode 100644 index 0000000..9bab8fe --- /dev/null +++ b/utplsql-maven-plugin/src/main/java/org/utplsql/model/ReporterConfiguration.java @@ -0,0 +1,24 @@ +package org.utplsql.model; + +public class ReporterConfiguration { + + private String outputFile; + + public ReporterConfiguration() { + super(); + } + + public ReporterConfiguration(String outputFile) { + super(); + this.outputFile = outputFile; + } + + public String getOutputFile() { + return outputFile; + } + + public void setOutputFile(String outputFile) { + this.outputFile = outputFile; + } + +} diff --git a/utplsql-maven-plugin/src/main/java/org/utplsql/model/ReporterParameter.java b/utplsql-maven-plugin/src/main/java/org/utplsql/model/ReporterParameter.java new file mode 100644 index 0000000..8a204de --- /dev/null +++ b/utplsql-maven-plugin/src/main/java/org/utplsql/model/ReporterParameter.java @@ -0,0 +1,28 @@ +package org.utplsql.model; + +import org.utplsql.helper.ReporterDefault; + +public class ReporterParameter { + + private ReporterDefault id; + + private ReporterConfiguration configuration; + + public ReporterDefault getId() { + return id; + } + + public void setId(ReporterDefault id) { + this.id = id; + } + + public ReporterConfiguration getConfiguration() { + return configuration; + } + + public void setConfiguration(ReporterConfiguration configuration) { + this.configuration = configuration; + } + + +} From 632446192d4003f3dcf258b7c36ca9bc7d71d529 Mon Sep 17 00:00:00 2001 From: rostskadat Date: Mon, 29 Jan 2018 15:35:07 +0100 Subject: [PATCH 06/71] Fixed path attribute. Can be null, in which case ut/PLSQL need to scan all the sources for the correct annotation --- .../main/java/org/utplsql/UtPLSQLMojo.java | 44 ++++++++++--------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java b/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java index e022d32..03168f2 100644 --- a/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java +++ b/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java @@ -19,6 +19,7 @@ import org.apache.maven.model.Resource; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.logging.Log; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; @@ -64,7 +65,7 @@ public class UtPLSQLMojo extends AbstractMojo { private List reporters; private Map mapReporters = new HashMap<>(); - @Parameter + @Parameter(defaultValue = "") private List paths; @Parameter @@ -83,8 +84,18 @@ public class UtPLSQLMojo extends AbstractMojo { */ @Override public void execute() throws MojoExecutionException { - FileMapperOptions sourceMappingOptions = buildOptions(sources, PluginDefault.buildDefaultSource()); - FileMapperOptions testMappingOptions = buildOptions(tests, PluginDefault.buildDefaultTest()); + FileMapperOptions sourceMappingOptions = null; + try { + sourceMappingOptions = buildOptions(sources, PluginDefault.buildDefaultSource()); + } catch (Exception e) { + throw new MojoExecutionException("Invalid in your pom.xml"); + } + FileMapperOptions testMappingOptions = null; + try { + testMappingOptions = buildOptions(tests, PluginDefault.buildDefaultTest()); + } catch (Exception e) { + throw new MojoExecutionException("Invalid in your pom.xml"); + } Connection connection = null; List reporterList = null; @@ -101,7 +112,7 @@ public void execute() throws MojoExecutionException { .addReporterList(reporterList) .sourceMappingOptions(sourceMappingOptions) .testMappingOptions(testMappingOptions) - // .excludeObject(excludeObject) + .excludeObject(excludeObject) .includeObject(includeObject) .skipCompatibilityCheck(skipCompatibilityCheck) .colorConsole(colorConsole) @@ -191,37 +202,28 @@ private List initReporters(Connection connection) throws SQLException private void dumpParameters(FileMapperOptions sourceMappingOptions, FileMapperOptions testMappingOptions, List reporterList) { - StringBuilder msg = new StringBuilder(); - msg.append("Invoking TestRunner with: ").append('\n'); - msg.append("reporters="); + Log log = getLog(); + log.debug("Invoking TestRunner with: "); + log.debug("reporters="); reporterList.forEach(new Consumer() { @Override public void accept(Reporter t) { - try { - msg.append(t.getSQLTypeName()).append(", "); - } catch (Exception e) { - // NA - } + log.debug(t.getSelfType()); } - }); - msg.append('\n'); - msg.append("sources="); + log.debug("sources="); sourceMappingOptions.getFilePaths().forEach(new Consumer() { @Override public void accept(String t) { - msg.append(t).append(", "); + log.debug(t); } }); - msg.append('\n'); - msg.append("tests="); + log.debug("tests="); testMappingOptions.getFilePaths().forEach(new Consumer() { @Override public void accept(String t) { - msg.append(t).append(", "); + log.debug(t); } }); - msg.append('\n'); - getLog().debug(msg.toString()); } } \ No newline at end of file From 963e128cfcd2c614d386adef42b566a060f4f3b0 Mon Sep 17 00:00:00 2001 From: rostskadat Date: Tue, 30 Jan 2018 09:55:43 +0100 Subject: [PATCH 07/71] Added some output when writing report --- utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java b/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java index 03168f2..f03a504 100644 --- a/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java +++ b/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java @@ -151,7 +151,7 @@ private void writeReporter(Connection connection, Reporter reporter) throws SQLE file.getParentFile().mkdirs(); } try (FileOutputStream fout = new FileOutputStream(file)) { - getLog().info(format("Writing report to %s", file.getAbsolutePath())); + getLog().info(format("Writing report %s to %s", reporter.getSelfType(), file.getAbsolutePath())); new OutputBuffer(reporter).printAvailable(connection, new PrintStream(fout)); } } else { From a0c0fd1bde89a11decf8855399063440b8e459e9 Mon Sep 17 00:00:00 2001 From: rostskadat Date: Tue, 30 Jan 2018 11:33:38 +0100 Subject: [PATCH 08/71] Using lambda function for dumping parameters --- .../main/java/org/utplsql/UtPLSQLMojo.java | 22 +++---------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java b/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java index f03a504..01b01a5 100644 --- a/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java +++ b/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java @@ -13,7 +13,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.function.Consumer; import org.apache.commons.lang3.StringUtils; import org.apache.maven.model.Resource; @@ -205,25 +204,10 @@ private void dumpParameters(FileMapperOptions sourceMappingOptions, FileMapperOp Log log = getLog(); log.debug("Invoking TestRunner with: "); log.debug("reporters="); - reporterList.forEach(new Consumer() { - @Override - public void accept(Reporter t) { - log.debug(t.getSelfType()); - } - }); + reporterList.forEach((Reporter r) -> log.debug(r.getSelfType())); log.debug("sources="); - sourceMappingOptions.getFilePaths().forEach(new Consumer() { - @Override - public void accept(String t) { - log.debug(t); - } - }); + sourceMappingOptions.getFilePaths().forEach(log::debug); log.debug("tests="); - testMappingOptions.getFilePaths().forEach(new Consumer() { - @Override - public void accept(String t) { - log.debug(t); - } - }); + testMappingOptions.getFilePaths().forEach(log::debug); } } \ No newline at end of file From 7f6cf2769a636ee73f02aa6cc14c100b8b2af645 Mon Sep 17 00:00:00 2001 From: rostskadat Date: Tue, 30 Jan 2018 12:17:38 +0100 Subject: [PATCH 09/71] Adding possibility to output to stdout --- utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java b/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java index 01b01a5..d4d824b 100644 --- a/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java +++ b/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java @@ -141,7 +141,7 @@ public void execute() throws MojoExecutionException { private void writeReporter(Connection connection, Reporter reporter) throws SQLException, IOException { String outputFile = mapReporters.get(reporter.getReporterId()).getConfiguration().getOutputFile(); - if (StringUtils.isNotBlank(outputFile)) { + if (StringUtils.isNotBlank(outputFile) && !StringUtils.equals("-", outputFile)) { File file = new File(outputFile); if (!file.isAbsolute()) { file = new File(targetDir, outputFile); From 1b0fa02014683778ac1e260b17f142e9fce0096f Mon Sep 17 00:00:00 2001 From: rostskadat Date: Tue, 30 Jan 2018 13:07:26 +0100 Subject: [PATCH 10/71] Added some documentation --- .../main/java/org/utplsql/UtPLSQLMojo.java | 7 +- .../org/utplsql/helper/PluginDefault.java | 67 +++++++++---------- .../org/utplsql/helper/ReporterDefault.java | 11 ++- .../org/utplsql/helper/SQLScannerHelper.java | 4 ++ 4 files changed, 52 insertions(+), 37 deletions(-) diff --git a/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java b/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java index d4d824b..d9523ed 100644 --- a/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java +++ b/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java @@ -33,7 +33,12 @@ import org.utplsql.model.ReporterConfiguration; import org.utplsql.model.ReporterParameter; - +/** + * 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(defaultValue = "jdbc:oracle:thin:@localhost:1521:ut3") diff --git a/utplsql-maven-plugin/src/main/java/org/utplsql/helper/PluginDefault.java b/utplsql-maven-plugin/src/main/java/org/utplsql/helper/PluginDefault.java index b4a9ce6..5cbf597 100644 --- a/utplsql-maven-plugin/src/main/java/org/utplsql/helper/PluginDefault.java +++ b/utplsql-maven-plugin/src/main/java/org/utplsql/helper/PluginDefault.java @@ -5,50 +5,47 @@ import org.apache.maven.model.Resource; /** + * This class provides methods to retrieve the list of resources in the default and directories. * * @author Alberto Hernández * */ -public class PluginDefault -{ +public class PluginDefault { - // Source Directory - private static final String SOURCE_DIRECTORY = "src/main/plsql"; + // Source Directory + private static final String SOURCE_DIRECTORY = "src/main/plsql"; - // Test Directory - private static final String TEST_DIRECTORY = "src/test/plsql"; + // Test Directory + private static final String TEST_DIRECTORY = "src/test/plsql"; - /** - * - * @return - */ - private static Resource buildDirectory(String directory, String includes) - { - Resource resource = new Resource(); + private PluginDefault() { + // NA + } - // Configure Resources - resource.setDirectory(directory); - resource.setIncludes(Arrays.asList(includes)); - - return resource; - } - - /** - * - * @return - */ - public static Resource buildDefaultSource() - { + /** + * This method returns {@link Resource} for the default {@code source} directory + * + * @return a {@link Resource} + */ + public static Resource buildDefaultSource() { return buildDirectory(SOURCE_DIRECTORY, "**/*.*"); - } - - /** - * - * @return - */ - public static Resource buildDefaultTest() - { + } + + /** + * This method returns {@link Resource} for the default {@code test} directory + * + * @return a {@link Resource} + */ + public static Resource buildDefaultTest() { return buildDirectory(TEST_DIRECTORY, "**/*.pkg"); - } + } + + + 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/helper/ReporterDefault.java b/utplsql-maven-plugin/src/main/java/org/utplsql/helper/ReporterDefault.java index 7fcd203..3fe204d 100644 --- a/utplsql-maven-plugin/src/main/java/org/utplsql/helper/ReporterDefault.java +++ b/utplsql-maven-plugin/src/main/java/org/utplsql/helper/ReporterDefault.java @@ -1,8 +1,17 @@ package org.utplsql.helper; +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. + * + * @author Alberto Hernández + * + */ public enum ReporterDefault { - UT_DOCUMENTATION_REPORTER(""), + UT_DOCUMENTATION_REPORTER("-"), UT_COVERAGE_HTML_REPORTER("utplsql/coverage-html-reporter.html"), UT_TEAMCITY_REPORTER("utplsql/teamcity-reporter.txt"), UT_XUNIT_REPORTER("utplsql/xunit-reporter.xml"), diff --git a/utplsql-maven-plugin/src/main/java/org/utplsql/helper/SQLScannerHelper.java b/utplsql-maven-plugin/src/main/java/org/utplsql/helper/SQLScannerHelper.java index 1863ac1..4ed1386 100644 --- a/utplsql-maven-plugin/src/main/java/org/utplsql/helper/SQLScannerHelper.java +++ b/utplsql-maven-plugin/src/main/java/org/utplsql/helper/SQLScannerHelper.java @@ -17,6 +17,10 @@ public class SQLScannerHelper { + private SQLScannerHelper() { + // NA + } + /** * * @param resouces From 3c59e9797763b6c81b504bc5d20142291c5fd5f9 Mon Sep 17 00:00:00 2001 From: rostskadat Date: Tue, 30 Jan 2018 16:08:22 +0100 Subject: [PATCH 11/71] Removed handling of and . It seems to make the coverage fails, since there no good example of sane default value. Removing until there is a use case for it --- .../src/main/java/org/utplsql/UtPLSQLMojo.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java b/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java index d9523ed..7084e0b 100644 --- a/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java +++ b/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java @@ -115,9 +115,9 @@ public void execute() throws MojoExecutionException { .addPathList(paths) .addReporterList(reporterList) .sourceMappingOptions(sourceMappingOptions) + // .excludeObject(excludeObject) + // .includeObject(includeObject) .testMappingOptions(testMappingOptions) - .excludeObject(excludeObject) - .includeObject(includeObject) .skipCompatibilityCheck(skipCompatibilityCheck) .colorConsole(colorConsole) .failOnErrors(!ignoreFailure); From 16b60d8bf56d1edb98e9e16ff313f3c410f386f6 Mon Sep 17 00:00:00 2001 From: rostskadat Date: Tue, 30 Jan 2018 16:34:30 +0100 Subject: [PATCH 12/71] Log which report logs to the stdout --- utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java b/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java index 7084e0b..d24ea5e 100644 --- a/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java +++ b/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java @@ -155,10 +155,12 @@ private void writeReporter(Connection connection, Reporter reporter) throws SQLE file.getParentFile().mkdirs(); } try (FileOutputStream fout = new FileOutputStream(file)) { + getLog().info(format("Writing report %s to %s", reporter.getSelfType(), file.getAbsolutePath())); new OutputBuffer(reporter).printAvailable(connection, new PrintStream(fout)); } } else { + getLog().info(format("Reporter %s:", reporter.getSelfType())); new OutputBuffer(reporter).printAvailable(connection, System.out); } } From 37d45913dbcc5fd804926d0f0cd58f4b7aae0a4d Mon Sep 17 00:00:00 2001 From: rostskadat Date: Mon, 5 Feb 2018 11:34:49 +0100 Subject: [PATCH 13/71] Added friendly message for invalid and resources --- .../main/java/org/utplsql/UtPLSQLMojo.java | 4 +- .../org/utplsql/helper/SQLScannerHelper.java | 81 ++++++++++--------- 2 files changed, 45 insertions(+), 40 deletions(-) diff --git a/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java b/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java index d24ea5e..e27b6e1 100644 --- a/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java +++ b/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java @@ -92,13 +92,13 @@ public void execute() throws MojoExecutionException { try { sourceMappingOptions = buildOptions(sources, PluginDefault.buildDefaultSource()); } catch (Exception e) { - throw new MojoExecutionException("Invalid in your pom.xml"); + throw new MojoExecutionException(format("Invalid in your pom.xml: %s", e.getMessage())); } FileMapperOptions testMappingOptions = null; try { testMappingOptions = buildOptions(tests, PluginDefault.buildDefaultTest()); } catch (Exception e) { - throw new MojoExecutionException("Invalid in your pom.xml"); + throw new MojoExecutionException(format("Invalid in your pom.xml: %s", e.getMessage())); } Connection connection = null; diff --git a/utplsql-maven-plugin/src/main/java/org/utplsql/helper/SQLScannerHelper.java b/utplsql-maven-plugin/src/main/java/org/utplsql/helper/SQLScannerHelper.java index 4ed1386..6be7baa 100644 --- a/utplsql-maven-plugin/src/main/java/org/utplsql/helper/SQLScannerHelper.java +++ b/utplsql-maven-plugin/src/main/java/org/utplsql/helper/SQLScannerHelper.java @@ -1,5 +1,7 @@ package org.utplsql.helper; +import static java.lang.String.format; + import java.io.File; import java.util.ArrayList; import java.util.Arrays; @@ -9,58 +11,61 @@ import org.codehaus.plexus.util.DirectoryScanner; /** - * Utility to Scan all resources + * Utility to Scan all resources * * @author Alberto Hernández * */ -public class SQLScannerHelper -{ - +public class SQLScannerHelper { + private SQLScannerHelper() { // NA } - /** - * - * @param resouces - * @return - */ - public static List findSQLs(List resources) - { + /** + * + * @param resouces + * @return + */ + public static List findSQLs(List resources) { List founds = new ArrayList<>(); - - for (Resource resource: resources) - { - // Build Scanner - DirectoryScanner scanner = buildScanner(resource); - scanner.scan(); + + for (Resource resource : resources) { + // Build Scanner + DirectoryScanner scanner = buildScanner(resource); + scanner.scan(); for (String basename : scanner.getIncludedFiles()) { founds.add(new File(scanner.getBasedir(), basename).getAbsolutePath()); } - // Append all scanned objects + // Append all scanned objects founds.addAll(Arrays.asList()); - } - - return founds; - } + } + + return founds; + } + + /** + * Build a scanner in forder to Find all Resource files + * + * @param resource + * @return + */ + private static DirectoryScanner buildScanner(Resource resource) { + if (resource != null) { + File baseDir = new File(resource.getDirectory()); + if (!baseDir.exists() || !baseDir.isDirectory() || !baseDir.canRead()) { + throw new IllegalArgumentException( + format("Invalid %s in resource. Check your pom.xml", resource.getDirectory())); + } - /** - * Build a scanner in forder to Find all Resource files - * @param resource - * @return - */ - private static DirectoryScanner buildScanner(Resource resource) - { - DirectoryScanner scanner = new DirectoryScanner(); - - scanner.setBasedir(resource.getDirectory()); - scanner.setIncludes(resource.getIncludes().toArray(new String[0])); - scanner.setExcludes(resource.getExcludes().toArray(new String[0])); - - - return scanner; - } + DirectoryScanner scanner = new DirectoryScanner(); + scanner.setBasedir(resource.getDirectory()); + scanner.setIncludes(resource.getIncludes().toArray(new String[0])); + scanner.setExcludes(resource.getExcludes().toArray(new String[0])); + return scanner; + } + throw new IllegalArgumentException(); + } } From d74cbb49491b946d76bbd9fba76e86abf0fbc47d Mon Sep 17 00:00:00 2001 From: Alberto Hernandez Date: Tue, 6 Feb 2018 12:05:11 +0100 Subject: [PATCH 14/71] Update README.md --- README.md | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/README.md b/README.md index b681574..96db034 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,96 @@ # utPLSQL-maven-plugin A maven plugin for running Unit Tests with utPLSQL v3+ + + +### Configuration + +* `url` + * URL of the Connection to the database + * Default: `jdbc:oracle:thin:@localhost:1521:ut3` +* `user` + * Credential of the connection to the database + * Default: `ut3` +* `password` + * Password of the connection to the database + * Default: `XNtxj8eEgA6X6b6f` +* `ignoreFailure` + * Ignore or continue when a test fail + * Default: `${maven.test.failure.ignore}` +* `colorConsole` + * Colors in the console + * `true` | `false` (default: `false`) +* `skipCompatibilityCheck` + * Skip the Compatibility Checks + * `true` | `false` (default: `false`) +* `reporters` + * List of the Reporters + * Enumeration: +* `paths` + * Paths of the resources + * Default: +* `sources` + * Sources of the scripts at the style of the maven resources +* `tests` + * Test fo the scripts at the style of the maven resources +* `targetDir` + * Target dir, this is a readonly property + * Default: `${project.build.directory}` +* `includeObject` + * Include Object +* `excludeObject` + * Exclude Objects + + + +### Example +```xml + + ${pom.groupId} + utplsql-maven-plugin + ${pom.version} + + test + + + + url_of_connection + user + password + + false + true + + + UT_COVERAGE_SONAR_REPORTER + UT_SONAR_TEST_REPORTER + + + + + SampleDirectory + + **/*pkg + **/*pkb + + + + SampleDirectory2 + + **/*pkb + + + + + + + src/main/test/test1 + + **/*pkg + + + + + + +``` + From b214363eaf8a07edfa2cf4004386c3e63d2bc36b Mon Sep 17 00:00:00 2001 From: Alberto Hernandez Date: Tue, 6 Feb 2018 12:47:46 +0100 Subject: [PATCH 15/71] Added Optional parameters to plugin Improve the Readme --- README.md | 6 +- .../main/java/org/utplsql/UtPLSQLMojo.java | 405 ++++++++++-------- 2 files changed, 231 insertions(+), 180 deletions(-) diff --git a/README.md b/README.md index 96db034..daa35be 100644 --- a/README.md +++ b/README.md @@ -24,10 +24,10 @@ A maven plugin for running Unit Tests with utPLSQL v3+ * `true` | `false` (default: `false`) * `reporters` * List of the Reporters - * Enumeration: + * Enumeration : `UT_DOCUMENTATION_REPORTER`, `UT_COVERAGE_HTML_REPORTER`, `UT_TEAMCITY_REPORTER`, `UT_XUNIT_REPORTER`, `UT_COVERALLS_REPORTER`, `UT_COVERAGE_SONAR_REPORTER`, `UT_SONAR_TEST_REPORTER` + * `paths` * Paths of the resources - * Default: * `sources` * Sources of the scripts at the style of the maven resources * `tests` @@ -57,7 +57,7 @@ A maven plugin for running Unit Tests with utPLSQL v3+ user password - false + false true diff --git a/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java b/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java index e27b6e1..162f950 100644 --- a/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java +++ b/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java @@ -40,181 +40,232 @@ * */ @Mojo(name = "test", defaultPhase = LifecyclePhase.TEST) -public class UtPLSQLMojo extends AbstractMojo { - @Parameter(defaultValue = "jdbc:oracle:thin:@localhost:1521:ut3") - private String url; - - @Parameter(defaultValue = "ut3") - private String user; - - @Parameter(defaultValue = "XNtxj8eEgA6X6b6f") - private String password; - - @Parameter - private String includeObject; - - @Parameter - private String excludeObject; - - @Parameter(defaultValue = "${maven.test.failure.ignore}") - private boolean ignoreFailure; - - @Parameter(defaultValue = "false") - private boolean colorConsole; - - @Parameter(defaultValue = "false") - private boolean skipCompatibilityCheck; - - @Parameter - private List reporters; - private Map mapReporters = new HashMap<>(); - - @Parameter(defaultValue = "") - private List paths; - - @Parameter - private List sources = new ArrayList<>(); - - @Parameter - private List tests = new ArrayList<>(); - - @Parameter(defaultValue = "${project.build.directory}", readonly = true) - private String targetDir; - - /** - * - * Execute the plugin - * - */ - @Override - public void execute() throws MojoExecutionException { - FileMapperOptions sourceMappingOptions = null; - try { - sourceMappingOptions = buildOptions(sources, PluginDefault.buildDefaultSource()); - } catch (Exception e) { - throw new MojoExecutionException(format("Invalid in your pom.xml: %s", e.getMessage())); - } - FileMapperOptions testMappingOptions = null; - try { - testMappingOptions = buildOptions(tests, PluginDefault.buildDefaultTest()); - } catch (Exception e) { - throw new MojoExecutionException(format("Invalid in your pom.xml: %s", e.getMessage())); - } - - Connection connection = null; - List reporterList = null; - try { - connection = DriverManager.getConnection(url, user, password); - reporterList = initReporters(connection); - - if (getLog().isDebugEnabled()) { - dumpParameters(sourceMappingOptions, testMappingOptions, reporterList); - } - - TestRunner runner = new TestRunner() - .addPathList(paths) - .addReporterList(reporterList) - .sourceMappingOptions(sourceMappingOptions) - // .excludeObject(excludeObject) - // .includeObject(includeObject) - .testMappingOptions(testMappingOptions) - .skipCompatibilityCheck(skipCompatibilityCheck) - .colorConsole(colorConsole) - .failOnErrors(!ignoreFailure); - - 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 { - for (Reporter reporter : reporterList) { - writeReporter(connection, reporter); - } - if (connection != null) { - connection.close(); - } - } catch (Exception e) { - getLog().error(e.getMessage(), e); - } - } - } - - private void writeReporter(Connection connection, Reporter reporter) throws SQLException, IOException { - String outputFile = mapReporters.get(reporter.getReporterId()).getConfiguration().getOutputFile(); - if (StringUtils.isNotBlank(outputFile) && !StringUtils.equals("-", outputFile)) { - File file = new File(outputFile); - if (!file.isAbsolute()) { - file = new File(targetDir, outputFile); - } - if (!file.getParentFile().exists()) { - file.getParentFile().mkdirs(); - } - try (FileOutputStream fout = new FileOutputStream(file)) { - - getLog().info(format("Writing report %s to %s", reporter.getSelfType(), file.getAbsolutePath())); - new OutputBuffer(reporter).printAvailable(connection, new PrintStream(fout)); - } - } else { - getLog().info(format("Reporter %s:", reporter.getSelfType())); - new OutputBuffer(reporter).printAvailable(connection, System.out); - } - } - - /** - * - * @param resources - * @return - */ - private FileMapperOptions buildOptions(List resources, Resource defaultResource) { - // Check if this element is empty - if (resources.isEmpty()) { - resources.add(defaultResource); - } - - List scripts = SQLScannerHelper.findSQLs(resources); - return new FileMapperOptions(scripts); - } - - /** - * Init all the reports - * - * @param connection - * @return - * @throws SQLException - */ - private List initReporters(Connection connection) throws SQLException { - List reporterList = new ArrayList<>(); - - for (ReporterParameter reporterParameter : reporters) { - String reporterName = reporterParameter.getId().name(); - Reporter reporter = ReporterFactory.createReporter(reporterName); - reporter.init(connection); - reporterList.add(reporter); - if (reporterParameter.getConfiguration() == null - || StringUtils.isEmpty(reporterParameter.getConfiguration().getOutputFile())) { - reporterParameter - .setConfiguration(new ReporterConfiguration(reporterParameter.getId().getOutputFile())); - } - mapReporters.put(reporter.getReporterId(), reporterParameter); - } - - return reporterList; - } - - private void dumpParameters(FileMapperOptions sourceMappingOptions, FileMapperOptions testMappingOptions, - List reporterList) { - Log log = getLog(); - log.debug("Invoking TestRunner with: "); - log.debug("reporters="); - reporterList.forEach((Reporter r) -> log.debug(r.getSelfType())); - log.debug("sources="); - sourceMappingOptions.getFilePaths().forEach(log::debug); - log.debug("tests="); - testMappingOptions.getFilePaths().forEach(log::debug); - } +public class UtPLSQLMojo extends AbstractMojo +{ + @Parameter(defaultValue = "jdbc:oracle:thin:@localhost:1521:ut3") + private String url; + + @Parameter(defaultValue = "ut3") + private String user; + + @Parameter(defaultValue = "XNtxj8eEgA6X6b6f") + private String password; + + @Parameter + private String includeObject; + + @Parameter + private String excludeObject; + + @Parameter(defaultValue = "${maven.test.failure.ignore}") + private boolean ignoreFailure; + + @Parameter(defaultValue = "false") + private boolean colorConsole; + + @Parameter(defaultValue = "false") + private boolean skipCompatibilityCheck; + + @Parameter + private List reporters; + private Map mapReporters = new HashMap<>(); + + @Parameter(defaultValue = "") + private List paths; + + @Parameter + private List sources = new ArrayList<>(); + + @Parameter + private List tests = new ArrayList<>(); + + @Parameter(defaultValue = "${project.build.directory}", readonly = true) + private String targetDir; + + /** + * + * Execute the plugin + * + */ + @Override + public void execute() throws MojoExecutionException + { + FileMapperOptions sourceMappingOptions = buildOptions(sources, PluginDefault.buildDefaultSource(), "sources"); + ; + FileMapperOptions testMappingOptions = buildOptions(tests, PluginDefault.buildDefaultTest(), "test"); + + Connection connection = null; + List reporterList = null; + try + { + connection = DriverManager.getConnection(url, user, password); + reporterList = initReporters(connection); + + if (getLog().isDebugEnabled()) + { + dumpParameters(sourceMappingOptions, testMappingOptions, reporterList); + } + + TestRunner runner = new TestRunner() + .addPathList(paths) + .addReporterList(reporterList) + .sourceMappingOptions(sourceMappingOptions) + .testMappingOptions(testMappingOptions) + .skipCompatibilityCheck(skipCompatibilityCheck) + .colorConsole(colorConsole) + .failOnErrors(!ignoreFailure); + + // Setting Optional Parameters + if (StringUtils.isNotEmpty(excludeObject)) + { + runner.excludeObject(excludeObject); + } + if (StringUtils.isNotEmpty(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 + { + // Write Reporters + for (Reporter reporter : reporterList) + { + writeReporter(connection, reporter); + } + if (connection != null) + { + connection.close(); + } + } + catch (Exception e) + { + getLog().error(e.getMessage(), e); + } + } + } + + /** + * + * @param connection + * @param reporter + * @throws SQLException + * @throws IOException + */ + private void writeReporter(Connection connection, Reporter reporter) throws SQLException, IOException + { + String outputFile = mapReporters.get(reporter.getReporterId()).getConfiguration().getOutputFile(); + if (StringUtils.isNotBlank(outputFile) && !StringUtils.equals("-", outputFile)) + { + File file = new File(outputFile); + if (!file.isAbsolute()) + { + file = new File(targetDir, outputFile); + } + if (!file.getParentFile().exists()) + { + file.getParentFile().mkdirs(); + } + try (FileOutputStream fout = new FileOutputStream(file)) + { + + getLog().info(format("Writing report %s to %s", reporter.getSelfType(), file.getAbsolutePath())); + new OutputBuffer(reporter).printAvailable(connection, new PrintStream(fout)); + } + } + else + { + getLog().info(format("Reporter %s:", reporter.getSelfType())); + new OutputBuffer(reporter).printAvailable(connection, System.out); + } + } + + /** + * + * @param resources + * @return + * @throws MojoExecutionException + */ + private FileMapperOptions buildOptions(List resources, Resource defaultResource, String msg) throws MojoExecutionException + { + try + { + // Check if this element is empty + if (resources.isEmpty()) + { + resources.add(defaultResource); + } + + List scripts = SQLScannerHelper.findSQLs(resources); + return new FileMapperOptions(scripts); + + } + catch (Exception e) + { + throw new MojoExecutionException(format("Invalid <%s> in your pom.xml: %s", msg, e.getMessage())); + + } + } + + /** + * Init all the reports + * + * @param connection + * @return + * @throws SQLException + */ + private List initReporters(Connection connection) throws SQLException + { + List reporterList = new ArrayList<>(); + + for (ReporterParameter reporterParameter : reporters) + { + String reporterName = reporterParameter.getId().name(); + Reporter reporter = ReporterFactory.createReporter(reporterName); + reporter.init(connection); + reporterList.add(reporter); + if (reporterParameter.getConfiguration() == null + || StringUtils.isEmpty(reporterParameter.getConfiguration().getOutputFile())) + { + reporterParameter + .setConfiguration(new ReporterConfiguration(reporterParameter.getId().getOutputFile())); + } + mapReporters.put(reporter.getReporterId(), reporterParameter); + } + + return reporterList; + } + + /** + * + * @param sourceMappingOptions + * @param testMappingOptions + * @param reporterList + */ + private void dumpParameters(FileMapperOptions sourceMappingOptions, FileMapperOptions testMappingOptions, + List reporterList) + { + Log log = getLog(); + log.debug("Invoking TestRunner with: "); + log.debug("reporters="); + reporterList.forEach((Reporter r) -> log.debug(r.getSelfType())); + log.debug("sources="); + sourceMappingOptions.getFilePaths().forEach(log::debug); + log.debug("tests="); + testMappingOptions.getFilePaths().forEach(log::debug); + } } \ No newline at end of file From 6b179c024fa2bd57e5b767b481f8e308a57de533 Mon Sep 17 00:00:00 2001 From: Alberto Hernandez Date: Tue, 6 Feb 2018 12:52:17 +0100 Subject: [PATCH 16/71] Update README.md Improved readability --- README.md | 76 +++++++++++++++++++++++++++---------------------------- 1 file changed, 37 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index daa35be..2e6d400 100644 --- a/README.md +++ b/README.md @@ -44,53 +44,51 @@ A maven plugin for running Unit Tests with utPLSQL v3+ ### Example ```xml - - ${pom.groupId} - utplsql-maven-plugin - ${pom.version} + + ${pom.groupId} + utplsql-maven-plugin + ${pom.version} test - url_of_connection - user - password + url_of_connection + user + password - false - true + false + true - - UT_COVERAGE_SONAR_REPORTER - UT_SONAR_TEST_REPORTER - - - - - SampleDirectory - - **/*pkg - **/*pkb - - - - SampleDirectory2 - - **/*pkb - - - - - - - src/main/test/test1 - - **/*pkg - - - + + UT_COVERAGE_SONAR_REPORTER + UT_SONAR_TEST_REPORTER + + + + SampleDirectory + + **/*pkg + **/*pkb + + + + SampleDirectory2 + + **/*pkb + + + + + + + src/main/test/test1 + + **/*pkg + + + ``` - From bdb8c10c524fd84cadc103fe07e92de6d436787d Mon Sep 17 00:00:00 2001 From: Alberto Hernandez Date: Wed, 7 Feb 2018 18:06:18 +0100 Subject: [PATCH 17/71] * Modified Reporters Configuration - Parametrized Name, OutputFile, Console * Removed default values for connections and use the same as the Java API * Added fully maven test in order to accomplish maven testing - The only drawback is that we have the parameter connection inside the pom test. * Updated the Readme of project --- README.md | 67 ++++----- .../main/java/org/utplsql/UtPLSQLMojo.java | 120 ++++++----------- .../org/utplsql/helper/PluginDefault.java | 112 ++++++++++----- .../utplsql/model/ReporterConfiguration.java | 24 ---- .../org/utplsql/model/ReporterParameter.java | 92 ++++++++++--- .../org/utplsql/reporter/ReporterWriter.java | 127 ++++++++++++++++++ .../java/org/utpsql/test/UtPLSQLMojoTest.java | 44 ++++-- .../src/test/resources/pom.xml | 46 ++++--- .../resources/scripts/sources/PKG_TEST_ME.bdy | 28 ++++ .../resources/scripts/sources/PKG_TEST_ME.spc | 8 ++ .../resources/scripts/sources/TO_TEST_ME.tab | 8 ++ .../scripts/test/TEST_PKG_TEST_ME.bdy | 126 +++++++++++++++++ .../scripts/test/TEST_PKG_TEST_ME.spc | 86 ++++++++++++ 13 files changed, 669 insertions(+), 219 deletions(-) delete mode 100644 utplsql-maven-plugin/src/main/java/org/utplsql/model/ReporterConfiguration.java create mode 100644 utplsql-maven-plugin/src/main/java/org/utplsql/reporter/ReporterWriter.java create mode 100644 utplsql-maven-plugin/src/test/resources/scripts/sources/PKG_TEST_ME.bdy create mode 100644 utplsql-maven-plugin/src/test/resources/scripts/sources/PKG_TEST_ME.spc create mode 100644 utplsql-maven-plugin/src/test/resources/scripts/sources/TO_TEST_ME.tab create mode 100644 utplsql-maven-plugin/src/test/resources/scripts/test/TEST_PKG_TEST_ME.bdy create mode 100644 utplsql-maven-plugin/src/test/resources/scripts/test/TEST_PKG_TEST_ME.spc diff --git a/README.md b/README.md index 2e6d400..53d457e 100644 --- a/README.md +++ b/README.md @@ -1,30 +1,36 @@ # utPLSQL-maven-plugin A maven plugin for running Unit Tests with utPLSQL v3+ +### Compatibility -### Configuration +This plugin is compatible with the Java-API 3.0.4. + +### Prerequisites +You have to be a fully utPLSQL environment available compatible with the Java API. + + +### Plugin Parameters * `url` * URL of the Connection to the database - * Default: `jdbc:oracle:thin:@localhost:1521:ut3` + * Default: `${dbURL}` * `user` * Credential of the connection to the database - * Default: `ut3` + * Default: `${dbUser}` * `password` * Password of the connection to the database - * Default: `XNtxj8eEgA6X6b6f` + * Default: `${dbPass}` * `ignoreFailure` * Ignore or continue when a test fail * Default: `${maven.test.failure.ignore}` -* `colorConsole` - * Colors in the console - * `true` | `false` (default: `false`) * `skipCompatibilityCheck` * Skip the Compatibility Checks * `true` | `false` (default: `false`) * `reporters` - * List of the Reporters - * Enumeration : `UT_DOCUMENTATION_REPORTER`, `UT_COVERAGE_HTML_REPORTER`, `UT_TEAMCITY_REPORTER`, `UT_XUNIT_REPORTER`, `UT_COVERALLS_REPORTER`, `UT_COVERAGE_SONAR_REPORTER`, `UT_SONAR_TEST_REPORTER` + * 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 @@ -42,53 +48,54 @@ A maven plugin for running Unit Tests with utPLSQL v3+ -### Example +### Sample of use +The next snippet is a sample of declaration of the pom ```xml - - ${pom.groupId} + + org.utplsql utplsql-maven-plugin - ${pom.version} + 1.0.0-SNAPSHOT test - url_of_connection user password - false - true - - UT_COVERAGE_SONAR_REPORTER - UT_SONAR_TEST_REPORTER + + UT_COVERAGE_SONAR_REPORTER + utplsql/coverage-sonar-reporter.xml + true + + + UT_SONAR_TEST_REPORTER + utplsql/sonar-test-reporter.xml + false + + + UT_TEAMCITY_REPORTER + - SampleDirectory + src/test/resources/scripts/sources **/*pkg **/*pkb - - - SampleDirectory2 - - **/*pkb - - - src/main/test/test1 + src/test/resources/scripts/test **/*pkg + **/*pkb - - + ``` diff --git a/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java b/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java index 162f950..8ddd083 100644 --- a/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java +++ b/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java @@ -2,17 +2,11 @@ import static java.lang.String.format; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.PrintStream; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; import org.apache.commons.lang3.StringUtils; import org.apache.maven.model.Resource; @@ -23,15 +17,14 @@ import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.utplsql.api.FileMapperOptions; -import org.utplsql.api.OutputBuffer; import org.utplsql.api.TestRunner; import org.utplsql.api.exception.SomeTestsFailedException; import org.utplsql.api.reporter.Reporter; import org.utplsql.api.reporter.ReporterFactory; import org.utplsql.helper.PluginDefault; import org.utplsql.helper.SQLScannerHelper; -import org.utplsql.model.ReporterConfiguration; import org.utplsql.model.ReporterParameter; +import org.utplsql.reporter.ReporterWriter; /** * This class expose the {@link TestRunner} interface to Maven. @@ -42,13 +35,13 @@ @Mojo(name = "test", defaultPhase = LifecyclePhase.TEST) public class UtPLSQLMojo extends AbstractMojo { - @Parameter(defaultValue = "jdbc:oracle:thin:@localhost:1521:ut3") + @Parameter(defaultValue = "${dbUrl}") private String url; - @Parameter(defaultValue = "ut3") + @Parameter(defaultValue = "${dbUser}") private String user; - @Parameter(defaultValue = "XNtxj8eEgA6X6b6f") + @Parameter(defaultValue = "${dbPass}") private String password; @Parameter @@ -57,18 +50,11 @@ public class UtPLSQLMojo extends AbstractMojo @Parameter private String excludeObject; - @Parameter(defaultValue = "${maven.test.failure.ignore}") - private boolean ignoreFailure; - - @Parameter(defaultValue = "false") - private boolean colorConsole; - @Parameter(defaultValue = "false") private boolean skipCompatibilityCheck; @Parameter private List reporters; - private Map mapReporters = new HashMap<>(); @Parameter(defaultValue = "") private List paths; @@ -82,6 +68,15 @@ public class UtPLSQLMojo extends AbstractMojo @Parameter(defaultValue = "${project.build.directory}", readonly = true) private String targetDir; + @Parameter(defaultValue = "${maven.test.failure.ignore}") + private boolean ignoreFailure; + + // Color in the console, loaded by environment variables + private boolean colorConsole = PluginDefault.resolveColor(); + + // Reporter Writer + private ReporterWriter reporterWriter; + /** * * Execute the plugin @@ -90,21 +85,17 @@ public class UtPLSQLMojo extends AbstractMojo @Override public void execute() throws MojoExecutionException { - FileMapperOptions sourceMappingOptions = buildOptions(sources, PluginDefault.buildDefaultSource(), "sources"); - ; - FileMapperOptions testMappingOptions = buildOptions(tests, PluginDefault.buildDefaultTest(), "test"); - Connection connection = null; - List reporterList = null; try { + FileMapperOptions sourceMappingOptions = buildOptions(sources, PluginDefault.buildDefaultSource(), "sources"); + FileMapperOptions testMappingOptions = buildOptions(tests, PluginDefault.buildDefaultTest(), "test"); + + // Create the Connection to the Database connection = DriverManager.getConnection(url, user, password); - reporterList = initReporters(connection); + List reporterList = initReporters(connection); - if (getLog().isDebugEnabled()) - { - dumpParameters(sourceMappingOptions, testMappingOptions, reporterList); - } + logParameters(sourceMappingOptions, testMappingOptions, reporterList); TestRunner runner = new TestRunner() .addPathList(paths) @@ -116,11 +107,11 @@ public void execute() throws MojoExecutionException .failOnErrors(!ignoreFailure); // Setting Optional Parameters - if (StringUtils.isNotEmpty(excludeObject)) + if (StringUtils.isNotBlank(excludeObject)) { runner.excludeObject(excludeObject); } - if (StringUtils.isNotEmpty(includeObject)) + if (StringUtils.isNotBlank(includeObject)) { runner.includeObject(includeObject); } @@ -143,10 +134,8 @@ public void execute() throws MojoExecutionException try { // Write Reporters - for (Reporter reporter : reporterList) - { - writeReporter(connection, reporter); - } + reporterWriter.writeReporters(connection); + if (connection != null) { connection.close(); @@ -159,41 +148,6 @@ public void execute() throws MojoExecutionException } } - /** - * - * @param connection - * @param reporter - * @throws SQLException - * @throws IOException - */ - private void writeReporter(Connection connection, Reporter reporter) throws SQLException, IOException - { - String outputFile = mapReporters.get(reporter.getReporterId()).getConfiguration().getOutputFile(); - if (StringUtils.isNotBlank(outputFile) && !StringUtils.equals("-", outputFile)) - { - File file = new File(outputFile); - if (!file.isAbsolute()) - { - file = new File(targetDir, outputFile); - } - if (!file.getParentFile().exists()) - { - file.getParentFile().mkdirs(); - } - try (FileOutputStream fout = new FileOutputStream(file)) - { - - getLog().info(format("Writing report %s to %s", reporter.getSelfType(), file.getAbsolutePath())); - new OutputBuffer(reporter).printAvailable(connection, new PrintStream(fout)); - } - } - else - { - getLog().info(format("Reporter %s:", reporter.getSelfType())); - new OutputBuffer(reporter).printAvailable(connection, System.out); - } - } - /** * * @param resources @@ -217,12 +171,11 @@ private FileMapperOptions buildOptions(List resources, Resource defaul catch (Exception e) { throw new MojoExecutionException(format("Invalid <%s> in your pom.xml: %s", msg, e.getMessage())); - } } /** - * Init all the reports + * Init all the reporters * * @param connection * @return @@ -232,19 +185,20 @@ private List initReporters(Connection connection) throws SQLException { List reporterList = new ArrayList<>(); + // Initializate Reporters + reporterWriter = new ReporterWriter(targetDir); + for (ReporterParameter reporterParameter : reporters) { - String reporterName = reporterParameter.getId().name(); - Reporter reporter = ReporterFactory.createReporter(reporterName); + Reporter reporter = ReporterFactory.createReporter(reporterParameter.getName()); reporter.init(connection); reporterList.add(reporter); - if (reporterParameter.getConfiguration() == null - || StringUtils.isEmpty(reporterParameter.getConfiguration().getOutputFile())) + + // Only added the reporter if at least one of the output is required + if (StringUtils.isNotBlank(reporterParameter.getFileOutput()) || reporterParameter.isConsoleOutput()) { - reporterParameter - .setConfiguration(new ReporterConfiguration(reporterParameter.getId().getOutputFile())); + reporterWriter.addReporter(reporterParameter, reporter); } - mapReporters.put(reporter.getReporterId(), reporterParameter); } return reporterList; @@ -256,10 +210,18 @@ private List initReporters(Connection connection) throws SQLException * @param testMappingOptions * @param reporterList */ - private void dumpParameters(FileMapperOptions sourceMappingOptions, FileMapperOptions testMappingOptions, + private void logParameters(FileMapperOptions sourceMappingOptions, FileMapperOptions testMappingOptions, List reporterList) { Log log = getLog(); + log.info("Invoking TestRunner with: " + targetDir); + + // Do nothing when the debug is disabled + if (!log.isDebugEnabled()) + { + return; + } + log.debug("Invoking TestRunner with: "); log.debug("reporters="); reporterList.forEach((Reporter r) -> log.debug(r.getSelfType())); diff --git a/utplsql-maven-plugin/src/main/java/org/utplsql/helper/PluginDefault.java b/utplsql-maven-plugin/src/main/java/org/utplsql/helper/PluginDefault.java index 5cbf597..252e80c 100644 --- a/utplsql-maven-plugin/src/main/java/org/utplsql/helper/PluginDefault.java +++ b/utplsql-maven-plugin/src/main/java/org/utplsql/helper/PluginDefault.java @@ -1,6 +1,7 @@ package org.utplsql.helper; import java.util.Arrays; +import java.util.Map; import org.apache.maven.model.Resource; @@ -10,42 +11,79 @@ * @author Alberto Hernández * */ -public class PluginDefault { - - // Source Directory - private static final String SOURCE_DIRECTORY = "src/main/plsql"; - - // Test Directory - private static final String TEST_DIRECTORY = "src/test/plsql"; - - 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, "**/*.*"); - } - - /** - * This method returns {@link Resource} for the default {@code test} directory - * - * @return a {@link Resource} - */ - public static Resource buildDefaultTest() { - return buildDirectory(TEST_DIRECTORY, "**/*.pkg"); - } - - - 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 +{ + + private static final String STYLE_COLOR_PROPERTY = "style.color"; + + private static final String BATCH_MODE = "B"; + + private static final String LOG_FILE = "l"; + + // Source Directory + private static final String SOURCE_DIRECTORY = "src/main/plsql"; + + // Test Directory + private static final String TEST_DIRECTORY = "src/test/plsql"; + + 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, "**/*.*"); + } + + /** + * This method returns {@link Resource} for the default {@code test} directory + * + * @return a {@link Resource} + */ + public static Resource buildDefaultTest() + { + return buildDirectory(TEST_DIRECTORY, "**/*.pkg"); + } + + private static Resource buildDirectory(String directory, String includes) + { + Resource resource = new Resource(); + resource.setDirectory(directory); + resource.setIncludes(Arrays.asList(includes)); + return resource; + } + + /** + * + * @return + */ + public static boolean resolveColor() + { + final Map env = System.getenv(); + String color = env.get(STYLE_COLOR_PROPERTY); + + if ("always".equals(color)) + { + return true; + } + + if ("never".equals(color)) + { + return false; + } + + if (env.containsKey(BATCH_MODE) || env.containsKey(LOG_FILE)) + { + return false; + } + + return false; + } } diff --git a/utplsql-maven-plugin/src/main/java/org/utplsql/model/ReporterConfiguration.java b/utplsql-maven-plugin/src/main/java/org/utplsql/model/ReporterConfiguration.java deleted file mode 100644 index 9bab8fe..0000000 --- a/utplsql-maven-plugin/src/main/java/org/utplsql/model/ReporterConfiguration.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.utplsql.model; - -public class ReporterConfiguration { - - private String outputFile; - - public ReporterConfiguration() { - super(); - } - - public ReporterConfiguration(String outputFile) { - super(); - this.outputFile = outputFile; - } - - public String getOutputFile() { - return outputFile; - } - - public void setOutputFile(String outputFile) { - this.outputFile = outputFile; - } - -} diff --git a/utplsql-maven-plugin/src/main/java/org/utplsql/model/ReporterParameter.java b/utplsql-maven-plugin/src/main/java/org/utplsql/model/ReporterParameter.java index 8a204de..56ebc60 100644 --- a/utplsql-maven-plugin/src/main/java/org/utplsql/model/ReporterParameter.java +++ b/utplsql-maven-plugin/src/main/java/org/utplsql/model/ReporterParameter.java @@ -1,28 +1,84 @@ package org.utplsql.model; -import org.utplsql.helper.ReporterDefault; +import org.codehaus.plexus.util.StringUtils; -public class ReporterParameter { - - private ReporterDefault id; +public class ReporterParameter +{ - private ReporterConfiguration configuration; + // Name of the registered reported in UtPLSQL + private String name; - public ReporterDefault getId() { - return id; - } + // File Output of the reporter + private String fileOutput; - public void setId(ReporterDefault id) { - this.id = id; - } + // Writes the report to console + private boolean consoleOutput; - public ReporterConfiguration getConfiguration() { - return configuration; - } + /** + * + */ + public ReporterParameter() + { + super(); + } - public void setConfiguration(ReporterConfiguration configuration) { - this.configuration = configuration; - } - + /** + * @return the name + */ + public String getName() + { + return name; + } + + /** + * @param name + * the name to set + */ + public void setName(String name) + { + this.name = name; + } + + /** + * @return the fileOutput + */ + public String getFileOutput() + { + return fileOutput; + } + + /** + * @param fileOutput + * the fileOutput to set + */ + public void setFileOutput(String fileOutput) + { + this.fileOutput = fileOutput; + } + + /** + * @return the consoleOutput + */ + public boolean isConsoleOutput() + { + return 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); + } } diff --git a/utplsql-maven-plugin/src/main/java/org/utplsql/reporter/ReporterWriter.java b/utplsql-maven-plugin/src/main/java/org/utplsql/reporter/ReporterWriter.java new file mode 100644 index 0000000..2673480 --- /dev/null +++ b/utplsql-maven-plugin/src/main/java/org/utplsql/reporter/ReporterWriter.java @@ -0,0 +1,127 @@ +package org.utplsql.reporter; + +import static java.lang.String.format; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.sql.Connection; +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.lang3.tuple.Pair; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.plugin.logging.SystemStreamLog; +import org.utplsql.api.OutputBuffer; +import org.utplsql.api.reporter.Reporter; +import org.utplsql.model.ReporterParameter; + +public class ReporterWriter +{ + private static final Log LOG = new SystemStreamLog(); + + // Reporter Parameters + private List> listReporters; + + // Output Directory + private String outputDirectory; + + /** + * + */ + public ReporterWriter(String outputDirectory) + { + listReporters = new ArrayList<>(); + this.outputDirectory = outputDirectory; + } + + /** + * + * @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 = new OutputBuffer(reporter); + + 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.getSelfType(), file.getAbsolutePath())); + + // Added to the Report + printStreams.add(new PrintStream(fout)); + } + + if (reporterParameter.isConsoleOutput()) + { + LOG.info(format("Writing report %s to Console", reporter.getSelfType())); + 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)); + } + +} diff --git a/utplsql-maven-plugin/src/test/java/org/utpsql/test/UtPLSQLMojoTest.java b/utplsql-maven-plugin/src/test/java/org/utpsql/test/UtPLSQLMojoTest.java index eac56cc..dc891a2 100644 --- a/utplsql-maven-plugin/src/test/java/org/utpsql/test/UtPLSQLMojoTest.java +++ b/utplsql-maven-plugin/src/test/java/org/utpsql/test/UtPLSQLMojoTest.java @@ -1,5 +1,7 @@ package org.utpsql.test; +import java.io.File; + import org.apache.maven.plugin.testing.MojoRule; import org.junit.Assert; import org.junit.Rule; @@ -8,28 +10,44 @@ public class UtPLSQLMojoTest { - public static final String POM_PATH = "src/test/resources/pom.xml"; + public static final String POM_PATH = "src/test/resources/"; + + public static final String OUTPUT_DIRECTORY = "target/test-classes"; @Rule - public MojoRule rule = new MojoRule() + public MojoRule rule = new MojoRule(); + + @Test + public void testDefinition() throws Exception { - @Override - protected void before() throws Throwable + + try { - } + UtPLSQLMojo myMojo = (UtPLSQLMojo) rule.lookupConfiguredMojo(new File(POM_PATH), "test"); - @Override - protected void after() + Assert.assertNotNull(myMojo); + myMojo.execute(); + + checkCoverReportsGenerated("utplsql/coverage-sonar-reporter.xml", "utplsql/sonar-test-reporter.xml"); + } + catch (Exception e) { + e.printStackTrace(); + Assert.fail("Unexpected Exception running the test of Definition"); } - }; + } - @Test - public void testDefinition() throws Exception + /** + * + * @param files + */ + private void checkCoverReportsGenerated(String... files) { - UtPLSQLMojo myMojo = (UtPLSQLMojo) rule.lookupMojo("test", POM_PATH); - Assert.assertNotNull(myMojo); - myMojo.execute(); + for (String filename : files) + { + File file = new File(OUTPUT_DIRECTORY, filename); + Assert.assertTrue("The reporter for " + filename + " was not generated", file.exists()); + } } } diff --git a/utplsql-maven-plugin/src/test/resources/pom.xml b/utplsql-maven-plugin/src/test/resources/pom.xml index 5f91cad..3eeae3d 100644 --- a/utplsql-maven-plugin/src/test/resources/pom.xml +++ b/utplsql-maven-plugin/src/test/resources/pom.xml @@ -8,8 +8,17 @@ maven-plugin utplsql-maven-plugin Maven Plugin Test - + + + + jdbc:oracle:thin:@180.129.3.101:1521:xe + ut3 + XNtxj8eEgA6X6b6f + + + ../../../target/test-classes + ${pom.groupId} @@ -19,42 +28,43 @@ test - - url_of_connection - user - password - - false - true + false + + + :plsql + - UT_COVERAGE_SONAR_REPORTER - UT_SONAR_TEST_REPORTER + + UT_COVERAGE_SONAR_REPORTER + utplsql/coverage-sonar-reporter.xml + true + + + UT_SONAR_TEST_REPORTER + utplsql/sonar-test-reporter.xml + true + - SampleDirectory + src/test/resources/scripts/sources **/*pkg **/*pkb - - SampleDirectory2 - - **/*pkb - - - src/main/test/test1 + src/test/resources/scripts/test **/*pkg + **/*pkb diff --git a/utplsql-maven-plugin/src/test/resources/scripts/sources/PKG_TEST_ME.bdy b/utplsql-maven-plugin/src/test/resources/scripts/sources/PKG_TEST_ME.bdy new file mode 100644 index 0000000..a2ff185 --- /dev/null +++ b/utplsql-maven-plugin/src/test/resources/scripts/sources/PKG_TEST_ME.bdy @@ -0,0 +1,28 @@ +CREATE OR REPLACE PACKAGE BODY PKG_TEST_ME IS + + -- + -- This + -- + FUNCTION FC_TEST_ME(PPARAM1 IN VARCHAR2) RETURN NUMBER IS + BEGIN + IF PPARAM1 IS NULL THEN + RETURN NULL; + ELSIF PPARAM1 = '1' THEN + RETURN 1; + ELSE + RETURN 0; + END IF; + END FC_TEST_ME; + + PROCEDURE PR_TEST_ME(PSNAME IN VARCHAR2) IS + BEGIN + IF PSNAME IS NULL THEN + NULL; + ELSE + INSERT INTO TO_TEST_ME (SNAME) VALUES (PSNAME); + COMMIT; + END IF; + END PR_TEST_ME; + +END PKG_TEST_ME; +/ \ No newline at end of file diff --git a/utplsql-maven-plugin/src/test/resources/scripts/sources/PKG_TEST_ME.spc b/utplsql-maven-plugin/src/test/resources/scripts/sources/PKG_TEST_ME.spc new file mode 100644 index 0000000..67fe1f8 --- /dev/null +++ b/utplsql-maven-plugin/src/test/resources/scripts/sources/PKG_TEST_ME.spc @@ -0,0 +1,8 @@ +-- +-- This package is used TO demonstrate the utPL/SQL possibilities +-- +CREATE OR REPLACE PACKAGE PKG_TEST_ME AS + FUNCTION FC_TEST_ME(PPARAM1 IN VARCHAR2) RETURN NUMBER; + PROCEDURE PR_TEST_ME(PSNAME IN VARCHAR2); +END PKG_TEST_ME; +/ \ No newline at end of file diff --git a/utplsql-maven-plugin/src/test/resources/scripts/sources/TO_TEST_ME.tab b/utplsql-maven-plugin/src/test/resources/scripts/sources/TO_TEST_ME.tab new file mode 100644 index 0000000..1cd6f12 --- /dev/null +++ b/utplsql-maven-plugin/src/test/resources/scripts/sources/TO_TEST_ME.tab @@ -0,0 +1,8 @@ +-- +-- This is a table used to demonstrate the UNIT test framework. +-- +CREATE TABLE TO_TEST_ME +( + SNAME VARCHAR2(10) +) +/ diff --git a/utplsql-maven-plugin/src/test/resources/scripts/test/TEST_PKG_TEST_ME.bdy b/utplsql-maven-plugin/src/test/resources/scripts/test/TEST_PKG_TEST_ME.bdy new file mode 100644 index 0000000..6f347b6 --- /dev/null +++ b/utplsql-maven-plugin/src/test/resources/scripts/test/TEST_PKG_TEST_ME.bdy @@ -0,0 +1,126 @@ +CREATE OR REPLACE PACKAGE BODY TEST_PKG_TEST_ME AS + + --------------------------------------------------------------------------- + PROCEDURE SETUP_GLOBAL IS + BEGIN + -- Put here the code which is valid for all tests and that should be + -- executed once. + NULL; + END SETUP_GLOBAL; + + --------------------------------------------------------------------------- + PROCEDURE TEARDOWN_GLOBAL IS + BEGIN + -- Put here the code that should be called only once after all the test + -- have executed + NULL; + END TEARDOWN_GLOBAL; + + --------------------------------------------------------------------------- + PROCEDURE SETUP_TEST IS + BEGIN + -- Nothing to clean up globally + NULL; + END SETUP_TEST; + + PROCEDURE TEARDOWN_TEST IS + BEGIN + -- Nothing to clean up globally + NULL; + END TEARDOWN_TEST; + + PROCEDURE TEST_FC_INPUT_1 IS + BEGIN + -- Ok this is a real test where I check that the function return 1 + -- when called with a '1' parameter + UT.EXPECT(PKG_TEST_ME.FC_TEST_ME('1')).TO_EQUAL(1); + END; + + PROCEDURE SETUP_TEST_FC_INPUT_1 IS + BEGIN + -- Nothing to be done really + NULL; + END; + + PROCEDURE TEARDOWN_TEST_FC_INPUT_1 IS + BEGIN + -- Nothing to be done really + NULL; + END; + + PROCEDURE TEST_FC_INPUT_0 IS + BEGIN + -- Ok this is a real test where I check that the function return 0 + -- when called with a '0' parameter + UT.EXPECT(PKG_TEST_ME.FC_TEST_ME('0')).TO_EQUAL(0); + END; + + PROCEDURE TEST_FC_INPUT_NULL IS + BEGIN + -- Ok I check that the function return NULL + -- when called with a NULL parameter + UT.EXPECT(PKG_TEST_ME.FC_TEST_ME(NULL)).TO_BE_NULL; + END TEST_FC_INPUT_NULL; + + PROCEDURE TEST_PR_TEST_ME_NULL IS + VNCOUNT1 PLS_INTEGER; + VNCOUNT2 PLS_INTEGER; + BEGIN + -- In this example I check that the procedure does + -- not insert anything when passing it a NULL parameter + SELECT COUNT(1) INTO VNCOUNT1 FROM TO_TEST_ME; + PKG_TEST_ME.PR_TEST_ME(NULL); + SELECT COUNT(1) INTO VNCOUNT2 FROM TO_TEST_ME; + UT.EXPECT(VNCOUNT1).TO_EQUAL(VNCOUNT2); + END; + + PROCEDURE TEST_PR_TEST_ME_NOT_NULL IS + VNCOUNT1 PLS_INTEGER; + VNCOUNT2 PLS_INTEGER; + VSNAME TO_TEST_ME.SNAME%TYPE; + BEGIN + -- In this test I will check that I do insert a value + -- when the parameter is not null. I futher check that + -- the procedure has inserted the value I specified. + SELECT COUNT(1) INTO VNCOUNT1 FROM TO_TEST_ME; + VSNAME := TO_CHAR(VNCOUNT1); + PKG_TEST_ME.PR_TEST_ME(VSNAME); + SELECT COUNT(1) INTO VNCOUNT2 FROM TO_TEST_ME; + + -- Check that I have inserted the value + UT.EXPECT(VNCOUNT1 + 1).TO_EQUAL(VNCOUNT2); + SELECT COUNT(1) INTO VNCOUNT2 FROM TO_TEST_ME T WHERE T.SNAME = VSNAME; + + -- Check that I inserted the one I said I would insert + UT.EXPECT(VNCOUNT2).TO_EQUAL(1); + DELETE FROM TO_TEST_ME T WHERE T.SNAME = VSNAME; + COMMIT; + END; + + PROCEDURE TEST_PR_TEST_ME_EXISTS IS + BEGIN + -- In case the value exists the procedure should fail with an exception. + BEGIN + PKG_TEST_ME.PR_TEST_ME('EXISTS'); + PKG_TEST_ME.PR_TEST_ME('EXISTS'); + EXCEPTION + WHEN OTHERS THEN + UT.FAIL('Unexpected exception raised'); + END; + END; + + PROCEDURE TEST_PR_TEST_ME_CURSOR IS + TYPE REF_CURSOR IS REF CURSOR; + VEXPECTED REF_CURSOR; + VACTUAL REF_CURSOR; + BEGIN + EXECUTE IMMEDIATE 'TRUNCATE TABLE TO_TEST_ME'; + OPEN VEXPECTED FOR + SELECT T.SNAME FROM TO_TEST_ME T; + OPEN VACTUAL FOR + SELECT T.SNAME FROM TO_TEST_ME T; + UT.EXPECT(VEXPECTED).TO_(EQUAL(VACTUAL)); + END; + +END; +/ diff --git a/utplsql-maven-plugin/src/test/resources/scripts/test/TEST_PKG_TEST_ME.spc b/utplsql-maven-plugin/src/test/resources/scripts/test/TEST_PKG_TEST_ME.spc new file mode 100644 index 0000000..a2b5f6d --- /dev/null +++ b/utplsql-maven-plugin/src/test/resources/scripts/test/TEST_PKG_TEST_ME.spc @@ -0,0 +1,86 @@ +CREATE OR REPLACE PACKAGE TEST_PKG_TEST_ME AS + -- + -- This package shows all the possibilities to unit test + -- your PL/SQL package. NOTE that it is not limited to + -- testing your package. You can do that on all your + -- procedure/functions... + -- + + /** + * This two parameters are used by the test framework in + * order to identify the test suite to run + */ + -- %suite(TEST_PKG_TEST_ME) + -- %suitepath(plsql.examples) + + /* + * This method is invoked once before any other method. + * It should contain all the setup code that is relevant + * for all your test. It might be inserting a register, + * creating a type, etc... + */ + -- %beforeall + PROCEDURE SETUP_GLOBAL; + + /* + * This method is invoked once after all other method. + * It can be used to clean up all the resources that + * you created in your script + */ + -- %afterall + PROCEDURE TEARDOWN_GLOBAL; + + /* + * This method is called once before each test. + */ + -- %beforeeach + PROCEDURE SETUP_TEST; + + /* + * This method is called once after each test. + */ + -- %aftereach + PROCEDURE TEARDOWN_TEST; + + /** + * This is a real test. The main test can declare a setup + * and teardown method in order to setup and cleanup things + * for that specific test. + */ + -- %test + -- %displayname(Checking if function ('1') returns 1) + -- %beforetest(SETUP_TEST_FC_INPUT_1) + -- %aftertest(TEARDOWN_TEST_FC_INPUT_1) + PROCEDURE TEST_FC_INPUT_1; + PROCEDURE SETUP_TEST_FC_INPUT_1; + PROCEDURE TEARDOWN_TEST_FC_INPUT_1; + + -- %test + -- %displayname(Checking if function ('0') returns 0) + PROCEDURE TEST_FC_INPUT_0; + + -- %test + -- %displayname(Checking if function (NULL) returns NULL) + PROCEDURE TEST_FC_INPUT_NULL; + + -- %test + -- %displayname(Checking if procedure (NULL) insert) + PROCEDURE TEST_PR_TEST_ME_NULL; + + -- %test + -- %displayname(Checking if procedure (NOT NULL) insert) + -- %rollback(manual) + PROCEDURE TEST_PR_TEST_ME_NOT_NULL; + + -- %test + -- %displayname(Checking if procedure (NOT NULL) insert while existing) + -- %rollback(manual) + PROCEDURE TEST_PR_TEST_ME_EXISTS; + + -- %test + -- %displayname(Demonstrating the use of cursor) + -- %rollback(manual) + PROCEDURE TEST_PR_TEST_ME_CURSOR; + +END; +/ From 47df5d55628c6f3b7e4176f8dc5a9e15ffe96cad Mon Sep 17 00:00:00 2001 From: alberto-hernandez Date: Tue, 15 May 2018 21:00:58 +0200 Subject: [PATCH 18/71] Upgrade the Maven Plugin to the API version 3.1.0 --- README.md | 6 +++- pom.xml | 2 +- utplsql-maven-plugin/pom.xml | 18 ++++++++++-- .../main/java/org/utplsql/UtPLSQLMojo.java | 28 +++++++++++-------- .../org/utplsql/reporter/ReporterWriter.java | 24 +++++++++++----- .../src/test/resources/pom.xml | 2 +- 6 files changed, 55 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 53d457e..4cafa9e 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ A maven plugin for running Unit Tests with utPLSQL v3+ ### Compatibility -This plugin is compatible with the Java-API 3.0.4. +This plugin is compatible with the Java-API 3.1.0. ### Prerequisites You have to be a fully utPLSQL environment available compatible with the Java API. @@ -20,6 +20,9 @@ You have to be a fully utPLSQL environment available compatible with the Java AP * `password` * Password of the connection to the database * Default: `${dbPass}` +* `version` + * Version of the utplsql + * Default: `3.1.0` * `ignoreFailure` * Ignore or continue when a test fail * Default: `${maven.test.failure.ignore}` @@ -62,6 +65,7 @@ The next snippet is a sample of declaration of the pom url_of_connection user password + 3.1.0 false diff --git a/pom.xml b/pom.xml index e16cf20..4e79161 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.utplsql utplsql-maven-plugin-build - 1.0-SNAPSHOT + 1.0.0-SNAPSHOT pom utplsql-maven-plugin Maven Plugin Build diff --git a/utplsql-maven-plugin/pom.xml b/utplsql-maven-plugin/pom.xml index c11545f..6c3fa54 100644 --- a/utplsql-maven-plugin/pom.xml +++ b/utplsql-maven-plugin/pom.xml @@ -17,13 +17,12 @@ UTF-8 1.8 - org.utplsql java-api - 3.0.4 + 3.1.0 @@ -118,9 +117,22 @@ - + + + + utplsql-java-api + https://packagecloud.io/utplsql/utplsql-java-api/maven2 + + true + + + true + + + + diff --git a/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java b/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java index 8ddd083..4ef8ab4 100644 --- a/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java +++ b/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java @@ -18,6 +18,7 @@ import org.apache.maven.plugins.annotations.Parameter; import org.utplsql.api.FileMapperOptions; import org.utplsql.api.TestRunner; +import org.utplsql.api.Version; import org.utplsql.api.exception.SomeTestsFailedException; import org.utplsql.api.reporter.Reporter; import org.utplsql.api.reporter.ReporterFactory; @@ -43,6 +44,9 @@ public class UtPLSQLMojo extends AbstractMojo @Parameter(defaultValue = "${dbPass}") private String password; + + @Parameter(defaultValue = "3.1.0") + private String version; @Parameter private String includeObject; @@ -86,13 +90,14 @@ public class UtPLSQLMojo extends AbstractMojo public void execute() throws MojoExecutionException { Connection connection = null; - try + try { FileMapperOptions sourceMappingOptions = buildOptions(sources, PluginDefault.buildDefaultSource(), "sources"); FileMapperOptions testMappingOptions = buildOptions(tests, PluginDefault.buildDefaultTest(), "test"); - + // Create the Connection to the Database connection = DriverManager.getConnection(url, user, password); + List reporterList = initReporters(connection); logParameters(sourceMappingOptions, testMappingOptions, reporterList); @@ -117,7 +122,7 @@ public void execute() throws MojoExecutionException } runner.run(connection); - + } catch (SomeTestsFailedException e) { @@ -135,11 +140,6 @@ public void execute() throws MojoExecutionException { // Write Reporters reporterWriter.writeReporters(connection); - - if (connection != null) - { - connection.close(); - } } catch (Exception e) { @@ -184,13 +184,17 @@ private FileMapperOptions buildOptions(List resources, Resource defaul private List initReporters(Connection connection) throws SQLException { List reporterList = new ArrayList<>(); + + Version utlVersion = new Version (version); - // Initializate Reporters - reporterWriter = new ReporterWriter(targetDir); + // Initialized Reporters + reporterWriter = new ReporterWriter(targetDir, utlVersion); + + ReporterFactory reporterFactory = ReporterFactory.createEmpty(); for (ReporterParameter reporterParameter : reporters) { - Reporter reporter = ReporterFactory.createReporter(reporterParameter.getName()); + Reporter reporter = reporterFactory.createReporter(reporterParameter.getName()); reporter.init(connection); reporterList.add(reporter); @@ -224,7 +228,7 @@ private void logParameters(FileMapperOptions sourceMappingOptions, FileMapperOpt log.debug("Invoking TestRunner with: "); log.debug("reporters="); - reporterList.forEach((Reporter r) -> log.debug(r.getSelfType())); + reporterList.forEach((Reporter r) -> log.debug(r.getTypeName())); log.debug("sources="); sourceMappingOptions.getFilePaths().forEach(log::debug); log.debug("tests="); diff --git a/utplsql-maven-plugin/src/main/java/org/utplsql/reporter/ReporterWriter.java b/utplsql-maven-plugin/src/main/java/org/utplsql/reporter/ReporterWriter.java index 2673480..6d5a65f 100644 --- a/utplsql-maven-plugin/src/main/java/org/utplsql/reporter/ReporterWriter.java +++ b/utplsql-maven-plugin/src/main/java/org/utplsql/reporter/ReporterWriter.java @@ -14,7 +14,9 @@ import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.logging.Log; import org.apache.maven.plugin.logging.SystemStreamLog; -import org.utplsql.api.OutputBuffer; +import org.utplsql.api.Version; +import org.utplsql.api.outputBuffer.OutputBuffer; +import org.utplsql.api.outputBuffer.OutputBufferProvider; import org.utplsql.api.reporter.Reporter; import org.utplsql.model.ReporterParameter; @@ -27,14 +29,22 @@ public class ReporterWriter // Output Directory private String outputDirectory; + + // Database Version + private Version databaseVersion; + /** - * + * Constructor of the reporter writer + * @param outputDirectory + * @param databaseVersion */ - public ReporterWriter(String outputDirectory) + public ReporterWriter(String outputDirectory, Version databaseVersion) { - listReporters = new ArrayList<>(); + this.listReporters = new ArrayList<>(); this.outputDirectory = outputDirectory; + this.databaseVersion = databaseVersion; + } /** @@ -64,7 +74,7 @@ private void writeReports(Connection connection, Reporter reporter, ReporterPara // try { - OutputBuffer buffer = new OutputBuffer(reporter); + OutputBuffer buffer = OutputBufferProvider.getCompatibleOutputBuffer(databaseVersion, reporter, connection); if (reporterParameter.isFileOutput()) { @@ -82,7 +92,7 @@ private void writeReports(Connection connection, Reporter reporter, ReporterPara } fout = new FileOutputStream(file); - LOG.info(format("Writing report %s to %s", reporter.getSelfType(), file.getAbsolutePath())); + LOG.info(format("Writing report %s to %s", reporter.getTypeName(), file.getAbsolutePath())); // Added to the Report printStreams.add(new PrintStream(fout)); @@ -90,7 +100,7 @@ private void writeReports(Connection connection, Reporter reporter, ReporterPara if (reporterParameter.isConsoleOutput()) { - LOG.info(format("Writing report %s to Console", reporter.getSelfType())); + LOG.info(format("Writing report %s to Console", reporter.getTypeName())); printStreams.add(System.out); } buffer.printAvailable(connection, printStreams); diff --git a/utplsql-maven-plugin/src/test/resources/pom.xml b/utplsql-maven-plugin/src/test/resources/pom.xml index 3eeae3d..abac3fc 100644 --- a/utplsql-maven-plugin/src/test/resources/pom.xml +++ b/utplsql-maven-plugin/src/test/resources/pom.xml @@ -11,7 +11,7 @@ - jdbc:oracle:thin:@180.129.3.101:1521:xe + jdbc:oracle:thin:@127.0.0.1:1521:xe ut3 XNtxj8eEgA6X6b6f From 0946db122f45ff29fd6072b05e5e66c756e005bf Mon Sep 17 00:00:00 2001 From: ahernandez Date: Wed, 16 May 2018 22:47:28 +0200 Subject: [PATCH 19/71] Upgraded version to 3.1.0 to be aligned with API Retrieve the Framework version with the API utility Upgrade documentation to remove parameter version --- README.md | 3 --- pom.xml | 2 +- utplsql-maven-plugin/pom.xml | 2 +- .../src/main/java/org/utplsql/UtPLSQLMojo.java | 6 ++---- 4 files changed, 4 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 4cafa9e..4c62921 100644 --- a/README.md +++ b/README.md @@ -20,9 +20,6 @@ You have to be a fully utPLSQL environment available compatible with the Java AP * `password` * Password of the connection to the database * Default: `${dbPass}` -* `version` - * Version of the utplsql - * Default: `3.1.0` * `ignoreFailure` * Ignore or continue when a test fail * Default: `${maven.test.failure.ignore}` diff --git a/pom.xml b/pom.xml index 4e79161..99e21ae 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.utplsql utplsql-maven-plugin-build - 1.0.0-SNAPSHOT + 3.1.0-SNAPSHOT pom utplsql-maven-plugin Maven Plugin Build diff --git a/utplsql-maven-plugin/pom.xml b/utplsql-maven-plugin/pom.xml index 6c3fa54..13496c1 100644 --- a/utplsql-maven-plugin/pom.xml +++ b/utplsql-maven-plugin/pom.xml @@ -6,7 +6,7 @@ utplsql-maven-plugin maven-plugin - 1.0.0-SNAPSHOT + 3.1.0-SNAPSHOT utplsql-maven-plugin Maven Plugin diff --git a/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java b/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java index 4ef8ab4..8145811 100644 --- a/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java +++ b/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java @@ -16,6 +16,7 @@ import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; +import org.utplsql.api.DBHelper; import org.utplsql.api.FileMapperOptions; import org.utplsql.api.TestRunner; import org.utplsql.api.Version; @@ -45,9 +46,6 @@ public class UtPLSQLMojo extends AbstractMojo @Parameter(defaultValue = "${dbPass}") private String password; - @Parameter(defaultValue = "3.1.0") - private String version; - @Parameter private String includeObject; @@ -185,7 +183,7 @@ private List initReporters(Connection connection) throws SQLException { List reporterList = new ArrayList<>(); - Version utlVersion = new Version (version); + Version utlVersion = DBHelper.getDatabaseFrameworkVersion(connection); // Initialized Reporters reporterWriter = new ReporterWriter(targetDir, utlVersion); From e3c4e4f060b7c61b0118f8c02921f3c838be5784 Mon Sep 17 00:00:00 2001 From: Jacek Gebal Date: Thu, 17 May 2018 20:54:34 +0100 Subject: [PATCH 20/71] Adding initial Travis config for the project --- .travis.yml | 59 +++++++++++++++++++++++++++++++++ .travis/create_api_user.sh | 17 ++++++++++ .travis/create_release.sh | 33 ++++++++++++++++++ .travis/install_demo_project.sh | 44 ++++++++++++++++++++++++ .travis/install_utplsql.sh | 36 ++++++++++++++++++++ .travis/maven_cfg.sh | 17 ++++++++++ .travis/settings.xml | 51 ++++++++++++++++++++++++++++ .travis/start_db.sh | 14 ++++++++ 8 files changed, 271 insertions(+) create mode 100644 .travis.yml create mode 100644 .travis/create_api_user.sh create mode 100644 .travis/create_release.sh create mode 100644 .travis/install_demo_project.sh create mode 100644 .travis/install_utplsql.sh create mode 100644 .travis/maven_cfg.sh create mode 100644 .travis/settings.xml create mode 100644 .travis/start_db.sh diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..c3e80cd --- /dev/null +++ b/.travis.yml @@ -0,0 +1,59 @@ +sudo: required +language: java + +services: + - docker + +jdk: + - oraclejdk8 + +env: + global: + - DOCKER_CFG=$HOME/.docker + - DOCKER_REPO="utplsqlv3/oracledb" + - CACHE_DIR=$HOME/.cache + - MAVEN_HOME=/usr/local/maven + - MAVEN_CFG=$HOME/.m2 + - DB_URL="127.0.0.1:1521:XE" + - DB_USER=app + - DB_PASS=app + - ORACLE_VERSION="11g-r2-xe" + - DOCKER_OPTIONS="--shm-size=1g" + +cache: + directories: + - $DOCKER_CFG + - $CACHE_DIR + - $MAVEN_CFG + +install: + - bash .travis/maven_cfg.sh + - bash .travis/start_db.sh + - bash .travis/install_utplsql.sh + - bash .travis/install_demo_project.sh + +script: + - mvn package + +#before_deploy: +# - bash .travis/create_release.sh +# - if [ ! -z "$TRAVIS_TAG" ]; then VERSION=$(tr -d "/v/" <<<$TRAVIS_TAG); mvn org.codehaus.mojo:versions-maven-plugin:2.1:set -DnewVersion=${VERSION}; fi +# +#deploy: +# - provider: releases +# api_key: $GITHUB_API_TOKEN +# file: utPLSQL-cli.zip +# skip_cleanup: true +# on: +# repository: utPLSQL/utPLSQL-cli +# tags: true +# - provider: bintray +# file: bintray.json +# user: ${BINTRAY_USER} +# key: ${BINTRAY_API_KEY} +# dry-run: false +# skip_cleanup: true +# on: +# repository: utPLSQL/utPLSQL-cli +# branch: develop +# diff --git a/.travis/create_api_user.sh b/.travis/create_api_user.sh new file mode 100644 index 0000000..c898f15 --- /dev/null +++ b/.travis/create_api_user.sh @@ -0,0 +1,17 @@ +#!/bin/bash +set -ev + +sqlplus -S -L sys/oracle@//127.0.0.1:1521/xe AS SYSDBA < bintray.json < demo_project.sh.tmp < install.sh.tmp < + + + + + + + + maven.oracle.com + ${env.ORACLE_OTN_USER} + ${env.ORACLE_OTN_PASSWORD} + + + ANY + ANY + OAM 11g + + + + + + http.protocol.allow-circular-redirects + %b,true + + + + + + + + + diff --git a/.travis/start_db.sh b/.travis/start_db.sh new file mode 100644 index 0000000..2367d64 --- /dev/null +++ b/.travis/start_db.sh @@ -0,0 +1,14 @@ +#!/bin/bash +set -ev + +# If docker credentials are not cached, do the login. +if [ ! -f $DOCKER_CFG/config.json ]; then + docker login -u "$DOCKER_USER" -p "$DOCKER_PASSWORD" +else + echo "Using docker login from cache..." +fi + +# Pull the specified db version from docker hub. +docker pull $DOCKER_REPO:$ORACLE_VERSION +docker run -d --name $ORACLE_VERSION $DOCKER_OPTIONS -p 1521:1521 $DOCKER_REPO:$ORACLE_VERSION +docker logs -f $ORACLE_VERSION | grep -m 1 "DATABASE IS READY TO USE!" --line-buffered From 69ad19dc14db5335927262199442a9cbce2d5314 Mon Sep 17 00:00:00 2001 From: Jacek Gebal Date: Thu, 17 May 2018 21:23:17 +0100 Subject: [PATCH 21/71] Setting properties for the test run --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c3e80cd..064d2be 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,7 +33,7 @@ install: - bash .travis/install_demo_project.sh script: - - mvn package + - mvn package -ddbUrl="${DB_URL}" -ddbUser="${DB_USER}" -ddbPass="${DB_PASS}" #before_deploy: # - bash .travis/create_release.sh From 54ec57f0167c4032d8f78632416d2043f2b0cb60 Mon Sep 17 00:00:00 2001 From: Jacek Gebal Date: Thu, 17 May 2018 21:38:37 +0100 Subject: [PATCH 22/71] Added slack notifications for Travis --- .travis.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.travis.yml b/.travis.yml index 064d2be..c5207cc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -57,3 +57,10 @@ script: # repository: utPLSQL/utPLSQL-cli # branch: develop # + +notifications: + slack: + rooms: + - secure: "Gz0pGOOM6xbnz8Q/B3RzOFoVr8QGXsDSHcgCloPnO3ZkEOh4JJikqWAVdZrksMxhewIBRpbdIWAZOgsNXvW+cEDXxfml3X9Clj2wg5Uon97UeI+5WEHDhLYHn7t9EYr9QvVSOuQgBIiddk6kURxY4N0eAA4VUti8BDcMRq+gPxF1w/toFJXVR/I/tkLxcHPTbWQ9X87nNWcQgMoHe2AixYpglntmtoLXJ5F8MF08fcyTX7GJQ5xjq7HbYy+/39nEhQo2ZPhHHfk2rS6gIUY0wc+MAqobxvesplgGDybdTQyrdl48VjJ/CiQDedglUbNN9VYTFjPIYMdWCUCLV1uL866aNMiBpB7CQoNhi5WS7RERE9gblVPX2k6tOda27fEWlhjha6OmdK6TQ9qTITU7U4OTSOz41dDPeVfqMHRggxo3ozlLONTiZ1y9fz/Ez9WjiJjtUDt60vgnVIo7BcQV/yDJcqAtQbfWyf0n73g5lMBvLGnO2Agm2N7hNEeCbpr+PZUoqkEM/e4SxdUCQGi8Ppi9Zp0E4v0iG7hyjzol+G4T8JN0bUGg0OOow/bfZa5J2aUsrC1qP/ZLpMA94NI6ZlL2wRHhZ9JtVSDLjtSwq9yW5XF7o7kdqBWBCslbGnYPoCoHOzfZuUvArSlRoGNu75dw/Qhoo9gFl1RG/RlChaU=" + on_success: change + on_failure: always \ No newline at end of file From ee999b8b22a2ff1a5518dea36e5ff3e7da736f77 Mon Sep 17 00:00:00 2001 From: ahernandez Date: Thu, 17 May 2018 22:39:44 +0200 Subject: [PATCH 23/71] Fix of #10, Sonar Coverage Reports --- .../src/main/java/org/utplsql/helper/SQLScannerHelper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utplsql-maven-plugin/src/main/java/org/utplsql/helper/SQLScannerHelper.java b/utplsql-maven-plugin/src/main/java/org/utplsql/helper/SQLScannerHelper.java index 6be7baa..1431e7f 100644 --- a/utplsql-maven-plugin/src/main/java/org/utplsql/helper/SQLScannerHelper.java +++ b/utplsql-maven-plugin/src/main/java/org/utplsql/helper/SQLScannerHelper.java @@ -35,7 +35,7 @@ public static List findSQLs(List resources) { DirectoryScanner scanner = buildScanner(resource); scanner.scan(); for (String basename : scanner.getIncludedFiles()) { - founds.add(new File(scanner.getBasedir(), basename).getAbsolutePath()); + founds.add(new File(scanner.getBasedir(), basename).getPath()); } // Append all scanned objects From f420b07d37d4a6bdf59a1f9d09c068a3c082bbe4 Mon Sep 17 00:00:00 2001 From: Jacek Gebal Date: Thu, 17 May 2018 21:41:39 +0100 Subject: [PATCH 24/71] Fixing mvn params. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c5207cc..e55d95a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,7 +33,7 @@ install: - bash .travis/install_demo_project.sh script: - - mvn package -ddbUrl="${DB_URL}" -ddbUser="${DB_USER}" -ddbPass="${DB_PASS}" + - mvn package "-DdbUrl=${DB_URL}" "-DdbUser=${DB_USER}" "-DdbPass=${DB_PASS}" #before_deploy: # - bash .travis/create_release.sh From 09d5dc7108bad4a73a8de2faa1ff0712e6e47e6b Mon Sep 17 00:00:00 2001 From: Jacek Gebal Date: Thu, 17 May 2018 21:49:38 +0100 Subject: [PATCH 25/71] Fixing mvn params. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e55d95a..b95be96 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,7 +33,7 @@ install: - bash .travis/install_demo_project.sh script: - - mvn package "-DdbUrl=${DB_URL}" "-DdbUser=${DB_USER}" "-DdbPass=${DB_PASS}" + - mvn package -DdbUser="${DB_USER}" -DdbPass="${DB_PASS}" #before_deploy: # - bash .travis/create_release.sh From 861d5329a1b197e280e6c53a8257d7c082b006ff Mon Sep 17 00:00:00 2001 From: ahernandez Date: Thu, 17 May 2018 23:12:07 +0200 Subject: [PATCH 26/71] [#9] Tested on Oracle 11 with framework version of 3.0.4 and 3.1.1 --- utplsql-maven-plugin/src/test/resources/pom.xml | 4 ++-- .../src/test/resources/scripts/test/TEST_PKG_TEST_ME.spc | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/utplsql-maven-plugin/src/test/resources/pom.xml b/utplsql-maven-plugin/src/test/resources/pom.xml index abac3fc..233c067 100644 --- a/utplsql-maven-plugin/src/test/resources/pom.xml +++ b/utplsql-maven-plugin/src/test/resources/pom.xml @@ -32,8 +32,8 @@ false - - :plsql + + ut3 diff --git a/utplsql-maven-plugin/src/test/resources/scripts/test/TEST_PKG_TEST_ME.spc b/utplsql-maven-plugin/src/test/resources/scripts/test/TEST_PKG_TEST_ME.spc index a2b5f6d..aa185f6 100644 --- a/utplsql-maven-plugin/src/test/resources/scripts/test/TEST_PKG_TEST_ME.spc +++ b/utplsql-maven-plugin/src/test/resources/scripts/test/TEST_PKG_TEST_ME.spc @@ -10,7 +10,7 @@ CREATE OR REPLACE PACKAGE TEST_PKG_TEST_ME AS * This two parameters are used by the test framework in * order to identify the test suite to run */ - -- %suite(TEST_PKG_TEST_ME) + -- %suite(plsql) -- %suitepath(plsql.examples) /* From 6068ce0cee2821d78948c2537e0170092b73f364 Mon Sep 17 00:00:00 2001 From: Jacek Gebal Date: Fri, 18 May 2018 16:37:27 +0100 Subject: [PATCH 27/71] Fixing mvn params. --- .travis.yml | 2 +- .travis/install_utplsql.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index b95be96..8c59019 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,7 +33,7 @@ install: - bash .travis/install_demo_project.sh script: - - mvn package -DdbUser="${DB_USER}" -DdbPass="${DB_PASS}" + - mvn package #before_deploy: # - bash .travis/create_release.sh diff --git a/.travis/install_utplsql.sh b/.travis/install_utplsql.sh index 403132a..2f7a0bd 100644 --- a/.travis/install_utplsql.sh +++ b/.travis/install_utplsql.sh @@ -17,7 +17,7 @@ curl -L -O "https://github.com/utPLSQL/utPLSQL/releases/download/$UTPLSQL_VERSIO cat > install.sh.tmp < Date: Fri, 18 May 2018 16:43:23 +0100 Subject: [PATCH 28/71] Fixing tests for issues with 3.0.4 annotations positioning. --- .../src/test/resources/scripts/test/TEST_PKG_TEST_ME.spc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utplsql-maven-plugin/src/test/resources/scripts/test/TEST_PKG_TEST_ME.spc b/utplsql-maven-plugin/src/test/resources/scripts/test/TEST_PKG_TEST_ME.spc index a2b5f6d..86ae400 100644 --- a/utplsql-maven-plugin/src/test/resources/scripts/test/TEST_PKG_TEST_ME.spc +++ b/utplsql-maven-plugin/src/test/resources/scripts/test/TEST_PKG_TEST_ME.spc @@ -1,4 +1,6 @@ CREATE OR REPLACE PACKAGE TEST_PKG_TEST_ME AS + -- %suite(TEST_PKG_TEST_ME) + -- %suitepath(plsql.examples) -- -- This package shows all the possibilities to unit test -- your PL/SQL package. NOTE that it is not limited to @@ -10,8 +12,6 @@ CREATE OR REPLACE PACKAGE TEST_PKG_TEST_ME AS * This two parameters are used by the test framework in * order to identify the test suite to run */ - -- %suite(TEST_PKG_TEST_ME) - -- %suitepath(plsql.examples) /* * This method is invoked once before any other method. From a4a4bb5c24a548cdc0eff9faa224897708a0280b Mon Sep 17 00:00:00 2001 From: Jacek Gebal Date: Fri, 18 May 2018 16:58:40 +0100 Subject: [PATCH 29/71] Moved to utPLSQL 3.1.1 --- .travis/install_utplsql.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis/install_utplsql.sh b/.travis/install_utplsql.sh index 2f7a0bd..79074d0 100644 --- a/.travis/install_utplsql.sh +++ b/.travis/install_utplsql.sh @@ -3,7 +3,7 @@ set -ev cd $(dirname $(readlink -f $0)) # Download the specified version of utPLSQL. -UTPLSQL_VERSION="v3.0.4" +UTPLSQL_VERSION="v3.1.1" UTPLSQL_FILE="utPLSQL" curl -L -O "https://github.com/utPLSQL/utPLSQL/releases/download/$UTPLSQL_VERSION/$UTPLSQL_FILE.tar.gz" From 8e387cc69c467aa641a2bf2976ef3b0075e8ffad Mon Sep 17 00:00:00 2001 From: Jacek Gebal Date: Fri, 18 May 2018 18:09:30 +0100 Subject: [PATCH 30/71] Refactored Travis build to use local project test resources --- .travis/install_demo_project.sh | 29 ++++++------------- .../src/test/resources/pom.xml | 4 +-- 2 files changed, 11 insertions(+), 22 deletions(-) diff --git a/.travis/install_demo_project.sh b/.travis/install_demo_project.sh index adb9566..9cd079b 100644 --- a/.travis/install_demo_project.sh +++ b/.travis/install_demo_project.sh @@ -1,9 +1,8 @@ #!/bin/bash set -ev -cd $(dirname $(readlink -f $0)) -PROJECT_FILE="utPLSQL-demo-project" -git clone -b develop --single-branch https://github.com/utPLSQL/utPLSQL-demo-project.git +PROJECT_FILES_SRC="utplsql-maven-plugin/src/test/resources" +PROJECT_FILES="resources" cat > demo_project.sh.tmp < jdbc:oracle:thin:@127.0.0.1:1521:xe - ut3 - XNtxj8eEgA6X6b6f + app + app From 600c61ccf7da452633ab98bdb8585aec368a30a4 Mon Sep 17 00:00:00 2001 From: Jacek Gebal Date: Fri, 18 May 2018 18:33:52 +0100 Subject: [PATCH 31/71] Fixed include filters in tests --- utplsql-maven-plugin/src/test/resources/pom.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/utplsql-maven-plugin/src/test/resources/pom.xml b/utplsql-maven-plugin/src/test/resources/pom.xml index 475190b..40cebfb 100644 --- a/utplsql-maven-plugin/src/test/resources/pom.xml +++ b/utplsql-maven-plugin/src/test/resources/pom.xml @@ -53,8 +53,8 @@ src/test/resources/scripts/sources - **/*pkg - **/*pkb + **/*bdy + **/*spc @@ -63,8 +63,8 @@ src/test/resources/scripts/test - **/*pkg - **/*pkb + **/*bdy + **/*spc From da9e28ae89ce2ff8bc4643aff03fcbee748f00b0 Mon Sep 17 00:00:00 2001 From: ahernandez Date: Sun, 20 May 2018 19:08:42 +0200 Subject: [PATCH 32/71] Refactor code to package org.utplsql.maven.plugin Fix for #6, in order to pass the DB credentials from command line --- .../{ => maven/plugin}/UtPLSQLMojo.java | 63 ++++++++++++------- .../plugin}/helper/PluginDefault.java | 2 +- .../plugin}/helper/ReporterDefault.java | 2 +- .../plugin}/helper/SQLScannerHelper.java | 2 +- .../plugin}/model/ReporterParameter.java | 2 +- .../plugin}/reporter/ReporterWriter.java | 4 +- .../plugin}/test/UtPLSQLMojoTest.java | 4 +- .../src/test/resources/pom.xml | 7 ++- .../scripts/test/TEST_PKG_TEST_ME.spc | 4 +- 9 files changed, 57 insertions(+), 33 deletions(-) rename utplsql-maven-plugin/src/main/java/org/utplsql/{ => maven/plugin}/UtPLSQLMojo.java (82%) rename utplsql-maven-plugin/src/main/java/org/utplsql/{ => maven/plugin}/helper/PluginDefault.java (93%) rename utplsql-maven-plugin/src/main/java/org/utplsql/{ => maven/plugin}/helper/ReporterDefault.java (93%) rename utplsql-maven-plugin/src/main/java/org/utplsql/{ => maven/plugin}/helper/SQLScannerHelper.java (94%) rename utplsql-maven-plugin/src/main/java/org/utplsql/{ => maven/plugin}/model/ReporterParameter.java (90%) rename utplsql-maven-plugin/src/main/java/org/utplsql/{ => maven/plugin}/reporter/ReporterWriter.java (93%) rename utplsql-maven-plugin/src/test/java/org/utpsql/{ => maven/plugin}/test/UtPLSQLMojoTest.java (92%) diff --git a/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java b/utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/UtPLSQLMojo.java similarity index 82% rename from utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java rename to utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/UtPLSQLMojo.java index 8145811..9e408ba 100644 --- a/utplsql-maven-plugin/src/main/java/org/utplsql/UtPLSQLMojo.java +++ b/utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/UtPLSQLMojo.java @@ -1,4 +1,4 @@ -package org.utplsql; +package org.utplsql.maven.plugin; import static java.lang.String.format; @@ -23,10 +23,10 @@ import org.utplsql.api.exception.SomeTestsFailedException; import org.utplsql.api.reporter.Reporter; import org.utplsql.api.reporter.ReporterFactory; -import org.utplsql.helper.PluginDefault; -import org.utplsql.helper.SQLScannerHelper; -import org.utplsql.model.ReporterParameter; -import org.utplsql.reporter.ReporterWriter; +import org.utplsql.maven.plugin.helper.PluginDefault; +import org.utplsql.maven.plugin.helper.SQLScannerHelper; +import org.utplsql.maven.plugin.model.ReporterParameter; +import org.utplsql.maven.plugin.reporter.ReporterWriter; /** * This class expose the {@link TestRunner} interface to Maven. @@ -37,41 +37,42 @@ @Mojo(name = "test", defaultPhase = LifecyclePhase.TEST) public class UtPLSQLMojo extends AbstractMojo { - @Parameter(defaultValue = "${dbUrl}") - private String url; + @Parameter(property = "dbUrl") + protected String url; - @Parameter(defaultValue = "${dbUser}") - private String user; + @Parameter(property = "dbUser") + protected String user; - @Parameter(defaultValue = "${dbPass}") - private String password; + @Parameter(property = "dbPass") + protected String password; @Parameter - private String includeObject; + protected String includeObject; @Parameter - private String excludeObject; + protected String excludeObject; @Parameter(defaultValue = "false") - private boolean skipCompatibilityCheck; + protected boolean skipCompatibilityCheck; @Parameter - private List reporters; + protected List reporters; @Parameter(defaultValue = "") - private List paths; + protected List paths; @Parameter - private List sources = new ArrayList<>(); + protected List sources = new ArrayList<>(); @Parameter - private List tests = new ArrayList<>(); + protected List tests = new ArrayList<>(); @Parameter(defaultValue = "${project.build.directory}", readonly = true) - private String targetDir; + protected String targetDir; @Parameter(defaultValue = "${maven.test.failure.ignore}") - private boolean ignoreFailure; + protected boolean ignoreFailure; + // Color in the console, loaded by environment variables private boolean colorConsole = PluginDefault.resolveColor(); @@ -87,6 +88,8 @@ public class UtPLSQLMojo extends AbstractMojo @Override public void execute() throws MojoExecutionException { + loadDefaultCredentials(); + Connection connection = null; try { @@ -137,7 +140,8 @@ public void execute() throws MojoExecutionException try { // Write Reporters - reporterWriter.writeReporters(connection); + if (connection != null) + reporterWriter.writeReporters(connection); } catch (Exception e) { @@ -145,6 +149,23 @@ public void execute() throws MojoExecutionException } } } + + /** + * Load + * + */ + private void loadDefaultCredentials () + { + if (StringUtils.isEmpty(user)) + { + user = System.getProperty("dbUser"); + } + + if (StringUtils.isEmpty(password)) + { + password = System.getProperty("dbPass"); + } + } /** * diff --git a/utplsql-maven-plugin/src/main/java/org/utplsql/helper/PluginDefault.java b/utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/helper/PluginDefault.java similarity index 93% rename from utplsql-maven-plugin/src/main/java/org/utplsql/helper/PluginDefault.java rename to utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/helper/PluginDefault.java index 252e80c..0969ab8 100644 --- a/utplsql-maven-plugin/src/main/java/org/utplsql/helper/PluginDefault.java +++ b/utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/helper/PluginDefault.java @@ -1,4 +1,4 @@ -package org.utplsql.helper; +package org.utplsql.maven.plugin.helper; import java.util.Arrays; import java.util.Map; diff --git a/utplsql-maven-plugin/src/main/java/org/utplsql/helper/ReporterDefault.java b/utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/helper/ReporterDefault.java similarity index 93% rename from utplsql-maven-plugin/src/main/java/org/utplsql/helper/ReporterDefault.java rename to utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/helper/ReporterDefault.java index 3fe204d..840beac 100644 --- a/utplsql-maven-plugin/src/main/java/org/utplsql/helper/ReporterDefault.java +++ b/utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/helper/ReporterDefault.java @@ -1,4 +1,4 @@ -package org.utplsql.helper; +package org.utplsql.maven.plugin.helper; import org.utplsql.api.reporter.Reporter; diff --git a/utplsql-maven-plugin/src/main/java/org/utplsql/helper/SQLScannerHelper.java b/utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/helper/SQLScannerHelper.java similarity index 94% rename from utplsql-maven-plugin/src/main/java/org/utplsql/helper/SQLScannerHelper.java rename to utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/helper/SQLScannerHelper.java index 1431e7f..3026ff1 100644 --- a/utplsql-maven-plugin/src/main/java/org/utplsql/helper/SQLScannerHelper.java +++ b/utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/helper/SQLScannerHelper.java @@ -1,4 +1,4 @@ -package org.utplsql.helper; +package org.utplsql.maven.plugin.helper; import static java.lang.String.format; diff --git a/utplsql-maven-plugin/src/main/java/org/utplsql/model/ReporterParameter.java b/utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/model/ReporterParameter.java similarity index 90% rename from utplsql-maven-plugin/src/main/java/org/utplsql/model/ReporterParameter.java rename to utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/model/ReporterParameter.java index 56ebc60..979d7cc 100644 --- a/utplsql-maven-plugin/src/main/java/org/utplsql/model/ReporterParameter.java +++ b/utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/model/ReporterParameter.java @@ -1,4 +1,4 @@ -package org.utplsql.model; +package org.utplsql.maven.plugin.model; import org.codehaus.plexus.util.StringUtils; diff --git a/utplsql-maven-plugin/src/main/java/org/utplsql/reporter/ReporterWriter.java b/utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/reporter/ReporterWriter.java similarity index 93% rename from utplsql-maven-plugin/src/main/java/org/utplsql/reporter/ReporterWriter.java rename to utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/reporter/ReporterWriter.java index 6d5a65f..a9732db 100644 --- a/utplsql-maven-plugin/src/main/java/org/utplsql/reporter/ReporterWriter.java +++ b/utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/reporter/ReporterWriter.java @@ -1,4 +1,4 @@ -package org.utplsql.reporter; +package org.utplsql.maven.plugin.reporter; import static java.lang.String.format; @@ -18,7 +18,7 @@ import org.utplsql.api.outputBuffer.OutputBuffer; import org.utplsql.api.outputBuffer.OutputBufferProvider; import org.utplsql.api.reporter.Reporter; -import org.utplsql.model.ReporterParameter; +import org.utplsql.maven.plugin.model.ReporterParameter; public class ReporterWriter { diff --git a/utplsql-maven-plugin/src/test/java/org/utpsql/test/UtPLSQLMojoTest.java b/utplsql-maven-plugin/src/test/java/org/utpsql/maven/plugin/test/UtPLSQLMojoTest.java similarity index 92% rename from utplsql-maven-plugin/src/test/java/org/utpsql/test/UtPLSQLMojoTest.java rename to utplsql-maven-plugin/src/test/java/org/utpsql/maven/plugin/test/UtPLSQLMojoTest.java index dc891a2..796575d 100644 --- a/utplsql-maven-plugin/src/test/java/org/utpsql/test/UtPLSQLMojoTest.java +++ b/utplsql-maven-plugin/src/test/java/org/utpsql/maven/plugin/test/UtPLSQLMojoTest.java @@ -1,4 +1,4 @@ -package org.utpsql.test; +package org.utpsql.maven.plugin.test; import java.io.File; @@ -6,7 +6,7 @@ import org.junit.Assert; import org.junit.Rule; import org.junit.Test; -import org.utplsql.UtPLSQLMojo; +import org.utplsql.maven.plugin.UtPLSQLMojo; public class UtPLSQLMojoTest { diff --git a/utplsql-maven-plugin/src/test/resources/pom.xml b/utplsql-maven-plugin/src/test/resources/pom.xml index 233c067..e0bca3d 100644 --- a/utplsql-maven-plugin/src/test/resources/pom.xml +++ b/utplsql-maven-plugin/src/test/resources/pom.xml @@ -12,9 +12,12 @@ jdbc:oracle:thin:@127.0.0.1:1521:xe - ut3 + + + ../../../target/test-classes diff --git a/utplsql-maven-plugin/src/test/resources/scripts/test/TEST_PKG_TEST_ME.spc b/utplsql-maven-plugin/src/test/resources/scripts/test/TEST_PKG_TEST_ME.spc index aa185f6..86ae400 100644 --- a/utplsql-maven-plugin/src/test/resources/scripts/test/TEST_PKG_TEST_ME.spc +++ b/utplsql-maven-plugin/src/test/resources/scripts/test/TEST_PKG_TEST_ME.spc @@ -1,4 +1,6 @@ CREATE OR REPLACE PACKAGE TEST_PKG_TEST_ME AS + -- %suite(TEST_PKG_TEST_ME) + -- %suitepath(plsql.examples) -- -- This package shows all the possibilities to unit test -- your PL/SQL package. NOTE that it is not limited to @@ -10,8 +12,6 @@ CREATE OR REPLACE PACKAGE TEST_PKG_TEST_ME AS * This two parameters are used by the test framework in * order to identify the test suite to run */ - -- %suite(plsql) - -- %suitepath(plsql.examples) /* * This method is invoked once before any other method. From a3a18339dee14b5e3b18c0de3043d94183ae7e68 Mon Sep 17 00:00:00 2001 From: ahernandez Date: Sun, 20 May 2018 19:28:33 +0200 Subject: [PATCH 33/71] Comment Fixed DB Credentials --- utplsql-maven-plugin/src/test/resources/pom.xml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/utplsql-maven-plugin/src/test/resources/pom.xml b/utplsql-maven-plugin/src/test/resources/pom.xml index 4553b18..c48a759 100644 --- a/utplsql-maven-plugin/src/test/resources/pom.xml +++ b/utplsql-maven-plugin/src/test/resources/pom.xml @@ -12,11 +12,10 @@ jdbc:oracle:thin:@127.0.0.1:1521:xe - + From 2a65efff75b5e62374db8a74f47bc0d68cde579b Mon Sep 17 00:00:00 2001 From: ahernandez Date: Sun, 20 May 2018 20:01:48 +0200 Subject: [PATCH 34/71] Implementation of #12 --- .../org/utplsql/maven/plugin/UtPLSQLMojo.java | 120 ++++++++++++++++-- 1 file changed, 112 insertions(+), 8 deletions(-) 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 9e408ba..f55d198 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 @@ -61,17 +61,49 @@ public class UtPLSQLMojo extends AbstractMojo @Parameter(defaultValue = "") protected List paths; + // Sources Configuration @Parameter protected List sources = new ArrayList<>(); + + @Parameter + private String sourcesRegexExpression; + + @Parameter + private Integer sourcesOwnerSubexpression; + + @Parameter + private Integer sourcesNameSubexpression; + + @Parameter + private Integer sourcesTypeSubexpression; + + // Tests Configuration + @Parameter protected List tests = new ArrayList<>(); + + @Parameter + private String testsRegexExpression; + + @Parameter + private Integer testsOwnerSubexpression; + + @Parameter + private Integer testsNameSubexpression; + + @Parameter + private Integer testsTypeSubexpression; + @Parameter(defaultValue = "${project.build.directory}", readonly = true) protected String targetDir; @Parameter(defaultValue = "${maven.test.failure.ignore}") protected boolean ignoreFailure; + + + // Color in the console, loaded by environment variables @@ -93,8 +125,8 @@ public void execute() throws MojoExecutionException Connection connection = null; try { - FileMapperOptions sourceMappingOptions = buildOptions(sources, PluginDefault.buildDefaultSource(), "sources"); - FileMapperOptions testMappingOptions = buildOptions(tests, PluginDefault.buildDefaultTest(), "test"); + FileMapperOptions sourceMappingOptions = buildSourcesOptions(); + FileMapperOptions testMappingOptions = buildTestsOptions(); // Create the Connection to the Database connection = DriverManager.getConnection(url, user, password); @@ -173,26 +205,98 @@ private void loadDefaultCredentials () * @return * @throws MojoExecutionException */ - private FileMapperOptions buildOptions(List resources, Resource defaultResource, String msg) throws MojoExecutionException + private FileMapperOptions buildSourcesOptions() throws MojoExecutionException { try { // Check if this element is empty - if (resources.isEmpty()) + if (sources.isEmpty()) { - resources.add(defaultResource); + sources.add(PluginDefault.buildDefaultSource()); } - List scripts = SQLScannerHelper.findSQLs(resources); - return new FileMapperOptions(scripts); + List scripts = SQLScannerHelper.findSQLs(sources); + FileMapperOptions fileMapperOptions = new FileMapperOptions(scripts); + + 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); + } + + return fileMapperOptions; } catch (Exception e) { - throw new MojoExecutionException(format("Invalid <%s> in your pom.xml: %s", msg, e.getMessage())); + throw new MojoExecutionException("Invalid in your pom.xml: " + e.getMessage()); } + } + + + /** + * + * @param resources + * @return + * @throws MojoExecutionException + */ + private FileMapperOptions buildTestsOptions() throws MojoExecutionException + { + try + { + // Check if this element is empty + if (tests.isEmpty()) + { + tests.add(PluginDefault.buildDefaultTest()); + } + List scripts = SQLScannerHelper.findSQLs(tests); + FileMapperOptions fileMapperOptions = new FileMapperOptions(scripts); + + 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); + } + + return fileMapperOptions; + + } + catch (Exception e) + { + throw new MojoExecutionException("Invalid in your pom.xml: " + e.getMessage()); + } + + } /** * Init all the reporters * From 774b2650e8930342b56b047141dfcb0a30e83461 Mon Sep 17 00:00:00 2001 From: ahernandez Date: Sun, 20 May 2018 20:10:44 +0200 Subject: [PATCH 35/71] Update documentation Added parameters to #12 --- README.md | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 4c62921..1889eda 100644 --- a/README.md +++ b/README.md @@ -11,15 +11,12 @@ You have to be a fully utPLSQL environment available compatible with the Java AP ### Plugin Parameters -* `url` +* `dbUrl` * URL of the Connection to the database - * Default: `${dbURL}` -* `user` +* `dbUser` * Credential of the connection to the database - * Default: `${dbUser}` -* `password` +* `dbPass` * Password of the connection to the database - * Default: `${dbPass}` * `ignoreFailure` * Ignore or continue when a test fail * Default: `${maven.test.failure.ignore}` @@ -34,10 +31,25 @@ You have to be a fully utPLSQL environment available compatible with the Java AP * `paths` * Paths of the resources -* `sources` - * Sources of the scripts at the style of the maven resources +* `sourcesRegexExpression` + * +* `sourcesOwnerSubexpression` + * +* `sourcesNameSubexpression` + * +* `sourcesTypeSubexpression` + * + * `tests` * Test fo the scripts at the style of the maven resources +* `testsRegexExpression` + * +* `testsOwnerSubexpression` + * +* `testsNameSubexpression` + * +* `testsTypeSubexpression` + * `targetDir` * Target dir, this is a readonly property * Default: `${project.build.directory}` @@ -59,9 +71,9 @@ The next snippet is a sample of declaration of the pom test - url_of_connection - user - password + url_of_connection + user + password 3.1.0 false From 2d5850616c49556541c0b55688258be237843805 Mon Sep 17 00:00:00 2001 From: Jerome Garec Date: Wed, 23 May 2018 14:28:07 +0200 Subject: [PATCH 36/71] Refactor test project * Move test project to a dedicated location * Fix generated coverage, and check file paths for #11 * Checks output file content (duration should be set to 1) --- .../maven/plugin/test/UtPLSQLMojoTest.java | 29 ++++++++++++++----- .../utplsql/coverage-sonar-reporter.xml | 12 ++++++++ .../utplsql/sonar-test-reporter.xml | 18 ++++++++++++ .../resources/{ => simple-project}/pom.xml | 10 +++---- .../scripts/sources/APP.PKG_TEST_ME.bdy} | 0 .../scripts/sources/APP.PKG_TEST_ME.spc} | 0 .../scripts/sources/TO_TEST_ME.tab | 0 .../scripts/tests/APP.TEST_PKG_TEST_ME.bdy} | 0 .../scripts/tests/APP.TEST_PKG_TEST_ME.spc} | 0 9 files changed, 55 insertions(+), 14 deletions(-) create mode 100644 utplsql-maven-plugin/src/test/resources/simple-project/expected-output/utplsql/coverage-sonar-reporter.xml create mode 100644 utplsql-maven-plugin/src/test/resources/simple-project/expected-output/utplsql/sonar-test-reporter.xml rename utplsql-maven-plugin/src/test/resources/{ => simple-project}/pom.xml (87%) rename utplsql-maven-plugin/src/test/resources/{scripts/sources/PKG_TEST_ME.bdy => simple-project/scripts/sources/APP.PKG_TEST_ME.bdy} (100%) rename utplsql-maven-plugin/src/test/resources/{scripts/sources/PKG_TEST_ME.spc => simple-project/scripts/sources/APP.PKG_TEST_ME.spc} (100%) rename utplsql-maven-plugin/src/test/resources/{ => simple-project}/scripts/sources/TO_TEST_ME.tab (100%) rename utplsql-maven-plugin/src/test/resources/{scripts/test/TEST_PKG_TEST_ME.bdy => simple-project/scripts/tests/APP.TEST_PKG_TEST_ME.bdy} (100%) rename utplsql-maven-plugin/src/test/resources/{scripts/test/TEST_PKG_TEST_ME.spc => simple-project/scripts/tests/APP.TEST_PKG_TEST_ME.spc} (100%) diff --git a/utplsql-maven-plugin/src/test/java/org/utpsql/maven/plugin/test/UtPLSQLMojoTest.java b/utplsql-maven-plugin/src/test/java/org/utpsql/maven/plugin/test/UtPLSQLMojoTest.java index 796575d..66da391 100644 --- a/utplsql-maven-plugin/src/test/java/org/utpsql/maven/plugin/test/UtPLSQLMojoTest.java +++ b/utplsql-maven-plugin/src/test/java/org/utpsql/maven/plugin/test/UtPLSQLMojoTest.java @@ -1,7 +1,9 @@ package org.utpsql.maven.plugin.test; import java.io.File; +import java.io.IOException; +import org.apache.commons.io.FileUtils; import org.apache.maven.plugin.testing.MojoRule; import org.junit.Assert; import org.junit.Rule; @@ -10,9 +12,7 @@ public class UtPLSQLMojoTest { - public static final String POM_PATH = "src/test/resources/"; - - public static final String OUTPUT_DIRECTORY = "target/test-classes"; + public static final String TARGET_DIRECTORY = "target/test-classes"; @Rule public MojoRule rule = new MojoRule(); @@ -23,12 +23,13 @@ public void testDefinition() throws Exception try { - UtPLSQLMojo myMojo = (UtPLSQLMojo) rule.lookupConfiguredMojo(new File(POM_PATH), "test"); + final String PROJECT_NAME = "simple-project"; + UtPLSQLMojo myMojo = (UtPLSQLMojo) rule.lookupConfiguredMojo(new File(TARGET_DIRECTORY+"/"+PROJECT_NAME), "test"); Assert.assertNotNull(myMojo); myMojo.execute(); - checkCoverReportsGenerated("utplsql/coverage-sonar-reporter.xml", "utplsql/sonar-test-reporter.xml"); + checkCoverReportsGenerated(PROJECT_NAME,"utplsql/coverage-sonar-reporter.xml", "utplsql/sonar-test-reporter.xml"); } catch (Exception e) { @@ -41,12 +42,24 @@ public void testDefinition() throws Exception * * @param files */ - private void checkCoverReportsGenerated(String... files) + private void checkCoverReportsGenerated(String projectName, String... files) { for (String filename : files) { - File file = new File(OUTPUT_DIRECTORY, filename); - Assert.assertTrue("The reporter for " + filename + " was not generated", file.exists()); + File outputFile = new File(TARGET_DIRECTORY+"/"+projectName+"/target/", filename); + File expectedOutputFile = new File(TARGET_DIRECTORY+"/"+projectName+"/expected-output/", filename); + + Assert.assertTrue("The reporter for " + filename + " was not generated", outputFile.exists()); + try { + // Duration is set to 1 before comparing contents. + Assert.assertEquals("The files differ!", + FileUtils.readFileToString(outputFile, "utf-8").replaceAll("(duration=\"[0-9\\.]*\")", "duration=\"1\""), + FileUtils.readFileToString(expectedOutputFile, "utf-8")); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + Assert.fail("Unexpected Exception running the test of Definition"); + } } } diff --git a/utplsql-maven-plugin/src/test/resources/simple-project/expected-output/utplsql/coverage-sonar-reporter.xml b/utplsql-maven-plugin/src/test/resources/simple-project/expected-output/utplsql/coverage-sonar-reporter.xml new file mode 100644 index 0000000..804f11c --- /dev/null +++ b/utplsql-maven-plugin/src/test/resources/simple-project/expected-output/utplsql/coverage-sonar-reporter.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/utplsql-maven-plugin/src/test/resources/simple-project/expected-output/utplsql/sonar-test-reporter.xml b/utplsql-maven-plugin/src/test/resources/simple-project/expected-output/utplsql/sonar-test-reporter.xml new file mode 100644 index 0000000..baa2643 --- /dev/null +++ b/utplsql-maven-plugin/src/test/resources/simple-project/expected-output/utplsql/sonar-test-reporter.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/utplsql-maven-plugin/src/test/resources/pom.xml b/utplsql-maven-plugin/src/test/resources/simple-project/pom.xml similarity index 87% rename from utplsql-maven-plugin/src/test/resources/pom.xml rename to utplsql-maven-plugin/src/test/resources/simple-project/pom.xml index c48a759..3cbd422 100644 --- a/utplsql-maven-plugin/src/test/resources/pom.xml +++ b/utplsql-maven-plugin/src/test/resources/simple-project/pom.xml @@ -11,7 +11,7 @@ - jdbc:oracle:thin:@127.0.0.1:1521:xe + jdbc:oracle:thin:@127.0.0.1:1521:xe + + + + + + + ${pom.groupId} + utplsql-maven-plugin + ${pom.version} + + test + + + + + false + + + app + + + + + UT_COVERAGE_SONAR_REPORTER + utplsql/coverage-sonar-reporter.xml + true + + + UT_SONAR_TEST_REPORTER + utplsql/sonar-test-reporter.xml + true + + + + + + src/test/resources/regex-project/scripts/sources + + **/*bdy + **/*spc + + + + .*(\\|\/)(\w+)(\\|\/)(\w+)(\\|\/)(\w+).(\w{3}) + 2 + 6 + 7 + + + + src/test/resources/regex-project/scripts/test + + **/*bdy + **/*spc + + + + .*(\\|\/)(\w+)(\\|\/)(\w+)(\\|\/)(\w+).(\w{3}) + 2 + 6 + 7 + + + + + + \ No newline at end of file diff --git a/utplsql-maven-plugin/src/test/resources/regex-project/scripts/sources/app/packages/PKG_TEST_ME.bdy b/utplsql-maven-plugin/src/test/resources/regex-project/scripts/sources/app/packages/PKG_TEST_ME.bdy new file mode 100644 index 0000000..29cea5e --- /dev/null +++ b/utplsql-maven-plugin/src/test/resources/regex-project/scripts/sources/app/packages/PKG_TEST_ME.bdy @@ -0,0 +1,28 @@ +CREATE OR REPLACE PACKAGE BODY APP.PKG_TEST_ME IS + + -- + -- This + -- + FUNCTION FC_TEST_ME(PPARAM1 IN VARCHAR2) RETURN NUMBER IS + BEGIN + IF PPARAM1 IS NULL THEN + RETURN NULL; + ELSIF PPARAM1 = '1' THEN + RETURN 1; + ELSE + RETURN 0; + END IF; + END FC_TEST_ME; + + PROCEDURE PR_TEST_ME(PSNAME IN VARCHAR2) IS + BEGIN + IF PSNAME IS NULL THEN + NULL; + ELSE + INSERT INTO TO_TEST_ME (SNAME) VALUES (PSNAME); + COMMIT; + END IF; + END PR_TEST_ME; + +END PKG_TEST_ME; +/ \ No newline at end of file diff --git a/utplsql-maven-plugin/src/test/resources/regex-project/scripts/sources/app/packages/PKG_TEST_ME.spc b/utplsql-maven-plugin/src/test/resources/regex-project/scripts/sources/app/packages/PKG_TEST_ME.spc new file mode 100644 index 0000000..e23c420 --- /dev/null +++ b/utplsql-maven-plugin/src/test/resources/regex-project/scripts/sources/app/packages/PKG_TEST_ME.spc @@ -0,0 +1,8 @@ +-- +-- This package is used TO demonstrate the utPL/SQL possibilities +-- +CREATE OR REPLACE PACKAGE app.PKG_TEST_ME AS + FUNCTION FC_TEST_ME(PPARAM1 IN VARCHAR2) RETURN NUMBER; + PROCEDURE PR_TEST_ME(PSNAME IN VARCHAR2); +END PKG_TEST_ME; +/ \ No newline at end of file diff --git a/utplsql-maven-plugin/src/test/resources/regex-project/scripts/sources/app/tables/TO_TEST_ME.tab b/utplsql-maven-plugin/src/test/resources/regex-project/scripts/sources/app/tables/TO_TEST_ME.tab new file mode 100644 index 0000000..b2e90d9 --- /dev/null +++ b/utplsql-maven-plugin/src/test/resources/regex-project/scripts/sources/app/tables/TO_TEST_ME.tab @@ -0,0 +1,8 @@ +-- +-- This is a table used to demonstrate the UNIT test framework. +-- +CREATE TABLE TO_TEST_ME +( + SNAME VARCHAR2(10) +) +/ diff --git a/utplsql-maven-plugin/src/test/resources/regex-project/scripts/test/app/packages/TEST_PKG_TEST_ME.bdy b/utplsql-maven-plugin/src/test/resources/regex-project/scripts/test/app/packages/TEST_PKG_TEST_ME.bdy new file mode 100644 index 0000000..32d6b35 --- /dev/null +++ b/utplsql-maven-plugin/src/test/resources/regex-project/scripts/test/app/packages/TEST_PKG_TEST_ME.bdy @@ -0,0 +1,126 @@ +CREATE OR REPLACE PACKAGE BODY app.TEST_PKG_TEST_ME AS + + --------------------------------------------------------------------------- + PROCEDURE SETUP_GLOBAL IS + BEGIN + -- Put here the code which is valid for all tests and that should be + -- executed once. + NULL; + END SETUP_GLOBAL; + + --------------------------------------------------------------------------- + PROCEDURE TEARDOWN_GLOBAL IS + BEGIN + -- Put here the code that should be called only once after all the test + -- have executed + NULL; + END TEARDOWN_GLOBAL; + + --------------------------------------------------------------------------- + PROCEDURE SETUP_TEST IS + BEGIN + -- Nothing to clean up globally + NULL; + END SETUP_TEST; + + PROCEDURE TEARDOWN_TEST IS + BEGIN + -- Nothing to clean up globally + NULL; + END TEARDOWN_TEST; + + PROCEDURE TEST_FC_INPUT_1 IS + BEGIN + -- Ok this is a real test where I check that the function return 1 + -- when called with a '1' parameter + UT.EXPECT(PKG_TEST_ME.FC_TEST_ME('1')).TO_EQUAL(1); + END; + + PROCEDURE SETUP_TEST_FC_INPUT_1 IS + BEGIN + -- Nothing to be done really + NULL; + END; + + PROCEDURE TEARDOWN_TEST_FC_INPUT_1 IS + BEGIN + -- Nothing to be done really + NULL; + END; + + PROCEDURE TEST_FC_INPUT_0 IS + BEGIN + -- Ok this is a real test where I check that the function return 0 + -- when called with a '0' parameter + UT.EXPECT(PKG_TEST_ME.FC_TEST_ME('0')).TO_EQUAL(0); + END; + + PROCEDURE TEST_FC_INPUT_NULL IS + BEGIN + -- Ok I check that the function return NULL + -- when called with a NULL parameter + UT.EXPECT(PKG_TEST_ME.FC_TEST_ME(NULL)).TO_BE_NULL; + END TEST_FC_INPUT_NULL; + + PROCEDURE TEST_PR_TEST_ME_NULL IS + VNCOUNT1 PLS_INTEGER; + VNCOUNT2 PLS_INTEGER; + BEGIN + -- In this example I check that the procedure does + -- not insert anything when passing it a NULL parameter + SELECT COUNT(1) INTO VNCOUNT1 FROM TO_TEST_ME; + PKG_TEST_ME.PR_TEST_ME(NULL); + SELECT COUNT(1) INTO VNCOUNT2 FROM TO_TEST_ME; + UT.EXPECT(VNCOUNT1).TO_EQUAL(VNCOUNT2); + END; + + PROCEDURE TEST_PR_TEST_ME_NOT_NULL IS + VNCOUNT1 PLS_INTEGER; + VNCOUNT2 PLS_INTEGER; + VSNAME TO_TEST_ME.SNAME%TYPE; + BEGIN + -- In this test I will check that I do insert a value + -- when the parameter is not null. I futher check that + -- the procedure has inserted the value I specified. + SELECT COUNT(1) INTO VNCOUNT1 FROM TO_TEST_ME; + VSNAME := TO_CHAR(VNCOUNT1); + PKG_TEST_ME.PR_TEST_ME(VSNAME); + SELECT COUNT(1) INTO VNCOUNT2 FROM TO_TEST_ME; + + -- Check that I have inserted the value + UT.EXPECT(VNCOUNT1 + 1).TO_EQUAL(VNCOUNT2); + SELECT COUNT(1) INTO VNCOUNT2 FROM TO_TEST_ME T WHERE T.SNAME = VSNAME; + + -- Check that I inserted the one I said I would insert + UT.EXPECT(VNCOUNT2).TO_EQUAL(1); + DELETE FROM TO_TEST_ME T WHERE T.SNAME = VSNAME; + COMMIT; + END; + + PROCEDURE TEST_PR_TEST_ME_EXISTS IS + BEGIN + -- In case the value exists the procedure should fail with an exception. + BEGIN + PKG_TEST_ME.PR_TEST_ME('EXISTS'); + PKG_TEST_ME.PR_TEST_ME('EXISTS'); + EXCEPTION + WHEN OTHERS THEN + UT.FAIL('Unexpected exception raised'); + END; + END; + + PROCEDURE TEST_PR_TEST_ME_CURSOR IS + TYPE REF_CURSOR IS REF CURSOR; + VEXPECTED REF_CURSOR; + VACTUAL REF_CURSOR; + BEGIN + EXECUTE IMMEDIATE 'TRUNCATE TABLE TO_TEST_ME'; + OPEN VEXPECTED FOR + SELECT T.SNAME FROM TO_TEST_ME T; + OPEN VACTUAL FOR + SELECT T.SNAME FROM TO_TEST_ME T; + UT.EXPECT(VEXPECTED).TO_(EQUAL(VACTUAL)); + END; + +END; +/ diff --git a/utplsql-maven-plugin/src/test/resources/regex-project/scripts/test/app/packages/TEST_PKG_TEST_ME.spc b/utplsql-maven-plugin/src/test/resources/regex-project/scripts/test/app/packages/TEST_PKG_TEST_ME.spc new file mode 100644 index 0000000..f22deac --- /dev/null +++ b/utplsql-maven-plugin/src/test/resources/regex-project/scripts/test/app/packages/TEST_PKG_TEST_ME.spc @@ -0,0 +1,86 @@ +CREATE OR REPLACE PACKAGE app.TEST_PKG_TEST_ME AS + -- %suite(TEST_PKG_TEST_ME) + -- %suitepath(plsql.examples) + -- + -- This package shows all the possibilities to unit test + -- your PL/SQL package. NOTE that it is not limited to + -- testing your package. You can do that on all your + -- procedure/functions... + -- + + /** + * This two parameters are used by the test framework in + * order to identify the test suite to run + */ + + /* + * This method is invoked once before any other method. + * It should contain all the setup code that is relevant + * for all your test. It might be inserting a register, + * creating a type, etc... + */ + -- %beforeall + PROCEDURE SETUP_GLOBAL; + + /* + * This method is invoked once after all other method. + * It can be used to clean up all the resources that + * you created in your script + */ + -- %afterall + PROCEDURE TEARDOWN_GLOBAL; + + /* + * This method is called once before each test. + */ + -- %beforeeach + PROCEDURE SETUP_TEST; + + /* + * This method is called once after each test. + */ + -- %aftereach + PROCEDURE TEARDOWN_TEST; + + /** + * This is a real test. The main test can declare a setup + * and teardown method in order to setup and cleanup things + * for that specific test. + */ + -- %test + -- %displayname(Checking if function ('1') returns 1) + -- %beforetest(SETUP_TEST_FC_INPUT_1) + -- %aftertest(TEARDOWN_TEST_FC_INPUT_1) + PROCEDURE TEST_FC_INPUT_1; + PROCEDURE SETUP_TEST_FC_INPUT_1; + PROCEDURE TEARDOWN_TEST_FC_INPUT_1; + + -- %test + -- %displayname(Checking if function ('0') returns 0) + PROCEDURE TEST_FC_INPUT_0; + + -- %test + -- %displayname(Checking if function (NULL) returns NULL) + PROCEDURE TEST_FC_INPUT_NULL; + + -- %test + -- %displayname(Checking if procedure (NULL) insert) + PROCEDURE TEST_PR_TEST_ME_NULL; + + -- %test + -- %displayname(Checking if procedure (NOT NULL) insert) + -- %rollback(manual) + PROCEDURE TEST_PR_TEST_ME_NOT_NULL; + + -- %test + -- %displayname(Checking if procedure (NOT NULL) insert while existing) + -- %rollback(manual) + PROCEDURE TEST_PR_TEST_ME_EXISTS; + + -- %test + -- %displayname(Demonstrating the use of cursor) + -- %rollback(manual) + PROCEDURE TEST_PR_TEST_ME_CURSOR; + +END; +/ From ebcdeec833746fd0b0dfe6a61090c03700951632 Mon Sep 17 00:00:00 2001 From: Jerome Garec Date: Wed, 23 May 2018 16:41:08 +0200 Subject: [PATCH 38/71] Update documentation for #12 --- README.md | 47 ++++++++++++++++++------------------ pom.xml | 3 +-- utplsql-maven-plugin/pom.xml | 3 +-- 3 files changed, 25 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 1889eda..f014a6f 100644 --- a/README.md +++ b/README.md @@ -31,50 +31,45 @@ You have to be a fully utPLSQL environment available compatible with the Java AP * `paths` * Paths of the resources + +* `sources` + * Path to project source files * `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 * `tests` - * Test fo the scripts at the style of the maven resources + * Path to project test files * `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` - -* `targetDir` - * Target dir, this is a readonly property - * Default: `${project.build.directory}` -* `includeObject` - * Include Object -* `excludeObject` - * Exclude Objects + * Object Type is identified by the expression with the specified set of brackets ### Sample of use The next snippet is a sample of declaration of the pom ```xml - + org.utplsql utplsql-maven-plugin 1.0.0-SNAPSHOT - - test - - + + test + + url_of_connection user password - 3.1.0 false @@ -109,6 +104,10 @@ The next snippet is a sample of declaration of the pom - - + + ``` + +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. diff --git a/pom.xml b/pom.xml index 99e21ae..a1d6312 100644 --- a/pom.xml +++ b/pom.xml @@ -9,8 +9,7 @@ utplsql-maven-plugin Maven Plugin Build - - http://maven.apache.org + https://github.com/utPLSQL/utPLSQL-maven-plugin UTF-8 diff --git a/utplsql-maven-plugin/pom.xml b/utplsql-maven-plugin/pom.xml index 13496c1..c0628df 100644 --- a/utplsql-maven-plugin/pom.xml +++ b/utplsql-maven-plugin/pom.xml @@ -10,8 +10,7 @@ utplsql-maven-plugin Maven Plugin - - http://maven.apache.org + https://github.com/utPLSQL/utPLSQL-maven-plugin UTF-8 From 3f3d1010c7f047c10bb343df8bf3fb632a48ea93 Mon Sep 17 00:00:00 2001 From: Jacek Gebal Date: Thu, 24 May 2018 00:35:36 +0100 Subject: [PATCH 39/71] Refactored Travis build to use local project test resources (cherry picked from commit 8e387cc) --- .travis/install_demo_project.sh | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/.travis/install_demo_project.sh b/.travis/install_demo_project.sh index adb9566..9cd079b 100644 --- a/.travis/install_demo_project.sh +++ b/.travis/install_demo_project.sh @@ -1,9 +1,8 @@ #!/bin/bash set -ev -cd $(dirname $(readlink -f $0)) -PROJECT_FILE="utPLSQL-demo-project" -git clone -b develop --single-branch https://github.com/utPLSQL/utPLSQL-demo-project.git +PROJECT_FILES_SRC="utplsql-maven-plugin/src/test/resources" +PROJECT_FILES="resources" cat > demo_project.sh.tmp < Date: Thu, 24 May 2018 00:35:36 +0100 Subject: [PATCH 40/71] Refactored Travis build to use local project test resources (cherry picked from commit 8e387cc) --- .travis/install_demo_project.sh | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/.travis/install_demo_project.sh b/.travis/install_demo_project.sh index adb9566..9cd079b 100644 --- a/.travis/install_demo_project.sh +++ b/.travis/install_demo_project.sh @@ -1,9 +1,8 @@ #!/bin/bash set -ev -cd $(dirname $(readlink -f $0)) -PROJECT_FILE="utPLSQL-demo-project" -git clone -b develop --single-branch https://github.com/utPLSQL/utPLSQL-demo-project.git +PROJECT_FILES_SRC="utplsql-maven-plugin/src/test/resources" +PROJECT_FILES="resources" cat > demo_project.sh.tmp < Date: Thu, 24 May 2018 10:19:27 +0200 Subject: [PATCH 41/71] Fix build, use simple-project to populate database --- .travis/install_demo_project.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.travis/install_demo_project.sh b/.travis/install_demo_project.sh index 9cd079b..5be2934 100644 --- a/.travis/install_demo_project.sh +++ b/.travis/install_demo_project.sh @@ -1,7 +1,7 @@ #!/bin/bash set -ev -PROJECT_FILES_SRC="utplsql-maven-plugin/src/test/resources" +PROJECT_FILES_SRC="utplsql-maven-plugin/src/test/resources/simple-project" PROJECT_FILES="resources" cat > demo_project.sh.tmp < Date: Fri, 25 May 2018 15:53:38 +0200 Subject: [PATCH 42/71] Fix travis build Ignore windows / mac / linux carriage return differences Ignore test duration differences --- .../maven/plugin/test/UtPLSQLMojoTest.java | 25 +++++++++++++------ .../utplsql/coverage-sonar-reporter.xml | 4 +-- .../utplsql/sonar-test-reporter.xml | 4 +-- .../utplsql/coverage-sonar-reporter.xml | 4 +-- .../utplsql/sonar-test-reporter.xml | 4 +-- 5 files changed, 26 insertions(+), 15 deletions(-) diff --git a/utplsql-maven-plugin/src/test/java/org/utpsql/maven/plugin/test/UtPLSQLMojoTest.java b/utplsql-maven-plugin/src/test/java/org/utpsql/maven/plugin/test/UtPLSQLMojoTest.java index 652b6ba..0272b30 100644 --- a/utplsql-maven-plugin/src/test/java/org/utpsql/maven/plugin/test/UtPLSQLMojoTest.java +++ b/utplsql-maven-plugin/src/test/java/org/utpsql/maven/plugin/test/UtPLSQLMojoTest.java @@ -2,6 +2,10 @@ import java.io.File; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.stream.Collectors; +import java.util.stream.Stream; import org.apache.commons.io.FileUtils; import org.apache.maven.plugin.testing.MojoRule; @@ -29,7 +33,7 @@ public void testDefinition() throws Exception Assert.assertNotNull(myMojo); myMojo.execute(); - checkCoverReportsGenerated(PROJECT_NAME,"utplsql/coverage-sonar-reporter.xml", "utplsql/sonar-test-reporter.xml"); + checkReportsGenerated(PROJECT_NAME,"utplsql/coverage-sonar-reporter.xml", "utplsql/sonar-test-reporter.xml"); } catch (Exception e) { @@ -49,7 +53,7 @@ public void testRegexDefinition() throws Exception Assert.assertNotNull(myMojo); myMojo.execute(); - checkCoverReportsGenerated(PROJECT_NAME,"utplsql/coverage-sonar-reporter.xml", "utplsql/sonar-test-reporter.xml"); + checkReportsGenerated(PROJECT_NAME,"utplsql/coverage-sonar-reporter.xml", "utplsql/sonar-test-reporter.xml"); } catch (Exception e) { @@ -62,7 +66,7 @@ public void testRegexDefinition() throws Exception * * @param files */ - private void checkCoverReportsGenerated(String projectName, String... files) + private void checkReportsGenerated(String projectName, String... files) { for (String filename : files) { @@ -71,10 +75,18 @@ private void checkCoverReportsGenerated(String projectName, String... files) Assert.assertTrue("The reporter for " + filename + " was not generated", outputFile.exists()); try { - // Duration is set to 1 before comparing contents. + // 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_DIRECTORY,projectName,"target",filename)); + String outputContent = stream.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(outputFile, "utf-8").replaceAll("(duration=\"[0-9\\.]*\")", "duration=\"1\""), - FileUtils.readFileToString(expectedOutputFile, "utf-8")); + outputContent, + FileUtils.readFileToString(expectedOutputFile, "utf-8").replace("\r","")); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -82,5 +94,4 @@ private void checkCoverReportsGenerated(String projectName, String... files) } } } - } diff --git a/utplsql-maven-plugin/src/test/resources/regex-project/expected-output/utplsql/coverage-sonar-reporter.xml b/utplsql-maven-plugin/src/test/resources/regex-project/expected-output/utplsql/coverage-sonar-reporter.xml index a7a24ba..79a7998 100644 --- a/utplsql-maven-plugin/src/test/resources/regex-project/expected-output/utplsql/coverage-sonar-reporter.xml +++ b/utplsql-maven-plugin/src/test/resources/regex-project/expected-output/utplsql/coverage-sonar-reporter.xml @@ -1,5 +1,5 @@ - + @@ -9,4 +9,4 @@ - + \ No newline at end of file diff --git a/utplsql-maven-plugin/src/test/resources/regex-project/expected-output/utplsql/sonar-test-reporter.xml b/utplsql-maven-plugin/src/test/resources/regex-project/expected-output/utplsql/sonar-test-reporter.xml index d2fb47a..f3ce4f9 100644 --- a/utplsql-maven-plugin/src/test/resources/regex-project/expected-output/utplsql/sonar-test-reporter.xml +++ b/utplsql-maven-plugin/src/test/resources/regex-project/expected-output/utplsql/sonar-test-reporter.xml @@ -1,5 +1,5 @@ - + @@ -15,4 +15,4 @@ - + \ No newline at end of file diff --git a/utplsql-maven-plugin/src/test/resources/simple-project/expected-output/utplsql/coverage-sonar-reporter.xml b/utplsql-maven-plugin/src/test/resources/simple-project/expected-output/utplsql/coverage-sonar-reporter.xml index 804f11c..e4b4222 100644 --- a/utplsql-maven-plugin/src/test/resources/simple-project/expected-output/utplsql/coverage-sonar-reporter.xml +++ b/utplsql-maven-plugin/src/test/resources/simple-project/expected-output/utplsql/coverage-sonar-reporter.xml @@ -1,5 +1,5 @@ - + @@ -9,4 +9,4 @@ - + \ No newline at end of file diff --git a/utplsql-maven-plugin/src/test/resources/simple-project/expected-output/utplsql/sonar-test-reporter.xml b/utplsql-maven-plugin/src/test/resources/simple-project/expected-output/utplsql/sonar-test-reporter.xml index baa2643..712cb69 100644 --- a/utplsql-maven-plugin/src/test/resources/simple-project/expected-output/utplsql/sonar-test-reporter.xml +++ b/utplsql-maven-plugin/src/test/resources/simple-project/expected-output/utplsql/sonar-test-reporter.xml @@ -1,5 +1,5 @@ - + @@ -15,4 +15,4 @@ - + \ No newline at end of file From a2c357f26bcd80f5ec3bd35770cbfac56aa9ddde Mon Sep 17 00:00:00 2001 From: Jerome Garec Date: Tue, 29 May 2018 17:40:40 +0200 Subject: [PATCH 43/71] Adds support of custom type parameters (#5) * Adds new parameters : sourcesCustomTypeMapping & testsCustomTypeMapping * Adds one new sample project --- README.md | 8 +- .../maven/plugin/CustomTypeMapping.java | 50 +++++++ .../org/utplsql/maven/plugin/UtPLSQLMojo.java | 24 +++- .../maven/plugin/test/UtPLSQLMojoTest.java | 20 +++ .../utplsql/coverage-sonar-reporter.xml | 12 ++ .../utplsql/sonar-test-reporter.xml | 18 +++ .../resources/type-mapping-project/pom.xml | 94 +++++++++++++ .../app/package_bodies/PKG_TEST_ME.sql | 28 ++++ .../sources/app/packages/PKG_TEST_ME.sql | 8 ++ .../scripts/sources/app/tables/TO_TEST_ME.tab | 8 ++ .../app/package_bodies/TEST_PKG_TEST_ME.sql | 126 ++++++++++++++++++ .../test/app/packages/TEST_PKG_TEST_ME.sql | 86 ++++++++++++ 12 files changed, 477 insertions(+), 5 deletions(-) create mode 100644 utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/CustomTypeMapping.java create mode 100644 utplsql-maven-plugin/src/test/resources/type-mapping-project/expected-output/utplsql/coverage-sonar-reporter.xml create mode 100644 utplsql-maven-plugin/src/test/resources/type-mapping-project/expected-output/utplsql/sonar-test-reporter.xml create mode 100644 utplsql-maven-plugin/src/test/resources/type-mapping-project/pom.xml create mode 100644 utplsql-maven-plugin/src/test/resources/type-mapping-project/scripts/sources/app/package_bodies/PKG_TEST_ME.sql create mode 100644 utplsql-maven-plugin/src/test/resources/type-mapping-project/scripts/sources/app/packages/PKG_TEST_ME.sql create mode 100644 utplsql-maven-plugin/src/test/resources/type-mapping-project/scripts/sources/app/tables/TO_TEST_ME.tab create mode 100644 utplsql-maven-plugin/src/test/resources/type-mapping-project/scripts/test/app/package_bodies/TEST_PKG_TEST_ME.sql create mode 100644 utplsql-maven-plugin/src/test/resources/type-mapping-project/scripts/test/app/packages/TEST_PKG_TEST_ME.sql diff --git a/README.md b/README.md index f014a6f..b759a54 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,9 @@ You have to be a fully utPLSQL environment available compatible with the Java AP * `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 + * 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 @@ -53,7 +55,8 @@ You have to be a fully utPLSQL environment available compatible with the Java AP * 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 ### Sample of use @@ -111,3 +114,4 @@ The next snippet is a sample of declaration of the pom 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. 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 new file mode 100644 index 0000000..2ce9cf6 --- /dev/null +++ b/utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/CustomTypeMapping.java @@ -0,0 +1,50 @@ +package org.utplsql.maven.plugin; + +/** + * Bean used by maven to populate its model. + * + * + * ... + * ... + * + * + */ +public class CustomTypeMapping { + /** + * Object type. + */ + private String type; + + /** + * Custom mapping value. + */ + private String customMapping; + + /** + * @return The Object type. + */ + public String getType() { + return type; + } + + /** + * @param type The Object type. + */ + public void setType(final String type) { + this.type = type; + } + + /** + * @return Custom mapping value. + */ + public String getCustomMapping() { + return customMapping; + } + + /** + * @param mapping 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 f55d198..c2e5a25 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 @@ -1,7 +1,5 @@ package org.utplsql.maven.plugin; -import static java.lang.String.format; - import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; @@ -18,6 +16,7 @@ import org.apache.maven.plugins.annotations.Parameter; import org.utplsql.api.DBHelper; import org.utplsql.api.FileMapperOptions; +import org.utplsql.api.KeyValuePair; import org.utplsql.api.TestRunner; import org.utplsql.api.Version; import org.utplsql.api.exception.SomeTestsFailedException; @@ -76,7 +75,9 @@ public class UtPLSQLMojo extends AbstractMojo @Parameter private Integer sourcesTypeSubexpression; - + + @Parameter + private List sourcesCustomTypeMapping; // Tests Configuration @@ -95,6 +96,9 @@ public class UtPLSQLMojo extends AbstractMojo @Parameter private Integer testsTypeSubexpression; + @Parameter + private List testsCustomTypeMapping; + @Parameter(defaultValue = "${project.build.directory}", readonly = true) protected String targetDir; @@ -238,6 +242,13 @@ private FileMapperOptions buildSourcesOptions() throws MojoExecutionException fileMapperOptions.setTypeSubExpression(sourcesTypeSubexpression); } + if (sourcesCustomTypeMapping != null && sourcesCustomTypeMapping.size() > 0) { + fileMapperOptions.setTypeMappings(new ArrayList()); + for (CustomTypeMapping typeMapping : sourcesCustomTypeMapping) { + fileMapperOptions.getTypeMappings().add(new KeyValuePair(typeMapping.getCustomMapping(),typeMapping.getType())); + } + } + return fileMapperOptions; } @@ -288,6 +299,13 @@ private FileMapperOptions buildTestsOptions() throws MojoExecutionException fileMapperOptions.setTypeSubExpression(testsTypeSubexpression); } + if (testsCustomTypeMapping != null && testsCustomTypeMapping.size() > 0) { + fileMapperOptions.setTypeMappings(new ArrayList()); + for (CustomTypeMapping typeMapping : testsCustomTypeMapping) { + fileMapperOptions.getTypeMappings().add(new KeyValuePair(typeMapping.getCustomMapping(),typeMapping.getType())); + } + } + return fileMapperOptions; } diff --git a/utplsql-maven-plugin/src/test/java/org/utpsql/maven/plugin/test/UtPLSQLMojoTest.java b/utplsql-maven-plugin/src/test/java/org/utpsql/maven/plugin/test/UtPLSQLMojoTest.java index 0272b30..7695c8b 100644 --- a/utplsql-maven-plugin/src/test/java/org/utpsql/maven/plugin/test/UtPLSQLMojoTest.java +++ b/utplsql-maven-plugin/src/test/java/org/utpsql/maven/plugin/test/UtPLSQLMojoTest.java @@ -61,6 +61,26 @@ public void testRegexDefinition() throws Exception Assert.fail("Unexpected Exception running the test of Definition"); } } + + @Test + public void testTypeMappingDefinition() throws Exception + { + try + { + final String PROJECT_NAME = "type-mapping-project"; + UtPLSQLMojo myMojo = (UtPLSQLMojo) rule.lookupConfiguredMojo(new File(TARGET_DIRECTORY+"/"+PROJECT_NAME), "test"); + + Assert.assertNotNull(myMojo); + myMojo.execute(); + + checkReportsGenerated(PROJECT_NAME,"utplsql/coverage-sonar-reporter.xml", "utplsql/sonar-test-reporter.xml"); + } + catch (Exception e) + { + e.printStackTrace(); + Assert.fail("Unexpected Exception running the test of Definition"); + } + } /** * diff --git a/utplsql-maven-plugin/src/test/resources/type-mapping-project/expected-output/utplsql/coverage-sonar-reporter.xml b/utplsql-maven-plugin/src/test/resources/type-mapping-project/expected-output/utplsql/coverage-sonar-reporter.xml new file mode 100644 index 0000000..65ddd2b --- /dev/null +++ b/utplsql-maven-plugin/src/test/resources/type-mapping-project/expected-output/utplsql/coverage-sonar-reporter.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/utplsql-maven-plugin/src/test/resources/type-mapping-project/expected-output/utplsql/sonar-test-reporter.xml b/utplsql-maven-plugin/src/test/resources/type-mapping-project/expected-output/utplsql/sonar-test-reporter.xml new file mode 100644 index 0000000..84e9996 --- /dev/null +++ b/utplsql-maven-plugin/src/test/resources/type-mapping-project/expected-output/utplsql/sonar-test-reporter.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/utplsql-maven-plugin/src/test/resources/type-mapping-project/pom.xml b/utplsql-maven-plugin/src/test/resources/type-mapping-project/pom.xml new file mode 100644 index 0000000..95a197e --- /dev/null +++ b/utplsql-maven-plugin/src/test/resources/type-mapping-project/pom.xml @@ -0,0 +1,94 @@ + + 4.0.0 + + org.utplsql + utplsql-maven-plugin-test + 1.0.0-SNAPSHOT + maven-plugin + + utplsql-maven-plugin Maven Plugin Test + + + + jdbc:oracle:thin:@127.0.0.1:1521:xe + + + + + + + + ${pom.groupId} + utplsql-maven-plugin + ${pom.version} + + test + + + + + false + + + app + + + + + UT_COVERAGE_SONAR_REPORTER + utplsql/coverage-sonar-reporter.xml + true + + + UT_SONAR_TEST_REPORTER + utplsql/sonar-test-reporter.xml + true + + + + + + src/test/resources/type-mapping-project/scripts/sources + + **/*sql + + + + .*(\\|\/)(\w+)(\\|\/)(\w+)(\\|\/)(\w+).(\w{3}) + 2 + 6 + 4 + + + package body + package_bodies + + + + + + src/test/resources/type-mapping-project/scripts/test + + **/*sql + + + + .*(\\|\/)(\w+)(\\|\/)(\w+)(\\|\/)(\w+).(\w{3}) + 2 + 6 + 4 + + + package body + package_bodies + + + + + + + \ No newline at end of file diff --git a/utplsql-maven-plugin/src/test/resources/type-mapping-project/scripts/sources/app/package_bodies/PKG_TEST_ME.sql b/utplsql-maven-plugin/src/test/resources/type-mapping-project/scripts/sources/app/package_bodies/PKG_TEST_ME.sql new file mode 100644 index 0000000..29cea5e --- /dev/null +++ b/utplsql-maven-plugin/src/test/resources/type-mapping-project/scripts/sources/app/package_bodies/PKG_TEST_ME.sql @@ -0,0 +1,28 @@ +CREATE OR REPLACE PACKAGE BODY APP.PKG_TEST_ME IS + + -- + -- This + -- + FUNCTION FC_TEST_ME(PPARAM1 IN VARCHAR2) RETURN NUMBER IS + BEGIN + IF PPARAM1 IS NULL THEN + RETURN NULL; + ELSIF PPARAM1 = '1' THEN + RETURN 1; + ELSE + RETURN 0; + END IF; + END FC_TEST_ME; + + PROCEDURE PR_TEST_ME(PSNAME IN VARCHAR2) IS + BEGIN + IF PSNAME IS NULL THEN + NULL; + ELSE + INSERT INTO TO_TEST_ME (SNAME) VALUES (PSNAME); + COMMIT; + END IF; + END PR_TEST_ME; + +END PKG_TEST_ME; +/ \ No newline at end of file diff --git a/utplsql-maven-plugin/src/test/resources/type-mapping-project/scripts/sources/app/packages/PKG_TEST_ME.sql b/utplsql-maven-plugin/src/test/resources/type-mapping-project/scripts/sources/app/packages/PKG_TEST_ME.sql new file mode 100644 index 0000000..e23c420 --- /dev/null +++ b/utplsql-maven-plugin/src/test/resources/type-mapping-project/scripts/sources/app/packages/PKG_TEST_ME.sql @@ -0,0 +1,8 @@ +-- +-- This package is used TO demonstrate the utPL/SQL possibilities +-- +CREATE OR REPLACE PACKAGE app.PKG_TEST_ME AS + FUNCTION FC_TEST_ME(PPARAM1 IN VARCHAR2) RETURN NUMBER; + PROCEDURE PR_TEST_ME(PSNAME IN VARCHAR2); +END PKG_TEST_ME; +/ \ No newline at end of file diff --git a/utplsql-maven-plugin/src/test/resources/type-mapping-project/scripts/sources/app/tables/TO_TEST_ME.tab b/utplsql-maven-plugin/src/test/resources/type-mapping-project/scripts/sources/app/tables/TO_TEST_ME.tab new file mode 100644 index 0000000..b2e90d9 --- /dev/null +++ b/utplsql-maven-plugin/src/test/resources/type-mapping-project/scripts/sources/app/tables/TO_TEST_ME.tab @@ -0,0 +1,8 @@ +-- +-- This is a table used to demonstrate the UNIT test framework. +-- +CREATE TABLE TO_TEST_ME +( + SNAME VARCHAR2(10) +) +/ diff --git a/utplsql-maven-plugin/src/test/resources/type-mapping-project/scripts/test/app/package_bodies/TEST_PKG_TEST_ME.sql b/utplsql-maven-plugin/src/test/resources/type-mapping-project/scripts/test/app/package_bodies/TEST_PKG_TEST_ME.sql new file mode 100644 index 0000000..32d6b35 --- /dev/null +++ b/utplsql-maven-plugin/src/test/resources/type-mapping-project/scripts/test/app/package_bodies/TEST_PKG_TEST_ME.sql @@ -0,0 +1,126 @@ +CREATE OR REPLACE PACKAGE BODY app.TEST_PKG_TEST_ME AS + + --------------------------------------------------------------------------- + PROCEDURE SETUP_GLOBAL IS + BEGIN + -- Put here the code which is valid for all tests and that should be + -- executed once. + NULL; + END SETUP_GLOBAL; + + --------------------------------------------------------------------------- + PROCEDURE TEARDOWN_GLOBAL IS + BEGIN + -- Put here the code that should be called only once after all the test + -- have executed + NULL; + END TEARDOWN_GLOBAL; + + --------------------------------------------------------------------------- + PROCEDURE SETUP_TEST IS + BEGIN + -- Nothing to clean up globally + NULL; + END SETUP_TEST; + + PROCEDURE TEARDOWN_TEST IS + BEGIN + -- Nothing to clean up globally + NULL; + END TEARDOWN_TEST; + + PROCEDURE TEST_FC_INPUT_1 IS + BEGIN + -- Ok this is a real test where I check that the function return 1 + -- when called with a '1' parameter + UT.EXPECT(PKG_TEST_ME.FC_TEST_ME('1')).TO_EQUAL(1); + END; + + PROCEDURE SETUP_TEST_FC_INPUT_1 IS + BEGIN + -- Nothing to be done really + NULL; + END; + + PROCEDURE TEARDOWN_TEST_FC_INPUT_1 IS + BEGIN + -- Nothing to be done really + NULL; + END; + + PROCEDURE TEST_FC_INPUT_0 IS + BEGIN + -- Ok this is a real test where I check that the function return 0 + -- when called with a '0' parameter + UT.EXPECT(PKG_TEST_ME.FC_TEST_ME('0')).TO_EQUAL(0); + END; + + PROCEDURE TEST_FC_INPUT_NULL IS + BEGIN + -- Ok I check that the function return NULL + -- when called with a NULL parameter + UT.EXPECT(PKG_TEST_ME.FC_TEST_ME(NULL)).TO_BE_NULL; + END TEST_FC_INPUT_NULL; + + PROCEDURE TEST_PR_TEST_ME_NULL IS + VNCOUNT1 PLS_INTEGER; + VNCOUNT2 PLS_INTEGER; + BEGIN + -- In this example I check that the procedure does + -- not insert anything when passing it a NULL parameter + SELECT COUNT(1) INTO VNCOUNT1 FROM TO_TEST_ME; + PKG_TEST_ME.PR_TEST_ME(NULL); + SELECT COUNT(1) INTO VNCOUNT2 FROM TO_TEST_ME; + UT.EXPECT(VNCOUNT1).TO_EQUAL(VNCOUNT2); + END; + + PROCEDURE TEST_PR_TEST_ME_NOT_NULL IS + VNCOUNT1 PLS_INTEGER; + VNCOUNT2 PLS_INTEGER; + VSNAME TO_TEST_ME.SNAME%TYPE; + BEGIN + -- In this test I will check that I do insert a value + -- when the parameter is not null. I futher check that + -- the procedure has inserted the value I specified. + SELECT COUNT(1) INTO VNCOUNT1 FROM TO_TEST_ME; + VSNAME := TO_CHAR(VNCOUNT1); + PKG_TEST_ME.PR_TEST_ME(VSNAME); + SELECT COUNT(1) INTO VNCOUNT2 FROM TO_TEST_ME; + + -- Check that I have inserted the value + UT.EXPECT(VNCOUNT1 + 1).TO_EQUAL(VNCOUNT2); + SELECT COUNT(1) INTO VNCOUNT2 FROM TO_TEST_ME T WHERE T.SNAME = VSNAME; + + -- Check that I inserted the one I said I would insert + UT.EXPECT(VNCOUNT2).TO_EQUAL(1); + DELETE FROM TO_TEST_ME T WHERE T.SNAME = VSNAME; + COMMIT; + END; + + PROCEDURE TEST_PR_TEST_ME_EXISTS IS + BEGIN + -- In case the value exists the procedure should fail with an exception. + BEGIN + PKG_TEST_ME.PR_TEST_ME('EXISTS'); + PKG_TEST_ME.PR_TEST_ME('EXISTS'); + EXCEPTION + WHEN OTHERS THEN + UT.FAIL('Unexpected exception raised'); + END; + END; + + PROCEDURE TEST_PR_TEST_ME_CURSOR IS + TYPE REF_CURSOR IS REF CURSOR; + VEXPECTED REF_CURSOR; + VACTUAL REF_CURSOR; + BEGIN + EXECUTE IMMEDIATE 'TRUNCATE TABLE TO_TEST_ME'; + OPEN VEXPECTED FOR + SELECT T.SNAME FROM TO_TEST_ME T; + OPEN VACTUAL FOR + SELECT T.SNAME FROM TO_TEST_ME T; + UT.EXPECT(VEXPECTED).TO_(EQUAL(VACTUAL)); + END; + +END; +/ diff --git a/utplsql-maven-plugin/src/test/resources/type-mapping-project/scripts/test/app/packages/TEST_PKG_TEST_ME.sql b/utplsql-maven-plugin/src/test/resources/type-mapping-project/scripts/test/app/packages/TEST_PKG_TEST_ME.sql new file mode 100644 index 0000000..f22deac --- /dev/null +++ b/utplsql-maven-plugin/src/test/resources/type-mapping-project/scripts/test/app/packages/TEST_PKG_TEST_ME.sql @@ -0,0 +1,86 @@ +CREATE OR REPLACE PACKAGE app.TEST_PKG_TEST_ME AS + -- %suite(TEST_PKG_TEST_ME) + -- %suitepath(plsql.examples) + -- + -- This package shows all the possibilities to unit test + -- your PL/SQL package. NOTE that it is not limited to + -- testing your package. You can do that on all your + -- procedure/functions... + -- + + /** + * This two parameters are used by the test framework in + * order to identify the test suite to run + */ + + /* + * This method is invoked once before any other method. + * It should contain all the setup code that is relevant + * for all your test. It might be inserting a register, + * creating a type, etc... + */ + -- %beforeall + PROCEDURE SETUP_GLOBAL; + + /* + * This method is invoked once after all other method. + * It can be used to clean up all the resources that + * you created in your script + */ + -- %afterall + PROCEDURE TEARDOWN_GLOBAL; + + /* + * This method is called once before each test. + */ + -- %beforeeach + PROCEDURE SETUP_TEST; + + /* + * This method is called once after each test. + */ + -- %aftereach + PROCEDURE TEARDOWN_TEST; + + /** + * This is a real test. The main test can declare a setup + * and teardown method in order to setup and cleanup things + * for that specific test. + */ + -- %test + -- %displayname(Checking if function ('1') returns 1) + -- %beforetest(SETUP_TEST_FC_INPUT_1) + -- %aftertest(TEARDOWN_TEST_FC_INPUT_1) + PROCEDURE TEST_FC_INPUT_1; + PROCEDURE SETUP_TEST_FC_INPUT_1; + PROCEDURE TEARDOWN_TEST_FC_INPUT_1; + + -- %test + -- %displayname(Checking if function ('0') returns 0) + PROCEDURE TEST_FC_INPUT_0; + + -- %test + -- %displayname(Checking if function (NULL) returns NULL) + PROCEDURE TEST_FC_INPUT_NULL; + + -- %test + -- %displayname(Checking if procedure (NULL) insert) + PROCEDURE TEST_PR_TEST_ME_NULL; + + -- %test + -- %displayname(Checking if procedure (NOT NULL) insert) + -- %rollback(manual) + PROCEDURE TEST_PR_TEST_ME_NOT_NULL; + + -- %test + -- %displayname(Checking if procedure (NOT NULL) insert while existing) + -- %rollback(manual) + PROCEDURE TEST_PR_TEST_ME_EXISTS; + + -- %test + -- %displayname(Demonstrating the use of cursor) + -- %rollback(manual) + PROCEDURE TEST_PR_TEST_ME_CURSOR; + +END; +/ From fbfda7121a66c585c4505db3ccd4251074fe72a1 Mon Sep 17 00:00:00 2001 From: Jerome Garec Date: Wed, 6 Jun 2018 18:37:49 +0200 Subject: [PATCH 44/71] Fix regex complexity --- .../test/resources/type-mapping-project/pom.xml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/utplsql-maven-plugin/src/test/resources/type-mapping-project/pom.xml b/utplsql-maven-plugin/src/test/resources/type-mapping-project/pom.xml index 95a197e..42312f9 100644 --- a/utplsql-maven-plugin/src/test/resources/type-mapping-project/pom.xml +++ b/utplsql-maven-plugin/src/test/resources/type-mapping-project/pom.xml @@ -58,10 +58,10 @@ - .*(\\|\/)(\w+)(\\|\/)(\w+)(\\|\/)(\w+).(\w{3}) - 2 - 6 - 4 + .*/(\w+)/(\w+)/(\w+)\.\w{3} + 1 + 3 + 2 package body @@ -77,10 +77,10 @@ - .*(\\|\/)(\w+)(\\|\/)(\w+)(\\|\/)(\w+).(\w{3}) - 2 - 6 - 4 + .*/(\w+)/(\w+)/(\w+)\.\w{3} + 1 + 3 + 2 package body From 204c4fa576c29c9d3b8370dd85cd5ae1ac4ecc92 Mon Sep 17 00:00:00 2001 From: jgarec Date: Sun, 15 Jul 2018 18:09:03 +0200 Subject: [PATCH 45/71] Feature/refactor tests (#19) * Refactor existing tests to integration tests Java : Add a new module "it" Move all existing tests into this new module Bind these tests to integration-test phase with failsafe plugin Each Integration test is run with maven-verifier-plugin Travis : Provides explicitly url parameter on maven command line Run tests and integration tests in 2 steps --- .gitignore | 2 + .travis.yml | 5 +- .travis/install_demo_project.sh | 2 +- pom.xml | 5 +- utplsql-maven-plugin-it/pom.xml | 134 ++++++++++ .../maven/plugin/test/UtPLSQLMojoIT.java | 163 +++++++++++ .../utplsql/coverage-sonar-reporter.xml | 2 +- .../utplsql/sonar-test-reporter.xml | 2 +- .../src/it/resources/regex-project/pom.xml | 82 ++++++ .../sources/app/packages/PKG_TEST_ME.bdy | 0 .../sources/app/packages/PKG_TEST_ME.spc | 0 .../scripts/sources/app/tables/TO_TEST_ME.tab | 0 .../test/app/packages/TEST_PKG_TEST_ME.bdy | 0 .../test/app/packages/TEST_PKG_TEST_ME.spc | 0 .../utplsql/coverage-sonar-reporter.xml | 2 +- .../utplsql/sonar-test-reporter.xml | 2 +- .../src/it/resources/simple-project/pom.xml | 76 ++++++ .../scripts/sources/APP.PKG_TEST_ME.bdy | 54 ++-- .../scripts/sources/APP.PKG_TEST_ME.spc | 14 +- .../scripts/sources}/TO_TEST_ME.tab | 0 .../scripts/tests/APP.TEST_PKG_TEST_ME.bdy | 252 +++++++++--------- .../scripts/tests/APP.TEST_PKG_TEST_ME.spc | 172 ++++++------ .../utplsql/coverage-sonar-reporter.xml | 2 +- .../utplsql/sonar-test-reporter.xml | 2 +- .../it/resources/type-mapping-project/pom.xml | 92 +++++++ .../app/package_bodies/PKG_TEST_ME.sql | 0 .../sources/app/packages/PKG_TEST_ME.sql | 0 .../sources/app/tables}/TO_TEST_ME.tab | 16 +- .../app/package_bodies/TEST_PKG_TEST_ME.sql | 0 .../test/app/packages/TEST_PKG_TEST_ME.sql | 0 utplsql-maven-plugin/pom.xml | 12 +- .../maven/plugin/test/UtPLSQLMojoTest.java | 117 -------- .../src/test/resources/regex-project/pom.xml | 85 ------ .../src/test/resources/simple-project/pom.xml | 76 ------ .../resources/type-mapping-project/pom.xml | 94 ------- 35 files changed, 826 insertions(+), 639 deletions(-) create mode 100644 utplsql-maven-plugin-it/pom.xml create mode 100644 utplsql-maven-plugin-it/src/it/java/org/utpsql/maven/plugin/test/UtPLSQLMojoIT.java rename {utplsql-maven-plugin/src/test/resources/simple-project => utplsql-maven-plugin-it/src/it/resources/regex-project}/expected-output/utplsql/coverage-sonar-reporter.xml (82%) rename {utplsql-maven-plugin/src/test/resources/simple-project => utplsql-maven-plugin-it/src/it/resources/regex-project}/expected-output/utplsql/sonar-test-reporter.xml (85%) create mode 100644 utplsql-maven-plugin-it/src/it/resources/regex-project/pom.xml rename {utplsql-maven-plugin/src/test => utplsql-maven-plugin-it/src/it}/resources/regex-project/scripts/sources/app/packages/PKG_TEST_ME.bdy (100%) rename {utplsql-maven-plugin/src/test => utplsql-maven-plugin-it/src/it}/resources/regex-project/scripts/sources/app/packages/PKG_TEST_ME.spc (100%) rename {utplsql-maven-plugin/src/test => utplsql-maven-plugin-it/src/it}/resources/regex-project/scripts/sources/app/tables/TO_TEST_ME.tab (100%) rename {utplsql-maven-plugin/src/test => utplsql-maven-plugin-it/src/it}/resources/regex-project/scripts/test/app/packages/TEST_PKG_TEST_ME.bdy (100%) rename {utplsql-maven-plugin/src/test => utplsql-maven-plugin-it/src/it}/resources/regex-project/scripts/test/app/packages/TEST_PKG_TEST_ME.spc (100%) rename {utplsql-maven-plugin/src/test/resources/regex-project => utplsql-maven-plugin-it/src/it/resources/simple-project}/expected-output/utplsql/coverage-sonar-reporter.xml (81%) rename {utplsql-maven-plugin/src/test/resources/regex-project => utplsql-maven-plugin-it/src/it/resources/simple-project}/expected-output/utplsql/sonar-test-reporter.xml (84%) create mode 100644 utplsql-maven-plugin-it/src/it/resources/simple-project/pom.xml rename {utplsql-maven-plugin/src/test => utplsql-maven-plugin-it/src/it}/resources/simple-project/scripts/sources/APP.PKG_TEST_ME.bdy (94%) rename {utplsql-maven-plugin/src/test => utplsql-maven-plugin-it/src/it}/resources/simple-project/scripts/sources/APP.PKG_TEST_ME.spc (97%) rename {utplsql-maven-plugin/src/test/resources/type-mapping-project/scripts/sources/app/tables => utplsql-maven-plugin-it/src/it/resources/simple-project/scripts/sources}/TO_TEST_ME.tab (100%) rename {utplsql-maven-plugin/src/test => utplsql-maven-plugin-it/src/it}/resources/simple-project/scripts/tests/APP.TEST_PKG_TEST_ME.bdy (96%) rename {utplsql-maven-plugin/src/test => utplsql-maven-plugin-it/src/it}/resources/simple-project/scripts/tests/APP.TEST_PKG_TEST_ME.spc (96%) rename {utplsql-maven-plugin/src/test => utplsql-maven-plugin-it/src/it}/resources/type-mapping-project/expected-output/utplsql/coverage-sonar-reporter.xml (79%) rename {utplsql-maven-plugin/src/test => utplsql-maven-plugin-it/src/it}/resources/type-mapping-project/expected-output/utplsql/sonar-test-reporter.xml (82%) create mode 100644 utplsql-maven-plugin-it/src/it/resources/type-mapping-project/pom.xml rename {utplsql-maven-plugin/src/test => utplsql-maven-plugin-it/src/it}/resources/type-mapping-project/scripts/sources/app/package_bodies/PKG_TEST_ME.sql (100%) rename {utplsql-maven-plugin/src/test => utplsql-maven-plugin-it/src/it}/resources/type-mapping-project/scripts/sources/app/packages/PKG_TEST_ME.sql (100%) rename {utplsql-maven-plugin/src/test/resources/simple-project/scripts/sources => utplsql-maven-plugin-it/src/it/resources/type-mapping-project/scripts/sources/app/tables}/TO_TEST_ME.tab (93%) rename {utplsql-maven-plugin/src/test => utplsql-maven-plugin-it/src/it}/resources/type-mapping-project/scripts/test/app/package_bodies/TEST_PKG_TEST_ME.sql (100%) rename {utplsql-maven-plugin/src/test => utplsql-maven-plugin-it/src/it}/resources/type-mapping-project/scripts/test/app/packages/TEST_PKG_TEST_ME.sql (100%) delete mode 100644 utplsql-maven-plugin/src/test/java/org/utpsql/maven/plugin/test/UtPLSQLMojoTest.java delete mode 100644 utplsql-maven-plugin/src/test/resources/regex-project/pom.xml delete mode 100644 utplsql-maven-plugin/src/test/resources/simple-project/pom.xml delete mode 100644 utplsql-maven-plugin/src/test/resources/type-mapping-project/pom.xml diff --git a/.gitignore b/.gitignore index bb57f02..55f4354 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,5 @@ log/ target/ .mvn +log.txt +**/pom.xml.versionsBackup \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index b95be96..6ed1b72 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,7 +33,10 @@ install: - bash .travis/install_demo_project.sh script: - - mvn package -DdbUser="${DB_USER}" -DdbPass="${DB_PASS}" + - echo "Run Unit tests" + - mvn test + - echo "Run Integration tests" + - mvn verify -Dmaven.skip.test -DdbUser="${DB_USER}" -DdbPass="${DB_PASS}" -DdbUrl="jdbc:oracle:thin:@${DB_URL}" #before_deploy: # - bash .travis/create_release.sh diff --git a/.travis/install_demo_project.sh b/.travis/install_demo_project.sh index 5be2934..61c6319 100644 --- a/.travis/install_demo_project.sh +++ b/.travis/install_demo_project.sh @@ -1,7 +1,7 @@ #!/bin/bash set -ev -PROJECT_FILES_SRC="utplsql-maven-plugin/src/test/resources/simple-project" +PROJECT_FILES_SRC="utplsql-maven-plugin-it/src/it/resources/simple-project" PROJECT_FILES="resources" cat > demo_project.sh.tmp <4.0.0 org.utplsql - utplsql-maven-plugin-build + utplsql-maven-plugin-parent 3.1.0-SNAPSHOT pom - utplsql-maven-plugin Maven Plugin Build + utplsql-maven-plugin Parent https://github.com/utPLSQL/utPLSQL-maven-plugin @@ -18,6 +18,7 @@ utplsql-maven-plugin + utplsql-maven-plugin-it diff --git a/utplsql-maven-plugin-it/pom.xml b/utplsql-maven-plugin-it/pom.xml new file mode 100644 index 0000000..19a9e24 --- /dev/null +++ b/utplsql-maven-plugin-it/pom.xml @@ -0,0 +1,134 @@ + + 4.0.0 + + + org.utplsql + utplsql-maven-plugin-parent + 3.1.0-SNAPSHOT + + utplsql-maven-plugin Integration tests + utplsql-maven-plugin-it + jar + + + 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.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 + + + + + + + + \ 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 new file mode 100644 index 0000000..ca902e8 --- /dev/null +++ b/utplsql-maven-plugin-it/src/it/java/org/utpsql/maven/plugin/test/UtPLSQLMojoIT.java @@ -0,0 +1,163 @@ +package org.utpsql.maven.plugin.test; + +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import org.apache.commons.io.FileUtils; +import org.apache.maven.it.VerificationException; +import org.apache.maven.it.Verifier; +import org.apache.maven.it.util.ResourceExtractor; +import org.apache.maven.model.Model; +import org.apache.maven.model.io.xpp3.MavenXpp3Reader; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +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()); + + // delete plugin + //verifier.deleteArtifact( model.getGroupId(), model.getArtifactId(), model.getVersion(), "pom" ); + + // install plugin + verifier.setAutoclean(false); + verifier.addCliOption("-Dmaven.skip.test=true"); + verifier.addCliOption("-DskipITs"); + verifier.executeGoal("install"); + + pluginVersion = model.getVersion(); + } + + + @Test + public void testSimpleDefinition() 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 testRegexDefinition() 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 of Definition"); + } + } + + @Test + public void testTypeMappingDefinition() 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 of Definition"); + } + } + + /** + * + * @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("(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!", + outputContent, + FileUtils.readFileToString(expectedOutputFile, "utf-8").replace("\r","")); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + Assert.fail("Unexpected Exception running the test of Definition"); + } + } + } +} diff --git a/utplsql-maven-plugin/src/test/resources/simple-project/expected-output/utplsql/coverage-sonar-reporter.xml b/utplsql-maven-plugin-it/src/it/resources/regex-project/expected-output/utplsql/coverage-sonar-reporter.xml similarity index 82% rename from utplsql-maven-plugin/src/test/resources/simple-project/expected-output/utplsql/coverage-sonar-reporter.xml rename to utplsql-maven-plugin-it/src/it/resources/regex-project/expected-output/utplsql/coverage-sonar-reporter.xml index e4b4222..0628e51 100644 --- a/utplsql-maven-plugin/src/test/resources/simple-project/expected-output/utplsql/coverage-sonar-reporter.xml +++ b/utplsql-maven-plugin-it/src/it/resources/regex-project/expected-output/utplsql/coverage-sonar-reporter.xml @@ -1,5 +1,5 @@ - + diff --git a/utplsql-maven-plugin/src/test/resources/simple-project/expected-output/utplsql/sonar-test-reporter.xml b/utplsql-maven-plugin-it/src/it/resources/regex-project/expected-output/utplsql/sonar-test-reporter.xml similarity index 85% rename from utplsql-maven-plugin/src/test/resources/simple-project/expected-output/utplsql/sonar-test-reporter.xml rename to utplsql-maven-plugin-it/src/it/resources/regex-project/expected-output/utplsql/sonar-test-reporter.xml index 712cb69..6e6fad7 100644 --- a/utplsql-maven-plugin/src/test/resources/simple-project/expected-output/utplsql/sonar-test-reporter.xml +++ b/utplsql-maven-plugin-it/src/it/resources/regex-project/expected-output/utplsql/sonar-test-reporter.xml @@ -1,5 +1,5 @@ - + 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 new file mode 100644 index 0000000..cc7e20e --- /dev/null +++ b/utplsql-maven-plugin-it/src/it/resources/regex-project/pom.xml @@ -0,0 +1,82 @@ + + 4.0.0 + + 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 + + + + + false + + + app + + + + + 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/test + + **/*bdy + **/*spc + + + + .*(\\|\/)(\w+)(\\|\/)(\w+)(\\|\/)(\w+).(\w{3}) + 2 + 6 + 7 + + + + + + + + \ No newline at end of file diff --git a/utplsql-maven-plugin/src/test/resources/regex-project/scripts/sources/app/packages/PKG_TEST_ME.bdy b/utplsql-maven-plugin-it/src/it/resources/regex-project/scripts/sources/app/packages/PKG_TEST_ME.bdy similarity index 100% rename from utplsql-maven-plugin/src/test/resources/regex-project/scripts/sources/app/packages/PKG_TEST_ME.bdy rename to utplsql-maven-plugin-it/src/it/resources/regex-project/scripts/sources/app/packages/PKG_TEST_ME.bdy diff --git a/utplsql-maven-plugin/src/test/resources/regex-project/scripts/sources/app/packages/PKG_TEST_ME.spc b/utplsql-maven-plugin-it/src/it/resources/regex-project/scripts/sources/app/packages/PKG_TEST_ME.spc similarity index 100% rename from utplsql-maven-plugin/src/test/resources/regex-project/scripts/sources/app/packages/PKG_TEST_ME.spc rename to utplsql-maven-plugin-it/src/it/resources/regex-project/scripts/sources/app/packages/PKG_TEST_ME.spc diff --git a/utplsql-maven-plugin/src/test/resources/regex-project/scripts/sources/app/tables/TO_TEST_ME.tab b/utplsql-maven-plugin-it/src/it/resources/regex-project/scripts/sources/app/tables/TO_TEST_ME.tab similarity index 100% rename from utplsql-maven-plugin/src/test/resources/regex-project/scripts/sources/app/tables/TO_TEST_ME.tab rename to utplsql-maven-plugin-it/src/it/resources/regex-project/scripts/sources/app/tables/TO_TEST_ME.tab diff --git a/utplsql-maven-plugin/src/test/resources/regex-project/scripts/test/app/packages/TEST_PKG_TEST_ME.bdy b/utplsql-maven-plugin-it/src/it/resources/regex-project/scripts/test/app/packages/TEST_PKG_TEST_ME.bdy similarity index 100% rename from utplsql-maven-plugin/src/test/resources/regex-project/scripts/test/app/packages/TEST_PKG_TEST_ME.bdy rename to utplsql-maven-plugin-it/src/it/resources/regex-project/scripts/test/app/packages/TEST_PKG_TEST_ME.bdy diff --git a/utplsql-maven-plugin/src/test/resources/regex-project/scripts/test/app/packages/TEST_PKG_TEST_ME.spc b/utplsql-maven-plugin-it/src/it/resources/regex-project/scripts/test/app/packages/TEST_PKG_TEST_ME.spc similarity index 100% rename from utplsql-maven-plugin/src/test/resources/regex-project/scripts/test/app/packages/TEST_PKG_TEST_ME.spc rename to utplsql-maven-plugin-it/src/it/resources/regex-project/scripts/test/app/packages/TEST_PKG_TEST_ME.spc diff --git a/utplsql-maven-plugin/src/test/resources/regex-project/expected-output/utplsql/coverage-sonar-reporter.xml b/utplsql-maven-plugin-it/src/it/resources/simple-project/expected-output/utplsql/coverage-sonar-reporter.xml similarity index 81% rename from utplsql-maven-plugin/src/test/resources/regex-project/expected-output/utplsql/coverage-sonar-reporter.xml rename to utplsql-maven-plugin-it/src/it/resources/simple-project/expected-output/utplsql/coverage-sonar-reporter.xml index 79a7998..5824011 100644 --- a/utplsql-maven-plugin/src/test/resources/regex-project/expected-output/utplsql/coverage-sonar-reporter.xml +++ b/utplsql-maven-plugin-it/src/it/resources/simple-project/expected-output/utplsql/coverage-sonar-reporter.xml @@ -1,5 +1,5 @@ - + diff --git a/utplsql-maven-plugin/src/test/resources/regex-project/expected-output/utplsql/sonar-test-reporter.xml b/utplsql-maven-plugin-it/src/it/resources/simple-project/expected-output/utplsql/sonar-test-reporter.xml similarity index 84% rename from utplsql-maven-plugin/src/test/resources/regex-project/expected-output/utplsql/sonar-test-reporter.xml rename to utplsql-maven-plugin-it/src/it/resources/simple-project/expected-output/utplsql/sonar-test-reporter.xml index f3ce4f9..1908eac 100644 --- a/utplsql-maven-plugin/src/test/resources/regex-project/expected-output/utplsql/sonar-test-reporter.xml +++ b/utplsql-maven-plugin-it/src/it/resources/simple-project/expected-output/utplsql/sonar-test-reporter.xml @@ -1,5 +1,5 @@ - + 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 new file mode 100644 index 0000000..2e51a04 --- /dev/null +++ b/utplsql-maven-plugin-it/src/it/resources/simple-project/pom.xml @@ -0,0 +1,76 @@ + + 4.0.0 + + org.utplsql + utplsql-maven-plugin-simple-test + 1.0.0 + pom + + utplsql-maven-plugin IT Simple + + + + + + + + ${project.groupId} + utplsql-maven-plugin + ${utplsql-maven-plugin-version} + + + + test + + + + + false + + + app + + + + + 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/tests + + **/*bdy + **/*spc + + + + + + + + + + + + + \ No newline at end of file diff --git a/utplsql-maven-plugin/src/test/resources/simple-project/scripts/sources/APP.PKG_TEST_ME.bdy b/utplsql-maven-plugin-it/src/it/resources/simple-project/scripts/sources/APP.PKG_TEST_ME.bdy similarity index 94% rename from utplsql-maven-plugin/src/test/resources/simple-project/scripts/sources/APP.PKG_TEST_ME.bdy rename to utplsql-maven-plugin-it/src/it/resources/simple-project/scripts/sources/APP.PKG_TEST_ME.bdy index a2ff185..d7f60de 100644 --- a/utplsql-maven-plugin/src/test/resources/simple-project/scripts/sources/APP.PKG_TEST_ME.bdy +++ b/utplsql-maven-plugin-it/src/it/resources/simple-project/scripts/sources/APP.PKG_TEST_ME.bdy @@ -1,28 +1,28 @@ -CREATE OR REPLACE PACKAGE BODY PKG_TEST_ME IS - - -- - -- This - -- - FUNCTION FC_TEST_ME(PPARAM1 IN VARCHAR2) RETURN NUMBER IS - BEGIN - IF PPARAM1 IS NULL THEN - RETURN NULL; - ELSIF PPARAM1 = '1' THEN - RETURN 1; - ELSE - RETURN 0; - END IF; - END FC_TEST_ME; - - PROCEDURE PR_TEST_ME(PSNAME IN VARCHAR2) IS - BEGIN - IF PSNAME IS NULL THEN - NULL; - ELSE - INSERT INTO TO_TEST_ME (SNAME) VALUES (PSNAME); - COMMIT; - END IF; - END PR_TEST_ME; - -END PKG_TEST_ME; +CREATE OR REPLACE PACKAGE BODY PKG_TEST_ME IS + + -- + -- This + -- + FUNCTION FC_TEST_ME(PPARAM1 IN VARCHAR2) RETURN NUMBER IS + BEGIN + IF PPARAM1 IS NULL THEN + RETURN NULL; + ELSIF PPARAM1 = '1' THEN + RETURN 1; + ELSE + RETURN 0; + END IF; + END FC_TEST_ME; + + PROCEDURE PR_TEST_ME(PSNAME IN VARCHAR2) IS + BEGIN + IF PSNAME IS NULL THEN + NULL; + ELSE + INSERT INTO TO_TEST_ME (SNAME) VALUES (PSNAME); + COMMIT; + END IF; + END PR_TEST_ME; + +END PKG_TEST_ME; / \ No newline at end of file diff --git a/utplsql-maven-plugin/src/test/resources/simple-project/scripts/sources/APP.PKG_TEST_ME.spc b/utplsql-maven-plugin-it/src/it/resources/simple-project/scripts/sources/APP.PKG_TEST_ME.spc similarity index 97% rename from utplsql-maven-plugin/src/test/resources/simple-project/scripts/sources/APP.PKG_TEST_ME.spc rename to utplsql-maven-plugin-it/src/it/resources/simple-project/scripts/sources/APP.PKG_TEST_ME.spc index 67fe1f8..26b2589 100644 --- a/utplsql-maven-plugin/src/test/resources/simple-project/scripts/sources/APP.PKG_TEST_ME.spc +++ b/utplsql-maven-plugin-it/src/it/resources/simple-project/scripts/sources/APP.PKG_TEST_ME.spc @@ -1,8 +1,8 @@ --- --- This package is used TO demonstrate the utPL/SQL possibilities --- -CREATE OR REPLACE PACKAGE PKG_TEST_ME AS - FUNCTION FC_TEST_ME(PPARAM1 IN VARCHAR2) RETURN NUMBER; - PROCEDURE PR_TEST_ME(PSNAME IN VARCHAR2); -END PKG_TEST_ME; +-- +-- This package is used TO demonstrate the utPL/SQL possibilities +-- +CREATE OR REPLACE PACKAGE PKG_TEST_ME AS + FUNCTION FC_TEST_ME(PPARAM1 IN VARCHAR2) RETURN NUMBER; + PROCEDURE PR_TEST_ME(PSNAME IN VARCHAR2); +END PKG_TEST_ME; / \ No newline at end of file diff --git a/utplsql-maven-plugin/src/test/resources/type-mapping-project/scripts/sources/app/tables/TO_TEST_ME.tab b/utplsql-maven-plugin-it/src/it/resources/simple-project/scripts/sources/TO_TEST_ME.tab similarity index 100% rename from utplsql-maven-plugin/src/test/resources/type-mapping-project/scripts/sources/app/tables/TO_TEST_ME.tab rename to utplsql-maven-plugin-it/src/it/resources/simple-project/scripts/sources/TO_TEST_ME.tab diff --git a/utplsql-maven-plugin/src/test/resources/simple-project/scripts/tests/APP.TEST_PKG_TEST_ME.bdy b/utplsql-maven-plugin-it/src/it/resources/simple-project/scripts/tests/APP.TEST_PKG_TEST_ME.bdy similarity index 96% rename from utplsql-maven-plugin/src/test/resources/simple-project/scripts/tests/APP.TEST_PKG_TEST_ME.bdy rename to utplsql-maven-plugin-it/src/it/resources/simple-project/scripts/tests/APP.TEST_PKG_TEST_ME.bdy index 6f347b6..115bc15 100644 --- a/utplsql-maven-plugin/src/test/resources/simple-project/scripts/tests/APP.TEST_PKG_TEST_ME.bdy +++ b/utplsql-maven-plugin-it/src/it/resources/simple-project/scripts/tests/APP.TEST_PKG_TEST_ME.bdy @@ -1,126 +1,126 @@ -CREATE OR REPLACE PACKAGE BODY TEST_PKG_TEST_ME AS - - --------------------------------------------------------------------------- - PROCEDURE SETUP_GLOBAL IS - BEGIN - -- Put here the code which is valid for all tests and that should be - -- executed once. - NULL; - END SETUP_GLOBAL; - - --------------------------------------------------------------------------- - PROCEDURE TEARDOWN_GLOBAL IS - BEGIN - -- Put here the code that should be called only once after all the test - -- have executed - NULL; - END TEARDOWN_GLOBAL; - - --------------------------------------------------------------------------- - PROCEDURE SETUP_TEST IS - BEGIN - -- Nothing to clean up globally - NULL; - END SETUP_TEST; - - PROCEDURE TEARDOWN_TEST IS - BEGIN - -- Nothing to clean up globally - NULL; - END TEARDOWN_TEST; - - PROCEDURE TEST_FC_INPUT_1 IS - BEGIN - -- Ok this is a real test where I check that the function return 1 - -- when called with a '1' parameter - UT.EXPECT(PKG_TEST_ME.FC_TEST_ME('1')).TO_EQUAL(1); - END; - - PROCEDURE SETUP_TEST_FC_INPUT_1 IS - BEGIN - -- Nothing to be done really - NULL; - END; - - PROCEDURE TEARDOWN_TEST_FC_INPUT_1 IS - BEGIN - -- Nothing to be done really - NULL; - END; - - PROCEDURE TEST_FC_INPUT_0 IS - BEGIN - -- Ok this is a real test where I check that the function return 0 - -- when called with a '0' parameter - UT.EXPECT(PKG_TEST_ME.FC_TEST_ME('0')).TO_EQUAL(0); - END; - - PROCEDURE TEST_FC_INPUT_NULL IS - BEGIN - -- Ok I check that the function return NULL - -- when called with a NULL parameter - UT.EXPECT(PKG_TEST_ME.FC_TEST_ME(NULL)).TO_BE_NULL; - END TEST_FC_INPUT_NULL; - - PROCEDURE TEST_PR_TEST_ME_NULL IS - VNCOUNT1 PLS_INTEGER; - VNCOUNT2 PLS_INTEGER; - BEGIN - -- In this example I check that the procedure does - -- not insert anything when passing it a NULL parameter - SELECT COUNT(1) INTO VNCOUNT1 FROM TO_TEST_ME; - PKG_TEST_ME.PR_TEST_ME(NULL); - SELECT COUNT(1) INTO VNCOUNT2 FROM TO_TEST_ME; - UT.EXPECT(VNCOUNT1).TO_EQUAL(VNCOUNT2); - END; - - PROCEDURE TEST_PR_TEST_ME_NOT_NULL IS - VNCOUNT1 PLS_INTEGER; - VNCOUNT2 PLS_INTEGER; - VSNAME TO_TEST_ME.SNAME%TYPE; - BEGIN - -- In this test I will check that I do insert a value - -- when the parameter is not null. I futher check that - -- the procedure has inserted the value I specified. - SELECT COUNT(1) INTO VNCOUNT1 FROM TO_TEST_ME; - VSNAME := TO_CHAR(VNCOUNT1); - PKG_TEST_ME.PR_TEST_ME(VSNAME); - SELECT COUNT(1) INTO VNCOUNT2 FROM TO_TEST_ME; - - -- Check that I have inserted the value - UT.EXPECT(VNCOUNT1 + 1).TO_EQUAL(VNCOUNT2); - SELECT COUNT(1) INTO VNCOUNT2 FROM TO_TEST_ME T WHERE T.SNAME = VSNAME; - - -- Check that I inserted the one I said I would insert - UT.EXPECT(VNCOUNT2).TO_EQUAL(1); - DELETE FROM TO_TEST_ME T WHERE T.SNAME = VSNAME; - COMMIT; - END; - - PROCEDURE TEST_PR_TEST_ME_EXISTS IS - BEGIN - -- In case the value exists the procedure should fail with an exception. - BEGIN - PKG_TEST_ME.PR_TEST_ME('EXISTS'); - PKG_TEST_ME.PR_TEST_ME('EXISTS'); - EXCEPTION - WHEN OTHERS THEN - UT.FAIL('Unexpected exception raised'); - END; - END; - - PROCEDURE TEST_PR_TEST_ME_CURSOR IS - TYPE REF_CURSOR IS REF CURSOR; - VEXPECTED REF_CURSOR; - VACTUAL REF_CURSOR; - BEGIN - EXECUTE IMMEDIATE 'TRUNCATE TABLE TO_TEST_ME'; - OPEN VEXPECTED FOR - SELECT T.SNAME FROM TO_TEST_ME T; - OPEN VACTUAL FOR - SELECT T.SNAME FROM TO_TEST_ME T; - UT.EXPECT(VEXPECTED).TO_(EQUAL(VACTUAL)); - END; - -END; -/ +CREATE OR REPLACE PACKAGE BODY TEST_PKG_TEST_ME AS + + --------------------------------------------------------------------------- + PROCEDURE SETUP_GLOBAL IS + BEGIN + -- Put here the code which is valid for all tests and that should be + -- executed once. + NULL; + END SETUP_GLOBAL; + + --------------------------------------------------------------------------- + PROCEDURE TEARDOWN_GLOBAL IS + BEGIN + -- Put here the code that should be called only once after all the test + -- have executed + NULL; + END TEARDOWN_GLOBAL; + + --------------------------------------------------------------------------- + PROCEDURE SETUP_TEST IS + BEGIN + -- Nothing to clean up globally + NULL; + END SETUP_TEST; + + PROCEDURE TEARDOWN_TEST IS + BEGIN + -- Nothing to clean up globally + NULL; + END TEARDOWN_TEST; + + PROCEDURE TEST_FC_INPUT_1 IS + BEGIN + -- Ok this is a real test where I check that the function return 1 + -- when called with a '1' parameter + UT.EXPECT(PKG_TEST_ME.FC_TEST_ME('1')).TO_EQUAL(1); + END; + + PROCEDURE SETUP_TEST_FC_INPUT_1 IS + BEGIN + -- Nothing to be done really + NULL; + END; + + PROCEDURE TEARDOWN_TEST_FC_INPUT_1 IS + BEGIN + -- Nothing to be done really + NULL; + END; + + PROCEDURE TEST_FC_INPUT_0 IS + BEGIN + -- Ok this is a real test where I check that the function return 0 + -- when called with a '0' parameter + UT.EXPECT(PKG_TEST_ME.FC_TEST_ME('0')).TO_EQUAL(0); + END; + + PROCEDURE TEST_FC_INPUT_NULL IS + BEGIN + -- Ok I check that the function return NULL + -- when called with a NULL parameter + UT.EXPECT(PKG_TEST_ME.FC_TEST_ME(NULL)).TO_BE_NULL; + END TEST_FC_INPUT_NULL; + + PROCEDURE TEST_PR_TEST_ME_NULL IS + VNCOUNT1 PLS_INTEGER; + VNCOUNT2 PLS_INTEGER; + BEGIN + -- In this example I check that the procedure does + -- not insert anything when passing it a NULL parameter + SELECT COUNT(1) INTO VNCOUNT1 FROM TO_TEST_ME; + PKG_TEST_ME.PR_TEST_ME(NULL); + SELECT COUNT(1) INTO VNCOUNT2 FROM TO_TEST_ME; + UT.EXPECT(VNCOUNT1).TO_EQUAL(VNCOUNT2); + END; + + PROCEDURE TEST_PR_TEST_ME_NOT_NULL IS + VNCOUNT1 PLS_INTEGER; + VNCOUNT2 PLS_INTEGER; + VSNAME TO_TEST_ME.SNAME%TYPE; + BEGIN + -- In this test I will check that I do insert a value + -- when the parameter is not null. I futher check that + -- the procedure has inserted the value I specified. + SELECT COUNT(1) INTO VNCOUNT1 FROM TO_TEST_ME; + VSNAME := TO_CHAR(VNCOUNT1); + PKG_TEST_ME.PR_TEST_ME(VSNAME); + SELECT COUNT(1) INTO VNCOUNT2 FROM TO_TEST_ME; + + -- Check that I have inserted the value + UT.EXPECT(VNCOUNT1 + 1).TO_EQUAL(VNCOUNT2); + SELECT COUNT(1) INTO VNCOUNT2 FROM TO_TEST_ME T WHERE T.SNAME = VSNAME; + + -- Check that I inserted the one I said I would insert + UT.EXPECT(VNCOUNT2).TO_EQUAL(1); + DELETE FROM TO_TEST_ME T WHERE T.SNAME = VSNAME; + COMMIT; + END; + + PROCEDURE TEST_PR_TEST_ME_EXISTS IS + BEGIN + -- In case the value exists the procedure should fail with an exception. + BEGIN + PKG_TEST_ME.PR_TEST_ME('EXISTS'); + PKG_TEST_ME.PR_TEST_ME('EXISTS'); + EXCEPTION + WHEN OTHERS THEN + UT.FAIL('Unexpected exception raised'); + END; + END; + + PROCEDURE TEST_PR_TEST_ME_CURSOR IS + TYPE REF_CURSOR IS REF CURSOR; + VEXPECTED REF_CURSOR; + VACTUAL REF_CURSOR; + BEGIN + EXECUTE IMMEDIATE 'TRUNCATE TABLE TO_TEST_ME'; + OPEN VEXPECTED FOR + SELECT T.SNAME FROM TO_TEST_ME T; + OPEN VACTUAL FOR + SELECT T.SNAME FROM TO_TEST_ME T; + UT.EXPECT(VEXPECTED).TO_(EQUAL(VACTUAL)); + END; + +END; +/ diff --git a/utplsql-maven-plugin/src/test/resources/simple-project/scripts/tests/APP.TEST_PKG_TEST_ME.spc b/utplsql-maven-plugin-it/src/it/resources/simple-project/scripts/tests/APP.TEST_PKG_TEST_ME.spc similarity index 96% rename from utplsql-maven-plugin/src/test/resources/simple-project/scripts/tests/APP.TEST_PKG_TEST_ME.spc rename to utplsql-maven-plugin-it/src/it/resources/simple-project/scripts/tests/APP.TEST_PKG_TEST_ME.spc index 86ae400..e2c82fa 100644 --- a/utplsql-maven-plugin/src/test/resources/simple-project/scripts/tests/APP.TEST_PKG_TEST_ME.spc +++ b/utplsql-maven-plugin-it/src/it/resources/simple-project/scripts/tests/APP.TEST_PKG_TEST_ME.spc @@ -1,86 +1,86 @@ -CREATE OR REPLACE PACKAGE TEST_PKG_TEST_ME AS - -- %suite(TEST_PKG_TEST_ME) - -- %suitepath(plsql.examples) - -- - -- This package shows all the possibilities to unit test - -- your PL/SQL package. NOTE that it is not limited to - -- testing your package. You can do that on all your - -- procedure/functions... - -- - - /** - * This two parameters are used by the test framework in - * order to identify the test suite to run - */ - - /* - * This method is invoked once before any other method. - * It should contain all the setup code that is relevant - * for all your test. It might be inserting a register, - * creating a type, etc... - */ - -- %beforeall - PROCEDURE SETUP_GLOBAL; - - /* - * This method is invoked once after all other method. - * It can be used to clean up all the resources that - * you created in your script - */ - -- %afterall - PROCEDURE TEARDOWN_GLOBAL; - - /* - * This method is called once before each test. - */ - -- %beforeeach - PROCEDURE SETUP_TEST; - - /* - * This method is called once after each test. - */ - -- %aftereach - PROCEDURE TEARDOWN_TEST; - - /** - * This is a real test. The main test can declare a setup - * and teardown method in order to setup and cleanup things - * for that specific test. - */ - -- %test - -- %displayname(Checking if function ('1') returns 1) - -- %beforetest(SETUP_TEST_FC_INPUT_1) - -- %aftertest(TEARDOWN_TEST_FC_INPUT_1) - PROCEDURE TEST_FC_INPUT_1; - PROCEDURE SETUP_TEST_FC_INPUT_1; - PROCEDURE TEARDOWN_TEST_FC_INPUT_1; - - -- %test - -- %displayname(Checking if function ('0') returns 0) - PROCEDURE TEST_FC_INPUT_0; - - -- %test - -- %displayname(Checking if function (NULL) returns NULL) - PROCEDURE TEST_FC_INPUT_NULL; - - -- %test - -- %displayname(Checking if procedure (NULL) insert) - PROCEDURE TEST_PR_TEST_ME_NULL; - - -- %test - -- %displayname(Checking if procedure (NOT NULL) insert) - -- %rollback(manual) - PROCEDURE TEST_PR_TEST_ME_NOT_NULL; - - -- %test - -- %displayname(Checking if procedure (NOT NULL) insert while existing) - -- %rollback(manual) - PROCEDURE TEST_PR_TEST_ME_EXISTS; - - -- %test - -- %displayname(Demonstrating the use of cursor) - -- %rollback(manual) - PROCEDURE TEST_PR_TEST_ME_CURSOR; - -END; -/ +CREATE OR REPLACE PACKAGE TEST_PKG_TEST_ME AS + -- %suite(TEST_PKG_TEST_ME) + -- %suitepath(plsql.examples) + -- + -- This package shows all the possibilities to unit test + -- your PL/SQL package. NOTE that it is not limited to + -- testing your package. You can do that on all your + -- procedure/functions... + -- + + /** + * This two parameters are used by the test framework in + * order to identify the test suite to run + */ + + /* + * This method is invoked once before any other method. + * It should contain all the setup code that is relevant + * for all your test. It might be inserting a register, + * creating a type, etc... + */ + -- %beforeall + PROCEDURE SETUP_GLOBAL; + + /* + * This method is invoked once after all other method. + * It can be used to clean up all the resources that + * you created in your script + */ + -- %afterall + PROCEDURE TEARDOWN_GLOBAL; + + /* + * This method is called once before each test. + */ + -- %beforeeach + PROCEDURE SETUP_TEST; + + /* + * This method is called once after each test. + */ + -- %aftereach + PROCEDURE TEARDOWN_TEST; + + /** + * This is a real test. The main test can declare a setup + * and teardown method in order to setup and cleanup things + * for that specific test. + */ + -- %test + -- %displayname(Checking if function ('1') returns 1) + -- %beforetest(SETUP_TEST_FC_INPUT_1) + -- %aftertest(TEARDOWN_TEST_FC_INPUT_1) + PROCEDURE TEST_FC_INPUT_1; + PROCEDURE SETUP_TEST_FC_INPUT_1; + PROCEDURE TEARDOWN_TEST_FC_INPUT_1; + + -- %test + -- %displayname(Checking if function ('0') returns 0) + PROCEDURE TEST_FC_INPUT_0; + + -- %test + -- %displayname(Checking if function (NULL) returns NULL) + PROCEDURE TEST_FC_INPUT_NULL; + + -- %test + -- %displayname(Checking if procedure (NULL) insert) + PROCEDURE TEST_PR_TEST_ME_NULL; + + -- %test + -- %displayname(Checking if procedure (NOT NULL) insert) + -- %rollback(manual) + PROCEDURE TEST_PR_TEST_ME_NOT_NULL; + + -- %test + -- %displayname(Checking if procedure (NOT NULL) insert while existing) + -- %rollback(manual) + PROCEDURE TEST_PR_TEST_ME_EXISTS; + + -- %test + -- %displayname(Demonstrating the use of cursor) + -- %rollback(manual) + PROCEDURE TEST_PR_TEST_ME_CURSOR; + +END; +/ diff --git a/utplsql-maven-plugin/src/test/resources/type-mapping-project/expected-output/utplsql/coverage-sonar-reporter.xml b/utplsql-maven-plugin-it/src/it/resources/type-mapping-project/expected-output/utplsql/coverage-sonar-reporter.xml similarity index 79% rename from utplsql-maven-plugin/src/test/resources/type-mapping-project/expected-output/utplsql/coverage-sonar-reporter.xml rename to utplsql-maven-plugin-it/src/it/resources/type-mapping-project/expected-output/utplsql/coverage-sonar-reporter.xml index 65ddd2b..f046682 100644 --- a/utplsql-maven-plugin/src/test/resources/type-mapping-project/expected-output/utplsql/coverage-sonar-reporter.xml +++ b/utplsql-maven-plugin-it/src/it/resources/type-mapping-project/expected-output/utplsql/coverage-sonar-reporter.xml @@ -1,5 +1,5 @@ - + diff --git a/utplsql-maven-plugin/src/test/resources/type-mapping-project/expected-output/utplsql/sonar-test-reporter.xml b/utplsql-maven-plugin-it/src/it/resources/type-mapping-project/expected-output/utplsql/sonar-test-reporter.xml similarity index 82% rename from utplsql-maven-plugin/src/test/resources/type-mapping-project/expected-output/utplsql/sonar-test-reporter.xml rename to utplsql-maven-plugin-it/src/it/resources/type-mapping-project/expected-output/utplsql/sonar-test-reporter.xml index 84e9996..cd174ad 100644 --- a/utplsql-maven-plugin/src/test/resources/type-mapping-project/expected-output/utplsql/sonar-test-reporter.xml +++ b/utplsql-maven-plugin-it/src/it/resources/type-mapping-project/expected-output/utplsql/sonar-test-reporter.xml @@ -1,5 +1,5 @@ - + 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 new file mode 100644 index 0000000..92f4819 --- /dev/null +++ b/utplsql-maven-plugin-it/src/it/resources/type-mapping-project/pom.xml @@ -0,0 +1,92 @@ + + 4.0.0 + + org.utplsql + utplsql-maven-plugin-type-mapping-test + 1.0.0 + + pom + + utplsql-maven-plugin IT Type Mapping + + + + + + + + ${project.groupId} + utplsql-maven-plugin + ${utplsql-maven-plugin-version} + + + + test + + + + + false + + + app + + + + + 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/test + + **/*sql + + + + .*/(\w+)/(\w+)/(\w+)\.\w{3} + 1 + 3 + 2 + + + package body + package_bodies + + + + + + + + + \ No newline at end of file diff --git a/utplsql-maven-plugin/src/test/resources/type-mapping-project/scripts/sources/app/package_bodies/PKG_TEST_ME.sql b/utplsql-maven-plugin-it/src/it/resources/type-mapping-project/scripts/sources/app/package_bodies/PKG_TEST_ME.sql similarity index 100% rename from utplsql-maven-plugin/src/test/resources/type-mapping-project/scripts/sources/app/package_bodies/PKG_TEST_ME.sql rename to utplsql-maven-plugin-it/src/it/resources/type-mapping-project/scripts/sources/app/package_bodies/PKG_TEST_ME.sql diff --git a/utplsql-maven-plugin/src/test/resources/type-mapping-project/scripts/sources/app/packages/PKG_TEST_ME.sql b/utplsql-maven-plugin-it/src/it/resources/type-mapping-project/scripts/sources/app/packages/PKG_TEST_ME.sql similarity index 100% rename from utplsql-maven-plugin/src/test/resources/type-mapping-project/scripts/sources/app/packages/PKG_TEST_ME.sql rename to utplsql-maven-plugin-it/src/it/resources/type-mapping-project/scripts/sources/app/packages/PKG_TEST_ME.sql diff --git a/utplsql-maven-plugin/src/test/resources/simple-project/scripts/sources/TO_TEST_ME.tab b/utplsql-maven-plugin-it/src/it/resources/type-mapping-project/scripts/sources/app/tables/TO_TEST_ME.tab similarity index 93% rename from utplsql-maven-plugin/src/test/resources/simple-project/scripts/sources/TO_TEST_ME.tab rename to utplsql-maven-plugin-it/src/it/resources/type-mapping-project/scripts/sources/app/tables/TO_TEST_ME.tab index 1cd6f12..b2e90d9 100644 --- a/utplsql-maven-plugin/src/test/resources/simple-project/scripts/sources/TO_TEST_ME.tab +++ b/utplsql-maven-plugin-it/src/it/resources/type-mapping-project/scripts/sources/app/tables/TO_TEST_ME.tab @@ -1,8 +1,8 @@ --- --- This is a table used to demonstrate the UNIT test framework. --- -CREATE TABLE TO_TEST_ME -( - SNAME VARCHAR2(10) -) -/ +-- +-- This is a table used to demonstrate the UNIT test framework. +-- +CREATE TABLE TO_TEST_ME +( + SNAME VARCHAR2(10) +) +/ diff --git a/utplsql-maven-plugin/src/test/resources/type-mapping-project/scripts/test/app/package_bodies/TEST_PKG_TEST_ME.sql b/utplsql-maven-plugin-it/src/it/resources/type-mapping-project/scripts/test/app/package_bodies/TEST_PKG_TEST_ME.sql similarity index 100% rename from utplsql-maven-plugin/src/test/resources/type-mapping-project/scripts/test/app/package_bodies/TEST_PKG_TEST_ME.sql rename to utplsql-maven-plugin-it/src/it/resources/type-mapping-project/scripts/test/app/package_bodies/TEST_PKG_TEST_ME.sql diff --git a/utplsql-maven-plugin/src/test/resources/type-mapping-project/scripts/test/app/packages/TEST_PKG_TEST_ME.sql b/utplsql-maven-plugin-it/src/it/resources/type-mapping-project/scripts/test/app/packages/TEST_PKG_TEST_ME.sql similarity index 100% rename from utplsql-maven-plugin/src/test/resources/type-mapping-project/scripts/test/app/packages/TEST_PKG_TEST_ME.sql rename to utplsql-maven-plugin-it/src/it/resources/type-mapping-project/scripts/test/app/packages/TEST_PKG_TEST_ME.sql diff --git a/utplsql-maven-plugin/pom.xml b/utplsql-maven-plugin/pom.xml index c0628df..5dbbf0c 100644 --- a/utplsql-maven-plugin/pom.xml +++ b/utplsql-maven-plugin/pom.xml @@ -1,12 +1,16 @@ - 4.0.0 + + org.utplsql + utplsql-maven-plugin-parent + 3.1.0-SNAPSHOT + - org.utplsql utplsql-maven-plugin maven-plugin - 3.1.0-SNAPSHOT utplsql-maven-plugin Maven Plugin @@ -50,6 +54,8 @@ + + org.apache.maven.plugin-testing diff --git a/utplsql-maven-plugin/src/test/java/org/utpsql/maven/plugin/test/UtPLSQLMojoTest.java b/utplsql-maven-plugin/src/test/java/org/utpsql/maven/plugin/test/UtPLSQLMojoTest.java deleted file mode 100644 index 7695c8b..0000000 --- a/utplsql-maven-plugin/src/test/java/org/utpsql/maven/plugin/test/UtPLSQLMojoTest.java +++ /dev/null @@ -1,117 +0,0 @@ -package org.utpsql.maven.plugin.test; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import org.apache.commons.io.FileUtils; -import org.apache.maven.plugin.testing.MojoRule; -import org.junit.Assert; -import org.junit.Rule; -import org.junit.Test; -import org.utplsql.maven.plugin.UtPLSQLMojo; - -public class UtPLSQLMojoTest -{ - public static final String TARGET_DIRECTORY = "target/test-classes"; - - @Rule - public MojoRule rule = new MojoRule(); - - @Test - public void testDefinition() throws Exception - { - - try - { - final String PROJECT_NAME = "simple-project"; - UtPLSQLMojo myMojo = (UtPLSQLMojo) rule.lookupConfiguredMojo(new File(TARGET_DIRECTORY+"/"+PROJECT_NAME), "test"); - - Assert.assertNotNull(myMojo); - myMojo.execute(); - - checkReportsGenerated(PROJECT_NAME,"utplsql/coverage-sonar-reporter.xml", "utplsql/sonar-test-reporter.xml"); - } - catch (Exception e) - { - e.printStackTrace(); - Assert.fail("Unexpected Exception running the test of Definition"); - } - } - - @Test - public void testRegexDefinition() throws Exception - { - try - { - final String PROJECT_NAME = "regex-project"; - UtPLSQLMojo myMojo = (UtPLSQLMojo) rule.lookupConfiguredMojo(new File(TARGET_DIRECTORY+"/"+PROJECT_NAME), "test"); - - Assert.assertNotNull(myMojo); - myMojo.execute(); - - checkReportsGenerated(PROJECT_NAME,"utplsql/coverage-sonar-reporter.xml", "utplsql/sonar-test-reporter.xml"); - } - catch (Exception e) - { - e.printStackTrace(); - Assert.fail("Unexpected Exception running the test of Definition"); - } - } - - @Test - public void testTypeMappingDefinition() throws Exception - { - try - { - final String PROJECT_NAME = "type-mapping-project"; - UtPLSQLMojo myMojo = (UtPLSQLMojo) rule.lookupConfiguredMojo(new File(TARGET_DIRECTORY+"/"+PROJECT_NAME), "test"); - - Assert.assertNotNull(myMojo); - myMojo.execute(); - - checkReportsGenerated(PROJECT_NAME,"utplsql/coverage-sonar-reporter.xml", "utplsql/sonar-test-reporter.xml"); - } - catch (Exception e) - { - e.printStackTrace(); - Assert.fail("Unexpected Exception running the test of Definition"); - } - } - - /** - * - * @param files - */ - private void checkReportsGenerated(String projectName, String... files) - { - for (String filename : files) - { - File outputFile = new File(TARGET_DIRECTORY+"/"+projectName+"/target/", filename); - File expectedOutputFile = new File(TARGET_DIRECTORY+"/"+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_DIRECTORY,projectName,"target",filename)); - String outputContent = stream.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!", - outputContent, - FileUtils.readFileToString(expectedOutputFile, "utf-8").replace("\r","")); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - Assert.fail("Unexpected Exception running the test of Definition"); - } - } - } -} diff --git a/utplsql-maven-plugin/src/test/resources/regex-project/pom.xml b/utplsql-maven-plugin/src/test/resources/regex-project/pom.xml deleted file mode 100644 index cbf04a8..0000000 --- a/utplsql-maven-plugin/src/test/resources/regex-project/pom.xml +++ /dev/null @@ -1,85 +0,0 @@ - - 4.0.0 - - org.utplsql - utplsql-maven-plugin-test - 1.0.0-SNAPSHOT - maven-plugin - - utplsql-maven-plugin Maven Plugin Test - - - - jdbc:oracle:thin:@127.0.0.1:1521:xe - - - - - - - - ${pom.groupId} - utplsql-maven-plugin - ${pom.version} - - test - - - - - false - - - app - - - - - UT_COVERAGE_SONAR_REPORTER - utplsql/coverage-sonar-reporter.xml - true - - - UT_SONAR_TEST_REPORTER - utplsql/sonar-test-reporter.xml - true - - - - - - src/test/resources/regex-project/scripts/sources - - **/*bdy - **/*spc - - - - .*(\\|\/)(\w+)(\\|\/)(\w+)(\\|\/)(\w+).(\w{3}) - 2 - 6 - 7 - - - - src/test/resources/regex-project/scripts/test - - **/*bdy - **/*spc - - - - .*(\\|\/)(\w+)(\\|\/)(\w+)(\\|\/)(\w+).(\w{3}) - 2 - 6 - 7 - - - - - - \ No newline at end of file diff --git a/utplsql-maven-plugin/src/test/resources/simple-project/pom.xml b/utplsql-maven-plugin/src/test/resources/simple-project/pom.xml deleted file mode 100644 index 3cbd422..0000000 --- a/utplsql-maven-plugin/src/test/resources/simple-project/pom.xml +++ /dev/null @@ -1,76 +0,0 @@ - - 4.0.0 - - org.utplsql - utplsql-maven-plugin-test - 1.0.0-SNAPSHOT - maven-plugin - - utplsql-maven-plugin Maven Plugin Test - - - - jdbc:oracle:thin:@127.0.0.1:1521:xe - - - - - - - ${pom.groupId} - utplsql-maven-plugin - ${pom.version} - - test - - - - - false - - - app - - - - - UT_COVERAGE_SONAR_REPORTER - utplsql/coverage-sonar-reporter.xml - true - - - UT_SONAR_TEST_REPORTER - utplsql/sonar-test-reporter.xml - true - - - - - - src/test/resources/simple-project/scripts/sources - - **/*bdy - **/*spc - - - - - - - src/test/resources/simple-project/scripts/tests - - **/*bdy - **/*spc - - - - - - - - - \ No newline at end of file diff --git a/utplsql-maven-plugin/src/test/resources/type-mapping-project/pom.xml b/utplsql-maven-plugin/src/test/resources/type-mapping-project/pom.xml deleted file mode 100644 index 42312f9..0000000 --- a/utplsql-maven-plugin/src/test/resources/type-mapping-project/pom.xml +++ /dev/null @@ -1,94 +0,0 @@ - - 4.0.0 - - org.utplsql - utplsql-maven-plugin-test - 1.0.0-SNAPSHOT - maven-plugin - - utplsql-maven-plugin Maven Plugin Test - - - - jdbc:oracle:thin:@127.0.0.1:1521:xe - - - - - - - - ${pom.groupId} - utplsql-maven-plugin - ${pom.version} - - test - - - - - false - - - app - - - - - UT_COVERAGE_SONAR_REPORTER - utplsql/coverage-sonar-reporter.xml - true - - - UT_SONAR_TEST_REPORTER - utplsql/sonar-test-reporter.xml - true - - - - - - src/test/resources/type-mapping-project/scripts/sources - - **/*sql - - - - .*/(\w+)/(\w+)/(\w+)\.\w{3} - 1 - 3 - 2 - - - package body - package_bodies - - - - - - src/test/resources/type-mapping-project/scripts/test - - **/*sql - - - - .*/(\w+)/(\w+)/(\w+)\.\w{3} - 1 - 3 - 2 - - - package body - package_bodies - - - - - - - \ No newline at end of file From ef684c2a8114e19be4583ac37e1d9c9d64ba83a0 Mon Sep 17 00:00:00 2001 From: Jerome Garec Date: Thu, 7 Jun 2018 13:06:33 +0200 Subject: [PATCH 46/71] Upgrade java-api to latest snapshot * Add new logs : UTPLSQL version & java-api version --- utplsql-maven-plugin/pom.xml | 2 +- .../src/main/java/org/utplsql/maven/plugin/UtPLSQLMojo.java | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/utplsql-maven-plugin/pom.xml b/utplsql-maven-plugin/pom.xml index 5dbbf0c..363be2c 100644 --- a/utplsql-maven-plugin/pom.xml +++ b/utplsql-maven-plugin/pom.xml @@ -25,7 +25,7 @@ org.utplsql java-api - 3.1.0 + 3.1.1-SNAPSHOT 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 c2e5a25..ca10eef 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 @@ -16,6 +16,7 @@ import org.apache.maven.plugins.annotations.Parameter; import org.utplsql.api.DBHelper; import org.utplsql.api.FileMapperOptions; +import org.utplsql.api.JavaApiVersionInfo; import org.utplsql.api.KeyValuePair; import org.utplsql.api.TestRunner; import org.utplsql.api.Version; @@ -124,6 +125,7 @@ public class UtPLSQLMojo extends AbstractMojo @Override public void execute() throws MojoExecutionException { + getLog().debug("Java Api Version = "+JavaApiVersionInfo.getVersion()); loadDefaultCredentials(); Connection connection = null; @@ -134,6 +136,7 @@ public void execute() throws MojoExecutionException // Create the Connection to the Database connection = DriverManager.getConnection(url, user, password); + getLog().info("utPLSQL Version = "+DBHelper.getDatabaseFrameworkVersion(connection)); List reporterList = initReporters(connection); From 47116e7c31801b05384c687d0c3c26c83e4e2341 Mon Sep 17 00:00:00 2001 From: Jerome Garec Date: Thu, 7 Jun 2018 13:14:19 +0200 Subject: [PATCH 47/71] DbURL can be configured with an environment variable --- .../java/org/utplsql/maven/plugin/UtPLSQLMojo.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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 ca10eef..b9a6f00 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 @@ -126,7 +126,7 @@ public class UtPLSQLMojo extends AbstractMojo public void execute() throws MojoExecutionException { getLog().debug("Java Api Version = "+JavaApiVersionInfo.getVersion()); - loadDefaultCredentials(); + loadConfFromEnvironment(); Connection connection = null; try @@ -190,11 +190,16 @@ public void execute() throws MojoExecutionException } /** - * Load + * Load some configuration from env variables. * */ - private void loadDefaultCredentials () + private void loadConfFromEnvironment () { + if (StringUtils.isEmpty(url)) + { + url = System.getProperty("dbUrl"); + } + if (StringUtils.isEmpty(user)) { user = System.getProperty("dbUser"); From e49b4cdd23c5a0b31b019a290d4f2ceb22a9e072 Mon Sep 17 00:00:00 2001 From: Jerome Garec Date: Fri, 29 Jun 2018 21:07:38 +0200 Subject: [PATCH 48/71] Adds owners parameters for #5 * Adds 2 new parameters : sourcesOwner / testsOwner * Adds 1 new project sample (owner-param-project) * Refactor travis build (run tests with ut3 user) * Improve documentation --- .travis.yml | 9 +- .travis/create_api_user.sh | 17 -- .travis/install_demo_owner_project.sh | 50 ++++ .travis/install_demo_project.sh | 2 + .travis/install_utplsql.sh | 16 +- README.md | 44 +++- .../maven/plugin/test/UtPLSQLMojoIT.java | 243 +++++++++--------- .../utplsql/coverage-sonar-reporter.xml | 12 + .../utplsql/sonar-test-reporter.xml | 18 ++ .../it/resources/owner-param-project/pom.xml | 89 +++++++ .../foo/package_bodies/PKG_TEST_ME.sql | 28 ++ .../sources/foo/packages/PKG_TEST_ME.sql | 8 + .../scripts/sources/foo/tables/TO_TEST_ME.tab | 8 + .../bar/package_bodies/TEST_PKG_TEST_ME.sql | 126 +++++++++ .../test/bar/packages/TEST_PKG_TEST_ME.sql | 86 +++++++ .../org/utplsql/maven/plugin/UtPLSQLMojo.java | 20 +- 16 files changed, 630 insertions(+), 146 deletions(-) delete mode 100644 .travis/create_api_user.sh create mode 100644 .travis/install_demo_owner_project.sh create mode 100644 utplsql-maven-plugin-it/src/it/resources/owner-param-project/expected-output/utplsql/coverage-sonar-reporter.xml create mode 100644 utplsql-maven-plugin-it/src/it/resources/owner-param-project/expected-output/utplsql/sonar-test-reporter.xml create mode 100644 utplsql-maven-plugin-it/src/it/resources/owner-param-project/pom.xml create mode 100644 utplsql-maven-plugin-it/src/it/resources/owner-param-project/scripts/sources/foo/package_bodies/PKG_TEST_ME.sql create mode 100644 utplsql-maven-plugin-it/src/it/resources/owner-param-project/scripts/sources/foo/packages/PKG_TEST_ME.sql create mode 100644 utplsql-maven-plugin-it/src/it/resources/owner-param-project/scripts/sources/foo/tables/TO_TEST_ME.tab create mode 100644 utplsql-maven-plugin-it/src/it/resources/owner-param-project/scripts/test/bar/package_bodies/TEST_PKG_TEST_ME.sql create mode 100644 utplsql-maven-plugin-it/src/it/resources/owner-param-project/scripts/test/bar/packages/TEST_PKG_TEST_ME.sql diff --git a/.travis.yml b/.travis.yml index 6ed1b72..a4b623b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,8 +15,8 @@ env: - MAVEN_HOME=/usr/local/maven - MAVEN_CFG=$HOME/.m2 - DB_URL="127.0.0.1:1521:XE" - - DB_USER=app - - DB_PASS=app + - DB_UT3_USER=ut3 + - DB_UT3_PASS=ut3 - ORACLE_VERSION="11g-r2-xe" - DOCKER_OPTIONS="--shm-size=1g" @@ -29,14 +29,15 @@ cache: install: - bash .travis/maven_cfg.sh - bash .travis/start_db.sh - - bash .travis/install_utplsql.sh + - bash .travis/install_utplsql.sh $DB_UT3_USER $DB_UT3_PASS - bash .travis/install_demo_project.sh + - bash .travis/install_demo_owner_project.sh script: - echo "Run Unit tests" - mvn test - echo "Run Integration tests" - - mvn verify -Dmaven.skip.test -DdbUser="${DB_USER}" -DdbPass="${DB_PASS}" -DdbUrl="jdbc:oracle:thin:@${DB_URL}" + - mvn verify -Dmaven.skip.test -DdbUser="${DB_UT3_USER}" -DdbPass="${DB_UT3_PASS}" -DdbUrl="jdbc:oracle:thin:@${DB_URL}" #before_deploy: # - bash .travis/create_release.sh diff --git a/.travis/create_api_user.sh b/.travis/create_api_user.sh deleted file mode 100644 index c898f15..0000000 --- a/.travis/create_api_user.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash -set -ev - -sqlplus -S -L sys/oracle@//127.0.0.1:1521/xe AS SYSDBA < demo_project.sh.tmp < demo_project.sh.tmp < install.sh.tmp < org.utplsql utplsql-maven-plugin - 1.0.0-SNAPSHOT + 3.1.0 test @@ -73,7 +108,10 @@ The next snippet is a sample of declaration of the pom url_of_connection user password - false + false + + schema_name + UT_COVERAGE_SONAR_REPORTER @@ -115,3 +153,5 @@ 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/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 ca902e8..203af8a 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 @@ -19,145 +19,152 @@ import org.junit.BeforeClass; import org.junit.Test; -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()); - - // delete plugin - //verifier.deleteArtifact( model.getGroupId(), model.getArtifactId(), model.getVersion(), "pom" ); - - // install plugin - verifier.setAutoclean(false); - verifier.addCliOption("-Dmaven.skip.test=true"); - verifier.addCliOption("-DskipITs"); - verifier.executeGoal("install"); - - pluginVersion = model.getVersion(); - } +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 testSimpleDefinition() throws Exception - { + public void testSimpleProject() throws Exception { - try - { + try { final String PROJECT_NAME = "simple-project"; - File testProject = ResourceExtractor.simpleExtractResources(getClass(), "/"+ PROJECT_NAME); + 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.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"); + + 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()); } - catch (Exception e) - { + } + + @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 of Definition "+e.getMessage()); + Assert.fail("Unexpected Exception running the test : " + e.getMessage()); } } - + @Test - public void testRegexDefinition() 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 of Definition"); - } - } - + 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 testTypeMappingDefinition() 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 of Definition"); - } - } + public void testOwnerParameterProject() 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()); + } + } /** * * @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("(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!", - outputContent, - FileUtils.readFileToString(expectedOutputFile, "utf-8").replace("\r","")); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - Assert.fail("Unexpected Exception running the test of Definition"); - } + 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("(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!", outputContent, + FileUtils.readFileToString(expectedOutputFile, "utf-8").replace("\r", "")); + } 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/owner-param-project/expected-output/utplsql/coverage-sonar-reporter.xml b/utplsql-maven-plugin-it/src/it/resources/owner-param-project/expected-output/utplsql/coverage-sonar-reporter.xml new file mode 100644 index 0000000..ee91996 --- /dev/null +++ b/utplsql-maven-plugin-it/src/it/resources/owner-param-project/expected-output/utplsql/coverage-sonar-reporter.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/utplsql-maven-plugin-it/src/it/resources/owner-param-project/expected-output/utplsql/sonar-test-reporter.xml b/utplsql-maven-plugin-it/src/it/resources/owner-param-project/expected-output/utplsql/sonar-test-reporter.xml new file mode 100644 index 0000000..ac04b30 --- /dev/null +++ b/utplsql-maven-plugin-it/src/it/resources/owner-param-project/expected-output/utplsql/sonar-test-reporter.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ 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 new file mode 100644 index 0000000..abf7f0b --- /dev/null +++ b/utplsql-maven-plugin-it/src/it/resources/owner-param-project/pom.xml @@ -0,0 +1,89 @@ + + 4.0.0 + + org.utplsql + utplsql-maven-plugin-owner-parameter-test + 1.0.0 + pom + + utplsql-maven-plugin IT Owner Parameter + + + + + + + + + ${project.groupId} + utplsql-maven-plugin + ${utplsql-maven-plugin-version} + + test + + + + + false + + + tests_owner + + + + + 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/test + + **/*sql + + + + tests_owner + .*/\w+/(\w+)/(\w+)\.\w{3} + 2 + 1 + + + package body + package_bodies + + + + + + + \ No newline at end of file diff --git a/utplsql-maven-plugin-it/src/it/resources/owner-param-project/scripts/sources/foo/package_bodies/PKG_TEST_ME.sql b/utplsql-maven-plugin-it/src/it/resources/owner-param-project/scripts/sources/foo/package_bodies/PKG_TEST_ME.sql new file mode 100644 index 0000000..894119f --- /dev/null +++ b/utplsql-maven-plugin-it/src/it/resources/owner-param-project/scripts/sources/foo/package_bodies/PKG_TEST_ME.sql @@ -0,0 +1,28 @@ +CREATE OR REPLACE PACKAGE BODY CODE_OWNER.PKG_TEST_ME IS + + -- + -- This + -- + FUNCTION FC_TEST_ME(PPARAM1 IN VARCHAR2) RETURN NUMBER IS + BEGIN + IF PPARAM1 IS NULL THEN + RETURN NULL; + ELSIF PPARAM1 = '1' THEN + RETURN 1; + ELSE + RETURN 0; + END IF; + END FC_TEST_ME; + + PROCEDURE PR_TEST_ME(PSNAME IN VARCHAR2) IS + BEGIN + IF PSNAME IS NULL THEN + NULL; + ELSE + INSERT INTO TO_TEST_ME (SNAME) VALUES (PSNAME); + COMMIT; + END IF; + END PR_TEST_ME; + +END PKG_TEST_ME; +/ \ No newline at end of file diff --git a/utplsql-maven-plugin-it/src/it/resources/owner-param-project/scripts/sources/foo/packages/PKG_TEST_ME.sql b/utplsql-maven-plugin-it/src/it/resources/owner-param-project/scripts/sources/foo/packages/PKG_TEST_ME.sql new file mode 100644 index 0000000..959b122 --- /dev/null +++ b/utplsql-maven-plugin-it/src/it/resources/owner-param-project/scripts/sources/foo/packages/PKG_TEST_ME.sql @@ -0,0 +1,8 @@ +-- +-- This package is used TO demonstrate the utPL/SQL possibilities +-- +CREATE OR REPLACE PACKAGE CODE_OWNER.PKG_TEST_ME AS + FUNCTION FC_TEST_ME(PPARAM1 IN VARCHAR2) RETURN NUMBER; + PROCEDURE PR_TEST_ME(PSNAME IN VARCHAR2); +END PKG_TEST_ME; +/ \ No newline at end of file diff --git a/utplsql-maven-plugin-it/src/it/resources/owner-param-project/scripts/sources/foo/tables/TO_TEST_ME.tab b/utplsql-maven-plugin-it/src/it/resources/owner-param-project/scripts/sources/foo/tables/TO_TEST_ME.tab new file mode 100644 index 0000000..b2e90d9 --- /dev/null +++ b/utplsql-maven-plugin-it/src/it/resources/owner-param-project/scripts/sources/foo/tables/TO_TEST_ME.tab @@ -0,0 +1,8 @@ +-- +-- This is a table used to demonstrate the UNIT test framework. +-- +CREATE TABLE TO_TEST_ME +( + SNAME VARCHAR2(10) +) +/ diff --git a/utplsql-maven-plugin-it/src/it/resources/owner-param-project/scripts/test/bar/package_bodies/TEST_PKG_TEST_ME.sql b/utplsql-maven-plugin-it/src/it/resources/owner-param-project/scripts/test/bar/package_bodies/TEST_PKG_TEST_ME.sql new file mode 100644 index 0000000..1b34f08 --- /dev/null +++ b/utplsql-maven-plugin-it/src/it/resources/owner-param-project/scripts/test/bar/package_bodies/TEST_PKG_TEST_ME.sql @@ -0,0 +1,126 @@ +CREATE OR REPLACE PACKAGE BODY TESTS_OWNER.TEST_PKG_TEST_ME AS + + --------------------------------------------------------------------------- + PROCEDURE SETUP_GLOBAL IS + BEGIN + -- Put here the code which is valid for all tests and that should be + -- executed once. + NULL; + END SETUP_GLOBAL; + + --------------------------------------------------------------------------- + PROCEDURE TEARDOWN_GLOBAL IS + BEGIN + -- Put here the code that should be called only once after all the test + -- have executed + NULL; + END TEARDOWN_GLOBAL; + + --------------------------------------------------------------------------- + PROCEDURE SETUP_TEST IS + BEGIN + -- Nothing to clean up globally + NULL; + END SETUP_TEST; + + PROCEDURE TEARDOWN_TEST IS + BEGIN + -- Nothing to clean up globally + NULL; + END TEARDOWN_TEST; + + PROCEDURE TEST_FC_INPUT_1 IS + BEGIN + -- Ok this is a real test where I check that the function return 1 + -- when called with a '1' parameter + UT.EXPECT(PKG_TEST_ME.FC_TEST_ME('1')).TO_EQUAL(1); + END; + + PROCEDURE SETUP_TEST_FC_INPUT_1 IS + BEGIN + -- Nothing to be done really + NULL; + END; + + PROCEDURE TEARDOWN_TEST_FC_INPUT_1 IS + BEGIN + -- Nothing to be done really + NULL; + END; + + PROCEDURE TEST_FC_INPUT_0 IS + BEGIN + -- Ok this is a real test where I check that the function return 0 + -- when called with a '0' parameter + UT.EXPECT(PKG_TEST_ME.FC_TEST_ME('0')).TO_EQUAL(0); + END; + + PROCEDURE TEST_FC_INPUT_NULL IS + BEGIN + -- Ok I check that the function return NULL + -- when called with a NULL parameter + UT.EXPECT(PKG_TEST_ME.FC_TEST_ME(NULL)).TO_BE_NULL; + END TEST_FC_INPUT_NULL; + + PROCEDURE TEST_PR_TEST_ME_NULL IS + VNCOUNT1 PLS_INTEGER; + VNCOUNT2 PLS_INTEGER; + BEGIN + -- In this example I check that the procedure does + -- not insert anything when passing it a NULL parameter + SELECT COUNT(1) INTO VNCOUNT1 FROM TO_TEST_ME; + PKG_TEST_ME.PR_TEST_ME(NULL); + SELECT COUNT(1) INTO VNCOUNT2 FROM TO_TEST_ME; + UT.EXPECT(VNCOUNT1).TO_EQUAL(VNCOUNT2); + END; + + PROCEDURE TEST_PR_TEST_ME_NOT_NULL IS + VNCOUNT1 PLS_INTEGER; + VNCOUNT2 PLS_INTEGER; + VSNAME TO_TEST_ME.SNAME%TYPE; + BEGIN + -- In this test I will check that I do insert a value + -- when the parameter is not null. I futher check that + -- the procedure has inserted the value I specified. + SELECT COUNT(1) INTO VNCOUNT1 FROM TO_TEST_ME; + VSNAME := TO_CHAR(VNCOUNT1); + PKG_TEST_ME.PR_TEST_ME(VSNAME); + SELECT COUNT(1) INTO VNCOUNT2 FROM TO_TEST_ME; + + -- Check that I have inserted the value + UT.EXPECT(VNCOUNT1 + 1).TO_EQUAL(VNCOUNT2); + SELECT COUNT(1) INTO VNCOUNT2 FROM TO_TEST_ME T WHERE T.SNAME = VSNAME; + + -- Check that I inserted the one I said I would insert + UT.EXPECT(VNCOUNT2).TO_EQUAL(1); + DELETE FROM TO_TEST_ME T WHERE T.SNAME = VSNAME; + COMMIT; + END; + + PROCEDURE TEST_PR_TEST_ME_EXISTS IS + BEGIN + -- In case the value exists the procedure should fail with an exception. + BEGIN + PKG_TEST_ME.PR_TEST_ME('EXISTS'); + PKG_TEST_ME.PR_TEST_ME('EXISTS'); + EXCEPTION + WHEN OTHERS THEN + UT.FAIL('Unexpected exception raised'); + END; + END; + + PROCEDURE TEST_PR_TEST_ME_CURSOR IS + TYPE REF_CURSOR IS REF CURSOR; + VEXPECTED REF_CURSOR; + VACTUAL REF_CURSOR; + BEGIN + EXECUTE IMMEDIATE 'TRUNCATE TABLE CODE_OWNER.TO_TEST_ME'; + OPEN VEXPECTED FOR + SELECT T.SNAME FROM TO_TEST_ME T; + OPEN VACTUAL FOR + SELECT T.SNAME FROM TO_TEST_ME T; + UT.EXPECT(VEXPECTED).TO_(EQUAL(VACTUAL)); + END; + +END; +/ diff --git a/utplsql-maven-plugin-it/src/it/resources/owner-param-project/scripts/test/bar/packages/TEST_PKG_TEST_ME.sql b/utplsql-maven-plugin-it/src/it/resources/owner-param-project/scripts/test/bar/packages/TEST_PKG_TEST_ME.sql new file mode 100644 index 0000000..b0cdf54 --- /dev/null +++ b/utplsql-maven-plugin-it/src/it/resources/owner-param-project/scripts/test/bar/packages/TEST_PKG_TEST_ME.sql @@ -0,0 +1,86 @@ +CREATE OR REPLACE PACKAGE TESTS_OWNER.TEST_PKG_TEST_ME AS + -- %suite(TEST_PKG_TEST_ME) + -- %suitepath(plsql.examples) + -- + -- This package shows all the possibilities to unit test + -- your PL/SQL package. NOTE that it is not limited to + -- testing your package. You can do that on all your + -- procedure/functions... + -- + + /** + * This two parameters are used by the test framework in + * order to identify the test suite to run + */ + + /* + * This method is invoked once before any other method. + * It should contain all the setup code that is relevant + * for all your test. It might be inserting a register, + * creating a type, etc... + */ + -- %beforeall + PROCEDURE SETUP_GLOBAL; + + /* + * This method is invoked once after all other method. + * It can be used to clean up all the resources that + * you created in your script + */ + -- %afterall + PROCEDURE TEARDOWN_GLOBAL; + + /* + * This method is called once before each test. + */ + -- %beforeeach + PROCEDURE SETUP_TEST; + + /* + * This method is called once after each test. + */ + -- %aftereach + PROCEDURE TEARDOWN_TEST; + + /** + * This is a real test. The main test can declare a setup + * and teardown method in order to setup and cleanup things + * for that specific test. + */ + -- %test + -- %displayname(Checking if function ('1') returns 1) + -- %beforetest(SETUP_TEST_FC_INPUT_1) + -- %aftertest(TEARDOWN_TEST_FC_INPUT_1) + PROCEDURE TEST_FC_INPUT_1; + PROCEDURE SETUP_TEST_FC_INPUT_1; + PROCEDURE TEARDOWN_TEST_FC_INPUT_1; + + -- %test + -- %displayname(Checking if function ('0') returns 0) + PROCEDURE TEST_FC_INPUT_0; + + -- %test + -- %displayname(Checking if function (NULL) returns NULL) + PROCEDURE TEST_FC_INPUT_NULL; + + -- %test + -- %displayname(Checking if procedure (NULL) insert) + PROCEDURE TEST_PR_TEST_ME_NULL; + + -- %test + -- %displayname(Checking if procedure (NOT NULL) insert) + -- %rollback(manual) + PROCEDURE TEST_PR_TEST_ME_NOT_NULL; + + -- %test + -- %displayname(Checking if procedure (NOT NULL) insert while existing) + -- %rollback(manual) + PROCEDURE TEST_PR_TEST_ME_EXISTS; + + -- %test + -- %displayname(Demonstrating the use of cursor) + -- %rollback(manual) + PROCEDURE TEST_PR_TEST_ME_CURSOR; + +END; +/ 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 b9a6f00..bd2d6fd 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 @@ -65,6 +65,9 @@ public class UtPLSQLMojo extends AbstractMojo @Parameter protected List sources = new ArrayList<>(); + @Parameter + private String sourcesOwner; + @Parameter private String sourcesRegexExpression; @@ -85,6 +88,9 @@ public class UtPLSQLMojo extends AbstractMojo @Parameter protected List tests = new ArrayList<>(); + @Parameter + private String testsOwner; + @Parameter private String testsRegexExpression; @@ -230,6 +236,11 @@ private FileMapperOptions buildSourcesOptions() throws MojoExecutionException List scripts = SQLScannerHelper.findSQLs(sources); FileMapperOptions fileMapperOptions = new FileMapperOptions(scripts); + if (StringUtils.isNotEmpty(sourcesOwner)) + { + fileMapperOptions.setObjectOwner(sourcesOwner); + } + if (StringUtils.isNotEmpty(sourcesRegexExpression)) { fileMapperOptions.setRegexPattern(sourcesRegexExpression); @@ -250,7 +261,7 @@ private FileMapperOptions buildSourcesOptions() throws MojoExecutionException fileMapperOptions.setTypeSubExpression(sourcesTypeSubexpression); } - if (sourcesCustomTypeMapping != null && sourcesCustomTypeMapping.size() > 0) { + if (sourcesCustomTypeMapping != null && !sourcesCustomTypeMapping.isEmpty()) { fileMapperOptions.setTypeMappings(new ArrayList()); for (CustomTypeMapping typeMapping : sourcesCustomTypeMapping) { fileMapperOptions.getTypeMappings().add(new KeyValuePair(typeMapping.getCustomMapping(),typeMapping.getType())); @@ -287,6 +298,11 @@ private FileMapperOptions buildTestsOptions() throws MojoExecutionException List scripts = SQLScannerHelper.findSQLs(tests); FileMapperOptions fileMapperOptions = new FileMapperOptions(scripts); + if (StringUtils.isNotEmpty(testsOwner)) + { + fileMapperOptions.setObjectOwner(testsOwner); + } + if (StringUtils.isNotEmpty(testsRegexExpression)) { fileMapperOptions.setRegexPattern(testsRegexExpression); @@ -307,7 +323,7 @@ private FileMapperOptions buildTestsOptions() throws MojoExecutionException fileMapperOptions.setTypeSubExpression(testsTypeSubexpression); } - if (testsCustomTypeMapping != null && testsCustomTypeMapping.size() > 0) { + if (testsCustomTypeMapping != null && !testsCustomTypeMapping.isEmpty()) { fileMapperOptions.setTypeMappings(new ArrayList()); for (CustomTypeMapping typeMapping : testsCustomTypeMapping) { fileMapperOptions.getTypeMappings().add(new KeyValuePair(typeMapping.getCustomMapping(),typeMapping.getType())); From 9039ac2260d8a7369374d8bf2e88e0c56201bea6 Mon Sep 17 00:00:00 2001 From: Jerome Garec Date: Wed, 18 Jul 2018 21:54:55 +0200 Subject: [PATCH 49/71] Fixes #21 : all parameters are now optional * IT : Add 1 new integration test project * FEATURE : Sources / tests / paths / reporters are now optional * FIX : Fixes owner-param project * FIX : Fixes wrong base dir for sources and tests scripts --- .../maven/plugin/test/UtPLSQLMojoIT.java | 23 +- .../it/resources/minimalist-project/pom.xml | 33 ++ .../utplsql/coverage-sonar-reporter.xml | 2 +- .../utplsql/sonar-test-reporter.xml | 2 +- .../it/resources/owner-param-project/pom.xml | 120 ++++---- utplsql-maven-plugin/pom.xml | 15 +- .../org/utplsql/maven/plugin/UtPLSQLMojo.java | 284 ++++++++---------- .../maven/plugin/helper/PluginDefault.java | 179 +++++------ .../maven/plugin/helper/SQLScannerHelper.java | 142 ++++----- .../maven/plugin/test/UtPLSQLMojoTest.java | 161 ++++++++++ .../invalidTestsSourcesDirectories/pom.xml | 78 +++++ .../directoryDoesNotExist/pom.xml | 62 ++++ .../directoryExists/pom.xml | 62 ++++ .../directoryExists/src/main/plsql/f1.sql | 0 .../directoryExists/src/main/plsql/f2.sql | 0 .../directoryExists/src/test/plsql/f2.pkg | 0 .../directoryExists/src/test/plsql/foo/f1.pkg | 0 .../directoryExists/src/test/plsql/foo/f1.sql | 0 .../resources/testSourcesTestsParams/pom.xml | 101 +++++++ .../testSourcesTestsParams/srcs/file.bdy | 0 .../testSourcesTestsParams/srcs/foo.sql | 0 .../testSourcesTestsParams/srcs/spec.spc | 0 .../testSourcesTestsParams/te/st/file.bdy | 0 .../testSourcesTestsParams/te/st/foo.sql | 0 .../testSourcesTestsParams/te/st/spec.spc | 0 25 files changed, 881 insertions(+), 383 deletions(-) create mode 100644 utplsql-maven-plugin-it/src/it/resources/minimalist-project/pom.xml create mode 100644 utplsql-maven-plugin/src/test/java/org/utplsql/maven/plugin/test/UtPLSQLMojoTest.java create mode 100644 utplsql-maven-plugin/src/test/resources/invalidTestsSourcesDirectories/pom.xml create mode 100644 utplsql-maven-plugin/src/test/resources/testNoSourcesTestsParams/directoryDoesNotExist/pom.xml create mode 100644 utplsql-maven-plugin/src/test/resources/testNoSourcesTestsParams/directoryExists/pom.xml create mode 100644 utplsql-maven-plugin/src/test/resources/testNoSourcesTestsParams/directoryExists/src/main/plsql/f1.sql create mode 100644 utplsql-maven-plugin/src/test/resources/testNoSourcesTestsParams/directoryExists/src/main/plsql/f2.sql create mode 100644 utplsql-maven-plugin/src/test/resources/testNoSourcesTestsParams/directoryExists/src/test/plsql/f2.pkg create mode 100644 utplsql-maven-plugin/src/test/resources/testNoSourcesTestsParams/directoryExists/src/test/plsql/foo/f1.pkg create mode 100644 utplsql-maven-plugin/src/test/resources/testNoSourcesTestsParams/directoryExists/src/test/plsql/foo/f1.sql create mode 100644 utplsql-maven-plugin/src/test/resources/testSourcesTestsParams/pom.xml create mode 100644 utplsql-maven-plugin/src/test/resources/testSourcesTestsParams/srcs/file.bdy create mode 100644 utplsql-maven-plugin/src/test/resources/testSourcesTestsParams/srcs/foo.sql create mode 100644 utplsql-maven-plugin/src/test/resources/testSourcesTestsParams/srcs/spec.spc create mode 100644 utplsql-maven-plugin/src/test/resources/testSourcesTestsParams/te/st/file.bdy create mode 100644 utplsql-maven-plugin/src/test/resources/testSourcesTestsParams/te/st/foo.sql create mode 100644 utplsql-maven-plugin/src/test/resources/testSourcesTestsParams/te/st/spec.spc 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 203af8a..af730c8 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 @@ -117,7 +117,7 @@ public void testTypeMappingProject() throws Exception { @Test public void testOwnerParameterProject() throws Exception { try { - final String PROJECT_NAME = "type-mapping-project"; + final String PROJECT_NAME = "owner-param-project"; File testProject = ResourceExtractor.simpleExtractResources(getClass(), "/" + PROJECT_NAME); Verifier verifier; @@ -137,6 +137,27 @@ public void testOwnerParameterProject() throws Exception { 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()); + } + } /** * 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 new file mode 100644 index 0000000..d410eff --- /dev/null +++ b/utplsql-maven-plugin-it/src/it/resources/minimalist-project/pom.xml @@ -0,0 +1,33 @@ + + 4.0.0 + + org.utplsql + utplsql-maven-plugin-minimalist-test + 1.0.0 + pom + + utplsql-maven-plugin IT Minimalist + + + + + + + + ${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/expected-output/utplsql/coverage-sonar-reporter.xml b/utplsql-maven-plugin-it/src/it/resources/owner-param-project/expected-output/utplsql/coverage-sonar-reporter.xml index ee91996..6718aa5 100644 --- a/utplsql-maven-plugin-it/src/it/resources/owner-param-project/expected-output/utplsql/coverage-sonar-reporter.xml +++ b/utplsql-maven-plugin-it/src/it/resources/owner-param-project/expected-output/utplsql/coverage-sonar-reporter.xml @@ -1,5 +1,5 @@ - + diff --git a/utplsql-maven-plugin-it/src/it/resources/owner-param-project/expected-output/utplsql/sonar-test-reporter.xml b/utplsql-maven-plugin-it/src/it/resources/owner-param-project/expected-output/utplsql/sonar-test-reporter.xml index ac04b30..e558e2f 100644 --- a/utplsql-maven-plugin-it/src/it/resources/owner-param-project/expected-output/utplsql/sonar-test-reporter.xml +++ b/utplsql-maven-plugin-it/src/it/resources/owner-param-project/expected-output/utplsql/sonar-test-reporter.xml @@ -1,5 +1,5 @@ - + 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 abf7f0b..f11ba46 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 @@ -20,69 +20,73 @@ ${project.groupId} utplsql-maven-plugin ${utplsql-maven-plugin-version} - - test - - - + + + + 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 - - - + + + scripts/test + + **/*sql + + + + tests_owner + .*/\w+/(\w+)/(\w+)\.\w{3} + 2 + 1 + + + package body + package_bodies + + + + + diff --git a/utplsql-maven-plugin/pom.xml b/utplsql-maven-plugin/pom.xml index 363be2c..14639dd 100644 --- a/utplsql-maven-plugin/pom.xml +++ b/utplsql-maven-plugin/pom.xml @@ -21,6 +21,12 @@ 1.8 + + + org.apache.maven + maven-core + 3.5.2 + org.utplsql @@ -54,8 +60,13 @@ - + + org.powermock + powermock-module-junit4 + 1.7.4 + test + org.apache.maven.plugin-testing @@ -84,8 +95,6 @@ 3.8.0 test - - 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 bd2d6fd..8673638 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 @@ -1,5 +1,6 @@ package org.utplsql.maven.plugin; +import java.io.File; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; @@ -14,6 +15,7 @@ import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.project.MavenProject; import org.utplsql.api.DBHelper; import org.utplsql.api.FileMapperOptions; import org.utplsql.api.JavaApiVersionInfo; @@ -35,8 +37,11 @@ * */ @Mojo(name = "test", defaultPhase = LifecyclePhase.TEST) -public class UtPLSQLMojo extends AbstractMojo -{ +public class UtPLSQLMojo extends AbstractMojo { + + @Parameter(readonly = true, defaultValue = "${project}") + private MavenProject project; + @Parameter(property = "dbUrl") protected String url; @@ -45,7 +50,7 @@ public class UtPLSQLMojo extends AbstractMojo @Parameter(property = "dbPass") protected String password; - + @Parameter protected String includeObject; @@ -56,66 +61,61 @@ public class UtPLSQLMojo extends AbstractMojo protected boolean skipCompatibilityCheck; @Parameter - protected List reporters; + protected List reporters = new ArrayList(); - @Parameter(defaultValue = "") - protected List paths; + @Parameter + protected List paths = new ArrayList(); // Sources Configuration @Parameter - protected List sources = new ArrayList<>(); - + protected List sources = new ArrayList(); + @Parameter private String sourcesOwner; - + @Parameter private String sourcesRegexExpression; - + @Parameter private Integer sourcesOwnerSubexpression; - + @Parameter private Integer sourcesNameSubexpression; - + @Parameter private Integer sourcesTypeSubexpression; - + @Parameter private List sourcesCustomTypeMapping; - + // Tests Configuration - + @Parameter protected List tests = new ArrayList<>(); - + @Parameter private String testsOwner; - + @Parameter private String testsRegexExpression; - + @Parameter private Integer testsOwnerSubexpression; - + @Parameter private Integer testsNameSubexpression; - + @Parameter private Integer testsTypeSubexpression; - + @Parameter - private List testsCustomTypeMapping; - + private List testsCustomTypeMapping; @Parameter(defaultValue = "${project.build.directory}", readonly = true) protected String targetDir; @Parameter(defaultValue = "${maven.test.failure.ignore}") protected boolean ignoreFailure; - - - - // Color in the console, loaded by environment variables private boolean colorConsole = PluginDefault.resolveColor(); @@ -129,90 +129,69 @@ public class UtPLSQLMojo extends AbstractMojo * */ @Override - public void execute() throws MojoExecutionException - { - getLog().debug("Java Api Version = "+JavaApiVersionInfo.getVersion()); + public void execute() throws MojoExecutionException { + getLog().debug("Java Api Version = " + JavaApiVersionInfo.getVersion()); loadConfFromEnvironment(); - + Connection connection = null; - try - { + try { FileMapperOptions sourceMappingOptions = buildSourcesOptions(); FileMapperOptions testMappingOptions = buildTestsOptions(); - + // Create the Connection to the Database connection = DriverManager.getConnection(url, user, password); - getLog().info("utPLSQL Version = "+DBHelper.getDatabaseFrameworkVersion(connection)); - + getLog().info("utPLSQL Version = " + DBHelper.getDatabaseFrameworkVersion(connection)); + List reporterList = initReporters(connection); logParameters(sourceMappingOptions, testMappingOptions, reporterList); - TestRunner runner = new TestRunner() - .addPathList(paths) - .addReporterList(reporterList) - .sourceMappingOptions(sourceMappingOptions) - .testMappingOptions(testMappingOptions) - .skipCompatibilityCheck(skipCompatibilityCheck) - .colorConsole(colorConsole) + TestRunner runner = new TestRunner().addPathList(paths).addReporterList(reporterList) + .sourceMappingOptions(sourceMappingOptions).testMappingOptions(testMappingOptions) + .skipCompatibilityCheck(skipCompatibilityCheck).colorConsole(colorConsole) .failOnErrors(!ignoreFailure); // Setting Optional Parameters - if (StringUtils.isNotBlank(excludeObject)) - { + if (StringUtils.isNotBlank(excludeObject)) { runner.excludeObject(excludeObject); } - if (StringUtils.isNotBlank(includeObject)) - { + if (StringUtils.isNotBlank(includeObject)) { runner.includeObject(includeObject); } runner.run(connection); - - } - catch (SomeTestsFailedException e) - { + + } catch (SomeTestsFailedException e) { getLog().error(e); throw new MojoExecutionException(e.getMessage()); - } - catch (SQLException e) - { + } catch (SQLException e) { getLog().error(e); throw new MojoExecutionException(e.getMessage(), e); - } - finally - { - try - { + } finally { + try { // Write Reporters - if (connection != null) + if (connection != null) reporterWriter.writeReporters(connection); - } - catch (Exception e) - { + } 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)) - { + private void loadConfFromEnvironment() { + if (StringUtils.isEmpty(url)) { + url = System.getProperty("dbUrl"); + } + + if (StringUtils.isEmpty(user)) { user = System.getProperty("dbUser"); } - - if (StringUtils.isEmpty(password)) - { + + if (StringUtils.isEmpty(password)) { password = System.getProperty("dbPass"); } } @@ -223,122 +202,114 @@ private void loadConfFromEnvironment () * @return * @throws MojoExecutionException */ - private FileMapperOptions buildSourcesOptions() throws MojoExecutionException - { - try - { + private FileMapperOptions buildSourcesOptions() throws MojoExecutionException { + try { // Check if this element is empty - if (sources.isEmpty()) - { - sources.add(PluginDefault.buildDefaultSource()); + if (sources.isEmpty()) { + File defaultSourceDirectory = new File(project.getBasedir(),PluginDefault.SOURCE_DIRECTORY); + if (defaultSourceDirectory.exists()) { + sources.add(PluginDefault.buildDefaultSource(project.getBasedir())); + } else { + return new FileMapperOptions(new ArrayList()); + } } - List scripts = SQLScannerHelper.findSQLs(sources); + List scripts = SQLScannerHelper.findSQLs(project.getBasedir(),sources); FileMapperOptions fileMapperOptions = new FileMapperOptions(scripts); - - if (StringUtils.isNotEmpty(sourcesOwner)) - { + + if (StringUtils.isNotEmpty(sourcesOwner)) { fileMapperOptions.setObjectOwner(sourcesOwner); } - - if (StringUtils.isNotEmpty(sourcesRegexExpression)) - { + + if (StringUtils.isNotEmpty(sourcesRegexExpression)) { fileMapperOptions.setRegexPattern(sourcesRegexExpression); } - - if (sourcesOwnerSubexpression != null) - { + + if (sourcesOwnerSubexpression != null) { fileMapperOptions.setOwnerSubExpression(sourcesOwnerSubexpression); } - - if (sourcesNameSubexpression != null) - { + + if (sourcesNameSubexpression != null) { fileMapperOptions.setNameSubExpression(sourcesNameSubexpression); } - - if (sourcesTypeSubexpression != null) - { + + 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())); - } + 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); } - catch (Exception e) - { - throw new MojoExecutionException("Invalid in your pom.xml: " + e.getMessage()); - } - + } - - + /** * * @param resources * @return * @throws MojoExecutionException */ - private FileMapperOptions buildTestsOptions() throws MojoExecutionException - { - try - { + private FileMapperOptions buildTestsOptions() throws MojoExecutionException { + try { // Check if this element is empty - if (tests.isEmpty()) - { - tests.add(PluginDefault.buildDefaultTest()); - } + if (tests.isEmpty()) { + File defaultTestDirecyory = new File(project.getBasedir(),PluginDefault.TEST_DIRECTORY); + if (defaultTestDirecyory.exists()) { + tests.add(PluginDefault.buildDefaultTest(project.getBasedir())); + } else { + return new FileMapperOptions(new ArrayList()); + } + } - List scripts = SQLScannerHelper.findSQLs(tests); + List scripts = SQLScannerHelper.findSQLs(project.getBasedir(),tests); FileMapperOptions fileMapperOptions = new FileMapperOptions(scripts); - - if (StringUtils.isNotEmpty(testsOwner)) - { + + if (StringUtils.isNotEmpty(testsOwner)) { fileMapperOptions.setObjectOwner(testsOwner); } - - if (StringUtils.isNotEmpty(testsRegexExpression)) - { + + if (StringUtils.isNotEmpty(testsRegexExpression)) { fileMapperOptions.setRegexPattern(testsRegexExpression); } - - if (testsOwnerSubexpression != null) - { + + if (testsOwnerSubexpression != null) { fileMapperOptions.setOwnerSubExpression(testsOwnerSubexpression); } - - if (testsNameSubexpression != null) - { + + if (testsNameSubexpression != null) { fileMapperOptions.setNameSubExpression(testsNameSubexpression); } - - if (testsTypeSubexpression != null) - { + + 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())); - } - } - + fileMapperOptions.setTypeMappings(new ArrayList()); + for (CustomTypeMapping typeMapping : testsCustomTypeMapping) { + fileMapperOptions.getTypeMappings() + .add(new KeyValuePair(typeMapping.getCustomMapping(), typeMapping.getType())); + } + } + return fileMapperOptions; - } - catch (Exception e) - { + } catch (Exception e) { throw new MojoExecutionException("Invalid in your pom.xml: " + e.getMessage()); } - + } + /** * Init all the reporters * @@ -346,26 +317,23 @@ private FileMapperOptions buildTestsOptions() throws MojoExecutionException * @return * @throws SQLException */ - private List initReporters(Connection connection) throws SQLException - { + private List initReporters(Connection connection) throws SQLException { List reporterList = new ArrayList<>(); - + Version utlVersion = DBHelper.getDatabaseFrameworkVersion(connection); // Initialized Reporters reporterWriter = new ReporterWriter(targetDir, utlVersion); - + ReporterFactory reporterFactory = ReporterFactory.createEmpty(); - for (ReporterParameter reporterParameter : reporters) - { + for (ReporterParameter reporterParameter : reporters) { Reporter reporter = reporterFactory.createReporter(reporterParameter.getName()); reporter.init(connection); reporterList.add(reporter); // Only added the reporter if at least one of the output is required - if (StringUtils.isNotBlank(reporterParameter.getFileOutput()) || reporterParameter.isConsoleOutput()) - { + if (StringUtils.isNotBlank(reporterParameter.getFileOutput()) || reporterParameter.isConsoleOutput()) { reporterWriter.addReporter(reporterParameter, reporter); } } @@ -380,14 +348,12 @@ private List initReporters(Connection connection) throws SQLException * @param reporterList */ private void logParameters(FileMapperOptions sourceMappingOptions, FileMapperOptions testMappingOptions, - List reporterList) - { + List reporterList) { Log log = getLog(); log.info("Invoking TestRunner with: " + targetDir); // Do nothing when the debug is disabled - if (!log.isDebugEnabled()) - { + if (!log.isDebugEnabled()) { return; } 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 0969ab8..eb615fe 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 @@ -1,89 +1,90 @@ -package org.utplsql.maven.plugin.helper; - -import java.util.Arrays; -import java.util.Map; - -import org.apache.maven.model.Resource; - -/** - * This class provides methods to retrieve the list of resources in the default and directories. - * - * @author Alberto Hernández - * - */ -public class PluginDefault -{ - - private static final String STYLE_COLOR_PROPERTY = "style.color"; - - private static final String BATCH_MODE = "B"; - - private static final String LOG_FILE = "l"; - - // Source Directory - private static final String SOURCE_DIRECTORY = "src/main/plsql"; - - // Test Directory - private static final String TEST_DIRECTORY = "src/test/plsql"; - - 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, "**/*.*"); - } - - /** - * This method returns {@link Resource} for the default {@code test} directory - * - * @return a {@link Resource} - */ - public static Resource buildDefaultTest() - { - return buildDirectory(TEST_DIRECTORY, "**/*.pkg"); - } - - private static Resource buildDirectory(String directory, String includes) - { - Resource resource = new Resource(); - resource.setDirectory(directory); - resource.setIncludes(Arrays.asList(includes)); - return resource; - } - - /** - * - * @return - */ - public static boolean resolveColor() - { - final Map env = System.getenv(); - String color = env.get(STYLE_COLOR_PROPERTY); - - if ("always".equals(color)) - { - return true; - } - - if ("never".equals(color)) - { - return false; - } - - if (env.containsKey(BATCH_MODE) || env.containsKey(LOG_FILE)) - { - return false; - } - - return false; - } - -} +package org.utplsql.maven.plugin.helper; + +import java.io.File; +import java.util.Arrays; +import java.util.Map; + +import org.apache.maven.model.Resource; + +/** + * This class provides methods to retrieve the list of resources in the default and directories. + * + * @author Alberto Hernández + * + */ +public class PluginDefault +{ + + private static final String STYLE_COLOR_PROPERTY = "style.color"; + + private static final String BATCH_MODE = "B"; + + private static final String LOG_FILE = "l"; + + // Source Directory + public static final String SOURCE_DIRECTORY = "src/main/plsql"; + + // Test Directory + public static final String TEST_DIRECTORY = "src/test/plsql"; + + private PluginDefault() + { + // NA + } + + /** + * This method returns {@link Resource} for the default {@code source} directory + * + * @return a {@link Resource} + */ + public static Resource buildDefaultSource(File baseDir) + { + return buildDirectory(baseDir,SOURCE_DIRECTORY, "**/*.*"); + } + + /** + * This method returns {@link Resource} for the default {@code test} directory + * + * @return a {@link Resource} + */ + public static Resource buildDefaultTest(File baseDir) + { + return buildDirectory(baseDir, TEST_DIRECTORY, "**/*.pkg"); + } + + private static Resource buildDirectory(File baseDir, String directory, String includes) + { + Resource resource = new Resource(); + resource.setDirectory(baseDir.getAbsolutePath()+"/"+directory); + resource.setIncludes(Arrays.asList(includes)); + return resource; + } + + /** + * + * @return + */ + public static boolean resolveColor() + { + final Map env = System.getenv(); + String color = env.get(STYLE_COLOR_PROPERTY); + + if ("always".equals(color)) + { + return true; + } + + if ("never".equals(color)) + { + return false; + } + + if (env.containsKey(BATCH_MODE) || env.containsKey(LOG_FILE)) + { + return false; + } + + return false; + } + +} 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 3026ff1..4a177f8 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 @@ -1,71 +1,71 @@ -package org.utplsql.maven.plugin.helper; - -import static java.lang.String.format; - -import java.io.File; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.apache.maven.model.Resource; -import org.codehaus.plexus.util.DirectoryScanner; - -/** - * Utility to Scan all resources - * - * @author Alberto Hernández - * - */ -public class SQLScannerHelper { - - private SQLScannerHelper() { - // NA - } - - /** - * - * @param resouces - * @return - */ - public static List findSQLs(List resources) { - List founds = new ArrayList<>(); - - for (Resource resource : resources) { - // Build Scanner - DirectoryScanner scanner = buildScanner(resource); - scanner.scan(); - for (String basename : scanner.getIncludedFiles()) { - founds.add(new File(scanner.getBasedir(), basename).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(Resource resource) { - if (resource != null) { - File baseDir = new File(resource.getDirectory()); - if (!baseDir.exists() || !baseDir.isDirectory() || !baseDir.canRead()) { - throw new IllegalArgumentException( - format("Invalid %s in resource. Check your pom.xml", resource.getDirectory())); - } - - DirectoryScanner scanner = new DirectoryScanner(); - scanner.setBasedir(resource.getDirectory()); - scanner.setIncludes(resource.getIncludes().toArray(new String[0])); - scanner.setExcludes(resource.getExcludes().toArray(new String[0])); - return scanner; - } - throw new IllegalArgumentException(); - } - -} +package org.utplsql.maven.plugin.helper; + +import static java.lang.String.format; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.apache.maven.model.Resource; +import org.codehaus.plexus.util.DirectoryScanner; + +/** + * Utility to Scan all resources + * + * @author Alberto Hernández + * + */ +public class SQLScannerHelper { + + private SQLScannerHelper() { + // NA + } + + /** + * + * @param resouces + * @return + */ + public static List findSQLs(File baseDir,List resources) { + List founds = new ArrayList(); + + for (Resource resource : resources) { + // Build Scanner + DirectoryScanner scanner = buildScanner(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(Resource resource) { + if (resource != null) { + File baseDir = new File(resource.getDirectory()); + if (!baseDir.exists() || !baseDir.isDirectory() || !baseDir.canRead()) { + throw new IllegalArgumentException( + format("Invalid %s in resource. Check your pom.xml", resource.getDirectory())); + } + + DirectoryScanner scanner = new DirectoryScanner(); + scanner.setBasedir(resource.getDirectory()); + scanner.setIncludes(resource.getIncludes().toArray(new String[0])); + scanner.setExcludes(resource.getExcludes().toArray(new String[0])); + return scanner; + } + throw new IllegalArgumentException(); + } + +} 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 new file mode 100644 index 0000000..bb69e06 --- /dev/null +++ b/utplsql-maven-plugin/src/test/java/org/utplsql/maven/plugin/test/UtPLSQLMojoTest.java @@ -0,0 +1,161 @@ +package org.utplsql.maven.plugin.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.util.List; + +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.testing.MojoRule; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.powermock.reflect.Whitebox; +import org.utplsql.api.FileMapperOptions; +import org.utplsql.maven.plugin.UtPLSQLMojo; + +public class UtPLSQLMojoTest { + + @Rule + public MojoRule rule = new MojoRule(); + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + /** + * 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 + 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")); + + } +} diff --git a/utplsql-maven-plugin/src/test/resources/invalidTestsSourcesDirectories/pom.xml b/utplsql-maven-plugin/src/test/resources/invalidTestsSourcesDirectories/pom.xml new file mode 100644 index 0000000..1c5e6f0 --- /dev/null +++ b/utplsql-maven-plugin/src/test/resources/invalidTestsSourcesDirectories/pom.xml @@ -0,0 +1,78 @@ + + 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 + + + + + + foo + + **/*sql + + + + + + + bar + + **/*.spc + **/*.bdy + + + + + + + + \ 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 new file mode 100644 index 0000000..6606b00 --- /dev/null +++ b/utplsql-maven-plugin/src/test/resources/testNoSourcesTestsParams/directoryDoesNotExist/pom.xml @@ -0,0 +1,62 @@ + + 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 new file mode 100644 index 0000000..7f38f37 --- /dev/null +++ b/utplsql-maven-plugin/src/test/resources/testNoSourcesTestsParams/directoryExists/pom.xml @@ -0,0 +1,62 @@ + + 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/testNoSourcesTestsParams/directoryExists/src/main/plsql/f1.sql b/utplsql-maven-plugin/src/test/resources/testNoSourcesTestsParams/directoryExists/src/main/plsql/f1.sql new file mode 100644 index 0000000..e69de29 diff --git a/utplsql-maven-plugin/src/test/resources/testNoSourcesTestsParams/directoryExists/src/main/plsql/f2.sql b/utplsql-maven-plugin/src/test/resources/testNoSourcesTestsParams/directoryExists/src/main/plsql/f2.sql new file mode 100644 index 0000000..e69de29 diff --git a/utplsql-maven-plugin/src/test/resources/testNoSourcesTestsParams/directoryExists/src/test/plsql/f2.pkg b/utplsql-maven-plugin/src/test/resources/testNoSourcesTestsParams/directoryExists/src/test/plsql/f2.pkg new file mode 100644 index 0000000..e69de29 diff --git a/utplsql-maven-plugin/src/test/resources/testNoSourcesTestsParams/directoryExists/src/test/plsql/foo/f1.pkg b/utplsql-maven-plugin/src/test/resources/testNoSourcesTestsParams/directoryExists/src/test/plsql/foo/f1.pkg new file mode 100644 index 0000000..e69de29 diff --git a/utplsql-maven-plugin/src/test/resources/testNoSourcesTestsParams/directoryExists/src/test/plsql/foo/f1.sql b/utplsql-maven-plugin/src/test/resources/testNoSourcesTestsParams/directoryExists/src/test/plsql/foo/f1.sql new file mode 100644 index 0000000..e69de29 diff --git a/utplsql-maven-plugin/src/test/resources/testSourcesTestsParams/pom.xml b/utplsql-maven-plugin/src/test/resources/testSourcesTestsParams/pom.xml new file mode 100644 index 0000000..69ba53e --- /dev/null +++ b/utplsql-maven-plugin/src/test/resources/testSourcesTestsParams/pom.xml @@ -0,0 +1,101 @@ + + 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 + + + + + + src/test/resources/testSourcesTestsParams/srcs + + **/*sql + + + + code_owner + .*/\w+/(\w+)/(\w+)\.\w{3} + 9 + 1 + 4 + + + foo + bar + + + + + + src/test/resources/testSourcesTestsParams/te/st + + **/*.spc + **/*.bdy + + + + tests_owner + .*/\w+/(\w+)/(\w+)\.\w{3} + 24 + 54 + 21 + + + abc + def + + + + + + + + \ No newline at end of file diff --git a/utplsql-maven-plugin/src/test/resources/testSourcesTestsParams/srcs/file.bdy b/utplsql-maven-plugin/src/test/resources/testSourcesTestsParams/srcs/file.bdy new file mode 100644 index 0000000..e69de29 diff --git a/utplsql-maven-plugin/src/test/resources/testSourcesTestsParams/srcs/foo.sql b/utplsql-maven-plugin/src/test/resources/testSourcesTestsParams/srcs/foo.sql new file mode 100644 index 0000000..e69de29 diff --git a/utplsql-maven-plugin/src/test/resources/testSourcesTestsParams/srcs/spec.spc b/utplsql-maven-plugin/src/test/resources/testSourcesTestsParams/srcs/spec.spc new file mode 100644 index 0000000..e69de29 diff --git a/utplsql-maven-plugin/src/test/resources/testSourcesTestsParams/te/st/file.bdy b/utplsql-maven-plugin/src/test/resources/testSourcesTestsParams/te/st/file.bdy new file mode 100644 index 0000000..e69de29 diff --git a/utplsql-maven-plugin/src/test/resources/testSourcesTestsParams/te/st/foo.sql b/utplsql-maven-plugin/src/test/resources/testSourcesTestsParams/te/st/foo.sql new file mode 100644 index 0000000..e69de29 diff --git a/utplsql-maven-plugin/src/test/resources/testSourcesTestsParams/te/st/spec.spc b/utplsql-maven-plugin/src/test/resources/testSourcesTestsParams/te/st/spec.spc new file mode 100644 index 0000000..e69de29 From a4d95456fe6095c4717902995f8140b945027b7b Mon Sep 17 00:00:00 2001 From: Jerome Garec Date: Fri, 27 Jul 2018 19:20:45 +0200 Subject: [PATCH 50/71] update java-api to 3.1.1 --- utplsql-maven-plugin/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utplsql-maven-plugin/pom.xml b/utplsql-maven-plugin/pom.xml index 14639dd..9a4d6a9 100644 --- a/utplsql-maven-plugin/pom.xml +++ b/utplsql-maven-plugin/pom.xml @@ -31,7 +31,7 @@ org.utplsql java-api - 3.1.1-SNAPSHOT + 3.1.1 From 43d1752642eccd47c6fe4841cf86d133808b8ada Mon Sep 17 00:00:00 2001 From: Jacek Gebal Date: Sun, 29 Jul 2018 16:01:43 +0100 Subject: [PATCH 51/71] Adding support for maven sonar on travis as per Travis: https://docs.travis-ci.com/user/sonarcloud/#sonarqube-scanner-for-maven --- .travis.yml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index a4b623b..6ec8686 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,12 @@ services: jdk: - oraclejdk8 +addons: + sonarcloud: + organization: utplsql + token: + secure: ${SONAR_TOKEN} + env: global: - DOCKER_CFG=$HOME/.docker @@ -35,9 +41,10 @@ install: script: - echo "Run Unit tests" - - mvn test + - mvn org.jacoco:jacoco-maven-plugin:prepare-agent test - echo "Run Integration tests" - - mvn verify -Dmaven.skip.test -DdbUser="${DB_UT3_USER}" -DdbPass="${DB_UT3_PASS}" -DdbUrl="jdbc:oracle:thin:@${DB_URL}" + - mvn org.jacoco:jacoco-maven-plugin:prepare-agent verify -Dmaven.skip.test -DdbUser="${DB_UT3_USER}" -DdbPass="${DB_UT3_PASS}" -DdbUrl="jdbc:oracle:thin:@${DB_URL}" + - mvn sonar:sonar #before_deploy: # - bash .travis/create_release.sh From 22c8369716dd72be4b141f752b3656ab324d78d6 Mon Sep 17 00:00:00 2001 From: Jacek Gebal Date: Sun, 29 Jul 2018 16:32:22 +0100 Subject: [PATCH 52/71] Touch on travis.yml --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 6ec8686..f0731e2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -46,6 +46,7 @@ script: - mvn org.jacoco:jacoco-maven-plugin:prepare-agent verify -Dmaven.skip.test -DdbUser="${DB_UT3_USER}" -DdbPass="${DB_UT3_PASS}" -DdbUrl="jdbc:oracle:thin:@${DB_URL}" - mvn sonar:sonar + #before_deploy: # - bash .travis/create_release.sh # - if [ ! -z "$TRAVIS_TAG" ]; then VERSION=$(tr -d "/v/" <<<$TRAVIS_TAG); mvn org.codehaus.mojo:versions-maven-plugin:2.1:set -DnewVersion=${VERSION}; fi From 2010e3a4ab216066a9511db46bd75a7a5afd4cdc Mon Sep 17 00:00:00 2001 From: Jacek Gebal Date: Sun, 29 Jul 2018 17:53:03 +0100 Subject: [PATCH 53/71] Added project badges and updated example pom in readme. --- README.md | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1dbf744..e7dbb4f 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ +[![Build status](https://travis-ci.org/utPLSQL/utPLSQL-maven-plugin.svg?branch=develop)](https://travis-ci.org/utPLSQL/utPLSQL-maven-plugin) +[![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+ @@ -97,6 +100,20 @@ You have to be a fully utPLSQL environment available compatible with the Java AP ### 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 @@ -105,9 +122,6 @@ The next snippet is a sample of declaration of the pom test - url_of_connection - user - password false schema_name @@ -147,6 +161,7 @@ The next snippet is a sample of declaration of the pom + ``` More project samples are available in the src/test/resources directory : From b13cd2a56396d8d3c44427c6f9b58acf8db0bcd8 Mon Sep 17 00:00:00 2001 From: jgarec Date: Mon, 30 Jul 2018 17:29:07 +0000 Subject: [PATCH 54/71] fixes #4 (#25) * Directory or includes are now optional (when the other one is set) * Add new tests * Fix a bug where files paths where relative to the plugin and not the tested project * Fix previous tests --- .../org/utplsql/maven/plugin/UtPLSQLMojo.java | 12 +-- .../maven/plugin/helper/PluginDefault.java | 22 +++-- .../maven/plugin/helper/SQLScannerHelper.java | 21 +++-- .../maven/plugin/test/UtPLSQLMojoTest.java | 53 ++++++++++++ .../missingDirectory/pom.xml | 80 +++++++++++++++++++ .../missingDirectory/src/main/plsql/f1.sql | 0 .../src/main/plsql/foo/f2.sql | 0 .../missingDirectory/src/test/plsql/f2.pkg | 0 .../src/test/plsql/foo/f1.pkg | 0 .../src/test/plsql/foo/f1.sql | 0 .../missingIncludes/pom.xml | 70 ++++++++++++++++ .../missingIncludes/src/main/foo/f1.sql | 0 .../missingIncludes/src/main/foo/foo/f2.sql | 0 .../missingIncludes/src/test/bar/f2.pkg | 0 .../missingIncludes/src/test/bar/foo/f1.pkg | 0 .../missingIncludes/src/test/bar/foo/f1.sql | 0 .../resources/testSourcesTestsParams/pom.xml | 4 +- 17 files changed, 242 insertions(+), 20 deletions(-) create mode 100644 utplsql-maven-plugin/src/test/resources/partialSourceAndTestTag/missingDirectory/pom.xml create mode 100644 utplsql-maven-plugin/src/test/resources/partialSourceAndTestTag/missingDirectory/src/main/plsql/f1.sql create mode 100644 utplsql-maven-plugin/src/test/resources/partialSourceAndTestTag/missingDirectory/src/main/plsql/foo/f2.sql create mode 100644 utplsql-maven-plugin/src/test/resources/partialSourceAndTestTag/missingDirectory/src/test/plsql/f2.pkg create mode 100644 utplsql-maven-plugin/src/test/resources/partialSourceAndTestTag/missingDirectory/src/test/plsql/foo/f1.pkg create mode 100644 utplsql-maven-plugin/src/test/resources/partialSourceAndTestTag/missingDirectory/src/test/plsql/foo/f1.sql create mode 100644 utplsql-maven-plugin/src/test/resources/partialSourceAndTestTag/missingIncludes/pom.xml create mode 100644 utplsql-maven-plugin/src/test/resources/partialSourceAndTestTag/missingIncludes/src/main/foo/f1.sql create mode 100644 utplsql-maven-plugin/src/test/resources/partialSourceAndTestTag/missingIncludes/src/main/foo/foo/f2.sql create mode 100644 utplsql-maven-plugin/src/test/resources/partialSourceAndTestTag/missingIncludes/src/test/bar/f2.pkg create mode 100644 utplsql-maven-plugin/src/test/resources/partialSourceAndTestTag/missingIncludes/src/test/bar/foo/f1.pkg create mode 100644 utplsql-maven-plugin/src/test/resources/partialSourceAndTestTag/missingIncludes/src/test/bar/foo/f1.sql 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 8673638..d25793c 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 @@ -208,13 +208,13 @@ private FileMapperOptions buildSourcesOptions() throws MojoExecutionException { if (sources.isEmpty()) { File defaultSourceDirectory = new File(project.getBasedir(),PluginDefault.SOURCE_DIRECTORY); if (defaultSourceDirectory.exists()) { - sources.add(PluginDefault.buildDefaultSource(project.getBasedir())); + sources.add(PluginDefault.buildDefaultSource()); } else { return new FileMapperOptions(new ArrayList()); } } - List scripts = SQLScannerHelper.findSQLs(project.getBasedir(),sources); + List scripts = SQLScannerHelper.findSQLs(project.getBasedir(),sources,PluginDefault.SOURCE_DIRECTORY, PluginDefault.SOURCE_FILE_PATTERN); FileMapperOptions fileMapperOptions = new FileMapperOptions(scripts); if (StringUtils.isNotEmpty(sourcesOwner)) { @@ -263,15 +263,15 @@ private FileMapperOptions buildTestsOptions() throws MojoExecutionException { try { // Check if this element is empty if (tests.isEmpty()) { - File defaultTestDirecyory = new File(project.getBasedir(),PluginDefault.TEST_DIRECTORY); - if (defaultTestDirecyory.exists()) { - tests.add(PluginDefault.buildDefaultTest(project.getBasedir())); + File defaultTestDirectory = new File(project.getBasedir(),PluginDefault.TEST_DIRECTORY); + if (defaultTestDirectory.exists()) { + tests.add(PluginDefault.buildDefaultTest()); } else { return new FileMapperOptions(new ArrayList()); } } - List scripts = SQLScannerHelper.findSQLs(project.getBasedir(),tests); + List scripts = SQLScannerHelper.findSQLs(project.getBasedir(),tests,PluginDefault.TEST_DIRECTORY, PluginDefault.TEST_FILE_PATTERN); FileMapperOptions fileMapperOptions = new FileMapperOptions(scripts); if (StringUtils.isNotEmpty(testsOwner)) { 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 eb615fe..f645fcb 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 @@ -26,6 +26,16 @@ public class PluginDefault // 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() { @@ -37,9 +47,9 @@ private PluginDefault() * * @return a {@link Resource} */ - public static Resource buildDefaultSource(File baseDir) + public static Resource buildDefaultSource() { - return buildDirectory(baseDir,SOURCE_DIRECTORY, "**/*.*"); + return buildDirectory(SOURCE_DIRECTORY, SOURCE_FILE_PATTERN); } /** @@ -47,15 +57,15 @@ public static Resource buildDefaultSource(File baseDir) * * @return a {@link Resource} */ - public static Resource buildDefaultTest(File baseDir) + public static Resource buildDefaultTest() { - return buildDirectory(baseDir, TEST_DIRECTORY, "**/*.pkg"); + return buildDirectory(TEST_DIRECTORY, TEST_FILE_PATTERN); } - private static Resource buildDirectory(File baseDir, String directory, String includes) + private static Resource buildDirectory(String directory, String includes) { Resource resource = new Resource(); - resource.setDirectory(baseDir.getAbsolutePath()+"/"+directory); + resource.setDirectory(directory); resource.setIncludes(Arrays.asList(includes)); return resource; } 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 4a177f8..b73facf 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 @@ -27,12 +27,21 @@ private SQLScannerHelper() { * @param resouces * @return */ - public static List findSQLs(File baseDir,List resources) { + 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(resource); + 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()); @@ -51,16 +60,16 @@ public static List findSQLs(File baseDir,List resources) { * @param resource * @return */ - private static DirectoryScanner buildScanner(Resource resource) { + private static DirectoryScanner buildScanner(String baseDir,Resource resource) { if (resource != null) { - File baseDir = new File(resource.getDirectory()); - if (!baseDir.exists() || !baseDir.isDirectory() || !baseDir.canRead()) { + 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())); } DirectoryScanner scanner = new DirectoryScanner(); - scanner.setBasedir(resource.getDirectory()); + scanner.setBasedir(fileBaseDir.getPath()); scanner.setIncludes(resource.getIncludes().toArray(new String[0])); scanner.setExcludes(resource.getExcludes().toArray(new String[0])); return scanner; 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 bb69e06..b51bb7d 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 @@ -158,4 +158,57 @@ public void testSourcesAndTestsParameterDoesNotExistButDefaultDirectoryExists() 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")); + } + + } diff --git a/utplsql-maven-plugin/src/test/resources/partialSourceAndTestTag/missingDirectory/pom.xml b/utplsql-maven-plugin/src/test/resources/partialSourceAndTestTag/missingDirectory/pom.xml new file mode 100644 index 0000000..796dda3 --- /dev/null +++ b/utplsql-maven-plugin/src/test/resources/partialSourceAndTestTag/missingDirectory/pom.xml @@ -0,0 +1,80 @@ + + 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 + + + + + + + **/*sql + + + + + + + **/*sql + + + + + + **/*.pkg + + + + + + + + \ No newline at end of file diff --git a/utplsql-maven-plugin/src/test/resources/partialSourceAndTestTag/missingDirectory/src/main/plsql/f1.sql b/utplsql-maven-plugin/src/test/resources/partialSourceAndTestTag/missingDirectory/src/main/plsql/f1.sql new file mode 100644 index 0000000..e69de29 diff --git a/utplsql-maven-plugin/src/test/resources/partialSourceAndTestTag/missingDirectory/src/main/plsql/foo/f2.sql b/utplsql-maven-plugin/src/test/resources/partialSourceAndTestTag/missingDirectory/src/main/plsql/foo/f2.sql new file mode 100644 index 0000000..e69de29 diff --git a/utplsql-maven-plugin/src/test/resources/partialSourceAndTestTag/missingDirectory/src/test/plsql/f2.pkg b/utplsql-maven-plugin/src/test/resources/partialSourceAndTestTag/missingDirectory/src/test/plsql/f2.pkg new file mode 100644 index 0000000..e69de29 diff --git a/utplsql-maven-plugin/src/test/resources/partialSourceAndTestTag/missingDirectory/src/test/plsql/foo/f1.pkg b/utplsql-maven-plugin/src/test/resources/partialSourceAndTestTag/missingDirectory/src/test/plsql/foo/f1.pkg new file mode 100644 index 0000000..e69de29 diff --git a/utplsql-maven-plugin/src/test/resources/partialSourceAndTestTag/missingDirectory/src/test/plsql/foo/f1.sql b/utplsql-maven-plugin/src/test/resources/partialSourceAndTestTag/missingDirectory/src/test/plsql/foo/f1.sql new file mode 100644 index 0000000..e69de29 diff --git a/utplsql-maven-plugin/src/test/resources/partialSourceAndTestTag/missingIncludes/pom.xml b/utplsql-maven-plugin/src/test/resources/partialSourceAndTestTag/missingIncludes/pom.xml new file mode 100644 index 0000000..e6459bf --- /dev/null +++ b/utplsql-maven-plugin/src/test/resources/partialSourceAndTestTag/missingIncludes/pom.xml @@ -0,0 +1,70 @@ + + 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 + + + + + + src/main/foo + + + + + src/test/bar + + + + + + + \ No newline at end of file diff --git a/utplsql-maven-plugin/src/test/resources/partialSourceAndTestTag/missingIncludes/src/main/foo/f1.sql b/utplsql-maven-plugin/src/test/resources/partialSourceAndTestTag/missingIncludes/src/main/foo/f1.sql new file mode 100644 index 0000000..e69de29 diff --git a/utplsql-maven-plugin/src/test/resources/partialSourceAndTestTag/missingIncludes/src/main/foo/foo/f2.sql b/utplsql-maven-plugin/src/test/resources/partialSourceAndTestTag/missingIncludes/src/main/foo/foo/f2.sql new file mode 100644 index 0000000..e69de29 diff --git a/utplsql-maven-plugin/src/test/resources/partialSourceAndTestTag/missingIncludes/src/test/bar/f2.pkg b/utplsql-maven-plugin/src/test/resources/partialSourceAndTestTag/missingIncludes/src/test/bar/f2.pkg new file mode 100644 index 0000000..e69de29 diff --git a/utplsql-maven-plugin/src/test/resources/partialSourceAndTestTag/missingIncludes/src/test/bar/foo/f1.pkg b/utplsql-maven-plugin/src/test/resources/partialSourceAndTestTag/missingIncludes/src/test/bar/foo/f1.pkg new file mode 100644 index 0000000..e69de29 diff --git a/utplsql-maven-plugin/src/test/resources/partialSourceAndTestTag/missingIncludes/src/test/bar/foo/f1.sql b/utplsql-maven-plugin/src/test/resources/partialSourceAndTestTag/missingIncludes/src/test/bar/foo/f1.sql new file mode 100644 index 0000000..e69de29 diff --git a/utplsql-maven-plugin/src/test/resources/testSourcesTestsParams/pom.xml b/utplsql-maven-plugin/src/test/resources/testSourcesTestsParams/pom.xml index 69ba53e..21139f8 100644 --- a/utplsql-maven-plugin/src/test/resources/testSourcesTestsParams/pom.xml +++ b/utplsql-maven-plugin/src/test/resources/testSourcesTestsParams/pom.xml @@ -55,7 +55,7 @@ - src/test/resources/testSourcesTestsParams/srcs + srcs **/*sql @@ -75,7 +75,7 @@ - src/test/resources/testSourcesTestsParams/te/st + te/st **/*.spc **/*.bdy From 9722a4fb07d078f25bd5044976377236b541fdf5 Mon Sep 17 00:00:00 2001 From: jgarec Date: Wed, 1 Aug 2018 19:26:24 +0000 Subject: [PATCH 55/71] Fixes #27 : color logging is based on maven configuration (#31) -B (batchmode) and -l (output to file) removes coloration -Dstyle.color=never removes coloration Note: style.color seems to require at least maven 3.5.3 --- .../org/utplsql/maven/plugin/UtPLSQLMojo.java | 11 +++--- .../maven/plugin/helper/PluginDefault.java | 37 ------------------- 2 files changed, 6 insertions(+), 42 deletions(-) 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 d25793c..1dbcfd2 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 @@ -16,6 +16,7 @@ import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; +import org.apache.maven.shared.utils.logging.MessageUtils; import org.utplsql.api.DBHelper; import org.utplsql.api.FileMapperOptions; import org.utplsql.api.JavaApiVersionInfo; @@ -61,14 +62,14 @@ public class UtPLSQLMojo extends AbstractMojo { protected boolean skipCompatibilityCheck; @Parameter - protected List reporters = new ArrayList(); + protected List reporters = new ArrayList<>(); @Parameter - protected List paths = new ArrayList(); + protected List paths = new ArrayList<>(); // Sources Configuration @Parameter - protected List sources = new ArrayList(); + protected List sources = new ArrayList<>(); @Parameter private String sourcesOwner; @@ -117,8 +118,8 @@ public class UtPLSQLMojo extends AbstractMojo { @Parameter(defaultValue = "${maven.test.failure.ignore}") protected boolean ignoreFailure; - // Color in the console, loaded by environment variables - private boolean colorConsole = PluginDefault.resolveColor(); + // Color in the console, bases on maven logging configuration + private boolean colorConsole = MessageUtils.isColorEnabled(); // Reporter Writer private ReporterWriter reporterWriter; 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 f645fcb..869747f 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 @@ -1,8 +1,6 @@ package org.utplsql.maven.plugin.helper; -import java.io.File; import java.util.Arrays; -import java.util.Map; import org.apache.maven.model.Resource; @@ -14,13 +12,6 @@ */ public class PluginDefault { - - private static final String STYLE_COLOR_PROPERTY = "style.color"; - - private static final String BATCH_MODE = "B"; - - private static final String LOG_FILE = "l"; - // Source Directory public static final String SOURCE_DIRECTORY = "src/main/plsql"; @@ -69,32 +60,4 @@ private static Resource buildDirectory(String directory, String includes) resource.setIncludes(Arrays.asList(includes)); return resource; } - - /** - * - * @return - */ - public static boolean resolveColor() - { - final Map env = System.getenv(); - String color = env.get(STYLE_COLOR_PROPERTY); - - if ("always".equals(color)) - { - return true; - } - - if ("never".equals(color)) - { - return false; - } - - if (env.containsKey(BATCH_MODE) || env.containsKey(LOG_FILE)) - { - return false; - } - - return false; - } - } From 50da81e579a1c5fef50b8855666b45ae5cc9b3fd Mon Sep 17 00:00:00 2001 From: Vinicius Avellar Date: Thu, 6 Sep 2018 22:52:21 +0100 Subject: [PATCH 56/71] Sets the console output on by default if no output option specified --- README.md | 129 ++++++++++-------- .../maven/plugin/test/UtPLSQLMojoIT.java | 9 +- utplsql-maven-plugin/pom.xml | 10 +- .../org/utplsql/maven/plugin/UtPLSQLMojo.java | 5 + .../maven/plugin/model/ReporterParameter.java | 10 +- .../maven/plugin/test/UtPLSQLMojoTest.java | 87 ++++++++++++ .../defaultConsoleOutputBehaviour/pom.xml | 84 ++++++++++++ 7 files changed, 267 insertions(+), 67 deletions(-) create mode 100644 utplsql-maven-plugin/src/test/resources/defaultConsoleOutputBehaviour/pom.xml diff --git a/README.md b/README.md index e7dbb4f..ce82511 100644 --- a/README.md +++ b/README.md @@ -101,66 +101,75 @@ You have to be a fully utPLSQL environment available compatible with the Java AP 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 - - - - - + 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.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 + + + + + + + + + ``` 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 af730c8..1c2a301 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 @@ -174,13 +174,16 @@ private void checkReportsGenerated(String projectName, String... files) { // 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("(duration=\"[0-9\\.]*\")", "duration=\"1\"")) + + 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!", outputContent, - FileUtils.readFileToString(expectedOutputFile, "utf-8").replace("\r", "")); + Assert.assertEquals("The files differ!", + FileUtils.readFileToString(expectedOutputFile, "utf-8").replace("\r", ""), outputContent); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); diff --git a/utplsql-maven-plugin/pom.xml b/utplsql-maven-plugin/pom.xml index 9a4d6a9..32c92a3 100644 --- a/utplsql-maven-plugin/pom.xml +++ b/utplsql-maven-plugin/pom.xml @@ -19,6 +19,7 @@ UTF-8 1.8 + 1.7.4 @@ -64,9 +65,16 @@ org.powermock powermock-module-junit4 - 1.7.4 + ${powermock.version} test + + + org.powermock + powermock-api-mockito2 + ${powermock.version} + test + org.apache.maven.plugin-testing 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 1dbcfd2..3f07121 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 @@ -332,6 +332,11 @@ private List initReporters(Connection connection) throws SQLException 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()) { 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 979d7cc..019c0e0 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 @@ -12,7 +12,7 @@ public class ReporterParameter private String fileOutput; // Writes the report to console - private boolean consoleOutput; + private Boolean consoleOutput; /** * @@ -55,13 +55,17 @@ public void setFileOutput(String fileOutput) { this.fileOutput = fileOutput; } + + public Boolean getConsoleOutput() { + return consoleOutput; + } /** * @return the consoleOutput */ - public boolean isConsoleOutput() + public Boolean isConsoleOutput() { - return consoleOutput; + return null != consoleOutput && consoleOutput; } /** 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 b51bb7d..6cd6891 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 @@ -1,21 +1,47 @@ package org.utplsql.maven.plugin.test; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.powermock.api.mockito.PowerMockito.mockStatic; +import static org.powermock.api.mockito.PowerMockito.when; import java.io.File; +import java.sql.Connection; +import java.util.ArrayList; import java.util.List; +import org.apache.commons.lang3.tuple.Pair; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.testing.MojoRule; import org.junit.Assert; +import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.reflect.Whitebox; +import org.utplsql.api.DBHelper; import org.utplsql.api.FileMapperOptions; +import org.utplsql.api.Version; +import org.utplsql.api.reporter.Reporter; +import org.utplsql.api.reporter.ReporterFactory; import org.utplsql.maven.plugin.UtPLSQLMojo; +import org.utplsql.maven.plugin.model.ReporterParameter; +import org.utplsql.maven.plugin.reporter.ReporterWriter; +@RunWith(PowerMockRunner.class) +@PrepareForTest({ + DBHelper.class, + ReporterFactory.class}) public class UtPLSQLMojoTest { @Rule @@ -24,6 +50,24 @@ public class UtPLSQLMojoTest { @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. * @@ -210,5 +254,48 @@ public void testSourcesAndTestsParameterHaveNotIncludesTag() throws Exception { 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); + + // 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"); + 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"); + 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()); + } } diff --git a/utplsql-maven-plugin/src/test/resources/defaultConsoleOutputBehaviour/pom.xml b/utplsql-maven-plugin/src/test/resources/defaultConsoleOutputBehaviour/pom.xml new file mode 100644 index 0000000..0bfc40f --- /dev/null +++ b/utplsql-maven-plugin/src/test/resources/defaultConsoleOutputBehaviour/pom.xml @@ -0,0 +1,84 @@ + + 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_DOCUMENTATION_REPORTER + + + UT_DOCUMENTATION_REPORTER + false + + + UT_COVERAGE_SONAR_REPORTER + coverage-sonar-reporter.xml + + + UT_SONAR_TEST_REPORTER + utplsql/sonar-test-reporter.xml + true + + + + + + foo + + **/*sql + + + + + + + bar + + **/*.spc + **/*.bdy + + + + + + + + \ No newline at end of file From 0dd57b91abafcfe3219cece378de9bb283a1bd28 Mon Sep 17 00:00:00 2001 From: Vinicius Avellar Date: Tue, 2 Oct 2018 23:27:35 +0100 Subject: [PATCH 57/71] #28 Optional reporters tag --- .../org/utplsql/maven/plugin/UtPLSQLMojo.java | 49 ++++++++++--------- .../maven/plugin/test/UtPLSQLMojoTest.java | 25 +++++++++- 2 files changed, 51 insertions(+), 23 deletions(-) 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 3f07121..f0df3d0 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 @@ -24,6 +24,7 @@ import org.utplsql.api.TestRunner; import org.utplsql.api.Version; import org.utplsql.api.exception.SomeTestsFailedException; +import org.utplsql.api.reporter.CoreReporters; import org.utplsql.api.reporter.Reporter; import org.utplsql.api.reporter.ReporterFactory; import org.utplsql.maven.plugin.helper.PluginDefault; @@ -138,21 +139,25 @@ public void execute() throws MojoExecutionException { try { FileMapperOptions sourceMappingOptions = buildSourcesOptions(); FileMapperOptions testMappingOptions = buildTestsOptions(); - - // Create the Connection to the Database + connection = DriverManager.getConnection(url, user, password); - getLog().info("utPLSQL Version = " + DBHelper.getDatabaseFrameworkVersion(connection)); - - List reporterList = initReporters(connection); - + + 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) + TestRunner runner = new TestRunner() + .addPathList(paths) + .addReporterList(reporterList) + .sourceMappingOptions(sourceMappingOptions) + .testMappingOptions(testMappingOptions) + .skipCompatibilityCheck(skipCompatibilityCheck) + .colorConsole(colorConsole) .failOnErrors(!ignoreFailure); - - // Setting Optional Parameters + if (StringUtils.isNotBlank(excludeObject)) { runner.excludeObject(excludeObject); } @@ -170,9 +175,9 @@ public void execute() throws MojoExecutionException { throw new MojoExecutionException(e.getMessage(), e); } finally { try { - // Write Reporters - if (connection != null) + if (null != connection) { reporterWriter.writeReporters(connection); + } } catch (Exception e) { getLog().error(e.getMessage(), e); } @@ -205,7 +210,6 @@ private void loadConfFromEnvironment() { */ private FileMapperOptions buildSourcesOptions() throws MojoExecutionException { try { - // Check if this element is empty if (sources.isEmpty()) { File defaultSourceDirectory = new File(project.getBasedir(),PluginDefault.SOURCE_DIRECTORY); if (defaultSourceDirectory.exists()) { @@ -262,7 +266,6 @@ private FileMapperOptions buildSourcesOptions() throws MojoExecutionException { */ private FileMapperOptions buildTestsOptions() throws MojoExecutionException { try { - // Check if this element is empty if (tests.isEmpty()) { File defaultTestDirectory = new File(project.getBasedir(),PluginDefault.TEST_DIRECTORY); if (defaultTestDirectory.exists()) { @@ -318,15 +321,18 @@ private FileMapperOptions buildTestsOptions() throws MojoExecutionException { * @return * @throws SQLException */ - private List initReporters(Connection connection) throws SQLException { - List reporterList = new ArrayList<>(); - - Version utlVersion = DBHelper.getDatabaseFrameworkVersion(connection); + private List initReporters( + Connection connection, Version utlVersion, ReporterFactory reporterFactory) throws SQLException { - // Initialized Reporters + List reporterList = new ArrayList<>(); reporterWriter = new ReporterWriter(targetDir, utlVersion); - ReporterFactory reporterFactory = ReporterFactory.createEmpty(); + 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()); @@ -358,7 +364,6 @@ private void logParameters(FileMapperOptions sourceMappingOptions, FileMapperOpt Log log = getLog(); log.info("Invoking TestRunner with: " + targetDir); - // Do nothing when the debug is disabled if (!log.isDebugEnabled()) { return; } 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 6cd6891..be464b9 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 @@ -266,7 +266,7 @@ public void testDefaultConsoleBehaviour() throws Exception { return mockReporter; }); - Whitebox.invokeMethod(utplsqlMojo, "initReporters", mockConnection); + 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"); @@ -298,4 +298,27 @@ public void testDefaultConsoleBehaviour() throws Exception { assertTrue(reporterParameter3.isFileOutput()); } + @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); + when(mockReporter.getTypeName()).thenReturn(invocation.getArgument(0)); + 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); + } + } From a51ff7457f387a856867c3c08587917691263551 Mon Sep 17 00:00:00 2001 From: Vinicius Avellar Date: Wed, 3 Oct 2018 23:29:22 +0100 Subject: [PATCH 58/71] #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 59/71] 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 60/71] 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 61/71] 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 + + + + + + + + + From 4ef5c165ebdce07eb1ffd150ab0599d66684a3eb Mon Sep 17 00:00:00 2001 From: Vinicius Avellar Date: Sun, 14 Oct 2018 12:10:05 +0100 Subject: [PATCH 62/71] Added travis deploy configuration --- .travis.yml | 41 +++++++++++++++++--------------------- .travis/create_release.sh | 33 ------------------------------ .travis/deploy_release.sh | 8 ++++++++ .travis/deploy_snapshot.sh | 12 +++++++++++ 4 files changed, 38 insertions(+), 56 deletions(-) delete mode 100644 .travis/create_release.sh create mode 100644 .travis/deploy_release.sh create mode 100644 .travis/deploy_snapshot.sh diff --git a/.travis.yml b/.travis.yml index f0731e2..9b55ab2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,6 +20,8 @@ env: - CACHE_DIR=$HOME/.cache - MAVEN_HOME=/usr/local/maven - MAVEN_CFG=$HOME/.m2 + - MAVEN_HELP_PLUGIN="org.apache.maven.plugins:maven-help-plugin:3.1.0" + - MAVEN_VERSION_PLUGIN="org.codehaus.mojo:versions-maven-plugin:2.7" - DB_URL="127.0.0.1:1521:XE" - DB_UT3_USER=ut3 - DB_UT3_PASS=ut3 @@ -46,33 +48,26 @@ script: - mvn org.jacoco:jacoco-maven-plugin:prepare-agent verify -Dmaven.skip.test -DdbUser="${DB_UT3_USER}" -DdbPass="${DB_UT3_PASS}" -DdbUrl="jdbc:oracle:thin:@${DB_URL}" - mvn sonar:sonar +before_deploy: + - bash $GPG_SECRET_KEYS | base64 --decode | $GPG_EXECUTABLE --import + - bash $GPG_OWNERTRUST | base64 --decode | $GPG_EXECUTABLE --import-ownertrust -#before_deploy: -# - bash .travis/create_release.sh -# - if [ ! -z "$TRAVIS_TAG" ]; then VERSION=$(tr -d "/v/" <<<$TRAVIS_TAG); mvn org.codehaus.mojo:versions-maven-plugin:2.1:set -DnewVersion=${VERSION}; fi -# -#deploy: -# - provider: releases -# api_key: $GITHUB_API_TOKEN -# file: utPLSQL-cli.zip -# skip_cleanup: true -# on: -# repository: utPLSQL/utPLSQL-cli -# tags: true -# - provider: bintray -# file: bintray.json -# user: ${BINTRAY_USER} -# key: ${BINTRAY_API_KEY} -# dry-run: false -# skip_cleanup: true -# on: -# repository: utPLSQL/utPLSQL-cli -# branch: develop -# +deploy: + - provider: script + script: ./travis/deploy_snapshot.sh + on: + repo: utPLSQL/utplsql-maven-plugin + branch: develop + - provider: script + script: ./travis/deploy_release.sh + on: + repo: utPLSQL/utplsql-maven-plugin + branch: master + tags: true notifications: slack: rooms: - secure: "Gz0pGOOM6xbnz8Q/B3RzOFoVr8QGXsDSHcgCloPnO3ZkEOh4JJikqWAVdZrksMxhewIBRpbdIWAZOgsNXvW+cEDXxfml3X9Clj2wg5Uon97UeI+5WEHDhLYHn7t9EYr9QvVSOuQgBIiddk6kURxY4N0eAA4VUti8BDcMRq+gPxF1w/toFJXVR/I/tkLxcHPTbWQ9X87nNWcQgMoHe2AixYpglntmtoLXJ5F8MF08fcyTX7GJQ5xjq7HbYy+/39nEhQo2ZPhHHfk2rS6gIUY0wc+MAqobxvesplgGDybdTQyrdl48VjJ/CiQDedglUbNN9VYTFjPIYMdWCUCLV1uL866aNMiBpB7CQoNhi5WS7RERE9gblVPX2k6tOda27fEWlhjha6OmdK6TQ9qTITU7U4OTSOz41dDPeVfqMHRggxo3ozlLONTiZ1y9fz/Ez9WjiJjtUDt60vgnVIo7BcQV/yDJcqAtQbfWyf0n73g5lMBvLGnO2Agm2N7hNEeCbpr+PZUoqkEM/e4SxdUCQGi8Ppi9Zp0E4v0iG7hyjzol+G4T8JN0bUGg0OOow/bfZa5J2aUsrC1qP/ZLpMA94NI6ZlL2wRHhZ9JtVSDLjtSwq9yW5XF7o7kdqBWBCslbGnYPoCoHOzfZuUvArSlRoGNu75dw/Qhoo9gFl1RG/RlChaU=" on_success: change - on_failure: always \ No newline at end of file + on_failure: always diff --git a/.travis/create_release.sh b/.travis/create_release.sh deleted file mode 100644 index f0656c9..0000000 --- a/.travis/create_release.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash -set -ev - -VERSION=`date +%Y%m%d%H%M` - -#overcome maven assemble issue: https://github.com/mojohaus/appassembler/issues/61 -sed -i '/CYGWIN\*) cygwin=true/c\ CYGWIN*|MINGW*) cygwin=true ;;' target/appassembler/bin/utplsql - -mkdir dist -mv target/appassembler utPLSQL-cli -# Remove Oracle libraries du to licensing problems -rm -f utPLSQL-cli/lib/ucp*.jar -rm -f utPLSQL-cli/lib/ojdbc8*.jar -rm -f utPLSQL-cli/lib/orai18n*.jar - -zip -r -q dist/utPLSQL-cli-${TRAVIS_BRANCH}-${VERSION}.zip utPLSQL-cli -zip -r -q utPLSQL-cli.zip utPLSQL-cli - -cat > bintray.json < Date: Sat, 20 Oct 2018 17:10:09 +0100 Subject: [PATCH 63/71] Fix repo name --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9b55ab2..a448e0e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -56,12 +56,12 @@ deploy: - provider: script script: ./travis/deploy_snapshot.sh on: - repo: utPLSQL/utplsql-maven-plugin + repo: utPLSQL/utPLSQL-maven-plugin branch: develop - provider: script script: ./travis/deploy_release.sh on: - repo: utPLSQL/utplsql-maven-plugin + repo: utPLSQL/utPLSQL-maven-plugin branch: master tags: true From 33a53a3e4164b37e2a7428dd7763a73f34d23296 Mon Sep 17 00:00:00 2001 From: Vinicius Avellar Date: Sat, 20 Oct 2018 17:26:01 +0100 Subject: [PATCH 64/71] Fix gpg key command --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index a448e0e..a5c3d48 100644 --- a/.travis.yml +++ b/.travis.yml @@ -49,8 +49,8 @@ script: - mvn sonar:sonar before_deploy: - - bash $GPG_SECRET_KEYS | base64 --decode | $GPG_EXECUTABLE --import - - bash $GPG_OWNERTRUST | base64 --decode | $GPG_EXECUTABLE --import-ownertrust + - $GPG_SECRET_KEYS | base64 --decode | $GPG_EXECUTABLE --import + - $GPG_OWNERTRUST | base64 --decode | $GPG_EXECUTABLE --import-ownertrust deploy: - provider: script From e055f42a25f425bac8b266de5ffaf6639984cce7 Mon Sep 17 00:00:00 2001 From: Vinicius Avellar Date: Sat, 20 Oct 2018 17:40:48 +0100 Subject: [PATCH 65/71] Fix gpg commands --- .travis.yml | 4 ++-- nil | 0 2 files changed, 2 insertions(+), 2 deletions(-) create mode 100644 nil diff --git a/.travis.yml b/.travis.yml index a5c3d48..e91d658 100644 --- a/.travis.yml +++ b/.travis.yml @@ -49,8 +49,8 @@ script: - mvn sonar:sonar before_deploy: - - $GPG_SECRET_KEYS | base64 --decode | $GPG_EXECUTABLE --import - - $GPG_OWNERTRUST | base64 --decode | $GPG_EXECUTABLE --import-ownertrust + - echo $GPG_SECRET_KEYS | base64 --decode | $GPG_EXECUTABLE --import + - echo $GPG_OWNERTRUST | base64 --decode | $GPG_EXECUTABLE --import-ownertrust deploy: - provider: script diff --git a/nil b/nil new file mode 100644 index 0000000..e69de29 From eb8443bd51054c7f6f1894cb1752d932495d6222 Mon Sep 17 00:00:00 2001 From: Vinicius Avellar Date: Sat, 20 Oct 2018 17:51:22 +0100 Subject: [PATCH 66/71] Added skip_cleanup config --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index e91d658..5af9306 100644 --- a/.travis.yml +++ b/.travis.yml @@ -54,11 +54,13 @@ before_deploy: deploy: - provider: script + skip_cleanup: true script: ./travis/deploy_snapshot.sh on: repo: utPLSQL/utPLSQL-maven-plugin branch: develop - provider: script + skip_cleanup: true script: ./travis/deploy_release.sh on: repo: utPLSQL/utPLSQL-maven-plugin From e69889b31cfaa7675d1bdbd4303b52d3c899e8f3 Mon Sep 17 00:00:00 2001 From: Vinicius Avellar Date: Sat, 20 Oct 2018 18:02:24 +0100 Subject: [PATCH 67/71] Added execute permissions to deployment scripts --- .travis/deploy_release.sh | 0 .travis/deploy_snapshot.sh | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 .travis/deploy_release.sh mode change 100644 => 100755 .travis/deploy_snapshot.sh diff --git a/.travis/deploy_release.sh b/.travis/deploy_release.sh old mode 100644 new mode 100755 diff --git a/.travis/deploy_snapshot.sh b/.travis/deploy_snapshot.sh old mode 100644 new mode 100755 From 3aec0d83e06dba9c28db9eca842364bb409a9b68 Mon Sep 17 00:00:00 2001 From: Vinicius Avellar Date: Sat, 20 Oct 2018 18:17:54 +0100 Subject: [PATCH 68/71] Fix deployment script path --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5af9306..75fa96f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -55,13 +55,13 @@ before_deploy: deploy: - provider: script skip_cleanup: true - script: ./travis/deploy_snapshot.sh + script: .travis/deploy_snapshot.sh on: repo: utPLSQL/utPLSQL-maven-plugin branch: develop - provider: script skip_cleanup: true - script: ./travis/deploy_release.sh + script: .travis/deploy_release.sh on: repo: utPLSQL/utPLSQL-maven-plugin branch: master From 7c62ea687e7081aa4d34366849aae7458e80d4a5 Mon Sep 17 00:00:00 2001 From: Vinicius Avellar Date: Sat, 20 Oct 2018 18:46:09 +0100 Subject: [PATCH 69/71] Deployment scripts tidy up --- .travis.yml | 2 -- .travis/deploy_release.sh | 4 ++-- .travis/deploy_snapshot.sh | 4 ++-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 75fa96f..a2ede99 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,8 +20,6 @@ env: - CACHE_DIR=$HOME/.cache - MAVEN_HOME=/usr/local/maven - MAVEN_CFG=$HOME/.m2 - - MAVEN_HELP_PLUGIN="org.apache.maven.plugins:maven-help-plugin:3.1.0" - - MAVEN_VERSION_PLUGIN="org.codehaus.mojo:versions-maven-plugin:2.7" - DB_URL="127.0.0.1:1521:XE" - DB_UT3_USER=ut3 - DB_UT3_PASS=ut3 diff --git a/.travis/deploy_release.sh b/.travis/deploy_release.sh index 362ac27..e8c0124 100755 --- a/.travis/deploy_release.sh +++ b/.travis/deploy_release.sh @@ -1,8 +1,8 @@ #!/bin/bash set -ev -VERSION=$(tr -d "/v/" <<<$TRAVIS_TAG); -mvn $MAVEN_VERSION_PLUGIN:set -DnewVersion=${VERSION}; +VERSION=$(tr -d "/v/" <<<${TRAVIS_TAG}) +mvn org.codehaus.mojo:versions-maven-plugin:2.7:set -DnewVersion=${VERSION} cd utplsql-maven-plugin mvn deploy -DskipTests -U -Prelease diff --git a/.travis/deploy_snapshot.sh b/.travis/deploy_snapshot.sh index 70e817c..516af76 100755 --- a/.travis/deploy_snapshot.sh +++ b/.travis/deploy_snapshot.sh @@ -2,11 +2,11 @@ set -ev DATE=`date +%Y%m%d%H%M` -OLD_VERSION=`mvn -q ${MAVEN_HELP_PLUGIN}:evaluate -DforceStdout -Dexpression=project.version` +OLD_VERSION=`mvn -q org.apache.maven.plugins:maven-help-plugin:3.1.0:evaluate -DforceStdout -Dexpression=project.version` VERSION=`sed "s/-SNAPSHOT/-${DATE}-SNAPSHOT/g" <<<"${OLD_VERSION}"` echo "Changing snapshot version, OLD: ${OLD_VERSION} NEW: ${VERSION}" -mvn $MAVEN_VERSION_PLUGIN:set -DnewVersion=${VERSION}; +mvn org.codehaus.mojo:versions-maven-plugin:2.7:set -DnewVersion=${VERSION} cd utplsql-maven-plugin mvn deploy -DskipTests -U -Prelease From 8f1395fd7bf8326cc927b52ff739d972fe099cbc Mon Sep 17 00:00:00 2001 From: Vinicius Avellar Date: Sat, 20 Oct 2018 18:58:12 +0100 Subject: [PATCH 70/71] Using bash to run the deployment script --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index a2ede99..2637680 100644 --- a/.travis.yml +++ b/.travis.yml @@ -53,13 +53,13 @@ before_deploy: deploy: - provider: script skip_cleanup: true - script: .travis/deploy_snapshot.sh + script: bash .travis/deploy_snapshot.sh on: repo: utPLSQL/utPLSQL-maven-plugin branch: develop - provider: script skip_cleanup: true - script: .travis/deploy_release.sh + script: bash .travis/deploy_release.sh on: repo: utPLSQL/utPLSQL-maven-plugin branch: master From d9bdc141e7f85c507c53227d07b5a7ccb62c26de Mon Sep 17 00:00:00 2001 From: Jacek Gebal Date: Sat, 20 Oct 2018 22:29:09 +0100 Subject: [PATCH 71/71] Update of `deploy_snapshot.sh` to obtain version using echo. --- .travis/deploy_snapshot.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis/deploy_snapshot.sh b/.travis/deploy_snapshot.sh index 516af76..c5cbf3e 100755 --- a/.travis/deploy_snapshot.sh +++ b/.travis/deploy_snapshot.sh @@ -2,7 +2,8 @@ set -ev DATE=`date +%Y%m%d%H%M` -OLD_VERSION=`mvn -q org.apache.maven.plugins:maven-help-plugin:3.1.0:evaluate -DforceStdout -Dexpression=project.version` +#using this solution to get version into variable: https://stackoverflow.com/a/26514030/1470603 +OLD_VERSION=$(mvn -q -Dexec.executable=echo -Dexec.args='${project.version}' --non-recursive exec:exec) VERSION=`sed "s/-SNAPSHOT/-${DATE}-SNAPSHOT/g" <<<"${OLD_VERSION}"` echo "Changing snapshot version, OLD: ${OLD_VERSION} NEW: ${VERSION}"