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 org.junit.ClassRule;
23 import org.junit.Rule;
24 import org.junit.Test;
25 import org.sonar.api.utils.System2;
26 import org.sonar.db.DbClient;
27 import org.sonar.db.DbTester;
28 import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetadataHolderRule;
29 import org.sonar.server.computation.task.projectanalysis.batch.BatchReportReaderRule;
31 import static java.util.Arrays.asList;
32 import static java.util.Collections.emptyList;
33 import static org.assertj.core.api.Assertions.assertThat;
35 public class PersistScannerContextStepTest {
36 private static final String ANALYSIS_UUID = "UUID";
39 public static final DbTester dbTester = DbTester.create(System2.INSTANCE);
42 public BatchReportReaderRule reportReader = new BatchReportReaderRule();
44 public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule()
45 .setUuid(ANALYSIS_UUID);
47 private DbClient dbClient = dbTester.getDbClient();
48 private PersistScannerContextStep underTest = new PersistScannerContextStep(reportReader, analysisMetadataHolder, dbClient);
51 public void getDescription() {
52 assertThat(underTest.getDescription()).isEqualTo("Persist scanner context");
56 public void executes_persist_lines_of_reportReader() {
57 reportReader.setScannerLogs(asList("log1", "log2"));
61 assertThat(dbClient.scannerContextDao().selectScannerContext(dbTester.getSession(), ANALYSIS_UUID))
62 .contains("log1" + '\n' + "log2");
66 public void executes_persist_does_not_persit_any_scanner_context_if_iterator_is_empty() {
67 reportReader.setScannerLogs(emptyList());
71 assertThat(dbClient.scannerContextDao().selectScannerContext(dbTester.getSession(), ANALYSIS_UUID))