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.ce.queue.CeTask;
27 import org.sonar.db.DbClient;
28 import org.sonar.db.DbTester;
29 import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetadataHolderRule;
30 import org.sonar.server.computation.task.projectanalysis.batch.BatchReportReaderRule;
32 import static java.util.Arrays.asList;
33 import static java.util.Collections.emptyList;
34 import static org.assertj.core.api.Assertions.assertThat;
35 import static org.mockito.Mockito.mock;
36 import static org.mockito.Mockito.when;
38 public class PersistScannerContextStepTest {
39 private static final String ANALYSIS_UUID = "UUID";
42 public static final DbTester dbTester = DbTester.create(System2.INSTANCE);
45 public BatchReportReaderRule reportReader = new BatchReportReaderRule();
47 public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule()
48 .setUuid(ANALYSIS_UUID);
50 private DbClient dbClient = dbTester.getDbClient();
51 private CeTask ceTask = mock(CeTask.class);
52 private PersistScannerContextStep underTest = new PersistScannerContextStep(reportReader, dbClient, ceTask);
55 public void getDescription() {
56 assertThat(underTest.getDescription()).isEqualTo("Persist scanner context");
60 public void executes_persist_lines_of_reportReader() {
61 String taskUuid = "task uuid";
62 when(ceTask.getUuid()).thenReturn(taskUuid);
63 reportReader.setScannerLogs(asList("log1", "log2"));
67 assertThat(dbClient.ceScannerContextDao().selectScannerContext(dbTester.getSession(), taskUuid))
68 .contains("log1" + '\n' + "log2");
72 public void executes_persist_does_not_persist_any_scanner_context_if_iterator_is_empty() {
73 reportReader.setScannerLogs(emptyList());
77 assertThat(dbClient.ceScannerContextDao().selectScannerContext(dbTester.getSession(), ANALYSIS_UUID))