Search in sources :

Example 86 with SearchOptions

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

the class IssueIndexTest method search_with_max_limit.

@Test
public void search_with_max_limit() {
    ComponentDto project = newProjectDto(newOrganizationDto());
    ComponentDto file = newFileDto(project, null);
    List<IssueDoc> issues = newArrayList();
    for (int i = 0; i < 500; i++) {
        String key = "ISSUE" + i;
        issues.add(IssueDocTesting.newDoc(key, file));
    }
    indexIssues(issues.toArray(new IssueDoc[] {}));
    IssueQuery.Builder query = IssueQuery.builder();
    SearchResult<IssueDoc> result = underTest.search(query.build(), new SearchOptions().setLimit(Integer.MAX_VALUE));
    assertThat(result.getDocs()).hasSize(SearchOptions.MAX_LIMIT);
}
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 87 with SearchOptions

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

the class IssueIndexTest method filter_by_created_at.

@Test
public void filter_by_created_at() {
    ComponentDto project = newProjectDto(newOrganizationDto());
    ComponentDto file = newFileDto(project, null);
    indexIssues(IssueDocTesting.newDoc("ISSUE1", file).setFuncCreationDate(parseDate("2014-09-20")));
    assertThat(underTest.search(IssueQuery.builder().createdAt(parseDate("2014-09-20")).build(), new SearchOptions()).getDocs()).hasSize(1);
    assertThat(underTest.search(IssueQuery.builder().createdAt(parseDate("2014-09-21")).build(), new SearchOptions()).getDocs()).isEmpty();
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) SearchOptions(org.sonar.server.es.SearchOptions) Test(org.junit.Test)

Example 88 with SearchOptions

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

the class IssueIndexTest method filter_by_created_after_must_not_be_in_future.

@Test
public void filter_by_created_after_must_not_be_in_future() {
    try {
        underTest.search(IssueQuery.builder().createdAfter(new Date(Long.MAX_VALUE)).build(), new SearchOptions());
        Fail.failBecauseExceptionWasNotThrown(IllegalArgumentException.class);
    } catch (IllegalArgumentException exception) {
        assertThat(exception.getMessage()).isEqualTo("Start bound cannot be in the future");
    }
}
Also used : SearchOptions(org.sonar.server.es.SearchOptions) Date(java.util.Date) DateUtils.parseDate(org.sonar.api.utils.DateUtils.parseDate) Test(org.junit.Test)

Example 89 with SearchOptions

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

the class IssueIndexTest method fixtureForCreatedAtFacet.

private SearchOptions fixtureForCreatedAtFacet() {
    ComponentDto project = newProjectDto(newOrganizationDto());
    ComponentDto file = newFileDto(project, null);
    IssueDoc issue0 = IssueDocTesting.newDoc("ISSUE0", file).setFuncCreationDate(parseDateTime("2011-04-25T00:05:13+0000"));
    IssueDoc issue1 = IssueDocTesting.newDoc("ISSUE1", file).setFuncCreationDate(parseDateTime("2014-09-01T12:34:56+0100"));
    IssueDoc issue2 = IssueDocTesting.newDoc("ISSUE2", file).setFuncCreationDate(parseDateTime("2014-09-01T10:46:00-1200"));
    IssueDoc issue3 = IssueDocTesting.newDoc("ISSUE3", file).setFuncCreationDate(parseDateTime("2014-09-02T23:34:56+1200"));
    IssueDoc issue4 = IssueDocTesting.newDoc("ISSUE4", file).setFuncCreationDate(parseDateTime("2014-09-05T12:34:56+0100"));
    IssueDoc issue5 = IssueDocTesting.newDoc("ISSUE5", file).setFuncCreationDate(parseDateTime("2014-09-20T12:34:56+0100"));
    IssueDoc issue6 = IssueDocTesting.newDoc("ISSUE6", file).setFuncCreationDate(parseDateTime("2015-01-18T12:34:56+0100"));
    indexIssues(issue0, issue1, issue2, issue3, issue4, issue5, issue6);
    return new SearchOptions().addFacets("createdAt");
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) SearchOptions(org.sonar.server.es.SearchOptions)

Example 90 with SearchOptions

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

the class IssueIndexTest method filter_by_statuses.

@Test
public void filter_by_statuses() {
    ComponentDto project = newProjectDto(newOrganizationDto());
    ComponentDto file = newFileDto(project, null);
    indexIssues(IssueDocTesting.newDoc("ISSUE1", file).setStatus(Issue.STATUS_CLOSED), IssueDocTesting.newDoc("ISSUE2", file).setStatus(Issue.STATUS_OPEN));
    assertThat(underTest.search(IssueQuery.builder().statuses(newArrayList(Issue.STATUS_CLOSED, Issue.STATUS_OPEN)).build(), new SearchOptions()).getDocs()).hasSize(2);
    assertThat(underTest.search(IssueQuery.builder().statuses(newArrayList(Issue.STATUS_CLOSED)).build(), new SearchOptions()).getDocs()).hasSize(1);
    assertThat(underTest.search(IssueQuery.builder().statuses(newArrayList(Issue.STATUS_CONFIRMED)).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