Search in sources :

Example 1 with Project

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

the class UserRepositoryDBTest method user_NOT_being_owner_of_project_but_listed_as_user_can_be_deleted__and_project_is_NOT_deleted.

@Test
public void user_NOT_being_owner_of_project_but_listed_as_user_can_be_deleted__and_project_is_NOT_deleted() throws Exception {
    /* prepare */
    Project project = TestProjectCreationFactory.createProject("project_repo_test3", user2);
    project.getUsers().add(user1);
    project.getWhiteList().add(new URI("http://www.example.org"));
    entityManager.persist(project);
    entityManager.persist(user1);
    prepareForDBTest();
    /* execute */
    userRepository.deleteUserWithAssociations(user1.getName());
    prepareForDBTest();
    assertProjectFound(project);
    assertUserNotFound(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)

Example 2 with Project

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

the class UserRepositoryDBTest method user_being_owner_of_project_and_also_listed_as_user_can_NOT_be_deleted_instead_a_notacceptable_exception_is_thrown.

@Test
public void user_being_owner_of_project_and_also_listed_as_user_can_NOT_be_deleted_instead_a_notacceptable_exception_is_thrown() {
    /* test */
    expected.expect(NotAcceptableException.class);
    expected.expectMessage("still owner of a project");
    /* prepare */
    Project project = TestProjectCreationFactory.createProject("project_repo_test2", user1);
    project.getUsers().add(user1);
    entityManager.persist(project);
    prepareForDBTest();
    /* execute */
    userRepository.deleteUserWithAssociations(user1.getName());
}
Also used : Project(com.mercedesbenz.sechub.domain.administration.project.Project) Test(org.junit.Test) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)

Example 3 with Project

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

the class ProjectRepositoryDBTest method project_with_owner_and_users_can_be_deleted.

@Test
public void project_with_owner_and_users_can_be_deleted() {
    /* prepare */
    Project project = TestProjectCreationFactory.createProject("project_repo_test2", user1);
    project.getUsers().add(user1);
    entityManager.persist(project);
    prepareForDBTest();
    /* execute */
    projectRepository.deleteProjectWithAssociations(project.getId());
    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 4 with Project

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

the class UserRepositoryDBTest method user_being_owner_of_project_can_NOT_be_deleted__instead_a_notaccetable_exception_is_thrown.

@Test
public void user_being_owner_of_project_can_NOT_be_deleted__instead_a_notaccetable_exception_is_thrown() {
    /* test */
    expected.expect(NotAcceptableException.class);
    expected.expectMessage("still owner of a project");
    /* prepare */
    Project project = TestProjectCreationFactory.createProject("project_repo_test1", user1);
    entityManager.persist(project);
    /* execute */
    userRepository.deleteUserWithAssociations(user1.getName());
}
Also used : Project(com.mercedesbenz.sechub.domain.administration.project.Project) Test(org.junit.Test) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)

Example 5 with Project

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

the class UserAdministrationRestControllerMockTest method show_user_details_returns_result_of_detail_service.

@Test
public void show_user_details_returns_result_of_detail_service() throws Exception {
    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(mockedUserDetailInformationService.fetchDetails("user1")).thenReturn(info);
    /* execute + test @formatter:off */
    this.mockMvc.perform(get(https(PORT_USED).buildAdminShowsUserDetailsUrl("user1"))).andExpect(status().isOk()).andExpect(jsonPath("$.userId", equalTo("user1"))).andExpect(jsonPath("$.email", equalTo("user1@example.org"))).andExpect(jsonPath("$.projects", equalTo(Arrays.asList("project1"))));
/* @formatter:on */
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Project(com.mercedesbenz.sechub.domain.administration.project.Project) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)

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