use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile in project irida by phac-nml.
the class ProjectSamplesControllerTest method testDownloadSamplesWithSameName.
@Test
public void testDownloadSamplesWithSameName() throws IOException {
Project project = TestDataFactory.constructProject();
Sample sample = TestDataFactory.constructSample();
MockHttpServletResponse response = new MockHttpServletResponse();
Path path = Paths.get(FILE_PATH);
SequenceFile file = new SequenceFile(path);
ImmutableList<SampleSequencingObjectJoin> filejoin = ImmutableList.of(new SampleSequencingObjectJoin(sample, new SingleEndSequenceFile(file)), new SampleSequencingObjectJoin(sample, new SingleEndSequenceFile(file)), new SampleSequencingObjectJoin(sample, new SingleEndSequenceFile(file)));
when(projectService.read(project.getId())).thenReturn(project);
when(sampleService.readMultiple(ImmutableList.of(sample.getId()))).thenReturn(ImmutableList.of(sample));
when(sequencingObjectService.getSequencingObjectsForSample(sample)).thenReturn(filejoin);
controller.downloadSamples(project.getId(), ImmutableList.of(sample.getId()), response);
verify(projectService).read(project.getId());
verify(sampleService).readMultiple(ImmutableList.of(sample.getId()));
verify(sequencingObjectService).getSequencingObjectsForSample(sample);
assertTrue("Response should contain a \"Content-Disposition\" header.", response.containsHeader("Content-Disposition"));
assertEquals("Content-Disposition should include the file name", "attachment; filename=\"test_project.zip\"", response.getHeader("Content-Disposition"));
try (ZipInputStream zipStream = new ZipInputStream(new ByteArrayInputStream(response.getContentAsByteArray()))) {
Set<String> names = new HashSet<>();
ZipEntry nextEntry = zipStream.getNextEntry();
while (nextEntry != null) {
names.add(nextEntry.getName());
nextEntry = zipStream.getNextEntry();
}
assertEquals("should be 3 unique filenames", 3, names.size());
}
}
use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile in project irida by phac-nml.
the class SamplesControllerTest method testDownloadAssembly.
@Test
public void testDownloadAssembly() throws IOException {
HttpServletResponse response = new MockHttpServletResponse();
Long sampleId = 1L;
Long assemblyId = 3L;
SequenceFile file = new SequenceFile(Paths.get("/tmp"));
file.setId(2L);
Sample sample = new Sample();
GenomeAssembly genomeAssembly = TestDataFactory.constructGenomeAssembly();
when(sampleService.read(sampleId)).thenReturn(sample);
when(sampleService.getGenomeAssemblyForSample(sample, assemblyId)).thenReturn(genomeAssembly);
when(readSamplePermission.isAllowed(any(Authentication.class), eq(sample))).thenReturn(true);
controller.downloadAssembly(sampleId, assemblyId, response);
verify(sampleService).read(sampleId);
verify(sampleService).getGenomeAssemblyForSample(sample, assemblyId);
}
use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile in project irida by phac-nml.
the class SamplesControllerTest method testGetSampleFilesNoAccess.
@SuppressWarnings("unchecked")
@Test
public void testGetSampleFilesNoAccess() throws IOException {
ExtendedModelMap model = new ExtendedModelMap();
Long sampleId = 1L;
Sample sample = new Sample();
SequenceFile file = new SequenceFile(Paths.get("/tmp"));
file.setId(2L);
Project project = new Project();
List<SampleSequencingObjectJoin> files = Lists.newArrayList(new SampleSequencingObjectJoin(sample, new SingleEndSequenceFile(file)));
when(sampleService.read(sampleId)).thenReturn(sample);
when(sequencingObjectService.getSequencesForSampleOfType(sample, SingleEndSequenceFile.class)).thenReturn(files);
when(updateSamplePermission.isAllowed(any(Authentication.class), eq(sample))).thenReturn(false);
when(projectService.getProjectsForSample(sample)).thenReturn(Lists.newArrayList(new ProjectSampleJoin(project, sample, true)));
String sampleFiles = controller.getSampleFilesWithoutProject(model, sampleId);
assertEquals(SamplesController.SAMPLE_FILES_PAGE, sampleFiles);
assertFalse((boolean) model.get(SamplesController.MODEL_ATTR_CAN_MANAGE_SAMPLE));
verify(sampleService).read(sampleId);
verify(sequencingObjectService).getSequencesForSampleOfType(sample, SingleEndSequenceFile.class);
verify(sequencingObjectService).getSequencesForSampleOfType(sample, SequenceFilePair.class);
}
use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile in project irida by phac-nml.
the class SequenceFileControllerTest method setUp.
@Before
public void setUp() {
sequencingRunService = mock(SequencingRunService.class);
analysisService = mock(AnalysisService.class);
objectService = mock(SequencingObjectService.class);
controller = new SequenceFileController(objectService, sequencingRunService, analysisService);
Path path = Paths.get(FILE_PATH);
SequenceFile file = new SequenceFile(path);
file.setId(FILE_ID);
SingleEndSequenceFile seqObject = new SingleEndSequenceFile(file);
when(objectService.read(anyLong())).thenReturn(seqObject);
}
use of ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile in project irida by phac-nml.
the class ReadAnalysisSubmissionPermissionTest method setUp.
/**
* Setup for tests
*/
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
readAnalysisSubmissionPermission = new ReadAnalysisSubmissionPermission(analysisSubmissionRepository, userRepository, sequencingObjectRepository, seqObjectPermission, pasRepository, readProjectPermission);
inputSingleFiles = Sets.newHashSet(new SingleEndSequenceFile(new SequenceFile()));
}
Aggregations