use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin in project irida by phac-nml.
the class ProjectsControllerTest method getUsersForProjectByRole.
private List<Join<Project, User>> getUsersForProjectByRole() {
List<Join<Project, User>> list = new ArrayList<>();
list.add(new ProjectUserJoin(getProject(), user, ProjectRole.PROJECT_OWNER));
return list;
}
use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin in project irida by phac-nml.
the class ProjectsControllerTest method mockSidebarInfo.
/**
* Mocks the information found within the project sidebar.
*/
private void mockSidebarInfo() {
Project project = getProject();
Collection<Join<Project, User>> ownerList = new ArrayList<>();
ownerList.add(new ProjectUserJoin(project, user, ProjectRole.PROJECT_OWNER));
when(userService.getUsersForProjectByRole(any(Project.class), any(ProjectRole.class))).thenReturn(ownerList);
when(projectService.read(PROJECT_ID)).thenReturn(project);
when(userService.getUserByUsername(anyString())).thenReturn(user);
}
use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin in project irida by phac-nml.
the class ReadProjectPermissionTest method testGrantPermission.
@Test
public void testGrantPermission() {
String username = "fbristow";
User u = new User();
u.setUsername(username);
Project p = new Project();
List<Join<Project, User>> projectUsers = new ArrayList<>();
projectUsers.add(new ProjectUserJoin(p, u, ProjectRole.PROJECT_USER));
when(userRepository.loadUserByUsername(username)).thenReturn(u);
when(projectRepository.findOne(1L)).thenReturn(p);
when(pujRepository.getUsersForProject(p)).thenReturn(projectUsers);
Authentication auth = new UsernamePasswordAuthenticationToken("fbristow", "password1");
assertTrue("permission was not granted.", readProjectPermission.isAllowed(auth, 1L));
verify(userRepository).loadUserByUsername(username);
verify(projectRepository).findOne(1L);
verify(pujRepository).getUsersForProject(p);
}
use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin in project irida by phac-nml.
the class ReadSamplePermissionTest method testGrantPermissionWithDomainObject.
@Test
public void testGrantPermissionWithDomainObject() {
String username = "fbristow";
User u = new User();
u.setUsername(username);
Project p = new Project();
Sample s = new Sample();
List<Join<Project, User>> projectUsers = new ArrayList<>();
projectUsers.add(new ProjectUserJoin(p, u, ProjectRole.PROJECT_USER));
List<Join<Project, Sample>> projectSampleList = new ArrayList<>();
projectSampleList.add(new ProjectSampleJoin(p, s, true));
when(psjRepository.getProjectForSample(s)).thenReturn(projectSampleList);
when(sampleRepository.findOne(1L)).thenReturn(s);
when(readProjectPermission.isAllowed(any(), eq(p))).thenReturn(true);
Authentication auth = new UsernamePasswordAuthenticationToken("fbristow", "password1");
assertTrue("permission was not granted.", readSamplePermission.isAllowed(auth, s));
verify(psjRepository).getProjectForSample(s);
// we didn't need to load the domain object for this test.
verifyZeroInteractions(sampleRepository);
}
use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin in project irida by phac-nml.
the class ReadSamplePermissionTest method testGrantPermission.
@Test
public void testGrantPermission() {
String username = "fbristow";
User u = new User();
u.setUsername(username);
Project p = new Project();
Sample s = new Sample();
List<Join<Project, User>> projectUsers = new ArrayList<>();
projectUsers.add(new ProjectUserJoin(p, u, ProjectRole.PROJECT_USER));
List<Join<Project, Sample>> projectSampleList = new ArrayList<>();
projectSampleList.add(new ProjectSampleJoin(p, s, true));
when(psjRepository.getProjectForSample(s)).thenReturn(projectSampleList);
when(sampleRepository.findOne(1L)).thenReturn(s);
when(readProjectPermission.isAllowed(any(), eq(p))).thenReturn(true);
Authentication auth = new UsernamePasswordAuthenticationToken("fbristow", "password1");
assertTrue("permission was not granted.", readSamplePermission.isAllowed(auth, 1L));
verify(sampleRepository).findOne(1L);
verify(psjRepository).getProjectForSample(s);
verify(readProjectPermission).isAllowed(any(), eq(p));
}
Aggregations