3 * Copyright (C) 2009-2016 SonarSource SA
4 * mailto:contact 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 java.util.List;
23 import org.elasticsearch.search.SearchHit;
24 import org.junit.Rule;
25 import org.junit.Test;
26 import org.sonar.api.config.Settings;
27 import org.sonar.api.utils.System2;
28 import org.sonar.db.DbClient;
29 import org.sonar.db.DbTester;
30 import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule;
31 import org.sonar.server.computation.task.projectanalysis.component.Component;
32 import org.sonar.server.computation.task.projectanalysis.component.ReportComponent;
33 import org.sonar.server.computation.task.step.ComputationStep;
34 import org.sonar.server.es.EsTester;
35 import org.sonar.server.test.db.TestTesting;
36 import org.sonar.server.test.index.TestDoc;
37 import org.sonar.server.test.index.TestIndexDefinition;
38 import org.sonar.server.test.index.TestIndexer;
40 import static org.assertj.core.api.Assertions.assertThat;
42 public class IndexTestsStepTest extends BaseStepTest {
45 public DbTester dbTester = DbTester.create(System2.INSTANCE);
48 public EsTester esTester = new EsTester(new TestIndexDefinition(new Settings()));
51 public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
53 DbClient dbClient = dbTester.getDbClient();
56 protected ComputationStep step() {
57 TestIndexer testIndexer = new TestIndexer(dbClient, esTester.client());
58 testIndexer.setEnabled(true);
59 return new IndexTestsStep(testIndexer, treeRootHolder);
63 public void index_test() throws Exception {
64 dbTester.prepareDbUnit(getClass(), "index_source.xml");
65 TestTesting.updateDataColumn(dbTester.getSession(), "FILE1_UUID", TestTesting.newRandomTests(1));
67 treeRootHolder.setRoot(ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").setKey("PROJECT_KEY").build());
71 List<SearchHit> docs = esTester.getDocuments(TestIndexDefinition.INDEX, TestIndexDefinition.TYPE);
72 assertThat(docs).hasSize(1);
73 TestDoc doc = new TestDoc(docs.get(0).sourceAsMap());
74 assertThat(doc.projectUuid()).isEqualTo("ABCD");
75 assertThat(doc.fileUuid()).isEqualTo("FILE1_UUID");
76 assertThat(doc.coveredFiles()).isNotEmpty();