Search in sources :

Example 31 with Sample

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

the class RESTProjectSamplesControllerTest method testGetProjectSample.

@Test
public void testGetProjectSample() throws IOException {
    Project p = TestDataFactory.constructProject();
    Sample s = TestDataFactory.constructSample();
    // mock out the service calls
    when(projectService.read(p.getId())).thenReturn(p);
    when(sampleService.read(s.getId())).thenReturn(s);
    when(sampleService.getSampleForProject(p, s.getId())).thenReturn(new ProjectSampleJoin(p, s, true));
    ModelMap modelMap = controller.getProjectSample(p.getId(), s.getId());
    verify(sampleService).getSampleForProject(p, s.getId());
    Object o = modelMap.get(RESTGenericController.RESOURCE_NAME);
    assertTrue(o instanceof Sample);
    Sample sr = (Sample) o;
    Link selfLink = sr.getLink(Link.REL_SELF);
    Link sequenceFilesLink = sr.getLink(RESTSampleSequenceFilesController.REL_SAMPLE_SEQUENCE_FILES);
    Link projectLink = sr.getLink(RESTProjectSamplesController.REL_PROJECT);
    String projectLocation = "http://localhost/api/projects/" + p.getId();
    String sampleLocation = "http://localhost/api/samples/" + s.getId();
    assertNotNull(selfLink);
    assertEquals(sampleLocation, selfLink.getHref());
    assertNotNull(sequenceFilesLink);
    assertEquals(sampleLocation + "/sequenceFiles", sequenceFilesLink.getHref());
    assertNotNull(projectLink);
    assertEquals(projectLocation, projectLink.getHref());
}
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) ModelMap(org.springframework.ui.ModelMap) Link(org.springframework.hateoas.Link) Test(org.junit.Test)

Example 32 with Sample

use of ca.corefacility.bioinformatics.irida.model.sample.Sample 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 33 with Sample

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

the class SampleSequenceFilesControllerTest method testGetSequenceFileForSample.

@Test
public void testGetSequenceFileForSample() throws IOException {
    Sample s = TestDataFactory.constructSample();
    SingleEndSequenceFile so = TestDataFactory.constructSingleEndSequenceFile();
    when(sampleService.read(s.getId())).thenReturn(s);
    when(sequencingObjectService.readSequencingObjectForSample(s, so.getId())).thenReturn(so);
    ModelMap modelMap = controller.readSequenceFileForSequencingObject(s.getId(), RESTSampleSequenceFilesController.objectLabels.get(so.getClass()), so.getId(), so.getSequenceFile().getId());
    verify(sampleService).read(s.getId());
    verify(sequencingObjectService).readSequencingObjectForSample(s, so.getId());
    Object o = modelMap.get(RESTGenericController.RESOURCE_NAME);
    assertNotNull(o);
    assertTrue(o instanceof SequenceFile);
    SequenceFile sfr = (SequenceFile) o;
    assertEquals(so.getSequenceFile().getFile(), sfr.getFile());
    Link self = sfr.getLink(Link.REL_SELF);
    Link sampleSequenceFiles = sfr.getLink(RESTSampleSequenceFilesController.REL_SAMPLE_SEQUENCE_FILES);
    Link sample = sfr.getLink(RESTSampleSequenceFilesController.REL_SAMPLE);
    String sampleLocation = "http://localhost/api/samples/" + s.getId();
    String sequenceFileLocation = sampleLocation + "/unpaired/" + so.getIdentifier() + "/files/" + so.getSequenceFile().getId();
    assertNotNull(self);
    assertEquals(sequenceFileLocation, self.getHref());
    assertNotNull(sampleSequenceFiles);
    assertEquals(sampleLocation + "/sequenceFiles", sampleSequenceFiles.getHref());
    assertNotNull(sample);
    assertEquals(sampleLocation, sample.getHref());
}
Also used : SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) ModelMap(org.springframework.ui.ModelMap) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Link(org.springframework.hateoas.Link) Test(org.junit.Test)

Example 34 with Sample

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

the class SampleSequenceFilesControllerTest method testAddNewSequenceFilePairToSample.

@Test
public void testAddNewSequenceFilePairToSample() throws IOException {
    Sample s = TestDataFactory.constructSample();
    String file1Name = "file1_R1_01.fastq.gz";
    String file2Name = "file2_R2_01.fastq.gz";
    SequenceFilePair pair = TestDataFactory.constructSequenceFilePair();
    Iterator<SequenceFile> iterator = pair.getFiles().iterator();
    SequenceFile sf1 = iterator.next();
    SequenceFile sf2 = iterator.next();
    sf1.setFile(Paths.get(file1Name));
    sf2.setFile(Paths.get(file2Name));
    sf1.setId(3245L);
    SampleSequencingObjectJoin sso = new SampleSequencingObjectJoin(s, pair);
    SequenceFileResource resource1 = new SequenceFileResource();
    SequenceFileResource resource2 = new SequenceFileResource();
    Path f1 = Files.createTempFile(null, null);
    Path f2 = Files.createTempFile(null, null);
    MockMultipartFile mmf1 = new MockMultipartFile(file1Name, file1Name, "blurgh1", FileCopyUtils.copyToByteArray(f1.toFile()));
    MockMultipartFile mmf2 = new MockMultipartFile(file2Name, file2Name, "blurgh2", FileCopyUtils.copyToByteArray(f2.toFile()));
    MockHttpServletResponse response = new MockHttpServletResponse();
    // mock out the service calls
    when(sampleService.read(s.getId())).thenReturn(s);
    when(sequencingObjectService.createSequencingObjectInSample(any(SequenceFilePair.class), Matchers.eq(s))).thenReturn(sso);
    ModelMap modelMap = controller.addNewSequenceFilePairToSample(s.getId(), mmf1, resource1, mmf2, resource2, response);
    verify(sampleService).read(s.getId());
    verify(sequencingObjectService).createSequencingObjectInSample(any(SequenceFilePair.class), Matchers.eq(s));
    Object o = modelMap.get(RESTGenericController.RESOURCE_NAME);
    assertNotNull("Object should not be null", o);
    assertTrue("Object should be an instance of SequenceFilePair", o instanceof SequenceFilePair);
    SequenceFilePair returnVal = (SequenceFilePair) o;
    Link selfCollection = returnVal.getLink(Link.REL_SELF);
    Link sampleRC = returnVal.getLink(RESTSampleSequenceFilesController.REL_SAMPLE);
    Link sampleSequenceFiles = returnVal.getLink(RESTSampleSequenceFilesController.REL_SAMPLE_SEQUENCE_FILES);
    String sampleLocation = "http://localhost/api/samples/" + s.getId();
    String pairLocation = sampleLocation + "/pairs/" + pair.getId();
    assertEquals("Pair location should be correct", pairLocation, selfCollection.getHref());
    assertEquals("Sample location should be correct", sampleLocation, sampleRC.getHref());
    assertEquals("Sequence file location should be correct", sampleLocation + "/sequenceFiles", sampleSequenceFiles.getHref());
    String sequenceFileLocation1 = pairLocation + "/files/" + sf1.getId();
    String sequenceFileLocation2 = pairLocation + "/files/" + sf2.getId();
    String[] sequenceFileLocs = new String[] { sequenceFileLocation1, sequenceFileLocation2 };
    String locationHeader = response.getHeader(HttpHeaders.LOCATION);
    assertEquals("The location header should have the self rel", pairLocation, locationHeader);
    Iterator<SequenceFile> filesIterator = returnVal.getFiles().iterator();
    for (int i = 0; i < 2; i++) {
        SequenceFile returnedFile = filesIterator.next();
        Link self = returnedFile.getLink(Link.REL_SELF);
        assertNotNull("Self link should not be null", self);
        assertEquals("Self reference should be correct", sequenceFileLocs[i], self.getHref());
    }
    assertEquals("HTTP status must be CREATED", HttpStatus.CREATED.value(), response.getStatus());
    Files.delete(f1);
    Files.delete(f2);
}
Also used : Path(java.nio.file.Path) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) ModelMap(org.springframework.ui.ModelMap) SequenceFileResource(ca.corefacility.bioinformatics.irida.web.assembler.resource.sequencefile.SequenceFileResource) SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Link(org.springframework.hateoas.Link) Test(org.junit.Test)

Example 35 with Sample

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

the class SampleSequenceFilesControllerTest method testAddNewSequenceFileToSample.

@Test
public void testAddNewSequenceFileToSample() throws IOException {
    Sample s = TestDataFactory.constructSample();
    SingleEndSequenceFile so = TestDataFactory.constructSingleEndSequenceFile();
    SequenceFile sf = so.getSequenceFile();
    SampleSequencingObjectJoin sso = new SampleSequencingObjectJoin(s, so);
    SequenceFileResource resource = new SequenceFileResource();
    Path f = Files.createTempFile(null, null);
    MockMultipartFile mmf = new MockMultipartFile("filename", "filename", "blurgh", FileCopyUtils.copyToByteArray(f.toFile()));
    MockHttpServletResponse response = new MockHttpServletResponse();
    when(sampleService.read(s.getId())).thenReturn(s);
    when(sequencingObjectService.createSequencingObjectInSample(any(SingleEndSequenceFile.class), Matchers.eq(s))).thenReturn(sso);
    when(sequencingObjectService.read(so.getId())).thenReturn(so);
    ModelMap modelMap = controller.addNewSequenceFileToSample(s.getId(), mmf, resource, response);
    verify(sampleService).read(s.getId());
    verify(sampleService, times(1)).read(s.getId());
    verify(sequencingObjectService).createSequencingObjectInSample(any(SingleEndSequenceFile.class), Matchers.eq(s));
    Object o = modelMap.get(RESTGenericController.RESOURCE_NAME);
    assertNotNull("object must not be null", o);
    assertTrue("object must be a SequenceFile", o instanceof SequenceFile);
    SequenceFile sfr = (SequenceFile) o;
    assertEquals("response must have CREATED status", HttpStatus.CREATED.value(), response.getStatus());
    Link self = sfr.getLink(Link.REL_SELF);
    Link sampleSequenceFiles = sfr.getLink(RESTSampleSequenceFilesController.REL_SAMPLE_SEQUENCE_FILES);
    Link sample = sfr.getLink(RESTSampleSequenceFilesController.REL_SAMPLE);
    String sampleLocation = "http://localhost/api/samples/" + s.getId();
    String sequenceFileLocation = sampleLocation + "/unpaired/" + so.getIdentifier() + "/files/" + sf.getId();
    assertNotNull("self reference must exist", self);
    assertEquals("self reference must be correct", sequenceFileLocation, self.getHref());
    assertNotNull("sequence files link must exist", sampleSequenceFiles);
    assertEquals("sequence files location must be correct", sampleLocation + "/sequenceFiles", sampleSequenceFiles.getHref());
    assertNotNull("sample link must exist", sample);
    assertEquals("sample location must be correct", sampleLocation, sample.getHref());
    Files.delete(f);
}
Also used : Path(java.nio.file.Path) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) ModelMap(org.springframework.ui.ModelMap) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) SequenceFileResource(ca.corefacility.bioinformatics.irida.web.assembler.resource.sequencefile.SequenceFileResource) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Link(org.springframework.hateoas.Link) Test(org.junit.Test)

Aggregations

Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)243 Test (org.junit.Test)162 Project (ca.corefacility.bioinformatics.irida.model.project.Project)114 WithMockUser (org.springframework.security.test.context.support.WithMockUser)71 ProjectSampleJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin)62 SampleSequencingObjectJoin (ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)53 SingleEndSequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)53 SequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)41 Join (ca.corefacility.bioinformatics.irida.model.joins.Join)33 SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)33 Path (java.nio.file.Path)28 ModelMap (org.springframework.ui.ModelMap)28 SequenceFilePair (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair)24 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)24 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)23 ArrayList (java.util.ArrayList)22 EntityNotFoundException (ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException)17 User (ca.corefacility.bioinformatics.irida.model.user.User)14 HashMap (java.util.HashMap)14 RelatedProjectJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin)13