Search in sources :

Example 6 with MetricCriterion

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

the class ProjectMeasuresIndexTest method facet_quality_gate_is_sticky.

@Test
public void facet_quality_gate_is_sticky() {
    index(// 2 docs with QG OK
    newDoc(NCLOC, 10d, COVERAGE, 0d).setQualityGateStatus(OK.name()), newDoc(NCLOC, 10d, COVERAGE, 0d).setQualityGateStatus(OK.name()), // 3 docs with QG WARN
    newDoc(NCLOC, 100d, COVERAGE, 0d).setQualityGateStatus(WARN.name()), newDoc(NCLOC, 100d, COVERAGE, 0d).setQualityGateStatus(WARN.name()), newDoc(NCLOC, 100d, COVERAGE, 0d).setQualityGateStatus(WARN.name()), // 4 docs with QG ERROR
    newDoc(NCLOC, 100d, COVERAGE, 0d).setQualityGateStatus(ERROR.name()), newDoc(NCLOC, 5000d, COVERAGE, 40d).setQualityGateStatus(ERROR.name()), newDoc(NCLOC, 12000d, COVERAGE, 50d).setQualityGateStatus(ERROR.name()), newDoc(NCLOC, 13000d, COVERAGE, 60d).setQualityGateStatus(ERROR.name()));
    Facets facets = underTest.search(new ProjectMeasuresQuery().setQualityGateStatus(ERROR).addMetricCriterion(new MetricCriterion(COVERAGE, Operator.LT, 55d)), new SearchOptions().addFacets(ALERT_STATUS_KEY, NCLOC)).getFacets();
    // Sticky facet on quality gate does not take into account quality gate filter
    assertThat(facets.get(ALERT_STATUS_KEY)).containsOnly(entry(OK.name(), 2L), entry(WARN.name(), 3L), entry(ERROR.name(), 3L));
    // But facet on ncloc does well take into into filters
    assertThat(facets.get(NCLOC)).containsExactly(entry("*-1000.0", 1L), entry("1000.0-10000.0", 1L), entry("10000.0-100000.0", 1L), 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 7 with MetricCriterion

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

the class ProjectMeasuresIndexTest method filter_with_equals.

@Test
public void filter_with_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.EQ, 80d));
    assertResults(query, PROJECT2);
}
Also used : MetricCriterion(org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion) Test(org.junit.Test)

Example 8 with MetricCriterion

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

the class ProjectMeasuresIndexTest method facet_ncloc_is_sticky.

@Test
public void facet_ncloc_is_sticky() {
    index(// 1 docs with ncloc<1K
    newDoc(NCLOC, 999d, COVERAGE, 0d, DUPLICATION, 0d), // 2 docs with ncloc>=1K and ncloc<10K
    newDoc(NCLOC, 1_000d, COVERAGE, 10d, DUPLICATION, 0d), newDoc(NCLOC, 9_999d, COVERAGE, 20d, DUPLICATION, 0d), // 3 docs with ncloc>=10K and ncloc<100K
    newDoc(NCLOC, 10_000d, COVERAGE, 31d, DUPLICATION, 0d), newDoc(NCLOC, 11_000d, COVERAGE, 40d, DUPLICATION, 0d), newDoc(NCLOC, 99_000d, COVERAGE, 50d, DUPLICATION, 0d), // 2 docs with ncloc>=100K and ncloc<500K
    newDoc(NCLOC, 100_000d, COVERAGE, 71d, DUPLICATION, 0d), newDoc(NCLOC, 499_000d, COVERAGE, 80d, DUPLICATION, 0d), // 1 docs with ncloc>= 500K
    newDoc(NCLOC, 501_000d, COVERAGE, 81d, DUPLICATION, 20d));
    Facets facets = underTest.search(new ProjectMeasuresQuery().addMetricCriterion(new MetricCriterion(NCLOC, Operator.LT, 10_000d)).addMetricCriterion(new MetricCriterion(DUPLICATION, Operator.LT, 10d)), new SearchOptions().addFacets(NCLOC, COVERAGE)).getFacets();
    // Sticky facet on ncloc does not take into account ncloc filter
    assertThat(facets.get(NCLOC)).containsExactly(entry("*-1000.0", 1L), entry("1000.0-10000.0", 2L), entry("10000.0-100000.0", 3L), entry("100000.0-500000.0", 2L), entry("500000.0-*", 0L));
    // But facet on coverage does well take into into filters
    assertThat(facets.get(COVERAGE)).containsExactly(entry("*-30.0", 3L), entry("30.0-50.0", 0L), entry("50.0-70.0", 0L), entry("70.0-80.0", 0L), entry("80.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 9 with MetricCriterion

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

the class ProjectMeasuresIndexTest method filter_with_lower_than.

@Test
public void filter_with_lower_than() {
    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.LT, 80d));
    assertResults(query, PROJECT1);
}
Also used : MetricCriterion(org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion) Test(org.junit.Test)

Example 10 with MetricCriterion

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

the class ProjectMeasuresIndexTest method filter_with_greater_than_or_equals.

@Test
public void filter_with_greater_than_or_equals() {
    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.GTE, 30_001d));
    assertResults(query, PROJECT2, PROJECT3);
    query = new ProjectMeasuresQuery().addMetricCriterion(new MetricCriterion(NCLOC, Operator.GTE, 100_000d));
    assertNoResults(query);
}
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