Search in sources :

Example 11 with MetricCriterion

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

the class ProjectMeasuresIndexTest method facet_duplicated_lines_density_is_sticky.

@Test
public void facet_duplicated_lines_density_is_sticky() {
    index(// docs with duplication<3%
    newDoc(DUPLICATION, 0d, NCLOC, 999d, COVERAGE, 0d), // docs with duplication>=3% and duplication<5%
    newDoc(DUPLICATION, 3d, NCLOC, 5000d, COVERAGE, 0d), newDoc(DUPLICATION, 4.9d, NCLOC, 6000d, COVERAGE, 0d), // docs with duplication>=5% and duplication<10%
    newDoc(DUPLICATION, 5d, NCLOC, 11000d, COVERAGE, 0d), // docs with duplication>=10% and duplication<20%
    newDoc(DUPLICATION, 10d, NCLOC, 120000d, COVERAGE, 10d), newDoc(DUPLICATION, 19.9d, NCLOC, 130000d, COVERAGE, 20d), // docs with duplication>= 20%
    newDoc(DUPLICATION, 20d, NCLOC, 1000000d, COVERAGE, 40d));
    Facets facets = underTest.search(new ProjectMeasuresQuery().addMetricCriterion(new MetricCriterion(DUPLICATION, Operator.LT, 10d)).addMetricCriterion(new MetricCriterion(COVERAGE, Operator.LT, 30d)), new SearchOptions().addFacets(DUPLICATION, NCLOC)).getFacets();
    // Sticky facet on duplication does not take into account duplication filter
    assertThat(facets.get(DUPLICATION)).containsExactly(entry("*-3.0", 1L), entry("3.0-5.0", 2L), entry("5.0-10.0", 1L), entry("10.0-20.0", 2L), entry("20.0-*", 0L));
    // But facet on ncloc does well take into into filters
    assertThat(facets.get(NCLOC)).containsExactly(entry("*-1000.0", 1L), entry("1000.0-10000.0", 2L), 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 12 with MetricCriterion

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

the class ProjectMeasuresIndexTest method facet_coverage_is_sticky.

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

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

the class ProjectMeasuresQueryValidatorTest method return_all_unknown_metrics.

@Test
public void return_all_unknown_metrics() throws Exception {
    insertValidMetric("ncloc");
    ProjectMeasuresQuery query = new ProjectMeasuresQuery().addMetricCriterion(new MetricCriterion("debt", GT, 10d)).addMetricCriterion(new MetricCriterion("ncloc", LTE, 20d)).addMetricCriterion(new MetricCriterion("coverage", GT, 30d)).setSort("duplications");
    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage("Unknown metric(s) [coverage, debt, duplications]");
    underTest.validate(dbSession, query);
}
Also used : MetricCriterion(org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion) ProjectMeasuresQuery(org.sonar.server.measure.index.ProjectMeasuresQuery) Test(org.junit.Test)

Example 14 with MetricCriterion

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

the class ProjectMeasuresQueryValidatorTest method does_not_fail_when_sort_is_by_name.

@Test
public void does_not_fail_when_sort_is_by_name() throws Exception {
    insertValidMetric("ncloc");
    ProjectMeasuresQuery query = new ProjectMeasuresQuery().addMetricCriterion(new MetricCriterion("ncloc", GT, 10d)).setSort("name");
    underTest.validate(dbSession, query);
}
Also used : MetricCriterion(org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion) ProjectMeasuresQuery(org.sonar.server.measure.index.ProjectMeasuresQuery) Test(org.junit.Test)

Example 15 with MetricCriterion

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

the class ProjectMeasuresQueryValidatorTest method does_not_fail_when_metric_criteria_contains_an_existing_metric.

@Test
public void does_not_fail_when_metric_criteria_contains_an_existing_metric() throws Exception {
    insertValidMetric("ncloc");
    ProjectMeasuresQuery query = new ProjectMeasuresQuery().addMetricCriterion(new MetricCriterion("ncloc", GT, 10d));
    underTest.validate(dbSession, query);
}
Also used : MetricCriterion(org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion) ProjectMeasuresQuery(org.sonar.server.measure.index.ProjectMeasuresQuery) 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