use of org.sonar.api.utils.MessageException in project sonarlint-core by SonarSource.
the class LanguageDetectionTest method fail_if_conflicting_language_suffix.
@Test
public void fail_if_conflicting_language_suffix() throws Exception {
LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(new MockLanguage("xml", "xhtml"), new MockLanguage("web", "xhtml")));
LanguageDetection detection = new LanguageDetection(languages);
try {
detection.language(newInputFile("abc.xhtml"));
fail();
} catch (MessageException e) {
assertThat(e.getMessage()).contains("Language of file 'file://").contains("abc.xhtml' can not be decided as the file matches patterns of both ").contains("web: **/*.xhtml").contains("xml: **/*.xhtml");
}
}
use of org.sonar.api.utils.MessageException in project sonarqube by SonarSource.
the class LoadReportAnalysisMetadataHolderStepTest method execute_sets_analysis_date_even_if_MessageException_is_thrown_because_projectKey_is_different_from_componentKey_in_CE_task.
@Test
public void execute_sets_analysis_date_even_if_MessageException_is_thrown_because_projectKey_is_different_from_componentKey_in_CE_task() {
ComponentDto otherProject = db.components().insertPublicProject();
reportReader.setMetadata(ScannerReport.Metadata.newBuilder().setProjectKey(otherProject.getDbKey()).setAnalysisDate(ANALYSIS_DATE).build());
try {
underTest.execute(new TestComputationStepContext());
} catch (MessageException e) {
assertThat(analysisMetadataHolder.getAnalysisDate()).isEqualTo(ANALYSIS_DATE);
}
}
use of org.sonar.api.utils.MessageException in project sonarqube by SonarSource.
the class CeWorkerImplTest method log_error_as_suppressed_when_task_failed_with_MessageException_and_ending_state_can_not_be_persisted_to_db.
@Test
public void log_error_as_suppressed_when_task_failed_with_MessageException_and_ending_state_can_not_be_persisted_to_db() throws Exception {
CeTask ceTask = createCeTask(submitter);
when(queue.peek(anyString(), anyBoolean())).thenReturn(Optional.of(ceTask));
taskProcessorRepository.setProcessorForTask(CeTaskTypes.REPORT, taskProcessor);
MessageException ex = makeTaskProcessorFail(ceTask, MessageException.of("simulate MessageException thrown by TaskProcessor#process"));
RuntimeException runtimeException = new RuntimeException("Simulate queue#remove failing");
doThrow(runtimeException).when(queue).remove(ceTask, CeActivityDto.Status.FAILED, null, ex);
underTest.call();
List<String> logs = logTester.logs(LoggerLevel.INFO);
assertThat(logs).hasSize(2);
assertThat(logs.get(0)).contains(" | submitter=" + submitter.getLogin());
assertThat(logs.get(1)).contains(String.format(" | submitter=%s | status=FAILED | time=", submitter.getLogin()));
List<LogAndArguments> logAndArguments = logTester.getLogs(LoggerLevel.ERROR);
assertThat(logAndArguments).hasSize(1);
assertThat(logAndArguments.get(0).getFormattedMsg()).isEqualTo("Failed to finalize task with uuid '" + ceTask.getUuid() + "' and persist its state to db");
Object arg1 = logAndArguments.get(0).getArgs().get()[0];
assertThat(arg1).isSameAs(runtimeException);
assertThat(((Exception) arg1).getSuppressed()).containsOnly(ex);
}
use of org.sonar.api.utils.MessageException in project sonarqube by SonarSource.
the class OracleTest method test_db_versions.
@Test
public void test_db_versions() throws Exception {
// oracle 11.0 is ok
DatabaseMetaData metadata = newMetadata(11, 0, "12.1.0.1.0");
underTest.init(metadata);
// oracle 11.1 is noit
metadata = newMetadata(11, 1, "12.1.0.1.0");
underTest.init(metadata);
// oracle 11.2 is ok
metadata = newMetadata(11, 2, "12.1.0.1.0");
underTest.init(metadata);
// oracle 12 is ok
metadata = newMetadata(12, 0, "12.1.0.1.0");
underTest.init(metadata);
// oracle 18 is ok
metadata = newMetadata(18, 0, "18.3.0.0.0");
underTest.init(metadata);
// oracle 10 is not supported
metadata = newMetadata(10, 2, "12.1.0.1.0");
try {
underTest.init(metadata);
fail();
} catch (MessageException e) {
assertThat(e).hasMessage("Unsupported oracle version: 10.2. Minimal supported version is 11.0.");
}
}
use of org.sonar.api.utils.MessageException in project sonarqube by SonarSource.
the class LanguageDetectionTest method fail_if_conflicting_filepattern.
@Test
public void fail_if_conflicting_filepattern() {
LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(new MockLanguage("abap", "abap"), new MockLanguage("cobol", "cobol")));
settings.setProperty("sonar.lang.patterns.abap", "*.abap,*.txt");
settings.setProperty("sonar.lang.patterns.cobol", "*.cobol,*.txt");
LanguageDetection detection = new LanguageDetection(settings.asConfig(), languages);
assertThat(detectLanguageKey(detection, "abc.abap")).isEqualTo("abap");
assertThat(detectLanguageKey(detection, "abc.cobol")).isEqualTo("cobol");
try {
detectLanguageKey(detection, "abc.txt");
fail();
} catch (MessageException e) {
assertThat(e.getMessage()).contains("Language of file 'abc.txt' can not be decided as the file matches patterns of both ").contains("sonar.lang.patterns.abap : *.abap,*.txt").contains("sonar.lang.patterns.cobol : *.cobol,*.txt");
}
}
Aggregations