Search in sources :

Example 21 with Join

use of ca.corefacility.bioinformatics.irida.model.joins.Join in project irida by phac-nml.

the class ProjectsControllerTest method getProjectsForUser.

private List<Join<Project, User>> getProjectsForUser() {
    List<Join<Project, User>> projects = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        Project p = new Project("project" + i);
        p.setId(1L + i);
        projects.add(new ProjectUserJoin(p, user, ProjectRole.PROJECT_USER));
    }
    return projects;
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) RelatedProjectJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin)

Example 22 with Join

use of ca.corefacility.bioinformatics.irida.model.joins.Join 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;
}
Also used : ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) RelatedProjectJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin)

Example 23 with Join

use of ca.corefacility.bioinformatics.irida.model.joins.Join 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);
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) RelatedProjectJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin) ProjectRole(ca.corefacility.bioinformatics.irida.model.enums.ProjectRole)

Example 24 with Join

use of ca.corefacility.bioinformatics.irida.model.joins.Join 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);
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) User(ca.corefacility.bioinformatics.irida.model.user.User) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) Authentication(org.springframework.security.core.Authentication) ArrayList(java.util.ArrayList) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) UserGroupJoin(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupJoin) UserGroupProjectJoin(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupProjectJoin) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) Test(org.junit.Test)

Example 25 with Join

use of ca.corefacility.bioinformatics.irida.model.joins.Join 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);
}
Also used : ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) Project(ca.corefacility.bioinformatics.irida.model.project.Project) User(ca.corefacility.bioinformatics.irida.model.user.User) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) Authentication(org.springframework.security.core.Authentication) ArrayList(java.util.ArrayList) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) Test(org.junit.Test)

Aggregations

Join (ca.corefacility.bioinformatics.irida.model.joins.Join)65 Project (ca.corefacility.bioinformatics.irida.model.project.Project)60 Test (org.junit.Test)40 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)35 User (ca.corefacility.bioinformatics.irida.model.user.User)35 ProjectSampleJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin)34 RelatedProjectJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin)26 ProjectUserJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin)23 ArrayList (java.util.ArrayList)20 WithMockUser (org.springframework.security.test.context.support.WithMockUser)20 ProjectAnalysisSubmissionJoin (ca.corefacility.bioinformatics.irida.model.workflow.submission.ProjectAnalysisSubmissionJoin)16 SampleSequencingObjectJoin (ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)14 ProjectRole (ca.corefacility.bioinformatics.irida.model.enums.ProjectRole)13 ReferenceFile (ca.corefacility.bioinformatics.irida.model.project.ReferenceFile)13 List (java.util.List)12 Set (java.util.Set)12 SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)11 Autowired (org.springframework.beans.factory.annotation.Autowired)11 ProjectSampleJoinRepository (ca.corefacility.bioinformatics.irida.repositories.joins.project.ProjectSampleJoinRepository)10 ProjectService (ca.corefacility.bioinformatics.irida.service.ProjectService)10