2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.persistence
.dao
.hibernate
.description
;
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
;
17 import java
.util
.ArrayList
;
18 import java
.util
.HashSet
;
19 import java
.util
.Iterator
;
20 import java
.util
.List
;
23 import java
.util
.UUID
;
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
;
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
;
56 public class DescriptionDaoHibernateImplTest
extends CdmTransactionalIntegrationTest
{
59 IDescriptionDao descriptionDao
;
62 IDefinedTermDao definedTermDao
;
67 private Set
<NamedArea
> namedAreas
;
68 private Set
<Feature
> features
;
70 private UUID northernAmericaUuid
;
71 private UUID southernAmericaUuid
;
72 private UUID antarcticaUuid
;
76 private UUID taxonSphingidaeUuid
;
78 private static final String
[] TABLE_NAMES
= new String
[] {"DESCRIPTIONBASE", "DESCRIPTIONELEMENTBASE", "DESCRIPTIONELEMENTBASE_LANGUAGESTRING", "HOMOTYPICALGROUP","LANGUAGESTRING"
79 , "ORIGINALSOURCEBASE", "REFERENCE", "TAXONBASE", "TAXONNAMEBASE", "HIBERNATE_SEQUENCES" };
83 uuid
= UUID
.fromString("5f3265ed-68ad-4ec3-826f-0d29d25986b9");
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");
91 features
= new HashSet
<Feature
>();
93 // loadDataSet(getClass().getClassLoader().getResourceAsStream("eu/etaxonomy/cdm/persistence/dao/hibernate/description/DescriptionDaoHibernateImplTest.xml"));
94 // printDataSet(System.err, TABLE_NAMES);
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
);
105 assert northernAmerica
!= null : "term must exist";
106 assert southernAmerica
!= null : "term must exist";
107 assert antarctica
!= null : "term must exist";
109 namedAreas
.add(northernAmerica
);
110 namedAreas
.add(southernAmerica
);
111 namedAreas
.add(antarctica
);
113 int numberOfDescriptions
= descriptionDao
.countDescriptionByDistribution(namedAreas
, null);
114 assertEquals("countDescriptionsByDistribution should return 23",23,numberOfDescriptions
);
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
);
123 assert northernAmerica
!= null : "term must exist";
124 assert southernAmerica
!= null : "term must exist";
125 assert antarctica
!= null : "term must exist";
127 namedAreas
.add(northernAmerica
);
128 namedAreas
.add(southernAmerica
);
129 namedAreas
.add(antarctica
);
131 int numberOfDescriptions
= descriptionDao
.countDescriptionByDistribution(namedAreas
, PresenceTerm
.PRESENT());
132 assertEquals("countDescriptionsByDistribution should return 20",20,numberOfDescriptions
);
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
);
141 assert northernAmerica
!= null : "term must exist";
142 assert southernAmerica
!= null : "term must exist";
143 assert antarctica
!= null : "term must exist";
145 namedAreas
.add(northernAmerica
);
146 namedAreas
.add(southernAmerica
);
147 namedAreas
.add(antarctica
);
149 List
<String
> propertyPaths
= new ArrayList
<String
>();
150 propertyPaths
.add("taxon");
152 List
<OrderHint
> orderHints
= new ArrayList
<OrderHint
>();
153 orderHints
.add(new OrderHint("titleCache",SortOrder
.ASCENDING
));
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());
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
);
170 assert northernAmerica
!= null : "term must exist";
171 assert southernAmerica
!= null : "term must exist";
172 assert antarctica
!= null : "term must exist";
174 namedAreas
.add(northernAmerica
);
175 namedAreas
.add(southernAmerica
);
176 namedAreas
.add(antarctica
);
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());
185 public void testCountDescriptionsWithText() {
186 int numberOfDescriptions
= descriptionDao
.countDescriptions(TaxonDescription
.class, null, true, null);
188 assertNotNull("countDescriptions should return a 2",numberOfDescriptions
);
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
);
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());
205 public void testCountDescriptionsWithTextAndFeatures() {
206 features
.add(Feature
.ECOLOGY());
207 int numberOfDescriptions
= descriptionDao
.countDescriptions(TaxonDescription
.class, null, true, features
);
209 assertNotNull("countDescriptions should return a 1",numberOfDescriptions
);
213 public void testListDescriptionsWithTextAndFeatures() {
214 assert Feature
.ECOLOGY() != null;
215 features
.add(Feature
.ECOLOGY());
217 List
<DescriptionBase
> descriptions
= descriptionDao
.listDescriptions(TaxonDescription
.class, null, true, features
, null, null, null, null);
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());
225 public void testCountDescriptionElements() {
226 DescriptionBase
<?
> description
= descriptionDao
.findByUuid(uuid
);
227 assert description
!= null : "description must exist";
229 int numberOfDescriptionElements
= descriptionDao
.countDescriptionElements(description
, null, TextData
.class);
231 assertEquals("countDescriptionElements should return 2",2,numberOfDescriptionElements
);
235 public void testGetDescriptionElements() {
236 DescriptionBase
<?
> description
= descriptionDao
.findByUuid(uuid
);
237 assert description
!= null : "description must exist";
239 List
<String
> propertyPaths
= new ArrayList
<String
>();
240 propertyPaths
.add("multilanguageText");
241 propertyPaths
.add("media");
242 propertyPaths
.add("feature");
243 propertyPaths
.add("sources.citation");
245 List
<DescriptionElementBase
> elements
= descriptionDao
.getDescriptionElements(description
, null, TextData
.class, null, null,propertyPaths
);
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());
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");
263 elements
= descriptionDao
.getDescriptionElements(description
, null, TextData
.class, null, null, propertyPaths
);
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());
272 if (descElB
.getId() == 34){
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()));
290 public void testCountDescriptionElementsFeature() {
291 features
.add(Feature
.ECOLOGY());
292 DescriptionBase
<?
> description
= descriptionDao
.findByUuid(uuid
);
293 assert description
!= null : "description must exist";
295 int numberOfDescriptionElements
= descriptionDao
.countDescriptionElements(description
, features
, TextData
.class);
297 assertEquals("countDescriptionElements should return 1",1,numberOfDescriptionElements
);
301 public void testGetDescriptionElementsByFeature() {
302 features
.add(Feature
.ECOLOGY());
303 DescriptionBase
<?
> description
= descriptionDao
.findByUuid(uuid
);
304 assert description
!= null : "description must exist";
306 List
<DescriptionElementBase
> elements
= descriptionDao
.getDescriptionElements(description
, features
, TextData
.class, null, null,null);
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());
314 public void testGetDescriptionElementForTaxon() {
316 Taxon taxonSphingidae
= (Taxon
) taxonDao
.load(taxonSphingidaeUuid
);
317 assert taxonSphingidae
!= null : "taxon must exist";
321 List
<DescriptionElementBase
> elements1
= descriptionDao
.getDescriptionElementForTaxon(
322 taxonSphingidae
, null, null, null, 0, null);
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());
330 List
<DescriptionElementBase
> elements2
= descriptionDao
.getDescriptionElementForTaxon(
331 taxonSphingidae
, null, DescriptionElementBase
.class, null, 0, null);
333 assertNotNull("getDescriptionElementForTaxon should return a List", elements2
);
334 assertTrue("getDescriptionElementForTaxon should be empty",elements2
.isEmpty());
338 List
<Distribution
> elements3
= descriptionDao
.getDescriptionElementForTaxon(
339 taxonSphingidae
, null, Distribution
.class, null, 0, null);
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());
348 public void testSaveClonedDescription() {
350 // printDataSet(System.err, new String[]{"TAXONBASE"});
352 Taxon taxon
= Taxon
.NewInstance(null, null);
353 taxon
.setTitleCache("##### created in testSaveClonedDescription()", true);
354 taxonDao
.save(taxon
);
355 commitAndStartNewTransaction(null);
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"});
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
);
377 DefinedTerm scope
= DefinedTerm
.SEX_FEMALE();
378 description
.addScope(scope
);
380 this.descriptionDao
.saveOrUpdate(description
);
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;
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());
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());
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());
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
);
434 @DataSet("DescriptionDaoHibernateImplTest.testListTaxonDescriptionMedia.xml")
435 public void testListTaxonDescriptionMedia(){
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);
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());
450 Set
<MarkerType
> markerTypes
= null;
451 Integer pageSize
= null;
452 Integer pageNumber
= null;
453 List
<String
> propertyPaths
= null;
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());
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());
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());
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());
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());
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());
488 System
.out
.println(mediaList
);
492 @DataSet("DescriptionDaoHibernateImplTest.testListTaxonDescriptionMedia.xml")
493 public void testcountTaxonDescriptionMedia(){
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);
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());
507 Set
<MarkerType
> markerTypes
= null;
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
);
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
);
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
);
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
);
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
);