Search in sources :

Example 6 with Facets

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

the class ProjectMeasuresIndexTest method facet_reliability_rating.

@Test
public void facet_reliability_rating() {
    index(// 3 docs with rating A
    newDoc(RELIABILITY_RATING, 1d), newDoc(RELIABILITY_RATING, 1d), newDoc(RELIABILITY_RATING, 1d), // 2 docs with rating B
    newDoc(RELIABILITY_RATING, 2d), newDoc(RELIABILITY_RATING, 2d), // 4 docs with rating C
    newDoc(RELIABILITY_RATING, 3d), newDoc(RELIABILITY_RATING, 3d), newDoc(RELIABILITY_RATING, 3d), newDoc(RELIABILITY_RATING, 3d), // 2 docs with rating D
    newDoc(RELIABILITY_RATING, 4d), newDoc(RELIABILITY_RATING, 4d), // 5 docs with rating E
    newDoc(RELIABILITY_RATING, 5d), newDoc(RELIABILITY_RATING, 5d), newDoc(RELIABILITY_RATING, 5d), newDoc(RELIABILITY_RATING, 5d), newDoc(RELIABILITY_RATING, 5d));
    Facets facets = underTest.search(new ProjectMeasuresQuery(), new SearchOptions().addFacets(RELIABILITY_RATING)).getFacets();
    assertThat(facets.get(RELIABILITY_RATING)).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)

Example 7 with Facets

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

the class ProjectMeasuresIndexTest method facet_ncloc.

@Test
public void facet_ncloc() {
    index(// 3 docs with ncloc<1K
    newDoc(NCLOC, 0d), newDoc(NCLOC, 0d), newDoc(NCLOC, 999d), // 2 docs with ncloc>=1K and ncloc<10K
    newDoc(NCLOC, 1_000d), newDoc(NCLOC, 9_999d), // 4 docs with ncloc>=10K and ncloc<100K
    newDoc(NCLOC, 10_000d), newDoc(NCLOC, 10_000d), newDoc(NCLOC, 11_000d), newDoc(NCLOC, 99_000d), // 2 docs with ncloc>=100K and ncloc<500K
    newDoc(NCLOC, 100_000d), newDoc(NCLOC, 499_000d), // 5 docs with ncloc>= 500K
    newDoc(NCLOC, 500_000d), newDoc(NCLOC, 100_000_000d), newDoc(NCLOC, 500_000d), newDoc(NCLOC, 1_000_000d), newDoc(NCLOC, 100_000_000_000d));
    Facets facets = underTest.search(new ProjectMeasuresQuery(), new SearchOptions().addFacets(NCLOC)).getFacets();
    assertThat(facets.get(NCLOC)).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 8 with Facets

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

the class ProjectMeasuresIndexTest method facet_security_rating.

@Test
public void facet_security_rating() {
    index(// 3 docs with rating A
    newDoc(SECURITY_RATING, 1.0d), newDoc(SECURITY_RATING, 1.0d), newDoc(SECURITY_RATING, 1.0d), // 2 docs with rating B
    newDoc(SECURITY_RATING, 2.0d), newDoc(SECURITY_RATING, 2.0d), // 4 docs with rating C
    newDoc(SECURITY_RATING, 3.0d), newDoc(SECURITY_RATING, 3.0d), newDoc(SECURITY_RATING, 3.0d), newDoc(SECURITY_RATING, 3.0d), // 2 docs with rating D
    newDoc(SECURITY_RATING, 4.0d), newDoc(SECURITY_RATING, 4.0d), // 5 docs with rating E
    newDoc(SECURITY_RATING, 5.0d), newDoc(SECURITY_RATING, 5.0d), newDoc(SECURITY_RATING, 5.0d), newDoc(SECURITY_RATING, 5.0d), newDoc(SECURITY_RATING, 5.0d));
    Facets facets = underTest.search(new ProjectMeasuresQuery(), new SearchOptions().addFacets(SECURITY_RATING)).getFacets();
    assertThat(facets.get(SECURITY_RATING)).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)

Example 9 with Facets

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

the class ProjectMeasuresIndexTest method facet_maintainability_rating_contains_only_projects_authorized_for_user.

@Test
public void facet_maintainability_rating_contains_only_projects_authorized_for_user() throws Exception {
    // User can see these projects
    indexForUser(USER1, // 3 docs with rating A
    newDoc(MAINTAINABILITY_RATING, 1d), newDoc(MAINTAINABILITY_RATING, 1d), newDoc(MAINTAINABILITY_RATING, 1d), // 2 docs with rating B
    newDoc(MAINTAINABILITY_RATING, 2d), newDoc(MAINTAINABILITY_RATING, 2d));
    // User cannot see these projects
    indexForUser(USER2, // docs with rating C
    newDoc(MAINTAINABILITY_RATING, 3d), // docs with rating D
    newDoc(MAINTAINABILITY_RATING, 4d), // docs with rating E
    newDoc(MAINTAINABILITY_RATING, 5d));
    userSession.logIn(USER1);
    Facets facets = underTest.search(new ProjectMeasuresQuery(), new SearchOptions().addFacets(MAINTAINABILITY_RATING)).getFacets();
    assertThat(facets.get(MAINTAINABILITY_RATING)).containsExactly(entry("1", 3L), entry("2", 2L), entry("3", 0L), entry("4", 0L), entry("5", 0L));
}
Also used : Facets(org.sonar.server.es.Facets) SearchOptions(org.sonar.server.es.SearchOptions) Test(org.junit.Test)

Example 10 with Facets

use of org.sonar.server.es.Facets 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)

Aggregations

Facets (org.sonar.server.es.Facets)23 SearchOptions (org.sonar.server.es.SearchOptions)23 Test (org.junit.Test)21 MetricCriterion (org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion)4 MoreObjects.firstNonNull (com.google.common.base.MoreObjects.firstNonNull)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Ordering (com.google.common.collect.Ordering)1 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)1 String.format (java.lang.String.format)1 Collections (java.util.Collections)1 Collections.emptyMap (java.util.Collections.emptyMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Function (java.util.function.Function)1 Collector (java.util.stream.Collector)1 Stream (java.util.stream.Stream)1