use of com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc in project sechub by mercedes-benz.
the class ProductExecutorConfigRestControllerRestDocTest method restdoc_admin_updates_executor_config.
@Test
@UseCaseRestDoc(useCase = UseCaseAdminUpdatesExecutorConfig.class)
public void restdoc_admin_updates_executor_config() throws Exception {
/* prepare */
String apiEndpoint = https(PORT_USED).buildAdminUpdatesProductExecutorConfig(UUID_PARAMETER.pathElement());
Class<? extends Annotation> useCase = UseCaseAdminUpdatesExecutorConfig.class;
UUID randomUUID = UUID.randomUUID();
TestExecutorConfig configFromUser = new TestExecutorConfig();
configFromUser.enabled = false;
configFromUser.name = "New name";
configFromUser.productIdentifier = ProductIdentifier.PDS_CODESCAN.name();
configFromUser.executorVersion = 1;
configFromUser.setup.baseURL = "https://productNew.example.com";
configFromUser.setup.credentials.user = "env:EXAMPLE_NEW_USENAME";
configFromUser.setup.credentials.password = "env:EXAMPLE_NEW_PASSWORD";
TestExecutorSetupJobParam param1 = new TestExecutorSetupJobParam("example.key1", "A value but changed. Remark: the other parameter (example.key2) has been removed by this call");
configFromUser.setup.jobParameters.add(param1);
/* execute + test @formatter:off */
this.mockMvc.perform(put(apiEndpoint, randomUUID).contentType(MediaType.APPLICATION_JSON_VALUE).content(JSONConverter.get().toJSON(configFromUser))).andExpect(status().isOk()).andDo(defineRestService().with().useCaseData(useCase).tag(RestDocFactory.extractTag(apiEndpoint)).requestSchema(OpenApiSchema.EXECUTOR_CONFIGURATION.getSchema()).and().document(requestFields(fieldWithPath(PROPERTY_NAME).description("The name of this configuration"), fieldWithPath(PROPERTY_PRODUCTIDENTIFIER).description("Executor product identifier"), fieldWithPath(PROPERTY_EXECUTORVERSION).description("Executor version"), fieldWithPath(PROPERTY_ENABLED).description("Enabled state of executor, per default false").optional(), fieldWithPath(PROPERTY_SETUP + "." + ProductExecutorConfigSetup.PROPERTY_BASEURL).description("Base URL to the product"), fieldWithPath(PROPERTY_SETUP + "." + ProductExecutorConfigSetup.PROPERTY_CREDENTIALS + "." + ProductExecutorConfigSetupCredentials.PROPERTY_USER).description(CREDENTIALS_USER_DESCRIPTION), fieldWithPath(PROPERTY_SETUP + "." + ProductExecutorConfigSetup.PROPERTY_CREDENTIALS + "." + ProductExecutorConfigSetupCredentials.PROPERTY_PASSWORD).description(CREDENTIALS_PWD_DESCRIPTION), fieldWithPath(PROPERTY_SETUP + "." + ProductExecutorConfigSetup.PROPERTY_JOBPARAMETERS + "[]." + ProductExecutorConfigSetupJobParameter.PROPERTY_KEY).description(JOBPARAM_KEY_DESCRIPTION).optional(), fieldWithPath(PROPERTY_SETUP + "." + ProductExecutorConfigSetup.PROPERTY_JOBPARAMETERS + "[]." + ProductExecutorConfigSetupJobParameter.PROPERTY_VALUE).description(JOBPARAM_VALUE_DESCRIPTION).optional()), pathParameters(parameterWithName(UUID_PARAMETER.paramName()).description("The configuration uuid"))));
/* @formatter:on */
}
use of com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc in project sechub by mercedes-benz.
the class UseCaseRestDocModelDataCollector method collect.
public UseCaseRestDocModel collect(UseCaseModel useCaseModel) {
if (DEBUG) {
LOG.info("start collecting");
}
UseCaseRestDocModel model = new UseCaseRestDocModel(useCaseModel);
Set<Method> annotatedMethods = reflections.getMethodsAnnotatedWith(UseCaseRestDoc.class);
if (annotatedMethods.size() == 0) {
throw new IllegalStateException("Criticial:Cannot generate REST documentation!\n" + "Reflections did not find any method annotated with @UseCaseRestDoc!\n" + "- If you started the collector from your IDE, please do not start directly, but instead start `AsciidocGeneratorManualTest.java`.\n" + " Doing this, the classpath will contain automatically all necessary resources.\n" + "- If you are inside a gradle build this is a criticial problem, because the documentation would not be generated correctly! ");
}
if (DEBUG) {
LOG.info("> will collect for:{} - {}", annotatedMethods.size(), annotatedMethods);
}
for (Method method : annotatedMethods) {
UseCaseRestDoc[] annos = method.getAnnotationsByType(UseCaseRestDoc.class);
if (annos.length == 0) {
continue;
}
if (annos.length > 1) {
throw new IllegalStateException("UseCaseRestDoc annotation may only added one time to test method!");
}
UseCaseRestDoc restDoc = annos[0];
Class<? extends Annotation> useCaseClass = restDoc.useCase();
if (DEBUG) {
LOG.info("inspect method:{}\n - usecase found:{}", method, useCaseClass);
}
UseCaseEntry useCaseEntry = useCaseModel.ensureUseCase(useCaseClass);
/* create and prepare rest doc entry */
UseCaseRestDocEntry restDocEntry = new UseCaseRestDocEntry();
restDocEntry.variantOriginValue = restDoc.variant();
restDocEntry.variantId = RestDocFactory.createVariantId(restDocEntry.variantOriginValue);
restDocEntry.usecaseEntry = useCaseEntry;
String path = RestDocFactory.createPath(useCaseClass, restDocEntry.variantId);
restDocEntry.identifier = RestDocFactory.createIdentifier(useCaseClass);
restDocEntry.path = path;
File projectRestDocGenFolder = scanForSpringRestDocGenFolder(restDocEntry);
restDocEntry.copiedRestDocFolder = copyToDocumentationProject(projectRestDocGenFolder, path);
restDocEntry.wanted = restDoc.wanted();
model.add(restDocEntry);
/* connect with usecase */
useCaseEntry.addLinkToRestDoc(restDocEntry);
}
return model;
}
use of com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc in project sechub by mercedes-benz.
the class ProductExecutorConfigRestControllerRestDocTest method restdoc_admin_creates_executor_config.
@Test
@UseCaseRestDoc(useCase = UseCaseAdminCreatesExecutorConfiguration.class)
public void restdoc_admin_creates_executor_config() throws Exception {
/* prepare */
String apiEndpoint = https(PORT_USED).buildAdminCreatesProductExecutorConfig();
Class<? extends Annotation> useCase = UseCaseAdminCreatesExecutorConfiguration.class;
UUID randomUUID = UUID.randomUUID();
when(createService.createProductExecutorConfig(any())).thenReturn(randomUUID.toString());
TestExecutorConfig configFromUser = new TestExecutorConfig();
configFromUser.enabled = false;
configFromUser.name = "PDS gosec config 1";
configFromUser.productIdentifier = ProductIdentifier.PDS_CODESCAN.name();
configFromUser.executorVersion = 1;
configFromUser.setup.baseURL = "https://productXYZ.example.com";
configFromUser.setup.credentials.user = "env:EXAMPLE_USENAME";
configFromUser.setup.credentials.password = "env:EXAMPLE_PASSWORD";
TestExecutorSetupJobParam param1 = new TestExecutorSetupJobParam("example.key1", "A value");
TestExecutorSetupJobParam param2 = new TestExecutorSetupJobParam("example.key2", "Another value");
configFromUser.setup.jobParameters.add(param1);
configFromUser.setup.jobParameters.add(param2);
/* execute + test @formatter:off */
this.mockMvc.perform(post(apiEndpoint).contentType(MediaType.APPLICATION_JSON_VALUE).content(JSONConverter.get().toJSON(configFromUser))).andExpect(status().isCreated()).andExpect(content().string(randomUUID.toString())).andDo(defineRestService().with().useCaseData(useCase).tag(RestDocFactory.extractTag(apiEndpoint)).responseSchema(OpenApiSchema.EXECUTOR_CONFIGURATION_ID.getSchema()).requestSchema(OpenApiSchema.EXECUTOR_CONFIGURATION.getSchema()).and().document(requestFields(fieldWithPath(PROPERTY_NAME).description("A name for this configuration"), fieldWithPath(PROPERTY_PRODUCTIDENTIFIER).description("Executor product identifier"), fieldWithPath(PROPERTY_EXECUTORVERSION).description("Executor version"), fieldWithPath(PROPERTY_ENABLED).description("Enabled state of executor, per default false").optional(), fieldWithPath(PROPERTY_SETUP + "." + ProductExecutorConfigSetup.PROPERTY_BASEURL).description("Base URL to the product"), fieldWithPath(PROPERTY_SETUP + "." + ProductExecutorConfigSetup.PROPERTY_CREDENTIALS + "." + ProductExecutorConfigSetupCredentials.PROPERTY_USER).description(CREDENTIALS_USER_DESCRIPTION), fieldWithPath(PROPERTY_SETUP + "." + ProductExecutorConfigSetup.PROPERTY_CREDENTIALS + "." + ProductExecutorConfigSetupCredentials.PROPERTY_PASSWORD).description(CREDENTIALS_PWD_DESCRIPTION), fieldWithPath(PROPERTY_SETUP + "." + ProductExecutorConfigSetup.PROPERTY_JOBPARAMETERS + "[]." + ProductExecutorConfigSetupJobParameter.PROPERTY_KEY).description(JOBPARAM_KEY_DESCRIPTION).optional(), fieldWithPath(PROPERTY_SETUP + "." + ProductExecutorConfigSetup.PROPERTY_JOBPARAMETERS + "[]." + ProductExecutorConfigSetupJobParameter.PROPERTY_VALUE).description(JOBPARAM_VALUE_DESCRIPTION).optional())));
/* @formatter:on */
}
use of com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc in project sechub by mercedes-benz.
the class ProductExecutorConfigRestControllerRestDocTest method restDoc_admin_deletes_executor_config.
@Test
@UseCaseRestDoc(useCase = UseCaseAdminDeletesExecutorConfiguration.class)
public void restDoc_admin_deletes_executor_config() throws Exception {
/* prepare */
String apiEndpoint = https(PORT_USED).buildAdminDeletesProductExecutorConfig(UUID_PARAMETER.pathElement());
Class<? extends Annotation> useCase = UseCaseAdminDeletesExecutorConfiguration.class;
/* execute + test @formatter:off */
UUID configUUID = UUID.randomUUID();
this.mockMvc.perform(delete(apiEndpoint, configUUID).contentType(MediaType.APPLICATION_JSON_VALUE)).andExpect(status().isOk()).andDo(defineRestService().with().useCaseData(useCase).tag(RestDocFactory.extractTag(apiEndpoint)).and().document(pathParameters(parameterWithName(UUID_PARAMETER.paramName()).description("The configuration uuid"))));
/* @formatter:on */
}
use of com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc in project sechub by mercedes-benz.
the class ProjectAdministrationRestControllerRestDocTest method restdoc_show_project_details.
@Test
@UseCaseRestDoc(useCase = UseCaseAdminShowsProjectDetails.class)
public void restdoc_show_project_details() throws Exception {
/* prepare */
String apiEndpoint = https(PORT_USED).buildAdminShowsProjectDetailsUrl(PROJECT_ID.pathElement());
Class<? extends Annotation> useCase = UseCaseAdminShowsProjectDetails.class;
Project project = mock(Project.class);
when(project.getId()).thenReturn("projectId1");
when(project.getAccessLevel()).thenReturn(ProjectAccessLevel.FULL);
Set<User> users = new LinkedHashSet<>();
User user1 = mock(User.class);
when(user1.getName()).thenReturn("name1");
User user2 = mock(User.class);
when(user2.getName()).thenReturn("name2");
users.add(user1);
users.add(user2);
when(project.getUsers()).thenReturn(users);
when(project.getOwner()).thenReturn(user1);
Set<URI> whiteList = new LinkedHashSet<>();
whiteList.add(new URI("http://www.sechub.example.org"));
whiteList.add(new URI("http://www.sechub.example.com"));
when(project.getWhiteList()).thenReturn(whiteList);
Set<ProjectMetaDataEntity> metaData = new LinkedHashSet<>();
ProjectMetaDataEntity entry = new ProjectMetaDataEntity("projectId1", "key1", "value1");
metaData.add(entry);
when(project.getMetaData()).thenReturn(metaData);
when(project.getDescription()).thenReturn("description");
ProjectDetailInformation detailInformation = new ProjectDetailInformation(project);
when(detailInformationService.fetchDetails("projectId1")).thenReturn(detailInformation);
/* execute + test @formatter:off */
this.mockMvc.perform(get(apiEndpoint, "projectId1").contentType(MediaType.APPLICATION_JSON_VALUE)).andDo(print()).andExpect(status().isOk()).andDo(defineRestService().with().useCaseData(useCase).tag(RestDocFactory.extractTag(apiEndpoint)).responseSchema(OpenApiSchema.PROJECT_DETAILS.getSchema()).and().document(pathParameters(parameterWithName(PROJECT_ID.paramName()).description("The id for project to show details for")), responseFields(fieldWithPath(ProjectDetailInformation.PROPERTY_PROJECT_ID).description("The name of the project"), fieldWithPath(ProjectDetailInformation.PROPERTY_USERS).description("A list of all users having access to the project"), fieldWithPath(ProjectDetailInformation.PROPERTY_OWNER).description("Username of the owner of this project. An owner is the person in charge."), fieldWithPath(ProjectDetailInformation.PROPERTY_WHITELIST).description("A list of all whitelisted URIs. Only these ones can be scanned for the project!"), fieldWithPath(ProjectDetailInformation.PROPERTY_METADATA).description("An JSON object containing metadata key-value pairs defined for this project."), fieldWithPath(ProjectDetailInformation.PROPERTY_METADATA + ".key1").description("An arbitrary metadata key"), fieldWithPath(ProjectDetailInformation.PROPERTY_ACCESSLEVEL).description("The project access level"), fieldWithPath(ProjectDetailInformation.PROPERTY_DESCRIPTION).description("The project description."))));
/* @formatter:on */
}
Aggregations