use of ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin in project irida by phac-nml.
the class ReadSequencingObjectPermissionTest method testRejectPermission.
@Test
public void testRejectPermission() {
Project p = new Project();
Sample s = new Sample();
List<Join<Project, Sample>> projectSampleList = new ArrayList<>();
projectSampleList.add(new ProjectSampleJoin(p, s, true));
SingleEndSequenceFile sf = new SingleEndSequenceFile(null);
SampleSequencingObjectJoin join = new SampleSequencingObjectJoin(s, sf);
when(psjRepository.getProjectForSample(s)).thenReturn(projectSampleList);
when(sequencingObjectRepository.findOne(1L)).thenReturn(sf);
when(ssoRepository.getSampleForSequencingObject(sf)).thenReturn(join);
when(readProjectPermission.isAllowed(any(), eq(p))).thenReturn(false);
Authentication auth = new UsernamePasswordAuthenticationToken("fbristow", "password1");
assertFalse("permission was granted.", permission.isAllowed(auth, 1L));
verify(sequencingObjectRepository).findOne(1L);
verify(psjRepository).getProjectForSample(s);
verify(ssoRepository).getSampleForSequencingObject(sf);
verify(readProjectPermission).isAllowed(any(), eq(p));
}
use of ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin in project irida by phac-nml.
the class ReadSequencingObjectPermissionTest method testGrantPermission.
@Test
public void testGrantPermission() {
Project p = new Project();
Sample s = new Sample();
List<Join<Project, Sample>> projectSampleList = new ArrayList<>();
projectSampleList.add(new ProjectSampleJoin(p, s, true));
SingleEndSequenceFile sf = new SingleEndSequenceFile(null);
SampleSequencingObjectJoin join = new SampleSequencingObjectJoin(s, sf);
when(psjRepository.getProjectForSample(s)).thenReturn(projectSampleList);
when(sequencingObjectRepository.findOne(1L)).thenReturn(sf);
when(ssoRepository.getSampleForSequencingObject(sf)).thenReturn(join);
when(readProjectPermission.isAllowed(any(), eq(p))).thenReturn(true);
Authentication auth = new UsernamePasswordAuthenticationToken("fbristow", "password1");
assertTrue("permission was not granted.", permission.isAllowed(auth, 1L));
verify(sequencingObjectRepository).findOne(1L);
verify(psjRepository).getProjectForSample(s);
verify(ssoRepository).getSampleForSequencingObject(sf);
verify(readProjectPermission).isAllowed(any(), eq(p));
}
use of ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin in project irida by phac-nml.
the class TestDataFactory method generateSequencingObjectsForSample.
public static List<SampleSequencingObjectJoin> generateSequencingObjectsForSample(Sample sample) {
List<SampleSequencingObjectJoin> join = new ArrayList<>();
for (long i = 0; i < 5; i++) {
Path path = Paths.get("/tmp/sequence-files/fake-file" + Math.random() + ".fast");
SequenceFile file = new SequenceFile(path);
file.setId(i);
SingleEndSequenceFile obj = new SingleEndSequenceFile(file);
obj.setId(i);
join.add(new SampleSequencingObjectJoin(sample, obj));
}
return join;
}
use of ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin in project irida by phac-nml.
the class SequencingObjectServiceImplIT method testGetUnpairedFilesForSample.
@Test
@WithMockUser(username = "admin", roles = "ADMIN")
public void testGetUnpairedFilesForSample() {
Sample s = sampleService.read(2L);
Collection<SampleSequencingObjectJoin> sequencesForSampleOfType = objectService.getSequencesForSampleOfType(s, SingleEndSequenceFile.class);
assertEquals(1, sequencesForSampleOfType.size());
SampleSequencingObjectJoin join = sequencesForSampleOfType.iterator().next();
assertEquals(new Long(4), join.getObject().getId());
}
use of ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin in project irida by phac-nml.
the class SequencingObjectServiceImplIT method testConcatenateSequenceFiles.
@Test
@WithMockUser(username = "admin", roles = "ADMIN")
public void testConcatenateSequenceFiles() throws IOException, InterruptedException, ConcatenateException {
String newFileName = "newname";
Sample sample = sampleService.read(1L);
SequenceFile file1 = createSequenceFile("file1");
SequenceFile file2 = createSequenceFile("file2");
long originalLength = file1.getFile().toFile().length();
SequencingObject so1 = new SingleEndSequenceFile(file1);
SequencingObject so2 = new SingleEndSequenceFile(file2);
SampleSequencingObjectJoin join1 = objectService.createSequencingObjectInSample(so1, sample);
SampleSequencingObjectJoin join2 = objectService.createSequencingObjectInSample(so2, sample);
// Wait 5 seconds. file processing should have run by then.
Thread.sleep(5000);
// re-read the original files so file processing will be complete
so1 = objectService.read(join1.getObject().getId());
so2 = objectService.read(join2.getObject().getId());
Collection<SampleSequencingObjectJoin> originalSeqs = objectService.getSequencingObjectsForSample(sample);
List<SequencingObject> fileSet = Lists.newArrayList(so1, so2);
SampleSequencingObjectJoin concatenateSequences = objectService.concatenateSequences(fileSet, newFileName, sample, false);
// Wait 5 seconds. file processing should have run by then.
Thread.sleep(5000);
Collection<SampleSequencingObjectJoin> newSeqs = objectService.getSequencingObjectsForSample(sample);
// re-read the concatenated file so file processing will be complete
concatenateSequences = sampleService.getSampleForSequencingObject(concatenateSequences.getObject());
assertTrue("new seq collection should contain originals", newSeqs.containsAll(originalSeqs));
assertTrue("new seq collection should contain new object", newSeqs.contains(concatenateSequences));
assertEquals("new seq collection should have 1 more object", originalSeqs.size() + 1, newSeqs.size());
SequencingObject newSeqObject = concatenateSequences.getObject();
SequenceFile newFile = newSeqObject.getFiles().iterator().next();
assertTrue("new file should contain new name", newFile.getFileName().contains(newFileName));
long newFileSize = newFile.getFile().toFile().length();
assertEquals("new file should be 2x size of originals", originalLength * 2, newFileSize);
}
Aggregations