diff --git a/.travis.yml b/.travis.yml index 5ef4630..8201fd0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,7 +34,7 @@ install: script: - mvn package -DskipTests - - mvn package jar:jar appassembler:assemble + - mvn package verify jar:jar appassembler:assemble before_deploy: - bash .travis/create_release.sh diff --git a/pom.xml b/pom.xml index 052f898..71f6616 100644 --- a/pom.xml +++ b/pom.xml @@ -10,17 +10,19 @@ cli http://maven.apache.org - - UTF-8 - 1.8 - 1.8 - + + UTF-8 + 1.8 + 1.8 + 1.0.3 + 5.0.3 + org.utplsql java-api - 3.0.4-SNAPSHOT + 3.0.5-SNAPSHOT compile @@ -48,11 +50,17 @@ compile - junit - junit - 4.12 + org.junit.jupiter + junit-jupiter-api + ${junit.jupiter.version} test - + + + org.junit.jupiter + junit-jupiter-engine + ${junit.jupiter.version} + test + @@ -75,6 +83,43 @@ + + org.apache.maven.plugins + maven-surefire-plugin + 2.19.1 + + + **/*IT.java + + + + + org.junit.platform + junit-platform-surefire-provider + ${junit.platform.version} + + + + + org.apache.maven.plugins + maven-failsafe-plugin + 2.19.1 + + + + integration-test + verify + + + + + + org.junit.platform + junit-platform-surefire-provider + ${junit.platform.version} + + + @@ -93,4 +138,26 @@ + + + utPLSQL-local + + + + + org.apache.maven.plugins + maven-failsafe-plugin + + + ${dbUrl} + ${dbUser} + ${dbPass} + + + + + + + + diff --git a/src/main/java/org/utplsql/cli/RunCommand.java b/src/main/java/org/utplsql/cli/RunCommand.java index 4f41d02..fbf5e3c 100644 --- a/src/main/java/org/utplsql/cli/RunCommand.java +++ b/src/main/java/org/utplsql/cli/RunCommand.java @@ -4,9 +4,8 @@ import com.beust.jcommander.Parameters; import org.utplsql.api.*; import org.utplsql.api.compatibility.CompatibilityProxy; -import org.utplsql.api.compatibility.OptionalFeatures; -import org.utplsql.api.exception.DatabaseNotCompatibleException; import org.utplsql.api.exception.SomeTestsFailedException; +import org.utplsql.api.reporter.CoverageHTMLReporter; import org.utplsql.api.reporter.Reporter; import org.utplsql.api.reporter.ReporterFactory; import org.utplsql.cli.exception.DatabaseConnectionFailed; @@ -15,6 +14,7 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.PrintStream; +import java.nio.file.Paths; import java.sql.Connection; import java.sql.SQLException; import java.util.ArrayList; @@ -219,6 +219,13 @@ private List initReporters( Connection conn, List rep for (ReporterOptions ro : reporterOptionsList) { Reporter reporter = ReporterFactory.createReporter(ro.getReporterName()); + + // Quick-hack for CoverageHTML Reporter + if ( reporter instanceof CoverageHTMLReporter && ro.outputToFile() ) { + ((CoverageHTMLReporter)reporter).setAssetsPath(ro.getOutputFileName()+"_assets/"); + CoverageHTMLReporter.writeReportAssetsTo(Paths.get(ro.getOutputFileName()+"_assets/")); + } + reporter.init(conn); ro.setReporterObj(reporter); reporterList.add(reporter); diff --git a/src/test/java/org/utplsql/cli/FileWalkerTest.java b/src/test/java/org/utplsql/cli/FileWalkerTest.java index b8e2738..9c00a8d 100644 --- a/src/test/java/org/utplsql/cli/FileWalkerTest.java +++ b/src/test/java/org/utplsql/cli/FileWalkerTest.java @@ -1,12 +1,13 @@ package org.utplsql.cli; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.File; import java.util.Collections; import java.util.List; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; + /** * Created by Vinicius on 18/06/2017. */ @@ -18,7 +19,7 @@ public class FileWalkerTest { public void fileWalker_Relative() { List fileList = new FileWalker().getFileList(BASE_DIR, "source"); Collections.sort(fileList); - Assert.assertArrayEquals(new Object[] { + assertArrayEquals(new Object[] { "source/packages/package.pkb".replace('/', File.separatorChar), "source/packages/package.pks".replace('/', File.separatorChar), "source/script.sql".replace('/', File.separatorChar), @@ -30,7 +31,7 @@ public void fileWalker_Relative() { public void fileWalker_Absolute() { List fileList = new FileWalker().getFileList(BASE_DIR, "source", false); Collections.sort(fileList); - Assert.assertArrayEquals(new Object[] { + assertArrayEquals(new Object[] { BASE_DIR.getAbsolutePath() + "/source/packages/package.pkb".replace('/', File.separatorChar), BASE_DIR.getAbsolutePath() + "/source/packages/package.pks".replace('/', File.separatorChar), BASE_DIR.getAbsolutePath() + "/source/script.sql".replace('/', File.separatorChar), diff --git a/src/test/java/org/utplsql/cli/RunCommandCoverageReporterIT.java b/src/test/java/org/utplsql/cli/RunCommandCoverageReporterIT.java new file mode 100644 index 0000000..52932bb --- /dev/null +++ b/src/test/java/org/utplsql/cli/RunCommandCoverageReporterIT.java @@ -0,0 +1,139 @@ +package org.utplsql.cli; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.File; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.HashSet; +import java.util.Scanner; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * System tests for Code Coverage Reporter + * + * @author pesse + */ +public class RunCommandCoverageReporterIT { + + private static final Pattern REGEX_COVERAGE_TITLE = Pattern.compile("([a-zA-Z0-9\\._]+)<\\/a>"); + + private Set tempPaths; + + private void addTempPath(Path path) { + tempPaths.add(path); + } + + private String getTempCoverageFileName(int counter) { + + return "tmpCoverage_" + String.valueOf(System.currentTimeMillis()) + "_" + String.valueOf(counter) + ".html"; + } + + /** + * Returns a random filename which does not yet exist on the local path + * + * @return + */ + private Path getTempCoverageFilePath() { + + int i = 1; + Path p = Paths.get(getTempCoverageFileName(i)); + + while ((Files.exists(p) || tempPaths.contains(p)) && i < 100) + p = Paths.get(getTempCoverageFileName(i++)); + + if (i >= 100) + throw new IllegalStateException("Could not get temporary file for coverage output"); + + addTempPath(p); + addTempPath(Paths.get(p.toString()+"_assets")); + + return p; + } + + /** + * Checks Coverage HTML Output if a given packageName is listed + * + * @param content + * @param packageName + * @return + */ + private boolean hasCoverageListed(String content, String packageName) { + Matcher m = REGEX_COVERAGE_TITLE.matcher(content); + + while (m.find()) { + if (packageName.equals(m.group(1))) + return true; + } + + return false; + } + + @BeforeEach + public void setupTest() { + tempPaths = new HashSet<>(); + } + + @Test + public void run_CodeCoverageWithIncludeAndExclude() throws Exception { + + Path coveragePath = getTempCoverageFilePath(); + + RunCommand runCmd = RunCommandTestHelper.createRunCommand(RunCommandTestHelper.getConnectionString(), + "-f=ut_coverage_html_reporter", "-o=" + coveragePath, "-s", "-exclude=app.award_bonus,app.betwnstr"); + + + int result = runCmd.run(); + + String content = new Scanner(coveragePath).useDelimiter("\\Z").next(); + + assertEquals(true, hasCoverageListed(content, "app.remove_rooms_by_name")); + assertEquals(false, hasCoverageListed(content, "app.award_bonus")); + assertEquals(false, hasCoverageListed(content, "app.betwnstr")); + + } + + @Test + public void coverageReporterWriteAssetsToOutput() throws Exception { + Path coveragePath = getTempCoverageFilePath(); + Path coverageAssetsPath = Paths.get(coveragePath.toString() + "_assets"); + + RunCommand runCmd = RunCommandTestHelper.createRunCommand(RunCommandTestHelper.getConnectionString(), + "-f=ut_coverage_html_reporter", "-o=" + coveragePath, "-s"); + + runCmd.run(); + + // Check application file exists + File applicationJs = coverageAssetsPath.resolve(Paths.get("application.js")).toFile(); + assertTrue(applicationJs.exists()); + + // Check correct script-part in HTML source exists + String content = new Scanner(coveragePath).useDelimiter("\\Z").next(); + assertTrue(content.contains("