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
.media
;
12 import static org
.junit
.Assert
.assertEquals
;
13 import static org
.junit
.Assert
.assertFalse
;
14 import static org
.junit
.Assert
.assertNotNull
;
16 import java
.util
.HashSet
;
17 import java
.util
.List
;
19 import java
.util
.UUID
;
21 import org
.junit
.Before
;
22 import org
.junit
.Test
;
23 import org
.unitils
.dbunit
.annotation
.DataSet
;
24 import org
.unitils
.spring
.annotation
.SpringBeanByType
;
26 import eu
.etaxonomy
.cdm
.model
.description
.IdentificationKey
;
27 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
28 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
29 import eu
.etaxonomy
.cdm
.persistence
.dao
.common
.IDefinedTermDao
;
30 import eu
.etaxonomy
.cdm
.persistence
.dao
.media
.IMediaDao
;
31 import eu
.etaxonomy
.cdm
.persistence
.dao
.taxon
.ITaxonDao
;
32 import eu
.etaxonomy
.cdm
.test
.integration
.CdmIntegrationTest
;
35 public class MediaDaoImplTest
extends CdmIntegrationTest
{
41 IDefinedTermDao definedTermDao
;
50 Set
<Taxon
> taxonomicScope
;
51 Set
<NamedArea
> geoScopes
;
55 europeUuid
= UUID
.fromString("e860871c-3a14-4ef2-9367-bbd92586c95b");
56 africaUuid
= UUID
.fromString("9444016a-b334-4772-8795-ed4019552087");
57 sphingidaeUuid
= UUID
.fromString("54e767ee-894e-4540-a758-f906ecb4e2d9");
59 taxonomicScope
= new HashSet
<Taxon
>();
60 geoScopes
= new HashSet
<NamedArea
>();
64 public void testCountIdentificationKeys() {
65 int numberOfIdentificationKeys
= mediaDao
.countIdentificationKeys(null,null);
67 assertEquals("countIdentificationKeys should return 3",3,numberOfIdentificationKeys
);
71 public void testGetIdentificationKeys() {
72 List
<IdentificationKey
> keys
= mediaDao
.getIdentificationKeys(null, null, null, null);
74 assertNotNull("getIdentificationKeys should return a List",keys
);
75 assertFalse("The list should not be empty",keys
.isEmpty());
76 assertEquals("The list should contain 3 IdentificationKey instances",3, keys
.size());
80 public void testCountIdentificationKeysWithScope() {
81 NamedArea europe
= (NamedArea
)definedTermDao
.findByUuid(europeUuid
);
82 NamedArea africa
= (NamedArea
)definedTermDao
.findByUuid(africaUuid
);
83 Taxon sphingidae
= (Taxon
)taxonDao
.findByUuid(sphingidaeUuid
);
84 assert europe
!= null : "NamedArea must exist";
85 assert africa
!= null : "NamedArea must exist";
86 assert sphingidae
!= null : "Taxon must exist";
88 geoScopes
.add(europe
);
89 geoScopes
.add(africa
);
90 taxonomicScope
.add(sphingidae
);
92 int numberOfIdentificationKeys
= mediaDao
.countIdentificationKeys(taxonomicScope
,geoScopes
);
94 assertEquals("countIdentificationKeys should return 1",1,numberOfIdentificationKeys
);
98 public void testGetIdentificationKeysWithScope() {
99 NamedArea europe
= (NamedArea
)definedTermDao
.findByUuid(europeUuid
);
100 NamedArea africa
= (NamedArea
)definedTermDao
.findByUuid(africaUuid
);
101 Taxon sphingidae
= (Taxon
)taxonDao
.findByUuid(sphingidaeUuid
);
102 assert europe
!= null : "NamedArea must exist";
103 assert africa
!= null : "NamedArea must exist";
104 assert sphingidae
!= null : "Taxon must exist";
106 geoScopes
.add(europe
);
107 geoScopes
.add(africa
);
108 taxonomicScope
.add(sphingidae
);
110 List
<IdentificationKey
> keys
= mediaDao
.getIdentificationKeys(taxonomicScope
,geoScopes
, null, null);
112 assertNotNull("getIdentificationKeys should return a List",keys
);
113 assertFalse("The list should not be empty",keys
.isEmpty());
114 assertEquals("The list should contain 1 IdentificationKey instance",1, keys
.size());