Search in sources :

Example 41 with Facets

use of org.sonar.server.es.Facets in project sonarqube by SonarSource.

the class ProjectMeasuresIndexTest method facet_security_hotspots_reviewed.

@Test
public void facet_security_hotspots_reviewed() {
    index(// 2 docs with no measure
    newDocWithNoMeasure(), newDocWithNoMeasure(), // 3 docs < 30%
    newDoc(SECURITY_HOTSPOTS_REVIEWED, 29), newDoc(SECURITY_HOTSPOTS_REVIEWED, 28), newDoc(SECURITY_HOTSPOTS_REVIEWED, 0), // 2 docs with >=30% and <50%
    newDoc(SECURITY_HOTSPOTS_REVIEWED, 30), newDoc(SECURITY_HOTSPOTS_REVIEWED, 49), // 4 docs with >=50% and <70%
    newDoc(SECURITY_HOTSPOTS_REVIEWED, 50), newDoc(SECURITY_HOTSPOTS_REVIEWED, 60), newDoc(SECURITY_HOTSPOTS_REVIEWED, 61), newDoc(SECURITY_HOTSPOTS_REVIEWED, 69), // 2 docs with >=70% and <80%
    newDoc(SECURITY_HOTSPOTS_REVIEWED, 70), newDoc(SECURITY_HOTSPOTS_REVIEWED, 79), // 5 docs with >= 80%
    newDoc(SECURITY_HOTSPOTS_REVIEWED, 80), newDoc(SECURITY_HOTSPOTS_REVIEWED, 90), newDoc(SECURITY_HOTSPOTS_REVIEWED, 93), newDoc(SECURITY_HOTSPOTS_REVIEWED, 99), newDoc(SECURITY_HOTSPOTS_REVIEWED, 100));
    Facets facets = underTest.search(new ProjectMeasuresQuery(), new SearchOptions().addFacets(SECURITY_HOTSPOTS_REVIEWED)).getFacets();
    assertThat(facets.get(SECURITY_HOTSPOTS_REVIEWED)).containsExactly(entry("*-30.0", 3L), entry("30.0-50.0", 2L), entry("50.0-70.0", 4L), entry("70.0-80.0", 2L), entry("80.0-*", 5L));
}
Also used : Facets(org.sonar.server.es.Facets) SearchOptions(org.sonar.server.es.SearchOptions) Test(org.junit.Test)

Example 42 with Facets

use of org.sonar.server.es.Facets in project sonarqube by SonarSource.

the class ProjectMeasuresIndexTest method facet_languages.

@Test
public void facet_languages() {
    index(newDoc().setLanguages(singletonList("java")), newDoc().setLanguages(singletonList("java")), newDoc().setLanguages(singletonList("xoo")), newDoc().setLanguages(singletonList("xml")), newDoc().setLanguages(asList("<null>", "java")), newDoc().setLanguages(asList("<null>", "java", "xoo")));
    Facets facets = underTest.search(new ProjectMeasuresQuery(), new SearchOptions().addFacets(LANGUAGES)).getFacets();
    assertThat(facets.get(LANGUAGES)).containsOnly(entry("<null>", 2L), entry("java", 4L), entry("xoo", 2L), entry("xml", 1L));
}
Also used : Facets(org.sonar.server.es.Facets) SearchOptions(org.sonar.server.es.SearchOptions) Test(org.junit.Test)

Example 43 with Facets

use of org.sonar.server.es.Facets in project sonarqube by SonarSource.

the class ProjectMeasuresIndexTest method facet_qualifier_is_sticky.

@Test
public void facet_qualifier_is_sticky() {
    index(// 2 docs with qualifier APP
    newDoc(NCLOC, 10d, COVERAGE, 0d).setQualifier(APP), newDoc(NCLOC, 10d, COVERAGE, 0d).setQualifier(APP), // 4 docs with qualifier TRK
    newDoc(NCLOC, 100d, COVERAGE, 0d).setQualifier(PROJECT), newDoc(NCLOC, 5000d, COVERAGE, 40d).setQualifier(PROJECT), newDoc(NCLOC, 12000d, COVERAGE, 50d).setQualifier(PROJECT), newDoc(NCLOC, 13000d, COVERAGE, 60d).setQualifier(PROJECT));
    Facets facets = underTest.search(new ProjectMeasuresQuery().setQualifiers(Sets.newHashSet(PROJECT)).addMetricCriterion(MetricCriterion.create(COVERAGE, Operator.LT, 55d)), new SearchOptions().addFacets(FILTER_QUALIFIER, NCLOC)).getFacets();
    // Sticky facet on qualifier does not take into account qualifier filter
    assertThat(facets.get(FILTER_QUALIFIER)).containsOnly(entry(APP, 2L), entry(PROJECT, 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 : Facets(org.sonar.server.es.Facets) SearchOptions(org.sonar.server.es.SearchOptions) Test(org.junit.Test)

Example 44 with Facets

use of org.sonar.server.es.Facets in project sonarqube by SonarSource.

the class ProjectMeasuresIndexTest method facet_languages_returns_more_than_10_languages_when_languages_filter_contains_value_not_in_top_10.

@Test
public void facet_languages_returns_more_than_10_languages_when_languages_filter_contains_value_not_in_top_10() {
    index(newDoc().setLanguages(asList("<null>", "java", "xoo", "css", "cpp")), newDoc().setLanguages(asList("xml", "php", "python", "perl", "ruby")), newDoc().setLanguages(asList("js", "scala")));
    Facets facets = underTest.search(new ProjectMeasuresQuery().setLanguages(ImmutableSet.of("xoo", "xml")), new SearchOptions().addFacets(LANGUAGES)).getFacets();
    assertThat(facets.get(LANGUAGES)).containsOnly(entry("<null>", 1L), entry("cpp", 1L), entry("css", 1L), entry("java", 1L), entry("js", 1L), entry("perl", 1L), entry("php", 1L), entry("python", 1L), entry("ruby", 1L), entry("scala", 1L), entry("xoo", 1L), entry("xml", 1L));
}
Also used : Facets(org.sonar.server.es.Facets) SearchOptions(org.sonar.server.es.SearchOptions) Test(org.junit.Test)

Example 45 with Facets

use of org.sonar.server.es.Facets in project sonarqube by SonarSource.

the class ProjectMeasuresIndexTest method facet_on_rating.

@Test
@UseDataProvider("rating_metric_keys")
public void facet_on_rating(String metricKey) {
    index(// 3 docs with rating A
    newDoc(metricKey, 1d), newDoc(metricKey, 1d), newDoc(metricKey, 1d), // 2 docs with rating B
    newDoc(metricKey, 2d), newDoc(metricKey, 2d), // 4 docs with rating C
    newDoc(metricKey, 3d), newDoc(metricKey, 3d), newDoc(metricKey, 3d), newDoc(metricKey, 3d), // 2 docs with rating D
    newDoc(metricKey, 4d), newDoc(metricKey, 4d), // 5 docs with rating E
    newDoc(metricKey, 5d), newDoc(metricKey, 5d), newDoc(metricKey, 5d), newDoc(metricKey, 5d), newDoc(metricKey, 5d));
    Facets facets = underTest.search(new ProjectMeasuresQuery(), new SearchOptions().addFacets(metricKey)).getFacets();
    assertThat(facets.get(metricKey)).containsExactly(entry("1", 3L), entry("2", 2L), entry("3", 4L), entry("4", 2L), entry("5", 5L));
}
Also used : Facets(org.sonar.server.es.Facets) SearchOptions(org.sonar.server.es.SearchOptions) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Aggregations

Facets (org.sonar.server.es.Facets)58 SearchOptions (org.sonar.server.es.SearchOptions)51 Test (org.junit.Test)50 SearchResponse (org.elasticsearch.action.search.SearchResponse)14 ComponentDto (org.sonar.db.component.ComponentDto)10 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)3 Paging (org.sonar.api.utils.Paging)2 MoreObjects.firstNonNull (com.google.common.base.MoreObjects.firstNonNull)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Maps (com.google.common.collect.Maps)1 Ordering (com.google.common.collect.Ordering)1 Sets (com.google.common.collect.Sets)1 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)1 ZoneId (java.time.ZoneId)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Collections.emptyMap (java.util.Collections.emptyMap)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1