Search in sources :

Example 26 with Facets

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

the class IssueIndexDebtTest method facets_on_components.

@Test
public void facets_on_components() {
    ComponentDto project = ComponentTesting.newPrivateProjectDto("A");
    ComponentDto file1 = ComponentTesting.newFileDto(project, null, "ABCD");
    ComponentDto file2 = ComponentTesting.newFileDto(project, null, "BCDE");
    ComponentDto file3 = ComponentTesting.newFileDto(project, null, "CDEF");
    indexIssues(IssueDocTesting.newDoc("I1", project).setEffort(10L), IssueDocTesting.newDoc("I2", file1).setEffort(10L), IssueDocTesting.newDoc("I3", file2).setEffort(10L), IssueDocTesting.newDoc("I4", file2).setEffort(10L), IssueDocTesting.newDoc("I5", file3).setEffort(10L));
    Facets facets = search("files");
    assertThat(facets.getNames()).containsOnly("files", FACET_MODE_EFFORT);
    assertThat(facets.get("files")).containsOnly(entry(file1.path(), 10L), entry(file2.path(), 20L), entry(file3.path(), 10L));
    assertThat(facets.get(FACET_MODE_EFFORT)).containsOnly(entry("total", 50L));
}
Also used : Facets(org.sonar.server.es.Facets) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 27 with Facets

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

the class IssueIndexDebtTest method facets_on_projects.

@Test
public void facets_on_projects() {
    ComponentDto project = ComponentTesting.newPrivateProjectDto("ABCD");
    ComponentDto project2 = ComponentTesting.newPrivateProjectDto("EFGH");
    indexIssues(IssueDocTesting.newDoc("I1", ComponentTesting.newFileDto(project, null)).setEffort(10L), IssueDocTesting.newDoc("I2", ComponentTesting.newFileDto(project, null)).setEffort(10L), IssueDocTesting.newDoc("I3", ComponentTesting.newFileDto(project2, null)).setEffort(10L));
    Facets facets = search("projects");
    assertThat(facets.getNames()).containsOnly("projects", FACET_MODE_EFFORT);
    assertThat(facets.get("projects")).containsOnly(entry("ABCD", 20L), entry("EFGH", 10L));
    assertThat(facets.get(FACET_MODE_EFFORT)).containsOnly(entry("total", 30L));
}
Also used : Facets(org.sonar.server.es.Facets) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 28 with Facets

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

the class IssueIndexDebtTest method facets_on_assignees.

@Test
public void facets_on_assignees() {
    ComponentDto project = ComponentTesting.newPrivateProjectDto();
    ComponentDto file = ComponentTesting.newFileDto(project, null);
    indexIssues(IssueDocTesting.newDoc("I1", file).setAssigneeUuid("uuid-steph").setEffort(10L), IssueDocTesting.newDoc("I2", file).setAssigneeUuid("uuid-simon").setEffort(10L), IssueDocTesting.newDoc("I3", file).setAssigneeUuid("uuid-simon").setEffort(10L), IssueDocTesting.newDoc("I4", file).setAssigneeUuid(null).setEffort(10L));
    Facets facets = new Facets(underTest.search(newQueryBuilder().build(), new SearchOptions().addFacets(singletonList("assignees"))), system2.getDefaultTimeZone().toZoneId());
    assertThat(facets.getNames()).containsOnly("assignees", FACET_MODE_EFFORT);
    assertThat(facets.get("assignees")).containsOnly(entry("uuid-steph", 10L), entry("uuid-simon", 20L), entry("", 10L));
    assertThat(facets.get(FACET_MODE_EFFORT)).containsOnly(entry("total", 40L));
}
Also used : Facets(org.sonar.server.es.Facets) ComponentDto(org.sonar.db.component.ComponentDto) SearchOptions(org.sonar.server.es.SearchOptions) Test(org.junit.Test)

Example 29 with Facets

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

the class IssueIndexDebtTest method facets_on_languages.

@Test
public void facets_on_languages() {
    ComponentDto project = ComponentTesting.newPrivateProjectDto();
    ComponentDto file = ComponentTesting.newFileDto(project, null);
    indexIssues(IssueDocTesting.newDoc("I1", file).setLanguage("xoo").setEffort(10L));
    Facets facets = search("languages");
    assertThat(facets.getNames()).containsOnly("languages", FACET_MODE_EFFORT);
    assertThat(facets.get("languages")).containsOnly(entry("xoo", 10L));
    assertThat(facets.get(FACET_MODE_EFFORT)).containsOnly(entry("total", 10L));
}
Also used : Facets(org.sonar.server.es.Facets) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 30 with Facets

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

the class IssueIndexFacetsTest method assertThatFacetHasExactly.

@SafeVarargs
private final void assertThatFacetHasExactly(IssueQuery.Builder query, String facet, Map.Entry<String, Long>... expectedEntries) {
    SearchResponse result = underTest.search(query.build(), new SearchOptions().addFacets(singletonList(facet)));
    Facets facets = new Facets(result, system2.getDefaultTimeZone().toZoneId());
    assertThat(facets.getNames()).containsOnly(facet, "effort");
    assertThat(facets.get(facet)).containsExactly(expectedEntries);
}
Also used : Facets(org.sonar.server.es.Facets) SearchOptions(org.sonar.server.es.SearchOptions) SearchResponse(org.elasticsearch.action.search.SearchResponse)

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