Search in sources :

Example 81 with SearchOptions

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

the class IssueIndexTest method facet_on_created_at_with_bounds_outside_of_data.

@Test
public void facet_on_created_at_with_bounds_outside_of_data() {
    SearchOptions options = fixtureForCreatedAtFacet();
    Map<String, Long> createdAt = underTest.search(IssueQuery.builder().createdAfter(parseDateTime("2009-01-01T00:00:00+0100")).createdBefore(parseDateTime("2016-01-01T00:00:00+0100")).build(), options).getFacets().get("createdAt");
    assertThat(createdAt).containsOnly(entry("2008-01-01T01:00:00+0000", 0L), entry("2009-01-01T01:00:00+0000", 0L), entry("2010-01-01T01:00:00+0000", 0L), entry("2011-01-01T01:00:00+0000", 1L), entry("2012-01-01T01:00:00+0000", 0L), entry("2013-01-01T01:00:00+0000", 0L), entry("2014-01-01T01:00:00+0000", 5L), entry("2015-01-01T01:00:00+0000", 1L));
}
Also used : SearchOptions(org.sonar.server.es.SearchOptions) Test(org.junit.Test)

Example 82 with SearchOptions

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

the class IssueIndexTest method paging.

@Test
public void paging() {
    ComponentDto project = newProjectDto(newOrganizationDto());
    ComponentDto file = newFileDto(project, null);
    for (int i = 0; i < 12; i++) {
        indexIssues(IssueDocTesting.newDoc("ISSUE" + i, file));
    }
    IssueQuery.Builder query = IssueQuery.builder();
    // There are 12 issues in total, with 10 issues per page, the page 2 should only contain 2 elements
    SearchResult<IssueDoc> result = underTest.search(query.build(), new SearchOptions().setPage(2, 10));
    assertThat(result.getDocs()).hasSize(2);
    assertThat(result.getTotal()).isEqualTo(12);
    result = underTest.search(IssueQuery.builder().build(), new SearchOptions().setOffset(0).setLimit(5));
    assertThat(result.getDocs()).hasSize(5);
    assertThat(result.getTotal()).isEqualTo(12);
    result = underTest.search(IssueQuery.builder().build(), new SearchOptions().setOffset(2).setLimit(0));
    assertThat(result.getDocs()).hasSize(10);
    assertThat(result.getTotal()).isEqualTo(12);
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) IssueQuery(org.sonar.server.issue.IssueQuery) SearchOptions(org.sonar.server.es.SearchOptions) Test(org.junit.Test)

Example 83 with SearchOptions

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

the class IssueIndexDebtTest method facets_on_severities.

@Test
public void facets_on_severities() {
    ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto());
    ComponentDto file = ComponentTesting.newFileDto(project, null);
    indexIssues(IssueDocTesting.newDoc("ISSUE1", file).setSeverity(Severity.INFO), IssueDocTesting.newDoc("ISSUE2", file).setSeverity(Severity.INFO), IssueDocTesting.newDoc("ISSUE3", file).setSeverity(Severity.MAJOR));
    SearchResult<IssueDoc> result = index.search(newQueryBuilder().build(), new SearchOptions().addFacets(newArrayList("severities")));
    assertThat(result.getFacets().getNames()).containsOnly("severities", FACET_MODE_EFFORT);
    assertThat(result.getFacets().get("severities")).containsOnly(entry("INFO", 20L), entry("MAJOR", 10L));
    assertThat(result.getFacets().get(FACET_MODE_EFFORT)).containsOnly(entry("total", 30L));
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) SearchOptions(org.sonar.server.es.SearchOptions) Test(org.junit.Test)

Example 84 with SearchOptions

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

the class IssueIndexTest method facet_on_created_at_with_more_than_20_months.

@Test
public void facet_on_created_at_with_more_than_20_months() {
    SearchOptions SearchOptions = fixtureForCreatedAtFacet();
    Map<String, Long> createdAt = underTest.search(IssueQuery.builder().createdAfter(parseDateTime("2011-01-01T00:00:00+0100")).createdBefore(parseDateTime("2016-01-01T00:00:00+0100")).build(), SearchOptions).getFacets().get("createdAt");
    assertThat(createdAt).containsOnly(entry("2010-01-01T01:00:00+0000", 0L), entry("2011-01-01T01:00:00+0000", 1L), entry("2012-01-01T01:00:00+0000", 0L), entry("2013-01-01T01:00:00+0000", 0L), entry("2014-01-01T01:00:00+0000", 5L), entry("2015-01-01T01:00:00+0000", 1L));
}
Also used : SearchOptions(org.sonar.server.es.SearchOptions) Test(org.junit.Test)

Example 85 with SearchOptions

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

the class IssueIndexTest method facets_on_projects.

@Test
public void facets_on_projects() {
    OrganizationDto organizationDto = newOrganizationDto();
    ComponentDto project = newProjectDto(organizationDto, "ABCD");
    ComponentDto project2 = newProjectDto(organizationDto, "EFGH");
    indexIssues(IssueDocTesting.newDoc("ISSUE1", newFileDto(project, null)), IssueDocTesting.newDoc("ISSUE2", newFileDto(project, null)), IssueDocTesting.newDoc("ISSUE3", newFileDto(project2, null)));
    SearchResult<IssueDoc> result = underTest.search(IssueQuery.builder().build(), new SearchOptions().addFacets(newArrayList("projectUuids")));
    assertThat(result.getFacets().getNames()).containsOnly("projectUuids");
    assertThat(result.getFacets().get("projectUuids")).containsOnly(entry("ABCD", 2L), entry("EFGH", 1L));
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) SearchOptions(org.sonar.server.es.SearchOptions) OrganizationTesting.newOrganizationDto(org.sonar.db.organization.OrganizationTesting.newOrganizationDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Aggregations

SearchOptions (org.sonar.server.es.SearchOptions)143 Test (org.junit.Test)127 ComponentDto (org.sonar.db.component.ComponentDto)62 Facets (org.sonar.server.es.Facets)22 RuleQuery (org.sonar.server.rule.index.RuleQuery)22 RuleDto (org.sonar.db.rule.RuleDto)16 RuleKey (org.sonar.api.rule.RuleKey)14 OrganizationDto (org.sonar.db.organization.OrganizationDto)11 IssueQuery (org.sonar.server.issue.IssueQuery)11 ActiveRuleKey (org.sonar.db.qualityprofile.ActiveRuleKey)10 ActiveRuleDto (org.sonar.db.qualityprofile.ActiveRuleDto)9 QualityProfileDto (org.sonar.db.qualityprofile.QualityProfileDto)9 SearchIdResult (org.sonar.server.es.SearchIdResult)9 DbSession (org.sonar.db.DbSession)8 OrganizationTesting.newOrganizationDto (org.sonar.db.organization.OrganizationTesting.newOrganizationDto)7 JsonWriter (org.sonar.api.utils.text.JsonWriter)5 MetricCriterion (org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion)5 RulesDefinition (org.sonar.api.server.rule.RulesDefinition)4 RuleParamDto (org.sonar.db.rule.RuleParamDto)4 UserDto (org.sonar.db.user.UserDto)3