com.trivago.cluecumber.rendering.pages.renderering.AllStepsPageRenderer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cluecumber-report-plugin
Show all versions of cluecumber-report-plugin
Plugin for generating clear Cucumber BDD test result reports.
package com.trivago.cluecumber.rendering.pages.renderering;
import com.trivago.cluecumber.constants.ChartConfiguration;
import com.trivago.cluecumber.constants.Status;
import com.trivago.cluecumber.exceptions.CluecumberPluginException;
import com.trivago.cluecumber.json.pojo.Step;
import com.trivago.cluecumber.rendering.pages.charts.ChartJsonConverter;
import com.trivago.cluecumber.rendering.pages.charts.StackedBarChartBuilder;
import com.trivago.cluecumber.rendering.pages.charts.pojos.Chart;
import com.trivago.cluecumber.rendering.pages.pojos.ResultCount;
import com.trivago.cluecumber.rendering.pages.pojos.pagecollections.AllStepsPageCollection;
import freemarker.template.Template;
import javax.inject.Inject;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class AllStepsPageRenderer extends PageRenderer {
private final ChartConfiguration chartConfiguration;
@Inject
public AllStepsPageRenderer(
final ChartJsonConverter chartJsonConverter,
final ChartConfiguration chartConfiguration
) {
super(chartJsonConverter);
this.chartConfiguration = chartConfiguration;
}
public String getRenderedContent(
final AllStepsPageCollection allStepsPageCollection, final Template template)
throws CluecumberPluginException {
addChartJsonToReportDetails(allStepsPageCollection);
return processedContent(template, allStepsPageCollection);
}
private void addChartJsonToReportDetails(final AllStepsPageCollection allTagsPageCollection) {
List passed = new ArrayList<>();
List failed = new ArrayList<>();
List skipped = new ArrayList<>();
int maximumNumberOfRuns = 0;
for (Map.Entry entry : allTagsPageCollection.getStepResultCounts().entrySet()) {
Step key = entry.getKey();
ResultCount value = entry.getValue();
passed.add(value.getPassed());
failed.add(value.getFailed());
skipped.add(value.getSkipped());
if (value.getTotal() > maximumNumberOfRuns) {
maximumNumberOfRuns = value.getTotal();
}
}
List keys = allTagsPageCollection.getStepResultCounts()
.keySet()
.stream()
.map(Step::returnNameWithArgumentPlaceholders)
.collect(Collectors.toList());
Chart chart =
new StackedBarChartBuilder(chartConfiguration)
.setLabels(keys)
.setxAxisLabel(allTagsPageCollection.getTotalNumberOfSteps() + " Steps")
.setyAxisStepSize(maximumNumberOfRuns)
.setyAxisLabel("Number of Usages")
.addValues(passed, Status.PASSED)
.addValues(failed, Status.FAILED)
.addValues(skipped, Status.SKIPPED)
.build();
allTagsPageCollection.getReportDetails().setChartJson(convertChartToJson(chart));
}
}