Search in sources :

Example 36 with UseCaseRestDoc

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 */
}
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)

Example 37 with UseCaseRestDoc

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();
        }
    }
}
Also used : UseCaseRestDoc(com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc) Method(java.lang.reflect.Method)

Aggregations

UseCaseRestDoc (com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc)37 Test (org.junit.Test)35 WebMvcTest (org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)35 UUID (java.util.UUID)17 WithMockUser (org.springframework.security.test.context.support.WithMockUser)7 SchedulerResult (com.mercedesbenz.sechub.domain.schedule.SchedulerResult)5 SecHubConfiguration (com.mercedesbenz.sechub.sharedkernel.configuration.SecHubConfiguration)5 UseCaseUserCreatesNewJob (com.mercedesbenz.sechub.sharedkernel.usecases.user.execute.UseCaseUserCreatesNewJob)5 TestExecutorConfig (com.mercedesbenz.sechub.test.executorconfig.TestExecutorConfig)5 ScheduleJobStatus (com.mercedesbenz.sechub.domain.schedule.ScheduleJobStatus)4 ScheduleSecHubJob (com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob)4 TestExecutorSetupJobParam (com.mercedesbenz.sechub.test.executorconfig.TestExecutorSetupJobParam)4 Project (com.mercedesbenz.sechub.domain.administration.project.Project)3 User (com.mercedesbenz.sechub.domain.administration.user.User)3 TestExecutionProfile (com.mercedesbenz.sechub.test.executionprofile.TestExecutionProfile)3 AdministrationAutoCleanupConfig (com.mercedesbenz.sechub.domain.administration.autocleanup.AdministrationAutoCleanupConfig)2 ProjectDetailInformation (com.mercedesbenz.sechub.domain.administration.project.ProjectDetailInformation)2 ProjectMetaDataEntity (com.mercedesbenz.sechub.domain.administration.project.ProjectMetaDataEntity)2 FalsePositiveJobData (com.mercedesbenz.sechub.domain.scan.project.FalsePositiveJobData)2 ScanMockData (com.mercedesbenz.sechub.domain.scan.project.ScanMockData)2