From 092fea1d41f4075fc66225d3359f23173fc7141a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A1roly=20Erd=C5=91s?= <2183410+ke4@users.noreply.github.com> Date: Thu, 22 Feb 2024 10:38:24 +0000 Subject: [PATCH] [Bugfix] Fix failing unit tests (#386) * Rename non identically named test class Both atlas-web-single-cell and atlas-web-core repository contained a test class with the same package and class name. * Add flexibility for HCA experiment controller's test * Clean TestConfigForHCA by extending TestConfig --- .../atlas/configuration/TestConfigForHCA.java | 57 +++++++++++++++++++ ...rIT.java => IdfParserForSingleCellIT.java} | 3 +- .../HcaHumanExperimentsControllerWIT.java | 7 ++- atlas-web-core | 2 +- 4 files changed, 63 insertions(+), 6 deletions(-) create mode 100644 app/src/test/java/uk/ac/ebi/atlas/configuration/TestConfigForHCA.java rename app/src/test/java/uk/ac/ebi/atlas/experimentimport/idf/{IdfParserIT.java => IdfParserForSingleCellIT.java} (97%) diff --git a/app/src/test/java/uk/ac/ebi/atlas/configuration/TestConfigForHCA.java b/app/src/test/java/uk/ac/ebi/atlas/configuration/TestConfigForHCA.java new file mode 100644 index 000000000..62873c198 --- /dev/null +++ b/app/src/test/java/uk/ac/ebi/atlas/configuration/TestConfigForHCA.java @@ -0,0 +1,57 @@ +package uk.ac.ebi.atlas.configuration; + +import com.google.common.collect.ImmutableSet; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.ComponentScan.Filter; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.FilterType; +import uk.ac.ebi.atlas.hcalandingpage.HcaHumanExperimentDao; +import uk.ac.ebi.atlas.hcalandingpage.HcaHumanExperimentService; +import uk.ac.ebi.atlas.solr.cloud.SolrCloudCollectionProxyFactory; +import uk.ac.ebi.atlas.trader.ExperimentTrader; + +import java.util.Set; + +@Configuration +// Enabling component scanning will also load BasePathsConfig, JdbcConfig and SolrConfig, so just using this class as +// application context is enough in integration tests. It’s important to exclude CacheConfig, otherwise Spring will +// complain if you want to inject classes such as ScxaExperimentTrader, since a proxy will be injected instead! As an +// exercise, remove CacheConfig.class and run tests in ScxaExperimentTraderIT. +@ComponentScan(basePackages = "uk.ac.ebi.atlas", + excludeFilters = @Filter(type = FilterType.ASSIGNABLE_TYPE, + value = {AppConfig.class, CacheConfig.class})) +public class TestConfigForHCA extends TestConfig { + + private static final String INVALID_CHARACTERISTIC_VALUE = "foo"; + private static final String VALID_CHARACTERISTIC_VALUE = "pancreas"; + + private static final ImmutableSet ALL_ACCESSION_IDS = + ImmutableSet.of("E-CURD-4", "E-EHCA-2", "E-GEOD-71585", "E-GEOD-81547", "E-GEOD-99058", "E-MTAB-5061", + "E-ENAD-53"); + + @Bean + public HcaHumanExperimentDao hcaHumanExperimentDao(SolrCloudCollectionProxyFactory solrCloudCollectionProxyFactory) { + + return new HcaHumanExperimentDao(solrCloudCollectionProxyFactory) { + + @Override + public ImmutableSet fetchExperimentAccessions(String characteristicName, + Set characteristicValues) { + if (characteristicValues.contains(INVALID_CHARACTERISTIC_VALUE)) { + return ImmutableSet.of(); + } else if(characteristicValues.contains(VALID_CHARACTERISTIC_VALUE)) { + return ImmutableSet.of("E-MTAB-5061"); + } else { + return ALL_ACCESSION_IDS; + } + } + }; + } + + @Bean + public HcaHumanExperimentService hcaHumanExperimentService(ExperimentTrader experimentTrader, + HcaHumanExperimentDao hcaHumanExperimentDao) { + return new HcaHumanExperimentService(experimentTrader, hcaHumanExperimentDao); + } +} diff --git a/app/src/test/java/uk/ac/ebi/atlas/experimentimport/idf/IdfParserIT.java b/app/src/test/java/uk/ac/ebi/atlas/experimentimport/idf/IdfParserForSingleCellIT.java similarity index 97% rename from app/src/test/java/uk/ac/ebi/atlas/experimentimport/idf/IdfParserIT.java rename to app/src/test/java/uk/ac/ebi/atlas/experimentimport/idf/IdfParserForSingleCellIT.java index 28d71df7f..7ff276982 100644 --- a/app/src/test/java/uk/ac/ebi/atlas/experimentimport/idf/IdfParserIT.java +++ b/app/src/test/java/uk/ac/ebi/atlas/experimentimport/idf/IdfParserForSingleCellIT.java @@ -17,7 +17,6 @@ import javax.inject.Inject; import javax.sql.DataSource; -import java.nio.file.Path; import static org.assertj.core.api.Assertions.assertThat; @@ -25,7 +24,7 @@ @ContextConfiguration(classes = TestConfig.class) @WebAppConfiguration @TestInstance(TestInstance.Lifecycle.PER_CLASS) -class IdfParserIT { +class IdfParserForSingleCellIT { @Inject private DataSource dataSource; diff --git a/app/src/test/java/uk/ac/ebi/atlas/hcalandingpage/HcaHumanExperimentsControllerWIT.java b/app/src/test/java/uk/ac/ebi/atlas/hcalandingpage/HcaHumanExperimentsControllerWIT.java index ceb46cdff..734e799b5 100644 --- a/app/src/test/java/uk/ac/ebi/atlas/hcalandingpage/HcaHumanExperimentsControllerWIT.java +++ b/app/src/test/java/uk/ac/ebi/atlas/hcalandingpage/HcaHumanExperimentsControllerWIT.java @@ -6,6 +6,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.ClassPathResource; import org.springframework.http.MediaType; @@ -16,7 +17,7 @@ import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; -import uk.ac.ebi.atlas.configuration.TestConfig; +import uk.ac.ebi.atlas.configuration.TestConfigForHCA; import javax.inject.Inject; import javax.sql.DataSource; @@ -26,9 +27,9 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -@ExtendWith(SpringExtension.class) +@ExtendWith({MockitoExtension.class, SpringExtension.class}) @WebAppConfiguration -@ContextConfiguration(classes = TestConfig.class) +@ContextConfiguration(classes = TestConfigForHCA.class) @TestInstance(TestInstance.Lifecycle.PER_CLASS) class HcaHumanExperimentsControllerWIT { @Inject diff --git a/atlas-web-core b/atlas-web-core index 2dcf1d8e0..59d2cec77 160000 --- a/atlas-web-core +++ b/atlas-web-core @@ -1 +1 @@ -Subproject commit 2dcf1d8e0e19f58be6971a3f642a50e2da3c1023 +Subproject commit 59d2cec7729ac0b9355f9ceb504e96bec1b742a1