Search in sources :

Example 76 with TestComputationStepContext

use of org.sonar.ce.task.step.TestComputationStepContext in project sonarqube by SonarSource.

the class RegisterQualityProfileStatusStepTest method register_updated_profile.

@Test
public void register_updated_profile() {
    QualityProfile qp1 = qp(QP_NAME_1, LANGUAGE_KEY_1, new Date(1000L));
    QualityProfile qp2 = qp(QP_NAME_1, LANGUAGE_KEY_1, new Date(1200L));
    mockBaseQPMeasures(treeRootHolder.getRoot(), arrayOf(qp1));
    mockRawQProfiles(ImmutableList.of(qp2));
    underTest.execute(new TestComputationStepContext());
    verify(qProfileStatusRepository).register(qp2.getQpKey(), UPDATED);
    verifyNoMoreInteractions(qProfileStatusRepository);
}
Also used : QualityProfile(org.sonar.server.qualityprofile.QualityProfile) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Date(java.util.Date) Test(org.junit.Test)

Example 77 with TestComputationStepContext

use of org.sonar.ce.task.step.TestComputationStepContext in project sonarqube by SonarSource.

the class PersistAnalysisWarningsStepTest method execute_persists_warnings_from_reportReader.

@Test
public void execute_persists_warnings_from_reportReader() {
    ScannerReport.AnalysisWarning warning1 = ScannerReport.AnalysisWarning.newBuilder().setText("warning 1").build();
    ScannerReport.AnalysisWarning warning2 = ScannerReport.AnalysisWarning.newBuilder().setText("warning 2").build();
    ImmutableList<ScannerReport.AnalysisWarning> warnings = of(warning1, warning2);
    reportReader.setAnalysisWarnings(warnings);
    underTest.execute(new TestComputationStepContext());
    verify(ceTaskMessages, times(1)).addAll(argumentCaptor.capture());
    assertThat(argumentCaptor.getValue()).extracting(CeTaskMessages.Message::getText, CeTaskMessages.Message::getType).containsExactly(tuple("warning 1", CeTaskMessageType.GENERIC), tuple("warning 2", CeTaskMessageType.GENERIC));
}
Also used : CeTaskMessages(org.sonar.ce.task.log.CeTaskMessages) ScannerReport(org.sonar.scanner.protocol.output.ScannerReport) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 78 with TestComputationStepContext

use of org.sonar.ce.task.step.TestComputationStepContext in project sonarqube by SonarSource.

the class PersistCrossProjectDuplicationIndexStepTest method nothing_to_persist_when_no_cpd_text_blocks_in_report.

@Test
public void nothing_to_persist_when_no_cpd_text_blocks_in_report() {
    when(crossProjectDuplicationStatusHolder.isEnabled()).thenReturn(true);
    reportReader.putDuplicationBlocks(FILE_1_REF, Collections.emptyList());
    TestComputationStepContext context = new TestComputationStepContext();
    underTest.execute(context);
    assertThat(dbTester.countRowsOfTable("duplications_index")).isZero();
    context.getStatistics().assertValue("inserts", 0);
}
Also used : TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 79 with TestComputationStepContext

use of org.sonar.ce.task.step.TestComputationStepContext in project sonarqube by SonarSource.

the class PersistCrossProjectDuplicationIndexStepTest method nothing_to_do_when_cross_project_duplication_is_disabled.

@Test
public void nothing_to_do_when_cross_project_duplication_is_disabled() {
    when(crossProjectDuplicationStatusHolder.isEnabled()).thenReturn(false);
    reportReader.putDuplicationBlocks(FILE_1_REF, singletonList(CPD_TEXT_BLOCK));
    TestComputationStepContext context = new TestComputationStepContext();
    underTest.execute(context);
    assertThat(dbTester.countRowsOfTable("duplications_index")).isZero();
    context.getStatistics().assertValue("inserts", null);
}
Also used : TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 80 with TestComputationStepContext

use of org.sonar.ce.task.step.TestComputationStepContext in project sonarqube by SonarSource.

the class PersistCrossProjectDuplicationIndexStepTest method persist_cpd_text_block.

@Test
public void persist_cpd_text_block() {
    when(crossProjectDuplicationStatusHolder.isEnabled()).thenReturn(true);
    reportReader.putDuplicationBlocks(FILE_1_REF, singletonList(CPD_TEXT_BLOCK));
    TestComputationStepContext context = new TestComputationStepContext();
    underTest.execute(context);
    Map<String, Object> dto = dbTester.selectFirst("select HASH, START_LINE, END_LINE, INDEX_IN_FILE, COMPONENT_UUID, ANALYSIS_UUID from duplications_index");
    assertThat(dto).containsEntry("HASH", CPD_TEXT_BLOCK.getHash()).containsEntry("START_LINE", 30L).containsEntry("END_LINE", 45L).containsEntry("INDEX_IN_FILE", 0L).containsEntry("COMPONENT_UUID", FILE_1.getUuid()).containsEntry("ANALYSIS_UUID", ANALYSIS_UUID);
    context.getStatistics().assertValue("inserts", 1);
}
Also used : TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Aggregations

TestComputationStepContext (org.sonar.ce.task.step.TestComputationStepContext)458 Test (org.junit.Test)431 ComponentDto (org.sonar.db.component.ComponentDto)91 ProjectDump (com.sonarsource.governance.projectdump.protobuf.ProjectDump)38 Component (org.sonar.ce.task.projectanalysis.component.Component)38 SnapshotDto (org.sonar.db.component.SnapshotDto)31 Date (java.util.Date)30 ReportComponent (org.sonar.ce.task.projectanalysis.component.ReportComponent)28 ComputationStep (org.sonar.ce.task.step.ComputationStep)24 RuleDefinitionDto (org.sonar.db.rule.RuleDefinitionDto)17 FileSourceDto (org.sonar.db.source.FileSourceDto)15 BaseStepTest (org.sonar.ce.task.projectanalysis.step.BaseStepTest)14 Project (org.sonar.server.project.Project)14 TextBlock (org.sonar.ce.task.projectanalysis.duplication.TextBlock)13 QualityProfile (org.sonar.server.qualityprofile.QualityProfile)13 Notification (org.sonar.api.notifications.Notification)12 DefaultIssue (org.sonar.core.issue.DefaultIssue)12 MeasureComputer (org.sonar.api.ce.measure.MeasureComputer)11 IssueDto (org.sonar.db.issue.IssueDto)11 IssuesChangesNotification (org.sonar.server.issue.notification.IssuesChangesNotification)11