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());
}
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);
}
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());
}
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);
}
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);
}
Aggregations