]> source.dussan.org Git - sonarqube.git/blob
31bb4c3eb5dc7716b298ff67748721cf20a74d85
[sonarqube.git] /
1 /*
2  * SonarQube
3  * Copyright (C) 2009-2023 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.ce.task.projectanalysis.step;
21
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;
32
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;
37
38 public class IndexAnalysisStepTest extends BaseStepTest {
39
40   private static final String PROJECT_KEY = "PROJECT_KEY";
41   private static final String PROJECT_UUID = "PROJECT_UUID";
42
43   @Rule
44   public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
45   @Rule
46   public BatchReportReaderRule reportReader = new BatchReportReaderRule();
47
48   private ProjectIndexer componentIndexer = mock(ProjectIndexer.class);
49   private IndexAnalysisStep underTest = new IndexAnalysisStep(treeRootHolder, componentIndexer);
50
51   @Test
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);
55
56     underTest.execute(new TestComputationStepContext());
57
58     verify(componentIndexer).indexOnAnalysis(PROJECT_UUID);
59   }
60
61   @Test
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);
65
66     underTest.execute(new TestComputationStepContext());
67
68     verify(componentIndexer).indexOnAnalysis(PROJECT_UUID);
69   }
70
71   @Override
72   protected ComputationStep step() {
73     return underTest;
74   }
75 }