From 786a91f85e61ac3359f54187043cd0ef97e1f1d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A1roly=20Erd=C5=91s?= <2183410+ke4@users.noreply.github.com> Date: Wed, 10 Apr 2024 15:47:42 +0100 Subject: [PATCH] [Bugfix] Alternative view refactoring (#183) * Fix test runners * Upgrade Mockito to 5.2.0 * Add ontology related files to the local Docker env * Remove large experiments from local env * Implement ExperimentCellCountDao interface * Remove experiment design tab from the experiment page * Remove unused stubbing * Add null check * Adjust test to code changes that happened in February 2022 Unfortunately test code was not adjusted when the `download` endpoint has been changed in February 2022 and probably the tests were not executed before the PR as merged. :-( * Add back E-MTAB-5214 to the experiment's fixtures * Add E-MTAB-5555 as a private experiment * Fix experiment fixture for GxaExperimentCrudIT * Remove E-MTAB-5200 from the small-experiment-fixture.sql as we don't have it local * Fix DASFeaturesControllerWIT's featuresURLGeneWithoutExpressions method * Add temporary folders to .gitignore * Fix port related issue for gradle task * New section - How to add a private experiment into our local env * Add known build issue to the README.md * Improve the README.md * Fix anchor in the README * Change property source to git.properties git.properties is being generated by the plugin * Define folder name to git.properties * Remove the definition of the folder for git.properties * Change the path and name of the generated git props file * Refactor how we handle the alternative views of an experiment * Update with the latest atlas-web-core module --- .../atlas/trader/GxaExperimentRepository.java | 5 ++ .../trader/GxaExperimentRepositoryIT.java | 18 ++++++ .../trader/GxaExperimentRepositoryTest.java | 59 +++++++++++++++---- atlas-web-core | 2 +- 4 files changed, 71 insertions(+), 13 deletions(-) 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