From: Andreas Müller Date: Wed, 31 Jan 2024 22:03:53 +0000 (+0100) Subject: ref #9500, ref #10330 add term tree based test but still use partOf version to be... X-Git-Tag: 5.42.0^2~18 X-Git-Url: https://dev.e-taxonomy.eu/gitweb/cdmlib.git/commitdiff_plain/12ebfd050581c6b5028613d5df03edf3b1677a37 ref #9500, ref #10330 add term tree based test but still use partOf version to be tested as long as it still exists --- diff --git a/cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/geo/DistributionServiceUtilitiesTest.java b/cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/geo/DistributionServiceUtilitiesTest.java index 75410b2e9d..6104e67519 100644 --- a/cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/geo/DistributionServiceUtilitiesTest.java +++ b/cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/geo/DistributionServiceUtilitiesTest.java @@ -110,9 +110,6 @@ public class DistributionServiceUtilitiesTest extends TermTestBase { @Before public void setup(){ //for testFilterXXX distributions = new ArrayList<>(); - - berlin = NamedArea.NewInstance("Berlin", "Berlin", "BER"); - berlin.setPartOf(Country.GERMANY()); } //copied from CondensedDistributionComposerEuroMedTest @@ -263,6 +260,7 @@ public class DistributionServiceUtilitiesTest extends TermTestBase { @Test public void testFilterDistributions_aggregated(){ + berlin = NamedArea.NewInstance("Berlin", "Berlin", "BER"); /* 1. * Aggregated elements are preferred over entered or imported elements @@ -335,9 +333,18 @@ public class DistributionServiceUtilitiesTest extends TermTestBase { @Test public void testFilterDistributions_subAreaPreference(){ subAreaPreference = true; + //NOTE: once removing partOf methods use areaTreeNotYetInUse instead TermTree areaTree = null; + TermTree areaTreeNotYetInUse = TermTree.NewInstance(TermType.NamedArea); TermTree statusTree = null; + berlin = NamedArea.NewInstance("Berlin", "Berlin", "BER"); + berlin.setPartOf(Country.GERMANY()); + TermNode germanyNode = areaTreeNotYetInUse.getRoot().addChild(Country.GERMANY()); + germanyNode.addChild(berlin); + //add europe, but not yet as parent of Germany + TermNode europeNode = areaTreeNotYetInUse.getRoot().addChild(NamedArea.EUROPE()); + /* * Sub area preference rule: If there is an area with a direct sub area * and both areas have the same status only the information on @@ -369,6 +376,7 @@ public class DistributionServiceUtilitiesTest extends TermTestBase { //now add Europe as parent of Germany => Europe should be removed Country.GERMANY().setPartOf(NamedArea.EUROPE()); + europeNode.addChild(germanyNode); filteredDistributions = DistributionServiceUtilities.filterDistributions(distributions, areaTree, statusTree, hideMarkedAreas, NO_PREFER_AGGREGATED, statusOrderPreference, subAreaPreference, true); Assert.assertEquals("Europe should be removed as in is a parent of Germany and ancestor of berlin", 1, filteredDistributions.size()); @@ -377,14 +385,14 @@ public class DistributionServiceUtilitiesTest extends TermTestBase { //now remove Germany from distributions => Europe should still be removed as it is an ancestor of berlin distributions.remove(distGermany); - Country.GERMANY().setPartOf(NamedArea.EUROPE()); filteredDistributions = DistributionServiceUtilities.filterDistributions(distributions, areaTree, statusTree, hideMarkedAreas, NO_PREFER_AGGREGATED, statusOrderPreference, subAreaPreference, true); Assert.assertEquals("Europe should be removed as it is an ancestor of berlin", 1, filteredDistributions.size()); //do not remove other area Distribution distFrance = Distribution.NewInstance(Country.FRANCE(), PresenceAbsenceTerm.NATIVE()); - Country.FRANCE().setPartOf(NamedArea.EUROPE()); + Country.FRANCE().setPartOf(NamedArea.EUROPE()); // + europeNode.addChild(Country.FRANCE()); distributions.add(distFrance); filteredDistributions = DistributionServiceUtilities.filterDistributions(distributions, areaTree, statusTree, hideMarkedAreas, NO_PREFER_AGGREGATED, statusOrderPreference, subAreaPreference, true);