Search in sources :

Example 26 with SearchOptions

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

the class IssueIndexTest method authorized_issues_on_user.

@Test
public void authorized_issues_on_user() {
    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);
    UserDto user1 = newUserDto();
    UserDto user2 = newUserDto();
    // project1 can be seen by john, project2 by max, project3 cannot be seen by anyone
    indexIssue(IssueDocTesting.newDoc("ISSUE1", file1));
    authorizationIndexerTester.allowOnlyUser(project1, user1);
    indexIssue(IssueDocTesting.newDoc("ISSUE2", file2));
    authorizationIndexerTester.allowOnlyUser(project2, user2);
    indexIssue(IssueDocTesting.newDoc("ISSUE3", file3));
    userSessionRule.logIn(user1);
    assertThat(underTest.search(IssueQuery.builder().build(), new SearchOptions()).getDocs()).hasSize(1);
    assertThat(underTest.search(IssueQuery.builder().projectUuids(newArrayList(project3.key())).build(), new SearchOptions()).getDocs()).hasSize(0);
    userSessionRule.logIn(user2);
    assertThat(underTest.search(IssueQuery.builder().build(), new SearchOptions()).getDocs()).hasSize(1);
    // another user
    userSessionRule.logIn(newUserDto());
    assertThat(underTest.search(IssueQuery.builder().build(), new SearchOptions()).getDocs()).hasSize(0);
}
Also used : UserTesting.newUserDto(org.sonar.db.user.UserTesting.newUserDto) UserDto(org.sonar.db.user.UserDto) ComponentDto(org.sonar.db.component.ComponentDto) 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 27 with SearchOptions

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

the class IssueIndexTest method facets_on_directories.

@Test
public void facets_on_directories() {
    ComponentDto project = newProjectDto(newOrganizationDto());
    ComponentDto file1 = newFileDto(project, null).setPath("src/main/xoo/F1.xoo");
    ComponentDto file2 = newFileDto(project, null).setPath("F2.xoo");
    indexIssues(IssueDocTesting.newDoc("ISSUE1", file1).setDirectoryPath("/src/main/xoo"), IssueDocTesting.newDoc("ISSUE2", file2).setDirectoryPath("/"));
    SearchResult<IssueDoc> result = underTest.search(IssueQuery.builder().build(), new SearchOptions().addFacets(newArrayList("directories")));
    assertThat(result.getFacets().getNames()).containsOnly("directories");
    assertThat(result.getFacets().get("directories")).containsOnly(entry("/src/main/xoo", 1L), entry("/", 1L));
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) SearchOptions(org.sonar.server.es.SearchOptions) Test(org.junit.Test)

Example 28 with SearchOptions

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

the class IssueIndexTest method facets_on_assignees_supports_dashes.

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

Example 29 with SearchOptions

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

the class IssueIndexTest method filter_by_projects.

@Test
public void filter_by_projects() {
    ComponentDto project = newProjectDto(newOrganizationDto());
    ComponentDto module = ComponentTesting.newModuleDto(project);
    ComponentDto subModule = ComponentTesting.newModuleDto(module);
    indexIssues(IssueDocTesting.newDoc("ISSUE1", project), IssueDocTesting.newDoc("ISSUE2", newFileDto(project, null)), IssueDocTesting.newDoc("ISSUE3", module), IssueDocTesting.newDoc("ISSUE4", newFileDto(module, null)), IssueDocTesting.newDoc("ISSUE5", subModule), IssueDocTesting.newDoc("ISSUE6", newFileDto(subModule, null)));
    assertThat(underTest.search(IssueQuery.builder().projectUuids(newArrayList(project.uuid())).build(), new SearchOptions()).getDocs()).hasSize(6);
    assertThat(underTest.search(IssueQuery.builder().projectUuids(newArrayList("unknown")).build(), new SearchOptions()).getDocs()).isEmpty();
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) SearchOptions(org.sonar.server.es.SearchOptions) Test(org.junit.Test)

Example 30 with SearchOptions

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

the class IssueIndexTest method facets_on_assignees.

@Test
public void facets_on_assignees() {
    ComponentDto project = newProjectDto(newOrganizationDto());
    ComponentDto file = newFileDto(project, null);
    indexIssues(IssueDocTesting.newDoc("ISSUE1", file).setAssignee("steph"), IssueDocTesting.newDoc("ISSUE2", file).setAssignee("simon"), IssueDocTesting.newDoc("ISSUE3", file).setAssignee("simon"), IssueDocTesting.newDoc("ISSUE4", file).setAssignee(null));
    SearchResult<IssueDoc> result = underTest.search(IssueQuery.builder().build(), new SearchOptions().addFacets(newArrayList("assignees")));
    assertThat(result.getFacets().getNames()).containsOnly("assignees");
    assertThat(result.getFacets().get("assignees")).containsOnly(entry("steph", 1L), entry("simon", 2L), entry("", 1L));
}
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