use of ca.corefacility.bioinformatics.irida.model.user.group.UserGroup in project irida by phac-nml.
the class UpdateUserGroupPermissionTest method testRejectNotInGroup.
@Test
public void testRejectNotInGroup() {
final String username = "user";
final User u = new User();
final User u2 = new User();
final UserGroup ug = new UserGroup("group");
u.setUsername(username);
when(userRepository.loadUserByUsername(username)).thenReturn(u);
when(userRepository.findOne(1L)).thenReturn(u);
when(userGroupRepository.findOne(1L)).thenReturn(ug);
when(userGroupJoinRepository.findUsersInGroup(ug)).thenReturn(ImmutableList.of(new UserGroupJoin(u2, ug, UserGroupRole.GROUP_OWNER)));
final Authentication auth = new UsernamePasswordAuthenticationToken(username, "password1");
assertFalse("permission should not be granted.", updateUserPermission.isAllowed(auth, 1L));
}
use of ca.corefacility.bioinformatics.irida.model.user.group.UserGroup in project irida by phac-nml.
the class ProjectServiceImplIT method testRemoveUserGroupOnProject.
@Test(expected = ProjectWithoutOwnerException.class)
@WithMockUser(username = "groupuser", roles = "USER")
public void testRemoveUserGroupOnProject() throws ProjectWithoutOwnerException {
final UserGroup userGroup = userGroupService.read(1L);
final Project project = projectService.read(9L);
projectService.removeUserGroupFromProject(project, userGroup);
}
use of ca.corefacility.bioinformatics.irida.model.user.group.UserGroup in project irida by phac-nml.
the class ProjectServiceImplIT method testUpdateUserGroupRoleOnProject.
@Test(expected = ProjectWithoutOwnerException.class)
@WithMockUser(username = "groupuser", roles = "USER")
public void testUpdateUserGroupRoleOnProject() throws ProjectWithoutOwnerException {
final UserGroup userGroup = userGroupService.read(1L);
final Project project = projectService.read(9L);
projectService.updateUserGroupProjectRole(project, userGroup, ProjectRole.PROJECT_USER);
}
use of ca.corefacility.bioinformatics.irida.model.user.group.UserGroup in project irida by phac-nml.
the class ProjectServiceImplTest method testGetProjectsForUser.
@Test
public void testGetProjectsForUser() {
final User u = new User();
final Project p1 = new Project("p1");
final Project p2 = new Project("p2");
final UserGroup ug = new UserGroup("group");
final ProjectUserJoin puj = new ProjectUserJoin(p1, u, ProjectRole.PROJECT_OWNER);
final UserGroupProjectJoin ugpj = new UserGroupProjectJoin(p2, ug, ProjectRole.PROJECT_OWNER);
when(pujRepository.getProjectsForUser(u)).thenReturn(ImmutableList.of(puj));
when(ugpjRepository.findProjectsByUser(u)).thenReturn(ImmutableList.of(ugpj));
final List<Join<Project, User>> projects = projectService.getProjectsForUser(u);
assertEquals("User should be in 2 projects.", 2, projects.size());
assertTrue("Should have found user project join.", projects.stream().anyMatch(p -> p.getSubject().equals(p1)));
assertTrue("Should have found group project join.", projects.stream().anyMatch(p -> p.getSubject().equals(p2)));
}
use of ca.corefacility.bioinformatics.irida.model.user.group.UserGroup in project irida by phac-nml.
the class UserGroupServiceImplIT method testCreateAndEditGroup.
@Test
@WithMockUser(username = "differentUser", roles = "USER")
public void testCreateAndEditGroup() {
final UserGroup ug = new UserGroup("new group");
final User u = userService.read(2L);
final User u2 = userService.read(3L);
userGroupService.create(ug);
// now we should check that we're part of the group:
final Collection<UserGroupJoin> groupUsers = userGroupService.getUsersForGroup(ug);
assertTrue("Should be in the group after creating it.", groupUsers.stream().anyMatch(j -> j.getSubject().equals(u)));
// and then also check that we can edit the group
ug.setName("not new group");
userGroupService.update(ug);
// and add users to the group
userGroupService.addUserToGroup(u2, ug, UserGroupRole.GROUP_MEMBER);
}
Aggregations