Search in sources :

Example 16 with MetricCriterion

use of org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion in project sonarqube by SonarSource.

the class ProjectMeasuresIndexTest method facet_maintainability_rating_is_sticky.

@Test
public void facet_maintainability_rating_is_sticky() {
    index(// docs with rating A
    newDoc(MAINTAINABILITY_RATING, 1d, NCLOC, 100d, COVERAGE, 0d), newDoc(MAINTAINABILITY_RATING, 1d, NCLOC, 200d, COVERAGE, 0d), newDoc(MAINTAINABILITY_RATING, 1d, NCLOC, 999d, COVERAGE, 0d), // docs with rating B
    newDoc(MAINTAINABILITY_RATING, 2d, NCLOC, 2000d, COVERAGE, 0d), newDoc(MAINTAINABILITY_RATING, 2d, NCLOC, 5000d, COVERAGE, 0d), // docs with rating C
    newDoc(MAINTAINABILITY_RATING, 3d, NCLOC, 20000d, COVERAGE, 0d), newDoc(MAINTAINABILITY_RATING, 3d, NCLOC, 30000d, COVERAGE, 0d), newDoc(MAINTAINABILITY_RATING, 3d, NCLOC, 40000d, COVERAGE, 0d), newDoc(MAINTAINABILITY_RATING, 3d, NCLOC, 50000d, COVERAGE, 0d), // docs with rating D
    newDoc(MAINTAINABILITY_RATING, 4d, NCLOC, 120000d, COVERAGE, 0d), // docs with rating E
    newDoc(MAINTAINABILITY_RATING, 5d, NCLOC, 600000d, COVERAGE, 40d), newDoc(MAINTAINABILITY_RATING, 5d, NCLOC, 700000d, COVERAGE, 50d), newDoc(MAINTAINABILITY_RATING, 5d, NCLOC, 800000d, COVERAGE, 60d));
    Facets facets = underTest.search(new ProjectMeasuresQuery().addMetricCriterion(new MetricCriterion(MAINTAINABILITY_RATING, Operator.LT, 3d)).addMetricCriterion(new MetricCriterion(COVERAGE, Operator.LT, 30d)), new SearchOptions().addFacets(MAINTAINABILITY_RATING, NCLOC)).getFacets();
    // Sticky facet on maintainability rating does not take into account maintainability rating filter
    assertThat(facets.get(MAINTAINABILITY_RATING)).containsExactly(entry("1", 3L), entry("2", 2L), entry("3", 4L), entry("4", 1L), entry("5", 0L));
    // But facet on ncloc does well take into into filters
    assertThat(facets.get(NCLOC)).containsExactly(entry("*-1000.0", 3L), entry("1000.0-10000.0", 2L), entry("10000.0-100000.0", 0L), entry("100000.0-500000.0", 0L), entry("500000.0-*", 0L));
}
Also used : MetricCriterion(org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion) Facets(org.sonar.server.es.Facets) SearchOptions(org.sonar.server.es.SearchOptions) Test(org.junit.Test)

Example 17 with MetricCriterion

use of org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion in project sonarqube by SonarSource.

the class ProjectMeasuresQueryTest method add_metric_criterion.

@Test
public void add_metric_criterion() throws Exception {
    underTest.addMetricCriterion(new MetricCriterion("coverage", EQ, 10d));
    assertThat(underTest.getMetricCriteria()).extracting(MetricCriterion::getMetricKey, MetricCriterion::getOperator, MetricCriterion::getValue).containsOnly(tuple("coverage", EQ, 10d));
}
Also used : MetricCriterion(org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion) Test(org.junit.Test)

Example 18 with MetricCriterion

use of org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion in project sonarqube by SonarSource.

the class ProjectMeasuresIndexTest method filter_on_several_metrics.

@Test
public void filter_on_several_metrics() {
    index(newDoc(PROJECT1, COVERAGE, 81d, NCLOC, 10_001d), newDoc(PROJECT2, COVERAGE, 80d, NCLOC, 10_001d), newDoc(PROJECT3, COVERAGE, 79d, NCLOC, 10_000d));
    ProjectMeasuresQuery esQuery = new ProjectMeasuresQuery().addMetricCriterion(new MetricCriterion(COVERAGE, Operator.LTE, 80d)).addMetricCriterion(new MetricCriterion(NCLOC, Operator.GT, 10_000d)).addMetricCriterion(new MetricCriterion(NCLOC, Operator.LT, 11_000d));
    assertResults(esQuery, PROJECT2);
}
Also used : MetricCriterion(org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion) Test(org.junit.Test)

Example 19 with MetricCriterion

use of org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion in project sonarqube by SonarSource.

the class ProjectMeasuresIndexTest method filter_with_greater_than.

@Test
public void filter_with_greater_than() {
    index(newDoc(PROJECT1, COVERAGE, 80d, NCLOC, 30_000d), newDoc(PROJECT2, COVERAGE, 80d, NCLOC, 30_001d), newDoc(PROJECT3, COVERAGE, 80d, NCLOC, 30_001d));
    ProjectMeasuresQuery query = new ProjectMeasuresQuery().addMetricCriterion(new MetricCriterion(NCLOC, Operator.GT, 30_000d));
    assertResults(query, PROJECT2, PROJECT3);
    query = new ProjectMeasuresQuery().addMetricCriterion(new MetricCriterion(NCLOC, Operator.GT, 100_000d));
    assertNoResults(query);
}
Also used : MetricCriterion(org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion) Test(org.junit.Test)

Example 20 with MetricCriterion

use of org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion in project sonarqube by SonarSource.

the class ProjectMeasuresIndexTest method filter_with_lower_than_or_equals.

@Test
public void filter_with_lower_than_or_equals() {
    index(newDoc(PROJECT1, COVERAGE, 79d, NCLOC, 10_000d), newDoc(PROJECT2, COVERAGE, 80d, NCLOC, 10_000d), newDoc(PROJECT3, COVERAGE, 81d, NCLOC, 10_000d));
    ProjectMeasuresQuery query = new ProjectMeasuresQuery().addMetricCriterion(new MetricCriterion(COVERAGE, Operator.LTE, 80d));
    assertResults(query, PROJECT1, PROJECT2);
}
Also used : MetricCriterion(org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion) Test(org.junit.Test)

Aggregations

MetricCriterion (org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion)22 Test (org.junit.Test)20 ProjectMeasuresQuery (org.sonar.server.measure.index.ProjectMeasuresQuery)8 SearchOptions (org.sonar.server.es.SearchOptions)6 Facets (org.sonar.server.es.Facets)4 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Multimap (com.google.common.collect.Multimap)1 Collections.emptyList (java.util.Collections.emptyList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 IntStream (java.util.stream.IntStream)1 Nullable (javax.annotation.Nullable)1 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)1 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)1