All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.qameta.allure.graph.GraphPlugin Maven / Gradle / Ivy

There is a newer version: 2.32.0
Show newest version
package io.qameta.allure.graph;

import io.qameta.allure.Aggregator;
import io.qameta.allure.context.JacksonContext;
import io.qameta.allure.core.Configuration;
import io.qameta.allure.core.LaunchResults;
import io.qameta.allure.entity.TestResult;

import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Plugin that generates data for Graph tab.
 *
 * @since 2.0
 */
public class GraphPlugin implements Aggregator {

    @Override
    public void aggregate(final Configuration configuration,
                          final List launchesResults,
                          final Path outputDirectory) throws IOException {
        final JacksonContext context = configuration.requireContext(JacksonContext.class);
        final Path dataFolder = Files.createDirectories(outputDirectory.resolve("data"));
        final Path graphFile = dataFolder.resolve("graph.json");

        final List data = launchesResults.stream()
                .flatMap(launch -> launch.getResults().stream())
                .map(this::createData)
                .collect(Collectors.toList());
        try (OutputStream os = Files.newOutputStream(graphFile)) {
            context.getValue().writeValue(os, data);
        }
    }

    private GraphData createData(final TestResult result) {
        return new GraphData()
                .withUid(result.getUid())
                .withName(result.getName())
                .withStatus(result.getStatus())
                .withTime(result.getTime())
                .withSeverity(result.getExtraBlock("severity"));
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy