c93ff71a6483bc401e71c4f902b799b9fb48a571
[cdmlib.git] / cdmlib-persistence / src / test / java / eu / etaxonomy / cdm / persistence / dao / hibernate / media / MediaDaoImplTest.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.media;
11
12 import static org.junit.Assert.assertEquals;
13 import static org.junit.Assert.assertFalse;
14 import static org.junit.Assert.assertNotNull;
15
16 import java.util.HashSet;
17 import java.util.List;
18 import java.util.Set;
19 import java.util.UUID;
20
21 import org.junit.Before;
22 import org.junit.Test;
23 import org.unitils.dbunit.annotation.DataSet;
24 import org.unitils.spring.annotation.SpringBeanByType;
25
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;
33
34 @DataSet
35 public class MediaDaoImplTest extends CdmIntegrationTest {
36
37 @SpringBeanByType
38 IMediaDao mediaDao;
39
40 @SpringBeanByType
41 IDefinedTermDao definedTermDao;
42
43 @SpringBeanByType
44 ITaxonDao taxonDao;
45
46 UUID europeUuid;
47 UUID africaUuid;
48 UUID sphingidaeUuid;
49
50 Set<Taxon> taxonomicScope;
51 Set<NamedArea> geoScopes;
52
53 @Before
54 public void setUp() {
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");
58
59 taxonomicScope = new HashSet<Taxon>();
60 geoScopes = new HashSet<NamedArea>();
61 }
62
63 @Test
64 public void testCountIdentificationKeys() {
65 int numberOfIdentificationKeys = mediaDao.countIdentificationKeys(null,null);
66
67 assertEquals("countIdentificationKeys should return 3",3,numberOfIdentificationKeys);
68 }
69
70 @Test
71 public void testGetIdentificationKeys() {
72 List<IdentificationKey> keys = mediaDao.getIdentificationKeys(null, null, null, null);
73
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());
77 }
78
79 @Test
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";
87
88 geoScopes.add(europe);
89 geoScopes.add(africa);
90 taxonomicScope.add(sphingidae);
91
92 int numberOfIdentificationKeys = mediaDao.countIdentificationKeys(taxonomicScope,geoScopes);
93
94 assertEquals("countIdentificationKeys should return 1",1,numberOfIdentificationKeys);
95 }
96
97 @Test
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";
105
106 geoScopes.add(europe);
107 geoScopes.add(africa);
108 taxonomicScope.add(sphingidae);
109
110 List<IdentificationKey> keys = mediaDao.getIdentificationKeys(taxonomicScope,geoScopes, null, null);
111
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());
115 }
116
117 }