Search in sources :

Example 36 with Facets

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

the class ProjectMeasuresIndexTest method facet_new_lines.

@Test
public void facet_new_lines() {
    index(// 3 docs with ncloc<1K
    newDoc(NEW_LINES, 0d), newDoc(NEW_LINES, 0d), newDoc(NEW_LINES, 999d), // 2 docs with ncloc>=1K and ncloc<10K
    newDoc(NEW_LINES, 1_000d), newDoc(NEW_LINES, 9_999d), // 4 docs with ncloc>=10K and ncloc<100K
    newDoc(NEW_LINES, 10_000d), newDoc(NEW_LINES, 10_000d), newDoc(NEW_LINES, 11_000d), newDoc(NEW_LINES, 99_000d), // 2 docs with ncloc>=100K and ncloc<500K
    newDoc(NEW_LINES, 100_000d), newDoc(NEW_LINES, 499_000d), // 5 docs with ncloc>= 500K
    newDoc(NEW_LINES, 500_000d), newDoc(NEW_LINES, 100_000_000d), newDoc(NEW_LINES, 500_000d), newDoc(NEW_LINES, 1_000_000d), newDoc(NEW_LINES, 100_000_000_000d));
    Facets facets = underTest.search(new ProjectMeasuresQuery(), new SearchOptions().addFacets(NEW_LINES)).getFacets();
    assertThat(facets.get(NEW_LINES)).containsExactly(entry("*-1000.0", 3L), entry("1000.0-10000.0", 2L), entry("10000.0-100000.0", 4L), entry("100000.0-500000.0", 2L), entry("500000.0-*", 5L));
}
Also used : Facets(org.sonar.server.es.Facets) SearchOptions(org.sonar.server.es.SearchOptions) Test(org.junit.Test)

Example 37 with Facets

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

the class ProjectMeasuresIndexTest method does_not_return_facet_when_no_facets_in_options.

@Test
public void does_not_return_facet_when_no_facets_in_options() {
    index(newDoc(PROJECT1, NCLOC, 10d, COVERAGE_KEY, 30d, MAINTAINABILITY_RATING, 3d).setQualityGateStatus(OK.name()));
    Facets facets = underTest.search(new ProjectMeasuresQuery(), new SearchOptions()).getFacets();
    assertThat(facets.getAll()).isEmpty();
}
Also used : Facets(org.sonar.server.es.Facets) SearchOptions(org.sonar.server.es.SearchOptions) Test(org.junit.Test)

Example 38 with Facets

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

the class ProjectMeasuresIndexTest method facet_duplicated_lines_density.

@Test
public void facet_duplicated_lines_density() {
    index(// 1 doc with no duplication
    newDocWithNoMeasure(), // 3 docs with duplication<3%
    newDoc(DUPLICATION, 0d), newDoc(DUPLICATION, 0d), newDoc(DUPLICATION, 2.9d), // 2 docs with duplication>=3% and duplication<5%
    newDoc(DUPLICATION, 3d), newDoc(DUPLICATION, 4.9d), // 4 docs with duplication>=5% and duplication<10%
    newDoc(DUPLICATION, 5d), newDoc(DUPLICATION, 6d), newDoc(DUPLICATION, 6d), newDoc(DUPLICATION, 9.9d), // 2 docs with duplication>=10% and duplication<20%
    newDoc(DUPLICATION, 10d), newDoc(DUPLICATION, 19.9d), // 5 docs with duplication>= 20%
    newDoc(DUPLICATION, 20d), newDoc(DUPLICATION, 20d), newDoc(DUPLICATION, 50d), newDoc(DUPLICATION, 80d), newDoc(DUPLICATION, 100d));
    Facets facets = underTest.search(new ProjectMeasuresQuery(), new SearchOptions().addFacets(DUPLICATION)).getFacets();
    assertThat(facets.get(DUPLICATION)).containsOnly(entry("NO_DATA", 1L), entry("*-3.0", 3L), entry("3.0-5.0", 2L), entry("5.0-10.0", 4L), entry("10.0-20.0", 2L), entry("20.0-*", 5L));
}
Also used : Facets(org.sonar.server.es.Facets) SearchOptions(org.sonar.server.es.SearchOptions) Test(org.junit.Test)

Example 39 with Facets

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

the class ProjectMeasuresIndexTest method facet_new_security_hotspots_reviewed.

@Test
public void facet_new_security_hotspots_reviewed() {
    index(// 2 docs with no measure
    newDocWithNoMeasure(), newDocWithNoMeasure(), // 3 docs < 30%
    newDoc(NEW_SECURITY_HOTSPOTS_REVIEWED, 29), newDoc(NEW_SECURITY_HOTSPOTS_REVIEWED, 28), newDoc(NEW_SECURITY_HOTSPOTS_REVIEWED, 0), // 2 docs with >=30% and <50%
    newDoc(NEW_SECURITY_HOTSPOTS_REVIEWED, 30), newDoc(NEW_SECURITY_HOTSPOTS_REVIEWED, 49), // 4 docs with >=50% and <70%
    newDoc(NEW_SECURITY_HOTSPOTS_REVIEWED, 50), newDoc(NEW_SECURITY_HOTSPOTS_REVIEWED, 60), newDoc(NEW_SECURITY_HOTSPOTS_REVIEWED, 61), newDoc(NEW_SECURITY_HOTSPOTS_REVIEWED, 69), // 2 docs with >=70% and <80%
    newDoc(NEW_SECURITY_HOTSPOTS_REVIEWED, 70), newDoc(NEW_SECURITY_HOTSPOTS_REVIEWED, 79), // 5 docs with >= 80%
    newDoc(NEW_SECURITY_HOTSPOTS_REVIEWED, 80), newDoc(NEW_SECURITY_HOTSPOTS_REVIEWED, 90), newDoc(NEW_SECURITY_HOTSPOTS_REVIEWED, 93), newDoc(NEW_SECURITY_HOTSPOTS_REVIEWED, 99), newDoc(NEW_SECURITY_HOTSPOTS_REVIEWED, 100));
    Facets facets = underTest.search(new ProjectMeasuresQuery(), new SearchOptions().addFacets(NEW_SECURITY_HOTSPOTS_REVIEWED)).getFacets();
    assertThat(facets.get(NEW_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 40 with Facets

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

the class ProjectMeasuresIndexTest method facet_tags_is_sticky.

@Test
public void facet_tags_is_sticky() {
    index(newDoc().setTags(newArrayList("finance")).setQualityGateStatus(OK.name()), newDoc().setTags(newArrayList("finance")).setQualityGateStatus(ERROR.name()), newDoc().setTags(newArrayList("cpp")).setQualityGateStatus(ERROR.name()));
    Facets facets = underTest.search(new ProjectMeasuresQuery().setTags(newHashSet("cpp")), new SearchOptions().addFacets(FIELD_TAGS).addFacets(ALERT_STATUS_KEY)).getFacets();
    assertThat(facets.get(FIELD_TAGS)).containsOnly(entry("finance", 2L), entry("cpp", 1L));
    assertThat(facets.get(ALERT_STATUS_KEY)).containsOnly(entry(OK.name(), 0L), entry(ERROR.name(), 1L), entry(WARN.name(), 0L));
}
Also used : Facets(org.sonar.server.es.Facets) SearchOptions(org.sonar.server.es.SearchOptions) Test(org.junit.Test)

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