exchange modifier classes by DefinedTerm, add termtype to csv files, make term loader...
[cdmlib.git] / cdmlib-persistence / src / test / java / eu / etaxonomy / cdm / persistence / dao / hibernate / description / DescriptionDaoHibernateImplTest.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9
10 package eu.etaxonomy.cdm.persistence.dao.hibernate.description;
11
12 import static org.junit.Assert.assertEquals;
13 import static org.junit.Assert.assertFalse;
14 import static org.junit.Assert.assertNotNull;
15 import static org.junit.Assert.assertTrue;
16
17 import java.util.ArrayList;
18 import java.util.HashSet;
19 import java.util.Iterator;
20 import java.util.List;
21 import java.util.Map;
22 import java.util.Set;
23 import java.util.UUID;
24
25 import org.hibernate.Hibernate;
26 import org.junit.Assert;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.unitils.dbunit.annotation.DataSet;
30 import org.unitils.spring.annotation.SpringBeanByType;
31
32 import eu.etaxonomy.cdm.model.common.DefinedTerm;
33 import eu.etaxonomy.cdm.model.common.Language;
34 import eu.etaxonomy.cdm.model.common.LanguageString;
35 import eu.etaxonomy.cdm.model.common.MarkerType;
36 import eu.etaxonomy.cdm.model.description.AbsenceTerm;
37 import eu.etaxonomy.cdm.model.description.DescriptionBase;
38 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
39 import eu.etaxonomy.cdm.model.description.Distribution;
40 import eu.etaxonomy.cdm.model.description.Feature;
41 import eu.etaxonomy.cdm.model.description.IModifiable;
42 import eu.etaxonomy.cdm.model.description.PresenceTerm;
43 import eu.etaxonomy.cdm.model.description.TaxonDescription;
44 import eu.etaxonomy.cdm.model.description.TextData;
45 import eu.etaxonomy.cdm.model.location.NamedArea;
46 import eu.etaxonomy.cdm.model.media.Media;
47 import eu.etaxonomy.cdm.model.taxon.Taxon;
48 import eu.etaxonomy.cdm.persistence.dao.common.IDefinedTermDao;
49 import eu.etaxonomy.cdm.persistence.dao.description.IDescriptionDao;
50 import eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonDao;
51 import eu.etaxonomy.cdm.persistence.query.OrderHint;
52 import eu.etaxonomy.cdm.persistence.query.OrderHint.SortOrder;
53 import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
54
55 @DataSet
56 public class DescriptionDaoHibernateImplTest extends CdmTransactionalIntegrationTest {
57
58 @SpringBeanByType
59 IDescriptionDao descriptionDao;
60
61 @SpringBeanByType
62 IDefinedTermDao definedTermDao;
63
64 @SpringBeanByType
65 ITaxonDao taxonDao;
66
67 private Set<NamedArea> namedAreas;
68 private Set<Feature> features;
69
70 private UUID northernAmericaUuid;
71 private UUID southernAmericaUuid;
72 private UUID antarcticaUuid;
73
74 private UUID uuid;
75
76 private UUID taxonSphingidaeUuid;
77
78 private static final String[] TABLE_NAMES = new String[] {"DESCRIPTIONBASE", "DESCRIPTIONELEMENTBASE", "DESCRIPTIONELEMENTBASE_LANGUAGESTRING", "HOMOTYPICALGROUP","LANGUAGESTRING"
79 , "ORIGINALSOURCEBASE", "REFERENCE", "TAXONBASE", "TAXONNAMEBASE", "HIBERNATE_SEQUENCES" };
80
81 @Before
82 public void setUp() {
83 uuid = UUID.fromString("5f3265ed-68ad-4ec3-826f-0d29d25986b9");
84
85 namedAreas = new HashSet<NamedArea>();
86 northernAmericaUuid = UUID.fromString("2757e726-d897-4546-93bd-7951d203bf6f");
87 southernAmericaUuid = UUID.fromString("6310b3ba-96f4-4855-bb5b-326e7af188ea");
88 antarcticaUuid = UUID.fromString("791b3aa0-54dd-4bed-9b68-56b4680aad0c");
89 taxonSphingidaeUuid = UUID.fromString("54e767ee-894e-4540-a758-f906ecb4e2d9");
90
91 features = new HashSet<Feature>();
92
93 // loadDataSet(getClass().getClassLoader().getResourceAsStream("eu/etaxonomy/cdm/persistence/dao/hibernate/description/DescriptionDaoHibernateImplTest.xml"));
94 // printDataSet(System.err, TABLE_NAMES);
95 }
96
97
98 @Test
99 public void testCountByDistribution() {
100 // printDataSet(System.err, TABLE_NAMES);
101 NamedArea northernAmerica = (NamedArea)definedTermDao.findByUuid(northernAmericaUuid);
102 NamedArea southernAmerica = (NamedArea)definedTermDao.findByUuid(southernAmericaUuid);
103 NamedArea antarctica = (NamedArea)definedTermDao.findByUuid(antarcticaUuid);
104
105 assert northernAmerica != null : "term must exist";
106 assert southernAmerica != null : "term must exist";
107 assert antarctica != null : "term must exist";
108
109 namedAreas.add(northernAmerica);
110 namedAreas.add(southernAmerica);
111 namedAreas.add(antarctica);
112
113 int numberOfDescriptions = descriptionDao.countDescriptionByDistribution(namedAreas, null);
114 assertEquals("countDescriptionsByDistribution should return 23",23,numberOfDescriptions);
115 }
116
117 @Test
118 public void testCountByDistributionWithStatus() {
119 NamedArea northernAmerica = (NamedArea)definedTermDao.findByUuid(northernAmericaUuid);
120 NamedArea southernAmerica = (NamedArea)definedTermDao.findByUuid(southernAmericaUuid);
121 NamedArea antarctica = (NamedArea)definedTermDao.findByUuid(antarcticaUuid);
122
123 assert northernAmerica != null : "term must exist";
124 assert southernAmerica != null : "term must exist";
125 assert antarctica != null : "term must exist";
126
127 namedAreas.add(northernAmerica);
128 namedAreas.add(southernAmerica);
129 namedAreas.add(antarctica);
130
131 int numberOfDescriptions = descriptionDao.countDescriptionByDistribution(namedAreas, PresenceTerm.PRESENT());
132 assertEquals("countDescriptionsByDistribution should return 20",20,numberOfDescriptions);
133 }
134
135 @Test
136 public void testGetByDistribution() {
137 NamedArea northernAmerica = (NamedArea)definedTermDao.findByUuid(northernAmericaUuid);
138 NamedArea southernAmerica = (NamedArea)definedTermDao.findByUuid(southernAmericaUuid);
139 NamedArea antarctica = (NamedArea)definedTermDao.findByUuid(antarcticaUuid);
140
141 assert northernAmerica != null : "term must exist";
142 assert southernAmerica != null : "term must exist";
143 assert antarctica != null : "term must exist";
144
145 namedAreas.add(northernAmerica);
146 namedAreas.add(southernAmerica);
147 namedAreas.add(antarctica);
148
149 List<String> propertyPaths = new ArrayList<String>();
150 propertyPaths.add("taxon");
151
152 List<OrderHint> orderHints = new ArrayList<OrderHint>();
153 orderHints.add(new OrderHint("titleCache",SortOrder.ASCENDING));
154
155 List<TaxonDescription> descriptions = descriptionDao.searchDescriptionByDistribution(namedAreas, null, 10,2,orderHints,propertyPaths);
156 assertNotNull("searchDescriptionByDistribution should return a List",descriptions);
157 assertFalse("searchDescriptionsByDistribution should not be empty",descriptions.isEmpty());
158 assertEquals("searchDescriptionsByDistribution should return 3 elements",3,descriptions.size());
159 assertTrue("TaxonDescription.taxon should be initialized",Hibernate.isInitialized(descriptions.get(0).getTaxon()));
160 assertEquals("Sphingidae Linnaeus, 1758 sec. cate-sphingidae.org should come first","Sphingidae Linnaeus, 1758 sec. cate-sphingidae.org",descriptions.get(0).getTitleCache());
161 assertEquals("Sphinx Linnaeus, 1758 sec. cate-sphingidae.org should come last","Sphinx Linnaeus, 1758 sec. cate-sphingidae.org",descriptions.get(2).getTitleCache());
162 }
163
164 @Test
165 public void testGetByDistributionWithStatus() {
166 NamedArea northernAmerica = (NamedArea)definedTermDao.findByUuid(northernAmericaUuid);
167 NamedArea southernAmerica = (NamedArea)definedTermDao.findByUuid(southernAmericaUuid);
168 NamedArea antarctica = (NamedArea)definedTermDao.findByUuid(antarcticaUuid);
169
170 assert northernAmerica != null : "term must exist";
171 assert southernAmerica != null : "term must exist";
172 assert antarctica != null : "term must exist";
173
174 namedAreas.add(northernAmerica);
175 namedAreas.add(southernAmerica);
176 namedAreas.add(antarctica);
177
178 List<TaxonDescription> descriptions = descriptionDao.searchDescriptionByDistribution(namedAreas, AbsenceTerm.ABSENT(), 10,0,null,null);
179 assertNotNull("searchDescriptionByDistribution should return a List",descriptions);
180 assertFalse("searchDescriptionsByDistribution should not be empty",descriptions.isEmpty());
181 assertEquals("searchDescriptionsByDistribution should return 3 elements",3,descriptions.size());
182 }
183
184 @Test
185 public void testCountDescriptionsWithText() {
186 int numberOfDescriptions = descriptionDao.countDescriptions(TaxonDescription.class, null, true, null);
187
188 assertNotNull("countDescriptions should return a 2",numberOfDescriptions);
189 }
190
191 @Test
192 public void testListDescriptionsWithText() {
193 List<OrderHint> orderHints = new ArrayList<OrderHint>();
194 orderHints.add(new OrderHint("titleCache",SortOrder.ASCENDING));
195 List<String> propertyPaths = new ArrayList<String>();
196 propertyPaths.add("taxon");
197 List<DescriptionBase> descriptions = descriptionDao.listDescriptions(TaxonDescription.class, null, true, null,null,null,orderHints,propertyPaths);
198
199 assertNotNull("listDescriptions should return a List",descriptions);
200 assertFalse("listDescriptions should not be empty", descriptions.isEmpty());
201 assertEquals("listDescriptions should return 2 descriptions",2,descriptions.size());
202 }
203
204 @Test
205 public void testCountDescriptionsWithTextAndFeatures() {
206 features.add(Feature.ECOLOGY());
207 int numberOfDescriptions = descriptionDao.countDescriptions(TaxonDescription.class, null, true, features);
208
209 assertNotNull("countDescriptions should return a 1",numberOfDescriptions);
210 }
211
212 @Test
213 public void testListDescriptionsWithTextAndFeatures() {
214 assert Feature.ECOLOGY() != null;
215 features.add(Feature.ECOLOGY());
216
217 List<DescriptionBase> descriptions = descriptionDao.listDescriptions(TaxonDescription.class, null, true, features, null, null, null, null);
218
219 assertNotNull("listDescriptions should return a List",descriptions);
220 assertFalse("listDescriptions should not be empty", descriptions.isEmpty());
221 assertEquals("listDescriptions should return 1 descriptions",1,descriptions.size());
222 }
223
224 @Test
225 public void testCountDescriptionElements() {
226 DescriptionBase<?> description = descriptionDao.findByUuid(uuid);
227 assert description != null : "description must exist";
228
229 int numberOfDescriptionElements = descriptionDao.countDescriptionElements(description, null, TextData.class);
230
231 assertEquals("countDescriptionElements should return 2",2,numberOfDescriptionElements);
232 }
233
234 @Test
235 public void testGetDescriptionElements() {
236 DescriptionBase<?> description = descriptionDao.findByUuid(uuid);
237 assert description != null : "description must exist";
238
239 List<String> propertyPaths = new ArrayList<String>();
240 propertyPaths.add("multilanguageText");
241 propertyPaths.add("media");
242 propertyPaths.add("feature");
243 propertyPaths.add("sources.citation");
244
245 List<DescriptionElementBase> elements = descriptionDao.getDescriptionElements(description, null, TextData.class, null, null,propertyPaths);
246
247 for (DescriptionElementBase descElB: elements){
248 if (descElB instanceof TextData){
249 Map<Language, LanguageString> multiLanguage = ((TextData)descElB).getMultilanguageText();
250 LanguageString defaultString = multiLanguage.get(Language.DEFAULT());
251
252 }
253 }
254 Iterator<DescriptionElementBase> elements2 = description.getElements().iterator();
255 while(elements2.hasNext()){
256 DescriptionElementBase element = elements2.next();
257 if (element instanceof TextData){
258 Map<Language, LanguageString> multiLanguage = ((TextData)element).getMultilanguageText();
259 LanguageString defaultString = multiLanguage.get(Language.DEFAULT());
260 defaultString.setText("blablub");
261 }
262 }
263 elements = descriptionDao.getDescriptionElements(description, null, TextData.class, null, null, propertyPaths);
264
265 DescriptionElementBase element34 = null;
266 for (DescriptionElementBase descElB: elements){
267 if (descElB instanceof TextData){
268 Map<Language, LanguageString> multiLanguage = ((TextData)descElB).getMultilanguageText();
269 LanguageString defaultString = multiLanguage.get(Language.DEFAULT());
270 //???
271 }
272 if (descElB.getId() == 34){
273 element34 = descElB;
274 }
275 }
276
277 assertNotNull("getDescriptionElements should return a List", elements);
278 assertFalse("getDescriptionElements should not be empty",elements.isEmpty());
279 assertEquals("getDescriptionElement should return 2 elements",2,elements.size());
280 assertNotNull("Description Element with ID 34 should be part of the list",element34);
281 assertTrue("DescriptionElement.sources should be initialized",Hibernate.isInitialized(element34.getSources()));
282 assertTrue("DescriptionElement.sources should have elements",element34.getSources().size() > 0);
283 assertTrue("ReferencedEntityBase.citation should be initialized",Hibernate.isInitialized(element34.getSources().iterator().next().getCitation()));
284 assertTrue("DescriptionElementBase.feature should be initialized",Hibernate.isInitialized(element34.getFeature()));
285 assertTrue("DescriptionElementBase.media should be initialized",Hibernate.isInitialized(element34.getMedia()));
286 assertTrue("TextData.multilanguageText should be initialized",Hibernate.isInitialized(((TextData)element34).getMultilanguageText()));
287 }
288
289 @Test
290 public void testCountDescriptionElementsFeature() {
291 features.add(Feature.ECOLOGY());
292 DescriptionBase<?> description = descriptionDao.findByUuid(uuid);
293 assert description != null : "description must exist";
294
295 int numberOfDescriptionElements = descriptionDao.countDescriptionElements(description, features, TextData.class);
296
297 assertEquals("countDescriptionElements should return 1",1,numberOfDescriptionElements);
298 }
299
300 @Test
301 public void testGetDescriptionElementsByFeature() {
302 features.add(Feature.ECOLOGY());
303 DescriptionBase<?> description = descriptionDao.findByUuid(uuid);
304 assert description != null : "description must exist";
305
306 List<DescriptionElementBase> elements = descriptionDao.getDescriptionElements(description, features, TextData.class, null, null,null);
307
308 assertNotNull("getDescriptionElements should return a List");
309 assertFalse("getDescriptionElements should not be empty",elements.isEmpty());
310 assertEquals("getDescriptionElement should return 1 elements",1,elements.size());
311 }
312
313 @Test
314 public void testGetDescriptionElementForTaxon() {
315
316 Taxon taxonSphingidae = (Taxon) taxonDao.load(taxonSphingidaeUuid);
317 assert taxonSphingidae != null : "taxon must exist";
318
319 // 1.
320
321 List<DescriptionElementBase> elements1 = descriptionDao.getDescriptionElementForTaxon(
322 taxonSphingidae , null, null, null, 0, null);
323
324 assertNotNull("getDescriptionElementForTaxon should return a List", elements1);
325 assertFalse("getDescriptionElementForTaxon should not be empty",elements1.isEmpty());
326 assertEquals("getDescriptionElementForTaxon should return 1 elements",1,elements1.size());
327
328 // 2.
329
330 List<DescriptionElementBase> elements2 = descriptionDao.getDescriptionElementForTaxon(
331 taxonSphingidae , null, DescriptionElementBase.class, null, 0, null);
332
333 assertNotNull("getDescriptionElementForTaxon should return a List", elements2);
334 assertTrue("getDescriptionElementForTaxon should be empty",elements2.isEmpty());
335
336 // 3.
337
338 List<Distribution> elements3 = descriptionDao.getDescriptionElementForTaxon(
339 taxonSphingidae , null, Distribution.class, null, 0, null);
340
341 assertNotNull("getDescriptionElementForTaxon should return a List", elements3);
342 assertFalse("getDescriptionElementForTaxon should not be empty",elements3.isEmpty());
343 assertEquals("getDescriptionElementForTaxon should return 1 elements",1,elements3.size());
344 }
345
346 //see #2234
347 @Test
348 public void testSaveClonedDescription() {
349
350 // printDataSet(System.err, new String[]{"TAXONBASE"});
351
352 Taxon taxon = Taxon.NewInstance(null, null);
353 taxon.setTitleCache("##### created in testSaveClonedDescription()", true);
354 taxonDao.save(taxon);
355 commitAndStartNewTransaction(null);
356
357 TaxonDescription description = TaxonDescription.NewInstance(taxon);
358 this.descriptionDao.saveOrUpdate(description);
359 // TaxonDescription clonedDescription = (TaxonDescription)description.clone();
360 // this.descriptionDao.saveOrUpdate(clonedDescription);
361 // printDataSet(System.err, new String[]{"TAXONBASE"});
362
363 assertTrue(true);
364
365 }
366
367 //see #2592
368 @Test
369 public void testSaveScope(){
370 int n1 = this.descriptionDao.count();
371 Taxon taxon = Taxon.NewInstance(null, null);
372 TaxonDescription description = TaxonDescription.NewInstance(taxon);
373 this.taxonDao.save(taxon);
374 int n2 = this.descriptionDao.count();
375 Assert.assertEquals(1, n2-n1);
376
377 DefinedTerm scope = DefinedTerm.SEX_FEMALE();
378 description.addScope(scope);
379
380 this.descriptionDao.saveOrUpdate(description);
381
382 }
383
384 @Test
385 public void testListTaxonDescriptionWithMarker(){
386 Taxon taxon = (Taxon)this.taxonDao.findByUuid(UUID.fromString("b04cc9cb-2b4a-4cc4-a94a-3c93a2158b06"));
387 Set<DefinedTerm> scopes = null;
388 Set<NamedArea> geographicalScope = null;
389 Integer pageSize = null;
390 Integer pageNumber = null;
391 List<String> propertyPaths = null;
392
393 //complete
394 MarkerType completeMarkerType = (MarkerType)this.definedTermDao.findByUuid(UUID.fromString("b4b1b2ab-89a8-4ce6-8110-d60b8b1bc433")); //Marker "complete"
395 Assert.assertNotNull("MarkerType for 'complete' should exist", completeMarkerType);
396 Set<MarkerType> markerTypes = new HashSet<MarkerType>();
397 markerTypes.add(completeMarkerType);
398 int n1 = this.descriptionDao.countTaxonDescriptions(taxon, scopes, geographicalScope, markerTypes);
399 Assert.assertEquals("There should be 1 description marked 'complete'", 1, n1);
400 List<TaxonDescription> descriptions = this.descriptionDao.listTaxonDescriptions(taxon, scopes, geographicalScope, markerTypes, pageSize, pageNumber, propertyPaths);
401 Assert.assertEquals("There should be 1 description marked 'complete'", 1, descriptions.size());
402
403 //doubtful
404 MarkerType isDoubtfulMarkerType = (MarkerType)this.definedTermDao.findByUuid(UUID.fromString("b51325c8-05fe-421a-832b-d86fc249ef6e")); //Marker "doubtful"
405 Assert.assertNotNull("MarkerType for 'doubtful' should exist", isDoubtfulMarkerType);
406 markerTypes = new HashSet<MarkerType>(); //reset
407 markerTypes.add(isDoubtfulMarkerType);
408 int n2 = this.descriptionDao.countTaxonDescriptions(taxon, scopes, geographicalScope, markerTypes);
409 Assert.assertEquals("There should be no description marked 'doubtful'", 0, n2);
410 descriptions = this.descriptionDao.listTaxonDescriptions(taxon, scopes, geographicalScope, markerTypes, pageSize, pageNumber, propertyPaths);
411 Assert.assertEquals("There should be 0 description marked 'doubtful'", 0, descriptions.size());
412
413 //imported = false
414 UUID uuidImported = UUID.fromString("96878790-4ceb-42a2-9738-a2242079b679");
415 MarkerType importedMarkerType = (MarkerType)this.definedTermDao.findByUuid(uuidImported);
416 Assert.assertNotNull("MarkerType for 'imported' should exist", completeMarkerType);
417 markerTypes = new HashSet<MarkerType>();
418 markerTypes.add(importedMarkerType);
419 int n3 = this.descriptionDao.countTaxonDescriptions(taxon, scopes, geographicalScope, markerTypes);
420 Assert.assertEquals("There should be no description marked 'imported' as true", 0, n3);
421 descriptions = this.descriptionDao.listTaxonDescriptions(taxon, scopes, geographicalScope, markerTypes, pageSize, pageNumber, propertyPaths);
422 Assert.assertEquals("There should be no description marked 'imported' as true", 0, descriptions.size());
423 markerTypes = null;
424 descriptions = this.descriptionDao.listTaxonDescriptions(taxon, scopes, geographicalScope, markerTypes, pageSize, pageNumber, propertyPaths);
425 Assert.assertEquals("There should be 1 description", 1, descriptions.size());
426 TaxonDescription desc = descriptions.iterator().next();
427 boolean hasMarkerImportedAsFalse = desc.hasMarker(importedMarkerType, false);
428 Assert.assertTrue("The only description should have a negative marker on 'imported'", hasMarkerImportedAsFalse);
429
430 }
431
432
433 @Test
434 @DataSet("DescriptionDaoHibernateImplTest.testListTaxonDescriptionMedia.xml")
435 public void testListTaxonDescriptionMedia(){
436 //init
437 Taxon firstTaxon = (Taxon)this.taxonDao.findByUuid(UUID.fromString("496b1325-be50-4b0a-9aa2-3ecd610215f2"));
438 Taxon secondTaxon = (Taxon)this.taxonDao.findByUuid(UUID.fromString("822d98dc-9ef7-44b7-a870-94573a3bcb46"));
439 Taxon thirdTaxon = (Taxon)this.taxonDao.findByUuid(UUID.fromString("54e767ee-894e-4540-a758-f906ecb4e2d9"));
440 MarkerType markerType890 = (MarkerType)this.definedTermDao.findById(890);
441 MarkerType markerType892 = (MarkerType)this.definedTermDao.findById(892);
442
443 Assert.assertNotNull("First taxon should exist", firstTaxon);
444 Assert.assertNotNull("Second taxon should exist", secondTaxon);
445 Assert.assertNotNull("Third taxon should exist", thirdTaxon);
446 Assert.assertEquals("There should be 6 descriptions in the database", 6, this.descriptionDao.count());
447
448
449 //set parameter
450 Set<MarkerType> markerTypes = null;
451 Integer pageSize = null;
452 Integer pageNumber = null;
453 List<String> propertyPaths = null;
454
455 //test
456 //first Taxon gallery filter
457 List<Media> mediaList = this.descriptionDao.listTaxonDescriptionMedia(firstTaxon.getUuid(), true, markerTypes, pageSize, pageNumber, propertyPaths);
458 Assert.assertEquals("media list size for first taxon and filter on image galleries should be 1", 1, mediaList.size());
459
460 //first taxon all descriptions
461 mediaList = this.descriptionDao.listTaxonDescriptionMedia(firstTaxon.getUuid(), false, markerTypes, pageSize, pageNumber, propertyPaths);
462 Assert.assertEquals("media list size for first taxon without filter on image galleries should be 2", 2, mediaList.size());
463
464 //second taxon
465 mediaList = this.descriptionDao.listTaxonDescriptionMedia(secondTaxon.getUuid(), true, markerTypes, pageSize, pageNumber, propertyPaths);
466 Assert.assertEquals("media list size for second taxon and filter on image galleries should be 2", 2, mediaList.size());
467
468 //all taxa
469 mediaList = this.descriptionDao.listTaxonDescriptionMedia(null, true, markerTypes, pageSize, pageNumber, propertyPaths);
470 Assert.assertEquals("media list size for any taxon and filter on image galleries should be 3", 3, mediaList.size());
471 //with marker
472 markerTypes = new HashSet<MarkerType>();
473 mediaList = this.descriptionDao.listTaxonDescriptionMedia(null, true, markerTypes, pageSize, pageNumber, propertyPaths);
474 Assert.assertEquals("Empty marker type set should give same result as before: 3", 3, mediaList.size());
475 markerTypes.add(markerType890);
476 mediaList = this.descriptionDao.listTaxonDescriptionMedia(null, true, markerTypes, pageSize, pageNumber, propertyPaths);
477 Assert.assertEquals("markerType890 should only give 1 result", 1, mediaList.size());
478 markerTypes.add(markerType892);
479 mediaList = this.descriptionDao.listTaxonDescriptionMedia(null, true, markerTypes, pageSize, pageNumber, propertyPaths);
480 Assert.assertEquals("markerType892 should not give additional result as the markers value is false", 1, mediaList.size());
481 markerTypes = null;
482
483 //check deduplication
484 mediaList = this.descriptionDao.listTaxonDescriptionMedia(null, false, markerTypes, pageSize, pageNumber, propertyPaths);
485 Assert.assertEquals("media list size for any taxon without filter on image galleries should be 3", 3, mediaList.size());
486
487
488 System.out.println(mediaList);
489 }
490
491 @Test
492 @DataSet("DescriptionDaoHibernateImplTest.testListTaxonDescriptionMedia.xml")
493 public void testcountTaxonDescriptionMedia(){
494 //init
495 Taxon firstTaxon = (Taxon)this.taxonDao.findByUuid(UUID.fromString("496b1325-be50-4b0a-9aa2-3ecd610215f2"));
496 Taxon secondTaxon = (Taxon)this.taxonDao.findByUuid(UUID.fromString("822d98dc-9ef7-44b7-a870-94573a3bcb46"));
497 Taxon thirdTaxon = (Taxon)this.taxonDao.findByUuid(UUID.fromString("54e767ee-894e-4540-a758-f906ecb4e2d9"));
498 MarkerType markerType890 = (MarkerType)this.definedTermDao.findById(890);
499 MarkerType markerType892 = (MarkerType)this.definedTermDao.findById(892);
500
501 Assert.assertNotNull("First taxon should exist", firstTaxon);
502 Assert.assertNotNull("Second taxon should exist", secondTaxon);
503 Assert.assertNotNull("Third taxon should exist", thirdTaxon);
504 Assert.assertEquals("There should be 6 descriptions in the database", 6, this.descriptionDao.count());
505
506 //set parameter
507 Set<MarkerType> markerTypes = null;
508
509 //test
510 //first Taxon gallery filter
511 int mediaCount = this.descriptionDao.countTaxonDescriptionMedia(firstTaxon.getUuid(), true, markerTypes);
512 Assert.assertEquals("media list size for first taxon and filter on image galleries should be 1", 1, mediaCount);
513 mediaCount = this.descriptionDao.countTaxonDescriptionMedia(firstTaxon.getUuid(), false, markerTypes);
514 Assert.assertEquals("media list size for first taxon without filter on image galleries should be 2", 2, mediaCount);
515
516 //second taxon
517 mediaCount = this.descriptionDao.countTaxonDescriptionMedia(secondTaxon.getUuid(), true, markerTypes);
518 Assert.assertEquals("media list size for second taxon and filter on image galleries should be 2", 2, mediaCount);
519
520 //all taxa
521 mediaCount = this.descriptionDao.countTaxonDescriptionMedia(null, true, markerTypes);
522 Assert.assertEquals("media list size for any taxon and filter on image galleries should be 3", 3, mediaCount);
523 //with marker
524 markerTypes = new HashSet<MarkerType>();
525 mediaCount = this.descriptionDao.countTaxonDescriptionMedia(null, true, markerTypes);
526 Assert.assertEquals("Empty marker type set should give same result as before: 3", 3, mediaCount);
527 markerTypes.add(markerType890);
528 mediaCount = this.descriptionDao.countTaxonDescriptionMedia(null, true, markerTypes);
529 Assert.assertEquals("markerType890 should only give 1 result", 1, mediaCount);
530 markerTypes.add(markerType892);
531 mediaCount = this.descriptionDao.countTaxonDescriptionMedia(null, true, markerTypes);
532 Assert.assertEquals("markerType892 should not give additional result as the markers value is false", 1, mediaCount);
533 markerTypes = null;
534
535 //check deduplication
536 mediaCount = this.descriptionDao.countTaxonDescriptionMedia(null, false, markerTypes);
537 Assert.assertEquals("media list size for any taxon without filter on image galleries should be 3", 3, mediaCount);
538
539 }
540
541
542 }