Search in sources :

Example 1 with SecHubMessage

use of com.mercedesbenz.sechub.commons.model.SecHubMessage in project sechub by mercedes-benz.

the class ReportTransformationResultMergerTest method result1_result2_merged_contains_all_messages.

@Test
public void result1_result2_merged_contains_all_messages() {
    /* prepare */
    ReportTransformationResult result1 = new ReportTransformationResult();
    ReportTransformationResult result2 = new ReportTransformationResult();
    SecHubMessage message1 = new SecHubMessage(SecHubMessageType.INFO, "msg1");
    SecHubMessage message2 = new SecHubMessage(SecHubMessageType.INFO, "msg2");
    result1.getMessages().add(message1);
    result2.getMessages().add(message2);
    /* execute */
    ReportTransformationResult merged = mergerToTest.merge(result1, result2);
    /* test */
    Set<SecHubMessage> messages = merged.getMessages();
    assertEquals(2, messages.size());
    assertTrue(messages.contains(message1));
    assertTrue(messages.contains(message2));
}
Also used : SecHubMessage(com.mercedesbenz.sechub.commons.model.SecHubMessage) Test(org.junit.Test)

Example 2 with SecHubMessage

use of com.mercedesbenz.sechub.commons.model.SecHubMessage in project sechub by mercedes-benz.

the class ScanSecHubReportTest method scanreport_result_with_report_containing_sechub_report_model_init_and_json_parts_work.

@Test
void scanreport_result_with_report_containing_sechub_report_model_init_and_json_parts_work() {
    /* prepare */
    SecHubReportModel reportModel = new SecHubReportModel();
    SecHubFinding finding = new SecHubFinding();
    finding.setName("finding1");
    reportModel.getResult().getFindings().add(finding);
    reportModel.setStatus(SecHubStatus.FAILED);
    reportModel.getMessages().add(new SecHubMessage(SecHubMessageType.WARNING, "Testwarning"));
    ScanReport report = new ScanReport();
    report.setResult(reportModel.toJSON());
    report.setResultType(ScanReportResultType.MODEL);
    /* execute */
    ScanSecHubReport createdReport = new ScanSecHubReport(report);
    // now we also check if the JSON deserialization /serialization works as
    // expected
    String json = createdReport.toJSON();
    ScanSecHubReport reportToTest = ScanSecHubReport.fromJSONString(json);
    /* test */
    assertEquals(SecHubStatus.FAILED, reportToTest.getStatus());
    // traffic light was not set at all
    assertEquals(null, reportToTest.getTrafficLight());
    assertEquals(1, reportToTest.getMessages().size());
    SecHubMessage message1 = reportToTest.getMessages().iterator().next();
    assertEquals("Testwarning", message1.getText());
    assertEquals(SecHubMessageType.WARNING, message1.getType());
    assertEquals(1, reportToTest.getResult().getFindings().size());
    assertEquals(1, reportToTest.getResult().getCount());
}
Also used : SecHubReportModel(com.mercedesbenz.sechub.commons.model.SecHubReportModel) SecHubMessage(com.mercedesbenz.sechub.commons.model.SecHubMessage) SecHubFinding(com.mercedesbenz.sechub.commons.model.SecHubFinding) Test(org.junit.jupiter.api.Test)

Example 3 with SecHubMessage

use of com.mercedesbenz.sechub.commons.model.SecHubMessage in project sechub by mercedes-benz.

the class SerecoProductResultTransformer method handleAnnotation.

private void handleAnnotation(SerecoAnnotation annotation, ReportTransformationResult transformerResult, UUID sechubJobUUID) {
    if (annotation == null) {
        return;
    }
    SerecoAnnotationType annotationType = annotation.getType();
    String annotationValue = annotation.getValue();
    if (annotationType == null) {
        LOG.error("Sereco message type not set for message :{}, sechub job uuid: {}", annotationValue, sechubJobUUID);
        return;
    }
    switch(annotationType) {
        case USER_INFO:
            appendSecHubMessage(transformerResult, new SecHubMessage(SecHubMessageType.INFO, annotationValue));
            return;
        case USER_WARNING:
            appendSecHubMessage(transformerResult, new SecHubMessage(SecHubMessageType.WARNING, annotationValue));
            return;
        case USER_ERROR:
            appendSecHubMessage(transformerResult, new SecHubMessage(SecHubMessageType.ERROR, annotationValue));
            return;
        case INTERNAL_ERROR_PRODUCT_FAILED:
            /* internal errors are marked with status failed */
            transformerResult.setStatus(SecHubStatus.FAILED);
            /* we add an information to user as well */
            appendSecHubMessage(transformerResult, new SecHubMessage(SecHubMessageType.ERROR, "Job execution failed because of an internal problem."));
            return;
        default:
            // nothing
            LOG.error("Unhandled sereco annotation type:{}, value:{}, sechub job uuid: {}", annotationType, annotationValue, sechubJobUUID);
    }
}
Also used : SecHubMessage(com.mercedesbenz.sechub.commons.model.SecHubMessage) SerecoAnnotationType(com.mercedesbenz.sechub.sereco.metadata.SerecoAnnotationType)

Aggregations

SecHubMessage (com.mercedesbenz.sechub.commons.model.SecHubMessage)3 SecHubFinding (com.mercedesbenz.sechub.commons.model.SecHubFinding)1 SecHubReportModel (com.mercedesbenz.sechub.commons.model.SecHubReportModel)1 SerecoAnnotationType (com.mercedesbenz.sechub.sereco.metadata.SerecoAnnotationType)1 Test (org.junit.Test)1 Test (org.junit.jupiter.api.Test)1