Search in sources :

Example 21 with SearchOptions

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

the class IssueIndexTest method filter_by_created_after.

@Test
public void filter_by_created_after() {
    ComponentDto project = newProjectDto(newOrganizationDto());
    ComponentDto file = newFileDto(project, null);
    indexIssues(IssueDocTesting.newDoc("ISSUE1", file).setFuncCreationDate(parseDate("2014-09-20")), IssueDocTesting.newDoc("ISSUE2", file).setFuncCreationDate(parseDate("2014-09-23")));
    assertThat(underTest.search(IssueQuery.builder().createdAfter(parseDate("2014-09-19")).build(), new SearchOptions()).getDocs()).hasSize(2);
    // Lower bound is included
    assertThat(underTest.search(IssueQuery.builder().createdAfter(parseDate("2014-09-20")).build(), new SearchOptions()).getDocs()).hasSize(2);
    assertThat(underTest.search(IssueQuery.builder().createdAfter(parseDate("2014-09-21")).build(), new SearchOptions()).getDocs()).hasSize(1);
    assertThat(underTest.search(IssueQuery.builder().createdAfter(parseDate("2014-09-25")).build(), new SearchOptions()).getDocs()).isEmpty();
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) SearchOptions(org.sonar.server.es.SearchOptions) Test(org.junit.Test)

Example 22 with SearchOptions

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

the class IssueIndexTest method filter_by_created_before.

@Test
public void filter_by_created_before() {
    ComponentDto project = newProjectDto(newOrganizationDto());
    ComponentDto file = newFileDto(project, null);
    indexIssues(IssueDocTesting.newDoc("ISSUE1", file).setFuncCreationDate(parseDate("2014-09-20")), IssueDocTesting.newDoc("ISSUE2", file).setFuncCreationDate(parseDate("2014-09-23")));
    assertThat(underTest.search(IssueQuery.builder().createdBefore(parseDate("2014-09-19")).build(), new SearchOptions()).getDocs()).isEmpty();
    // Upper bound is excluded
    assertThat(underTest.search(IssueQuery.builder().createdBefore(parseDate("2014-09-20")).build(), new SearchOptions()).getDocs()).isEmpty();
    assertThat(underTest.search(IssueQuery.builder().createdBefore(parseDate("2014-09-21")).build(), new SearchOptions()).getDocs()).hasSize(1);
    assertThat(underTest.search(IssueQuery.builder().createdBefore(parseDate("2014-09-25")).build(), new SearchOptions()).getDocs()).hasSize(2);
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) SearchOptions(org.sonar.server.es.SearchOptions) Test(org.junit.Test)

Example 23 with SearchOptions

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

the class IssueIndexTest method filter_by_create_after_and_before_take_into_account_timezone.

@Test
public void filter_by_create_after_and_before_take_into_account_timezone() {
    ComponentDto project = newProjectDto(newOrganizationDto());
    ComponentDto file = newFileDto(project, null);
    indexIssues(IssueDocTesting.newDoc("ISSUE1", file).setFuncCreationDate(parseDateTime("2014-09-20T00:00:00+0100")), IssueDocTesting.newDoc("ISSUE2", file).setFuncCreationDate(parseDateTime("2014-09-23T00:00:00+0100")));
    assertThat(underTest.search(IssueQuery.builder().createdAfter(parseDateTime("2014-09-19T23:00:00+0000")).createdBefore(parseDateTime("2014-09-22T23:00:01+0000")).build(), new SearchOptions()).getDocs()).hasSize(2);
    assertThat(underTest.search(IssueQuery.builder().createdAfter(parseDateTime("2014-09-19T23:00:01+0000")).createdBefore(parseDateTime("2014-09-22T23:00:00+0000")).build(), new SearchOptions()).getDocs()).hasSize(0);
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) SearchOptions(org.sonar.server.es.SearchOptions) Test(org.junit.Test)

Example 24 with SearchOptions

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

the class IssueIndexTest method facets_on_authors.

@Test
public void facets_on_authors() {
    ComponentDto project = newProjectDto(newOrganizationDto());
    ComponentDto file = newFileDto(project, null);
    indexIssues(IssueDocTesting.newDoc("ISSUE1", file).setAuthorLogin("steph"), IssueDocTesting.newDoc("ISSUE2", file).setAuthorLogin("simon"), IssueDocTesting.newDoc("ISSUE3", file).setAuthorLogin("simon"), IssueDocTesting.newDoc("ISSUE4", file).setAuthorLogin(null));
    SearchResult<IssueDoc> result = underTest.search(IssueQuery.builder().build(), new SearchOptions().addFacets(newArrayList("authors")));
    assertThat(result.getFacets().getNames()).containsOnly("authors");
    assertThat(result.getFacets().get("authors")).containsOnly(entry("steph", 1L), entry("simon", 2L));
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) SearchOptions(org.sonar.server.es.SearchOptions) Test(org.junit.Test)

Example 25 with SearchOptions

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

the class IssueIndexTest method filter_by_resolutions.

@Test
public void filter_by_resolutions() {
    ComponentDto project = newProjectDto(newOrganizationDto());
    ComponentDto file = newFileDto(project, null);
    indexIssues(IssueDocTesting.newDoc("ISSUE1", file).setResolution(Issue.RESOLUTION_FALSE_POSITIVE), IssueDocTesting.newDoc("ISSUE2", file).setResolution(Issue.RESOLUTION_FIXED));
    assertThat(underTest.search(IssueQuery.builder().resolutions(newArrayList(Issue.RESOLUTION_FALSE_POSITIVE, Issue.RESOLUTION_FIXED)).build(), new SearchOptions()).getDocs()).hasSize(2);
    assertThat(underTest.search(IssueQuery.builder().resolutions(newArrayList(Issue.RESOLUTION_FALSE_POSITIVE)).build(), new SearchOptions()).getDocs()).hasSize(1);
    assertThat(underTest.search(IssueQuery.builder().resolutions(newArrayList(Issue.RESOLUTION_REMOVED)).build(), new SearchOptions()).getDocs()).isEmpty();
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) SearchOptions(org.sonar.server.es.SearchOptions) 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