use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile in project irida by phac-nml.
the class SampleServiceImplTest method testRemoveSequenceFileFromSample.
@Test
public void testRemoveSequenceFileFromSample() {
Sample s = new Sample();
s.setId(1111L);
SequenceFile sf = new SequenceFile();
sf.setId(2222L);
SingleEndSequenceFile obj = new SingleEndSequenceFile(sf);
obj.setId(2L);
SampleSequencingObjectJoin join = new SampleSequencingObjectJoin(s, obj);
when(ssoRepository.readObjectForSample(s, obj.getId())).thenReturn(join);
sampleService.removeSequencingObjectFromSample(s, obj);
verify(ssoRepository).delete(join);
}
use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile in project irida by phac-nml.
the class SampleServiceImplTest method testGetTotalBasesForSampleFailMultipleFastQC.
/**
* Tests out failing to get the total bases from a sample with one sequence
* file due to too many FastQC
*
* @throws SequenceFileAnalysisException
*/
@Test(expected = SequenceFileAnalysisException.class)
public void testGetTotalBasesForSampleFailMultipleFastQC() throws SequenceFileAnalysisException {
Sample s1 = new Sample();
s1.setId(1L);
SequenceFile sf1 = new SequenceFile();
sf1.setId(2222L);
SampleSequencingObjectJoin join = new SampleSequencingObjectJoin(s1, new SingleEndSequenceFile(sf1));
when(ssoRepository.getSequencesForSample(s1)).thenReturn(Arrays.asList(join));
sampleService.getTotalBasesForSample(s1);
}
use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile 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.sequenceFile.SingleEndSequenceFile 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);
}
use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile in project irida by phac-nml.
the class SampleSequenceFilesControllerTest method testGetSampleSequenceFiles.
@Test
public void testGetSampleSequenceFiles() throws IOException {
Sample s = TestDataFactory.constructSample();
SingleEndSequenceFile so = TestDataFactory.constructSingleEndSequenceFile();
SampleSequencingObjectJoin r = new SampleSequencingObjectJoin(s, so);
List<SampleSequencingObjectJoin> relationships = Lists.newArrayList(r);
// mock out the service calls
when(sampleService.read(s.getId())).thenReturn(s);
when(sequencingObjectService.getSequencingObjectsForSample(s)).thenReturn(relationships);
ModelMap modelMap = controller.getSampleSequenceFiles(s.getId());
// verify that the service calls were used.
verify(sampleService).read(s.getId());
verify(sequencingObjectService).getSequencingObjectsForSample(s);
Object o = modelMap.get(RESTGenericController.RESOURCE_NAME);
assertTrue(o instanceof ResourceCollection);
@SuppressWarnings("unchecked") ResourceCollection<SequenceFile> resources = (ResourceCollection<SequenceFile>) o;
assertNotNull(resources);
assertEquals(1, resources.size());
Link selfCollection = resources.getLink(Link.REL_SELF);
Link sample = resources.getLink(RESTSampleSequenceFilesController.REL_SAMPLE);
String sampleLocation = "http://localhost/api/samples/" + s.getId();
String sequenceFileLocation = sampleLocation + "/unpaired/" + so.getIdentifier() + "/files/" + so.getSequenceFile().getId();
assertEquals(sampleLocation + "/sequenceFiles", selfCollection.getHref());
assertEquals(sampleLocation, sample.getHref());
// confirm that the self rel for an individual sequence file exists
SequenceFile sfr = resources.iterator().next();
Link self = sfr.getLink(Link.REL_SELF);
assertEquals(sequenceFileLocation, self.getHref());
assertEquals(so.getSequenceFile().getFile(), sfr.getFile());
}
Aggregations