Search in sources :

Example 6 with MessageException

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");
    }
}
Also used : MessageException(org.sonar.api.utils.MessageException) Languages(org.sonar.api.resources.Languages) Test(org.junit.Test)

Example 7 with MessageException

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);
    }
}
Also used : MessageException(org.sonar.api.utils.MessageException) ComponentDto(org.sonar.db.component.ComponentDto) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 8 with MessageException

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);
}
Also used : MessageException(org.sonar.api.utils.MessageException) LogAndArguments(org.sonar.api.utils.log.LogAndArguments) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CeTask(org.sonar.ce.task.CeTask) MessageException(org.sonar.api.utils.MessageException) Test(org.junit.Test)

Example 9 with MessageException

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.");
    }
}
Also used : MessageException(org.sonar.api.utils.MessageException) DatabaseMetaData(java.sql.DatabaseMetaData) Test(org.junit.Test)

Example 10 with MessageException

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");
    }
}
Also used : MessageException(org.sonar.api.utils.MessageException) LanguagesRepository(org.sonar.scanner.repository.language.LanguagesRepository) DefaultLanguagesRepository(org.sonar.scanner.repository.language.DefaultLanguagesRepository) Languages(org.sonar.api.resources.Languages) DefaultLanguagesRepository(org.sonar.scanner.repository.language.DefaultLanguagesRepository) Test(org.junit.Test)

Aggregations

MessageException (org.sonar.api.utils.MessageException)12 Test (org.junit.Test)11 Languages (org.sonar.api.resources.Languages)3 TestComputationStepContext (org.sonar.ce.task.step.TestComputationStepContext)3 DatabaseMetaData (java.sql.DatabaseMetaData)2 ComponentDto (org.sonar.db.component.ComponentDto)2 Oracle (org.sonar.db.dialect.Oracle)2 DefaultLanguagesRepository (org.sonar.scanner.repository.language.DefaultLanguagesRepository)2 LanguagesRepository (org.sonar.scanner.repository.language.LanguagesRepository)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 LogAndArguments (org.sonar.api.utils.log.LogAndArguments)1 CeTask (org.sonar.ce.task.CeTask)1 HttpException (org.sonarqube.ws.client.HttpException)1