Search in sources :

Example 76 with User

use of ca.corefacility.bioinformatics.irida.model.user.User in project irida by phac-nml.

the class UserServiceImplIT method testUpdateOwnAccountSucceed.

@Test
@WithMockUser(username = "fbristow", roles = "MANAGER")
public void testUpdateOwnAccountSucceed() {
    String updatedPhoneNumber = "456-7890";
    Map<String, Object> properties = ImmutableMap.of("phoneNumber", (Object) updatedPhoneNumber);
    User updated = userService.updateFields(1L, properties);
    assertEquals("Phone number should be updated.", updatedPhoneNumber, updated.getPhoneNumber());
}
Also used : WithMockUser(org.springframework.security.test.context.support.WithMockUser) User(ca.corefacility.bioinformatics.irida.model.user.User) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 77 with User

use of ca.corefacility.bioinformatics.irida.model.user.User in project irida by phac-nml.

the class UserServiceImplIT method testGetUserByUsername.

@Test
@WithMockUser(username = "fbristow", roles = "MANAGER")
public void testGetUserByUsername() {
    String username = "fbristow";
    User u = userService.getUserByUsername(username);
    assertEquals("Username is wrong.", username, u.getUsername());
}
Also used : WithMockUser(org.springframework.security.test.context.support.WithMockUser) User(ca.corefacility.bioinformatics.irida.model.user.User) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 78 with User

use of ca.corefacility.bioinformatics.irida.model.user.User in project irida by phac-nml.

the class ProjectEventsControllerTest method testGetRecentEventsForUser.

@Test
public void testGetRecentEventsForUser() {
    ExtendedModelMap model = new ExtendedModelMap();
    ProjectEvent event = new UserRoleSetProjectEvent();
    Page<ProjectEvent> page = new PageImpl<>(Lists.newArrayList(event));
    User user = new User();
    Principal principal = () -> "username";
    when(userService.getUserByUsername(principal.getName())).thenReturn(user);
    when(eventService.getEventsForUser(eq(user), any(Pageable.class))).thenReturn(page);
    String recentEventsForProject = controller.getRecentEventsForUser(model, principal, 10);
    assertEquals(ProjectEventsController.EVENTS_VIEW, recentEventsForProject);
    assertTrue(model.containsAttribute("events"));
    @SuppressWarnings("unchecked") List<Map<String, Object>> events = (List<Map<String, Object>>) model.get("events");
    assertEquals(1, events.size());
    Map<String, Object> next = events.iterator().next();
    assertTrue(next.containsKey("name"));
    assertTrue(next.containsKey("event"));
    assertEquals(ProjectEventsController.FRAGMENT_NAMES.get(event.getClass()), next.get("name"));
    assertEquals(event, next.get("event"));
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) UserRoleSetProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent) User(ca.corefacility.bioinformatics.irida.model.user.User) Pageable(org.springframework.data.domain.Pageable) List(java.util.List) Map(java.util.Map) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) Principal(java.security.Principal) UserRoleSetProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent) ProjectEvent(ca.corefacility.bioinformatics.irida.model.event.ProjectEvent) Test(org.junit.Test)

Example 79 with User

use of ca.corefacility.bioinformatics.irida.model.user.User in project irida by phac-nml.

the class ProjectMembersControllerTest method testUdateUserSelfRole.

public void testUdateUserSelfRole() throws ProjectWithoutOwnerException {
    Long projectId = 1L;
    Long userId = 2L;
    Project project = new Project();
    User user = new User(userId, USER_NAME, null, null, "Tom", "Matthews", null);
    ProjectRole projectRole = ProjectRole.PROJECT_USER;
    when(projectService.read(projectId)).thenReturn(project);
    when(userService.read(userId)).thenReturn(user);
    when(messageSource.getMessage(any(), any(), any())).thenReturn("");
    final Map<String, String> result = controller.updateUserRole(projectId, userId, projectRole.toString(), null);
    assertTrue("should have failure message.", result.containsKey("failure"));
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) User(ca.corefacility.bioinformatics.irida.model.user.User) ProjectRole(ca.corefacility.bioinformatics.irida.model.enums.ProjectRole)

Example 80 with User

use of ca.corefacility.bioinformatics.irida.model.user.User in project irida by phac-nml.

the class ProjectMembersControllerTest method testAddProjectMember.

@Test
public void testAddProjectMember() {
    Long projectId = 1L;
    Long userId = 2L;
    Project project = new Project();
    User user = new User(userId, "tom", null, null, "Tom", "Matthews", null);
    ProjectRole projectRole = ProjectRole.PROJECT_USER;
    when(projectService.read(projectId)).thenReturn(project);
    when(userService.read(userId)).thenReturn(user);
    when(messageSource.getMessage(any(), any(), any())).thenReturn("My random string");
    controller.addProjectMember(projectId, userId, projectRole.toString(), Locale.US);
    verify(projectService).read(projectId);
    verify(userService).read(userId);
    verify(projectService).addUserToProject(project, user, projectRole);
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) User(ca.corefacility.bioinformatics.irida.model.user.User) ProjectRole(ca.corefacility.bioinformatics.irida.model.enums.ProjectRole) Test(org.junit.Test)

Aggregations

User (ca.corefacility.bioinformatics.irida.model.user.User)252 Test (org.junit.Test)153 Project (ca.corefacility.bioinformatics.irida.model.project.Project)84 WithMockUser (org.springframework.security.test.context.support.WithMockUser)57 Authentication (org.springframework.security.core.Authentication)45 Join (ca.corefacility.bioinformatics.irida.model.joins.Join)34 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)27 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)27 PageRequest (org.springframework.data.domain.PageRequest)26 UserGroup (ca.corefacility.bioinformatics.irida.model.user.group.UserGroup)25 ProjectRole (ca.corefacility.bioinformatics.irida.model.enums.ProjectRole)24 ProjectUserJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin)24 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)19 Principal (java.security.Principal)19 ProjectSampleJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin)18 RelatedProjectJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin)18 List (java.util.List)18 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)17 EntityNotFoundException (ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException)16 ArrayList (java.util.ArrayList)16