Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
CoverageHTML Reporter will now reference its assets correctly when ou…
…tput

is written to a subfolder.
Fixes #94
  • Loading branch information
pesse committed Jul 24, 2018
commit 7df3131e2871470b9b6c5669e7301cd2dabfd8ca
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.utplsql.api.reporter.ReporterFactory;
import org.utplsql.cli.ReporterOptions;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.sql.Connection;
import java.sql.SQLException;
Expand All @@ -27,15 +28,34 @@ public LocalAssetsCoverageHTMLReporter(String selfType, Object[] attributes) {
public Reporter init(Connection con, CompatibilityProxy compatibilityProxy, ReporterFactory reporterFactory) throws SQLException {
super.init(con, compatibilityProxy, reporterFactory);

if ( options != null && options.outputToFile() )
writeReportAssetsTo(Paths.get(getAssetsPath()));
if ( hasOutputToFile() ) {
writeReportAssetsTo(getPhysicalAssetPath());
}

return this;
}

private String getNameOfOutputFile() {
Path outputPath = Paths.get(options.getOutputFileName());
return outputPath.getName(outputPath.getNameCount()-1).toString();
}

private Path getPhysicalAssetPath() {
Path outputPath = Paths.get(options.getOutputFileName());
if ( outputPath.getNameCount() > 1 )
return outputPath.getParent().resolve(getAssetsPath());
else
return Paths.get(getAssetsPath());
}

private void setAssetsPathFromOptions() {
if ( options != null && options.outputToFile() )
setAssetsPath(options.getOutputFileName()+"_assets/");
if ( hasOutputToFile() ) {
setAssetsPath(getNameOfOutputFile() + "_assets/");
}
}

private boolean hasOutputToFile() {
return (options != null && options.outputToFile());
}

@Override
Expand Down
22 changes: 22 additions & 0 deletions src/test/java/org/utplsql/cli/RunCommandCoverageReporterIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,26 @@ public void coverageReporterWriteAssetsToOutput() throws Exception {
assertTrue(content.contains("<title>Code coverage</title>"));
}

@Test
public void coverageReporterWriteAssetsToSubfolder() throws Exception {

Path origCoveratePath = getTempCoverageFilePath();
Path coveragePath = Paths.get(origCoveratePath.toString(), origCoveratePath.toString());
Path coverageAssetsPath = Paths.get(coveragePath.toString() + "_assets");

TestHelper.runApp("run", TestHelper.getConnectionString(),
"-f=ut_coverage_html_reporter", "-o=" + coveragePath, "-s");


// 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 String(Files.readAllBytes(coveragePath));
assertTrue(content.contains("<script src='" + origCoveratePath.toString() + "_assets" + "/application.js'"));

// Check correct title exists
assertTrue(content.contains("<title>Code coverage</title>"));
}
}