Revision b11aa70a
Added by Andreas Müller over 4 years ago
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/utility/DescriptionUtilityTest.java | ||
---|---|---|
39 | 39 |
@SpringBeanByType |
40 | 40 |
private ITermService termService; |
41 | 41 |
|
42 |
Collection<Distribution> distributions = null; |
|
43 |
Collection<Distribution> filteredDistributions = null; |
|
44 |
boolean subAreaPreference = false; |
|
45 |
boolean statusOrderPreference = false; |
|
46 |
Set<MarkerType> hideMarkedAreas = null; |
|
47 |
MarkerType fallbackAreaMarkerType = null; |
|
48 |
NamedArea berlin = null; |
|
42 |
private Collection<Distribution> distributions = null; |
|
43 |
private Collection<Distribution> filteredDistributions = null; |
|
44 |
private boolean subAreaPreference = false; |
|
45 |
private boolean statusOrderPreference = false; |
|
46 |
private Set<MarkerType> hideMarkedAreas = null; |
|
47 |
private NamedArea berlin = null; |
|
49 | 48 |
|
50 | 49 |
@Before |
51 | 50 |
public void setup(){ |
... | ... | |
79 | 78 |
distributions.add(germanyIntroduced); |
80 | 79 |
|
81 | 80 |
statusOrderPreference= true; |
82 |
filteredDistributions = DescriptionUtility.filterDistributions(distributions, hideMarkedAreas, true, statusOrderPreference, subAreaPreference); |
|
81 |
boolean preferComputed = true; |
|
82 |
filteredDistributions = DescriptionUtility.filterDistributions(distributions, hideMarkedAreas, preferComputed, statusOrderPreference, subAreaPreference); |
|
83 | 83 |
Assert.assertEquals(1, filteredDistributions.size()); |
84 | 84 |
Assert.assertEquals("expecting to see computed status INTRODUCED even it has lower preference than NATIVE", PresenceAbsenceTerm.INTRODUCED(), filteredDistributions.iterator().next().getStatus()); |
85 | 85 |
|
... | ... | |
93 | 93 |
aggParentDescription.addElement(parentComputedDistribution); |
94 | 94 |
distributions.add(parentComputedDistribution); |
95 | 95 |
|
96 |
filteredDistributions = DescriptionUtility.filterDistributions(distributions, hideMarkedAreas, true, statusOrderPreference, subAreaPreference);
|
|
96 |
filteredDistributions = DescriptionUtility.filterDistributions(distributions, hideMarkedAreas, preferComputed, statusOrderPreference, subAreaPreference);
|
|
97 | 97 |
Assert.assertEquals(2, filteredDistributions.size()); |
98 |
|
|
99 | 98 |
} |
100 | 99 |
|
101 | 100 |
@Test |
... | ... | |
119 | 118 |
@Test |
120 | 119 |
public void testFilterDistributions_subAreaPreference(){ |
121 | 120 |
subAreaPreference = true; |
121 |
boolean preferComputed = true; |
|
122 | 122 |
|
123 | 123 |
/* |
124 | 124 |
* Sub area preference rule: If there is an area with a direct sub area |
... | ... | |
132 | 132 |
// no computed data |
133 | 133 |
distributions.add(distGermany); |
134 | 134 |
distributions.add(distBerlin); |
135 |
filteredDistributions = DescriptionUtility.filterDistributions(distributions, hideMarkedAreas, true, statusOrderPreference, subAreaPreference); |
|
135 |
filteredDistributions = DescriptionUtility.filterDistributions(distributions, |
|
136 |
hideMarkedAreas, preferComputed, statusOrderPreference, subAreaPreference); |
|
136 | 137 |
Assert.assertEquals(1, filteredDistributions.size()); |
137 | 138 |
Assert.assertEquals(berlin, filteredDistributions.iterator().next().getArea()); |
138 | 139 |
|
139 | 140 |
// mixed situation |
140 | 141 |
distGermany.addMarker(Marker.NewInstance(MarkerType.COMPUTED(), true)); |
141 |
filteredDistributions = DescriptionUtility.filterDistributions(distributions, hideMarkedAreas, true, statusOrderPreference, subAreaPreference); |
|
142 |
filteredDistributions = DescriptionUtility.filterDistributions(distributions, |
|
143 |
hideMarkedAreas, preferComputed, statusOrderPreference, subAreaPreference); |
|
142 | 144 |
Assert.assertEquals(1, filteredDistributions.size()); |
143 | 145 |
Assert.assertEquals(berlin, filteredDistributions.iterator().next().getArea()); |
144 | 146 |
|
145 | 147 |
// all computed |
146 | 148 |
distBerlin.addMarker(Marker.NewInstance(MarkerType.COMPUTED(), true)); |
147 |
filteredDistributions = DescriptionUtility.filterDistributions(distributions, hideMarkedAreas, true, statusOrderPreference, subAreaPreference); |
|
149 |
filteredDistributions = DescriptionUtility.filterDistributions(distributions, |
|
150 |
hideMarkedAreas, preferComputed, statusOrderPreference, subAreaPreference); |
|
148 | 151 |
Assert.assertEquals(1, filteredDistributions.size()); |
149 | 152 |
Assert.assertEquals(berlin, filteredDistributions.iterator().next().getArea()); |
150 | 153 |
} |
... | ... | |
169 | 172 |
belgium.addMarker(Marker.NewInstance(MarkerType.TO_BE_CHECKED(), true)); |
170 | 173 |
france.addMarker(Marker.NewInstance(MarkerType.IMPORTED(), true)); |
171 | 174 |
|
172 |
hideMarkedAreas = new HashSet<MarkerType>();
|
|
175 |
hideMarkedAreas = new HashSet<>(); |
|
173 | 176 |
hideMarkedAreas.add(MarkerType.TO_BE_CHECKED()); |
174 | 177 |
hideMarkedAreas.add(MarkerType.IMPORTED()); |
175 | 178 |
|
... | ... | |
181 | 184 |
@Test |
182 | 185 |
public void testFilterDistributions_fallbackArea_hidden(){ |
183 | 186 |
|
187 |
boolean preferComputed = true; |
|
188 |
|
|
184 | 189 |
NamedArea jugoslavia = NamedArea.NewInstance("Former Yugoslavia ", "", "Ju"); |
185 | 190 |
jugoslavia.setIdInVocabulary("Ju"); |
186 | 191 |
NamedArea serbia = NamedArea.NewInstance("Serbia", "", "Sr"); |
... | ... | |
196 | 201 |
// using TO_BE_CHECKED to mark Ju as fallback area |
197 | 202 |
jugoslavia.addMarker(Marker.NewInstance(MarkerType.TO_BE_CHECKED(), true)); |
198 | 203 |
|
199 |
hideMarkedAreas = new HashSet<MarkerType>();
|
|
204 |
hideMarkedAreas = new HashSet<>(); |
|
200 | 205 |
hideMarkedAreas.add(MarkerType.TO_BE_CHECKED()); |
201 | 206 |
|
202 | 207 |
filteredDistributions = DescriptionUtility.filterDistributions( |
203 | 208 |
distributions, |
204 | 209 |
hideMarkedAreas, |
205 |
true,
|
|
210 |
preferComputed,
|
|
206 | 211 |
statusOrderPreference, |
207 | 212 |
subAreaPreference); |
208 | 213 |
|
... | ... | |
213 | 218 |
@Test |
214 | 219 |
public void testFilterDistributions_fallbackArea_shown_1(){ |
215 | 220 |
|
221 |
boolean preferComputed = true; |
|
222 |
|
|
216 | 223 |
NamedArea jugoslavia = NamedArea.NewInstance("Former Yugoslavia ", "", "Ju"); |
217 | 224 |
jugoslavia.setIdInVocabulary("Ju"); |
218 | 225 |
NamedArea serbia = NamedArea.NewInstance("Serbia", "", "Sr"); |
... | ... | |
230 | 237 |
// this hides serbia so jugoslavia should be shown |
231 | 238 |
serbia.addMarker(Marker.NewInstance(MarkerType.TO_BE_CHECKED(), true)); |
232 | 239 |
|
233 |
hideMarkedAreas = new HashSet<MarkerType>();
|
|
240 |
hideMarkedAreas = new HashSet<>(); |
|
234 | 241 |
hideMarkedAreas.add(MarkerType.TO_BE_CHECKED()); |
235 | 242 |
|
236 | 243 |
filteredDistributions = DescriptionUtility.filterDistributions( |
237 | 244 |
distributions, |
238 | 245 |
hideMarkedAreas, |
239 |
true,
|
|
246 |
preferComputed,
|
|
240 | 247 |
statusOrderPreference, |
241 | 248 |
subAreaPreference); |
242 | 249 |
|
... | ... | |
260 | 267 |
// using TO_BE_CHECKED to mark Ju as fallback area |
261 | 268 |
jugoslavia.addMarker(Marker.NewInstance(MarkerType.TO_BE_CHECKED(), true)); |
262 | 269 |
|
263 |
hideMarkedAreas = new HashSet<MarkerType>();
|
|
270 |
hideMarkedAreas = new HashSet<>(); |
|
264 | 271 |
hideMarkedAreas.add(MarkerType.TO_BE_CHECKED()); |
265 | 272 |
|
266 | 273 |
filteredDistributions = DescriptionUtility.filterDistributions( |
Also available in: Unified diff
cleanup