3 * Copyright (C) 2009-2017 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.server.computation.task.projectanalysis.step;
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;
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;
37 public class IndexAnalysisStepTest extends BaseStepTest {
39 private static final String PROJECT_KEY = "PROJECT_KEY";
40 private static final String PROJECT_UUID = "PROJECT_UUID";
43 public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
45 public BatchReportReaderRule reportReader = new BatchReportReaderRule();
47 private ProjectIndexer componentIndexer = mock(ProjectIndexer.class);
48 private IndexAnalysisStep underTest = new IndexAnalysisStep(treeRootHolder, componentIndexer);
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);
57 verify(componentIndexer).indexProject(PROJECT_UUID, ProjectIndexer.Cause.NEW_ANALYSIS);
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);
67 verify(componentIndexer).indexProject(PROJECT_UUID, ProjectIndexer.Cause.NEW_ANALYSIS);
71 protected ComputationStep step() {