]> source.dussan.org Git - sonarqube.git/blob
16b792b4174e73eeeb272233ede7d1e5da82a379
[sonarqube.git] /
1 /*
2  * SonarQube
3  * Copyright (C) 2009-2017 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.computation.task.projectanalysis.step;
21
22 import org.junit.Rule;
23 import org.junit.Test;
24 import org.sonar.server.computation.task.projectanalysis.batch.BatchReportReaderRule;
25 import org.sonar.server.computation.task.projectanalysis.component.Component;
26 import org.sonar.server.computation.task.projectanalysis.component.ReportComponent;
27 import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule;
28 import org.sonar.server.computation.task.projectanalysis.component.ViewsComponent;
29 import org.sonar.server.computation.task.step.ComputationStep;
30 import org.sonar.server.es.ProjectIndexer;
31
32 import static org.mockito.Mockito.mock;
33 import static org.mockito.Mockito.verify;
34 import static org.sonar.server.computation.task.projectanalysis.component.Component.Type.PROJECT;
35 import static org.sonar.server.computation.task.projectanalysis.component.Component.Type.VIEW;
36
37 public class IndexAnalysisStepTest extends BaseStepTest {
38
39   private static final String PROJECT_KEY = "PROJECT_KEY";
40   private static final String PROJECT_UUID = "PROJECT_UUID";
41
42   @Rule
43   public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
44   @Rule
45   public BatchReportReaderRule reportReader = new BatchReportReaderRule();
46
47   private ProjectIndexer componentIndexer = mock(ProjectIndexer.class);
48   private IndexAnalysisStep underTest = new IndexAnalysisStep(treeRootHolder, componentIndexer);
49
50   @Test
51   public void call_indexByProjectUuid_of_indexer_for_project() {
52     Component project = ReportComponent.builder(PROJECT, 1).setUuid(PROJECT_UUID).setKey(PROJECT_KEY).build();
53     treeRootHolder.setRoot(project);
54
55     underTest.execute();
56
57     verify(componentIndexer).indexProject(PROJECT_UUID, ProjectIndexer.Cause.NEW_ANALYSIS);
58   }
59
60   @Test
61   public void call_indexByProjectUuid_of_indexer_for_view() {
62     Component view = ViewsComponent.builder(VIEW, PROJECT_KEY).setUuid(PROJECT_UUID).build();
63     treeRootHolder.setRoot(view);
64
65     underTest.execute();
66
67     verify(componentIndexer).indexProject(PROJECT_UUID, ProjectIndexer.Cause.NEW_ANALYSIS);
68   }
69
70   @Override
71   protected ComputationStep step() {
72     return underTest;
73   }
74 }