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);
}
}
Aggregations