ExperimentCrud { public UUID importExperiment(String experimentAccession, boolean isPrivate) { checkNotNull(experimentAccession); Pair<ExperimentConfiguration, CondensedSdrfParserOutput> files = loadAndValidateFiles(experimentAccession); ExperimentConfiguration experimentConfiguration = files.getLeft(); CondensedSdrfParserOutput condensedSdrfParserOutput = files.getRight(); IdfParserOutput idfParserOutput = idfParser.parse(experimentAccession); Optional<String> accessKey = fetchExperimentAccessKey(experimentAccession); ExperimentDTO experimentDTO = ExperimentDTO.create( condensedSdrfParserOutput, idfParserOutput, condensedSdrfParserOutput .getExperimentDesign() .getSpeciesForAssays( experimentConfiguration.getAssayGroups().stream() .flatMap(assayGroup -> assayGroup.assaysAnalyzedForThisDataColumn().stream()) .collect(Collectors.toSet())), isPrivate); if (accessKey.isPresent()) { deleteExperiment(experimentAccession); } UUID accessKeyUuid = accessKey.map(UUID::fromString).orElseGet(UUID::randomUUID); experimentDao.addExperiment(experimentDTO, accessKeyUuid); updateWithNewExperimentDesign(condensedSdrfParserOutput.getExperimentDesign(), experimentDTO); return accessKeyUuid; } ExperimentCrud(ExperimentDao experimentDao,
                          ExperimentChecker experimentChecker,
                          CondensedSdrfParser condensedSdrfParser,
                          IdfParser idfParser,
                          ExperimentDesignFileWriterService experimentDesignFileWriterService,
                          ConfigurationTrader configurationTrader); UUID importExperiment(String experimentAccession, boolean isPrivate); UUID importSingleCellExperiment(String experimentAccession, boolean isPrivate); void deleteExperiment(String experimentAccession); ExperimentDTO findExperiment(String experimentAccession); List<ExperimentDTO> findAllExperiments(); void makeExperimentPrivate(String experimentAccession); void makeExperimentPublic(String experimentAccession); void updateExperimentDesign(String experimentAccession); void updateSingleCellExperimentDesign(String experimentAccession); void checkFiles(String experimentAccession);  }
@Test(expected = IllegalStateException.class) public void failImportOnValidationWhenExperimentDesignDoesNotMatchAssayGroups() throws IOException { given(condensedSdrfParserOutputMock.getExperimentDesign()).willReturn(new ExperimentDesign()); subject.importExperiment(EXPERIMENT_ACCESSION, false); }
@Test(expected = IllegalStateException.class) public void failImportOnValidationWhenExperimentDesignDoesNotMatchAssayGroups2() throws IOException { when(experimentConfigurationMock.getAssayGroups()) .thenReturn(ImmutableList.of(AssayGroupFactory.create("different assay", "different run"))); subject.importExperiment(EXPERIMENT_ACCESSION, false); }
@Test public void importExperimentParsesDesignFileOnce() throws IOException { subject.importExperiment(EXPERIMENT_ACCESSION, false); verify(condensedSdrfParserMock).parse(EXPERIMENT_ACCESSION, experimentType); }
@Test(expected = UncheckedIOException.class) public void ioExceptionsAreWrapped() throws IOException { doThrow(new IOException()) .when(experimentDesignFileWriterService) .writeExperimentDesignFile( eq(EXPERIMENT_ACCESSION), eq(ExperimentType.RNASEQ_MRNA_BASELINE), any(ExperimentDesign.class)); subject.importExperiment(EXPERIMENT_ACCESSION, false); }