Search in sources :

Example 1 with ScanReport

use of com.mercedesbenz.sechub.domain.scan.report.ScanReport in project sechub by mercedes-benz.

the class ScanReportRestControllerRestDocTest method get_report_from_existing_job_returns_information_as_json_when_type_is_APPLICATION_JSON_UTF8.

@UseCaseRestDoc(useCase = UseCaseUserDownloadsJobReport.class, variant = "JSON", wanted = { SpringRestDocOutput.PATH_PARAMETERS, SpringRestDocOutput.REQUEST_FIELDS, SpringRestDocOutput.CURL_REQUEST })
@Test
@WithMockUser
public void get_report_from_existing_job_returns_information_as_json_when_type_is_APPLICATION_JSON_UTF8() throws Exception {
    /* prepare */
    String apiEndpoint = https(PORT_USED).buildGetJobReportUrl(PROJECT_ID.pathElement(), JOB_UUID.pathElement());
    Class<? extends Annotation> useCase = UseCaseUserDownloadsJobReport.class;
    ScanReport report = new ScanReport(jobUUID, PROJECT1_ID);
    report.setResult("{'count':'1'}");
    report.setTrafficLight(TrafficLight.YELLOW);
    ScanSecHubReport scanSecHubReport = new ScanSecHubReport(report);
    when(downloadReportService.getScanSecHubReport(PROJECT1_ID, jobUUID)).thenReturn(scanSecHubReport);
    /* execute + test @formatter:off */
    this.mockMvc.perform(get(apiEndpoint, PROJECT1_ID, jobUUID).accept(MediaType.APPLICATION_JSON_VALUE).contentType(MediaType.APPLICATION_JSON_VALUE)).andExpect(status().isOk()).andExpect(content().json("{\"jobUUID\":\"" + jobUUID.toString() + "\",\"result\":{\"count\":0,\"findings\":[]},\"trafficLight\":\"YELLOW\"}")).andDo(defineRestService().with().useCaseData(useCase, "JSON").tag(RestDocFactory.extractTag(apiEndpoint)).responseSchema(OpenApiSchema.SECHUB_REPORT.getSchema()).and().document(pathParameters(parameterWithName(PROJECT_ID.paramName()).description("The project Id"), parameterWithName(JOB_UUID.paramName()).description("The job UUID"))));
/* @formatter:on */
}
Also used : ScanSecHubReport(com.mercedesbenz.sechub.domain.scan.report.ScanSecHubReport) ScanReport(com.mercedesbenz.sechub.domain.scan.report.ScanReport) UseCaseUserDownloadsJobReport(com.mercedesbenz.sechub.sharedkernel.usecases.user.execute.UseCaseUserDownloadsJobReport) WithMockUser(org.springframework.security.test.context.support.WithMockUser) UseCaseRestDoc(com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc) Test(org.junit.Test) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)

Example 2 with ScanReport

use of com.mercedesbenz.sechub.domain.scan.report.ScanReport in project sechub by mercedes-benz.

the class ScanReportRestControllerRestDocTest method get_report_from_existing_job_returns_information_as_html_when_type_is_APPLICATION_XHTML_XML.

@UseCaseRestDoc(useCase = UseCaseUserDownloadsJobReport.class, variant = "HTML", wanted = { SpringRestDocOutput.PATH_PARAMETERS, SpringRestDocOutput.REQUEST_FIELDS, SpringRestDocOutput.CURL_REQUEST })
@Test
@WithMockUser
public void get_report_from_existing_job_returns_information_as_html_when_type_is_APPLICATION_XHTML_XML() throws Exception {
    /* prepare */
    String apiEndpoint = https(PORT_USED).buildGetJobReportUrl(PROJECT_ID.pathElement(), JOB_UUID.pathElement());
    Class<? extends Annotation> useCase = UseCaseUserDownloadsJobReport.class;
    ScanReport report = new ScanReport(jobUUID, PROJECT1_ID);
    report.setResult("{'count':'1'}");
    report.setTrafficLight(TrafficLight.YELLOW);
    ScanSecHubReport scanSecHubReport = new ScanSecHubReport(report);
    when(downloadReportService.getScanSecHubReport(PROJECT1_ID, jobUUID)).thenReturn(scanSecHubReport);
    /* execute + test @formatter:off */
    this.mockMvc.perform(get(apiEndpoint, PROJECT1_ID, jobUUID).accept(MediaType.APPLICATION_XHTML_XML).contentType(MediaType.APPLICATION_JSON_VALUE)).andExpect(status().isOk()).andExpect(content().contentType("text/html;charset=UTF-8")).andExpect(content().encoding("UTF-8")).andExpect(content().string(containsString(jobUUID.toString()))).andExpect(content().string(containsString("theRedStyle"))).andDo(defineRestService().with().useCaseData(useCase, "HTML").tag(RestDocFactory.extractTag(apiEndpoint)).responseSchema(OpenApiSchema.SECHUB_REPORT.getSchema()).and().document(pathParameters(parameterWithName(PROJECT_ID.paramName()).description("The project Id"), parameterWithName(JOB_UUID.paramName()).description("The job UUID"))));
/* @formatter:on */
}
Also used : ScanSecHubReport(com.mercedesbenz.sechub.domain.scan.report.ScanSecHubReport) ScanReport(com.mercedesbenz.sechub.domain.scan.report.ScanReport) UseCaseUserDownloadsJobReport(com.mercedesbenz.sechub.sharedkernel.usecases.user.execute.UseCaseUserDownloadsJobReport) WithMockUser(org.springframework.security.test.context.support.WithMockUser) UseCaseRestDoc(com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc) Test(org.junit.Test) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)

Example 3 with ScanReport

use of com.mercedesbenz.sechub.domain.scan.report.ScanReport in project sechub by mercedes-benz.

the class ScanReportRestControllerMockTest method get_report_from_existing_job_returns_406_NOT_ACCEPTABLE__when_type_is_APPLICATION_PDF.

@Test
@WithMockUser
public void get_report_from_existing_job_returns_406_NOT_ACCEPTABLE__when_type_is_APPLICATION_PDF() throws Exception {
    /* prepare */
    ScanReport scanReport = new ScanReport(randomUUID, PROJECT1_ID);
    scanReport.setResult("{'count':'1'}");
    scanReport.setTrafficLight(TrafficLight.YELLOW);
    ScanSecHubReport scanSecHubReport = new ScanSecHubReport(scanReport);
    when(downloadReportService.getScanSecHubReport(PROJECT1_ID, randomUUID)).thenReturn(scanSecHubReport);
    /* execute + test @formatter:off */
    this.mockMvc.perform(get(https(PORT_USED).buildGetJobReportUrl(PROJECT1_ID, randomUUID)).accept(MediaType.APPLICATION_PDF).contentType(MediaType.APPLICATION_JSON_VALUE)).andExpect(status().isNotAcceptable());
/* @formatter:on */
}
Also used : ScanSecHubReport(com.mercedesbenz.sechub.domain.scan.report.ScanSecHubReport) ScanReport(com.mercedesbenz.sechub.domain.scan.report.ScanReport) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)

Example 4 with ScanReport

use of com.mercedesbenz.sechub.domain.scan.report.ScanReport in project sechub by mercedes-benz.

the class ScanReportRestControllerMockTest method internalTestAcceptedAndReturnsJSON.

private void internalTestAcceptedAndReturnsJSON(MediaType acceptedType) throws Exception {
    /* prepare */
    ScanReport report = new ScanReport(randomUUID, PROJECT1_ID);
    report.setResult("{'count':'1'}");
    report.setTrafficLight(TrafficLight.YELLOW);
    ScanSecHubReport scanSecHubReport = new ScanSecHubReport(report);
    when(downloadReportService.getScanSecHubReport(PROJECT1_ID, randomUUID)).thenReturn(scanSecHubReport);
    /* execute + test @formatter:off */
    this.mockMvc.perform(get(https(PORT_USED).buildGetJobReportUrl(PROJECT1_ID, randomUUID)).accept(acceptedType).contentType(MediaType.APPLICATION_JSON_VALUE)).andExpect(status().isOk()).andExpect(content().json("{\"jobUUID\":\"" + randomUUID.toString() + "\",\"result\":{\"count\":0,\"findings\":[]},\"trafficLight\":\"YELLOW\"}"));
/* @formatter:on */
}
Also used : ScanSecHubReport(com.mercedesbenz.sechub.domain.scan.report.ScanSecHubReport) ScanReport(com.mercedesbenz.sechub.domain.scan.report.ScanReport)

Example 5 with ScanReport

use of com.mercedesbenz.sechub.domain.scan.report.ScanReport in project sechub by mercedes-benz.

the class ScanReportRestControllerMockTest method internalTestAcceptedAndReturnsHTML.

private void internalTestAcceptedAndReturnsHTML(MediaType acceptedType) throws Exception {
    /* prepare */
    ScanReport report = new ScanReport(randomUUID, PROJECT1_ID);
    report.setResult("{'count':'1'}");
    report.setTrafficLight(TrafficLight.YELLOW);
    ScanSecHubReport scanSecHubReport = new ScanSecHubReport(report);
    when(downloadReportService.getScanSecHubReport(PROJECT1_ID, randomUUID)).thenReturn(scanSecHubReport);
    /* execute + test @formatter:off */
    this.mockMvc.perform(get(https(PORT_USED).buildGetJobReportUrl(PROJECT1_ID, randomUUID)).accept(acceptedType).contentType(MediaType.APPLICATION_JSON_VALUE)).andDo(print()).andExpect(status().isOk()).andExpect(content().contentType("text/html;charset=UTF-8")).andExpect(content().encoding("UTF-8")).andExpect(content().string(containsString(randomUUID.toString()))).andExpect(content().string(containsString("theRedStyle")));
/* @formatter:on */
}
Also used : ScanSecHubReport(com.mercedesbenz.sechub.domain.scan.report.ScanSecHubReport) ScanReport(com.mercedesbenz.sechub.domain.scan.report.ScanReport)

Aggregations

ScanReport (com.mercedesbenz.sechub.domain.scan.report.ScanReport)7 ScanSecHubReport (com.mercedesbenz.sechub.domain.scan.report.ScanSecHubReport)6 Test (org.junit.Test)3 WebMvcTest (org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)3 WithMockUser (org.springframework.security.test.context.support.WithMockUser)3 UseCaseRestDoc (com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc)2 UseCaseUserDownloadsJobReport (com.mercedesbenz.sechub.sharedkernel.usecases.user.execute.UseCaseUserDownloadsJobReport)2 JSONConverterException (com.mercedesbenz.sechub.commons.model.JSONConverterException)1 ScanReportException (com.mercedesbenz.sechub.domain.scan.report.ScanReportException)1 NotFoundException (com.mercedesbenz.sechub.sharedkernel.error.NotFoundException)1 SecHubExecutionAbandonedException (com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionAbandonedException)1 SecHubExecutionContext (com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext)1 SecHubExecutionException (com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionException)1 DomainMessageSynchronousResult (com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessageSynchronousResult)1 IsSendingSyncMessageAnswer (com.mercedesbenz.sechub.sharedkernel.messaging.IsSendingSyncMessageAnswer)1 IOException (java.io.IOException)1 UUID (java.util.UUID)1