Search in sources :

Example 56 with Project

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

the class ProjectServiceImplTest method testGetProjectsForSample.

@Test
public void testGetProjectsForSample() {
    Sample sample = new Sample("my sample");
    @SuppressWarnings("unchecked") List<Join<Project, Sample>> projects = Lists.newArrayList(new ProjectSampleJoin(new Project("p1"), sample, true), new ProjectSampleJoin(new Project("p2"), sample, true));
    when(psjRepository.getProjectForSample(sample)).thenReturn(projects);
    List<Join<Project, Sample>> projectsForSample = projectService.getProjectsForSample(sample);
    assertEquals(2, projectsForSample.size());
    verify(psjRepository).getProjectForSample(sample);
}
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) ProjectReferenceFileJoin(ca.corefacility.bioinformatics.irida.model.project.ProjectReferenceFileJoin) RelatedProjectJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin) 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) UserGroupProjectJoin(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupProjectJoin) Test(org.junit.Test)

Example 57 with Project

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

the class ProjectServiceImplTest method testCreateProject.

@Test
public void testCreateProject() {
    // The currently logged-in user should be added to the project when it's
    // created.
    Project p = project();
    String username = "fbristow";
    User u = new User();
    u.setUsername(username);
    Authentication auth = new UsernamePasswordAuthenticationToken(u, null);
    SecurityContextHolder.getContext().setAuthentication(auth);
    when(projectRepository.save(p)).thenReturn(p);
    when(userRepository.loadUserByUsername(username)).thenReturn(u);
    projectService.create(p);
    verify(projectRepository).save(p);
    verify(userRepository).loadUserByUsername(username);
    SecurityContextHolder.getContext().setAuthentication(null);
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) User(ca.corefacility.bioinformatics.irida.model.user.User) Authentication(org.springframework.security.core.Authentication) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) Test(org.junit.Test)

Example 58 with Project

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

the class ProjectServiceImplTest method testAddReferenceFileToProject.

@Test
public void testAddReferenceFileToProject() throws IOException {
    Project p = new Project();
    Path createTempFile = Files.createTempFile(null, null);
    ReferenceFile f = new ReferenceFile(createTempFile);
    when(referenceFileRepository.save(f)).thenReturn(f);
    projectService.addReferenceFileToProject(p, f);
    verify(referenceFileRepository).save(f);
    verify(prfjRepository).save(new ProjectReferenceFileJoin(p, f));
}
Also used : Path(java.nio.file.Path) Project(ca.corefacility.bioinformatics.irida.model.project.Project) ReferenceFile(ca.corefacility.bioinformatics.irida.model.project.ReferenceFile) ProjectReferenceFileJoin(ca.corefacility.bioinformatics.irida.model.project.ProjectReferenceFileJoin) Test(org.junit.Test)

Example 59 with Project

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

the class SampleServiceImplTest method testMergeSamples.

@Test
public void testMergeSamples() {
    // For every sample in toMerge, the service should:
    // 1. call SequenceFileRepository to get the sequence files in that
    // sample,
    // 2. call SequenceFileRepository to add the sequence files to
    // mergeInto,
    // 3. call SampleRepository to persist the sample as deleted.
    final int SIZE = 3;
    Sample s = s(1L);
    Project project = p(1L);
    Sample[] toMerge = new Sample[SIZE];
    SequenceFile[] toMerge_sf = new SequenceFile[SIZE];
    SequencingObject[] toMerge_so = new SequencingObject[SIZE];
    SampleSequencingObjectJoin[] s_so_joins = new SampleSequencingObjectJoin[SIZE];
    SampleSequencingObjectJoin[] s_so_original = new SampleSequencingObjectJoin[SIZE];
    ProjectSampleJoin[] p_s_joins = new ProjectSampleJoin[SIZE];
    List<Sample> mergeSamples = new ArrayList<>();
    for (long i = 0; i < SIZE; i++) {
        int p = (int) i;
        toMerge[p] = s(i + 2);
        mergeSamples.add(toMerge[p]);
        toMerge_sf[p] = sf(i + 2);
        toMerge_so[p] = so(i + 2);
        s_so_joins[p] = new SampleSequencingObjectJoin(s, toMerge_so[p]);
        p_s_joins[p] = new ProjectSampleJoin(project, toMerge[p], true);
        List<Join<Project, Sample>> projectSampleJoins = new ArrayList<>();
        projectSampleJoins.add(p_s_joins[p]);
        List<SampleSequencingObjectJoin> sampleSeqObjectJoins = new ArrayList<>();
        SampleSequencingObjectJoin join = new SampleSequencingObjectJoin(toMerge[p], toMerge_so[p]);
        sampleSeqObjectJoins.add(join);
        s_so_original[p] = join;
        when(ssoRepository.getSequencesForSample(toMerge[p])).thenReturn(null);
        when(ssoRepository.getSequencesForSample(toMerge[p])).thenReturn(sampleSeqObjectJoins);
        when(ssoRepository.save(s_so_joins[p])).thenReturn(s_so_joins[p]);
        when(ssoRepository.readObjectForSample(toMerge[p], toMerge_so[p].getId())).thenReturn(join);
        when(psjRepository.getProjectForSample(toMerge[p])).thenReturn(projectSampleJoins);
        // for deletion
        when(psjRepository.readSampleForProject(project, toMerge[p])).thenReturn(p_s_joins[p]);
    }
    List<Join<Project, Sample>> joins = new ArrayList<>();
    joins.add(new ProjectSampleJoin(project, s, true));
    when(psjRepository.getProjectForSample(s)).thenReturn(joins);
    Sample saved = sampleService.mergeSamples(project, s, mergeSamples);
    verify(psjRepository).getProjectForSample(s);
    for (int i = 0; i < SIZE; i++) {
        verify(ssoRepository).getSequencesForSample(toMerge[i]);
        verify(ssoRepository).save(s_so_joins[i]);
        verify(ssoRepository).delete(s_so_original[i]);
        verify(sampleRepository).delete(toMerge[i].getId());
        verify(psjRepository).getProjectForSample(toMerge[i]);
        verify(psjRepository).delete(p_s_joins[i]);
    }
    assertEquals("The saved sample should be the same as the sample to merge into.", s, saved);
}
Also used : SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) 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) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) Project(ca.corefacility.bioinformatics.irida.model.project.Project) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) Test(org.junit.Test)

Example 60 with Project

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

the class TestDataFactory method constructProject.

/**
 * Construct a simple {@link ca.corefacility.bioinformatics.irida.model.Project}.
 *
 * @return a project with a name and identifier.
 */
public static Project constructProject() {
    Project p = new Project();
    p.setId(1L);
    return p;
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project)

Aggregations

Project (ca.corefacility.bioinformatics.irida.model.project.Project)331 Test (org.junit.Test)190 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)120 User (ca.corefacility.bioinformatics.irida.model.user.User)88 WithMockUser (org.springframework.security.test.context.support.WithMockUser)80 ProjectSampleJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin)71 Join (ca.corefacility.bioinformatics.irida.model.joins.Join)62 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)51 RelatedProjectJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin)37 ArrayList (java.util.ArrayList)34 ProjectUserJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin)30 SampleSequencingObjectJoin (ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)30 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)27 ProjectRole (ca.corefacility.bioinformatics.irida.model.enums.ProjectRole)25 ReferenceFile (ca.corefacility.bioinformatics.irida.model.project.ReferenceFile)23 ProjectEvent (ca.corefacility.bioinformatics.irida.model.event.ProjectEvent)22 ProjectAnalysisSubmissionJoin (ca.corefacility.bioinformatics.irida.model.workflow.submission.ProjectAnalysisSubmissionJoin)22 List (java.util.List)22 UserRoleSetProjectEvent (ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent)21 ImmutableMap (com.google.common.collect.ImmutableMap)21