Search in sources :

Example 1 with BlueTestResult

use of io.jenkins.blueocean.rest.model.BlueTestResult in project blueocean-plugin by jenkinsci.

the class BlueTestResultContainerImpl method filterByStatus.

@VisibleForTesting
public static Iterator<BlueTestResult> filterByStatus(Iterable<BlueTestResult> results, String status) {
    String[] statusAtoms = StringUtils.split(status, ',');
    Predicate<BlueTestResult> predicate = Predicates.alwaysFalse();
    if (statusAtoms == null || statusAtoms.length == 0) {
        throw new BadRequestException("status not provided");
    }
    for (String statusString : statusAtoms) {
        Status queryStatus;
        try {
            queryStatus = Status.valueOf(statusString.toUpperCase());
        } catch (IllegalArgumentException e) {
            throw new BadRequestException("bad status " + status, e);
        }
        predicate = Predicates.or(predicate, new StatusPredicate(queryStatus));
    }
    return Iterables.filter(results, predicate).iterator();
}
Also used : Status(io.jenkins.blueocean.rest.model.BlueTestResult.Status) BadRequestException(io.jenkins.blueocean.commons.ServiceException.BadRequestException) BlueTestResult(io.jenkins.blueocean.rest.model.BlueTestResult) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with BlueTestResult

use of io.jenkins.blueocean.rest.model.BlueTestResult in project blueocean-plugin by jenkinsci.

the class BlueTestResultContainerImpl method get.

@Override
public BlueTestResult get(final String name) {
    Result resolved = resolve();
    if (resolved.summary == null || resolved.results == null) {
        throw new NotFoundException("no tests");
    }
    BlueTestResult testResult = IterableUtils.find(resolved.results, blueTestResult -> blueTestResult != null && blueTestResult.getId().equals(name), null);
    if (testResult == null) {
        throw new NotFoundException("not found");
    }
    return testResult;
}
Also used : NotFoundException(io.jenkins.blueocean.commons.ServiceException.NotFoundException) BlueTestResult(io.jenkins.blueocean.rest.model.BlueTestResult) BlueTestResult(io.jenkins.blueocean.rest.model.BlueTestResult) Result(io.jenkins.blueocean.rest.factory.BlueTestResultFactory.Result)

Example 3 with BlueTestResult

use of io.jenkins.blueocean.rest.model.BlueTestResult in project blueocean-plugin by jenkinsci.

the class BlueTestResultContainerImpl method filterByState.

// for testing purpose
public static Predicate<BlueTestResult> filterByState(String state) {
    String[] stateAtoms = StringUtils.split(state, ',');
    Predicate<BlueTestResult> predicate = blueTestResult -> false;
    if (stateAtoms == null || stateAtoms.length == 0) {
        throw new BadRequestException("state not provided");
    }
    for (String stateString : stateAtoms) {
        Predicate<BlueTestResult> statePredicate;
        try {
            if (stateString.startsWith("!")) {
                StatePredicate tmp = new StatePredicate(State.valueOf(stateString.toUpperCase().substring(1)));
                statePredicate = blueTestResult -> !tmp.test(blueTestResult);
            } else {
                statePredicate = new StatePredicate(State.valueOf(stateString.toUpperCase()));
            }
        } catch (IllegalArgumentException e) {
            throw new BadRequestException("bad state " + state, e);
        }
        predicate = predicate.or(statePredicate);
    }
    return predicate;
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) Iterator(java.util.Iterator) StringUtils.isEmpty(org.apache.commons.lang.StringUtils.isEmpty) Predicate(java.util.function.Predicate) StaplerRequest(org.kohsuke.stapler.StaplerRequest) Reachable(io.jenkins.blueocean.rest.Reachable) IterableUtils(io.jenkins.blueocean.commons.IterableUtils) NotFoundException(io.jenkins.blueocean.commons.ServiceException.NotFoundException) Run(hudson.model.Run) BadRequestException(io.jenkins.blueocean.commons.ServiceException.BadRequestException) Status(io.jenkins.blueocean.rest.model.BlueTestResult.Status) BlueTestResult(io.jenkins.blueocean.rest.model.BlueTestResult) BlueTestResultFactory(io.jenkins.blueocean.rest.factory.BlueTestResultFactory) Stapler(org.kohsuke.stapler.Stapler) State(io.jenkins.blueocean.rest.model.BlueTestResult.State) BlueTestResultContainer(io.jenkins.blueocean.rest.model.BlueTestResultContainer) NonNull(edu.umd.cs.findbugs.annotations.NonNull) Nullable(edu.umd.cs.findbugs.annotations.Nullable) StreamSupport(java.util.stream.StreamSupport) Result(io.jenkins.blueocean.rest.factory.BlueTestResultFactory.Result) BadRequestException(io.jenkins.blueocean.commons.ServiceException.BadRequestException) BlueTestResult(io.jenkins.blueocean.rest.model.BlueTestResult)

Example 4 with BlueTestResult

use of io.jenkins.blueocean.rest.model.BlueTestResult in project blueocean-plugin by jenkinsci.

the class BlueTestResultContainerImpl method iterator.

@NonNull
@Override
public Iterator<BlueTestResult> iterator() {
    Result resolved = resolve();
    if (resolved.summary == null || resolved.results == null) {
        throw new NotFoundException("no tests");
    }
    StaplerRequest request = Stapler.getCurrentRequest();
    if (request != null) {
        String status = request.getParameter("status");
        String state = request.getParameter("state");
        String age = request.getParameter("age");
        return getBlueTestResultIterator(resolved.results, status, state, age);
    }
    return resolved.results.iterator();
}
Also used : StaplerRequest(org.kohsuke.stapler.StaplerRequest) NotFoundException(io.jenkins.blueocean.commons.ServiceException.NotFoundException) BlueTestResult(io.jenkins.blueocean.rest.model.BlueTestResult) Result(io.jenkins.blueocean.rest.factory.BlueTestResultFactory.Result) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Example 5 with BlueTestResult

use of io.jenkins.blueocean.rest.model.BlueTestResult in project blueocean-plugin by jenkinsci.

the class BlueTestResultContainerImplTest method testsFilteredByState.

@Test
public void testsFilteredByState() throws Exception {
    List<BlueTestResult> allResults = IteratorUtils.toList(container.iterator());
    List<BlueTestResult> regressions = IteratorUtils.toList(container.getBlueTestResultIterator(allResults, null, State.REGRESSION.name(), null));
    assertEquals(2, regressions.size());
    for (BlueTestResult tr : regressions) {
        assertEquals(State.REGRESSION, tr.getTestState());
    }
}
Also used : BlueTestResult(io.jenkins.blueocean.rest.model.BlueTestResult) Test(org.junit.Test)

Aggregations

BlueTestResult (io.jenkins.blueocean.rest.model.BlueTestResult)11 BadRequestException (io.jenkins.blueocean.commons.ServiceException.BadRequestException)4 NotFoundException (io.jenkins.blueocean.commons.ServiceException.NotFoundException)4 Result (io.jenkins.blueocean.rest.factory.BlueTestResultFactory.Result)4 Test (org.junit.Test)4 NonNull (edu.umd.cs.findbugs.annotations.NonNull)3 State (io.jenkins.blueocean.rest.model.BlueTestResult.State)3 Status (io.jenkins.blueocean.rest.model.BlueTestResult.Status)3 StaplerRequest (org.kohsuke.stapler.StaplerRequest)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Nullable (edu.umd.cs.findbugs.annotations.Nullable)2 Run (hudson.model.Run)2 IterableUtils (io.jenkins.blueocean.commons.IterableUtils)2 Reachable (io.jenkins.blueocean.rest.Reachable)2 BlueTestResultFactory (io.jenkins.blueocean.rest.factory.BlueTestResultFactory)2 BlueTestResultContainer (io.jenkins.blueocean.rest.model.BlueTestResultContainer)2 Iterator (java.util.Iterator)2 Predicate (java.util.function.Predicate)2 StreamSupport (java.util.stream.StreamSupport)2 StringUtils (org.apache.commons.lang.StringUtils)2