From 36ce66180b8103d16a9d63bc21b86174c79349e7 Mon Sep 17 00:00:00 2001 From: pal155 Date: Tue, 9 Feb 2021 10:41:13 +1100 Subject: [PATCH 1/2] Fix test cases in travis --- .../java/au/org/ala/sds/model/SensitivityZoneTest.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/test/java/au/org/ala/sds/model/SensitivityZoneTest.java b/src/test/java/au/org/ala/sds/model/SensitivityZoneTest.java index 9e01916a..98b1041f 100644 --- a/src/test/java/au/org/ala/sds/model/SensitivityZoneTest.java +++ b/src/test/java/au/org/ala/sds/model/SensitivityZoneTest.java @@ -14,12 +14,17 @@ ***************************************************************************/ package au.org.ala.sds.model; +import org.junit.BeforeClass; +import org.junit.Test; + import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import org.junit.Test; - public class SensitivityZoneTest { + @BeforeClass + public static void runOnce() throws Exception { + System.setProperty("sds.config.file", "/sds-test.properties"); + } @Test public void isInAustralia() { From 412034cdd6836b0684292fc41b1e6cf8a5ccc792 Mon Sep 17 00:00:00 2001 From: pal155 Date: Tue, 9 Feb 2021 15:01:52 +1100 Subject: [PATCH 2/2] Fix test cases in travis --- pom.xml | 6 ++++++ .../ala/sds/ExoticBiologicalControlTest.java | 4 ++-- .../java/au/org/ala/sds/GeneraliseTest.java | 3 ++- .../org/ala/sds/PlantPestCategory5Test.java | 3 ++- .../org/ala/sds/PlantPestEradicatedTest.java | 5 ++++- .../PlantPestIdentifiedToHigherTaxonTest.java | 3 ++- .../sds/PlantPestNotKnownInAustraliaTest.java | 3 ++- ...PlantPestSubjectToOfficialControlTest.java | 3 ++- .../sds/PlantPestUnderEradicationTest.java | 3 ++- .../org/ala/sds/ProblematicFileInputTest.java | 3 ++- .../java/au/org/ala/sds/ScotlandTests.java | 3 ++- src/test/java/au/org/ala/sds/SearchTest.java | 3 ++- .../org/ala/sds/SensitiveDataServiceTest.java | 3 ++- .../sds/model/SensitiveSpeciesStoreTest.java | 6 ++---- .../ala/sds/model/SensitivityZoneTest.java | 3 ++- .../au/org/ala/sds/util/GeoLocationTest.java | 2 +- .../java/au/org/ala/sds/util/TestUtils.java | 20 +++++++++++++++++++ src/test/resources/log4j.xml | 4 ++-- 18 files changed, 59 insertions(+), 21 deletions(-) create mode 100644 src/test/java/au/org/ala/sds/util/TestUtils.java diff --git a/pom.xml b/pom.xml index 4173c668..a2880ecb 100644 --- a/pom.xml +++ b/pom.xml @@ -57,6 +57,12 @@ au.org.ala ala-name-matching 3.5 + + + ch.qos.logback + logback-classic + + compile diff --git a/src/test/java/au/org/ala/sds/ExoticBiologicalControlTest.java b/src/test/java/au/org/ala/sds/ExoticBiologicalControlTest.java index f47abf10..326cf8ad 100644 --- a/src/test/java/au/org/ala/sds/ExoticBiologicalControlTest.java +++ b/src/test/java/au/org/ala/sds/ExoticBiologicalControlTest.java @@ -17,6 +17,7 @@ import au.org.ala.names.search.ALANameSearcher; import au.org.ala.sds.model.SensitiveTaxon; import au.org.ala.sds.util.Configuration; +import au.org.ala.sds.util.TestUtils; import au.org.ala.sds.validation.*; import org.junit.BeforeClass; import org.junit.Test; @@ -34,8 +35,7 @@ public class ExoticBiologicalControlTest { @BeforeClass public static void runOnce() throws Exception { - - System.setProperty("sds.config.file", "/sds-test.properties"); + TestUtils.initConfig(); System.out.println(Configuration.getInstance().getNameMatchingIndex()); nameSearcher = new ALANameSearcher(Configuration.getInstance().getNameMatchingIndex()); //The URI to the test list - only contains entries that are used in one or more the the tests diff --git a/src/test/java/au/org/ala/sds/GeneraliseTest.java b/src/test/java/au/org/ala/sds/GeneraliseTest.java index e0c7f2de..5ba18c88 100644 --- a/src/test/java/au/org/ala/sds/GeneraliseTest.java +++ b/src/test/java/au/org/ala/sds/GeneraliseTest.java @@ -22,6 +22,7 @@ import java.util.HashMap; import java.util.Map; +import au.org.ala.sds.util.TestUtils; import org.junit.BeforeClass; import org.junit.Test; @@ -51,7 +52,7 @@ public static void runOnce() throws Exception { // ((BasicDataSource) dataSource).setUsername("root"); // ((BasicDataSource) dataSource).setPassword("password"); - System.setProperty("sds.config.file", "/sds-test.properties"); + TestUtils.initConfig(); nameSearcher = new ALANameSearcher(Configuration.getInstance().getNameMatchingIndex()); //finder = SensitiveSpeciesFinderFactory.getSensitiveSpeciesFinder(cbIndexSearch); String uri = nameSearcher.getClass().getClassLoader().getResource("sensitive-species.xml").toURI().toString(); diff --git a/src/test/java/au/org/ala/sds/PlantPestCategory5Test.java b/src/test/java/au/org/ala/sds/PlantPestCategory5Test.java index 413ec951..a5095d38 100644 --- a/src/test/java/au/org/ala/sds/PlantPestCategory5Test.java +++ b/src/test/java/au/org/ala/sds/PlantPestCategory5Test.java @@ -18,6 +18,7 @@ import au.org.ala.sds.model.SensitiveTaxon; import au.org.ala.sds.util.Configuration; import au.org.ala.sds.util.PlantPestUtils; +import au.org.ala.sds.util.TestUtils; import au.org.ala.sds.validation.MessageFactory; import au.org.ala.sds.validation.ServiceFactory; import au.org.ala.sds.validation.ValidationOutcome; @@ -46,7 +47,7 @@ public class PlantPestCategory5Test { @BeforeClass public static void runOnce() throws Exception { - System.setProperty("sds.config.file", "/sds-test.properties"); + TestUtils.initConfig(); System.out.println(Configuration.getInstance().getNameMatchingIndex()); nameSearcher = new ALANameSearcher(Configuration.getInstance().getNameMatchingIndex()); //The URI to the test list - only contains entries that are used in one or more the the tests diff --git a/src/test/java/au/org/ala/sds/PlantPestEradicatedTest.java b/src/test/java/au/org/ala/sds/PlantPestEradicatedTest.java index 277b3e8b..71a0a41f 100644 --- a/src/test/java/au/org/ala/sds/PlantPestEradicatedTest.java +++ b/src/test/java/au/org/ala/sds/PlantPestEradicatedTest.java @@ -20,6 +20,7 @@ import au.org.ala.sds.model.Message; import au.org.ala.sds.util.AUWorkarounds; import au.org.ala.sds.util.GeoLocationHelper; +import au.org.ala.sds.util.TestUtils; import au.org.ala.sds.validation.*; import org.junit.BeforeClass; import org.junit.Ignore; @@ -50,7 +51,9 @@ public static void runOnce() throws Exception { // ((BasicDataSource) dataSource).setUsername("root"); // ((BasicDataSource) dataSource).setPassword("password"); - System.setProperty("sds.config.file", "/sds-test.properties"); + TestUtils.initConfig(); + Configuration.getInstance().setZoneUrl(PlantPestEradicatedTest.class.getResource("/sensitivity-zones.xml").toExternalForm()); + Configuration.getInstance().setCategoriesUrl(PlantPestEradicatedTest.class.getResource("/sensitivity-categories.xml").toExternalForm()); nameSearcher = new ALANameSearcher(Configuration.getInstance().getNameMatchingIndex()); //finder = SensitiveSpeciesFinderFactory.getSensitiveSpeciesFinder("file:///data/sds/sensitive-species-new.xml", cbIndexSearch); String uri = nameSearcher.getClass().getClassLoader().getResource("sensitive-species.xml").toURI().toString(); diff --git a/src/test/java/au/org/ala/sds/PlantPestIdentifiedToHigherTaxonTest.java b/src/test/java/au/org/ala/sds/PlantPestIdentifiedToHigherTaxonTest.java index 035f86bd..d71d83bf 100644 --- a/src/test/java/au/org/ala/sds/PlantPestIdentifiedToHigherTaxonTest.java +++ b/src/test/java/au/org/ala/sds/PlantPestIdentifiedToHigherTaxonTest.java @@ -18,6 +18,7 @@ import au.org.ala.sds.model.SensitiveTaxon; import au.org.ala.sds.util.Configuration; import au.org.ala.sds.util.PlantPestUtils; +import au.org.ala.sds.util.TestUtils; import au.org.ala.sds.validation.*; import org.junit.BeforeClass; import org.junit.Test; @@ -39,7 +40,7 @@ public class PlantPestIdentifiedToHigherTaxonTest { @BeforeClass public static void runOnce() throws Exception { - System.setProperty("sds.config.file", "/sds-test.properties"); + TestUtils.initConfig(); System.out.println(Configuration.getInstance().getNameMatchingIndex()); nameSearcher = new ALANameSearcher(Configuration.getInstance().getNameMatchingIndex()); //The URI to the test list - only contains entries that are used in one or more the the tests diff --git a/src/test/java/au/org/ala/sds/PlantPestNotKnownInAustraliaTest.java b/src/test/java/au/org/ala/sds/PlantPestNotKnownInAustraliaTest.java index c8f8a672..5430b03f 100644 --- a/src/test/java/au/org/ala/sds/PlantPestNotKnownInAustraliaTest.java +++ b/src/test/java/au/org/ala/sds/PlantPestNotKnownInAustraliaTest.java @@ -19,6 +19,7 @@ import java.util.Map; import au.org.ala.sds.model.Message; +import au.org.ala.sds.util.TestUtils; import au.org.ala.sds.validation.*; import org.junit.BeforeClass; import org.junit.Ignore; @@ -45,7 +46,7 @@ public class PlantPestNotKnownInAustraliaTest { @BeforeClass public static void runOnce() throws Exception { - System.setProperty("sds.config.file", "/sds-test.properties"); + TestUtils.initConfig(); nameSearcher = new ALANameSearcher(Configuration.getInstance().getNameMatchingIndex()); //use test versions // Configuration.getInstance().setZoneUrl(nameSearcher.getClass().getClassLoader().getResource("sensitivity-zones.xml").toURI().toString()); diff --git a/src/test/java/au/org/ala/sds/PlantPestSubjectToOfficialControlTest.java b/src/test/java/au/org/ala/sds/PlantPestSubjectToOfficialControlTest.java index 4ecbf0cc..4706efe6 100644 --- a/src/test/java/au/org/ala/sds/PlantPestSubjectToOfficialControlTest.java +++ b/src/test/java/au/org/ala/sds/PlantPestSubjectToOfficialControlTest.java @@ -21,6 +21,7 @@ import au.org.ala.sds.model.Message; import au.org.ala.sds.util.AUWorkarounds; import au.org.ala.sds.util.GeoLocationHelper; +import au.org.ala.sds.util.TestUtils; import au.org.ala.sds.validation.*; import org.junit.BeforeClass; import org.junit.Ignore; @@ -51,7 +52,7 @@ public static void runOnce() throws Exception { // ((BasicDataSource) dataSource).setUsername("root"); // ((BasicDataSource) dataSource).setPassword("password"); - System.setProperty("sds.config.file", "/sds-test.properties"); + TestUtils.initConfig(); nameSearcher = new ALANameSearcher(Configuration.getInstance().getNameMatchingIndex()); //finder = SensitiveSpeciesFinderFactory.getSensitiveSpeciesFinder("file:///data/sds/sensitive-species-test.xml", cbIndexSearch); String uri = nameSearcher.getClass().getClassLoader().getResource("sensitive-species.xml").toURI().toString(); diff --git a/src/test/java/au/org/ala/sds/PlantPestUnderEradicationTest.java b/src/test/java/au/org/ala/sds/PlantPestUnderEradicationTest.java index c64d709d..72392cc6 100644 --- a/src/test/java/au/org/ala/sds/PlantPestUnderEradicationTest.java +++ b/src/test/java/au/org/ala/sds/PlantPestUnderEradicationTest.java @@ -18,6 +18,7 @@ import au.org.ala.sds.model.SensitiveTaxon; import au.org.ala.sds.util.AUWorkarounds; import au.org.ala.sds.util.GeoLocationHelper; +import au.org.ala.sds.util.TestUtils; import au.org.ala.sds.validation.*; import org.junit.BeforeClass; import org.junit.Test; @@ -51,7 +52,7 @@ public static void runOnce() throws Exception { // ((BasicDataSource) dataSource).setUsername("root"); // ((BasicDataSource) dataSource).setPassword("password"); - System.setProperty("sds.config.file", "/sds-test.properties"); + TestUtils.initConfig(); nameSearcher = new ALANameSearcher(Configuration.getInstance().getNameMatchingIndex()); //finder = SensitiveSpeciesFinderFactory.getSensitiveSpeciesFinder("file:///data/sds/sensitive-species-new.xml", cbIndexSearch); String uri = nameSearcher.getClass().getClassLoader().getResource("sensitive-species.xml").toURI().toString(); diff --git a/src/test/java/au/org/ala/sds/ProblematicFileInputTest.java b/src/test/java/au/org/ala/sds/ProblematicFileInputTest.java index 321abf8e..938fae3c 100644 --- a/src/test/java/au/org/ala/sds/ProblematicFileInputTest.java +++ b/src/test/java/au/org/ala/sds/ProblematicFileInputTest.java @@ -2,6 +2,7 @@ import java.util.Map; +import au.org.ala.sds.util.TestUtils; import org.apache.commons.lang.StringUtils; import org.junit.BeforeClass; import org.junit.Test; @@ -26,7 +27,7 @@ public class ProblematicFileInputTest { //@BeforeClass public static void runOnce() throws Exception { - System.setProperty("sds.config.file", "/sds-test.properties"); + TestUtils.initConfig(); nameSearcher = new ALANameSearcher(Configuration.getInstance().getNameMatchingIndex()); finder = SensitiveSpeciesFinderFactory.getSensitiveSpeciesFinder("file:///data/sds/sensitive-species.xml", nameSearcher); } diff --git a/src/test/java/au/org/ala/sds/ScotlandTests.java b/src/test/java/au/org/ala/sds/ScotlandTests.java index 1c52da18..a7da9d8f 100644 --- a/src/test/java/au/org/ala/sds/ScotlandTests.java +++ b/src/test/java/au/org/ala/sds/ScotlandTests.java @@ -4,6 +4,7 @@ import au.org.ala.sds.model.SensitiveTaxon; import au.org.ala.sds.model.SensitivityZoneFactory; import au.org.ala.sds.util.Configuration; +import au.org.ala.sds.util.TestUtils; import au.org.ala.sds.validation.ValidationOutcome; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -25,7 +26,7 @@ public class ScotlandTests { @BeforeClass public static void runOnce() throws Exception { - System.setProperty("sds.config.file", "/sds-test.properties"); + TestUtils.initConfig(); SensitivityZoneFactory.reset(); //FIXME this isnt pleasant nameSearcher = new ALANameSearcher(Configuration.getInstance().getNameMatchingIndex()); String uri = nameSearcher.getClass().getClassLoader().getResource("sensitive-species-scotland.xml").toURI().toString(); diff --git a/src/test/java/au/org/ala/sds/SearchTest.java b/src/test/java/au/org/ala/sds/SearchTest.java index 46e2dda8..30c3ea84 100644 --- a/src/test/java/au/org/ala/sds/SearchTest.java +++ b/src/test/java/au/org/ala/sds/SearchTest.java @@ -17,6 +17,7 @@ import au.org.ala.names.search.ALANameSearcher; import au.org.ala.sds.model.SensitiveTaxon; import au.org.ala.sds.util.Configuration; +import au.org.ala.sds.util.TestUtils; import org.junit.BeforeClass; import org.junit.Test; @@ -33,7 +34,7 @@ public class SearchTest { @BeforeClass public static void runOnce() throws Exception { - System.setProperty("sds.config.file", "/sds-test.properties"); + TestUtils.initConfig(); nameSearcher = new ALANameSearcher(Configuration.getInstance().getNameMatchingIndex()); String uri = nameSearcher.getClass().getClassLoader().getResource("sensitive-species.xml").toURI().toString(); finder = SensitiveSpeciesFinderFactory.getSensitiveSpeciesFinder(uri, nameSearcher, true); diff --git a/src/test/java/au/org/ala/sds/SensitiveDataServiceTest.java b/src/test/java/au/org/ala/sds/SensitiveDataServiceTest.java index 58736567..ccb3b32a 100644 --- a/src/test/java/au/org/ala/sds/SensitiveDataServiceTest.java +++ b/src/test/java/au/org/ala/sds/SensitiveDataServiceTest.java @@ -16,6 +16,7 @@ import au.org.ala.names.search.ALANameSearcher; import au.org.ala.sds.util.Configuration; +import au.org.ala.sds.util.TestUtils; import au.org.ala.sds.validation.FactCollection; import au.org.ala.sds.validation.MessageFactory; import au.org.ala.sds.validation.ValidationOutcome; @@ -41,7 +42,7 @@ public class SensitiveDataServiceTest { @BeforeClass public static void runOnce() throws Exception { - System.setProperty("sds.config.file", "/sds-test.properties"); + TestUtils.initConfig(); System.out.println(Configuration.getInstance().getNameMatchingIndex()); nameSearcher = new ALANameSearcher(Configuration.getInstance().getNameMatchingIndex()); //The URI to the test list - only contains entries that are used in one or more the the tests diff --git a/src/test/java/au/org/ala/sds/model/SensitiveSpeciesStoreTest.java b/src/test/java/au/org/ala/sds/model/SensitiveSpeciesStoreTest.java index 51774e68..adff13c2 100644 --- a/src/test/java/au/org/ala/sds/model/SensitiveSpeciesStoreTest.java +++ b/src/test/java/au/org/ala/sds/model/SensitiveSpeciesStoreTest.java @@ -18,15 +18,13 @@ import au.org.ala.sds.SensitiveSpeciesFinder; import au.org.ala.sds.SensitiveSpeciesFinderFactory; import au.org.ala.sds.util.Configuration; +import au.org.ala.sds.util.TestUtils; import org.junit.Test; public class SensitiveSpeciesStoreTest { @Test public void testCreate() throws Exception { - System.setProperty("sds.config.file", "/sds-test.properties"); - Configuration.getInstance().setSpeciesUrl(SensitiveSpeciesStoreTest.class.getResource("/sensitive-species.xml").toExternalForm()); - Configuration.getInstance().setZoneUrl(SensitiveSpeciesStoreTest.class.getResource("/sensitivity-zones.xml").toExternalForm()); - Configuration.getInstance().setCategoriesUrl(SensitiveSpeciesStoreTest.class.getResource("/sensitivity-categories.xml").toExternalForm()); + TestUtils.initConfig(); SensitiveSpeciesFinder finder = SensitiveSpeciesFinderFactory.getSensitiveSpeciesFinder(new ALANameSearcher(Configuration.getInstance().getNameMatchingIndex())); SensitiveTaxon taxon = finder.findSensitiveSpecies("Acacia dealbata"); } diff --git a/src/test/java/au/org/ala/sds/model/SensitivityZoneTest.java b/src/test/java/au/org/ala/sds/model/SensitivityZoneTest.java index 98b1041f..a3ddfb5b 100644 --- a/src/test/java/au/org/ala/sds/model/SensitivityZoneTest.java +++ b/src/test/java/au/org/ala/sds/model/SensitivityZoneTest.java @@ -14,6 +14,7 @@ ***************************************************************************/ package au.org.ala.sds.model; +import au.org.ala.sds.util.TestUtils; import org.junit.BeforeClass; import org.junit.Test; @@ -23,7 +24,7 @@ public class SensitivityZoneTest { @BeforeClass public static void runOnce() throws Exception { - System.setProperty("sds.config.file", "/sds-test.properties"); + TestUtils.initConfig(); } @Test diff --git a/src/test/java/au/org/ala/sds/util/GeoLocationTest.java b/src/test/java/au/org/ala/sds/util/GeoLocationTest.java index 6f3bcc59..c5baf738 100644 --- a/src/test/java/au/org/ala/sds/util/GeoLocationTest.java +++ b/src/test/java/au/org/ala/sds/util/GeoLocationTest.java @@ -31,7 +31,7 @@ public class GeoLocationTest { @BeforeClass public static void runOnce() throws Exception { - System.setProperty("sds.config.file", "/sds-test.properties"); + TestUtils.initConfig(); } diff --git a/src/test/java/au/org/ala/sds/util/TestUtils.java b/src/test/java/au/org/ala/sds/util/TestUtils.java new file mode 100644 index 00000000..c53b05d8 --- /dev/null +++ b/src/test/java/au/org/ala/sds/util/TestUtils.java @@ -0,0 +1,20 @@ +package au.org.ala.sds.util; + +import au.org.ala.names.search.ALANameSearcher; +import au.org.ala.sds.PlantPestEradicatedTest; +import au.org.ala.sds.SensitiveSpeciesFinderFactory; + +public class TestUtils { + /** + * Set up a common configuration + * + * @throws Exception + */ + public static void initConfig() throws Exception { + System.setProperty("sds.config.file", "/sds-test.properties"); + Configuration.getInstance().setSpeciesUrl(TestUtils.class.getResource("/sensitive-species.xml").toExternalForm()); + Configuration.getInstance().setZoneUrl(TestUtils.class.getResource("/sensitivity-zones.xml").toExternalForm()); + Configuration.getInstance().setCategoriesUrl(TestUtils.class.getResource("/sensitivity-categories.xml").toExternalForm()); + } + +} diff --git a/src/test/resources/log4j.xml b/src/test/resources/log4j.xml index 600b1ad9..cd42d1d2 100644 --- a/src/test/resources/log4j.xml +++ b/src/test/resources/log4j.xml @@ -5,7 +5,7 @@ - + @@ -27,7 +27,7 @@ - +