gt:     RuleDto rule = newRule();
context: /*
   * SonarQube, open source software quality management tool.
   * Copyright (C) 2008-2014 SonarSource
   * mailto:contact AT sonarsource DOT com
   *
   * SonarQube is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation; either
   * version 3 of the License, or (at your option) any later version.
   *
   * SonarQube is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public License
   * along with this program; if not, write to the Free Software Foundation,
   * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
   */
  
  package org.sonar.server.issue.ws;
  
  import java.util.List;
  import org.junit.After;
  import org.junit.Before;
  import org.junit.ClassRule;
  import org.junit.Rule;
  import org.junit.Test;
  import org.sonar.api.resources.Qualifiers;
  import org.sonar.api.rule.RuleStatus;
  import org.sonar.api.security.DefaultGroups;
  import org.sonar.api.server.ws.WebService;
  import org.sonar.api.utils.DateUtils;
  import org.sonar.api.web.UserRole;
  import org.sonar.core.permission.GlobalPermissions;
  import org.sonar.db.DbClient;
  import org.sonar.db.DbSession;
  import org.sonar.db.component.ComponentDto;
  import org.sonar.db.issue.IssueDto;
  import org.sonar.db.rule.RuleDto;
  import org.sonar.db.rule.RuleTesting;
  import org.sonar.db.component.ComponentTesting;
  import org.sonar.server.issue.IssueTesting;
  import org.sonar.server.issue.filter.IssueFilterParameters;
  import org.sonar.server.issue.index.IssueIndexer;
  import org.sonar.server.permission.PermissionChange;
  import org.sonar.server.permission.PermissionUpdater;
  import org.sonar.server.rule.db.RuleDao;
  import org.sonar.server.tester.ServerTester;
  import org.sonar.server.tester.UserSessionRule;
  import org.sonar.server.view.index.ViewDoc;
  import org.sonar.server.view.index.ViewIndexer;
  import org.sonar.server.ws.WsTester;
  import org.sonar.server.ws.WsTester.Result;
  
  import static com.google.common.collect.Lists.newArrayList;
  
  public class SearchActionComponentsMediumTest {
  
    @ClassRule
    public static ServerTester tester = new ServerTester().withStartupTasks().withEsIndexes();
  
    @Rule
    public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester);
  
    DbClient db;
    DbSession session;
    WsTester wsTester;
  
    @Before
    public void setUp() {
      tester.clearDbAndIndexes();
      db = tester.get(DbClient.class);
      wsTester = tester.get(WsTester.class);
      session = db.openSession(false);
    }
  
    @After
    public void after() {
      session.close();
    }
  
    @Test
    public void issues_on_different_projects() throws Exception {
      RuleDto rule = newRule();
      ComponentDto project = insertComponent(ComponentTesting.newProjectDto("P1").setKey("PK1"));
      setDefaultProjectPermission(project);
      ComponentDto file = insertComponent(ComponentTesting.newFileDto(project, "F1").setKey("FK1"));
      IssueDto issue = IssueTesting.newDto(rule, file, project)
        .setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2")
        .setStatus("OPEN").setResolution("OPEN")
        .setSeverity("MAJOR")
        .setIssueCreationDate(DateUtils.parseDateTime("2014-09-04T00:00:00+0100"))
        .setIssueUpdateDate(DateUtils.parseDateTime("2017-12-04T00:00:00+0100"));
      db.issueDao().insert(session, issue);
  
      ComponentDto project2 = insertComponent(ComponentTesting.newProjectDto("P2").setKey("PK2"));
      setDefaultProjectPermission(project2);
      ComponentDto file2 = insertComponent(ComponentTesting.newFileDto(project2, "F2").setKey("FK2"));
      IssueDto issue2 = IssueTesting.newDto(rule, file2, project2)
        .setKee("92fd47d4-b650-4037-80bc-7b112bd4eac2")
        .setStatus("OPEN").setResolution("OPEN")
        .setSeverity("MAJOR")
        .setIssueCreationDate(DateUtils.parseDateTime("2014-09-04T00:00:00+0100"))
        .setIssueUpdateDate(DateUtils.parseDateTime("2017-12-04T00:00:00+0100"));
      db.issueDao().insert(session, issue2);
      session.commit();
      tester.get(IssueIndexer.class).indexAll();
  
      WsTester.Result result = wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION).execute();
      result.assertJson(this.getClass(), "issues_on_different_projects.json");
    }
  
    @Test
    public void search_by_project_uuid() throws Exception {
      ComponentDto project = insertComponent(ComponentTesting.newProjectDto("P1").setKey("PK1"));
      setDefaultProjectPermission(project);
      ComponentDto file = insertComponent(ComponentTesting.newFileDto(project, "F1").setKey("FK1"));
      IssueDto issue = IssueTesting.newDto(newRule(), file, project).setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2");
      db.issueDao().insert(session, issue);
      session.commit();
      tester.get(IssueIndexer.class).indexAll();
  
      wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION)
        .setParam(IssueFilterParameters.PROJECT_UUIDS, project.uuid())
        .execute()
        .assertJson(this.getClass(), "search_by_project_uuid.json");
  
      wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION)
        .setParam(IssueFilterParameters.PROJECT_UUIDS, "unknown")
        .execute()
        .assertJson(this.getClass(), "no_issue.json");
  
      wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION)
        .setParam(IssueFilterParameters.COMPONENT_UUIDS, project.uuid())
        .execute()
        .assertJson(this.getClass(), "search_by_project_uuid.json");
  
      wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION)
        .setParam(IssueFilterParameters.COMPONENT_UUIDS, "unknown")
        .execute()
        .assertJson(this.getClass(), "no_issue.json");
    }
  
    @Test
    public void project_facet_is_sticky() throws Exception {
      ComponentDto project1 = insertComponent(ComponentTesting.newProjectDto("P1").setKey("PK1"));
      ComponentDto project2 = insertComponent(ComponentTesting.newProjectDto("P2").setKey("PK2"));
      ComponentDto project3 = insertComponent(ComponentTesting.newProjectDto("P3").setKey("PK3"));
      setDefaultProjectPermission(project1);
      setDefaultProjectPermission(project2);
      setDefaultProjectPermission(project3);
      ComponentDto file1 = insertComponent(ComponentTesting.newFileDto(project1, "F1").setKey("FK1"));
      ComponentDto file2 = insertComponent(ComponentTesting.newFileDto(project2, "F2").setKey("FK2"));
      ComponentDto file3 = insertComponent(ComponentTesting.newFileDto(project3, "F3").setKey("FK3"));
      RuleDto rule = newRule();
      IssueDto issue1 = IssueTesting.newDto(rule, file1, project1).setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2");
      IssueDto issue2 = IssueTesting.newDto(rule, file2, project2).setKee("2bd4eac2-b650-4037-80bc-7b1182fd47d4");
      IssueDto issue3 = IssueTesting.newDto(rule, file3, project3).setKee("7b1182fd-b650-4037-80bc-82fd47d4eac2");
      db.issueDao().insert(session, issue1, issue2, issue3);
      session.commit();
      tester.get(IssueIndexer.class).indexAll();
  
      wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION)
        .setParam(IssueFilterParameters.PROJECT_UUIDS, project1.uuid())
        .setParam(WebService.Param.FACETS, "projectUuids")
        .execute()
        .assertJson(this.getClass(), "display_sticky_project_facet.json");
    }
  
    @Test
    public void search_by_file_uuid() throws Exception {
      ComponentDto project = insertComponent(ComponentTesting.newProjectDto("P1").setKey("PK1"));
      setDefaultProjectPermission(project);
      ComponentDto file = insertComponent(ComponentTesting.newFileDto(project, "F1").setKey("FK1"));
      IssueDto issue = IssueTesting.newDto(newRule(), file, project).setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2");
      db.issueDao().insert(session, issue);
      session.commit();
      tester.get(IssueIndexer.class).indexAll();
  
      wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION)
        .setParam(IssueFilterParameters.FILE_UUIDS, file.uuid())
        .execute()
        .assertJson(this.getClass(), "search_by_file_uuid.json");
  
      wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION)
        .setParam(IssueFilterParameters.FILE_UUIDS, "unknown")
        .execute()
        .assertJson(this.getClass(), "no_issue.json");
  
      wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION)
        .setParam(IssueFilterParameters.COMPONENT_UUIDS, file.uuid())
        .execute()
        .assertJson(this.getClass(), "search_by_file_uuid.json");
  
      wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION)
        .setParam(IssueFilterParameters.COMPONENT_UUIDS, "unknown")
        .execute()
        .assertJson(this.getClass(), "no_issue.json");
    }
  
    @Test
    public void search_by_file_key() throws Exception {
      ComponentDto project = insertComponent(ComponentTesting.newProjectDto("P1").setKey("PK1"));
      setDefaultProjectPermission(project);
      ComponentDto file = insertComponent(ComponentTesting.newFileDto(project, "F1").setKey("FK1"));
      ComponentDto unitTest = insertComponent(ComponentTesting.newFileDto(project, "F2").setQualifier(Qualifiers.UNIT_TEST_FILE).setKey("FK2"));
  