Project

General

Profile

Download (33.7 KB) Statistics
| Branch: | Tag: | Revision:
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.io.FileNotFoundException;
18
import java.util.ArrayList;
19
import java.util.Collection;
20
import java.util.HashSet;
21
import java.util.Iterator;
22
import java.util.List;
23
import java.util.Map;
24
import java.util.Set;
25
import java.util.UUID;
26

    
27
import org.hibernate.Hibernate;
28
import org.junit.Assert;
29
import org.junit.Before;
30
import org.junit.Test;
31
import org.unitils.dbunit.annotation.DataSet;
32
import org.unitils.spring.annotation.SpringBeanByType;
33

    
34
import eu.etaxonomy.cdm.model.common.DefinedTerm;
35
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
36
import eu.etaxonomy.cdm.model.common.Language;
37
import eu.etaxonomy.cdm.model.common.LanguageString;
38
import eu.etaxonomy.cdm.model.common.MarkerType;
39
import eu.etaxonomy.cdm.model.common.Representation;
40
import eu.etaxonomy.cdm.model.description.DescriptionBase;
41
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
42
import eu.etaxonomy.cdm.model.description.Distribution;
43
import eu.etaxonomy.cdm.model.description.Feature;
44
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
45
import eu.etaxonomy.cdm.model.description.SpecimenDescription;
46
import eu.etaxonomy.cdm.model.description.TaxonDescription;
47
import eu.etaxonomy.cdm.model.description.TextData;
48
import eu.etaxonomy.cdm.model.location.NamedArea;
49
import eu.etaxonomy.cdm.model.media.Media;
50
import eu.etaxonomy.cdm.model.taxon.Taxon;
51
import eu.etaxonomy.cdm.persistence.dao.common.IDefinedTermDao;
52
import eu.etaxonomy.cdm.persistence.dao.description.IDescriptionDao;
53
import eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonDao;
54
import eu.etaxonomy.cdm.persistence.dto.TermDto;
55
import eu.etaxonomy.cdm.persistence.query.OrderHint;
56
import eu.etaxonomy.cdm.persistence.query.OrderHint.SortOrder;
57
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
58

    
59
@DataSet
60
public class DescriptionDaoHibernateImplTest extends CdmTransactionalIntegrationTest {
61

    
62
    @SpringBeanByType
63
    IDescriptionDao descriptionDao;
64

    
65
    @SpringBeanByType
66
    IDefinedTermDao definedTermDao;
67

    
68
    @SpringBeanByType
69
    ITaxonDao taxonDao;
70

    
71
    private Set<NamedArea> namedAreas;
72
    private Set<Feature> features;
73

    
74
    private UUID northernAmericaUuid;
75
    private UUID southernAmericaUuid;
76
    private UUID antarcticaUuid;
77

    
78
    private UUID uuid;
79

    
80
    private UUID taxonSphingidaeUuid;
81

    
82
    private static final String[] TABLE_NAMES = new String[] {"DESCRIPTIONBASE", "DESCRIPTIONELEMENTBASE", "DESCRIPTIONELEMENTBASE_LANGUAGESTRING", "HOMOTYPICALGROUP","LANGUAGESTRING"
83
            , "ORIGINALSOURCEBASE", "REFERENCE", "TAXONBASE", "TAXONNAMEBASE", "HIBERNATE_SEQUENCES" };
84

    
85
    @Before
86
    public void setUp() {
87
        uuid = UUID.fromString("5f3265ed-68ad-4ec3-826f-0d29d25986b9");
88

    
89
        namedAreas = new HashSet<NamedArea>();
90
        northernAmericaUuid = UUID.fromString("2757e726-d897-4546-93bd-7951d203bf6f");
91
        southernAmericaUuid = UUID.fromString("6310b3ba-96f4-4855-bb5b-326e7af188ea");
92
        antarcticaUuid = UUID.fromString("791b3aa0-54dd-4bed-9b68-56b4680aad0c");
93
        taxonSphingidaeUuid = UUID.fromString("54e767ee-894e-4540-a758-f906ecb4e2d9");
94

    
95
        features = new HashSet<Feature>();
96

    
97
//		loadDataSet(getClass().getClassLoader().getResourceAsStream("eu/etaxonomy/cdm/persistence/dao/hibernate/description/DescriptionDaoHibernateImplTest.xml"));
98
//		printDataSet(System.err, TABLE_NAMES);
99
    }
100

    
101

    
102
    @Test
103
    public void testCountByDistribution() {
104
//		printDataSet(System.err, TABLE_NAMES);
105
        NamedArea northernAmerica = (NamedArea)definedTermDao.findByUuid(northernAmericaUuid);
106
        NamedArea southernAmerica = (NamedArea)definedTermDao.findByUuid(southernAmericaUuid);
107
        NamedArea antarctica = (NamedArea)definedTermDao.findByUuid(antarcticaUuid);
108

    
109
        assert northernAmerica != null : "term must exist";
110
        assert southernAmerica != null : "term must exist";
111
        assert antarctica != null : "term must exist";
112

    
113
        namedAreas.add(northernAmerica);
114
        namedAreas.add(southernAmerica);
115
        namedAreas.add(antarctica);
116

    
117
        int numberOfDescriptions = descriptionDao.countDescriptionByDistribution(namedAreas, null);
118
        assertEquals("countDescriptionsByDistribution should return 23",23,numberOfDescriptions);
119
    }
120

    
121
    @Test
122
    public void testCountByDistributionWithStatus() {
123
        NamedArea northernAmerica = (NamedArea)definedTermDao.findByUuid(northernAmericaUuid);
124
        NamedArea southernAmerica = (NamedArea)definedTermDao.findByUuid(southernAmericaUuid);
125
        NamedArea antarctica = (NamedArea)definedTermDao.findByUuid(antarcticaUuid);
126

    
127
        assert northernAmerica != null : "term must exist";
128
        assert southernAmerica != null : "term must exist";
129
        assert antarctica != null : "term must exist";
130

    
131
        namedAreas.add(northernAmerica);
132
        namedAreas.add(southernAmerica);
133
        namedAreas.add(antarctica);
134

    
135
        int numberOfDescriptions = descriptionDao.countDescriptionByDistribution(namedAreas, PresenceAbsenceTerm.PRESENT());
136
        assertEquals("countDescriptionsByDistribution should return 20",20,numberOfDescriptions);
137
    }
138

    
139
    @Test
140
    public void testGetByDistribution() {
141
        NamedArea northernAmerica = (NamedArea)definedTermDao.findByUuid(northernAmericaUuid);
142
        NamedArea southernAmerica = (NamedArea)definedTermDao.findByUuid(southernAmericaUuid);
143
        NamedArea antarctica = (NamedArea)definedTermDao.findByUuid(antarcticaUuid);
144

    
145
        assert northernAmerica != null : "term must exist";
146
        assert southernAmerica != null : "term must exist";
147
        assert antarctica != null : "term must exist";
148

    
149
        namedAreas.add(northernAmerica);
150
        namedAreas.add(southernAmerica);
151
        namedAreas.add(antarctica);
152

    
153
        List<String> propertyPaths = new ArrayList<String>();
154
        propertyPaths.add("taxon");
155

    
156
        List<OrderHint> orderHints = new ArrayList<OrderHint>();
157
        orderHints.add(new OrderHint("titleCache",SortOrder.ASCENDING));
158

    
159
        List<TaxonDescription> descriptions = descriptionDao.searchDescriptionByDistribution(namedAreas, null, 10,2,orderHints,propertyPaths);
160
        assertNotNull("searchDescriptionByDistribution should return a List",descriptions);
161
        assertFalse("searchDescriptionsByDistribution should not be empty",descriptions.isEmpty());
162
        assertEquals("searchDescriptionsByDistribution should return 3 elements",3,descriptions.size());
163
        assertTrue("TaxonDescription.taxon should be initialized",Hibernate.isInitialized(descriptions.get(0).getTaxon()));
164
        assertEquals("Sphingidae Linnaeus, 1758 sec. cate-sphingidae.org should come first","Sphingidae Linnaeus, 1758 sec. cate-sphingidae.org",descriptions.get(0).getTitleCache());
165
        assertEquals("Sphinx Linnaeus, 1758 sec. cate-sphingidae.org should come last","Sphinx Linnaeus, 1758 sec. cate-sphingidae.org",descriptions.get(2).getTitleCache());
166
    }
167

    
168
    @Test
169
    public void testGetByDistributionWithStatus() {
170
        NamedArea northernAmerica = (NamedArea)definedTermDao.findByUuid(northernAmericaUuid);
171
        NamedArea southernAmerica = (NamedArea)definedTermDao.findByUuid(southernAmericaUuid);
172
        NamedArea antarctica = (NamedArea)definedTermDao.findByUuid(antarcticaUuid);
173

    
174
        assert northernAmerica != null : "term must exist";
175
        assert southernAmerica != null : "term must exist";
176
        assert antarctica != null : "term must exist";
177

    
178
        namedAreas.add(northernAmerica);
179
        namedAreas.add(southernAmerica);
180
        namedAreas.add(antarctica);
181

    
182
        List<TaxonDescription> descriptions = descriptionDao.searchDescriptionByDistribution(namedAreas, PresenceAbsenceTerm.ABSENT(), 10,0,null,null);
183
        assertNotNull("searchDescriptionByDistribution should return a List",descriptions);
184
        assertFalse("searchDescriptionsByDistribution should not be empty",descriptions.isEmpty());
185
        assertEquals("searchDescriptionsByDistribution should return 3 elements",3,descriptions.size());
186
    }
187

    
188
    @Test
189
    public void testCountDescriptionsWithText() {
190
        int numberOfDescriptions = descriptionDao.countDescriptions(TaxonDescription.class, null, true, null);
191

    
192
        assertNotNull("countDescriptions should return a 2",numberOfDescriptions);
193
    }
194

    
195
    @Test
196
    public void testListDescriptionsWithText() {
197
        List<OrderHint> orderHints = new ArrayList<OrderHint>();
198
        orderHints.add(new OrderHint("titleCache",SortOrder.ASCENDING));
199
        List<String> propertyPaths = new ArrayList<String>();
200
        propertyPaths.add("taxon");
201
        List<DescriptionBase> descriptions = descriptionDao.listDescriptions(TaxonDescription.class, null, true, null,null,null,orderHints,propertyPaths);
202

    
203
        assertNotNull("listDescriptions should return a List",descriptions);
204
        assertFalse("listDescriptions should not be empty", descriptions.isEmpty());
205
        assertEquals("listDescriptions should return 2 descriptions",2,descriptions.size());
206
    }
207

    
208
    @Test
209
    public void testCountDescriptionsWithTextAndFeatures() {
210
        features.add(Feature.ECOLOGY());
211
        int numberOfDescriptions = descriptionDao.countDescriptions(TaxonDescription.class, null, true, features);
212

    
213
        assertNotNull("countDescriptions should return a 1",numberOfDescriptions);
214
    }
215

    
216
    @Test
217
    public void testListDescriptionsWithTextAndFeatures() {
218
        assert Feature.ECOLOGY() != null;
219
        features.add(Feature.ECOLOGY());
220

    
221
        List<DescriptionBase> descriptions = descriptionDao.listDescriptions(TaxonDescription.class, null, true, features, null, null, null, null);
222

    
223
        assertNotNull("listDescriptions should return a List",descriptions);
224
        assertFalse("listDescriptions should not be empty", descriptions.isEmpty());
225
        assertEquals("listDescriptions should return 1 descriptions",1,descriptions.size());
226
    }
227

    
228
    @Test
229
    public void testCountDescriptionElements() {
230

    
231
        int numberOfDescriptionElements = descriptionDao.countDescriptionElements(null, null, null, null);
232
        assertEquals("expecting 37 description elements in total", 37, numberOfDescriptionElements);
233

    
234
        numberOfDescriptionElements = descriptionDao.countDescriptionElements(null, null, null, TextData.class);
235
        assertEquals("expecting 4 description elements of type TextData", 4, numberOfDescriptionElements);
236

    
237
        numberOfDescriptionElements = descriptionDao.countDescriptionElements(null, TaxonDescription.class, null, TextData.class);
238
        assertEquals("expecting 3 description elements of type TextData", 3, numberOfDescriptionElements);
239

    
240
        DescriptionBase<?> description = descriptionDao.findByUuid(uuid);
241
        assert description != null : "description must exist";
242

    
243
        numberOfDescriptionElements = descriptionDao.countDescriptionElements(description, null, null, TextData.class);
244

    
245
        assertEquals("expecting 2 description elements of type TextData in specific description", 2, numberOfDescriptionElements);
246
    }
247

    
248
    @Test
249
    public void testGetDescriptionElements() {
250

    
251
        List<DescriptionElementBase> elements = descriptionDao.getDescriptionElements(null, null, null, null, null, null, null);
252
        assertEquals("expecting 37 description elements in total", 37, elements.size());
253

    
254
        elements = descriptionDao.getDescriptionElements(null, null, null, TextData.class, null, null, null);
255
        assertEquals("expecting 4 description elements of type TextData", 4, elements.size());
256

    
257
        elements = descriptionDao.getDescriptionElements(null, TaxonDescription.class, null, TextData.class, null, null, null);
258
        assertEquals("expecting 3 description elements of type TextData", 3, elements.size());
259

    
260
        elements = descriptionDao.getDescriptionElements(null, SpecimenDescription.class, null, TextData.class, null, null, null);
261
        assertEquals("expecting 1 description elements of type TextData", 1, elements.size());
262

    
263
        DescriptionBase<?> description = descriptionDao.findByUuid(uuid);
264
        assert description != null : "description must exist";
265

    
266
        List<String> propertyPaths = new ArrayList<String>();
267
        propertyPaths.add("multilanguageText");
268
        propertyPaths.add("media");
269
        propertyPaths.add("feature");
270
        propertyPaths.add("sources.citation");
271

    
272
        elements = descriptionDao.getDescriptionElements(description, null, null, TextData.class, null, null, propertyPaths);
273

    
274
        for (DescriptionElementBase descElB: elements){
275
            if (descElB instanceof TextData){
276
                Map<Language, LanguageString> multiLanguage = ((TextData)descElB).getMultilanguageText();
277
                LanguageString defaultString = multiLanguage.get(Language.DEFAULT());
278

    
279
            }
280
        }
281
        Iterator<DescriptionElementBase> elements2 = description.getElements().iterator();
282
        while(elements2.hasNext()){
283
            DescriptionElementBase element = elements2.next();
284
            if (element instanceof TextData){
285
                Map<Language, LanguageString> multiLanguage = ((TextData)element).getMultilanguageText();
286
                LanguageString defaultString = multiLanguage.get(Language.DEFAULT());
287
                defaultString.setText("blablub");
288
            }
289
        }
290
        elements = descriptionDao.getDescriptionElements(description, null, null, TextData.class, null, null, propertyPaths);
291

    
292
        DescriptionElementBase element34 = null;
293
        for (DescriptionElementBase descElB: elements){
294
            if (descElB instanceof TextData){
295
                Map<Language, LanguageString> multiLanguage = ((TextData)descElB).getMultilanguageText();
296
                LanguageString defaultString = multiLanguage.get(Language.DEFAULT());
297
                //???
298
            }
299
            if (descElB.getId() == 34){
300
                element34 = descElB;
301
            }
302
        }
303

    
304
        assertNotNull("getDescriptionElements should return a List", elements);
305
        assertEquals("getDescriptionElement should return 2 elements",2,elements.size());
306
        assertNotNull("Description Element with ID 34 should be part of the list",element34);
307
        assertTrue("DescriptionElement.sources should be initialized",Hibernate.isInitialized(element34.getSources()));
308
        assertTrue("DescriptionElement.sources should have elements",element34.getSources().size() > 0);
309
        assertTrue("ReferencedEntityBase.citation should be initialized",Hibernate.isInitialized(element34.getSources().iterator().next().getCitation()));
310
        assertTrue("DescriptionElementBase.feature should be initialized",Hibernate.isInitialized(element34.getFeature()));
311
        assertTrue("DescriptionElementBase.media should be initialized",Hibernate.isInitialized(element34.getMedia()));
312
        assertTrue("TextData.multilanguageText should be initialized",Hibernate.isInitialized(((TextData)element34).getMultilanguageText()));
313
    }
314

    
315
    @Test
316
    public void testCountDescriptionElementsFeature() {
317
        features.add(Feature.ECOLOGY());
318
        DescriptionBase<?> description = descriptionDao.findByUuid(uuid);
319
        assert description != null : "description must exist";
320

    
321
        int numberOfDescriptionElements = descriptionDao.countDescriptionElements(description, features, TextData.class);
322

    
323
        assertEquals("countDescriptionElements should return 1", 1, numberOfDescriptionElements);
324
    }
325

    
326
    @Test
327
    public void testGetDescriptionElementsByFeature() {
328

    
329
        // 2. search for one Feature: ECOLOGY
330
        features.add(Feature.ECOLOGY());
331
        DescriptionBase<?> description = descriptionDao.findByUuid(uuid);
332
        assert description != null : "description must exist";
333

    
334
        List<DescriptionElementBase> elements = descriptionDao.getDescriptionElements(null, null, features, TextData.class, null, null,null);
335
        assertNotNull("getDescriptionElements should return a List", elements);
336
        assertEquals("getDescriptionElement should return 2 elements", 2, elements.size());
337

    
338
        elements = descriptionDao.getDescriptionElements(description, null, features, TextData.class, null, null,null);
339
        assertEquals("getDescriptionElement should return 1 elements", 1, elements.size());
340

    
341
        elements = descriptionDao.getDescriptionElements(null, SpecimenDescription.class, features, TextData.class, null, null,null);
342
        assertEquals("getDescriptionElement should return 1 elements", 1, elements.size());
343

    
344
        // 2. search for more Features: ECOLOGY & DESCRIPTION
345
        features.add(Feature.DESCRIPTION());
346
        elements = descriptionDao.getDescriptionElements(null, null, features, TextData.class, null, null,null);
347
        assertEquals("getDescriptionElement should return 4 elements", 4, elements.size());
348

    
349
        elements = descriptionDao.getDescriptionElements(null, TaxonDescription.class, features, TextData.class, null, null,null);
350
        assertEquals("getDescriptionElement should return 3 elements", 3, elements.size());
351
    }
352

    
353
    @Test
354
    public void testGetDescriptionElementForTaxon() {
355

    
356
        Taxon taxonSphingidae = (Taxon) taxonDao.load(taxonSphingidaeUuid);
357
        assert taxonSphingidae != null : "taxon must exist";
358

    
359
        // 1.
360

    
361
        List<DescriptionElementBase> elements1 = descriptionDao.getDescriptionElementForTaxon(
362
                taxonSphingidae.getUuid() , null, null, null, 0, null);
363

    
364
        assertNotNull("getDescriptionElementForTaxon should return a List", elements1);
365
        assertEquals("getDescriptionElementForTaxon should return 1 elements",1,elements1.size());
366

    
367
        // 2.
368

    
369
        List<DescriptionElementBase> elements2 = descriptionDao.getDescriptionElementForTaxon(
370
                taxonSphingidae.getUuid() , null, DescriptionElementBase.class, null, 0, null);
371

    
372
        assertNotNull("getDescriptionElementForTaxon should return a List", elements2);
373
        assertTrue("getDescriptionElementForTaxon should be empty",elements2.isEmpty());
374

    
375
        // 3.
376

    
377
        List<Distribution> elements3 = descriptionDao.getDescriptionElementForTaxon(
378
                taxonSphingidae.getUuid() , null, Distribution.class, null, 0, null);
379

    
380
        assertNotNull("getDescriptionElementForTaxon should return a List", elements3);
381
        assertEquals("getDescriptionElementForTaxon should return 1 elements",1,elements3.size());
382
    }
383

    
384
    //see #2234
385
    @Test
386
    public void testSaveClonedDescription() {
387

    
388
//		printDataSet(System.err, new String[]{"TAXONBASE"});
389

    
390
        Taxon taxon = Taxon.NewInstance(null, null);
391
        taxon.setTitleCache("##### created in testSaveClonedDescription()", true);
392
        taxonDao.save(taxon);
393
        commitAndStartNewTransaction(null);
394

    
395
        TaxonDescription description = TaxonDescription.NewInstance(taxon);
396
        this.descriptionDao.saveOrUpdate(description);
397
//		TaxonDescription clonedDescription = (TaxonDescription)description.clone();
398
//		this.descriptionDao.saveOrUpdate(clonedDescription);
399
//		printDataSet(System.err, new String[]{"TAXONBASE"});
400

    
401
        assertTrue(true);
402

    
403
    }
404

    
405
    //see #2592
406
    @Test
407
    public void testSaveScope(){
408
        int n1 = this.descriptionDao.count();
409
        Taxon taxon = Taxon.NewInstance(null, null);
410
        TaxonDescription description = TaxonDescription.NewInstance(taxon);
411
        this.taxonDao.save(taxon);
412
        int n2 = this.descriptionDao.count();
413
        Assert.assertEquals(1, n2-n1);
414

    
415
        DefinedTerm scope = DefinedTerm.SEX_FEMALE();
416
        description.addScope(scope);
417

    
418
        this.descriptionDao.saveOrUpdate(description);
419

    
420
    }
421

    
422
    @Test
423
    public void testListTaxonDescriptionWithMarker(){
424
        Taxon taxon = (Taxon)this.taxonDao.findByUuid(UUID.fromString("b04cc9cb-2b4a-4cc4-a94a-3c93a2158b06"));
425
        Set<DefinedTerm> scopes = null;
426
        Set<NamedArea> geographicalScope = null;
427
        Integer pageSize = null;
428
        Integer pageNumber = null;
429
        List<String> propertyPaths = null;
430

    
431
        //complete
432
        MarkerType completeMarkerType = (MarkerType)this.definedTermDao.findByUuid(UUID.fromString("b4b1b2ab-89a8-4ce6-8110-d60b8b1bc433")); //Marker "complete"
433
        Assert.assertNotNull("MarkerType for 'complete' should exist", completeMarkerType);
434
        Set<MarkerType> markerTypes = new HashSet<MarkerType>();
435
        markerTypes.add(completeMarkerType);
436
        int n1 = this.descriptionDao.countTaxonDescriptions(taxon, scopes, geographicalScope, markerTypes);
437
        Assert.assertEquals("There should be 1 description marked 'complete'", 1, n1);
438
        List<TaxonDescription> descriptions = this.descriptionDao.listTaxonDescriptions(taxon, scopes, geographicalScope, markerTypes, pageSize, pageNumber, propertyPaths);
439
        Assert.assertEquals("There should be 1 description marked 'complete'", 1, descriptions.size());
440

    
441
        //doubtful
442
        MarkerType isDoubtfulMarkerType = (MarkerType)this.definedTermDao.findByUuid(UUID.fromString("b51325c8-05fe-421a-832b-d86fc249ef6e")); //Marker "doubtful"
443
        Assert.assertNotNull("MarkerType for 'doubtful' should exist", isDoubtfulMarkerType);
444
        markerTypes = new HashSet<MarkerType>();  //reset
445
        markerTypes.add(isDoubtfulMarkerType);
446
        int n2 = this.descriptionDao.countTaxonDescriptions(taxon, scopes, geographicalScope, markerTypes);
447
        Assert.assertEquals("There should be no description marked 'doubtful'", 0, n2);
448
        descriptions = this.descriptionDao.listTaxonDescriptions(taxon, scopes, geographicalScope, markerTypes, pageSize, pageNumber, propertyPaths);
449
        Assert.assertEquals("There should be 0 description marked 'doubtful'", 0, descriptions.size());
450

    
451
        //imported = false
452
        UUID uuidImported = UUID.fromString("96878790-4ceb-42a2-9738-a2242079b679");
453
        MarkerType importedMarkerType = (MarkerType)this.definedTermDao.findByUuid(uuidImported);
454
        Assert.assertNotNull("MarkerType for 'imported' should exist", completeMarkerType);
455
        markerTypes = new HashSet<MarkerType>();
456
        markerTypes.add(importedMarkerType);
457
        int n3 = this.descriptionDao.countTaxonDescriptions(taxon, scopes, geographicalScope, markerTypes);
458
        Assert.assertEquals("There should be no description marked 'imported' as true", 0, n3);
459
        descriptions = this.descriptionDao.listTaxonDescriptions(taxon, scopes, geographicalScope, markerTypes, pageSize, pageNumber, propertyPaths);
460
        Assert.assertEquals("There should be no description marked 'imported' as true", 0, descriptions.size());
461
        markerTypes = null;
462
        descriptions = this.descriptionDao.listTaxonDescriptions(taxon, scopes, geographicalScope, markerTypes, pageSize, pageNumber, propertyPaths);
463
        Assert.assertEquals("There should be 1 description", 1, descriptions.size());
464
        TaxonDescription desc = descriptions.iterator().next();
465
        boolean hasMarkerImportedAsFalse = desc.hasMarker(importedMarkerType, false);
466
        Assert.assertTrue("The only description should have a negative marker on 'imported'", hasMarkerImportedAsFalse);
467

    
468
    }
469

    
470
//
471
//        //complete
472
//        MarkerType completeMarkerType = (MarkerType)this.definedTermDao.findByUuid(UUID.fromString("b4b1b2ab-89a8-4ce6-8110-d60b8b1bc433")); //Marker "complete"
473
//
474
//        Assert.assertNotNull("MarkerType for 'complete' should exist", completeMarkerType);
475
//        Set<MarkerType> markerTypes = new HashSet<MarkerType>();
476
//        markerTypes.add(completeMarkerType);
477
//        int n1 = this.descriptionDao.countTaxonDescriptions(taxon, scopes, geographicalScope, markerTypes);
478
//        Assert.assertEquals("There should be 1 description marked 'complete'", 1, n1);
479
//        List<TaxonDescription> descriptions = this.descriptionDao.listTaxonDescriptions(taxon, scopes, geographicalScope, markerTypes, pageSize, pageNumber, propertyPaths);
480
//        Assert.assertEquals("There should be 1 description marked 'complete'", 1, descriptions.size());
481
//
482
//        //doubtful
483
//        MarkerType isDoubtfulMarkerType = (MarkerType)this.definedTermDao.findByUuid(UUID.fromString("b51325c8-05fe-421a-832b-d86fc249ef6e")); //Marker "doubtful"
484
//        Assert.assertNotNull("MarkerType for 'doubtful' should exist", isDoubtfulMarkerType);
485
//        markerTypes = new HashSet<MarkerType>();  //reset
486
//        markerTypes.add(isDoubtfulMarkerType);
487
//        int n2 = this.descriptionDao.countTaxonDescriptions(taxon, scopes, geographicalScope, markerTypes);
488
//        Assert.assertEquals("There should be no description marked 'doubtful'", 0, n2);
489
//        descriptions = this.descriptionDao.listTaxonDescriptions(taxon, scopes, geographicalScope, markerTypes, pageSize, pageNumber, propertyPaths);
490
//        Assert.assertEquals("There should be 0 description marked 'doubtful'", 0, descriptions.size());
491
//
492
//        //imported = false
493
//        UUID uuidImported = UUID.fromString("96878790-4ceb-42a2-9738-a2242079b679");
494
//        MarkerType importedMarkerType = (MarkerType)this.definedTermDao.findByUuid(uuidImported);
495
//        Assert.assertNotNull("MarkerType for 'imported' should exist", completeMarkerType);
496
//        markerTypes = new HashSet<MarkerType>();
497
//        markerTypes.add(importedMarkerType);
498
//        int n3 = this.descriptionDao.countTaxonDescriptions(taxon, scopes, geographicalScope, markerTypes);
499
//        Assert.assertEquals("There should be no description marked 'imported' as true", 0, n3);
500
//        descriptions = this.descriptionDao.listTaxonDescriptions(taxon, scopes, geographicalScope, markerTypes, pageSize, pageNumber, propertyPaths);
501
//        Assert.assertEquals("There should be no description marked 'imported' as true", 0, descriptions.size());
502
//        markerTypes = null;
503
//        descriptions = this.descriptionDao.listTaxonDescriptions(taxon, scopes, geographicalScope, markerTypes, pageSize, pageNumber, propertyPaths);
504
//        Assert.assertEquals("There should be 1 description", 1, descriptions.size());
505
//        TaxonDescription desc = descriptions.iterator().next();
506
//        boolean hasMarkerImportedAsFalse = desc.hasMarker(importedMarkerType, false);
507
//        Assert.assertTrue("The only description should have a negative marker on 'imported'", hasMarkerImportedAsFalse);
508
//
509
//    }
510

    
511

    
512
    @Test
513
    @DataSet("DescriptionDaoHibernateImplTest.testListTaxonDescriptionMedia.xml")
514
    public void testListTaxonDescriptionMedia(){
515
        //init
516
        Taxon firstTaxon = (Taxon)this.taxonDao.findByUuid(UUID.fromString("496b1325-be50-4b0a-9aa2-3ecd610215f2"));
517
        Taxon secondTaxon = (Taxon)this.taxonDao.findByUuid(UUID.fromString("822d98dc-9ef7-44b7-a870-94573a3bcb46"));
518
        Taxon thirdTaxon = (Taxon)this.taxonDao.findByUuid(UUID.fromString("54e767ee-894e-4540-a758-f906ecb4e2d9"));
519
        MarkerType markerType890 = (MarkerType)this.definedTermDao.findById(890);
520
        MarkerType markerType892 = (MarkerType)this.definedTermDao.findById(892);
521

    
522
        Assert.assertNotNull("First taxon should exist", firstTaxon);
523
        Assert.assertNotNull("Second taxon should exist", secondTaxon);
524
        Assert.assertNotNull("Third taxon should exist", thirdTaxon);
525
        Assert.assertEquals("There should be 6 descriptions in the database", 6, this.descriptionDao.count());
526

    
527

    
528
        //set parameter
529
        Set<MarkerType> markerTypes = null;
530
        Integer pageSize = null;
531
        Integer pageNumber = null;
532
        List<String> propertyPaths = null;
533

    
534
        //test
535
        //first Taxon gallery filter
536
        List<Media> mediaList = this.descriptionDao.listTaxonDescriptionMedia(firstTaxon.getUuid(), true, markerTypes, pageSize, pageNumber, propertyPaths);
537
        Assert.assertEquals("media list size for first taxon and filter on image galleries should be 1", 1, mediaList.size());
538

    
539
        //first taxon all descriptions
540
        mediaList = this.descriptionDao.listTaxonDescriptionMedia(firstTaxon.getUuid(), false, markerTypes, pageSize, pageNumber, propertyPaths);
541
        Assert.assertEquals("media list size for first taxon without filter on image galleries should be 2", 2, mediaList.size());
542

    
543
        //second taxon
544
        mediaList = this.descriptionDao.listTaxonDescriptionMedia(secondTaxon.getUuid(), true, markerTypes, pageSize, pageNumber, propertyPaths);
545
        Assert.assertEquals("media list size for second taxon and filter on image galleries should be 2", 2, mediaList.size());
546

    
547
        //all taxa
548
        mediaList = this.descriptionDao.listTaxonDescriptionMedia(null, true, markerTypes, pageSize, pageNumber, propertyPaths);
549
        Assert.assertEquals("media list size for any taxon and filter on image galleries should be 3", 3, mediaList.size());
550
        //with marker
551
        markerTypes = new HashSet<MarkerType>();
552
        mediaList = this.descriptionDao.listTaxonDescriptionMedia(null, true, markerTypes, pageSize, pageNumber, propertyPaths);
553
        Assert.assertEquals("Empty marker type set should give same result as before: 3", 3, mediaList.size());
554
        markerTypes.add(markerType890);
555
        mediaList = this.descriptionDao.listTaxonDescriptionMedia(null, true, markerTypes, pageSize, pageNumber, propertyPaths);
556
        Assert.assertEquals("markerType890 should only give 1 result", 1, mediaList.size());
557
        markerTypes.add(markerType892);
558
        mediaList = this.descriptionDao.listTaxonDescriptionMedia(null, true, markerTypes, pageSize, pageNumber, propertyPaths);
559
        Assert.assertEquals("markerType892 should not give additional result as the markers value is false", 1, mediaList.size());
560
        markerTypes = null;
561

    
562
        //check deduplication
563
        mediaList = this.descriptionDao.listTaxonDescriptionMedia(null, false, markerTypes, pageSize, pageNumber, propertyPaths);
564
        Assert.assertEquals("media list size for any taxon without filter on image galleries should be 3", 3, mediaList.size());
565

    
566
//        System.out.println(mediaList);
567
    }
568

    
569
    @Test
570
    @DataSet("DescriptionDaoHibernateImplTest.testListTaxonDescriptionMedia.xml")
571
    public void testcountTaxonDescriptionMedia(){
572
        //init
573
        Taxon firstTaxon = (Taxon)this.taxonDao.findByUuid(UUID.fromString("496b1325-be50-4b0a-9aa2-3ecd610215f2"));
574
        Taxon secondTaxon = (Taxon)this.taxonDao.findByUuid(UUID.fromString("822d98dc-9ef7-44b7-a870-94573a3bcb46"));
575
        Taxon thirdTaxon = (Taxon)this.taxonDao.findByUuid(UUID.fromString("54e767ee-894e-4540-a758-f906ecb4e2d9"));
576
        MarkerType markerType890 = (MarkerType)this.definedTermDao.findById(890);
577
        MarkerType markerType892 = (MarkerType)this.definedTermDao.findById(892);
578

    
579
        Assert.assertNotNull("First taxon should exist", firstTaxon);
580
        Assert.assertNotNull("Second taxon should exist", secondTaxon);
581
        Assert.assertNotNull("Third taxon should exist", thirdTaxon);
582
        Assert.assertEquals("There should be 6 descriptions in the database", 6, this.descriptionDao.count());
583

    
584
        //set parameter
585
        Set<MarkerType> markerTypes = null;
586

    
587
        //test
588
        //first Taxon gallery filter
589
        int mediaCount = this.descriptionDao.countTaxonDescriptionMedia(firstTaxon.getUuid(), true, markerTypes);
590
        Assert.assertEquals("media list size for first taxon and filter on image galleries should be 1", 1, mediaCount);
591
        mediaCount = this.descriptionDao.countTaxonDescriptionMedia(firstTaxon.getUuid(), false, markerTypes);
592
        Assert.assertEquals("media list size for first taxon without filter on image galleries should be 2", 2, mediaCount);
593

    
594
        //second taxon
595
        mediaCount = this.descriptionDao.countTaxonDescriptionMedia(secondTaxon.getUuid(), true, markerTypes);
596
        Assert.assertEquals("media list size for second taxon and filter on image galleries should be 2", 2, mediaCount);
597

    
598
        //all taxa
599
        mediaCount = this.descriptionDao.countTaxonDescriptionMedia(null, true, markerTypes);
600
        Assert.assertEquals("media list size for any taxon and filter on image galleries should be 3", 3, mediaCount);
601
        //with marker
602
        markerTypes = new HashSet<MarkerType>();
603
        mediaCount = this.descriptionDao.countTaxonDescriptionMedia(null, true, markerTypes);
604
        Assert.assertEquals("Empty marker type set should give same result as before: 3", 3, mediaCount);
605
        markerTypes.add(markerType890);
606
        mediaCount = this.descriptionDao.countTaxonDescriptionMedia(null, true, markerTypes);
607
        Assert.assertEquals("markerType890 should only give 1 result", 1, mediaCount);
608
        markerTypes.add(markerType892);
609
        mediaCount = this.descriptionDao.countTaxonDescriptionMedia(null, true, markerTypes);
610
        Assert.assertEquals("markerType892 should not give additional result as the markers value is false", 1, mediaCount);
611
        markerTypes = null;
612

    
613
        //check deduplication
614
        mediaCount = this.descriptionDao.countTaxonDescriptionMedia(null, false, markerTypes);
615
        Assert.assertEquals("media list size for any taxon without filter on image galleries should be 3", 3, mediaCount);
616

    
617
    }
618

    
619
    @Test
620
    @DataSet
621
    public void testListNamedAreasInUse(){
622

    
623
        Collection<TermDto> list = null;
624

    
625
        DefinedTermBase antarctica = definedTermDao.load(antarcticaUuid);
626
        antarctica.getRepresentations().add(Representation.NewInstance("Antarktis", "Antarktis", "An", Language.GERMAN()));
627
        definedTermDao.saveOrUpdate(antarctica);
628
        commitAndStartNewTransaction(null);
629

    
630
        list = descriptionDao.listNamedAreasInUse(false, null, null);
631
        Assert.assertEquals(3, list.size());
632

    
633
    }
634

    
635
    @Test
636
    @DataSet
637
    // @Ignore // the first query in listNamedAreasInUse is for some reason not working with h2
638
    public void testListNamedAreasInUseWithParents(){
639

    
640
        Collection<TermDto> list = null;
641

    
642
        list = descriptionDao.listNamedAreasInUse(true, null, null);
643
        Assert.assertEquals(3, list.size());
644

    
645
    }
646

    
647

    
648
    /* (non-Javadoc)
649
     * @see eu.etaxonomy.cdm.test.integration.CdmIntegrationTest#createTestData()
650
     */
651
    @Override
652
    public void createTestDataSet() throws FileNotFoundException {
653
        // TODO Auto-generated method stub
654

    
655
    }
656

    
657

    
658
}
(1-1/4)