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
.common
;
13 import static org
.junit
.Assert
.assertEquals
;
14 import static org
.junit
.Assert
.assertFalse
;
15 import static org
.junit
.Assert
.assertNotNull
;
16 import static org
.junit
.Assert
.assertNull
;
18 import java
.util
.HashSet
;
19 import java
.util
.List
;
21 import java
.util
.UUID
;
23 import org
.junit
.Before
;
24 import org
.junit
.Test
;
25 import org
.unitils
.dbunit
.annotation
.DataSet
;
26 import org
.unitils
.spring
.annotation
.SpringBeanByType
;
28 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTermBase
;
29 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
30 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
31 import eu
.etaxonomy
.cdm
.persistence
.dao
.common
.IDefinedTermDao
;
32 import eu
.etaxonomy
.cdm
.test
.integration
.CdmIntegrationTest
;
35 public class DefinedTermDaoImplTest
extends CdmIntegrationTest
{
38 private IDefinedTermDao dao
;
42 private UUID northernEuropeUuid
;
43 private UUID middleEuropeUuid
;
44 private UUID westTropicalAfricaUuid
;
45 private Set
<NamedArea
> namedAreas
;
49 uuid
= UUID
.fromString("d6781519-ec60-4afa-b5ea-375f4d2a1729");
50 armUuid
= UUID
.fromString("7a0fde13-26e9-4382-a5c9-5640fc2b3334");
51 northernEuropeUuid
= UUID
.fromString("22524ba2-6e57-4b71-89ab-89fc50fba6b4");
52 middleEuropeUuid
= UUID
.fromString("d292f237-da3d-408b-93a1-3257a8c80b97");
53 westTropicalAfricaUuid
= UUID
.fromString("931164ad-ec16-4133-afab-bdef25d67636");
54 namedAreas
= new HashSet
<NamedArea
>();
58 public void findByTitle() throws Exception
{
59 List
<DefinedTermBase
> terms
= dao
.findByTitle("nomenclature");
60 assertNotNull("findByTitle should return a List", terms
);
61 assertEquals("findByTitle should return one term ",terms
.size(),1);
62 assertEquals("findByTitle should return a term with uuid " + uuid
,terms
.get(0).getUuid(),uuid
);
66 * FIXME Should list() be tested in CdmEntityDaoBaseTest?
67 * Also - how is this list sorted? Should we supply an enum that allows
68 * the list to be sorted by different fields (titleCache? label? text? uri?)
71 public void listOneTerm() {
72 List
<DefinedTermBase
> terms
= dao
.list(1,2017);
73 assertNotNull("list should return a list",terms
);
74 assertEquals("list should return one term",1, terms
.size());
75 assertEquals("list should return one term with uuid " + uuid
, uuid
,terms
.get(0).getUuid());
79 public void listManyTerms() {
80 List
<DefinedTermBase
> terms
= dao
.list(5,2013);
81 assertNotNull("list should return a list",terms
);
82 assertEquals("list should return five terms",5, terms
.size());
83 assertEquals("list should return a term with uuid " + uuid
+ " at position 5", uuid
,terms
.get(4).getUuid());
87 public void getTermByUUID() {
88 DefinedTermBase term
= dao
.findByUuid(uuid
);
89 assertNotNull("findByUuid should return a term",term
);
94 public void getLanguageByIso2() {
95 Language lang
= dao
.getLanguageByIso("arm");
96 assertEquals("getLanguageByIso should return the correct Language instance",lang
.getUuid(), armUuid
);
100 public void getLanguageByIso1() {
101 Language lang
= dao
.getLanguageByIso("hy");
102 assertEquals("getLanguageByIso should return the correct Language instance",lang
.getUuid(), armUuid
);
106 public void getLanguageByMalformedIso1() {
107 Language lang
= dao
.getLanguageByIso("a");
108 assertNull("getLanguageByIso should return null for this malformed Iso \'a\'",lang
);
112 public void getLanguageByMalformedIso2() {
113 Language lang
= dao
.getLanguageByIso("abcd");
114 assertNull("getLanguageByIso should return null for this malformed Iso \'abcd\'",lang
);
118 public void testGetIncludes() {
119 NamedArea northernEurope
= (NamedArea
)dao
.findByUuid(northernEuropeUuid
);
120 assert northernEurope
!= null : "NamedArea must exist";
121 namedAreas
.add(northernEurope
);
123 List
<NamedArea
> includes
= dao
.getIncludes(namedAreas
, null, null);
125 assertNotNull("getIncludes should return a List",includes
);
126 assertFalse("The list should not be empty",includes
.isEmpty());
127 assertEquals("getIncludes should return 9 NamedArea entities",9,includes
.size());
131 public void countIncludes() {
132 NamedArea northernEurope
= (NamedArea
)dao
.findByUuid(northernEuropeUuid
);
133 assert northernEurope
!= null : "NamedArea must exist";
134 namedAreas
.add(northernEurope
);
136 int numberOfIncludes
= dao
.countIncludes(namedAreas
);
137 assertEquals("countIncludes should return 9",9, numberOfIncludes
);
142 public void testGetPartOf() {
143 NamedArea northernEurope
= (NamedArea
)dao
.findByUuid(northernEuropeUuid
);
144 NamedArea middleEurope
= (NamedArea
)dao
.findByUuid(middleEuropeUuid
);
145 NamedArea westTropicalAfrica
= (NamedArea
)dao
.findByUuid(westTropicalAfricaUuid
);
146 assert northernEurope
!= null : "NamedArea must exist";
147 assert middleEurope
!= null : "NamedArea must exist";
148 assert westTropicalAfrica
!= null : "NamedArea must exist";
149 namedAreas
.add(northernEurope
);
150 namedAreas
.add(middleEurope
);
151 namedAreas
.add(westTropicalAfrica
);
153 List
<NamedArea
> partOf
= dao
.getPartOf(namedAreas
, null, null);
155 assertNotNull("getPartOf should return a List",partOf
);
156 assertFalse("The list should not be empty",partOf
.isEmpty());
157 assertEquals("getPartOf should return 2 NamedArea entities",2,partOf
.size());
161 public void countPartOf() {
162 NamedArea northernEurope
= (NamedArea
)dao
.findByUuid(northernEuropeUuid
);
163 NamedArea middleEurope
= (NamedArea
)dao
.findByUuid(middleEuropeUuid
);
164 NamedArea westTropicalAfrica
= (NamedArea
)dao
.findByUuid(westTropicalAfricaUuid
);
165 assert northernEurope
!= null : "NamedArea must exist";
166 assert middleEurope
!= null : "NamedArea must exist";
167 assert westTropicalAfrica
!= null : "NamedArea must exist";
168 namedAreas
.add(northernEurope
);
169 namedAreas
.add(middleEurope
);
170 namedAreas
.add(westTropicalAfrica
);
172 int numberOfPartOf
= dao
.countPartOf(namedAreas
);
173 assertEquals("countPartOf should return 2",2,numberOfPartOf
);