Search in sources :

Example 21 with IssueIndexer

use of org.sonar.server.issue.index.IssueIndexer in project sonarqube by SonarSource.

the class SearchActionMediumTest method assigned_to_me_facet_is_sticky_relative_to_assignees.

@Test
public void assigned_to_me_facet_is_sticky_relative_to_assignees() throws Exception {
    db.userDao().insert(session, new UserDto().setLogin("alice").setName("Alice").setEmail("alice@email.com"));
    ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization2, "PROJECT_ID").setKey("PROJECT_KEY"));
    setDefaultProjectPermission(project);
    ComponentDto file = insertComponent(ComponentTesting.newFileDto(project, null, "FILE_ID").setKey("FILE_KEY"));
    RuleDto rule = newRule();
    IssueDto issue1 = IssueTesting.newDto(rule, file, project).setIssueCreationDate(DateUtils.parseDate("2014-09-04")).setIssueUpdateDate(DateUtils.parseDate("2017-12-04")).setEffort(10L).setStatus("OPEN").setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2").setSeverity("MAJOR").setAssignee("john-bob.polop");
    IssueDto issue2 = IssueTesting.newDto(rule, file, project).setIssueCreationDate(DateUtils.parseDate("2014-09-04")).setIssueUpdateDate(DateUtils.parseDate("2017-12-04")).setEffort(10L).setStatus("OPEN").setKee("7b112bd4-b650-4037-80bc-82fd47d4eac2").setSeverity("MAJOR").setAssignee("alice");
    IssueDto issue3 = IssueTesting.newDto(rule, file, project).setIssueCreationDate(DateUtils.parseDate("2014-09-04")).setIssueUpdateDate(DateUtils.parseDate("2017-12-04")).setEffort(10L).setStatus("OPEN").setKee("82fd47d4-4037-b650-80bc-7b112bd4eac2").setSeverity("MAJOR");
    db.issueDao().insert(session, issue1, issue2, issue3);
    session.commit();
    IssueIndexer r = tester.get(IssueIndexer.class);
    r.indexOnStartup(r.getIndexTypes());
    userSessionRule.logIn("john-bob.polop");
    wsTester.newGetRequest(CONTROLLER_ISSUES, ACTION_SEARCH).setParam("resolved", "false").setParam("assignees", "alice").setParam(WebService.Param.FACETS, "assignees,assigned_to_me").execute().assertJson(this.getClass(), "assigned_to_me_facet_sticky.json");
}
Also used : RuleDto(org.sonar.db.rule.RuleDto) UserDto(org.sonar.db.user.UserDto) ComponentDto(org.sonar.db.component.ComponentDto) IssueDto(org.sonar.db.issue.IssueDto) IssueIndexer(org.sonar.server.issue.index.IssueIndexer) Test(org.junit.Test)

Example 22 with IssueIndexer

use of org.sonar.server.issue.index.IssueIndexer in project sonarqube by SonarSource.

the class SearchActionMediumTest method components_contains_sub_projects.

@Test
public void components_contains_sub_projects() throws Exception {
    ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization1, "PROJECT_ID").setKey("ProjectHavingModule"));
    setDefaultProjectPermission(project);
    ComponentDto module = insertComponent(ComponentTesting.newModuleDto(project).setKey("ModuleHavingFile"));
    ComponentDto file = insertComponent(ComponentTesting.newFileDto(module, null, "BCDE").setKey("FileLinkedToModule"));
    IssueDto issue = IssueTesting.newDto(newRule(), file, project);
    db.issueDao().insert(session, issue);
    session.commit();
    IssueIndexer r = tester.get(IssueIndexer.class);
    r.indexOnStartup(r.getIndexTypes());
    WsTester.Result result = wsTester.newGetRequest(CONTROLLER_ISSUES, ACTION_SEARCH).setParam(PARAM_ADDITIONAL_FIELDS, "_all").execute();
    result.assertJson(this.getClass(), "components_contains_sub_projects.json");
}
Also used : WsTester(org.sonar.server.ws.WsTester) ComponentDto(org.sonar.db.component.ComponentDto) IssueDto(org.sonar.db.issue.IssueDto) IssueIndexer(org.sonar.server.issue.index.IssueIndexer) Test(org.junit.Test)

Example 23 with IssueIndexer

use of org.sonar.server.issue.index.IssueIndexer in project sonarqube by SonarSource.

the class ViewIndexerTest method clear_views_lookup_cache_on_index_view_uuid.

@Test
public void clear_views_lookup_cache_on_index_view_uuid() {
    IssueIndex issueIndex = new IssueIndex(esTester.client(), System2.INSTANCE, userSessionRule, new AuthorizationTypeSupport(userSessionRule));
    IssueIndexer issueIndexer = new IssueIndexer(esTester.client(), new IssueIteratorFactory(dbClient));
    String viewUuid = "ABCD";
    RuleDto rule = RuleTesting.newXooX1();
    dbClient.ruleDao().insert(dbSession, rule);
    ComponentDto project1 = addProjectWithIssue(rule, dbTester.organizations().insert());
    issueIndexer.indexOnStartup(issueIndexer.getIndexTypes());
    permissionIndexer.indexProjectsByUuids(dbSession, asList(project1.uuid()));
    OrganizationDto organizationDto = dbTester.organizations().insert();
    ComponentDto view = ComponentTesting.newView(organizationDto, "ABCD");
    ComponentDto techProject1 = ComponentTesting.newProjectCopy("CDEF", project1, view);
    dbClient.componentDao().insert(dbSession, view, techProject1);
    dbSession.commit();
    // First view indexation
    underTest.index(viewUuid);
    // Execute issue query on view -> 1 issue on view
    SearchResult<IssueDoc> docs = issueIndex.search(IssueQuery.builder().viewUuids(newArrayList(viewUuid)).build(), new SearchOptions());
    assertThat(docs.getDocs()).hasSize(1);
    // Add a project to the view and index it again
    ComponentDto project2 = addProjectWithIssue(rule, organizationDto);
    issueIndexer.indexOnStartup(issueIndexer.getIndexTypes());
    permissionIndexer.indexProjectsByUuids(dbSession, asList(project2.uuid()));
    ComponentDto techProject2 = ComponentTesting.newProjectCopy("EFGH", project2, view);
    dbClient.componentDao().insert(dbSession, techProject2);
    dbSession.commit();
    underTest.index(viewUuid);
    // Execute issue query on view -> issue of project2 are well taken into account : the cache has been cleared
    assertThat(issueIndex.search(IssueQuery.builder().viewUuids(newArrayList(viewUuid)).build(), new SearchOptions()).getDocs()).hasSize(2);
}
Also used : IssueDoc(org.sonar.server.issue.index.IssueDoc) RuleDto(org.sonar.db.rule.RuleDto) IssueIndex(org.sonar.server.issue.index.IssueIndex) ComponentDto(org.sonar.db.component.ComponentDto) IssueIteratorFactory(org.sonar.server.issue.index.IssueIteratorFactory) IssueIndexer(org.sonar.server.issue.index.IssueIndexer) SearchOptions(org.sonar.server.es.SearchOptions) AuthorizationTypeSupport(org.sonar.server.permission.index.AuthorizationTypeSupport) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Aggregations

IssueIndexer (org.sonar.server.issue.index.IssueIndexer)23 Test (org.junit.Test)21 ComponentDto (org.sonar.db.component.ComponentDto)21 IssueDto (org.sonar.db.issue.IssueDto)19 WsTester (org.sonar.server.ws.WsTester)17 RuleDto (org.sonar.db.rule.RuleDto)10 UserDto (org.sonar.db.user.UserDto)7 IssueDao (org.sonar.db.issue.IssueDao)4 IssueChangeDao (org.sonar.db.issue.IssueChangeDao)2 IssueChangeDto (org.sonar.db.issue.IssueChangeDto)2 OrganizationDto (org.sonar.db.organization.OrganizationDto)1 SearchOptions (org.sonar.server.es.SearchOptions)1 IssueDoc (org.sonar.server.issue.index.IssueDoc)1 IssueIndex (org.sonar.server.issue.index.IssueIndex)1 IssueIteratorFactory (org.sonar.server.issue.index.IssueIteratorFactory)1 AuthorizationTypeSupport (org.sonar.server.permission.index.AuthorizationTypeSupport)1