Search in sources :

Example 6 with Analysis

use of org.icgc.dcc.song.server.model.analysis.Analysis in project SONG by overture-stack.

the class ExportServiceTest method runFullLoopTest.

/**
 * Given that  0 < numStudies < numAnalysesPerStudy, this test ensures that if the export service is requested for ONE
 * analysisId from EACH study, the response will return a list of size {@code numStudies}, where each element (which is
 * of type ExportedPayload) has exactly ONE payload (since there is only one analysis per study). This is a 2 in 1 test:
 * - it verifies the conversion of an existing analysis to a payload is correct, by submitting the
 * converted payload and comparing it with the original analysis
 * - it verifies the aggregation functionality of the export service, when given analysisIds belonging to
 * different studies
 */
private void runFullLoopTest(Class<? extends Analysis> analysisClass, int numStudies, int numAnalysesPerStudy) {
    val includeOtherIds = false;
    val includeAnalysisId = true;
    // Check the right parameters for this test are set
    assertCorrectConfig(numStudies, numAnalysesPerStudy);
    // Generate studies and there associated analyses
    val data = generateData(analysisClass, numStudies, numAnalysesPerStudy, includeAnalysisId, true);
    // [REDUCTION_TAG] Reduce the data so that there is one analysis for each study
    val reducedData = Maps.<String, Analysis>newHashMap();
    data.entrySet().stream().filter(e -> !reducedData.containsKey(e.getKey())).forEach(e -> {
        String studyId = e.getKey();
        List<? extends Analysis> analyses = e.getValue();
        int numAnalyses = analyses.size();
        int randomAnalysisPos = randomGenerator.generateRandomIntRange(0, numAnalyses);
        Analysis randomAnalysis = analyses.get(randomAnalysisPos);
        reducedData.put(studyId, randomAnalysis);
    });
    assertThat(reducedData.keySet()).hasSize(numStudies);
    assertThat(reducedData.values()).hasSize(numStudies);
    // Create a list of analysisIds that covers all the previously generated studies
    val requestedAnalysisIds = reducedData.values().stream().map(Analysis::getAnalysisId).collect(toImmutableList());
    assertThat(requestedAnalysisIds).hasSize(numStudies);
    // Export the analysis for the requested analysisIds
    val exportedPayloads = exportService.exportPayload(requestedAnalysisIds, includeAnalysisId, includeOtherIds);
    // There should be an ExportedPayload object for each study
    assertThat(exportedPayloads).hasSize(numStudies);
    for (val exportedPayload : exportedPayloads) {
        // There should be only 1 analysis for each study. Refer to the comment with REDUCTION_TAG.
        val studyId = exportedPayload.getStudyId();
        assertThat(exportedPayload.getPayloads()).hasSize(1);
        val payload = exportedPayload.getPayloads().get(0);
        val expectedAnalysis = reducedData.get(studyId);
        // Delete the previously created analysis so it can be created using the uploadService (frontdoor creation)
        deleteAnalysis(expectedAnalysis);
        // Depending on includeAnalysisId's value, either remove or keep the analysisId. Always keep the
        // other ids, so that it can be compared to the re-create analysis after submission
        massageAnalysisInplace(expectedAnalysis, includeAnalysisId, true);
        // Submit payload. Should create the same "otherIds" as the expected
        val actualAnalysis = submitPayload(studyId, payload, analysisClass);
        // Assert output analysis is correct
        assertAnalysis(actualAnalysis, expectedAnalysis);
    }
}
Also used : lombok.val(lombok.val) File(org.icgc.dcc.song.server.model.entity.File) SneakyThrows(lombok.SneakyThrows) IntStream.range(java.util.stream.IntStream.range) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Autowired(org.springframework.beans.factory.annotation.Autowired) SequencingReadAnalysis(org.icgc.dcc.song.server.model.analysis.SequencingReadAnalysis) ActiveProfiles(org.springframework.test.context.ActiveProfiles) TestFiles.assertSetsMatch(org.icgc.dcc.song.server.utils.TestFiles.assertSetsMatch) AnalysisTypes.resolveAnalysisType(org.icgc.dcc.song.server.model.enums.AnalysisTypes.resolveAnalysisType) TestExecutionListeners(org.springframework.test.context.TestExecutionListeners) VariantCallAnalysis(org.icgc.dcc.song.server.model.analysis.VariantCallAnalysis) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) ExportService(org.icgc.dcc.song.server.service.export.ExportService) SpringRunner(org.springframework.test.context.junit4.SpringRunner) Collectors.toSet(java.util.stream.Collectors.toSet) RandomGenerator.createRandomGenerator(org.icgc.dcc.song.core.utils.RandomGenerator.createRandomGenerator) Reductions.groupUnique(org.icgc.dcc.song.core.utils.Reductions.groupUnique) ImmutableMap(com.google.common.collect.ImmutableMap) Specimen(org.icgc.dcc.song.server.model.entity.Specimen) Collection(java.util.Collection) Set(java.util.Set) JsonUtils(org.icgc.dcc.song.core.utils.JsonUtils) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) JsonUtils.fromJson(org.icgc.dcc.song.core.utils.JsonUtils.fromJson) RandomGenerator(org.icgc.dcc.song.core.utils.RandomGenerator) RunWith(org.junit.runner.RunWith) SEQUENCING_READ(org.icgc.dcc.song.server.model.enums.AnalysisTypes.SEQUENCING_READ) Analysis(org.icgc.dcc.song.server.model.analysis.Analysis) StudyGenerator(org.icgc.dcc.song.server.utils.StudyGenerator) AnalysisGenerator.createAnalysisGenerator(org.icgc.dcc.song.server.utils.AnalysisGenerator.createAnalysisGenerator) DependencyInjectionTestExecutionListener(org.springframework.test.context.support.DependencyInjectionTestExecutionListener) Before(org.junit.Before) Donor(org.icgc.dcc.song.server.model.entity.Donor) VARIANT_CALL(org.icgc.dcc.song.server.model.enums.AnalysisTypes.VARIANT_CALL) JsonUtils.toJson(org.icgc.dcc.song.core.utils.JsonUtils.toJson) lombok.val(lombok.val) Test(org.junit.Test) Maps(com.google.common.collect.Maps) CompositeEntity(org.icgc.dcc.song.server.model.entity.composites.CompositeEntity) UploadStates.resolveState(org.icgc.dcc.song.server.model.enums.UploadStates.resolveState) AnalysisRepository(org.icgc.dcc.song.server.repository.AnalysisRepository) EMPTY_STRING(org.icgc.dcc.song.server.utils.TestFiles.EMPTY_STRING) Collectors.toImmutableList(org.icgc.dcc.common.core.util.stream.Collectors.toImmutableList) StudyGenerator.createStudyGenerator(org.icgc.dcc.song.server.utils.StudyGenerator.createStudyGenerator) UploadStates(org.icgc.dcc.song.server.model.enums.UploadStates) ResponseEntity(org.springframework.http.ResponseEntity) Sample(org.icgc.dcc.song.server.model.entity.Sample) SequencingReadAnalysis(org.icgc.dcc.song.server.model.analysis.SequencingReadAnalysis) VariantCallAnalysis(org.icgc.dcc.song.server.model.analysis.VariantCallAnalysis) Analysis(org.icgc.dcc.song.server.model.analysis.Analysis)

Aggregations

lombok.val (lombok.val)6 Analysis (org.icgc.dcc.song.server.model.analysis.Analysis)6 SequencingReadAnalysis (org.icgc.dcc.song.server.model.analysis.SequencingReadAnalysis)6 VariantCallAnalysis (org.icgc.dcc.song.server.model.analysis.VariantCallAnalysis)6 Maps (com.google.common.collect.Maps)5 Collectors.toSet (java.util.stream.Collectors.toSet)5 Slf4j (lombok.extern.slf4j.Slf4j)5 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)5 JsonUtils (org.icgc.dcc.song.core.utils.JsonUtils)5 JsonUtils.fromJson (org.icgc.dcc.song.core.utils.JsonUtils.fromJson)5 JsonUtils.toJson (org.icgc.dcc.song.core.utils.JsonUtils.toJson)5 RandomGenerator (org.icgc.dcc.song.core.utils.RandomGenerator)5 RandomGenerator.createRandomGenerator (org.icgc.dcc.song.core.utils.RandomGenerator.createRandomGenerator)5 File (org.icgc.dcc.song.server.model.entity.File)5 Sample (org.icgc.dcc.song.server.model.entity.Sample)5 CompositeEntity (org.icgc.dcc.song.server.model.entity.composites.CompositeEntity)5 SEQUENCING_READ (org.icgc.dcc.song.server.model.enums.AnalysisTypes.SEQUENCING_READ)5 VARIANT_CALL (org.icgc.dcc.song.server.model.enums.AnalysisTypes.VARIANT_CALL)5 AnalysisTypes.resolveAnalysisType (org.icgc.dcc.song.server.model.enums.AnalysisTypes.resolveAnalysisType)5 AnalysisRepository (org.icgc.dcc.song.server.repository.AnalysisRepository)5