Skip to content

Commit

Permalink
Merge pull request #6 from trivago/0.0.4
Browse files Browse the repository at this point in the history
0.0.4
  • Loading branch information
Benjamin Bischoff authored Nov 20, 2017
2 parents ad635bf + 736f84b commit 15f5305
Show file tree
Hide file tree
Showing 18 changed files with 336 additions and 25 deletions.
21 changes: 18 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
Expand All @@ -11,15 +12,29 @@ Back to [Readme](README.md).
- Support for non-image attachments
- Increased unit test coverage

## [0.0.4] - 2017-11-20

### Added

- Scenario duration is displayed on start page
- Feature file name is displayed on feature name mouse over

### Fixed

- Corrupt or empty JSON files do not fail report generation anymore

## [0.0.3] - 2017-11-15

- fixed handling of scenarios without steps
- fixed handling of undefined steps
### Fixed

- handling of scenarios without steps
- handling of undefined steps

## [0.0.2] - 2017-11-14

Initial project version on GitHub and Maven Central.

[Unreleased]: https://github.com/trivago/cluecumber-report-plugin/compare/0.0.3...HEAD
[Unreleased]: https://github.com/trivago/cluecumber-report-plugin/compare/0.0.4...HEAD
[0.0.4]: https://github.com/trivago/cluecumber-report-plugin/tree/0.0.4
[0.0.3]: https://github.com/trivago/cluecumber-report-plugin/tree/0.0.3
[0.0.2]: https://github.com/trivago/cluecumber-report-plugin/tree/0.0.2
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

# Cluecumber Report Maven Plugin

This plugin creates test reports from Cucumber JSON files.
This plugin creates aggregated test reports from Cucumber JSON files.

This project was created because
- some other projects are using legacy technology and/or were not maintained at all
Expand Down Expand Up @@ -62,8 +62,8 @@ This will generate JSON results for all Cucumber tests.
<goal>reporting</goal>
</goals>
<configuration>
<sourceJsonReportDirectory>${project.basedir}/src/main/resources/cucumber-report</sourceJsonReportDirectory>
<generatedHtmlReportDirectory>${project.build.directory}/cluecumber-report</generatedHtmlReportDirectory>
<sourceJsonReportDirectory>${project.build.directory}/cucumber-report</sourceJsonReportDirectory>
<generatedHtmlReportDirectory>${project.build.directory}/generated-report</generatedHtmlReportDirectory>
</configuration>
</execution>
</executions>
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.trivago.rta</groupId>
<artifactId>cluecumber-report-plugin</artifactId>
<version>0.0.3</version>
<version>0.0.4</version>
<url>https://github.com/trivago/cluecumber-report-plugin</url>

<name>Cluecumber Maven Plugin for Cucumber Reports</name>
Expand Down Expand Up @@ -148,7 +148,7 @@
<artifactId>maven-plugin-plugin</artifactId>
<version>${maven.plugin.plugin.version}</version>
<configuration>
<goalPrefix>cucable</goalPrefix>
<goalPrefix>cluecumber-report</goalPrefix>
<skipErrorNoDescriptorsFound>false</skipErrorNoDescriptorsFound>
</configuration>
<executions>
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/CluecumberReportPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,12 @@ public void execute() throws CluecumberPluginException {
List<Path> jsonFilePaths = fileSystemManager.getJsonFilePaths();
for (Path jsonFilePath : jsonFilePaths) {
String jsonString = fileIO.readContentFromFile(jsonFilePath.toString());
Report[] reports = jsonPojoConverter.convertJsonToReportPojos(jsonString);
startPageCollection.addReports(reports);
try {
Report[] reports = jsonPojoConverter.convertJsonToReportPojos(jsonString);
startPageCollection.addReports(reports);
} catch (CluecumberPluginException e) {
logger.error("Could not parse JSON in file '" + jsonFilePath.toString() + "': " + e.getMessage());
}
}
reportGenerator.generateReports(startPageCollection);
logger.info("Converted " + startPageCollection.getTotalNumberOfFeatures() + " features into test report.");
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/trivago/rta/constants/ChartColor.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package com.trivago.rta.constants;

/**
* This enum manages the colors for the overview and detail charts that correspond to the passed in {@link Status} value.
*/
public enum ChartColor {
PASSED(40, 167, 69), FAILED(220, 53, 69), SKIPPED(255, 193, 7);

Expand All @@ -29,6 +32,12 @@ public enum ChartColor {
this.b = b;
}

/**
* Get the corresponding chart color for the passed {@link Status}.
*
* @param status the {@link Status}.
* @return the matching {@link be.ceau.chart.color.Color}.
*/
public static be.ceau.chart.color.Color getChartColorByStatus(Status status) {
switch (status) {
case FAILED:
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/trivago/rta/constants/PluginSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package com.trivago.rta.constants;

/**
* Holder class for static plugin settings
*/
public class PluginSettings {
public final static String NAME = "Cluecumber Report Plugin";
}
3 changes: 3 additions & 0 deletions src/main/java/com/trivago/rta/constants/Status.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package com.trivago.rta.constants;

/**
* Enum to manage all states for steps and scenarios.
*/
public enum Status {
PASSED("passed"), FAILED("failed"), SKIPPED("skipped"), UNDEFINED("undefined");

Expand Down
24 changes: 24 additions & 0 deletions src/main/java/com/trivago/rta/filesystem/FileIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,18 @@

import static java.nio.file.Files.readAllBytes;

/**
* This class manages reading from and writing to files.
*/
@Singleton
public class FileIO {
/**
* Write string content to a file.
*
* @param content the string content to be written.
* @param filePath the complete path to the target file.
* @throws FileCreationException a {@link FileCreationException} in case the file cannot be created.
*/
public void writeContentToFile(final String content, final String filePath) throws FileCreationException {
try (PrintStream ps = new PrintStream(filePath)) {
ps.println(content);
Expand All @@ -38,6 +48,13 @@ public void writeContentToFile(final String content, final String filePath) thro
}
}

/**
* Write byte array content to a file.
*
* @param content the byte array content to be written.
* @param filePath the complete path to the target file.
* @throws FileCreationException a {@link FileCreationException} in case the file cannot be created.
*/
public void writeContentToFile(final byte[] content, final String filePath) throws FileCreationException {
Path path = Paths.get(filePath);
try {
Expand All @@ -47,6 +64,13 @@ public void writeContentToFile(final byte[] content, final String filePath) thro
}
}

/**
* Read string content from a file.
*
* @param filePath the complete path to the source file.
* @return the file contents as a string.
* @throws MissingFileException a {@link MissingFileException} in case the file does not exist.
*/
public String readContentFromFile(final String filePath) throws MissingFileException {
try {
byte[] bytes = readAllBytes(Paths.get(filePath));
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/com/trivago/rta/json/JsonPojoConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package com.trivago.rta.json;

import com.google.gson.Gson;
import com.google.gson.JsonParseException;
import com.trivago.rta.exceptions.CluecumberPluginException;
import com.trivago.rta.json.pojo.Element;
import com.trivago.rta.json.pojo.Report;
import com.trivago.rta.json.postprocessors.ElementPostProcessor;
Expand All @@ -37,7 +39,13 @@ public JsonPojoConverter(final ElementPostProcessor elementPostProcessor) {
gsonParser = builder.createGson();
}

public Report[] convertJsonToReportPojos(final String json) {
return gsonParser.fromJson(json, Report[].class);
public Report[] convertJsonToReportPojos(final String json) throws CluecumberPluginException {
Report[] reports = null;
try {
reports = gsonParser.fromJson(json, Report[].class);
} catch (JsonParseException e) {
throw new CluecumberPluginException(e.getMessage());
}
return reports;
}
}
14 changes: 8 additions & 6 deletions src/main/java/com/trivago/rta/json/pojo/Element.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ public class Element {
private List<Step> steps = new ArrayList<>();
private List<Tag> tags = new ArrayList<>();

private transient int scenarioIndex;
private transient String durationChartJson = "";
private transient int scenarioIndex = -1;

public List<Tag> getTags() {
return tags;
Expand Down Expand Up @@ -161,14 +160,17 @@ public void setScenarioIndex(final int scenarioIndex) {
this.scenarioIndex = scenarioIndex;
}

public String getTotalDurationString() {
long totalDurationMillis = 0;
public long getTotalDuration() {
long totalDurationMicroseconds = 0;
for (Step step : steps) {
totalDurationMillis += step.getResult().getDuration();
totalDurationMicroseconds += step.getResult().getDuration();
}
return totalDurationMicroseconds;
}

public String getTotalDurationString() {
final int microsecondFactor = 1000000;
Duration durationMilliseconds = Duration.ofMillis(totalDurationMillis / microsecondFactor);
Duration durationMilliseconds = Duration.ofMillis(getTotalDuration() / microsecondFactor);

long minutes = durationMilliseconds.toMinutes();
long seconds = durationMilliseconds.minusMinutes(minutes).getSeconds();
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/trivago/rta/json/pojo/Report.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@

package com.trivago.rta.json.pojo;

import java.util.ArrayList;
import java.util.List;

public class Report {
private int line;
private List<Element> elements;
private List<Element> elements = new ArrayList<>();
private String name;
private String description;
private String id;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/trivago/rta/properties/PropertyManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void validateSettings() throws CluecumberPluginException {
}

public void logProperties() {
logger.info(" sourceJsonReportDirectory : " + sourceJsonReportDirectory);
logger.info(" generatedHtmlReportDirectory : " + generatedHtmlReportDirectory);
logger.info("- sourceJsonReportDirectory : " + sourceJsonReportDirectory);
logger.info("- generatedHtmlReportDirectory : " + generatedHtmlReportDirectory);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public List<Report> getReports() {
}

public void addReports(final Report[] reportList) {
if (reportList == null){
return;
}
this.reports.addAll(Arrays.asList(reportList));
}

Expand Down
14 changes: 11 additions & 3 deletions src/main/resources/template/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,19 @@ <h5 class="navbar-text float-lg-left">Test Suite Overview - ${reportDetails.date
<tr>
<th>Feature</th>
<th>Scenario</th>
<th>Duration</th>
</tr>
</thead>
<tbody>
<#list reports as report>
<#list report.elements as element>
<#if element.failed>
<tr>
<td class="text-left text-capitalize">${report.name}</td>
<td class="text-left text-capitalize"><span data-toggle="tooltip" title="${report.uri}">${report.name}</span></td>
<td class="text-left text-capitalize">
<a href="scenario-detail/scenario_${element.scenarioIndex}.html">${element.name}</a>
</td>
<td class="text-left text-capitalize" data-order="${element.totalDuration}">${element.totalDurationString}</td>
</tr>
</#if>
</#list>
Expand All @@ -113,17 +115,19 @@ <h5 class="navbar-text float-lg-left">Test Suite Overview - ${reportDetails.date
<tr>
<th>Feature</th>
<th>Scenario</th>
<th>Duration</th>
</tr>
</thead>
<tbody>
<#list reports as report>
<#list report.elements as element>
<#if element.skipped>
<tr>
<td class="text-left text-capitalize">${report.name}</td>
<td class="text-left text-capitalize"><span data-toggle="tooltip" title="${report.uri}">${report.name}</span></td>
<td class="text-left text-capitalize">
<a href="scenario-detail/scenario_${element.scenarioIndex}.html">${element.name}</a>
</td>
<td class="text-left text-capitalize" data-order="${element.totalDuration}">${element.totalDurationString}</td>
</tr>
</#if>
</#list>
Expand All @@ -147,17 +151,19 @@ <h5 class="navbar-text float-lg-left">Test Suite Overview - ${reportDetails.date
<tr>
<th>Feature</th>
<th>Scenario</th>
<th>Duration</th>
</tr>
</thead>
<tbody>
<#list reports as report>
<#list report.elements as element>
<#if element.passed>
<tr>
<td class="text-left text-capitalize">${report.name}</td>
<td class="text-left text-capitalize"><span data-toggle="tooltip" title="${report.uri}">${report.name}</span></td>
<td class="text-left text-capitalize">
<a href="scenario-detail/scenario_${element.scenarioIndex}.html">${element.name}</a>
</td>
<td class="text-left text-capitalize" data-order="${element.totalDuration}">${element.totalDurationString}</td>
</tr>
</#if>
</#list>
Expand Down Expand Up @@ -192,6 +198,8 @@ <h5 class="navbar-text float-lg-left">Test Suite Overview - ${reportDetails.date
$('#results_skipped').DataTable();
$('#results_passed').DataTable();

$('[data-toggle="tooltip"]').tooltip();

var ctx = document.getElementById('chart-area').getContext("2d");
new Chart(ctx, eval(${reportDetails.chartJson}));
})
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/template/scenario-detail/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ <h5 class="navbar-text float-lg-left">Scenario Details - ${reportDetails.date}</
<#list element.steps as step>
<div class="row border border-top-0 border-left-0 border-right-0">
<div class="col-1 text-left">
${step?counter}
Step ${step?counter}
</div>
<div class="col-7 text-left">
${step.keyword} ${step.name}
Expand Down
Loading

0 comments on commit 15f5305

Please sign in to comment.