use of org.sonar.server.es.SearchOptions in project sonarqube by SonarSource.
the class IssueIndexTest method filter_by_languages.
@Test
public void filter_by_languages() {
ComponentDto project = newProjectDto(newOrganizationDto());
ComponentDto file = newFileDto(project, null);
RuleKey ruleKey = RuleKey.of("repo", "X1");
indexIssues(IssueDocTesting.newDoc("ISSUE1", file).setRuleKey(ruleKey.toString()).setLanguage("xoo"));
assertThat(underTest.search(IssueQuery.builder().languages(newArrayList("xoo")).build(), new SearchOptions()).getDocs()).hasSize(1);
assertThat(underTest.search(IssueQuery.builder().languages(newArrayList("unknown")).build(), new SearchOptions()).getDocs()).isEmpty();
}
use of org.sonar.server.es.SearchOptions in project sonarqube by SonarSource.
the class IssueIndexTest method default_sort_is_by_creation_date_then_project_then_file_then_line_then_issue_key.
@Test
public void default_sort_is_by_creation_date_then_project_then_file_then_line_then_issue_key() {
OrganizationDto organizationDto = newOrganizationDto();
ComponentDto project1 = newProjectDto(organizationDto, "P1");
ComponentDto file1 = newFileDto(project1, null, "F1").setPath("src/main/xoo/org/sonar/samples/File.xoo");
ComponentDto file2 = newFileDto(project1, null, "F2").setPath("src/main/xoo/org/sonar/samples/File2.xoo");
ComponentDto project2 = newProjectDto(organizationDto, "P2");
ComponentDto file3 = newFileDto(project2, null, "F3").setPath("src/main/xoo/org/sonar/samples/File3.xoo");
indexIssues(// file F1 from project P1
IssueDocTesting.newDoc("F1_1", file1).setLine(20).setFuncCreationDate(parseDateTime("2014-09-23T00:00:00+0100")), IssueDocTesting.newDoc("F1_2", file1).setLine(null).setFuncCreationDate(parseDateTime("2014-09-23T00:00:00+0100")), IssueDocTesting.newDoc("F1_3", file1).setLine(25).setFuncCreationDate(parseDateTime("2014-09-23T00:00:00+0100")), // file F2 from project P1
IssueDocTesting.newDoc("F2_1", file2).setLine(9).setFuncCreationDate(parseDateTime("2014-09-23T00:00:00+0100")), IssueDocTesting.newDoc("F2_2", file2).setLine(109).setFuncCreationDate(parseDateTime("2014-09-23T00:00:00+0100")), // two issues on the same line -> sort by key
IssueDocTesting.newDoc("F2_3", file2).setLine(109).setFuncCreationDate(parseDateTime("2014-09-23T00:00:00+0100")), // file F3 from project P2
IssueDocTesting.newDoc("F3_1", file3).setLine(20).setFuncCreationDate(parseDateTime("2014-09-24T00:00:00+0100")), IssueDocTesting.newDoc("F3_2", file3).setLine(20).setFuncCreationDate(parseDateTime("2014-09-23T00:00:00+0100")));
assertThat(underTest.search(IssueQuery.builder().build(), new SearchOptions()).getDocs()).extracting(IssueDoc::key).containsExactly("F3_1", "F1_2", "F1_1", "F1_3", "F2_1", "F2_2", "F2_3", "F3_2");
}
use of org.sonar.server.es.SearchOptions in project sonarqube by SonarSource.
the class IssueIndexTest method facet_on_created_at_with_less_than_20_months.
@Test
public void facet_on_created_at_with_less_than_20_months() {
SearchOptions SearchOptions = fixtureForCreatedAtFacet();
Map<String, Long> createdAt = underTest.search(IssueQuery.builder().createdAfter(parseDateTime("2014-09-01T00:00:00+0100")).createdBefore(parseDateTime("2015-01-19T00:00:00+0100")).build(), SearchOptions).getFacets().get("createdAt");
assertThat(createdAt).containsOnly(entry("2014-08-01T01:00:00+0000", 0L), entry("2014-09-01T01:00:00+0000", 5L), entry("2014-10-01T01:00:00+0000", 0L), entry("2014-11-01T01:00:00+0000", 0L), entry("2014-12-01T01:00:00+0000", 0L), entry("2015-01-01T01:00:00+0000", 1L));
}
use of org.sonar.server.es.SearchOptions in project sonarqube by SonarSource.
the class IssueIndexTest method filter_by_authors.
@Test
public void filter_by_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).setAssignee(null));
assertThat(underTest.search(IssueQuery.builder().authors(newArrayList("steph")).build(), new SearchOptions()).getDocs()).hasSize(1);
assertThat(underTest.search(IssueQuery.builder().authors(newArrayList("steph", "simon")).build(), new SearchOptions()).getDocs()).hasSize(2);
assertThat(underTest.search(IssueQuery.builder().authors(newArrayList("unknown")).build(), new SearchOptions()).getDocs()).isEmpty();
}
use of org.sonar.server.es.SearchOptions in project sonarqube by SonarSource.
the class IssueIndexTest method sort_by_file_and_line.
@Test
public void sort_by_file_and_line() {
ComponentDto project = newProjectDto(newOrganizationDto());
ComponentDto file1 = newFileDto(project, null, "F1").setPath("src/main/xoo/org/sonar/samples/File.xoo");
ComponentDto file2 = newFileDto(project, null, "F2").setPath("src/main/xoo/org/sonar/samples/File2.xoo");
indexIssues(// file F1
IssueDocTesting.newDoc("F1_2", file1).setLine(20), IssueDocTesting.newDoc("F1_1", file1).setLine(null), IssueDocTesting.newDoc("F1_3", file1).setLine(25), // file F2
IssueDocTesting.newDoc("F2_1", file2).setLine(9), IssueDocTesting.newDoc("F2_2", file2).setLine(109), // two issues on the same line -> sort by key
IssueDocTesting.newDoc("F2_3", file2).setLine(109));
// ascending sort -> F1 then F2. Line "0" first.
IssueQuery.Builder query = IssueQuery.builder().sort(IssueQuery.SORT_BY_FILE_LINE).asc(true);
SearchResult<IssueDoc> result = underTest.search(query.build(), new SearchOptions());
assertThat(result.getDocs()).hasSize(6);
assertThat(result.getDocs().get(0).key()).isEqualTo("F1_1");
assertThat(result.getDocs().get(1).key()).isEqualTo("F1_2");
assertThat(result.getDocs().get(2).key()).isEqualTo("F1_3");
assertThat(result.getDocs().get(3).key()).isEqualTo("F2_1");
assertThat(result.getDocs().get(4).key()).isEqualTo("F2_2");
assertThat(result.getDocs().get(5).key()).isEqualTo("F2_3");
// descending sort -> F2 then F1
query = IssueQuery.builder().sort(IssueQuery.SORT_BY_FILE_LINE).asc(false);
result = underTest.search(query.build(), new SearchOptions());
assertThat(result.getDocs()).hasSize(6);
assertThat(result.getDocs().get(0).key()).isEqualTo("F2_3");
assertThat(result.getDocs().get(1).key()).isEqualTo("F2_2");
assertThat(result.getDocs().get(2).key()).isEqualTo("F2_1");
assertThat(result.getDocs().get(3).key()).isEqualTo("F1_3");
assertThat(result.getDocs().get(4).key()).isEqualTo("F1_2");
assertThat(result.getDocs().get(5).key()).isEqualTo("F1_1");
}
Aggregations