Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add separate jsons for widgets (fixes #567) #650

Merged
merged 10 commits into from
Oct 30, 2017
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@
import io.qameta.allure.core.Plugin;
import io.qameta.allure.core.ReportWebPlugin;
import io.qameta.allure.core.TestsResultsPlugin;
import io.qameta.allure.duration.DurationPlugin;
import io.qameta.allure.environment.Allure1EnvironmentPlugin;
import io.qameta.allure.executor.ExecutorPlugin;
import io.qameta.allure.ga.GaPlugin;
import io.qameta.allure.graph.GraphPlugin;
import io.qameta.allure.history.HistoryPlugin;
import io.qameta.allure.history.HistoryTrendPlugin;
import io.qameta.allure.launch.LaunchPlugin;
import io.qameta.allure.mail.MailPlugin;
import io.qameta.allure.owner.OwnerPlugin;
import io.qameta.allure.retry.RetryPlugin;
import io.qameta.allure.severity.SeverityPlugin;
import io.qameta.allure.status.StatusChartPlugin;
import io.qameta.allure.suites.SuitesPlugin;
import io.qameta.allure.summary.SummaryPlugin;
import io.qameta.allure.tags.TagsPlugin;
import io.qameta.allure.timeline.TimelinePlugin;
import io.qameta.allure.widget.WidgetsPlugin;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -62,14 +62,14 @@ public ConfigurationBuilder useDefault() {
new CategoriesPlugin(),
new HistoryPlugin(),
new HistoryTrendPlugin(),
new GraphPlugin(),
new DurationPlugin(),
new StatusChartPlugin(),
new TimelinePlugin(),
new SuitesPlugin(),
new ReportWebPlugin(),
new TestsResultsPlugin(),
new AttachmentsPlugin(),
new MailPlugin(),
new WidgetsPlugin(),
new SummaryPlugin(),
new ExecutorPlugin(),
new LaunchPlugin(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,6 @@ public List<Reader> getReaders() {
.collect(Collectors.toList());
}

@Override
public List<Widget> getWidgets() {
return extensions.stream()
.filter(Widget.class::isInstance)
.map(Widget.class::cast)
.collect(Collectors.toList());
}

@Override
public <T> Optional<T> getContext(final Class<T> contextType) {
return extensions.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
import io.qameta.allure.core.Plugin;
import io.qameta.allure.core.ReportWebPlugin;
import io.qameta.allure.core.TestsResultsPlugin;
import io.qameta.allure.duration.DurationPlugin;
import io.qameta.allure.environment.Allure1EnvironmentPlugin;
import io.qameta.allure.executor.ExecutorPlugin;
import io.qameta.allure.graph.GraphPlugin;
import io.qameta.allure.history.HistoryPlugin;
import io.qameta.allure.history.HistoryTrendPlugin;
import io.qameta.allure.launch.LaunchPlugin;
Expand All @@ -25,11 +25,11 @@
import io.qameta.allure.plugin.DefaultPluginLoader;
import io.qameta.allure.retry.RetryPlugin;
import io.qameta.allure.severity.SeverityPlugin;
import io.qameta.allure.status.StatusChartPlugin;
import io.qameta.allure.suites.SuitesPlugin;
import io.qameta.allure.summary.SummaryPlugin;
import io.qameta.allure.tags.TagsPlugin;
import io.qameta.allure.timeline.TimelinePlugin;
import io.qameta.allure.widget.WidgetsPlugin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -65,13 +65,13 @@ public final class DummyReportGenerator {
new CategoriesPlugin(),
new HistoryPlugin(),
new HistoryTrendPlugin(),
new GraphPlugin(),
new DurationPlugin(),
new StatusChartPlugin(),
new TimelinePlugin(),
new SuitesPlugin(),
new TestsResultsPlugin(),
new AttachmentsPlugin(),
new MailPlugin(),
new WidgetsPlugin(),
new SummaryPlugin(),
new ExecutorPlugin(),
new LaunchPlugin(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import io.qameta.allure.CommonJsonAggregator;
import io.qameta.allure.CompositeAggregator;
import io.qameta.allure.Reader;
import io.qameta.allure.Widget;
import io.qameta.allure.context.JacksonContext;
import io.qameta.allure.core.Configuration;
import io.qameta.allure.core.LaunchResults;
Expand Down Expand Up @@ -47,7 +46,7 @@
* @since 2.0
*/
@SuppressWarnings("PMD.ExcessiveImports")
public class CategoriesPlugin extends CompositeAggregator implements Reader, Widget {
public class CategoriesPlugin extends CompositeAggregator implements Reader {

public static final String CATEGORIES = "categories";

Expand All @@ -65,7 +64,9 @@ public class CategoriesPlugin extends CompositeAggregator implements Reader, Wid
//@formatter:on

public CategoriesPlugin() {
super(Arrays.asList(new JsonAggregator(), new CsvExportAggregator()));
super(Arrays.asList(
new JsonAggregator(), new CsvExportAggregator(), new WidgetAggregator()
));
}

@Override
Expand All @@ -84,24 +85,6 @@ public void readResults(final Configuration configuration,
}
}

@Override
public String getName() {
return CATEGORIES;
}

@Override
public Object getData(final Configuration configuration, final List<LaunchResults> launches) {
final Tree<TestResult> data = getData(launches);
final List<TreeWidgetItem> items = data.getChildren().stream()
.filter(TestResultTreeGroup.class::isInstance)
.map(TestResultTreeGroup.class::cast)
.map(CategoriesPlugin::toWidgetItem)
.sorted(Comparator.comparing(TreeWidgetItem::getStatistic, comparator()).reversed())
.limit(10)
.collect(Collectors.toList());
return new TreeWidgetData().setItems(items).setTotal(data.getChildren().size());
}

@SuppressWarnings("PMD.DefaultPackage")
/* default */ static Tree<TestResult> getData(final List<LaunchResults> launchResults) {

Expand Down Expand Up @@ -192,8 +175,8 @@ private static class JsonAggregator extends CommonJsonAggregator {
}

@Override
protected Tree<TestResult> getData(final List<LaunchResults> launchResults) {
return CategoriesPlugin.getData(launchResults);
protected Tree<TestResult> getData(final List<LaunchResults> launches) {
return CategoriesPlugin.getData(launches);
}
}

Expand All @@ -217,4 +200,24 @@ protected List<CsvExportCategory> getData(final List<LaunchResults> launchesResu
return exportLabels;
}
}

private static class WidgetAggregator extends CommonJsonAggregator {

WidgetAggregator() {
super("widgets", JSON_FILE_NAME);
}

@Override
protected Object getData(final List<LaunchResults> launches) {
final Tree<TestResult> data = CategoriesPlugin.getData(launches);
final List<TreeWidgetItem> items = data.getChildren().stream()
.filter(TestResultTreeGroup.class::isInstance)
.map(TestResultTreeGroup.class::cast)
.map(CategoriesPlugin::toWidgetItem)
.sorted(Comparator.comparing(TreeWidgetItem::getStatistic, comparator()).reversed())
.limit(10)
.collect(Collectors.toList());
return new TreeWidgetData().setItems(items).setTotal(data.getChildren().size());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.qameta.allure.graph;
package io.qameta.allure.duration;

import io.qameta.allure.entity.Status;
import io.qameta.allure.entity.Time;
Expand All @@ -13,7 +13,7 @@
*/
@Data
@Accessors(chain = true)
public class GraphData implements Serializable {
public class DurationData implements Serializable {

private static final long serialVersionUID = 1L;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package io.qameta.allure.duration;

import io.qameta.allure.CommonJsonAggregator;
import io.qameta.allure.core.LaunchResults;
import io.qameta.allure.entity.TestResult;

import java.util.List;
import java.util.stream.Collectors;

/**
* Plugin that generates data for Duration graph.
*
* @since 2.0
*/
public class DurationPlugin extends CommonJsonAggregator {

public DurationPlugin() {
super("widgets", "duration.json");
}

@Override
protected List<DurationData> getData(final List<LaunchResults> launchesResults) {
return launchesResults.stream()
.flatMap(launch -> launch.getResults().stream())
.map(this::createData)
.collect(Collectors.toList());
}

private DurationData createData(final TestResult result) {
return new DurationData()
.setUid(result.getUid())
.setName(result.getName())
.setStatus(result.getStatus())
.setTime(result.getTime())
.setSeverity(result.getExtraBlock("severity"));
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.qameta.allure.environment;

import io.qameta.allure.Widget;
import io.qameta.allure.core.Configuration;
import io.qameta.allure.CommonJsonAggregator;
import io.qameta.allure.core.LaunchResults;
import io.qameta.allure.entity.EnvironmentItem;

Expand All @@ -17,29 +16,27 @@
/**
* @author Egor Borisov [email protected]
*/
public class Allure1EnvironmentPlugin implements Widget {
public class Allure1EnvironmentPlugin extends CommonJsonAggregator {

@Override
public List<EnvironmentItem> getData(final Configuration configuration,
final List<LaunchResults> launches) {
public Allure1EnvironmentPlugin() {
super("widgets", "environment.json");
}


protected List<EnvironmentItem> getData(final List<LaunchResults> launches) {
final List<Map.Entry<String, String>> launchEnvironments = launches.stream()
.flatMap(launch -> launch.getExtra(ENVIRONMENT_BLOCK_NAME,
(Supplier<Map<String, String>>) HashMap::new).entrySet().stream())
.collect(toList());

return launchEnvironments.stream()
.collect(groupingBy(Map.Entry::getKey, toList()))
.entrySet().stream().map(this::aggregateItem).collect(toList());
.entrySet().stream().map(Allure1EnvironmentPlugin::aggregateItem).collect(toList());
}

private EnvironmentItem aggregateItem(final Map.Entry<String, List<Map.Entry<String, String>>> entry) {
private static EnvironmentItem aggregateItem(final Map.Entry<String, List<Map.Entry<String, String>>> entry) {
return new EnvironmentItem()
.setName(entry.getKey())
.setValues(entry.getValue().stream().map(Map.Entry::getValue).collect(toList()));
}

@Override
public String getName() {
return "environment";
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.qameta.allure.executor;

import io.qameta.allure.CommonJsonAggregator;
import io.qameta.allure.Reader;
import io.qameta.allure.Widget;
import io.qameta.allure.context.JacksonContext;
import io.qameta.allure.core.Configuration;
import io.qameta.allure.core.LaunchResults;
Expand All @@ -19,17 +19,21 @@
/**
* @author charlie (Dmitry Baev).
*/
public class ExecutorPlugin implements Reader, Widget {
public class ExecutorPlugin extends CommonJsonAggregator implements Reader {

public static final String EXECUTORS_BLOCK_NAME = "executor";
private static final String EXECUTOR_JSON = "executor.json";
protected static final String JSON_FILE_NAME = "executor.json";

public ExecutorPlugin() {
super("widgets", "executors.json");
}

@Override
public void readResults(final Configuration configuration,
final ResultsVisitor visitor,
final Path directory) {
final JacksonContext context = configuration.requireContext(JacksonContext.class);
final Path executorFile = directory.resolve(EXECUTOR_JSON);
final Path executorFile = directory.resolve(JSON_FILE_NAME);
if (Files.exists(executorFile)) {
try (InputStream is = Files.newInputStream(executorFile)) {
final ExecutorInfo info = context.getValue().readValue(is, ExecutorInfo.class);
Expand All @@ -41,8 +45,7 @@ public void readResults(final Configuration configuration,
}

@Override
public List<ExecutorInfo> getData(final Configuration configuration,
final List<LaunchResults> launches) {
protected List<ExecutorInfo> getData(final List<LaunchResults> launches) {
return launches.stream()
.map(launchResults -> launchResults.getExtra(EXECUTORS_BLOCK_NAME))
.filter(Optional::isPresent)
Expand All @@ -51,9 +54,4 @@ public List<ExecutorInfo> getData(final Configuration configuration,
.map(ExecutorInfo.class::cast)
.collect(Collectors.toList());
}

@Override
public String getName() {
return "executors";
}
}

This file was deleted.

Loading