Search in sources :

Example 1 with SecHubResult

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

the class ScanSecHubReportTest method scanreport_result_by_report_model_does_not_recalculates_traffic_light_but_uses_report_traffic_light.

@Test
void scanreport_result_by_report_model_does_not_recalculates_traffic_light_but_uses_report_traffic_light() {
    /* prepare */
    SecHubResult result = new SecHubResult();
    SecHubFinding finding = new SecHubFinding();
    finding.setName("finding1");
    finding.setSeverity(Severity.CRITICAL);
    result.getFindings().add(finding);
    ScanReport report = new ScanReport();
    report.setResult(result.toJSON());
    report.setTrafficLight(TrafficLight.GREEN);
    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(TrafficLight.GREEN, reportToTest.getTrafficLight());
}
Also used : SecHubFinding(com.mercedesbenz.sechub.commons.model.SecHubFinding) SecHubResult(com.mercedesbenz.sechub.commons.model.SecHubResult) Test(org.junit.jupiter.api.Test)

Example 2 with SecHubResult

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

the class ScanSecHubReportTest method scanreport_result_recaclulates_count.

@Test
void scanreport_result_recaclulates_count() {
    /* prepare */
    SecHubResult result = new SecHubResult();
    SecHubFinding finding1 = new SecHubFinding();
    finding1.setName("finding1");
    SecHubFinding finding2 = new SecHubFinding();
    finding2.setName("finding2");
    List<SecHubFinding> findings = result.getFindings();
    findings.add(finding1);
    findings.add(finding2);
    result.setCount(1000);
    ScanReport report = new ScanReport();
    report.setResult(result.toJSON());
    /* execute */
    ScanSecHubReport reportToTest = new ScanSecHubReport(report);
    /* test */
    assertEquals(2, reportToTest.getResult().getCount());
}
Also used : SecHubFinding(com.mercedesbenz.sechub.commons.model.SecHubFinding) SecHubResult(com.mercedesbenz.sechub.commons.model.SecHubResult) Test(org.junit.jupiter.api.Test)

Example 3 with SecHubResult

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

the class ScanSecHubReportTest method scanreport_result_with_report_containing_sechub_result_init_and_json_parts_work.

@Test
void scanreport_result_with_report_containing_sechub_result_init_and_json_parts_work() {
    /* prepare */
    SecHubResult result = new SecHubResult();
    SecHubFinding finding = new SecHubFinding();
    finding.setName("finding1");
    result.getFindings().add(finding);
    ScanReport report = new ScanReport();
    report.setResult(result.toJSON());
    report.setTrafficLight(TrafficLight.YELLOW);
    report.setResultType(ScanReportResultType.RESULT);
    /* 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 */
    // no status available from simple result, expecting OK
    assertEquals(SecHubStatus.SUCCESS, reportToTest.getStatus());
    assertEquals(TrafficLight.YELLOW, reportToTest.getTrafficLight());
    assertEquals(0, reportToTest.getMessages().size());
    assertEquals(1, reportToTest.getResult().getFindings().size());
    assertEquals(1, reportToTest.getResult().getCount());
}
Also used : SecHubFinding(com.mercedesbenz.sechub.commons.model.SecHubFinding) SecHubResult(com.mercedesbenz.sechub.commons.model.SecHubResult) Test(org.junit.jupiter.api.Test)

Example 4 with SecHubResult

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

the class ScanSecHubReportTest method scanreport_result_by_reesult_does_NOT_set_version.

@Test
void scanreport_result_by_reesult_does_NOT_set_version() {
    /* prepare */
    SecHubResult result = new SecHubResult();
    ScanReport report = new ScanReport();
    report.setResult(result.toJSON());
    report.setResultType(ScanReportResultType.RESULT);
    /* execute */
    ScanSecHubReport createdReport = new ScanSecHubReport(report);
    /* test */
    assertEquals(null, createdReport.getReportVersion());
}
Also used : SecHubResult(com.mercedesbenz.sechub.commons.model.SecHubResult) Test(org.junit.jupiter.api.Test)

Example 5 with SecHubResult

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

the class AssertReport method assertFindings.

private List<SecHubFinding> assertFindings(SecHubReportData report) {
    assertNotNull("Report may not be null", report);
    SecHubResult result = report.getResult();
    assertNotNull(result);
    List<SecHubFinding> findings = result.getFindings();
    assertNotNull(findings);
    return findings;
}
Also used : SecHubFinding(com.mercedesbenz.sechub.commons.model.SecHubFinding) SecHubResult(com.mercedesbenz.sechub.commons.model.SecHubResult)

Aggregations

SecHubResult (com.mercedesbenz.sechub.commons.model.SecHubResult)11 SecHubFinding (com.mercedesbenz.sechub.commons.model.SecHubFinding)8 Test (org.junit.jupiter.api.Test)5 ReportTransformationResult (com.mercedesbenz.sechub.domain.scan.ReportTransformationResult)2 SecHubCodeCallStack (com.mercedesbenz.sechub.commons.model.SecHubCodeCallStack)1 TrafficLight (com.mercedesbenz.sechub.commons.model.TrafficLight)1 AssertSecHubResult (com.mercedesbenz.sechub.domain.scan.AssertSecHubResult)1 SecHubReportProductTransformerService (com.mercedesbenz.sechub.domain.scan.SecHubReportProductTransformerService)1 ReportProductExecutionService (com.mercedesbenz.sechub.domain.scan.product.ReportProductExecutionService)1 SecHubConfiguration (com.mercedesbenz.sechub.sharedkernel.configuration.SecHubConfiguration)1 SecHubExecutionContext (com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext)1 File (java.io.File)1 HashMap (java.util.HashMap)1 List (java.util.List)1 UUID (java.util.UUID)1 Before (org.junit.Before)1 Test (org.junit.Test)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1