Search in sources :

Example 36 with SearchOptions

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();
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) GroupTesting.newGroupDto(org.sonar.db.user.GroupTesting.newGroupDto) GroupDto(org.sonar.db.user.GroupDto) SearchOptions(org.sonar.server.es.SearchOptions) OrganizationTesting.newOrganizationDto(org.sonar.db.organization.OrganizationTesting.newOrganizationDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 37 with SearchOptions

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);
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) SearchOptions(org.sonar.server.es.SearchOptions) Test(org.junit.Test)

Example 38 with SearchOptions

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));
}
Also used : RuleKey(org.sonar.api.rule.RuleKey) ComponentDto(org.sonar.db.component.ComponentDto) SearchOptions(org.sonar.server.es.SearchOptions) Test(org.junit.Test)

Example 39 with SearchOptions

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));
}
Also used : SearchOptions(org.sonar.server.es.SearchOptions) Test(org.junit.Test)

Example 40 with SearchOptions

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();
}
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