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();
}
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);
}
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);
}
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());
}
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));
}
}
Aggregations