Search in sources :

Example 1 with TestComputationStepContext

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

the class HandleUnanalyzedLanguagesStepTest method execute_does_not_add_a_warning_in_SQ_community_edition_if_no_c_or_cpp_files.

@Test
public void execute_does_not_add_a_warning_in_SQ_community_edition_if_no_c_or_cpp_files() {
    when(editionProvider.get()).thenReturn(Optional.of(EditionProvider.Edition.COMMUNITY));
    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);
    reportReader.setMetadata(ScannerReport.Metadata.newBuilder().build());
    underTest.execute(new TestComputationStepContext());
    verify(ceTaskMessages, never()).add(any());
    assertThat(measureRepository.getAddedRawMeasure(PROJECT_REF, UNANALYZED_C_KEY)).isEmpty();
    assertThat(measureRepository.getAddedRawMeasure(PROJECT_REF, UNANALYZED_CPP_KEY)).isEmpty();
}
Also used : ScannerReport(org.sonar.scanner.protocol.output.ScannerReport) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 2 with TestComputationStepContext

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

the class HandleUnanalyzedLanguagesStepTest method add_warning_and_measures_in_SQ_community_edition_if_there_are_c_or_cpp_files.

@Test
public void add_warning_and_measures_in_SQ_community_edition_if_there_are_c_or_cpp_files() {
    when(editionProvider.get()).thenReturn(Optional.of(EditionProvider.Edition.COMMUNITY));
    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);
    reportReader.setMetadata(ScannerReport.Metadata.newBuilder().putNotAnalyzedFilesByLanguage("C++", 20).putNotAnalyzedFilesByLanguage("C", 10).putNotAnalyzedFilesByLanguage("SomeLang", 1000).build());
    underTest.execute(new TestComputationStepContext());
    verify(ceTaskMessages, times(1)).add(argumentCaptor.capture());
    assertThat(argumentCaptor.getAllValues()).extracting(Message::getText, Message::getType).containsExactly(tuple("10 unanalyzed C, 20 unanalyzed C++ and 1000 unanalyzed SomeLang files were detected in this project during the last analysis. C," + " C++ and SomeLang cannot be analyzed with your current SonarQube edition. Please consider" + " <a target=\"_blank\" href=\"https://www.sonarqube.org/trial-request/developer-edition/?referrer=sonarqube-cpp\">upgrading to Developer Edition</a> to find Bugs," + " Code Smells, Vulnerabilities and Security Hotspots in these files.", CeTaskMessageType.SUGGEST_DEVELOPER_EDITION_UPGRADE));
    assertThat(measureRepository.getAddedRawMeasure(PROJECT_REF, UNANALYZED_C_KEY).get().getIntValue()).isEqualTo(10);
    assertThat(measureRepository.getAddedRawMeasure(PROJECT_REF, UNANALYZED_CPP_KEY).get().getIntValue()).isEqualTo(20);
}
Also used : ScannerReport(org.sonar.scanner.protocol.output.ScannerReport) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 3 with TestComputationStepContext

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

the class PostMeasuresComputationChecksStepTest method context_contains_ncloc_when_available.

@Test
public void context_contains_ncloc_when_available() {
    PostMeasuresComputationCheck check = mock(PostMeasuresComputationCheck.class);
    measureRepository.addRawMeasure(DUMB_PROJECT.getReportAttributes().getRef(), CoreMetrics.NCLOC_KEY, Measure.newMeasureBuilder().create(10));
    newStep(check).execute(new TestComputationStepContext());
    ArgumentCaptor<Context> contextArgumentCaptor = ArgumentCaptor.forClass(Context.class);
    verify(check).onCheck(contextArgumentCaptor.capture());
    assertThat(contextArgumentCaptor.getValue().getNcloc()).isEqualTo(10);
}
Also used : TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Context(org.sonar.ce.task.projectanalysis.measure.PostMeasuresComputationCheck.Context) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 4 with TestComputationStepContext

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

the class PostMeasuresComputationChecksStepTest method context_contains_project_uuid_from_analysis_metada_holder.

@Test
public void context_contains_project_uuid_from_analysis_metada_holder() {
    Project project = Project.from(newPrivateProjectDto());
    analysisMetadataHolder.setProject(project);
    PostMeasuresComputationCheck check = mock(PostMeasuresComputationCheck.class);
    newStep(check).execute(new TestComputationStepContext());
    ArgumentCaptor<Context> contextArgumentCaptor = ArgumentCaptor.forClass(Context.class);
    verify(check).onCheck(contextArgumentCaptor.capture());
    assertThat(contextArgumentCaptor.getValue().getProjectUuid()).isEqualTo(project.getUuid());
}
Also used : TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Context(org.sonar.ce.task.projectanalysis.measure.PostMeasuresComputationCheck.Context) Project(org.sonar.server.project.Project) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 5 with TestComputationStepContext

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

the class PostMeasuresComputationChecksStepTest method fail_if_an_extension_throws_an_exception.

@Test
public void fail_if_an_extension_throws_an_exception() {
    PostMeasuresComputationCheck check1 = mock(PostMeasuresComputationCheck.class);
    PostMeasuresComputationCheck check2 = mock(PostMeasuresComputationCheck.class);
    doThrow(new IllegalStateException("BOOM")).when(check2).onCheck(any(Context.class));
    PostMeasuresComputationCheck check3 = mock(PostMeasuresComputationCheck.class);
    try {
        newStep(check1, check2, check3).execute(new TestComputationStepContext());
        fail();
    } catch (IllegalStateException e) {
        assertThat(e).hasMessage("BOOM");
        verify(check1).onCheck(any(Context.class));
        verify(check3, never()).onCheck(any(Context.class));
    }
}
Also used : TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Context(org.sonar.ce.task.projectanalysis.measure.PostMeasuresComputationCheck.Context) 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