Search in sources :

Example 76 with SequenceFile

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());
    }
}
Also used : Path(java.nio.file.Path) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) ZipEntry(java.util.zip.ZipEntry) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Project(ca.corefacility.bioinformatics.irida.model.project.Project) ZipInputStream(java.util.zip.ZipInputStream) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) ByteArrayInputStream(java.io.ByteArrayInputStream) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) Test(org.junit.Test)

Example 77 with SequenceFile

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);
}
Also used : SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) Authentication(org.springframework.security.core.Authentication) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) GenomeAssembly(ca.corefacility.bioinformatics.irida.model.assembly.GenomeAssembly) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 78 with SequenceFile

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);
}
Also used : ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) Project(ca.corefacility.bioinformatics.irida.model.project.Project) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) Authentication(org.springframework.security.core.Authentication) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Test(org.junit.Test)

Example 79 with SequenceFile

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);
}
Also used : Path(java.nio.file.Path) SequencingObjectService(ca.corefacility.bioinformatics.irida.service.SequencingObjectService) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) SequencingRunService(ca.corefacility.bioinformatics.irida.service.SequencingRunService) AnalysisService(ca.corefacility.bioinformatics.irida.service.AnalysisService) SequenceFileController(ca.corefacility.bioinformatics.irida.ria.web.files.SequenceFileController) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Before(org.junit.Before)

Example 80 with SequenceFile

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()));
}
Also used : ReadAnalysisSubmissionPermission(ca.corefacility.bioinformatics.irida.security.permissions.analysis.ReadAnalysisSubmissionPermission) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Before(org.junit.Before)

Aggregations

SequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)111 SingleEndSequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)84 Test (org.junit.Test)61 Path (java.nio.file.Path)50 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)39 SampleSequencingObjectJoin (ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)31 SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)25 SequenceFilePair (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair)20 Project (ca.corefacility.bioinformatics.irida.model.project.Project)15 AnalysisFastQC (ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC)15 WithMockUser (org.springframework.security.test.context.support.WithMockUser)13 IOException (java.io.IOException)11 SequencingRun (ca.corefacility.bioinformatics.irida.model.run.SequencingRun)9 ArrayList (java.util.ArrayList)9 ProjectSampleJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin)8 GZIPOutputStream (java.util.zip.GZIPOutputStream)8 Link (org.springframework.hateoas.Link)8 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)7 OutputStream (java.io.OutputStream)7 Before (org.junit.Before)7