Search in sources :

Example 11 with ProjectSampleJoin

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

the class SampleSequenceFilesControllerTest method testAddNewSequenceFilePairToSampleMismatchedRunIDs.

@Test(expected = IllegalArgumentException.class)
public void testAddNewSequenceFilePairToSampleMismatchedRunIDs() throws IOException {
    Project p = TestDataFactory.constructProject();
    Sample s = TestDataFactory.constructSample();
    SequenceFilePair pair = TestDataFactory.constructSequenceFilePair();
    SampleSequencingObjectJoin sso = new SampleSequencingObjectJoin(s, pair);
    SequenceFileResource resource1 = new SequenceFileResource();
    SequenceFileResource resource2 = new SequenceFileResource();
    resource1.setMiseqRunId(1L);
    resource2.setMiseqRunId(2L);
    Path f1 = Files.createTempFile(null, null);
    Path f2 = Files.createTempFile(null, null);
    MockMultipartFile mmf1 = new MockMultipartFile("filename1", "filename1", "blurgh1", FileCopyUtils.copyToByteArray(f1.toFile()));
    MockMultipartFile mmf2 = new MockMultipartFile("filename2", "filename2", "blurgh2", FileCopyUtils.copyToByteArray(f2.toFile()));
    MockHttpServletResponse response = new MockHttpServletResponse();
    when(sampleService.getSampleForProject(p, s.getId())).thenReturn(new ProjectSampleJoin(p, s, true));
    when(sequencingObjectService.createSequencingObjectInSample(any(SequenceFilePair.class), Matchers.eq(s))).thenReturn(sso);
    controller.addNewSequenceFilePairToSample(s.getId(), mmf1, resource1, mmf2, resource2, response);
}
Also used : Path(java.nio.file.Path) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) Project(ca.corefacility.bioinformatics.irida.model.project.Project) SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) SequenceFileResource(ca.corefacility.bioinformatics.irida.web.assembler.resource.sequencefile.SequenceFileResource) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 12 with ProjectSampleJoin

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

the class AssemblyFileProcessorTest method testAssembleFile.

@Test
public void testAssembleFile() {
    Long sequenceFileId = 1L;
    SequenceFilePair pair = new SequenceFilePair(new SequenceFile(Paths.get("file_R1_1.fastq.gz")), new SequenceFile(Paths.get("file_R2_1.fastq.gz")));
    Sample sample = new Sample();
    Project project = new Project();
    project.setAssembleUploads(true);
    when(objectRepository.findOne(sequenceFileId)).thenReturn(pair);
    when(ssoRepository.getSampleForSequencingObject(pair)).thenReturn(new SampleSequencingObjectJoin(sample, pair));
    when(psjRepository.getProjectForSample(sample)).thenReturn(ImmutableList.of(new ProjectSampleJoin(project, sample, true)));
    assertTrue("should want to assemble file", processor.shouldProcessFile(sequenceFileId));
    processor.process(pair);
    verify(submissionRepository).save(any(AnalysisSubmission.class));
}
Also used : ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) Project(ca.corefacility.bioinformatics.irida.model.project.Project) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) Test(org.junit.Test)

Example 13 with ProjectSampleJoin

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

the class AssemblyFileProcessorTest method testOneProjectEnabled.

@Test
public void testOneProjectEnabled() {
    SequenceFilePair pair = new SequenceFilePair(new SequenceFile(Paths.get("file_R1_1.fastq.gz")), new SequenceFile(Paths.get("file_R2_1.fastq.gz")));
    Sample sample = new Sample();
    Project project = new Project();
    project.setAssembleUploads(true);
    Project disabledProject = new Project();
    disabledProject.setAssembleUploads(false);
    when(ssoRepository.getSampleForSequencingObject(pair)).thenReturn(new SampleSequencingObjectJoin(sample, pair));
    when(psjRepository.getProjectForSample(sample)).thenReturn(ImmutableList.of(new ProjectSampleJoin(disabledProject, sample, true), new ProjectSampleJoin(project, sample, true)));
    processor.process(pair);
    verify(submissionRepository).save(any(AnalysisSubmission.class));
}
Also used : ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) Project(ca.corefacility.bioinformatics.irida.model.project.Project) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) Test(org.junit.Test)

Example 14 with ProjectSampleJoin

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

the class ProjectEventHandlerTest method testHandleSequenceFileAddedEventMultipleReturn.

@SuppressWarnings("unchecked")
@Test
public void testHandleSequenceFileAddedEventMultipleReturn() {
    Class<? extends ProjectEvent> clazz = DataAddedToSampleProjectEvent.class;
    Project project = new Project();
    Sample sample = new Sample();
    SequenceFile file = new SequenceFile();
    SingleEndSequenceFile seqObj1 = new SingleEndSequenceFile(file);
    SingleEndSequenceFile seqObj2 = new SingleEndSequenceFile(file);
    SampleSequencingObjectJoin join1 = new SampleSequencingObjectJoin(sample, seqObj1);
    SampleSequencingObjectJoin join2 = new SampleSequencingObjectJoin(sample, seqObj2);
    when(psjRepository.getProjectForSample(sample)).thenReturn(Lists.newArrayList(new ProjectSampleJoin(project, sample, true)));
    when(eventRepository.save(any(ProjectEvent.class))).thenReturn(new DataAddedToSampleProjectEvent(project, sample));
    Object[] args = {};
    MethodEvent methodEvent = new MethodEvent(clazz, Lists.newArrayList(join1, join2), args);
    handler.delegate(methodEvent);
    ArgumentCaptor<ProjectEvent> captor = ArgumentCaptor.forClass(ProjectEvent.class);
    verify(eventRepository).save(captor.capture());
    ProjectEvent event = captor.getValue();
    assertTrue(event instanceof DataAddedToSampleProjectEvent);
    verify(projectRepository).save(any(Project.class));
    verify(sampleRepository).save(any(Sample.class));
}
Also used : Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) 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) DataAddedToSampleProjectEvent(ca.corefacility.bioinformatics.irida.model.event.DataAddedToSampleProjectEvent) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) UserRoleSetProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent) UserRemovedProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRemovedProjectEvent) DataAddedToSampleProjectEvent(ca.corefacility.bioinformatics.irida.model.event.DataAddedToSampleProjectEvent) ProjectEvent(ca.corefacility.bioinformatics.irida.model.event.ProjectEvent) SampleAddedProjectEvent(ca.corefacility.bioinformatics.irida.model.event.SampleAddedProjectEvent) Test(org.junit.Test)

Example 15 with ProjectSampleJoin

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

the class ProjectEventHandlerTest method testDelegateSampleAdded.

@Test
public void testDelegateSampleAdded() {
    Class<? extends ProjectEvent> clazz = SampleAddedProjectEvent.class;
    Project project = new Project();
    Sample sample = new Sample();
    ProjectSampleJoin returnValue = new ProjectSampleJoin(project, sample, true);
    Object[] args = { project, sample };
    MethodEvent methodEvent = new MethodEvent(clazz, returnValue, args);
    when(eventRepository.save(any(ProjectEvent.class))).thenReturn(new SampleAddedProjectEvent(returnValue));
    handler.delegate(methodEvent);
    ArgumentCaptor<ProjectEvent> captor = ArgumentCaptor.forClass(ProjectEvent.class);
    verify(eventRepository).save(captor.capture());
    ProjectEvent event = captor.getValue();
    assertTrue(event instanceof SampleAddedProjectEvent);
    verify(projectRepository).save(any(Project.class));
}
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) SampleAddedProjectEvent(ca.corefacility.bioinformatics.irida.model.event.SampleAddedProjectEvent) UserRoleSetProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent) UserRemovedProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRemovedProjectEvent) DataAddedToSampleProjectEvent(ca.corefacility.bioinformatics.irida.model.event.DataAddedToSampleProjectEvent) ProjectEvent(ca.corefacility.bioinformatics.irida.model.event.ProjectEvent) SampleAddedProjectEvent(ca.corefacility.bioinformatics.irida.model.event.SampleAddedProjectEvent) 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