Search in sources :

Example 6 with Project

use of com.mercedesbenz.sechub.domain.administration.project.Project 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 */
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Project(com.mercedesbenz.sechub.domain.administration.project.Project) UseCaseAdminAssignsUserToProject(com.mercedesbenz.sechub.sharedkernel.usecases.admin.user.UseCaseAdminAssignsUserToProject) UseCaseAdminCreatesProject(com.mercedesbenz.sechub.sharedkernel.usecases.admin.project.UseCaseAdminCreatesProject) UseCaseAdminDeleteProject(com.mercedesbenz.sechub.sharedkernel.usecases.admin.project.UseCaseAdminDeleteProject) UseCaseAdminUnassignsUserFromProject(com.mercedesbenz.sechub.sharedkernel.usecases.admin.user.UseCaseAdminUnassignsUserFromProject) WithMockUser(org.springframework.security.test.context.support.WithMockUser) User(com.mercedesbenz.sechub.domain.administration.user.User) UseCaseAdminShowsProjectDetails(com.mercedesbenz.sechub.sharedkernel.usecases.admin.project.UseCaseAdminShowsProjectDetails) URI(java.net.URI) ProjectMetaDataEntity(com.mercedesbenz.sechub.domain.administration.project.ProjectMetaDataEntity) ProjectDetailInformation(com.mercedesbenz.sechub.domain.administration.project.ProjectDetailInformation) UseCaseRestDoc(com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest) Test(org.junit.Test)

Example 7 with Project

use of com.mercedesbenz.sechub.domain.administration.project.Project 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 */
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Project(com.mercedesbenz.sechub.domain.administration.project.Project) UseCaseAdminAssignsUserToProject(com.mercedesbenz.sechub.sharedkernel.usecases.admin.user.UseCaseAdminAssignsUserToProject) UseCaseAdminCreatesProject(com.mercedesbenz.sechub.sharedkernel.usecases.admin.project.UseCaseAdminCreatesProject) UseCaseAdminDeleteProject(com.mercedesbenz.sechub.sharedkernel.usecases.admin.project.UseCaseAdminDeleteProject) UseCaseAdminUnassignsUserFromProject(com.mercedesbenz.sechub.sharedkernel.usecases.admin.user.UseCaseAdminUnassignsUserFromProject) WithMockUser(org.springframework.security.test.context.support.WithMockUser) User(com.mercedesbenz.sechub.domain.administration.user.User) UseCaseAdminChangesProjectDescription(com.mercedesbenz.sechub.sharedkernel.usecases.admin.project.UseCaseAdminChangesProjectDescription) URI(java.net.URI) ProjectMetaDataEntity(com.mercedesbenz.sechub.domain.administration.project.ProjectMetaDataEntity) ProjectDetailInformation(com.mercedesbenz.sechub.domain.administration.project.ProjectDetailInformation) UseCaseRestDoc(com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest) Test(org.junit.Test)

Example 8 with Project

use of com.mercedesbenz.sechub.domain.administration.project.Project 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 9 with Project

use of com.mercedesbenz.sechub.domain.administration.project.Project in project sechub by mercedes-benz.

the class ProjectRepositoryDBTest method project_with_owner_can_be_deleted.

@Test
public void project_with_owner_can_be_deleted() {
    /* prepare */
    Project project = TestProjectCreationFactory.createProject("project_repo_test1", user1);
    entityManager.persist(project);
    /* execute */
    projectRepository.deleteProjectWithAssociations(project.getId());
    /* test */
    prepareForDBTest();
    assertProjectNotFound(project);
    assertUserFound(user1);
}
Also used : Project(com.mercedesbenz.sechub.domain.administration.project.Project) Test(org.junit.Test) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)

Example 10 with Project

use of com.mercedesbenz.sechub.domain.administration.project.Project in project sechub by mercedes-benz.

the class ProjectRepositoryDBTest method project_with_owner_whitelists_and_users_can_be_deleted__user_still_exists.

@Test
public void project_with_owner_whitelists_and_users_can_be_deleted__user_still_exists() throws Exception {
    /* prepare */
    Project project = TestProjectCreationFactory.createProject("project_repo_test2", user1);
    project.getUsers().add(user1);
    project.getWhiteList().add(new URI("http://www.example.org"));
    entityManager.persist(project);
    entityManager.persist(user1);
    prepareForDBTest();
    /* execute */
    projectRepository.deleteProjectWithAssociations(project.getId());
    prepareForDBTest();
    assertProjectNotFound(project);
    assertUserFound(user1);
}
Also used : Project(com.mercedesbenz.sechub.domain.administration.project.Project) URI(java.net.URI) Test(org.junit.Test) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)

Aggregations

Project (com.mercedesbenz.sechub.domain.administration.project.Project)10 Test (org.junit.Test)10 DataJpaTest (org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)6 URI (java.net.URI)4 LinkedHashSet (java.util.LinkedHashSet)4 WebMvcTest (org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)4 WithMockUser (org.springframework.security.test.context.support.WithMockUser)4 User (com.mercedesbenz.sechub.domain.administration.user.User)3 UseCaseRestDoc (com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc)3 ProjectDetailInformation (com.mercedesbenz.sechub.domain.administration.project.ProjectDetailInformation)2 ProjectMetaDataEntity (com.mercedesbenz.sechub.domain.administration.project.ProjectMetaDataEntity)2 UseCaseAdminCreatesProject (com.mercedesbenz.sechub.sharedkernel.usecases.admin.project.UseCaseAdminCreatesProject)2 UseCaseAdminDeleteProject (com.mercedesbenz.sechub.sharedkernel.usecases.admin.project.UseCaseAdminDeleteProject)2 UseCaseAdminAssignsUserToProject (com.mercedesbenz.sechub.sharedkernel.usecases.admin.user.UseCaseAdminAssignsUserToProject)2 UseCaseAdminUnassignsUserFromProject (com.mercedesbenz.sechub.sharedkernel.usecases.admin.user.UseCaseAdminUnassignsUserFromProject)2 UserDetailInformation (com.mercedesbenz.sechub.domain.administration.user.UserDetailInformation)1 UseCaseAdminChangesProjectDescription (com.mercedesbenz.sechub.sharedkernel.usecases.admin.project.UseCaseAdminChangesProjectDescription)1 UseCaseAdminShowsProjectDetails (com.mercedesbenz.sechub.sharedkernel.usecases.admin.project.UseCaseAdminShowsProjectDetails)1 UseCaseAdminDeletesUser (com.mercedesbenz.sechub.sharedkernel.usecases.admin.user.UseCaseAdminDeletesUser)1 UseCaseAdminGrantsAdminRightsToUser (com.mercedesbenz.sechub.sharedkernel.usecases.admin.user.UseCaseAdminGrantsAdminRightsToUser)1