Skip to content

Commit

Permalink
Merge pull request #39 from trivago/tag-overview
Browse files Browse the repository at this point in the history
Tag overview
  • Loading branch information
Benjamin Bischoff authored Mar 19, 2018
2 parents ec2f647 + c3a0f8a commit 658bba2
Show file tree
Hide file tree
Showing 29 changed files with 558 additions and 222 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

Back to [Readme](README.md).

## [0.5.0] - 2018-03-08
## [0.5.0] - 2018-03-19

# Added

* Tag summary page

# Fixed

* Background Scenario steps are now rendered correctly
* Various small bug fixes

## [0.3.0] - 2018-02-19

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@

<gson.version>2.8.2</gson.version>
<gsonfire.version>1.8.1</gsonfire.version>
<chart.version>2.2.0</chart.version>
<chart.version>2.3.1</chart.version>
<freemarker.version>2.3.27-incubating</freemarker.version>
</properties>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
package com.trivago.rta;/*
* Copyright 2018 trivago N.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -96,14 +96,14 @@ public void execute() throws CluecumberPluginException {
propertyManager.setCustomParameters(customParameters);
propertyManager.validateSettings();

logger.info("--------------------------------");
logger.info(" Cluecumber Report Maven Plugin ");
logger.info("--------------------------------");
logger.info("-----------------------------------------------");
logger.info(String.format(" Cluecumber Report Maven Plugin, version %s", getClass().getPackage().getImplementationVersion()));
logger.info("-----------------------------------------------");

propertyManager.logProperties();

// Create attachments directory for json attachment saving
fileSystemManager.createDirectory(propertyManager.getGeneratedHtmlReportDirectory() + "/attachments");
fileSystemManager.createDirectory(propertyManager.getGeneratedHtmlReportDirectory() + "/pages/scenario-detail");

StartPageCollection startPageCollection = new StartPageCollection();
List<Path> jsonFilePaths = fileSystemManager.getJsonFilePaths();
Expand All @@ -116,7 +116,7 @@ public void execute() throws CluecumberPluginException {
logger.error("Could not parse JSON in file '" + jsonFilePath.toString() + "': " + e.getMessage());
}
}
reportGenerator.generateReports(startPageCollection);
reportGenerator.generateReport(startPageCollection);
logger.info("Converted " + startPageCollection.getTotalNumberOfFeatures() + " features into test report:");
logger.info("- " + propertyManager.getGeneratedHtmlReportDirectory() + "/" + PluginSettings.START_PAGE_NAME);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/trivago/rta/constants/PluginSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class PluginSettings {
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 DETAIL_PAGE_NAME = PAGES_DIR + "/scenario-detail/scenario-detail.html";
public final static String TAG_SUMMARY_PAGE_NAME = PAGES_DIR + "/tag-summary.html";
public final static String START_PAGE_NAME = "index.html";
}
68 changes: 40 additions & 28 deletions src/main/java/com/trivago/rta/rendering/ReportGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import com.trivago.rta.constants.PluginSettings;
import com.trivago.rta.exceptions.CluecumberPluginException;
import com.trivago.rta.exceptions.filesystem.FileCreationException;
import com.trivago.rta.filesystem.FileIO;
import com.trivago.rta.filesystem.FileSystemManager;
import com.trivago.rta.json.pojo.Element;
Expand All @@ -27,6 +26,7 @@
import com.trivago.rta.properties.PropertyManager;
import com.trivago.rta.rendering.pages.pojos.DetailPageCollection;
import com.trivago.rta.rendering.pages.pojos.StartPageCollection;
import com.trivago.rta.rendering.pages.pojos.TagSummaryPageCollection;

import javax.inject.Inject;
import javax.inject.Singleton;
Expand Down Expand Up @@ -56,29 +56,41 @@ public ReportGenerator(
this.logger = logger;
}

public void generateReports(final StartPageCollection startPageCollection) throws CluecumberPluginException {
templateEngine.init(getClass(), PluginSettings.BASE_TEMPLATE_PATH);
public void generateReport(final StartPageCollection startPageCollection) throws CluecumberPluginException {
copyReportAssets();
fileSystemManager.createDirectory(propertyManager.getGeneratedHtmlReportDirectory() + "/" + PluginSettings.PAGES_DIR);
fileSystemManager.createDirectory(
propertyManager.getGeneratedHtmlReportDirectory() + "/" + PluginSettings.PAGES_DIR);

List<Report> reports = startPageCollection.getReports();
generateScenarioDetailPages(startPageCollection.getReports());
generateStartPage(startPageCollection);
generateTagSummaryPage(startPageCollection.getReports());
}

private void generateTagSummaryPage(final List<Report> reports) throws CluecumberPluginException {
TagSummaryPageCollection tagSummaryPageCollection = new TagSummaryPageCollection(reports);
fileIO.writeContentToFile(
templateEngine.getRenderedTagSummaryPageContent(tagSummaryPageCollection),
propertyManager.getGeneratedHtmlReportDirectory() + "/" + PluginSettings.TAG_SUMMARY_PAGE_NAME);
}

private void generateStartPage(final StartPageCollection startPageCollection) throws CluecumberPluginException {
fileIO.writeContentToFile(
templateEngine.getRenderedStartPageContent(startPageCollection),
propertyManager.getGeneratedHtmlReportDirectory() + "/" + PluginSettings.START_PAGE_NAME);
}

private void generateScenarioDetailPages(final List<Report> reports) throws CluecumberPluginException {
DetailPageCollection detailPageCollection;
for (Report report : reports) {
for (Element element : report.getElements()) {
detailPageCollection = new DetailPageCollection(element);
String renderedDetailPage = templateEngine.getRenderedDetailPage(detailPageCollection);
savePage(renderedDetailPage, PluginSettings.PAGES_DIR + "/scenario_" + element.getScenarioIndex() + ".html");
fileIO.writeContentToFile(
templateEngine.getRenderedDetailPageContent(detailPageCollection),
propertyManager.getGeneratedHtmlReportDirectory() + "/" +
PluginSettings.PAGES_DIR + "/scenario-detail/scenario_" +
element.getScenarioIndex() + ".html");
}
}

String renderedStartPage = templateEngine.getRenderedStartPage(startPageCollection);
fileIO.writeContentToFile(renderedStartPage, propertyManager.getGeneratedHtmlReportDirectory() + "/" + PluginSettings.START_PAGE_NAME);
}

private void savePage(final String renderedDetailPage, final String fileName) throws FileCreationException {
fileIO.writeContentToFile(
renderedDetailPage,
propertyManager.getGeneratedHtmlReportDirectory() + "/" + fileName);
}

private void copyReportAssets() throws CluecumberPluginException {
Expand All @@ -88,22 +100,22 @@ private void copyReportAssets() throws CluecumberPluginException {
fileSystemManager.createDirectory(propertyManager.getGeneratedHtmlReportDirectory() + "/css");

// Copy CSS resources
copyFileFromJarToFilesystemDestination("/css/bootstrap.min.css");
copyFileFromJarToFilesystemDestination("/css/cluecumber.css");
copyFileFromJarToFilesystemDestination("/css/dataTables.bootstrap4.min.css");
copyFileFromJarToFilesystemDestination("/css/jquery.fancybox.min.css");
copyFileFromJarToFilesystem("/css/bootstrap.min.css");
copyFileFromJarToFilesystem("/css/cluecumber.css");
copyFileFromJarToFilesystem("/css/dataTables.bootstrap4.min.css");
copyFileFromJarToFilesystem("/css/jquery.fancybox.min.css");

// Copy Javascript resources
copyFileFromJarToFilesystemDestination("/js/jquery-3.2.1.slim.min.js");
copyFileFromJarToFilesystemDestination("/js/bootstrap.min.js");
copyFileFromJarToFilesystemDestination("/js/popper.min.js");
copyFileFromJarToFilesystemDestination("/js/Chart.bundle.min.js");
copyFileFromJarToFilesystemDestination("/js/dataTables.bootstrap4.min.js");
copyFileFromJarToFilesystemDestination("/js/jquery.dataTables.min.js");
copyFileFromJarToFilesystemDestination("/js/jquery.fancybox.min.js");
copyFileFromJarToFilesystem("/js/jquery-3.2.1.slim.min.js");
copyFileFromJarToFilesystem("/js/bootstrap.min.js");
copyFileFromJarToFilesystem("/js/popper.min.js");
copyFileFromJarToFilesystem("/js/Chart.bundle.min.js");
copyFileFromJarToFilesystem("/js/dataTables.bootstrap4.min.js");
copyFileFromJarToFilesystem("/js/jquery.dataTables.min.js");
copyFileFromJarToFilesystem("/js/jquery.fancybox.min.js");
}

private void copyFileFromJarToFilesystemDestination(final String fileName) throws CluecumberPluginException {
private void copyFileFromJarToFilesystem(final String fileName) throws CluecumberPluginException {
fileSystemManager.exportResource(getClass(),
PluginSettings.BASE_TEMPLATE_PATH + fileName,
propertyManager.getGeneratedHtmlReportDirectory() + fileName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class TemplateConfiguration {
private Configuration cfg;

void init(final Class rootClass, final String basePath) {
cfg = new Configuration(Configuration.VERSION_2_3_26);
cfg = new Configuration(Configuration.VERSION_2_3_27);
cfg.setClassForTemplateLoading(rootClass, basePath);
cfg.setDefaultEncoding("UTF-8");
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
Expand All @@ -24,7 +24,8 @@ Template getTemplate(final String templateName) throws CluecumberPluginException
try {
template = cfg.getTemplate(templateName);
} catch (Exception e) {
throw new CluecumberPluginException("Template '" + templateName + "' was not found or not parsable: " + e.getMessage());
throw new CluecumberPluginException("Template '" + templateName + "' was not found or not parsable: " +
e.getMessage());
}
return template;
}
Expand Down
26 changes: 18 additions & 8 deletions src/main/java/com/trivago/rta/rendering/TemplateEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,44 +20,54 @@
import com.trivago.rta.exceptions.CluecumberPluginException;
import com.trivago.rta.rendering.pages.ScenarioDetailPageRenderer;
import com.trivago.rta.rendering.pages.StartPageRenderer;
import com.trivago.rta.rendering.pages.TagSummaryPageRenderer;
import com.trivago.rta.rendering.pages.pojos.DetailPageCollection;
import com.trivago.rta.rendering.pages.pojos.StartPageCollection;
import com.trivago.rta.rendering.pages.pojos.TagSummaryPageCollection;

import javax.inject.Inject;
import javax.inject.Singleton;

@Singleton
public class TemplateEngine {
private TemplateConfiguration templateConfiguration;
private final TemplateConfiguration templateConfiguration;
private final StartPageRenderer startPageRenderer;
private final ScenarioDetailPageRenderer scenarioDetailPageRenderer;
private final TagSummaryPageRenderer tagSummaryPageRenderer;

@Inject
public TemplateEngine(
final TemplateConfiguration templateConfiguration,
final StartPageRenderer startPageRenderer,
final ScenarioDetailPageRenderer scenarioDetailPageRenderer
final ScenarioDetailPageRenderer scenarioDetailPageRenderer,
final TagSummaryPageRenderer tagSummaryPageRenderer
) {
this.templateConfiguration = templateConfiguration;
templateConfiguration.init(this.getClass(), PluginSettings.BASE_TEMPLATE_PATH);

this.startPageRenderer = startPageRenderer;
this.scenarioDetailPageRenderer = scenarioDetailPageRenderer;
this.tagSummaryPageRenderer = tagSummaryPageRenderer;
}

void init(final Class rootClass, final String basePath) {
templateConfiguration.init(rootClass, basePath);
}

String getRenderedStartPage(final StartPageCollection startPageCollection) throws CluecumberPluginException {
String getRenderedStartPageContent(final StartPageCollection startPageCollection) throws CluecumberPluginException {
return startPageRenderer.getRenderedContent(
startPageCollection,
templateConfiguration.getTemplate(PluginSettings.START_PAGE_NAME)
);
}

String getRenderedDetailPage(final DetailPageCollection detailPageCollection) throws CluecumberPluginException {
String getRenderedDetailPageContent(final DetailPageCollection detailPageCollection) throws CluecumberPluginException {
return scenarioDetailPageRenderer.getRenderedContent(
detailPageCollection,
templateConfiguration.getTemplate(PluginSettings.DETAIL_PAGE_NAME)
);
}

String getRenderedTagSummaryPageContent(final TagSummaryPageCollection tagSummaryPageCollection) throws CluecumberPluginException {
return tagSummaryPageRenderer.getRenderedContent(
tagSummaryPageCollection,
templateConfiguration.getTemplate(PluginSettings.TAG_SUMMARY_PAGE_NAME)
);
}
}
26 changes: 18 additions & 8 deletions src/main/java/com/trivago/rta/rendering/pages/PageRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,26 @@

package com.trivago.rta.rendering.pages;

import com.trivago.rta.rendering.pages.pojos.ReportDetails;
import com.trivago.rta.exceptions.CluecumberPluginException;
import com.trivago.rta.rendering.pages.pojos.PageCollection;
import freemarker.template.Template;
import freemarker.template.TemplateException;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;

class PageRenderer {
void addCurrentDateToReportDetails(final ReportDetails reportDetails) {
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date();
reportDetails.setDate(dateFormat.format(date));

String processedContent(final Template template, final PageCollection pageCollection)
throws CluecumberPluginException {

Writer stringWriter = new StringWriter();
try {
template.process(pageCollection, stringWriter);
} catch (TemplateException | IOException e) {
throw new CluecumberPluginException("Could not render page content: " + e.getMessage());
}
return stringWriter.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,46 +21,35 @@
import be.ceau.chart.dataset.BarDataset;
import be.ceau.chart.options.BarOptions;
import be.ceau.chart.options.scales.BarScale;
import be.ceau.chart.options.scales.XAxis;
import be.ceau.chart.options.ticks.LinearTicks;
import com.trivago.rta.constants.ChartColor;
import com.trivago.rta.exceptions.CluecumberPluginException;
import com.trivago.rta.json.pojo.Element;
import com.trivago.rta.json.pojo.Step;
import com.trivago.rta.rendering.pages.pojos.DetailPageCollection;
import com.trivago.rta.rendering.pages.pojos.ReportDetails;
import freemarker.template.Template;
import freemarker.template.TemplateException;

import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.List;

@Singleton
public class ScenarioDetailPageRenderer extends PageRenderer {

public String getRenderedContent(final DetailPageCollection detailPageCollection, final Template template)
throws CluecumberPluginException {

ReportDetails reportDetails = new ReportDetails();
addChartJsonToReportDetails(detailPageCollection.getElement(), reportDetails);
addCurrentDateToReportDetails(reportDetails);
detailPageCollection.setReportDetails(reportDetails);

Writer stringWriter = new StringWriter();
try {
template.process(detailPageCollection, stringWriter);
} catch (TemplateException | IOException e) {
throw new CluecumberPluginException(e.getMessage());
}
return stringWriter.toString();
addChartJsonToReportDetails(detailPageCollection);
return processedContent(template, detailPageCollection);
}

private void addChartJsonToReportDetails(final Element element, final ReportDetails reportDetails) {
private void addChartJsonToReportDetails(final DetailPageCollection detailPageCollection) {
BarDataset barDataSet = new BarDataset();

BarData barData = new BarData();
int stepCounter = 1;

for (Step step : element.getSteps()) {
for (Step step : detailPageCollection.getElement().getSteps()) {
barData.addLabel("Step " + stepCounter);
barDataSet.addData(step.getResult().getDurationInMilliseconds());
barDataSet.addBackgroundColor(ChartColor.getChartColorByStatus(step.getStatus()));
Expand All @@ -69,11 +58,13 @@ private void addChartJsonToReportDetails(final Element element, final ReportDeta
barDataSet.setLabel("Step runtime");
barData.addDataset(barDataSet);

LinearTicks ticks = new LinearTicks().setMin(0);
BarScale scale = new BarScale()
.addyAxes(BarScale.yAxis().setTicks(ticks));
BarOptions barOptions = new BarOptions().setScales(scale);
BarScale barScale = new BarScale();
List<XAxis<LinearTicks>> xAxisList = new ArrayList<>();
xAxisList.add(new XAxis<LinearTicks>().setTicks(new LinearTicks().setMin(0)));
barScale.setxAxes(xAxisList);

BarOptions barOptions = new BarOptions().setScales(barScale);

reportDetails.setChartJson(new BarChart(barData, barOptions).toJson());
detailPageCollection.getReportDetails().setChartJson(new BarChart(barData, barOptions).toJson());
}
}
Loading

0 comments on commit 658bba2

Please sign in to comment.