use of com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc in project sechub by mercedes-benz.
the class UserAdministrationRestControllerRestDocTest method restdoc_show_user_details.
@Test
@UseCaseRestDoc(useCase = UseCaseAdminShowsUserDetails.class)
public void restdoc_show_user_details() throws Exception {
/* prepare */
String apiEndpoint = https(PORT_USED).buildAdminShowsUserDetailsUrl(USER_ID.pathElement());
Class<? extends Annotation> useCase = UseCaseAdminShowsUserDetails.class;
User user = mock(User.class);
when(user.getName()).thenReturn("user1");
when(user.getEmailAdress()).thenReturn("user1@example.org");
Set<Project> projects = new LinkedHashSet<>();
Project project1 = mock(Project.class);
when(project1.getId()).thenReturn("project1");
projects.add(project1);
when(user.getProjects()).thenReturn(projects);
UserDetailInformation info = new UserDetailInformation(user);
when(userDetailService.fetchDetails("user1")).thenReturn(info);
/* execute + test @formatter:off */
this.mockMvc.perform(get(apiEndpoint, "user1")).andExpect(status().isOk()).andDo(defineRestService().with().useCaseData(useCase).tag(RestDocFactory.extractTag(apiEndpoint)).responseSchema(OpenApiSchema.USER_DETAILS.getSchema()).and().document(pathParameters(parameterWithName(USER_ID.paramName()).description("The user id of user to show details for")), responseFields(fieldWithPath(UserDetailInformation.PROPERTY_USERNAME).description("The name of the user"), fieldWithPath(UserDetailInformation.PROPERTY_EMAIL).description("The mail adress of the user"), fieldWithPath(UserDetailInformation.PROPERTY_SUPERADMIN).description("True, when this user is a super administrator"), fieldWithPath(UserDetailInformation.PROPERTY_PROJECTS).description("The projects the user has access to"), fieldWithPath(UserDetailInformation.PROPERTY_OWNED_PROJECTS).description("The projects the user is owner of"))));
/* @formatter:on */
}
use of com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc in project sechub by mercedes-benz.
the class UsecaseStepsWithRestDocAreDocumentedTest method fetchMethodsDocumentedWithUsecaseRestdocAnnotation.
private void fetchMethodsDocumentedWithUsecaseRestdocAnnotation(TestContext context, Reflections reflections, Map<Class<?>, InspData> map) {
Set<Method> restDocAnnotatedMethods = reflections.getMethodsAnnotatedWith(UseCaseRestDoc.class);
for (Method method : restDocAnnotatedMethods) {
UseCaseRestDoc restdoc = method.getAnnotation(UseCaseRestDoc.class);
Class<? extends Annotation> usecaseClass = restdoc.useCase();
InspData found = map.get(usecaseClass);
if (found == null) {
context.problems.append("\nUseCaseRestDoc found, but not tagged inside one of the steps of " + restdoc.useCase());
} else {
found.restDocFoundInc();
}
}
}
Aggregations