Search in sources :

Example 1 with TestScopeFilter

use of jetbrains.buildServer.server.rest.data.problem.scope.TestScopeFilter in project teamcity-rest by JetBrains.

the class TestOccurrenceFinder method getFilter.

@NotNull
@Override
public ItemFilter<STestRun> getFilter(@NotNull final Locator locator) {
    final MultiCheckerFilter<STestRun> result = new MultiCheckerFilter<>();
    if (locator.isUnused(DIMENSION_ID)) {
        Long testRunId = locator.getSingleDimensionValueAsLong(DIMENSION_ID);
        // If someone voluntarily excluded personal build when searching by test run id, then assume that is exactly what they want.
        // Otherwise, return a test run in a personal build by default.
        locator.setDimensionIfNotPresent(INCLUDE_PERSONAL, "true");
        if (testRunId != null) {
            result.add(item -> testRunId.intValue() == item.getTestRunId());
        }
    }
    Status status = Util.resolveNull(locator.getSingleDimensionValue(STATUS), TestOccurrence::getStatusFromPosted);
    if (status != null) {
        result.add(item -> status.equals(item.getStatus()));
    }
    final Boolean ignoredDimension = locator.getSingleDimensionValueAsBoolean(IGNORED);
    if (ignoredDimension != null) {
        result.add(item -> FilterUtil.isIncludedByBooleanFilter(ignoredDimension, item.isIgnored()));
    }
    final String nameDimension = locator.getSingleDimensionValue(NAME);
    if (nameDimension != null) {
        ValueCondition nameCondition = ParameterCondition.createValueConditionFromPlainValueOrCondition(nameDimension);
        result.add(item -> nameCondition.matches(item.getTest().getName().getAsString()));
    }
    if (locator.getUnusedDimensions().contains(TEST)) {
        String testDimension = locator.getSingleDimensionValue(TEST);
        if (testDimension != null) {
            final PagedSearchResult<STest> tests = myTestFinder.getItems(testDimension);
            final HashSet<Long> testNameIds = new HashSet<>();
            for (STest test : tests.myEntries) {
                testNameIds.add(test.getTestNameId());
            }
            result.add(item -> testNameIds.contains(item.getTest().getTestNameId()));
        }
    }
    if (locator.isUnused(BUILD)) {
        String buildDimension = locator.getSingleDimensionValue(BUILD);
        if (buildDimension != null) {
            // Include test runs from personal build if user is looking for one specific build.
            boolean searchByBuildId = new Locator(buildDimension).isAnyPresent(BuildFinder.DIMENSION_ID);
            locator.setDimensionIfNotPresent(INCLUDE_PERSONAL, Boolean.toString(searchByBuildId));
            // todo: use buildPromotionFinder, use filter; drop personal builds filtering in test history
            List<BuildPromotion> builds = myBuildFinder.getBuilds(null, buildDimension).myEntries;
            result.add(item -> builds.contains(item.getBuild().getBuildPromotion()));
        }
    }
    if (locator.isUnused(BRANCH)) {
        String branchDimension = locator.getSingleDimensionValue(BRANCH);
        if (branchDimension != null) {
            Filter<STestRun> branchFilter = getBranchFilter(branchDimension);
            result.add(branchFilter::accept);
        }
    }
    if (locator.isUnused(BUILD_TYPE)) {
        String buildTypeDimension = locator.getSingleDimensionValue(BUILD_TYPE);
        if (buildTypeDimension != null) {
            final SBuildType buildType = myBuildTypeFinder.getBuildType(null, buildTypeDimension, false);
            result.add(item -> item.getBuild().getBuildTypeId().equals(buildType.getInternalId()));
        }
    }
    final Boolean currentlyInvestigatedDimension = locator.getSingleDimensionValueAsBoolean(CURRENTLY_INVESTIGATED);
    if (currentlyInvestigatedDimension != null) {
        result.add(item -> {
            // todo: check investigation in affected Project/buildType only, if set
            return FilterUtil.isIncludedByBooleanFilter(currentlyInvestigatedDimension, isCurrentlyInvestigated(item));
        });
    }
    final String investigationState = locator.getSingleDimensionValue(INVESTIGATION_STATE);
    if (investigationState != null) {
        result.add(hasInvestigationStateFilter(investigationState));
    }
    final Boolean currentlyMutedDimension = locator.getSingleDimensionValueAsBoolean(CURRENTLY_MUTED);
    if (currentlyMutedDimension != null) {
        // it is important to filter even if prefiltered items processed the tests as that does not consider mute scope
        result.add(item -> {
            // todo: check mute in affected Project/buildType only, if set
            return FilterUtil.isIncludedByBooleanFilter(currentlyMutedDimension, isCurrentlyMuted(item));
        });
    }
    final Boolean newFailure = locator.getSingleDimensionValueAsBoolean(NEW_FAILURE);
    if (newFailure != null) {
        // when newFailure is specified, do not match non-failed tests. This matches the logic of newFailure attribute presence in TestOccurrence
        result.add(item -> item.getStatus().isFailed() && FilterUtil.isIncludedByBooleanFilter(newFailure, item.isNewFailure()));
    }
    final Boolean muteDimension = locator.getSingleDimensionValueAsBoolean(MUTED);
    if (muteDimension != null) {
        result.add(item -> FilterUtil.isIncludedByBooleanFilter(muteDimension, item.isMuted()));
    }
    if (locator.isUnused(CURRENT)) {
        final Boolean currentDimension = locator.getSingleDimensionValueAsBoolean(CURRENT);
        if (currentDimension != null) {
            // todo: is this the same as the test occurring in current problems???
            result.add(item -> FilterUtil.isIncludedByBooleanFilter(currentDimension, !item.isFixed()));
        }
    }
    final String scopeDimension = locator.getSingleDimensionValue(SCOPE);
    if (scopeDimension != null) {
        final TestScopeFilter filter = myTestScopeFilterProducer.createFromLocatorString(scopeDimension);
        result.add(item -> filter.test(item));
    }
    if (locator.getUnusedDimensions().contains(INVOCATIONS)) {
        final String dimensionValue = locator.getSingleDimensionValue(INVOCATIONS);
        if (dimensionValue != null) {
            result.add(item -> {
                Collection<STestRun> testRuns = getInvocations(item);
                FinderSearchMatcher<STestRun> matcher = new FinderSearchMatcher<>(dimensionValue, new DelegatingAbstractFinder<STestRun>(TestOccurrenceFinder.this) {

                    @Nullable
                    @Override
                    public STestRun findSingleItem(@NotNull final Locator locator1) {
                        return null;
                    }

                    @NotNull
                    @Override
                    public ItemHolder<STestRun> getPrefilteredItems(@NotNull final Locator locator1) {
                        return getItemHolder(testRuns);
                    }
                });
                return matcher.matches(null);
            });
        }
    }
    // Exclude test runs form personal builds by default to , if not included by a special cases above.
    Filter<STestRun> personalBuildsFilter = getPersonalBuildsFilter(locator);
    result.add(personalBuildsFilter::accept);
    return result;
}
Also used : AggregatingItemHolder(jetbrains.buildServer.server.rest.data.util.AggregatingItemHolder) TestScopeFilter(jetbrains.buildServer.server.rest.data.problem.scope.TestScopeFilter) NotNull(org.jetbrains.annotations.NotNull) Status(jetbrains.buildServer.messages.Status) TestOccurrence(jetbrains.buildServer.server.rest.model.problem.TestOccurrence) Nullable(org.jetbrains.annotations.Nullable) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Status (jetbrains.buildServer.messages.Status)1 TestScopeFilter (jetbrains.buildServer.server.rest.data.problem.scope.TestScopeFilter)1 AggregatingItemHolder (jetbrains.buildServer.server.rest.data.util.AggregatingItemHolder)1 TestOccurrence (jetbrains.buildServer.server.rest.model.problem.TestOccurrence)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1