Search in sources :

Example 36 with ProjectSampleJoin

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

the class CartControllerTest method testAddProject.

@Test
public void testAddProject() {
    Map<String, Object> addProject = controller.addProject(projectId);
    assertTrue((boolean) addProject.get("success"));
    List<Join<Project, Sample>> joins = new ArrayList<>();
    samples.forEach((s) -> {
        joins.add(new ProjectSampleJoin(project, s, true));
    });
    when(sampleService.getSamplesForProject(project)).thenReturn(joins);
    verify(projectService).read(projectId);
    verify(sampleService).getSamplesForProject(project);
    Map<Project, Set<Sample>> selected = controller.getSelected();
    assertEquals(1, selected.keySet().size());
    Project projectKey = selected.keySet().iterator().next();
    assertEquals(project, projectKey);
    for (Sample s : selected.get(projectKey)) {
        assertTrue(sampleIds.contains(s.getId()));
    }
}
Also used : ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) Project(ca.corefacility.bioinformatics.irida.model.project.Project) HashSet(java.util.HashSet) Set(java.util.Set) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) ArrayList(java.util.ArrayList) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) Test(org.junit.Test)

Example 37 with ProjectSampleJoin

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

the class CartControllerTest method testData.

private void testData() {
    projectId = 1L;
    sampleIds = Sets.newHashSet(2L, 3L);
    project = new Project("project");
    project.setId(projectId);
    samples = new HashSet<>();
    when(projectService.read(projectId)).thenReturn(project);
    for (Long id : sampleIds) {
        Sample sample = new Sample("sample" + id);
        sample.setId(id);
        samples.add(sample);
        when(sampleService.getSampleForProject(project, id)).thenReturn(new ProjectSampleJoin(project, sample, true));
    }
}
Also used : ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) Project(ca.corefacility.bioinformatics.irida.model.project.Project) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample)

Example 38 with ProjectSampleJoin

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

the class ReadSequencingObjectPermissionTest method testRejectPermission.

@Test
public void testRejectPermission() {
    Project p = new Project();
    Sample s = new Sample();
    List<Join<Project, Sample>> projectSampleList = new ArrayList<>();
    projectSampleList.add(new ProjectSampleJoin(p, s, true));
    SingleEndSequenceFile sf = new SingleEndSequenceFile(null);
    SampleSequencingObjectJoin join = new SampleSequencingObjectJoin(s, sf);
    when(psjRepository.getProjectForSample(s)).thenReturn(projectSampleList);
    when(sequencingObjectRepository.findOne(1L)).thenReturn(sf);
    when(ssoRepository.getSampleForSequencingObject(sf)).thenReturn(join);
    when(readProjectPermission.isAllowed(any(), eq(p))).thenReturn(false);
    Authentication auth = new UsernamePasswordAuthenticationToken("fbristow", "password1");
    assertFalse("permission was granted.", permission.isAllowed(auth, 1L));
    verify(sequencingObjectRepository).findOne(1L);
    verify(psjRepository).getProjectForSample(s);
    verify(ssoRepository).getSampleForSequencingObject(sf);
    verify(readProjectPermission).isAllowed(any(), eq(p));
}
Also used : ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) Project(ca.corefacility.bioinformatics.irida.model.project.Project) 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) ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) Test(org.junit.Test)

Example 39 with ProjectSampleJoin

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

the class ReadSequencingObjectPermissionTest method testGrantPermission.

@Test
public void testGrantPermission() {
    Project p = new Project();
    Sample s = new Sample();
    List<Join<Project, Sample>> projectSampleList = new ArrayList<>();
    projectSampleList.add(new ProjectSampleJoin(p, s, true));
    SingleEndSequenceFile sf = new SingleEndSequenceFile(null);
    SampleSequencingObjectJoin join = new SampleSequencingObjectJoin(s, sf);
    when(psjRepository.getProjectForSample(s)).thenReturn(projectSampleList);
    when(sequencingObjectRepository.findOne(1L)).thenReturn(sf);
    when(ssoRepository.getSampleForSequencingObject(sf)).thenReturn(join);
    when(readProjectPermission.isAllowed(any(), eq(p))).thenReturn(true);
    Authentication auth = new UsernamePasswordAuthenticationToken("fbristow", "password1");
    assertTrue("permission was not granted.", permission.isAllowed(auth, 1L));
    verify(sequencingObjectRepository).findOne(1L);
    verify(psjRepository).getProjectForSample(s);
    verify(ssoRepository).getSampleForSequencingObject(sf);
    verify(readProjectPermission).isAllowed(any(), eq(p));
}
Also used : ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) Project(ca.corefacility.bioinformatics.irida.model.project.Project) 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) ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) Test(org.junit.Test)

Example 40 with ProjectSampleJoin

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

the class ReadSamplePermissionTest method testRejectPermission.

@Test
public void testRejectPermission() {
    String username = "fbristow";
    User u = new User();
    u.setUsername(username);
    Project p = new Project();
    Sample s = new Sample();
    List<Join<Project, Sample>> projectSampleList = new ArrayList<>();
    projectSampleList.add(new ProjectSampleJoin(p, s, true));
    List<Join<Project, User>> projectUsers = new ArrayList<>();
    projectUsers.add(new ProjectUserJoin(p, new User(), ProjectRole.PROJECT_USER));
    when(psjRepository.getProjectForSample(s)).thenReturn(projectSampleList);
    when(sampleRepository.findOne(1L)).thenReturn(s);
    when(readProjectPermission.isAllowed(any(), eq(p))).thenReturn(false);
    Authentication auth = new UsernamePasswordAuthenticationToken("fbristow", "password1");
    assertFalse("permission was granted.", readSamplePermission.isAllowed(auth, 1L));
    verify(sampleRepository).findOne(1L);
    verify(psjRepository).getProjectForSample(s);
}
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

ProjectSampleJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin)59 Project (ca.corefacility.bioinformatics.irida.model.project.Project)51 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)51 Test (org.junit.Test)43 Join (ca.corefacility.bioinformatics.irida.model.joins.Join)15 SampleSequencingObjectJoin (ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)15 ArrayList (java.util.ArrayList)11 SequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)8 SingleEndSequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)8 WithMockUser (org.springframework.security.test.context.support.WithMockUser)8 User (ca.corefacility.bioinformatics.irida.model.user.User)7 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)7 Authentication (org.springframework.security.core.Authentication)7 Transactional (org.springframework.transaction.annotation.Transactional)7 EntityExistsException (ca.corefacility.bioinformatics.irida.exceptions.EntityExistsException)6 SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)6 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)6 LaunchesProjectEvent (ca.corefacility.bioinformatics.irida.events.annotations.LaunchesProjectEvent)5 EntityNotFoundException (ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException)5 RelatedProjectJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin)5