use of org.sonar.server.es.SearchOptions in project sonarqube by SonarSource.
the class IssueIndexTest method authorized_issues_on_groups.
@Test
public void authorized_issues_on_groups() {
OrganizationDto org = newOrganizationDto();
ComponentDto project1 = newProjectDto(org);
ComponentDto project2 = newProjectDto(org);
ComponentDto project3 = newProjectDto(org);
ComponentDto file1 = newFileDto(project1, null);
ComponentDto file2 = newFileDto(project2, null);
ComponentDto file3 = newFileDto(project3, null);
GroupDto group1 = newGroupDto();
GroupDto group2 = newGroupDto();
// project1 can be seen by group1
indexIssue(IssueDocTesting.newDoc("ISSUE1", file1));
authorizationIndexerTester.allowOnlyGroup(project1, group1);
// project2 can be seen by group2
indexIssue(IssueDocTesting.newDoc("ISSUE2", file2));
authorizationIndexerTester.allowOnlyGroup(project2, group2);
// project3 can be seen by nobody
indexIssue(IssueDocTesting.newDoc("ISSUE3", file3));
userSessionRule.logIn().setGroups(group1);
assertThat(underTest.search(IssueQuery.builder().build(), new SearchOptions()).getDocs()).hasSize(1);
userSessionRule.logIn().setGroups(group2);
assertThat(underTest.search(IssueQuery.builder().build(), new SearchOptions()).getDocs()).hasSize(1);
userSessionRule.logIn().setGroups(group1, group2);
assertThat(underTest.search(IssueQuery.builder().build(), new SearchOptions()).getDocs()).hasSize(2);
GroupDto otherGroup = newGroupDto();
userSessionRule.logIn().setGroups(otherGroup);
assertThat(underTest.search(IssueQuery.builder().build(), new SearchOptions()).getDocs()).isEmpty();
userSessionRule.logIn().setGroups(group1, group2);
assertThat(underTest.search(IssueQuery.builder().projectUuids(newArrayList(project3.uuid())).build(), new SearchOptions()).getDocs()).isEmpty();
}
use of org.sonar.server.es.SearchOptions in project sonarqube by SonarSource.
the class IssueIndexTest method filter_by_components_on_non_contextualized_search.
@Test
public void filter_by_components_on_non_contextualized_search() {
ComponentDto project = newProjectDto(newOrganizationDto(), "project");
ComponentDto file1 = newFileDto(project, null, "file1");
ComponentDto module = ComponentTesting.newModuleDto(project).setUuid("module");
ComponentDto file2 = newFileDto(module, null, "file2");
ComponentDto subModule = ComponentTesting.newModuleDto(module).setUuid("subModule");
ComponentDto file3 = newFileDto(subModule, null, "file3");
String view = "ABCD";
indexView(view, newArrayList(project.uuid()));
indexIssues(IssueDocTesting.newDoc("ISSUE1", project), IssueDocTesting.newDoc("ISSUE2", file1), IssueDocTesting.newDoc("ISSUE3", module), IssueDocTesting.newDoc("ISSUE4", file2), IssueDocTesting.newDoc("ISSUE5", subModule), IssueDocTesting.newDoc("ISSUE6", file3));
assertThat(underTest.search(IssueQuery.builder().projectUuids(newArrayList("unknown")).build(), new SearchOptions()).getDocs()).isEmpty();
assertThat(underTest.search(IssueQuery.builder().projectUuids(newArrayList(project.uuid())).build(), new SearchOptions()).getDocs()).hasSize(6);
assertThat(underTest.search(IssueQuery.builder().viewUuids(newArrayList(view)).build(), new SearchOptions()).getDocs()).hasSize(6);
assertThat(underTest.search(IssueQuery.builder().moduleUuids(newArrayList(module.uuid())).build(), new SearchOptions()).getDocs()).hasSize(2);
// XXX
assertThat(underTest.search(IssueQuery.builder().moduleUuids(newArrayList(subModule.uuid())).build(), new SearchOptions()).getDocs()).hasSize(2);
// Misleading
// !
assertThat(underTest.search(IssueQuery.builder().fileUuids(newArrayList(file1.uuid())).build(), new SearchOptions()).getDocs()).hasSize(1);
assertThat(underTest.search(IssueQuery.builder().fileUuids(newArrayList(file1.uuid(), file2.uuid(), file3.uuid())).build(), new SearchOptions()).getDocs()).hasSize(3);
}
use of org.sonar.server.es.SearchOptions in project sonarqube by SonarSource.
the class IssueIndexTest method facets_on_languages.
@Test
public void facets_on_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"));
SearchResult<IssueDoc> result = underTest.search(IssueQuery.builder().build(), new SearchOptions().addFacets(newArrayList("languages")));
assertThat(result.getFacets().getNames()).containsOnly("languages");
assertThat(result.getFacets().get("languages")).containsOnly(entry("xoo", 1L));
}
use of org.sonar.server.es.SearchOptions in project sonarqube by SonarSource.
the class IssueIndexTest method facet_on_created_at_without_start_bound.
@Test
public void facet_on_created_at_without_start_bound() {
SearchOptions SearchOptions = fixtureForCreatedAtFacet();
Map<String, Long> createdAt = underTest.search(IssueQuery.builder().createdBefore(parseDateTime("2016-01-01T00:00:00+0100")).build(), SearchOptions).getFacets().get("createdAt");
assertThat(createdAt).containsOnly(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));
}
use of org.sonar.server.es.SearchOptions in project sonarqube by SonarSource.
the class IssueIndexTest method filter_by_keys.
@Test
public void filter_by_keys() {
ComponentDto project = newProjectDto(newOrganizationDto());
indexIssues(IssueDocTesting.newDoc("1", newFileDto(project, null)), IssueDocTesting.newDoc("2", newFileDto(project, null)));
assertThat(underTest.search(IssueQuery.builder().issueKeys(newArrayList("1", "2")).build(), new SearchOptions()).getDocs()).hasSize(2);
assertThat(underTest.search(IssueQuery.builder().issueKeys(newArrayList("1")).build(), new SearchOptions()).getDocs()).hasSize(1);
assertThat(underTest.search(IssueQuery.builder().issueKeys(newArrayList("3", "4")).build(), new SearchOptions()).getDocs()).isEmpty();
}
Aggregations