3 * Copyright (C) 2009-2023 SonarSource SA
4 * mailto:info AT sonarsource DOT com
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.
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.
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.
20 package org.sonar.ce.task.projectanalysis.step;
22 import org.junit.Rule;
23 import org.junit.Test;
24 import org.sonar.ce.task.projectanalysis.batch.BatchReportReaderRule;
25 import org.sonar.ce.task.projectanalysis.component.Component;
26 import org.sonar.ce.task.projectanalysis.component.ReportComponent;
27 import org.sonar.ce.task.projectanalysis.component.TreeRootHolderRule;
28 import org.sonar.ce.task.projectanalysis.component.ViewsComponent;
29 import org.sonar.ce.task.step.ComputationStep;
30 import org.sonar.ce.task.step.TestComputationStepContext;
31 import org.sonar.server.es.ProjectIndexer;
33 import static org.mockito.Mockito.mock;
34 import static org.mockito.Mockito.verify;
35 import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT;
36 import static org.sonar.ce.task.projectanalysis.component.Component.Type.VIEW;
38 public class IndexAnalysisStepTest extends BaseStepTest {
40 private static final String PROJECT_KEY = "PROJECT_KEY";
41 private static final String PROJECT_UUID = "PROJECT_UUID";
44 public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
46 public BatchReportReaderRule reportReader = new BatchReportReaderRule();
48 private ProjectIndexer componentIndexer = mock(ProjectIndexer.class);
49 private IndexAnalysisStep underTest = new IndexAnalysisStep(treeRootHolder, componentIndexer);
52 public void call_indexByProjectUuid_of_indexer_for_project() {
53 Component project = ReportComponent.builder(PROJECT, 1).setUuid(PROJECT_UUID).setKey(PROJECT_KEY).build();
54 treeRootHolder.setRoot(project);
56 underTest.execute(new TestComputationStepContext());
58 verify(componentIndexer).indexOnAnalysis(PROJECT_UUID);
62 public void call_indexByProjectUuid_of_indexer_for_view() {
63 Component view = ViewsComponent.builder(VIEW, PROJECT_KEY).setUuid(PROJECT_UUID).build();
64 treeRootHolder.setRoot(view);
66 underTest.execute(new TestComputationStepContext());
68 verify(componentIndexer).indexOnAnalysis(PROJECT_UUID);
72 protected ComputationStep step() {