Search in sources :

Example 16 with AnalysisSubmission

use of ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission in project irida by phac-nml.

the class AnalysisSubmissionSampleProcessorImplIT method testUpdateSamplesFailAnalysisSubmittedNonProjectOwner.

/**
 * Verifies that even if "fbristow" (the project owner) is set to run this
 * code, the RunAsUserAspect will switch the user to the owner of the
 * analysis submission, a non-project owner who should not have the ability
 * to write to the samples (and so should throw an AccessDeniedException
 * for this test).
 */
@Test(expected = AccessDeniedException.class)
@WithMockUser(username = "fbristow", roles = "USER")
public void testUpdateSamplesFailAnalysisSubmittedNonProjectOwner() throws PostProcessingException {
    AnalysisSubmission a = analysisSubmissionRepository.findOne(3L);
    analysisSubmissionSampleProcessorImpl.updateSamples(a);
}
Also used : AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 17 with AnalysisSubmission

use of ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission in project irida by phac-nml.

the class AssemblySampleUpdaterIT method testUpdateSuccess.

@Test
@WithMockUser(username = "fbristow", roles = "USER")
public void testUpdateSuccess() {
    AnalysisSubmission a = analysisSubmissionRepository.findOne(1L);
    Sample s = sampleRepository.findOne(2L);
    assertEquals("Should be no join between sample and assembly", 0, sampleGenomeAssemblyJoinRepository.count());
    assemblySampleUpdater.update(Sets.newHashSet(s), a);
    assertEquals("Should exist a join between sample and assembly", 1, sampleGenomeAssemblyJoinRepository.count());
    SampleGenomeAssemblyJoin j = sampleGenomeAssemblyJoinRepository.findAll().iterator().next();
    assertEquals("Should have joined sample 2L", (Long) 2L, j.getSubject().getId());
    assertNotNull("Should have joined an assembly", j.getObject().getId());
}
Also used : SampleGenomeAssemblyJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.SampleGenomeAssemblyJoin) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 18 with AnalysisSubmission

use of ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission in project irida by phac-nml.

the class SISTRSampleUpdaterTest method testUpdaterPassed.

@SuppressWarnings("unchecked")
@Test
public void testUpdaterPassed() throws PostProcessingException, AnalysisAlreadySetException {
    ImmutableMap<String, String> expectedResults = ImmutableMap.of("SISTR serovar", "Enteritidis", "SISTR cgMLST Subspecies", "enterica", "SISTR QC Status", "PASS");
    Path outputPath = Paths.get("src/test/resources/files/sistr-predictions-pass.json");
    AnalysisOutputFile outputFile = new AnalysisOutputFile(outputPath, null, null, null);
    Analysis analysis = new Analysis(null, ImmutableMap.of("sistr-predictions", outputFile), null, null);
    AnalysisSubmission submission = AnalysisSubmission.builder(UUID.randomUUID()).inputFiles(ImmutableSet.of(new SingleEndSequenceFile(null))).build();
    submission.setAnalysis(analysis);
    Sample sample = new Sample();
    sample.setId(1L);
    ImmutableMap<MetadataTemplateField, MetadataEntry> metadataMap = ImmutableMap.of(new MetadataTemplateField("SISTR Field", "text"), new MetadataEntry("Value1", "text"));
    when(metadataTemplateService.getMetadataMap(any(Map.class))).thenReturn(metadataMap);
    updater.update(Lists.newArrayList(sample), submission);
    ArgumentCaptor<Map> mapCaptor = ArgumentCaptor.forClass(Map.class);
    // this is the important bit.  Ensures the correct values got pulled from the file
    verify(metadataTemplateService).getMetadataMap(mapCaptor.capture());
    Map<String, MetadataEntry> metadata = mapCaptor.getValue();
    int found = 0;
    for (Map.Entry<String, MetadataEntry> e : metadata.entrySet()) {
        if (expectedResults.containsKey(e.getKey())) {
            String expected = expectedResults.get(e.getKey());
            MetadataEntry value = e.getValue();
            assertEquals("metadata values should match", expected, value.getValue());
            found++;
        }
    }
    assertEquals("should have found the same number of results", expectedResults.keySet().size(), found);
    // this bit just ensures the merged data got saved
    verify(sampleService).updateFields(eq(sample.getId()), mapCaptor.capture());
    Map<MetadataTemplateField, MetadataEntry> value = (Map<MetadataTemplateField, MetadataEntry>) mapCaptor.getValue().get("metadata");
    assertEquals(metadataMap.keySet().iterator().next(), value.keySet().iterator().next());
}
Also used : Path(java.nio.file.Path) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Analysis(ca.corefacility.bioinformatics.irida.model.workflow.analysis.Analysis) MetadataEntry(ca.corefacility.bioinformatics.irida.model.sample.metadata.MetadataEntry) MetadataTemplateField(ca.corefacility.bioinformatics.irida.model.sample.MetadataTemplateField) AnalysisOutputFile(ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisOutputFile) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 19 with AnalysisSubmission

use of ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission in project irida by phac-nml.

the class SISTRSampleUpdaterTest method testUpdaterBadFile.

@Test(expected = PostProcessingException.class)
public void testUpdaterBadFile() throws PostProcessingException, AnalysisAlreadySetException {
    ImmutableMap<String, String> expectedResults = ImmutableMap.of("SISTR serovar", "Enteritidis", "SISTR cgMLST Subspecies", "enterica", "SISTR QC Status", "PASS");
    Path outputPath = Paths.get("src/test/resources/files/snp_tree.tree");
    AnalysisOutputFile outputFile = new AnalysisOutputFile(outputPath, null, null, null);
    Analysis analysis = new Analysis(null, ImmutableMap.of("sistr-predictions", outputFile), null, null);
    AnalysisSubmission submission = AnalysisSubmission.builder(UUID.randomUUID()).inputFiles(ImmutableSet.of(new SingleEndSequenceFile(null))).build();
    submission.setAnalysis(analysis);
    Sample sample = new Sample();
    sample.setId(1L);
    updater.update(Lists.newArrayList(sample), submission);
}
Also used : Path(java.nio.file.Path) Analysis(ca.corefacility.bioinformatics.irida.model.workflow.analysis.Analysis) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) AnalysisOutputFile(ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisOutputFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Test(org.junit.Test)

Example 20 with AnalysisSubmission

use of ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission in project irida by phac-nml.

the class SISTRSampleUpdaterTest method testUpdaterNoFile.

@Test(expected = PostProcessingException.class)
public void testUpdaterNoFile() throws PostProcessingException, AnalysisAlreadySetException {
    ImmutableMap<String, String> expectedResults = ImmutableMap.of("SISTR serovar", "Enteritidis", "SISTR cgMLST Subspecies", "enterica", "SISTR QC Status", "PASS");
    Path outputPath = Paths.get("src/test/resources/files/not_really_a_file.txt");
    AnalysisOutputFile outputFile = new AnalysisOutputFile(outputPath, null, null, null);
    Analysis analysis = new Analysis(null, ImmutableMap.of("sistr-predictions", outputFile), null, null);
    AnalysisSubmission submission = AnalysisSubmission.builder(UUID.randomUUID()).inputFiles(ImmutableSet.of(new SingleEndSequenceFile(null))).build();
    submission.setAnalysis(analysis);
    Sample sample = new Sample();
    sample.setId(1L);
    updater.update(Lists.newArrayList(sample), submission);
}
Also used : Path(java.nio.file.Path) Analysis(ca.corefacility.bioinformatics.irida.model.workflow.analysis.Analysis) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) AnalysisOutputFile(ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisOutputFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Test(org.junit.Test)

Aggregations

AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)183 Test (org.junit.Test)121 WithMockUser (org.springframework.security.test.context.support.WithMockUser)95 IridaWorkflow (ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow)30 Analysis (ca.corefacility.bioinformatics.irida.model.workflow.analysis.Analysis)30 Path (java.nio.file.Path)25 SequenceFilePair (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair)23 HistoriesClient (com.github.jmchilton.blend4j.galaxy.HistoriesClient)20 Project (ca.corefacility.bioinformatics.irida.model.project.Project)19 History (com.github.jmchilton.blend4j.galaxy.beans.History)19 SingleEndSequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)18 AnalysisOutputFile (ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisOutputFile)18 WorkflowsClient (com.github.jmchilton.blend4j.galaxy.WorkflowsClient)18 Workflow (com.github.jmchilton.blend4j.galaxy.beans.Workflow)18 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)15 User (ca.corefacility.bioinformatics.irida.model.user.User)15 EntityNotFoundException (ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException)12 ExecutionManagerException (ca.corefacility.bioinformatics.irida.exceptions.ExecutionManagerException)12 ProjectAnalysisSubmissionJoin (ca.corefacility.bioinformatics.irida.model.workflow.submission.ProjectAnalysisSubmissionJoin)12 ToolExecution (ca.corefacility.bioinformatics.irida.model.workflow.analysis.ToolExecution)11