Skip to content

Commit

Permalink
Merge pull request #31 from trivago/0.3.0
Browse files Browse the repository at this point in the history
0.3.0
  • Loading branch information
Benjamin Bischoff authored Feb 19, 2018
2 parents a9a7ac4 + 393520a commit bc9b3a7
Show file tree
Hide file tree
Showing 23 changed files with 389 additions and 96 deletions.
20 changes: 18 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,22 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

Back to [Readme](README.md).

## [0.2.0] - 2017-12-12
## [0.3.0] - 2018-02-03

# Added

* Scenario.output is now displayed in the scenario details

# Fixed

* Scenarios with pending and skipped steps are also considered skipped.
* Background scenarios are now merged to the following scenarios.

# Changed

* Internal organization of page types allows easier extension.

## [0.2.0] - 2018-01-16

# Added

Expand All @@ -22,7 +37,7 @@ Back to [Readme](README.md).

- Report generation is now much more resilient if information is missing in the JSON sources

## [0.1.1] - 2018-01-16
## [0.1.1] - 2017-12-12

# Removed

Expand Down Expand Up @@ -83,6 +98,7 @@ Back to [Readme](README.md).

Initial project version on GitHub and Maven Central.

[0.3.0]: https://github.com/trivago/cluecumber-report-plugin/tree/0.3.0
[0.2.0]: https://github.com/trivago/cluecumber-report-plugin/tree/0.2.0
[0.1.1]: https://github.com/trivago/cluecumber-report-plugin/tree/0.1.1
[0.1.0]: https://github.com/trivago/cluecumber-report-plugin/tree/0.1.0
Expand Down
2 changes: 1 addition & 1 deletion 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.2.0</version>
<version>0.3.0</version>
<url>https://github.com/trivago/cluecumber-report-plugin</url>

<name>Cluecumber Maven Plugin for Cucumber Reports</name>
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/com/trivago/rta/constants/PluginSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
*/
public class PluginSettings {
public final static String NAME = "Cluecumber Report Plugin";

public static final String BASE_TEMPLATE_PATH = "/template";
public static final String PAGES_DIR = "pages";

public final static String DETAIL_PAGE_NAME = PAGES_DIR + "/scenario-detail.html";
public final static String TAG_PAGE_NAME = PAGES_DIR + "/tag-summary.html";
public final static String START_PAGE_NAME = "index.html";
public final static String DETAIL_PAGE_NAME = "scenario-detail/detail.html";
}
25 changes: 12 additions & 13 deletions src/main/java/com/trivago/rta/filesystem/FileSystemManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,30 +82,29 @@ public void createDirectory(final String dirName) throws PathCreationException {
* @throws CluecumberPluginException (see {@link CluecumberPluginException}.
*/
public void exportResource(final Class baseClass, final String resourceName, final String destination) throws CluecumberPluginException {
InputStream stream = null;
OutputStream resStreamOut = null;
String jarFolder;
InputStream inputStream = null;
OutputStream outputStream = null;
try {
stream = baseClass.getResourceAsStream(resourceName);
if (stream == null) {
throw new Exception("Cannot get resource \"" + resourceName + "\" from Jar file.");
inputStream = baseClass.getResourceAsStream(resourceName);
if (inputStream == null) {
throw new Exception("Cannot get resource \"" + resourceName + "\".");
}

int readBytes;
byte[] buffer = new byte[BYTE_BLOCK];
resStreamOut = new FileOutputStream(destination);
while ((readBytes = stream.read(buffer)) > 0) {
resStreamOut.write(buffer, 0, readBytes);
outputStream = new FileOutputStream(destination);
while ((readBytes = inputStream.read(buffer)) > 0) {
outputStream.write(buffer, 0, readBytes);
}
} catch (Exception e) {
throw new CluecumberPluginException(e.getMessage());
} finally {
try {
if (stream != null) {
stream.close();
if (inputStream != null) {
inputStream.close();
}
if (resStreamOut != null) {
resStreamOut.close();
if (outputStream != null) {
outputStream.close();
}
} catch (IOException e) {
throw new CluecumberPluginException(e.getMessage());
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/trivago/rta/json/JsonPojoConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.trivago.rta.json.pojo.Element;
import com.trivago.rta.json.pojo.Report;
import com.trivago.rta.json.postprocessors.ElementPostProcessor;
import com.trivago.rta.json.postprocessors.ReportPostProcessor;
import io.gsonfire.GsonFireBuilder;

import javax.inject.Inject;
Expand All @@ -33,8 +34,9 @@ public class JsonPojoConverter {
private final Gson gsonParser;

@Inject
public JsonPojoConverter(final ElementPostProcessor elementPostProcessor) {
public JsonPojoConverter(final ReportPostProcessor reportPostProcessor, final ElementPostProcessor elementPostProcessor) {
GsonFireBuilder builder = new GsonFireBuilder()
.registerPostProcessor(Report.class, reportPostProcessor)
.registerPostProcessor(Element.class, elementPostProcessor);
gsonParser = builder.createGson();
}
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/com/trivago/rta/json/pojo/Element.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ public Status getStatus() {
return Status.SKIPPED;
}

// If all steps have the same status, return this as the scenario status.
for (Status status : Status.values()) {
int stepNumber = (int) steps.stream().filter(step -> step.getStatus() == status).count();
if (totalSteps == stepNumber) {
Expand All @@ -158,6 +159,14 @@ public Status getStatus() {
}
}

// Skip scenario if it contains a mixture of pending and skipped steps.
int totalSkippedSteps = (int) steps.stream().filter(
step -> step.getStatus() == Status.PENDING || step.getStatus() == Status.SKIPPED
).count();
if (totalSkippedSteps == totalSteps){
return Status.SKIPPED;
}

return Status.FAILED;
}

Expand All @@ -169,6 +178,28 @@ public void setScenarioIndex(final int scenarioIndex) {
this.scenarioIndex = scenarioIndex;
}

public int getTotalNumberOfSteps() {
return getSteps().size();
}

public int getTotalNumberOfPassedSteps() {
return getNumberOfStepsWithStatus(Status.PASSED);
}

public int getTotalNumberOfFailedSteps() {
return getNumberOfStepsWithStatus(Status.FAILED) +
getNumberOfStepsWithStatus(Status.UNDEFINED) +
getNumberOfStepsWithStatus(Status.AMBIGUOUS);
}

public int getTotalNumberOfSkippedSteps() {
return getNumberOfStepsWithStatus(Status.SKIPPED) + getNumberOfStepsWithStatus(Status.PENDING);
}

private int getNumberOfStepsWithStatus(final Status status) {
return (int) getSteps().stream().filter(step -> step.getStatus() == status).count();
}

public long getTotalDuration() {
long totalDurationMicroseconds = 0;
for (Before beforeStep : before) {
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/com/trivago/rta/json/pojo/Step.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@

package com.trivago.rta.json.pojo;

import com.trivago.rta.rendering.RenderingUtils;

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

public class Step extends ResultMatch {
private int line;
private String name = "";
private String keyword = "";
private List<String> output = new ArrayList<>();
private List<Row> rows = new ArrayList<>();
private List<Embedding> embeddings = new ArrayList<>();

Expand Down Expand Up @@ -66,12 +69,29 @@ public void setRows(final List<Row> rows) {
this.rows = rows;
}

public List<String> getOutput() {
return output;
}

public List<String> getEncodedOutput() {
List<String> encodedOutput = new ArrayList<>();
for (String outputString : output) {
encodedOutput.add(RenderingUtils.escapeHTML(outputString));
}
return encodedOutput;
}

public void setOutput(final List<String> output) {
this.output = output;
}

@Override
public String toString() {
return "Step{" +
"line=" + line +
", name='" + name + '\'' +
", keyword='" + keyword + '\'' +
", output=" + output +
", rows=" + rows +
", embeddings=" + embeddings +
'}';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ public ElementPostProcessor(

@Override
public void postDeserialize(final Element element, final JsonElement jsonElement, final Gson gson) {

addScenarioIndex(element);

try {
processAttachments(element.getSteps(), element.getAfter());
} catch (CluecumberPluginException e) {
Expand All @@ -70,7 +72,7 @@ public void postDeserialize(final Element element, final JsonElement jsonElement
/**
* Process attachments in steps and after hooks.
*
* @param steps The {@link Step} list.
* @param steps The {@link Step} list.
* @param afterHooks The {@link After} list.
* @throws CluecumberPluginException Exception if the attachments cannot be processed.
*/
Expand Down Expand Up @@ -148,6 +150,7 @@ private String saveImageEmbeddingToFileAndGetFilename(final Embedding embedding)

/**
* Add index to elements (used for link creation to the detail reports).
*
* @param element The current {@link Element}.
*/
private void addScenarioIndex(final Element element) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright 2018 trivago N.V.
*
* Licensed 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.
*/

package com.trivago.rta.json.postprocessors;

import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.trivago.rta.json.pojo.Element;
import com.trivago.rta.json.pojo.Report;
import com.trivago.rta.json.pojo.Step;
import com.trivago.rta.logging.CluecumberLogger;
import io.gsonfire.PostProcessor;

import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.List;

@Singleton
public class ReportPostProcessor implements PostProcessor<Report> {

private final CluecumberLogger logger;

@Inject
public ReportPostProcessor(final CluecumberLogger logger) {
this.logger = logger;
}

@Override
public void postDeserialize(final Report report, final JsonElement jsonElement, final Gson gson) {
mergeBackgroundScenarios(report);
}

private void mergeBackgroundScenarios(final Report report) {
List<Element> cleanedUpElements = new ArrayList<>();
Element currentBackgroundElement = null;

for (Element element : report.getElements()) {
if (element.getType().equalsIgnoreCase("background")) {
currentBackgroundElement = element;
} else {
if (currentBackgroundElement != null) {
for (Step step : currentBackgroundElement.getSteps()) {
element.getSteps().add(0, step);
}
}
cleanedUpElements.add(element);
}
}
report.setElements(cleanedUpElements);
}

@Override
public void postSerialize(final JsonElement jsonElement, final Report report, final Gson gson) {
// not used
}
}
Loading

0 comments on commit bc9b3a7

Please sign in to comment.