Search in sources :

Example 1 with SequenceFileResource

use of ca.corefacility.bioinformatics.irida.web.assembler.resource.sequencefile.SequenceFileResource 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 2 with SequenceFileResource

use of ca.corefacility.bioinformatics.irida.web.assembler.resource.sequencefile.SequenceFileResource 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 3 with SequenceFileResource

use of ca.corefacility.bioinformatics.irida.web.assembler.resource.sequencefile.SequenceFileResource 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)3 SampleSequencingObjectJoin (ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)3 SequenceFileResource (ca.corefacility.bioinformatics.irida.web.assembler.resource.sequencefile.SequenceFileResource)3 Path (java.nio.file.Path)3 Test (org.junit.Test)3 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)3 MockMultipartFile (org.springframework.mock.web.MockMultipartFile)3 SequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)2 SequenceFilePair (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair)2 SingleEndSequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)2 Link (org.springframework.hateoas.Link)2 ModelMap (org.springframework.ui.ModelMap)2 ProjectSampleJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin)1 Project (ca.corefacility.bioinformatics.irida.model.project.Project)1