Search in sources :

Example 1 with UserDetailInformation

use of com.mercedesbenz.sechub.domain.administration.user.UserDetailInformation 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 */
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Project(com.mercedesbenz.sechub.domain.administration.project.Project) UseCaseAdminGrantsAdminRightsToUser(com.mercedesbenz.sechub.sharedkernel.usecases.admin.user.UseCaseAdminGrantsAdminRightsToUser) UseCaseAdminDeletesUser(com.mercedesbenz.sechub.sharedkernel.usecases.admin.user.UseCaseAdminDeletesUser) WithMockUser(org.springframework.security.test.context.support.WithMockUser) User(com.mercedesbenz.sechub.domain.administration.user.User) UserDetailInformation(com.mercedesbenz.sechub.domain.administration.user.UserDetailInformation) UseCaseAdminShowsUserDetails(com.mercedesbenz.sechub.sharedkernel.usecases.admin.user.UseCaseAdminShowsUserDetails) UseCaseRestDoc(com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest) Test(org.junit.Test)

Aggregations

Project (com.mercedesbenz.sechub.domain.administration.project.Project)1 User (com.mercedesbenz.sechub.domain.administration.user.User)1 UserDetailInformation (com.mercedesbenz.sechub.domain.administration.user.UserDetailInformation)1 UseCaseRestDoc (com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc)1 UseCaseAdminDeletesUser (com.mercedesbenz.sechub.sharedkernel.usecases.admin.user.UseCaseAdminDeletesUser)1 UseCaseAdminGrantsAdminRightsToUser (com.mercedesbenz.sechub.sharedkernel.usecases.admin.user.UseCaseAdminGrantsAdminRightsToUser)1 UseCaseAdminShowsUserDetails (com.mercedesbenz.sechub.sharedkernel.usecases.admin.user.UseCaseAdminShowsUserDetails)1 LinkedHashSet (java.util.LinkedHashSet)1 Test (org.junit.Test)1 WebMvcTest (org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)1 WithMockUser (org.springframework.security.test.context.support.WithMockUser)1