diff --git a/app/src/main/java/uk/ac/ebi/atlas/trader/GxaExperimentRepository.java b/app/src/main/java/uk/ac/ebi/atlas/trader/GxaExperimentRepository.java index a1d02bf1..75396899 100644 --- a/app/src/main/java/uk/ac/ebi/atlas/trader/GxaExperimentRepository.java +++ b/app/src/main/java/uk/ac/ebi/atlas/trader/GxaExperimentRepository.java @@ -106,4 +106,9 @@ public Experiment getExperiment(String experimentAccession) { + ": experiment type " + experimentDto.getExperimentType() + " is not supported"); } } + + @Override + public String getExperimentType(String experimentAccession) { + return experimentCrudDao.getExperimentType(experimentAccession); + } } diff --git a/app/src/test/java/uk/ac/ebi/atlas/trader/GxaExperimentRepositoryIT.java b/app/src/test/java/uk/ac/ebi/atlas/trader/GxaExperimentRepositoryIT.java index a604f9eb..ba6cc4bd 100644 --- a/app/src/test/java/uk/ac/ebi/atlas/trader/GxaExperimentRepositoryIT.java +++ b/app/src/test/java/uk/ac/ebi/atlas/trader/GxaExperimentRepositoryIT.java @@ -100,4 +100,22 @@ void baselineProteomicsDiaExperiments() { .isInstanceOf(BaselineExperiment.class) .hasNoNullFieldsOrProperties(); } + + @Test + void whenExperimentDoesNotExists_ThrowsException() { + assertThatExceptionOfType(ResourceNotFoundException.class) + .isThrownBy( + () -> subject.getExperimentType( + jdbcUtils.fetchRandomExperimentAccession() + "_NOT_EXIST") + ); + } + + @Test + void whenExperimentExists_thenReturnsExperimentType() { + var experimentAccession = jdbcUtils.fetchRandomExperimentAccession(); + var originalExperimentType = jdbcUtils.fetchExperimentTypeByAccession(experimentAccession); + var experimentType = subject.getExperimentType(experimentAccession); + + assertThat(experimentType).isEqualTo(originalExperimentType); + } } diff --git a/app/src/test/java/uk/ac/ebi/atlas/trader/GxaExperimentRepositoryTest.java b/app/src/test/java/uk/ac/ebi/atlas/trader/GxaExperimentRepositoryTest.java index e7e26551..115b11c2 100644 --- a/app/src/test/java/uk/ac/ebi/atlas/trader/GxaExperimentRepositoryTest.java +++ b/app/src/test/java/uk/ac/ebi/atlas/trader/GxaExperimentRepositoryTest.java @@ -7,11 +7,13 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; +import uk.ac.ebi.atlas.controllers.ResourceNotFoundException; import uk.ac.ebi.atlas.experimentimport.ExperimentCrudDao; import uk.ac.ebi.atlas.experimentimport.ExperimentDto; import uk.ac.ebi.atlas.experimentimport.idf.IdfParser; import uk.ac.ebi.atlas.experimentimport.idf.IdfParserOutput; import uk.ac.ebi.atlas.model.experiment.ExperimentDesign; +import uk.ac.ebi.atlas.model.experiment.ExperimentType; import uk.ac.ebi.atlas.trader.factory.BaselineExperimentFactory; import uk.ac.ebi.atlas.trader.factory.MicroarrayExperimentFactory; import uk.ac.ebi.atlas.trader.factory.ProteomicsDifferentialExperimentFactory; @@ -24,6 +26,8 @@ import java.util.concurrent.ThreadLocalRandom; import static org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.mockito.Mockito.when; import static uk.ac.ebi.atlas.model.experiment.ExperimentType.SINGLE_CELL_RNASEQ_MRNA_BASELINE; @@ -59,6 +63,9 @@ class GxaExperimentRepositoryTest { private GxaExperimentRepository subject; + private String experimentAccession; + private ExperimentDto experimentDto; + @BeforeEach void setUp() { subject = @@ -70,23 +77,25 @@ void setUp() { rnaSeqDifferentialExperimentFactoryMock, microarrayExperimentFactoryMock, proteomicsDifferentialExperimentFactoryMock); + + experimentAccession = generateRandomExperimentAccession(); + experimentDto = new ExperimentDto( + experimentAccession, + SINGLE_CELL_RNASEQ_MRNA_BASELINE, + generateRandomSpecies().getName(), + ImmutableList.of(generateRandomPubmedId()), + ImmutableList.of(generateRandomDoi()), + new Timestamp(new Date().getTime()), + new Timestamp(new Date().getTime()), + RNG.nextBoolean(), + UUID.randomUUID().toString()); + } @Test void cannotBuildNonBulkExperiments() { - var experimentAccession = generateRandomExperimentAccession(); - when(experimentCrudDaoMock.readExperiment(experimentAccession)) - .thenReturn(new ExperimentDto( - experimentAccession, - SINGLE_CELL_RNASEQ_MRNA_BASELINE, - generateRandomSpecies().getName(), - ImmutableList.of(generateRandomPubmedId()), - ImmutableList.of(generateRandomDoi()), - new Timestamp(new Date().getTime()), - new Timestamp(new Date().getTime()), - RNG.nextBoolean(), - UUID.randomUUID().toString())); + .thenReturn(experimentDto); when(experimentDesignParserMock.parse(experimentAccession)) .thenReturn(new ExperimentDesign()); @@ -102,4 +111,30 @@ void cannotBuildNonBulkExperiments() { assertThatIllegalArgumentException() .isThrownBy(() -> subject.getExperiment(experimentAccession)); } + + @Test + void whenExperimentDoesNotExists_ThrowsException() { + var experimentAccession = generateRandomExperimentAccession(); + + when(experimentCrudDaoMock.getExperimentType(experimentAccession)) + .thenThrow(ResourceNotFoundException.class); + + assertThatExceptionOfType(ResourceNotFoundException.class) + .isThrownBy( + () -> subject.getExperimentType(experimentAccession) + ); + } + + @Test + void whenExperimentExists_thenReturnsExperimentType() { + final String originalExperimentType = experimentDto.getExperimentType().name(); + + when(experimentCrudDaoMock.getExperimentType(experimentAccession)) + .thenReturn(originalExperimentType); + + var experimentType = subject.getExperimentType(experimentAccession); + + assertThat(experimentType).isEqualTo(originalExperimentType); + assertThat(ExperimentType.valueOf(experimentType)).isEqualTo(experimentDto.getExperimentType()); + } } diff --git a/atlas-web-core b/atlas-web-core index 4b7eab49..6db7fa93 160000 --- a/atlas-web-core +++ b/atlas-web-core @@ -1 +1 @@ -Subproject commit 4b7eab49792c3fdd8be0b753108e41d85b5031a7 +Subproject commit 6db7fa9337b6835fd52dfcb9f18381029bac3bab