Project

General

Profile

Revision c729e881

IDc729e88110b0496dc3f24b1d552dea39ad158386
Parent 88ffe656
Child a33d468f

Added by Andreas Müller 2 months ago

ref #8297, ref #9521 test for recursive fallback area recognition in filterDistributions

View differences:

cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/utility/DescriptionUtilityTest.java
11 11
import java.util.ArrayList;
12 12
import java.util.Collection;
13 13
import java.util.HashSet;
14
import java.util.List;
14 15
import java.util.Set;
16
import java.util.stream.Collector;
17
import java.util.stream.Collectors;
15 18

  
16 19
import org.junit.Assert;
17 20
import org.junit.Before;
......
40 43
    private Set<MarkerType> hideMarkedAreas = null;
41 44
    private NamedArea berlin = null;
42 45

  
46
    private Collector<NamedArea, ?, List<NamedArea>> toList = Collectors.toList();
47
    private static final boolean NO_PREFER_AGGREGATED = false;
48

  
43 49
    @Before
44 50
    public void setup(){
45 51
        distributions = new ArrayList<>();
......
116 122
    @Test
117 123
    public void testFilterDistributions_subAreaPreference(){
118 124
        subAreaPreference = true;
119
        boolean preferAggregated = false;
120 125

  
121 126
        /*
122 127
         * Sub area preference rule: If there is an area with a direct sub area
......
139 144
        distributions.add(distGermany);
140 145
        distributions.add(distBerlin);
141 146
        filteredDistributions = DescriptionUtility.filterDistributions(distributions,
142
                hideMarkedAreas, preferAggregated, statusOrderPreference, subAreaPreference, true, false);
147
                hideMarkedAreas, NO_PREFER_AGGREGATED, statusOrderPreference, subAreaPreference, true, false);
143 148
        Assert.assertEquals(1, filteredDistributions.size());
144 149
        Assert.assertEquals(berlin, filteredDistributions.iterator().next().getArea());
145 150

  
146 151
        // mixed situation
147 152
        distGermany.addMarker(Marker.NewInstance(MarkerType.COMPUTED(), true));
148 153
        filteredDistributions = DescriptionUtility.filterDistributions(distributions,
149
                hideMarkedAreas, preferAggregated, statusOrderPreference, subAreaPreference, true, false);
154
                hideMarkedAreas, NO_PREFER_AGGREGATED, statusOrderPreference, subAreaPreference, true, false);
150 155
        Assert.assertEquals(1, filteredDistributions.size());
151 156
        Assert.assertEquals(berlin, filteredDistributions.iterator().next().getArea());
152 157

  
153 158
        // all computed
154 159
        distBerlin.addMarker(Marker.NewInstance(MarkerType.COMPUTED(), true));
155 160
        filteredDistributions = DescriptionUtility.filterDistributions(distributions,
156
                hideMarkedAreas, preferAggregated, statusOrderPreference, subAreaPreference, true, false);
161
                hideMarkedAreas, NO_PREFER_AGGREGATED, statusOrderPreference, subAreaPreference, true, false);
157 162
        Assert.assertEquals(1, filteredDistributions.size());
158 163
        Assert.assertEquals(berlin, filteredDistributions.iterator().next().getArea());
159 164
    }
......
191 196
    @Test
192 197
    public void testFilterDistributions_fallbackArea_hidden(){
193 198

  
194
        boolean preferAggregated = false;
195

  
196
        NamedArea jugoslavia = NamedArea.NewInstance("Former Yugoslavia ", "", "Ju");
197
        jugoslavia.setIdInVocabulary("Ju");
198
        NamedArea serbia = NamedArea.NewInstance("Serbia", "", "Sr");
199
        serbia.setIdInVocabulary("Sr");
199
        NamedArea jugoslavia = NamedArea.NewInstance("", "Former Yugoslavia", "Ju");
200
        NamedArea serbia = NamedArea.NewInstance("", "Serbia", "Sr");
200 201
        jugoslavia.addIncludes(serbia);
201 202

  
203

  
202 204
        Distribution distJugoslavia = Distribution.NewInstance(jugoslavia, PresenceAbsenceTerm.NATIVE());
203 205
        Distribution distSerbia = Distribution.NewInstance(serbia, PresenceAbsenceTerm.NATIVE());
204 206

  
......
211 213
        hideMarkedAreas = new HashSet<>();
212 214
        hideMarkedAreas.add(MarkerType.TO_BE_CHECKED());
213 215

  
216
        boolean keepFallBackOnlyIfNoSubareaDataExists = true;
214 217
        filteredDistributions = DescriptionUtility.filterDistributions(
215 218
                distributions,
216 219
                hideMarkedAreas,
217
                preferAggregated,
220
                NO_PREFER_AGGREGATED,
218 221
                statusOrderPreference,
219 222
                subAreaPreference,
220
                true, false);
223
                keepFallBackOnlyIfNoSubareaDataExists, false);
224

  
225
        Assert.assertEquals(1, filteredDistributions.size());
226
        Assert.assertEquals(serbia, filteredDistributions.iterator().next().getArea());
227

  
228
        keepFallBackOnlyIfNoSubareaDataExists = false;
229
        filteredDistributions = DescriptionUtility.filterDistributions(
230
                distributions,
231
                hideMarkedAreas,
232
                NO_PREFER_AGGREGATED,
233
                statusOrderPreference,
234
                subAreaPreference,
235
                keepFallBackOnlyIfNoSubareaDataExists, false);
236

  
237
        Assert.assertEquals(2, filteredDistributions.size());
238
        Assert.assertTrue(filteredDistributions.stream().map(d->d.getArea()).collect(toList).contains(serbia));
239
        Assert.assertTrue(filteredDistributions.stream().map(d->d.getArea()).collect(toList).contains(jugoslavia));
240
    }
241

  
242
    @Test
243
    public void testFilterDistributions_fallbackArea_recursive(){
244

  
245
        NamedArea jugoslavia = NamedArea.NewInstance("", "Former Yugoslavia", "Ju");
246
        NamedArea serbia = NamedArea.NewInstance("", "Serbia", "Sr");
247
        jugoslavia.addIncludes(serbia);
248
        NamedArea partOfSerbia = NamedArea.NewInstance("", "Part-of-Serbia", "PoS");
249
        serbia.addIncludes(partOfSerbia);
250

  
251
        Distribution distJugoslavia = Distribution.NewInstance(jugoslavia, PresenceAbsenceTerm.NATIVE());
252
        Distribution distSerbia = Distribution.NewInstance(serbia, PresenceAbsenceTerm.NATIVE());
253
        Distribution distPartOfSerbia = Distribution.NewInstance(partOfSerbia, PresenceAbsenceTerm.NATIVE());
254

  
255
        distributions.add(distJugoslavia);
256

  
257
        // using TO_BE_CHECKED to mark Ju as fallback area
258
        jugoslavia.addMarker(Marker.NewInstance(MarkerType.TO_BE_CHECKED(), true));
259
        serbia.addMarker(Marker.NewInstance(MarkerType.TO_BE_CHECKED(), true));
260

  
261
        hideMarkedAreas = new HashSet<>();
262
        hideMarkedAreas.add(MarkerType.TO_BE_CHECKED());
263

  
264
        boolean keepFallBackOnlyIfNoSubareaDataExists = true;
265
        filteredDistributions = DescriptionUtility.filterDistributions(
266
                distributions, hideMarkedAreas, NO_PREFER_AGGREGATED,
267
                statusOrderPreference, subAreaPreference,
268
                keepFallBackOnlyIfNoSubareaDataExists, false);
269

  
270
        Assert.assertEquals(1, filteredDistributions.size());
271

  
272

  
273
        keepFallBackOnlyIfNoSubareaDataExists = false;
274
        filteredDistributions = DescriptionUtility.filterDistributions(
275
                distributions, hideMarkedAreas, NO_PREFER_AGGREGATED,
276
                statusOrderPreference, subAreaPreference,
277
                keepFallBackOnlyIfNoSubareaDataExists, false);
278

  
279
        Assert.assertEquals(1, filteredDistributions.size());
280
        Assert.assertEquals(jugoslavia, filteredDistributions.iterator().next().getArea());
281

  
282
        keepFallBackOnlyIfNoSubareaDataExists = true;
283
        distributions.add(distSerbia);
284
        filteredDistributions = DescriptionUtility.filterDistributions(
285
                distributions, hideMarkedAreas, NO_PREFER_AGGREGATED,
286
                statusOrderPreference, subAreaPreference,
287
                keepFallBackOnlyIfNoSubareaDataExists, false);
221 288

  
222 289
        Assert.assertEquals(1, filteredDistributions.size());
223 290
        Assert.assertEquals(serbia, filteredDistributions.iterator().next().getArea());
291

  
292
        keepFallBackOnlyIfNoSubareaDataExists = false;
293
        filteredDistributions = DescriptionUtility.filterDistributions(
294
                distributions, hideMarkedAreas, NO_PREFER_AGGREGATED,
295
                statusOrderPreference, subAreaPreference,
296
                keepFallBackOnlyIfNoSubareaDataExists, false);
297
        Assert.assertEquals(2, filteredDistributions.size());
298
        Assert.assertTrue(filteredDistributions.stream().map(d->d.getArea()).collect(toList).contains(jugoslavia));
299
        Assert.assertTrue(filteredDistributions.stream().map(d->d.getArea()).collect(toList).contains(serbia));
300

  
301
        distributions.add(distPartOfSerbia);
302
        keepFallBackOnlyIfNoSubareaDataExists = true;
303
        filteredDistributions = DescriptionUtility.filterDistributions(
304
                distributions, hideMarkedAreas, NO_PREFER_AGGREGATED,
305
                statusOrderPreference, subAreaPreference,
306
                keepFallBackOnlyIfNoSubareaDataExists, false);
307

  
308
        Assert.assertEquals(1, filteredDistributions.size());
309
        Assert.assertEquals(partOfSerbia, filteredDistributions.iterator().next().getArea());
310

  
311
        keepFallBackOnlyIfNoSubareaDataExists = false;
312
        filteredDistributions = DescriptionUtility.filterDistributions(
313
                distributions, hideMarkedAreas, NO_PREFER_AGGREGATED,
314
                statusOrderPreference, subAreaPreference,
315
                keepFallBackOnlyIfNoSubareaDataExists, false);
316
        Assert.assertEquals(3, filteredDistributions.size());
317
        Assert.assertTrue(filteredDistributions.stream().map(d->d.getArea()).collect(toList).contains(jugoslavia));
318
        Assert.assertTrue(filteredDistributions.stream().map(d->d.getArea()).collect(toList).contains(serbia));
319
        Assert.assertTrue(filteredDistributions.stream().map(d->d.getArea()).collect(toList).contains(partOfSerbia));
224 320
    }
225 321

  
322

  
226 323
    @Test
227 324
    public void testFilterDistributions_fallbackArea_shown_1(){
228 325

  

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)