You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SearchActionComponentsTest.java 41KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2019 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. package org.sonar.server.issue.ws;
  21. import java.time.Clock;
  22. import java.util.Arrays;
  23. import java.util.Date;
  24. import org.junit.Rule;
  25. import org.junit.Test;
  26. import org.junit.rules.ExpectedException;
  27. import org.sonar.api.config.internal.MapSettings;
  28. import org.sonar.api.resources.Languages;
  29. import org.sonar.api.resources.Qualifiers;
  30. import org.sonar.api.rule.RuleKey;
  31. import org.sonar.api.utils.Durations;
  32. import org.sonar.api.utils.System2;
  33. import org.sonar.db.DbClient;
  34. import org.sonar.db.DbTester;
  35. import org.sonar.db.component.ComponentDto;
  36. import org.sonar.db.issue.IssueDto;
  37. import org.sonar.db.organization.OrganizationDto;
  38. import org.sonar.db.rule.RuleDefinitionDto;
  39. import org.sonar.server.es.EsTester;
  40. import org.sonar.server.issue.IssueFieldsSetter;
  41. import org.sonar.server.issue.TransitionService;
  42. import org.sonar.server.issue.index.IssueIndex;
  43. import org.sonar.server.issue.index.IssueIndexer;
  44. import org.sonar.server.issue.index.IssueIteratorFactory;
  45. import org.sonar.server.issue.index.IssueQueryFactory;
  46. import org.sonar.server.issue.workflow.FunctionExecutor;
  47. import org.sonar.server.issue.workflow.IssueWorkflow;
  48. import org.sonar.server.permission.index.PermissionIndexerTester;
  49. import org.sonar.server.permission.index.WebAuthorizationTypeSupport;
  50. import org.sonar.server.tester.UserSessionRule;
  51. import org.sonar.server.view.index.ViewIndexer;
  52. import org.sonar.server.ws.WsActionTester;
  53. import org.sonar.server.ws.WsResponseCommonFormat;
  54. import org.sonarqube.ws.Issues;
  55. import org.sonarqube.ws.Issues.Component;
  56. import org.sonarqube.ws.Issues.Issue;
  57. import org.sonarqube.ws.Issues.SearchWsResponse;
  58. import static org.assertj.core.api.Assertions.assertThat;
  59. import static org.assertj.core.api.Assertions.tuple;
  60. import static org.sonar.api.resources.Qualifiers.APP;
  61. import static org.sonar.api.utils.DateUtils.addDays;
  62. import static org.sonar.api.utils.DateUtils.parseDateTime;
  63. import static org.sonar.api.web.UserRole.USER;
  64. import static org.sonar.core.util.Uuids.UUID_EXAMPLE_01;
  65. import static org.sonar.core.util.Uuids.UUID_EXAMPLE_02;
  66. import static org.sonar.db.component.BranchType.PULL_REQUEST;
  67. import static org.sonar.db.component.BranchType.SHORT;
  68. import static org.sonar.db.component.ComponentTesting.newDirectory;
  69. import static org.sonar.db.component.ComponentTesting.newFileDto;
  70. import static org.sonar.db.component.ComponentTesting.newModuleDto;
  71. import static org.sonar.db.component.ComponentTesting.newProjectCopy;
  72. import static org.sonar.db.component.ComponentTesting.newSubView;
  73. import static org.sonar.db.component.ComponentTesting.newView;
  74. import static org.sonar.db.issue.IssueTesting.newIssue;
  75. import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_BRANCH;
  76. import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENTS;
  77. import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENT_KEYS;
  78. import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENT_UUIDS;
  79. import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_DIRECTORIES;
  80. import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_FILE_UUIDS;
  81. import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_MODULE_UUIDS;
  82. import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_PROJECTS;
  83. import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_PROJECT_KEYS;
  84. import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_PULL_REQUEST;
  85. import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_SINCE_LEAK_PERIOD;
  86. public class SearchActionComponentsTest {
  87. @Rule
  88. public ExpectedException expectedException = ExpectedException.none();
  89. @Rule
  90. public UserSessionRule userSession = UserSessionRule.standalone();
  91. @Rule
  92. public DbTester db = DbTester.create();
  93. @Rule
  94. public EsTester es = EsTester.create();
  95. private DbClient dbClient = db.getDbClient();
  96. private IssueIndex issueIndex = new IssueIndex(es.client(), System2.INSTANCE, userSession, new WebAuthorizationTypeSupport(userSession));
  97. private IssueIndexer issueIndexer = new IssueIndexer(es.client(), dbClient, new IssueIteratorFactory(dbClient));
  98. private ViewIndexer viewIndexer = new ViewIndexer(dbClient, es.client());
  99. private IssueQueryFactory issueQueryFactory = new IssueQueryFactory(dbClient, Clock.systemUTC(), userSession);
  100. private IssueFieldsSetter issueFieldsSetter = new IssueFieldsSetter();
  101. private IssueWorkflow issueWorkflow = new IssueWorkflow(new FunctionExecutor(issueFieldsSetter), issueFieldsSetter);
  102. private SearchResponseLoader searchResponseLoader = new SearchResponseLoader(userSession, dbClient, new TransitionService(userSession, issueWorkflow));
  103. private Languages languages = new Languages();
  104. private SearchResponseFormat searchResponseFormat = new SearchResponseFormat(new Durations(), new WsResponseCommonFormat(languages), languages, new AvatarResolverImpl());
  105. private PermissionIndexerTester permissionIndexer = new PermissionIndexerTester(es, issueIndexer);
  106. private WsActionTester ws = new WsActionTester(new SearchAction(userSession, issueIndex, issueQueryFactory, searchResponseLoader, searchResponseFormat,
  107. new MapSettings().asConfig(), System2.INSTANCE, dbClient));
  108. @Test
  109. public void search_all_issues_when_no_parameter() {
  110. RuleDefinitionDto rule = db.rules().insert();
  111. ComponentDto project = db.components().insertPublicProject();
  112. ComponentDto projectFile = db.components().insertComponent(newFileDto(project));
  113. IssueDto issue = db.issues().insertIssue(newIssue(rule, project, projectFile));
  114. allowAnyoneOnProjects(project);
  115. indexIssues();
  116. SearchWsResponse result = ws.newRequest().executeProtobuf(SearchWsResponse.class);
  117. assertThat(result.getIssuesList()).extracting(Issues.Issue::getKey)
  118. .containsExactlyInAnyOrder(issue.getKey());
  119. }
  120. @Test
  121. public void issues_on_different_projects() {
  122. RuleDefinitionDto rule = db.rules().insert(r -> r.setRuleKey(RuleKey.of("xoo", "x1")));
  123. OrganizationDto organization1 = db.organizations().insert();
  124. ComponentDto project = db.components().insertPublicProject(organization1);
  125. ComponentDto file = db.components().insertComponent(newFileDto(project));
  126. IssueDto issue1 = db.issues().insert(rule, project, file);
  127. OrganizationDto organization2 = db.organizations().insert();
  128. ComponentDto project2 = db.components().insertPublicProject(organization2);
  129. ComponentDto file2 = db.components().insertComponent(newFileDto(project2));
  130. IssueDto issue2 = db.issues().insert(rule, project2, file2);
  131. allowAnyoneOnProjects(project, project2);
  132. indexIssues();
  133. SearchWsResponse response = ws.newRequest().executeProtobuf(SearchWsResponse.class);
  134. assertThat(response.getIssuesList())
  135. .extracting(Issue::getKey, Issue::getComponent, Issue::getProject)
  136. .containsExactlyInAnyOrder(
  137. tuple(issue1.getKey(), file.getKey(), project.getKey()),
  138. tuple(issue2.getKey(), file2.getKey(), project2.getKey()));
  139. assertThat(response.getComponentsList())
  140. .extracting(Component::getKey, Component::getEnabled)
  141. .containsExactlyInAnyOrder(tuple(project.getKey(), true), tuple(file.getKey(), true), tuple(project2.getKey(), true), tuple(file2.getKey(), true));
  142. }
  143. @Test
  144. public void search_by_module() {
  145. ComponentDto project = db.components().insertPublicProject();
  146. ComponentDto module1 = db.components().insertComponent(newModuleDto(project));
  147. ComponentDto file1 = db.components().insertComponent(newFileDto(module1));
  148. ComponentDto module2 = db.components().insertComponent(newModuleDto(project));
  149. ComponentDto file2 = db.components().insertComponent(newFileDto(module2));
  150. RuleDefinitionDto rule = db.rules().insert();
  151. IssueDto issue1 = db.issues().insert(rule, project, file1);
  152. IssueDto issue2 = db.issues().insert(rule, project, file2);
  153. allowAnyoneOnProjects(project);
  154. indexIssues();
  155. assertThat(ws.newRequest()
  156. .setParam(PARAM_COMPONENT_KEYS, module1.getKey())
  157. .executeProtobuf(SearchWsResponse.class).getIssuesList()).extracting(Issue::getKey)
  158. .containsExactlyInAnyOrder(issue1.getKey());
  159. assertThat(ws.newRequest()
  160. .setParam(PARAM_MODULE_UUIDS, module1.uuid())
  161. .executeProtobuf(SearchWsResponse.class).getIssuesList()).extracting(Issue::getKey)
  162. .containsExactlyInAnyOrder(issue1.getKey());
  163. }
  164. @Test
  165. public void do_not_return_module_key_on_single_module_projects() {
  166. ComponentDto project = db.components().insertPublicProject(p -> p.setDbKey("PK1"));
  167. ComponentDto module = db.components().insertComponent(newModuleDto("M1", project).setDbKey("MK1"));
  168. ComponentDto file = db.components().insertComponent(newFileDto(module, null, "F1").setDbKey("FK1"));
  169. RuleDefinitionDto rule = db.rules().insert(r -> r.setRuleKey(RuleKey.of("xoo", "x1")));
  170. db.issues().insert(rule, project, file, i -> i.setKee("ISSUE_IN_MODULE"));
  171. db.issues().insert(rule, project, project, i -> i.setKee("ISSUE_IN_ROOT_MODULE"));
  172. allowAnyoneOnProjects(project);
  173. indexIssues();
  174. SearchWsResponse searchResponse = ws.newRequest().executeProtobuf(SearchWsResponse.class);
  175. assertThat(searchResponse.getIssuesCount()).isEqualTo(2);
  176. for (Issue issue : searchResponse.getIssuesList()) {
  177. assertThat(issue.getProject()).isEqualTo("PK1");
  178. if (issue.getKey().equals("ISSUE_IN_MODULE")) {
  179. assertThat(issue.getSubProject()).isEqualTo("MK1");
  180. } else if (issue.getKey().equals("ISSUE_IN_ROOT_MODULE")) {
  181. assertThat(issue.hasSubProject()).isFalse();
  182. }
  183. }
  184. }
  185. @Test
  186. public void search_since_leak_period_on_project() {
  187. ComponentDto project = db.components().insertPublicProject(p -> p.setDbKey("PK1"));
  188. ComponentDto file = db.components().insertComponent(newFileDto(project, null, "F1").setDbKey("FK1"));
  189. db.components().insertSnapshot(project, a -> a.setPeriodDate(parseDateTime("2015-09-03T00:00:00+0100").getTime()));
  190. RuleDefinitionDto rule = db.rules().insert(r -> r.setRuleKey(RuleKey.of("xoo", "x1")));
  191. IssueDto issueAfterLeak = db.issues().insert(rule, project, file, i -> i.setKee(UUID_EXAMPLE_01)
  192. .setIssueCreationDate(parseDateTime("2015-09-04T00:00:00+0100"))
  193. .setIssueUpdateDate(parseDateTime("2015-10-04T00:00:00+0100")));
  194. IssueDto issueBeforeLeak = db.issues().insert(rule, project, file, i -> i.setKee(UUID_EXAMPLE_02)
  195. .setIssueCreationDate(parseDateTime("2014-09-04T00:00:00+0100"))
  196. .setIssueUpdateDate(parseDateTime("2015-10-04T00:00:00+0100")));
  197. allowAnyoneOnProjects(project);
  198. indexIssues();
  199. ws.newRequest()
  200. .setParam(PARAM_COMPONENT_UUIDS, project.uuid())
  201. .setParam(PARAM_SINCE_LEAK_PERIOD, "true")
  202. .execute()
  203. .assertJson(this.getClass(), "search_since_leak_period.json");
  204. }
  205. @Test
  206. public void search_since_leak_period_on_file_in_module_project() {
  207. ComponentDto project = db.components().insertPublicProject(p -> p.setDbKey("PK1"));
  208. ComponentDto module = db.components().insertComponent(newModuleDto(project));
  209. ComponentDto file = db.components().insertComponent(newFileDto(module, null, "F1").setDbKey("FK1"));
  210. db.components().insertSnapshot(project, a -> a.setPeriodDate(parseDateTime("2015-09-03T00:00:00+0100").getTime()));
  211. RuleDefinitionDto rule = db.rules().insert(r -> r.setRuleKey(RuleKey.of("xoo", "x1")));
  212. IssueDto issueAfterLeak = db.issues().insert(rule, project, file, i -> i.setKee(UUID_EXAMPLE_01)
  213. .setIssueCreationDate(parseDateTime("2015-09-04T00:00:00+0100"))
  214. .setIssueUpdateDate(parseDateTime("2015-10-04T00:00:00+0100")));
  215. IssueDto issueBeforeLeak = db.issues().insert(rule, project, file, i -> i.setKee(UUID_EXAMPLE_02)
  216. .setIssueCreationDate(parseDateTime("2014-09-04T00:00:00+0100"))
  217. .setIssueUpdateDate(parseDateTime("2015-10-04T00:00:00+0100")));
  218. allowAnyoneOnProjects(project);
  219. indexIssues();
  220. ws.newRequest()
  221. .setParam(PARAM_COMPONENT_UUIDS, project.uuid())
  222. .setParam(PARAM_FILE_UUIDS, file.uuid())
  223. .setParam(PARAM_SINCE_LEAK_PERIOD, "true")
  224. .execute()
  225. .assertJson(this.getClass(), "search_since_leak_period.json");
  226. }
  227. @Test
  228. public void search_by_file_uuid() {
  229. ComponentDto project = db.components().insertPublicProject(p -> p.setDbKey("PK1"));
  230. ComponentDto file = db.components().insertComponent(newFileDto(project, null, "F1").setDbKey("FK1"));
  231. RuleDefinitionDto rule = db.rules().insert(r -> r.setRuleKey(RuleKey.of("xoo", "x1")));
  232. IssueDto issue = db.issues().insert(rule, project, file, i -> i.setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2"));
  233. allowAnyoneOnProjects(project);
  234. indexIssues();
  235. ws.newRequest()
  236. .setParam(PARAM_FILE_UUIDS, file.uuid())
  237. .execute()
  238. .assertJson(this.getClass(), "search_by_file_uuid.json");
  239. ws.newRequest()
  240. .setParam(PARAM_FILE_UUIDS, "unknown")
  241. .execute()
  242. .assertJson(this.getClass(), "no_issue.json");
  243. ws.newRequest()
  244. .setParam(PARAM_COMPONENT_UUIDS, file.uuid())
  245. .execute()
  246. .assertJson(this.getClass(), "search_by_file_uuid.json");
  247. ws.newRequest()
  248. .setParam(PARAM_COMPONENT_UUIDS, "unknown")
  249. .execute()
  250. .assertJson(this.getClass(), "no_issue.json");
  251. }
  252. @Test
  253. public void search_by_file_key() {
  254. ComponentDto project = db.components().insertPublicProject(p -> p.setDbKey("PK1"));
  255. ComponentDto file = db.components().insertComponent(newFileDto(project, null, "F1").setDbKey("FK1"));
  256. ComponentDto unitTest = db.components().insertComponent(newFileDto(project, null, "F2").setQualifier(Qualifiers.UNIT_TEST_FILE).setDbKey("FK2"));
  257. RuleDefinitionDto rule = db.rules().insert(r -> r.setRuleKey(RuleKey.of("xoo", "x1")));
  258. IssueDto issueOnFile = db.issues().insert(rule, project, file, i -> i.setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2"));
  259. IssueDto issueOnTest = db.issues().insert(rule, project, unitTest, i -> i.setKee("2bd4eac2-b650-4037-80bc-7b1182fd47d4"));
  260. allowAnyoneOnProjects(project);
  261. indexIssues();
  262. ws.newRequest()
  263. .setParam(PARAM_COMPONENTS, file.getDbKey())
  264. .execute()
  265. .assertJson(this.getClass(), "search_by_file_key.json");
  266. ws.newRequest()
  267. .setParam(PARAM_COMPONENTS, unitTest.getDbKey())
  268. .execute()
  269. .assertJson(this.getClass(), "search_by_test_key.json");
  270. }
  271. @Test
  272. public void search_by_directory_path() {
  273. ComponentDto project = db.components().insertPublicProject(p -> p.setDbKey("PK1"));
  274. ComponentDto directory = db.components().insertComponent(newDirectory(project, "D1", "src/main/java/dir"));
  275. ComponentDto file = db.components().insertComponent(newFileDto(project, null, "F1").setDbKey("FK1").setPath(directory.path() + "/MyComponent.java"));
  276. RuleDefinitionDto rule = db.rules().insert(r -> r.setRuleKey(RuleKey.of("xoo", "x1")));
  277. db.issues().insert(rule, project, file, i -> i.setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2"));
  278. allowAnyoneOnProjects(project);
  279. indexIssues();
  280. ws.newRequest()
  281. .setParam(PARAM_COMPONENT_KEYS, directory.getKey())
  282. .execute()
  283. .assertJson(this.getClass(), "search_by_file_uuid.json");
  284. ws.newRequest()
  285. .setParam(PARAM_DIRECTORIES, "unknown")
  286. .execute()
  287. .assertJson(this.getClass(), "no_issue.json");
  288. ws.newRequest()
  289. .setParam(PARAM_DIRECTORIES, "src/main/java/dir")
  290. .execute()
  291. .assertJson(this.getClass(), "search_by_file_uuid.json");
  292. ws.newRequest()
  293. .setParam(PARAM_DIRECTORIES, "src/main/java")
  294. .execute()
  295. .assertJson(this.getClass(), "no_issue.json");
  296. }
  297. @Test
  298. public void search_by_directory_path_in_different_modules() {
  299. ComponentDto project = db.components().insertPublicProject(p -> p.setDbKey("PK1"));
  300. ComponentDto module1 = db.components().insertComponent(newModuleDto("M1", project).setDbKey("MK1"));
  301. ComponentDto module2 = db.components().insertComponent(newModuleDto("M2", project).setDbKey("MK2"));
  302. ComponentDto directory1 = db.components().insertComponent(newDirectory(module1, "D1", "src/main/java/dir"));
  303. ComponentDto directory2 = db.components().insertComponent(newDirectory(module2, "D2", "src/main/java/dir"));
  304. ComponentDto file1 = db.components().insertComponent(newFileDto(module1, directory1, "F1").setDbKey("FK1").setPath(directory1.path() + "/MyComponent.java"));
  305. db.components().insertComponent(newFileDto(module2, directory2, "F2").setDbKey("FK2").setPath(directory2.path() + "/MyComponent.java"));
  306. RuleDefinitionDto rule = db.rules().insert(r -> r.setRuleKey(RuleKey.of("xoo", "x1")));
  307. db.issues().insert(rule, project, file1, i -> i.setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2"));
  308. allowAnyoneOnProjects(project);
  309. indexIssues();
  310. ws.newRequest()
  311. .setParam(PARAM_COMPONENT_KEYS, directory1.getKey())
  312. .execute()
  313. .assertJson(this.getClass(), "search_by_directory_uuid.json");
  314. ws.newRequest()
  315. .setParam(PARAM_COMPONENT_KEYS, directory2.getKey())
  316. .execute()
  317. .assertJson(this.getClass(), "no_issue.json");
  318. ws.newRequest()
  319. .setParam(PARAM_MODULE_UUIDS, module1.uuid())
  320. .setParam(PARAM_DIRECTORIES, "src/main/java/dir")
  321. .execute()
  322. .assertJson(this.getClass(), "search_by_directory_uuid.json");
  323. ws.newRequest()
  324. .setParam(PARAM_MODULE_UUIDS, module2.uuid())
  325. .setParam(PARAM_DIRECTORIES, "src/main/java/dir")
  326. .execute()
  327. .assertJson(this.getClass(), "no_issue.json");
  328. ws.newRequest()
  329. .setParam(PARAM_DIRECTORIES, "src/main/java/dir")
  330. .execute()
  331. .assertJson(this.getClass(), "search_by_directory_uuid.json");
  332. ws.newRequest()
  333. .setParam(PARAM_DIRECTORIES, "src/main/java")
  334. .execute()
  335. .assertJson(this.getClass(), "no_issue.json");
  336. }
  337. @Test
  338. public void search_by_view_uuid() {
  339. ComponentDto project = db.components().insertPublicProject(p -> p.setDbKey("PK1"));
  340. ComponentDto file = db.components().insertComponent(newFileDto(project, null, "F1").setDbKey("FK1"));
  341. ComponentDto view = db.components().insertComponent(newView(db.getDefaultOrganization(), "V1").setDbKey("MyView"));
  342. db.components().insertComponent(newProjectCopy(project, view));
  343. RuleDefinitionDto rule = db.rules().insert(r -> r.setRuleKey(RuleKey.of("xoo", "x1")));
  344. db.issues().insert(rule, project, file, i -> i.setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2"));
  345. allowAnyoneOnProjects(project, view);
  346. indexIssuesAndViews();
  347. ws.newRequest()
  348. .setParam(PARAM_COMPONENT_KEYS, view.getKey())
  349. .execute()
  350. .assertJson(this.getClass(), "search_by_view_uuid.json");
  351. }
  352. @Test
  353. public void search_by_sub_view_uuid() {
  354. ComponentDto project = db.components().insertPublicProject(p -> p.setDbKey("PK1"));
  355. ComponentDto file = db.components().insertComponent(newFileDto(project, null, "F1").setDbKey("FK1"));
  356. RuleDefinitionDto rule = db.rules().insert(r -> r.setRuleKey(RuleKey.of("xoo", "x1")));
  357. db.issues().insert(rule, project, file, i -> i.setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2"));
  358. ComponentDto view = db.components().insertComponent(newView(db.getDefaultOrganization(), "V1").setDbKey("MyView"));
  359. ComponentDto subView = db.components().insertComponent(newSubView(view, "SV1", "MySubView"));
  360. db.components().insertComponent(newProjectCopy(project, subView));
  361. allowAnyoneOnProjects(project, view, subView);
  362. indexIssuesAndViews();
  363. ws.newRequest()
  364. .setParam(PARAM_COMPONENT_KEYS, subView.getKey())
  365. .execute()
  366. .assertJson(this.getClass(), "search_by_view_uuid.json");
  367. }
  368. @Test
  369. public void search_by_sub_view_uuid_return_only_authorized_view() {
  370. ComponentDto project = db.components().insertPublicProject(p -> p.setDbKey("PK1"));
  371. ComponentDto file = db.components().insertComponent(newFileDto(project, null, "F1").setDbKey("FK1"));
  372. RuleDefinitionDto rule = db.rules().insert(r -> r.setRuleKey(RuleKey.of("xoo", "x1")));
  373. db.issues().insert(rule, project, file, i -> i.setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2"));
  374. ComponentDto view = db.components().insertComponent(newView(db.getDefaultOrganization(), "V1").setDbKey("MyView"));
  375. ComponentDto subView = db.components().insertComponent(newSubView(view, "SV1", "MySubView"));
  376. db.components().insertComponent(newProjectCopy(project, subView));
  377. // User has no permission on the view, no issue will be returned
  378. allowAnyoneOnProjects(project);
  379. indexIssuesAndViews();
  380. ws.newRequest()
  381. .setParam(PARAM_COMPONENT_KEYS, subView.getKey())
  382. .execute()
  383. .assertJson(this.getClass(), "no_issue.json");
  384. }
  385. @Test
  386. public void search_by_application_key() {
  387. ComponentDto application = db.components().insertPrivateApplication(db.getDefaultOrganization());
  388. ComponentDto project1 = db.components().insertPrivateProject();
  389. ComponentDto project2 = db.components().insertPrivateProject();
  390. db.components().insertComponents(newProjectCopy(project1, application));
  391. db.components().insertComponents(newProjectCopy(project2, application));
  392. RuleDefinitionDto rule = db.rules().insert();
  393. IssueDto issue1 = db.issues().insert(rule, project1, project1);
  394. IssueDto issue2 = db.issues().insert(rule, project2, project2);
  395. allowAnyoneOnProjects(project1, project2, application);
  396. userSession.addProjectPermission(USER, application);
  397. indexIssuesAndViews();
  398. SearchWsResponse result = ws.newRequest()
  399. .setParam(PARAM_COMPONENT_KEYS, application.getDbKey())
  400. .executeProtobuf(SearchWsResponse.class);
  401. assertThat(result.getIssuesList()).extracting(Issue::getKey)
  402. .containsExactlyInAnyOrder(issue1.getKey(), issue2.getKey());
  403. }
  404. @Test
  405. public void search_by_application_key_and_branch() {
  406. ComponentDto application = db.components().insertMainBranch(c -> c.setQualifier(APP).setDbKey("app"));
  407. ComponentDto applicationBranch1 = db.components().insertProjectBranch(application, a -> a.setKey("app-branch1"));
  408. ComponentDto applicationBranch2 = db.components().insertProjectBranch(application, a -> a.setKey("app-branch2"));
  409. ComponentDto project1 = db.components().insertPrivateProject(p -> p.setDbKey("prj1"));
  410. ComponentDto project1Branch1 = db.components().insertProjectBranch(project1);
  411. ComponentDto fileOnProject1Branch1 = db.components().insertComponent(newFileDto(project1Branch1));
  412. ComponentDto project1Branch2 = db.components().insertProjectBranch(project1);
  413. ComponentDto project2 = db.components().insertPrivateProject(p -> p.setDbKey("prj2"));
  414. db.components().insertComponents(newProjectCopy(project1Branch1, applicationBranch1));
  415. db.components().insertComponents(newProjectCopy(project2, applicationBranch1));
  416. db.components().insertComponents(newProjectCopy(project1Branch2, applicationBranch2));
  417. RuleDefinitionDto rule = db.rules().insert();
  418. IssueDto issueOnProject1 = db.issues().insert(rule, project1, project1);
  419. IssueDto issueOnProject1Branch1 = db.issues().insert(rule, project1Branch1, project1Branch1);
  420. IssueDto issueOnFileOnProject1Branch1 = db.issues().insert(rule, project1Branch1, fileOnProject1Branch1);
  421. IssueDto issueOnProject1Branch2 = db.issues().insert(rule, project1Branch2, project1Branch2);
  422. IssueDto issueOnProject2 = db.issues().insert(rule, project2, project2);
  423. allowAnyoneOnProjects(project1, project2, application);
  424. userSession.addProjectPermission(USER, application);
  425. indexIssuesAndViews();
  426. // All issues on applicationBranch1
  427. assertThat(ws.newRequest()
  428. .setParam(PARAM_COMPONENT_KEYS, applicationBranch1.getKey())
  429. .setParam(PARAM_BRANCH, applicationBranch1.getBranch())
  430. .executeProtobuf(SearchWsResponse.class).getIssuesList())
  431. .extracting(Issue::getKey, Issue::getComponent, Issue::getProject, Issue::getBranch, Issue::hasBranch)
  432. .containsExactlyInAnyOrder(
  433. tuple(issueOnProject1Branch1.getKey(), project1Branch1.getKey(), project1Branch1.getKey(), project1Branch1.getBranch(), true),
  434. tuple(issueOnFileOnProject1Branch1.getKey(), fileOnProject1Branch1.getKey(), project1Branch1.getKey(), project1Branch1.getBranch(), true),
  435. tuple(issueOnProject2.getKey(), project2.getKey(), project2.getKey(), "", false));
  436. // Issues on project1Branch1
  437. assertThat(ws.newRequest()
  438. .setParam(PARAM_COMPONENT_KEYS, applicationBranch1.getKey())
  439. .setParam(PARAM_PROJECTS, project1.getKey())
  440. .setParam(PARAM_BRANCH, applicationBranch1.getBranch())
  441. .executeProtobuf(SearchWsResponse.class).getIssuesList())
  442. .extracting(Issue::getKey, Issue::getComponent, Issue::getBranch)
  443. .containsExactlyInAnyOrder(
  444. tuple(issueOnProject1Branch1.getKey(), project1Branch1.getKey(), project1Branch1.getBranch()),
  445. tuple(issueOnFileOnProject1Branch1.getKey(), fileOnProject1Branch1.getKey(), project1Branch1.getBranch()));
  446. }
  447. @Test
  448. public void ignore_application_without_browse_permission() {
  449. ComponentDto project = db.components().insertPublicProject();
  450. ComponentDto application = db.components().insertApplication(db.getDefaultOrganization());
  451. db.components().insertComponents(newProjectCopy("PC1", project, application));
  452. RuleDefinitionDto rule = db.rules().insert();
  453. db.issues().insert(rule, project, project);
  454. allowAnyoneOnProjects(project);
  455. indexIssuesAndViews();
  456. SearchWsResponse result = ws.newRequest()
  457. .setParam(PARAM_COMPONENT_KEYS, application.getDbKey())
  458. .executeProtobuf(SearchWsResponse.class);
  459. assertThat(result.getIssuesList()).isEmpty();
  460. }
  461. @Test
  462. public void search_application_without_projects() {
  463. ComponentDto project = db.components().insertPublicProject();
  464. ComponentDto application = db.components().insertApplication(db.getDefaultOrganization());
  465. RuleDefinitionDto rule = db.rules().insert();
  466. db.issues().insert(rule, project, project);
  467. allowAnyoneOnProjects(project, application);
  468. indexIssuesAndViews();
  469. SearchWsResponse result = ws.newRequest()
  470. .setParam(PARAM_COMPONENT_KEYS, application.getDbKey())
  471. .executeProtobuf(SearchWsResponse.class);
  472. assertThat(result.getIssuesList()).isEmpty();
  473. }
  474. @Test
  475. public void search_by_application_and_by_leak() {
  476. Date now = new Date();
  477. RuleDefinitionDto rule = db.rules().insert();
  478. ComponentDto application = db.components().insertApplication(db.getDefaultOrganization());
  479. // Project 1
  480. ComponentDto project1 = db.components().insertPublicProject();
  481. db.components().insertSnapshot(project1, s -> s.setPeriodDate(addDays(now, -14).getTime()));
  482. db.components().insertComponents(newProjectCopy("PC1", project1, application));
  483. IssueDto project1Issue1 = db.issues().insert(rule, project1, project1, i -> i.setIssueCreationDate(addDays(now, -10)));
  484. IssueDto project1Issue2 = db.issues().insert(rule, project1, project1, i -> i.setIssueCreationDate(addDays(now, -20)));
  485. // Project 2
  486. ComponentDto project2 = db.components().insertPublicProject();
  487. db.components().insertSnapshot(project2, s -> s.setPeriodDate(addDays(now, -25).getTime()));
  488. db.components().insertComponents(newProjectCopy("PC2", project2, application));
  489. IssueDto project2Issue1 = db.issues().insert(rule, project2, project2, i -> i.setIssueCreationDate(addDays(now, -15)));
  490. IssueDto project2Issue2 = db.issues().insert(rule, project2, project2, i -> i.setIssueCreationDate(addDays(now, -30)));
  491. // Permissions and index
  492. allowAnyoneOnProjects(project1, project2, application);
  493. indexIssuesAndViews();
  494. SearchWsResponse result = ws.newRequest()
  495. .setParam(PARAM_COMPONENT_KEYS, application.getDbKey())
  496. .setParam(PARAM_SINCE_LEAK_PERIOD, "true")
  497. .executeProtobuf(SearchWsResponse.class);
  498. assertThat(result.getIssuesList()).extracting(Issue::getKey)
  499. .containsExactlyInAnyOrder(project1Issue1.getKey(), project2Issue1.getKey())
  500. .doesNotContain(project1Issue2.getKey(), project2Issue2.getKey());
  501. }
  502. @Test
  503. public void search_by_application_and_project() {
  504. ComponentDto project1 = db.components().insertPublicProject();
  505. ComponentDto project2 = db.components().insertPublicProject();
  506. ComponentDto application = db.components().insertApplication(db.getDefaultOrganization());
  507. db.components().insertComponents(newProjectCopy("PC1", project1, application));
  508. db.components().insertComponents(newProjectCopy("PC2", project2, application));
  509. RuleDefinitionDto rule = db.rules().insert();
  510. IssueDto issue1 = db.issues().insert(rule, project1, project1);
  511. IssueDto issue2 = db.issues().insert(rule, project2, project2);
  512. allowAnyoneOnProjects(project1, project2, application);
  513. indexIssuesAndViews();
  514. SearchWsResponse result = ws.newRequest()
  515. .setParam(PARAM_COMPONENT_KEYS, application.getDbKey())
  516. .setParam(PARAM_PROJECT_KEYS, project1.getDbKey())
  517. .executeProtobuf(SearchWsResponse.class);
  518. assertThat(result.getIssuesList()).extracting(Issue::getKey)
  519. .containsExactlyInAnyOrder(issue1.getKey())
  520. .doesNotContain(issue2.getKey());
  521. }
  522. @Test
  523. public void search_by_application_and_project_and_leak() {
  524. Date now = new Date();
  525. RuleDefinitionDto rule = db.rules().insert();
  526. ComponentDto application = db.components().insertApplication(db.getDefaultOrganization());
  527. // Project 1
  528. ComponentDto project1 = db.components().insertPublicProject();
  529. db.components().insertSnapshot(project1, s -> s.setPeriodDate(addDays(now, -14).getTime()));
  530. db.components().insertComponents(newProjectCopy("PC1", project1, application));
  531. IssueDto project1Issue1 = db.issues().insert(rule, project1, project1, i -> i.setIssueCreationDate(addDays(now, -10)));
  532. IssueDto project1Issue2 = db.issues().insert(rule, project1, project1, i -> i.setIssueCreationDate(addDays(now, -20)));
  533. // Project 2
  534. ComponentDto project2 = db.components().insertPublicProject();
  535. db.components().insertSnapshot(project2, s -> s.setPeriodDate(addDays(now, -25).getTime()));
  536. db.components().insertComponents(newProjectCopy("PC2", project2, application));
  537. IssueDto project2Issue1 = db.issues().insert(rule, project2, project2, i -> i.setIssueCreationDate(addDays(now, -15)));
  538. IssueDto project2Issue2 = db.issues().insert(rule, project2, project2, i -> i.setIssueCreationDate(addDays(now, -30)));
  539. // Permissions and index
  540. allowAnyoneOnProjects(project1, project2, application);
  541. indexIssuesAndViews();
  542. SearchWsResponse result = ws.newRequest()
  543. .setParam(PARAM_COMPONENT_KEYS, application.getDbKey())
  544. .setParam(PARAM_PROJECT_KEYS, project1.getDbKey())
  545. .setParam(PARAM_SINCE_LEAK_PERIOD, "true")
  546. .executeProtobuf(SearchWsResponse.class);
  547. assertThat(result.getIssuesList()).extracting(Issue::getKey)
  548. .containsExactlyInAnyOrder(project1Issue1.getKey())
  549. .doesNotContain(project1Issue2.getKey(), project2Issue1.getKey(), project2Issue2.getKey());
  550. }
  551. @Test
  552. public void search_by_application_and_by_leak_when_one_project_has_no_leak() {
  553. Date now = new Date();
  554. RuleDefinitionDto rule = db.rules().insert();
  555. ComponentDto application = db.components().insertApplication(db.getDefaultOrganization());
  556. // Project 1
  557. ComponentDto project1 = db.components().insertPublicProject();
  558. db.components().insertSnapshot(project1, s -> s.setPeriodDate(addDays(now, -14).getTime()));
  559. db.components().insertComponents(newProjectCopy("PC1", project1, application));
  560. IssueDto project1Issue1 = db.issues().insert(rule, project1, project1, i -> i.setIssueCreationDate(addDays(now, -10)));
  561. IssueDto project1Issue2 = db.issues().insert(rule, project1, project1, i -> i.setIssueCreationDate(addDays(now, -20)));
  562. // Project 2, without leak => no issue form it should be returned
  563. ComponentDto project2 = db.components().insertPublicProject();
  564. db.components().insertSnapshot(project2, s -> s.setPeriodDate(null));
  565. db.components().insertComponents(newProjectCopy("PC2", project2, application));
  566. IssueDto project2Issue1 = db.issues().insert(rule, project2, project2, i -> i.setIssueCreationDate(addDays(now, -15)));
  567. IssueDto project2Issue2 = db.issues().insert(rule, project2, project2, i -> i.setIssueCreationDate(addDays(now, -30)));
  568. // Permissions and index
  569. allowAnyoneOnProjects(project1, project2, application);
  570. indexIssuesAndViews();
  571. SearchWsResponse result = ws.newRequest()
  572. .setParam(PARAM_COMPONENT_KEYS, application.getDbKey())
  573. .setParam(PARAM_SINCE_LEAK_PERIOD, "true")
  574. .executeProtobuf(SearchWsResponse.class);
  575. assertThat(result.getIssuesList()).extracting(Issue::getKey)
  576. .containsExactlyInAnyOrder(project1Issue1.getKey())
  577. .doesNotContain(project1Issue2.getKey(), project2Issue1.getKey(), project2Issue2.getKey());
  578. }
  579. @Test
  580. public void search_by_branch() {
  581. RuleDefinitionDto rule = db.rules().insert();
  582. ComponentDto project = db.components().insertMainBranch();
  583. ComponentDto file = db.components().insertComponent(newFileDto(project));
  584. IssueDto issue = db.issues().insertIssue(newIssue(rule, project, file));
  585. ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(SHORT));
  586. ComponentDto branchFile = db.components().insertComponent(newFileDto(branch));
  587. IssueDto branchIssue = db.issues().insertIssue(newIssue(rule, branch, branchFile));
  588. allowAnyoneOnProjects(project);
  589. indexIssuesAndViews();
  590. // On component key + branch
  591. assertThat(ws.newRequest()
  592. .setParam(PARAM_COMPONENT_KEYS, project.getKey())
  593. .setParam(PARAM_BRANCH, branch.getBranch())
  594. .executeProtobuf(SearchWsResponse.class).getIssuesList())
  595. .extracting(Issue::getKey, Issue::getComponent, Issue::getBranch)
  596. .containsExactlyInAnyOrder(tuple(branchIssue.getKey(), branchFile.getKey(), branchFile.getBranch()));
  597. // On project key + branch
  598. assertThat(ws.newRequest()
  599. .setParam(PARAM_PROJECT_KEYS, project.getKey())
  600. .setParam(PARAM_BRANCH, branch.getBranch())
  601. .executeProtobuf(SearchWsResponse.class).getIssuesList())
  602. .extracting(Issue::getKey, Issue::getComponent, Issue::getBranch)
  603. .containsExactlyInAnyOrder(tuple(branchIssue.getKey(), branchFile.getKey(), branchFile.getBranch()));
  604. // On file key + branch
  605. assertThat(ws.newRequest()
  606. .setParam(PARAM_COMPONENT_KEYS, branchFile.getKey())
  607. .setParam(PARAM_BRANCH, branch.getBranch())
  608. .executeProtobuf(SearchWsResponse.class).getIssuesList())
  609. .extracting(Issue::getKey, Issue::getComponent, Issue::getBranch)
  610. .containsExactlyInAnyOrder(tuple(branchIssue.getKey(), branchFile.getKey(), branchFile.getBranch()));
  611. }
  612. @Test
  613. public void return_branch_in_component_list() {
  614. RuleDefinitionDto rule = db.rules().insert();
  615. ComponentDto project = db.components().insertPrivateProject();
  616. ComponentDto projectFile = db.components().insertComponent(newFileDto(project));
  617. IssueDto projectIssue = db.issues().insertIssue(newIssue(rule, project, projectFile));
  618. ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(SHORT));
  619. ComponentDto branchFile = db.components().insertComponent(newFileDto(branch));
  620. IssueDto branchIssue = db.issues().insertIssue(newIssue(rule, branch, branchFile));
  621. allowAnyoneOnProjects(project);
  622. indexIssuesAndViews();
  623. SearchWsResponse result = ws.newRequest()
  624. .setParam(PARAM_COMPONENT_KEYS, branch.getKey())
  625. .setParam(PARAM_BRANCH, branch.getBranch())
  626. .executeProtobuf(SearchWsResponse.class);
  627. assertThat(result.getComponentsList())
  628. .extracting(Issues.Component::getKey, Issues.Component::getBranch)
  629. .containsExactlyInAnyOrder(
  630. tuple(branchFile.getKey(), branchFile.getBranch()),
  631. tuple(branch.getKey(), branch.getBranch()));
  632. }
  633. @Test
  634. public void search_by_pull_request() {
  635. RuleDefinitionDto rule = db.rules().insert();
  636. ComponentDto project = db.components().insertPrivateProject();
  637. ComponentDto projectFile = db.components().insertComponent(newFileDto(project));
  638. IssueDto projectIssue = db.issues().insertIssue(newIssue(rule, project, projectFile));
  639. ComponentDto pullRequest = db.components().insertProjectBranch(project, b -> b.setBranchType(PULL_REQUEST));
  640. ComponentDto pullRequestFile = db.components().insertComponent(newFileDto(pullRequest));
  641. IssueDto pullRequestIssue = db.issues().insertIssue(newIssue(rule, pullRequest, pullRequestFile));
  642. allowAnyoneOnProjects(project);
  643. indexIssuesAndViews();
  644. SearchWsResponse result = ws.newRequest()
  645. .setParam(PARAM_COMPONENT_KEYS, pullRequest.getKey())
  646. .setParam(PARAM_PULL_REQUEST, pullRequest.getPullRequest())
  647. .executeProtobuf(SearchWsResponse.class);
  648. assertThat(result.getIssuesList())
  649. .extracting(Issue::getKey, Issue::getComponent, Issue::getPullRequest)
  650. .containsExactlyInAnyOrder(tuple(pullRequestIssue.getKey(), pullRequestFile.getKey(), pullRequestFile.getPullRequest()));
  651. assertThat(result.getComponentsList())
  652. .extracting(Issues.Component::getKey, Issues.Component::getPullRequest)
  653. .containsExactlyInAnyOrder(
  654. tuple(pullRequestFile.getKey(), pullRequestFile.getPullRequest()),
  655. tuple(pullRequest.getKey(), pullRequest.getPullRequest()));
  656. }
  657. @Test
  658. public void search_using_main_branch_name() {
  659. RuleDefinitionDto rule = db.rules().insert();
  660. ComponentDto project = db.components().insertMainBranch();
  661. ComponentDto projectFile = db.components().insertComponent(newFileDto(project));
  662. IssueDto projectIssue = db.issues().insertIssue(newIssue(rule, project, projectFile));
  663. allowAnyoneOnProjects(project);
  664. indexIssuesAndViews();
  665. SearchWsResponse result = ws.newRequest()
  666. .setParam(PARAM_COMPONENT_KEYS, project.getKey())
  667. .setParam(PARAM_BRANCH, "master")
  668. .executeProtobuf(SearchWsResponse.class);
  669. assertThat(result.getIssuesList())
  670. .extracting(Issue::getKey, Issue::getComponent, Issue::hasBranch)
  671. .containsExactlyInAnyOrder(tuple(projectIssue.getKey(), projectFile.getKey(), false));
  672. assertThat(result.getComponentsList())
  673. .extracting(Issues.Component::getKey, Issues.Component::hasBranch)
  674. .containsExactlyInAnyOrder(
  675. tuple(projectFile.getKey(), false),
  676. tuple(project.getKey(), false));
  677. }
  678. @Test
  679. public void does_not_return_branch_issues_on_not_contextualized_search() {
  680. RuleDefinitionDto rule = db.rules().insert();
  681. ComponentDto project = db.components().insertPrivateProject();
  682. ComponentDto projectFile = db.components().insertComponent(newFileDto(project));
  683. IssueDto projectIssue = db.issues().insertIssue(newIssue(rule, project, projectFile));
  684. ComponentDto branch = db.components().insertProjectBranch(project);
  685. ComponentDto branchFile = db.components().insertComponent(newFileDto(branch));
  686. IssueDto branchIssue = db.issues().insertIssue(newIssue(rule, branch, branchFile));
  687. allowAnyoneOnProjects(project);
  688. indexIssuesAndViews();
  689. SearchWsResponse result = ws.newRequest().executeProtobuf(SearchWsResponse.class);
  690. assertThat(result.getIssuesList()).extracting(Issue::getKey)
  691. .containsExactlyInAnyOrder(projectIssue.getKey())
  692. .doesNotContain(branchIssue.getKey());
  693. }
  694. @Test
  695. public void does_not_return_branch_issues_when_using_db_key() {
  696. RuleDefinitionDto rule = db.rules().insert();
  697. ComponentDto project = db.components().insertPrivateProject();
  698. ComponentDto projectFile = db.components().insertComponent(newFileDto(project));
  699. IssueDto projectIssue = db.issues().insertIssue(newIssue(rule, project, projectFile));
  700. ComponentDto branch = db.components().insertProjectBranch(project);
  701. ComponentDto branchFile = db.components().insertComponent(newFileDto(branch));
  702. IssueDto branchIssue = db.issues().insertIssue(newIssue(rule, branch, branchFile));
  703. allowAnyoneOnProjects(project);
  704. indexIssues();
  705. SearchWsResponse result = ws.newRequest()
  706. .setParam(PARAM_COMPONENT_KEYS, branch.getDbKey())
  707. .executeProtobuf(SearchWsResponse.class);
  708. assertThat(result.getIssuesList()).isEmpty();
  709. }
  710. private void allowAnyoneOnProjects(ComponentDto... projects) {
  711. userSession.registerComponents(projects);
  712. Arrays.stream(projects).forEach(p -> permissionIndexer.allowOnlyAnyone(p));
  713. }
  714. private void indexIssues() {
  715. issueIndexer.indexOnStartup(null);
  716. }
  717. private void indexIssuesAndViews() {
  718. indexIssues();
  719. viewIndexer.indexOnStartup(null);
  720. }
  721. }