summaryrefslogtreecommitdiffstats
path: root/sonar-duplications/pom.xml
diff options
context:
space:
mode:
authorEric Hartmann <hartmann.eric@gmail.com>2014-04-18 08:50:37 +0200
committerEric Hartmann <hartmann.eric@gmail.com>2014-04-18 08:58:08 +0200
commit569749ac16a1951cce90ff43f89831a246d2bf6c (patch)
tree1eb1d7b8f14e1c2d32d419dc242003bc6b2dab34 /sonar-duplications/pom.xml
parent30ef73eb8697120ef3d06b177e7e01c877977c5a (diff)
downloadsonarqube-569749ac16a1951cce90ff43f89831a246d2bf6c.tar.gz
sonarqube-569749ac16a1951cce90ff43f89831a246d2bf6c.zip
Upgrade to 4.4-SNAPSHOT
Diffstat (limited to 'sonar-duplications/pom.xml')
-rw-r--r--sonar-duplications/pom.xml2
1 files changed, 1 insertions, 1 deletions
diff --git a/sonar-duplications/pom.xml b/sonar-duplications/pom.xml
index ac43f3a7550..966de1cb244 100644
--- a/sonar-duplications/pom.xml
+++ b/sonar-duplications/pom.xml
@@ -4,7 +4,7 @@
<parent>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar</artifactId>
- <version>4.3-SNAPSHOT</version>
+ <version>4.4-SNAPSHOT</version>
</parent>
<artifactId>sonar-duplications</artifactId>
>84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
/*
 * SonarQube
 * Copyright (C) 2009-2025 SonarSource SA
 * mailto:info AT sonarsource DOT com
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
package org.sonar.ce.task.projectanalysis.step;

import java.util.Arrays;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.utils.System2;
import org.sonar.ce.task.CeTask;
import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderRule;
import org.sonar.ce.task.projectanalysis.batch.BatchReportReaderRule;
import org.sonar.ce.task.step.TestComputationStepContext;
import org.sonar.core.util.CloseableIterator;
import org.sonar.db.DbClient;
import org.sonar.db.DbTester;

import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class PersistScannerContextStepIT {
  private static final String ANALYSIS_UUID = "UUID";

  @ClassRule
  public static final DbTester dbTester = DbTester.create(System2.INSTANCE);

  @Rule
  public BatchReportReaderRule reportReader = new BatchReportReaderRule();
  @Rule
  public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule()
    .setUuid(ANALYSIS_UUID);

  private DbClient dbClient = dbTester.getDbClient();
  private CeTask ceTask = mock(CeTask.class);
  private PersistScannerContextStep underTest = new PersistScannerContextStep(reportReader, dbClient, ceTask);

  @Test
  public void getDescription() {
    assertThat(underTest.getDescription()).isEqualTo("Persist scanner context");
  }

  @Test
  public void executes_persist_lines_of_reportReader() {
    String taskUuid = "task uuid";
    when(ceTask.getUuid()).thenReturn(taskUuid);
    reportReader.setScannerLogs(asList("log1", "log2"));

    underTest.execute(new TestComputationStepContext());

    assertThat(dbClient.ceScannerContextDao().selectScannerContext(dbTester.getSession(), taskUuid))
      .contains("log1" + '\n' + "log2");
  }

  @Test
  public void executes_persist_does_not_persist_any_scanner_context_if_iterator_is_empty() {
    reportReader.setScannerLogs(emptyList());

    underTest.execute(new TestComputationStepContext());

    assertThat(dbClient.ceScannerContextDao().selectScannerContext(dbTester.getSession(), ANALYSIS_UUID))
      .isEmpty();
  }

  /**
   * SONAR-8306
   */
  @Test
  public void execute_does_not_fail_if_scanner_context_has_already_been_persisted() {
    dbClient.ceScannerContextDao().insert(dbTester.getSession(), ANALYSIS_UUID, CloseableIterator.from(Arrays.asList("a", "b", "c").iterator()));
    dbTester.commit();
    reportReader.setScannerLogs(asList("1", "2", "3"));
    when(ceTask.getUuid()).thenReturn(ANALYSIS_UUID);

    underTest.execute(new TestComputationStepContext());

    assertThat(dbClient.ceScannerContextDao().selectScannerContext(dbTester.getSession(), ANALYSIS_UUID))
      .contains("""
        1
        2
        3""");
  }
}