use of com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc in project sechub by mercedes-benz.
the class SchedulerRestControllerRestDocTest method restDoc_userUploadsBinaries.
@Test
@UseCaseRestDoc(useCase = UseCaseUserUploadsBinaries.class)
public void restDoc_userUploadsBinaries() throws Exception {
/* prepare */
String apiEndpoint = https(PORT_USED).buildUploadBinariesUrl(PROJECT_ID.pathElement(), JOB_UUID.pathElement());
Class<? extends Annotation> useCase = UseCaseUserUploadsBinaries.class;
ScheduleSecHubJob job = new ScheduleSecHubJob() {
public UUID getUUID() {
return randomUUID;
}
};
job.setExecutionResult(ExecutionResult.OK);
job.setStarted(LocalDateTime.now().minusMinutes(15));
job.setEnded(LocalDateTime.now());
job.setExecutionState(ExecutionState.INITIALIZING);
job.setOwner("CREATOR1");
job.setTrafficLight(TrafficLight.GREEN);
ScheduleJobStatus status = new ScheduleJobStatus(job);
when(mockedScheduleJobStatusService.getJobStatus(PROJECT1_ID, randomUUID)).thenReturn(status);
InputStream inputStreamTo = RestDocTestFileSupport.getTestfileSupport().getInputStreamTo("upload/tarfile_contains_only_test1.txt.tar");
MockMultipartFile file1 = new MockMultipartFile("file", inputStreamTo);
/* execute + test @formatter:off */
this.mockMvc.perform(multipart(apiEndpoint, PROJECT1_ID, randomUUID).file(file1).param("checkSum", "mychecksum")).andExpect(status().isOk()).andDo(defineRestService().with().useCaseData(useCase).tag(RestDocFactory.extractTag(apiEndpoint)).and().document(pathParameters(parameterWithName("projectId").description("The id of the project for which the binaries are uploaded for"), parameterWithName("jobUUID").description(DESCRIPTION_JOB_UUID)), requestParameters(parameterWithName("checkSum").description("A sha256 checksum for file upload validation")), // See: https://github.com/ePages-de/restdocs-api-spec/issues/105
requestParts(partWithName("file").description("The binaries as tarfile to upload"))));
/* @formatter:on */
}
use of com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc in project sechub by mercedes-benz.
the class SchedulerRestControllerRestDocTest method restDoc_userCreatesNewJob_codescan.
@Test
@UseCaseRestDoc(useCase = UseCaseUserCreatesNewJob.class, variant = "Code Scan")
public void restDoc_userCreatesNewJob_codescan() throws Exception {
/* prepare */
String apiEndpoint = https(PORT_USED).buildAddJobUrl(PROJECT_ID.pathElement());
Class<? extends Annotation> useCase = UseCaseUserCreatesNewJob.class;
UUID randomUUID = UUID.randomUUID();
SchedulerResult mockResult = new SchedulerResult(randomUUID);
when(mockedScheduleCreateJobService.createJob(any(), any(SecHubConfiguration.class))).thenReturn(mockResult);
/* execute + test @formatter:off */
this.mockMvc.perform(post(apiEndpoint, PROJECT1_ID).contentType(MediaType.APPLICATION_JSON_VALUE).content(configureSecHub().api("1.0").codeScanConfig().setFileSystemFolders("testproject1/src/main/java", "testproject2/src/main/java").build().toJSON())).andExpect(status().isOk()).andExpect(content().json("{jobId:" + randomUUID.toString() + "}")).andDo(print()).andDo(defineRestService().with().useCaseData(useCase, "Code Scan").tag(RestDocFactory.extractTag(apiEndpoint)).requestSchema(OpenApiSchema.SCAN_JOB.getSchema()).responseSchema(OpenApiSchema.JOB_ID.getSchema()).and().document(pathParameters(parameterWithName(PROJECT_ID.paramName()).description("The unique id of the project id where a new sechub job shall be created")), requestFields(fieldWithPath(PROPERTY_API_VERSION).description("The api version, currently only 1.0 is supported"), fieldWithPath(PROPERTY_CODE_SCAN).description("Code scan configuration block").optional(), fieldWithPath(PROPERTY_CODE_SCAN + "." + SecHubDataConfigurationUsageByName.PROPERTY_USE).description("Referenced data configuration objects by their unique names").optional(), fieldWithPath(PROPERTY_CODE_SCAN + "." + SecHubCodeScanConfiguration.PROPERTY_FILESYSTEM + "." + SecHubFileSystemConfiguration.PROPERTY_FOLDERS).description("Code scan sources from given file system folders").optional(), fieldWithPath(PROPERTY_CODE_SCAN + "." + SecHubCodeScanConfiguration.PROPERTY_FILESYSTEM + "." + SecHubFileSystemConfiguration.PROPERTY_FILES).description("Code scan sources from given file system files").optional()), responseFields(fieldWithPath(SchedulerResult.PROPERTY_JOBID).description("A unique job id"))));
/* @formatter:on */
}
use of com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc in project sechub by mercedes-benz.
the class SchedulerRestControllerRestDocTest method restDoc_userUploadsSourceCode.
@Test
@UseCaseRestDoc(useCase = UseCaseUserUploadsSourceCode.class)
public void restDoc_userUploadsSourceCode() throws Exception {
/* prepare */
String apiEndpoint = https(PORT_USED).buildUploadSourceCodeUrl(PROJECT_ID.pathElement(), JOB_UUID.pathElement());
Class<? extends Annotation> useCase = UseCaseUserUploadsSourceCode.class;
ScheduleSecHubJob job = new ScheduleSecHubJob() {
public UUID getUUID() {
return randomUUID;
}
};
job.setExecutionResult(ExecutionResult.OK);
job.setStarted(LocalDateTime.now().minusMinutes(15));
job.setEnded(LocalDateTime.now());
job.setExecutionState(ExecutionState.INITIALIZING);
job.setOwner("CREATOR1");
job.setTrafficLight(TrafficLight.GREEN);
ScheduleJobStatus status = new ScheduleJobStatus(job);
when(mockedScheduleJobStatusService.getJobStatus(PROJECT1_ID, randomUUID)).thenReturn(status);
InputStream inputStreamTo = RestDocTestFileSupport.getTestfileSupport().getInputStreamTo("upload/zipfile_contains_only_test1.txt.zip");
MockMultipartFile file1 = new MockMultipartFile("file", inputStreamTo);
/* execute + test @formatter:off */
this.mockMvc.perform(multipart(apiEndpoint, PROJECT1_ID, randomUUID).file(file1).param("checkSum", "mychecksum")).andExpect(status().isOk()).andDo(defineRestService().with().useCaseData(useCase).tag(RestDocFactory.extractTag(apiEndpoint)).and().document(pathParameters(parameterWithName("projectId").description("The id of the project where sourcecode shall be uploaded for"), parameterWithName("jobUUID").description(DESCRIPTION_JOB_UUID)), requestParameters(parameterWithName("checkSum").description("A sha256 checksum for file upload validation")), // See: https://github.com/ePages-de/restdocs-api-spec/issues/105
requestParts(partWithName("file").description("The sourcecode as zipfile to upload"))));
/* @formatter:on */
}
use of com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc in project sechub by mercedes-benz.
the class SchedulerRestControllerRestDocTest method restDoc_userCreatesNewJob_webscan_login_basic.
@Test
@UseCaseRestDoc(useCase = UseCaseUserCreatesNewJob.class, variant = "Web Scan login basic")
public void restDoc_userCreatesNewJob_webscan_login_basic() throws Exception {
/* prepare */
String apiEndpoint = https(PORT_USED).buildAddJobUrl(PROJECT_ID.pathElement());
Class<? extends Annotation> useCase = UseCaseUserCreatesNewJob.class;
UUID randomUUID = UUID.randomUUID();
SchedulerResult mockResult = new SchedulerResult(randomUUID);
when(mockedScheduleCreateJobService.createJob(any(), any(SecHubConfiguration.class))).thenReturn(mockResult);
/* execute + test @formatter:off */
this.mockMvc.perform(post(apiEndpoint, PROJECT1_ID).contentType(MediaType.APPLICATION_JSON_VALUE).content(configureSecHub().api("1.0").webConfig().addURI("https://localhost/mywebapp").login("https://localhost/mywebapp/login").basic("username1", "password1").build().toJSON())).andExpect(status().isOk()).andExpect(content().json("{jobId:" + randomUUID.toString() + "}")).andDo(defineRestService().with().useCaseData(useCase, "Web Scan login basic").tag(RestDocFactory.extractTag(apiEndpoint)).requestSchema(OpenApiSchema.SCAN_JOB.getSchema()).responseSchema(OpenApiSchema.JOB_ID.getSchema()).and().document(pathParameters(parameterWithName(PROJECT_ID.paramName()).description("The unique id of the project id where a new sechub job shall be created")), requestFields(fieldWithPath(PROPERTY_API_VERSION).description("The api version, currently only 1.0 is supported"), fieldWithPath(PROPERTY_WEB_SCAN).description("Webscan configuration block").optional(), fieldWithPath(PROPERTY_WEB_SCAN + "." + SecHubWebScanConfiguration.PROPERTY_URI).description("Webscan URI to scan for").optional(), fieldWithPath(PROPERTY_WEB_SCAN + "." + SecHubWebScanConfiguration.PROPERTY_LOGIN).description("Webscan login definition").optional(), fieldWithPath(PROPERTY_WEB_SCAN + "." + SecHubWebScanConfiguration.PROPERTY_LOGIN + ".url").description("Login URL").optional(), fieldWithPath(PROPERTY_WEB_SCAN + "." + SecHubWebScanConfiguration.PROPERTY_LOGIN + "." + WebLoginConfiguration.PROPERTY_BASIC).description("basic login definition").optional(), fieldWithPath(PROPERTY_WEB_SCAN + "." + SecHubWebScanConfiguration.PROPERTY_LOGIN + "." + WebLoginConfiguration.PROPERTY_BASIC + ".user").description("username").optional(), fieldWithPath(PROPERTY_WEB_SCAN + "." + SecHubWebScanConfiguration.PROPERTY_LOGIN + "." + WebLoginConfiguration.PROPERTY_BASIC + ".password").description("password").optional()), responseFields(fieldWithPath(SchedulerResult.PROPERTY_JOBID).description("A unique job id"))));
/* @formatter:on */
}
use of com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc in project sechub by mercedes-benz.
the class SignupAdministrationRestControllerRestDocTest method restdoc_list_user_signups.
@Test
@UseCaseRestDoc(useCase = UseCaseAdminListsOpenUserSignups.class)
public void restdoc_list_user_signups() throws Exception {
/* prepare */
String apiEndpoint = https(PORT_USED).buildAdminListsUserSignupsUrl();
Class<? extends Annotation> useCase = UseCaseAdminListsOpenUserSignups.class;
Signup signup1 = new Signup();
signup1.setEmailAdress("john.smith@example.com");
signup1.setUserId("johnsmith");
Signup signup2 = new Signup();
signup2.setEmailAdress("jane.smith@example.com");
signup2.setUserId("janesmith");
List<Signup> signupList = new ArrayList<>();
signupList.add(signup1);
signupList.add(signup2);
when(signupRepository.findAll()).thenReturn(signupList);
/* execute + test @formatter:off */
this.mockMvc.perform(get(apiEndpoint)).andExpect(status().isOk()).andExpect(content().json("[{\"userId\":\"johnsmith\",\"emailAdress\":\"john.smith@example.com\"},{\"userId\":\"janesmith\",\"emailAdress\":\"jane.smith@example.com\"}]")).andDo(defineRestService().with().useCaseData(useCase).tag(RestDocFactory.extractTag(apiEndpoint)).responseSchema(OpenApiSchema.SIGNUP_LIST.getSchema()).and().document(responseFields(fieldWithPath("[]").description("List of user signups").optional(), fieldWithPath("[]." + RestDocPathParameter.USER_ID.paramName()).type(JsonFieldType.STRING).description("The user id"), fieldWithPath("[].emailAdress").type(JsonFieldType.STRING).description("The email address"))));
/* @formatter:on */
}
Aggregations