Search in sources :

Example 1 with SecHubReportModel

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

the class ScanSecHubReportTest method report_by_model_sets_jobUUID_from_scanreport_when_not_inside_model.

@Test
void report_by_model_sets_jobUUID_from_scanreport_when_not_inside_model() {
    /* prepare */
    UUID uuid = UUID.randomUUID();
    ScanReport report = mock(ScanReport.class);
    when(report.getResultType()).thenReturn(ScanReportResultType.MODEL);
    when(report.getSecHubJobUUID()).thenReturn(uuid);
    SecHubReportModel model = new SecHubReportModel();
    String jsonResult = model.toJSON();
    when(report.getResult()).thenReturn(jsonResult);
    /* execute */
    ScanSecHubReport createdReport = new ScanSecHubReport(report);
    /* test */
    assertEquals(uuid, createdReport.getJobUUID());
}
Also used : SecHubReportModel(com.mercedesbenz.sechub.commons.model.SecHubReportModel) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 2 with SecHubReportModel

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

the class ReportTrafficLightCalculatorTest method prepareSechubResultWithFindings.

/* +-----------------------------------------------------------------------+ */
/* +............................ Helpers ..................................+ */
/* +-----------------------------------------------------------------------+ */
private SecHubReportModel prepareSechubResultWithFindings(Severity... severities) {
    List<SecHubFinding> findingList = new ArrayList<>();
    for (Severity severity : severities) {
        SecHubFinding finding = new SecHubFinding();
        finding.setSeverity(severity);
        findingList.add(finding);
    }
    SecHubReportModel model = new SecHubReportModel();
    model.getResult().getFindings().addAll(findingList);
    return model;
}
Also used : SecHubReportModel(com.mercedesbenz.sechub.commons.model.SecHubReportModel) SecHubFinding(com.mercedesbenz.sechub.commons.model.SecHubFinding) ArrayList(java.util.ArrayList) Severity(com.mercedesbenz.sechub.commons.model.Severity)

Example 3 with SecHubReportModel

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

the class ScanSecHubReportTest method report_by_model_has_jobUUID_from_model_when_there_not_null.

@Test
void report_by_model_has_jobUUID_from_model_when_there_not_null() {
    /* prepare */
    UUID uuid1 = UUID.randomUUID();
    UUID uuid2 = UUID.randomUUID();
    ScanReport report = mock(ScanReport.class);
    when(report.getResultType()).thenReturn(ScanReportResultType.MODEL);
    when(report.getSecHubJobUUID()).thenReturn(uuid1);
    SecHubReportModel model = new SecHubReportModel();
    model.setJobUUID(uuid2);
    String jsonResult = model.toJSON();
    when(report.getResult()).thenReturn(jsonResult);
    /* execute */
    ScanSecHubReport createdReport = new ScanSecHubReport(report);
    /* test */
    assertEquals(uuid2, createdReport.getJobUUID());
}
Also used : SecHubReportModel(com.mercedesbenz.sechub.commons.model.SecHubReportModel) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 4 with SecHubReportModel

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

the class ScanSecHubReportTest method report_by_model_sets_version_to_version_from_model.

@Test
void report_by_model_sets_version_to_version_from_model() {
    /* prepare */
    SecHubReportModel model = new SecHubReportModel();
    model.setReportVersion("42.0");
    ScanReport report = new ScanReport();
    report.setResult(model.toJSON());
    report.setResultType(ScanReportResultType.MODEL);
    /* execute */
    ScanSecHubReport createdReport = new ScanSecHubReport(report);
    /* test */
    assertEquals("42.0", createdReport.getReportVersion());
}
Also used : SecHubReportModel(com.mercedesbenz.sechub.commons.model.SecHubReportModel) Test(org.junit.jupiter.api.Test)

Example 5 with SecHubReportModel

use of com.mercedesbenz.sechub.commons.model.SecHubReportModel 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)

Aggregations

SecHubReportModel (com.mercedesbenz.sechub.commons.model.SecHubReportModel)5 Test (org.junit.jupiter.api.Test)4 SecHubFinding (com.mercedesbenz.sechub.commons.model.SecHubFinding)2 UUID (java.util.UUID)2 SecHubMessage (com.mercedesbenz.sechub.commons.model.SecHubMessage)1 Severity (com.mercedesbenz.sechub.commons.model.Severity)1 ArrayList (java.util.ArrayList)1