use of com.mercedesbenz.sechub.domain.administration.project.ProjectDetailInformation 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 */
}
use of com.mercedesbenz.sechub.domain.administration.project.ProjectDetailInformation in project sechub by mercedes-benz.
the class ProjectAdministrationRestControllerRestDocTest method restdoc_change_project_description.
@Test
@UseCaseRestDoc(useCase = UseCaseAdminChangesProjectDescription.class)
public void restdoc_change_project_description() throws Exception {
/* prepare */
String apiEndpoint = https(PORT_USED).buildAdminChangesProjectDescriptionUrl(PROJECT_ID.pathElement());
Class<? extends Annotation> useCase = UseCaseAdminChangesProjectDescription.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"));
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(detailsChangeService.changeProjectDescription(any(), any())).thenReturn(detailInformation);
/* execute + test @formatter:off */
this.mockMvc.perform(post(apiEndpoint, "projectId1").content("{\n" + " \"description\" : \"new description\"\n" + "}").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 change 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