1
|
/**
|
2
|
* Copyright (C) 2009 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.name;
|
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.assertNull;
|
16
|
|
17
|
import java.io.FileNotFoundException;
|
18
|
import java.util.HashSet;
|
19
|
import java.util.Iterator;
|
20
|
import java.util.List;
|
21
|
import java.util.Set;
|
22
|
import java.util.UUID;
|
23
|
|
24
|
import org.junit.Before;
|
25
|
import org.junit.Test;
|
26
|
import org.unitils.dbunit.annotation.DataSet;
|
27
|
import org.unitils.spring.annotation.SpringBeanByType;
|
28
|
|
29
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
30
|
import eu.etaxonomy.cdm.model.name.BotanicalName;
|
31
|
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
|
32
|
import eu.etaxonomy.cdm.model.name.HybridRelationship;
|
33
|
import eu.etaxonomy.cdm.model.name.NameRelationship;
|
34
|
import eu.etaxonomy.cdm.model.name.Rank;
|
35
|
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
|
36
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
37
|
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
|
38
|
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
|
39
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
40
|
import eu.etaxonomy.cdm.persistence.dao.name.IHomotypicalGroupDao;
|
41
|
import eu.etaxonomy.cdm.persistence.dao.name.ITaxonNameDao;
|
42
|
import eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonDao;
|
43
|
import eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException;
|
44
|
import eu.etaxonomy.cdm.test.integration.CdmIntegrationTest;
|
45
|
|
46
|
@DataSet
|
47
|
public class TaxonNameDaoHibernateImplTest extends CdmIntegrationTest {
|
48
|
|
49
|
@SpringBeanByType
|
50
|
ITaxonNameDao taxonNameDao;
|
51
|
|
52
|
@SpringBeanByType
|
53
|
ITaxonDao taxonDao;
|
54
|
|
55
|
@SpringBeanByType
|
56
|
IHomotypicalGroupDao homotypicalGroupDao;
|
57
|
|
58
|
private UUID cryptocoryneGriffithiiUuid;
|
59
|
private UUID acherontiaUuid;
|
60
|
private UUID acherontiaLachesisUuid;
|
61
|
private UUID atroposUuid;
|
62
|
|
63
|
@Before
|
64
|
public void setUp() {
|
65
|
cryptocoryneGriffithiiUuid = UUID.fromString("497a9955-5c5a-4f2b-b08c-2135d336d633");
|
66
|
acherontiaUuid = UUID.fromString("c2cab2ad-3e3a-47b8-8aa8-d9e1c0857647");
|
67
|
acherontiaLachesisUuid = UUID.fromString("7969821b-a2cf-4d01-95ec-6a5ed0ca3f69");
|
68
|
atroposUuid = UUID.fromString("27004fcc-14d4-47d4-a3e1-75750fdb5b79");
|
69
|
}
|
70
|
|
71
|
@Test
|
72
|
public void testGetHybridRelationships() {
|
73
|
BotanicalName cryptocoryneGriffithii = (BotanicalName)taxonNameDao.findByUuid(cryptocoryneGriffithiiUuid);
|
74
|
assert cryptocoryneGriffithii!= null : "name must exist";
|
75
|
|
76
|
List<HybridRelationship> result = taxonNameDao.getHybridNames(cryptocoryneGriffithii, null, null, null,null,null);
|
77
|
|
78
|
assertNotNull("getHybridNames should return a list",result);
|
79
|
assertFalse("the list should not be empty", result.isEmpty());
|
80
|
assertEquals("getHybridNames should return 1 HybridRelationship instance",1,result.size());
|
81
|
}
|
82
|
|
83
|
@Test
|
84
|
public void testCountHybridRelationships() {
|
85
|
BotanicalName cryptocoryneGriffithii = (BotanicalName)taxonNameDao.findByUuid(cryptocoryneGriffithiiUuid);
|
86
|
assert cryptocoryneGriffithii != null : "name must exist";
|
87
|
|
88
|
int count = taxonNameDao.countHybridNames(cryptocoryneGriffithii, null);
|
89
|
|
90
|
assertEquals("countHybridNames should return 1",1,count);
|
91
|
}
|
92
|
|
93
|
@Test
|
94
|
public void testGetNameRelationships() {
|
95
|
TaxonNameBase acherontia = taxonNameDao.findByUuid(acherontiaUuid);
|
96
|
assert acherontia != null : "name must exist";
|
97
|
|
98
|
List<NameRelationship> result = taxonNameDao.getNameRelationships(acherontia, NameRelationship.Direction.relatedFrom, null, null,null,null, null);
|
99
|
|
100
|
assertNotNull("getRelatedNames should return a list",result);
|
101
|
assertFalse("the list should not be empty", result.isEmpty());
|
102
|
assertEquals("getRelatedNames should return 1 NameRelationship instance",1,result.size());
|
103
|
|
104
|
// testing inverted direction
|
105
|
TaxonNameBase atropos = taxonNameDao.findByUuid(atroposUuid);
|
106
|
assert atropos != null : "name must exist";
|
107
|
|
108
|
result = taxonNameDao.getNameRelationships(atropos, NameRelationship.Direction.relatedTo, null, null,null,null, null);
|
109
|
|
110
|
assertNotNull("getRelatedNames should return a list",result);
|
111
|
assertFalse("the list should not be empty", result.isEmpty());
|
112
|
assertEquals("getRelatedNames should return 2 NameRelationship instance",2,result.size());
|
113
|
|
114
|
result = taxonNameDao.getNameRelationships(null, null, null, null,null,null, null);
|
115
|
|
116
|
assertNotNull("getRelatedNames should return a list",result);
|
117
|
assertFalse("the list should not be empty", result.isEmpty());
|
118
|
assertEquals("getRelatedNames should return all 2 NameRelationship instance",2,result.size());
|
119
|
}
|
120
|
|
121
|
@Test
|
122
|
public void testCountNameRelationships() {
|
123
|
TaxonNameBase acherontia = taxonNameDao.findByUuid(acherontiaUuid);
|
124
|
assert acherontia != null : "name must exist";
|
125
|
|
126
|
int count = taxonNameDao.countNameRelationships(acherontia, NameRelationship.Direction.relatedFrom, null);
|
127
|
|
128
|
assertEquals("countRelatedNames should return 1",1,count);
|
129
|
|
130
|
// testing inverted direction
|
131
|
TaxonNameBase atropos = taxonNameDao.findByUuid(atroposUuid);
|
132
|
assert atropos != null : "name must exist";
|
133
|
|
134
|
count = taxonNameDao.countNameRelationships(atropos, NameRelationship.Direction.relatedTo, null);
|
135
|
|
136
|
assertEquals("countRelatedNames should return 2",2,count);
|
137
|
}
|
138
|
|
139
|
@Test
|
140
|
public void testGetTypeDesignations() {
|
141
|
TaxonNameBase acherontiaLachesis = taxonNameDao.findByUuid(acherontiaLachesisUuid);
|
142
|
assert acherontiaLachesis != null : "name must exist";
|
143
|
|
144
|
List<TypeDesignationBase> result1 = taxonNameDao.getTypeDesignations(acherontiaLachesis, null, null, null, null, null);
|
145
|
|
146
|
assertNotNull("getTypeDesignations should return a list",result1);
|
147
|
assertFalse("the list should not be empty", result1.isEmpty());
|
148
|
assertEquals("getTypeDesignations should return 1 TypeDesignationBase instance",1,result1.size());
|
149
|
|
150
|
List<SpecimenTypeDesignation> result2 = taxonNameDao.getTypeDesignations(acherontiaLachesis, SpecimenTypeDesignation.class, null, null, null, null);
|
151
|
|
152
|
assertNotNull("getTypeDesignations should return a list",result2);
|
153
|
assertFalse("the list should not be empty", result2.isEmpty());
|
154
|
assertEquals("getTypeDesignations should return 1 TypeDesignationBase instance",1,result2.size());
|
155
|
}
|
156
|
|
157
|
@Test
|
158
|
public void testCountTypeDesignations() {
|
159
|
TaxonNameBase acherontiaLachesis = taxonNameDao.findByUuid(acherontiaLachesisUuid);
|
160
|
assert acherontiaLachesis != null : "name must exist";
|
161
|
|
162
|
int count = taxonNameDao.countTypeDesignations(acherontiaLachesis, null);
|
163
|
|
164
|
assertEquals("countTypeDesignations should return 1",1,count);
|
165
|
}
|
166
|
|
167
|
@Test
|
168
|
public void testSearchNames() {
|
169
|
List<TaxonNameBase> result = taxonNameDao.searchNames("Atropos", null, null, null, Rank.GENUS(), null, null, null, null);
|
170
|
|
171
|
assertNotNull("searcNames should return a list",result);
|
172
|
assertFalse("the list should not be empty", result.isEmpty());
|
173
|
assertEquals("searchNames should return 3 TaxonNameBase instances",3,result.size());
|
174
|
}
|
175
|
|
176
|
@Test
|
177
|
public void testCountNames() {
|
178
|
int count = taxonNameDao.countNames("Atropos", null, null, null, Rank.GENUS());
|
179
|
|
180
|
assertEquals("countNames should return 3",3,count);
|
181
|
}
|
182
|
|
183
|
@Test
|
184
|
public void testCountNamesByExample() {
|
185
|
TaxonNameBase<?,?> zoologicalName = TaxonNameFactory.NewZoologicalInstance(Rank.GENUS());
|
186
|
zoologicalName.setGenusOrUninomial("Atropos");
|
187
|
Set<String> includedProperties = new HashSet<String>();
|
188
|
includedProperties.add("genusOrUninomial");
|
189
|
includedProperties.add("specificEpithet");
|
190
|
includedProperties.add("infraSpecificEpithet");
|
191
|
includedProperties.add("rank");
|
192
|
int count = taxonNameDao.count(zoologicalName, includedProperties);
|
193
|
|
194
|
assertEquals("countNames should return 3",3,count);
|
195
|
}
|
196
|
|
197
|
@Test
|
198
|
/**
|
199
|
* This test check for a specific bug (Ticket #686) where the rank of a taxon name base
|
200
|
* has no order index (=0)
|
201
|
*/
|
202
|
public void testMissingRankOrderIndex() {
|
203
|
TaxonNameBase acherontiaLachesis = taxonNameDao.findByUuid(acherontiaLachesisUuid);
|
204
|
Rank rank = null;
|
205
|
try {
|
206
|
rank = Rank.getRankByName(acherontiaLachesis.getRank().getLabel());
|
207
|
} catch (UnknownCdmTypeException e) {
|
208
|
e.printStackTrace();
|
209
|
}
|
210
|
assertNotNull(rank);
|
211
|
assertFalse("Rank are equal, level must not be higher", rank.isHigher(acherontiaLachesis.getRank()));
|
212
|
assertFalse("Rank are equal, level must not be lower", rank.isLower(acherontiaLachesis.getRank()));
|
213
|
}
|
214
|
|
215
|
@Test
|
216
|
public void testDeleteTaxon(){
|
217
|
TaxonNameBase acherontiaLachesis = taxonNameDao.findByUuid(UUID.fromString("497a9955-5c5a-4f2b-b08c-2135d336d633"));
|
218
|
HibernateProxyHelper.deproxy(acherontiaLachesis, TaxonNameBase.class);
|
219
|
Set<TaxonBase> taxonBases = acherontiaLachesis.getTaxonBases();
|
220
|
HomotypicalGroup group = acherontiaLachesis.getHomotypicalGroup();
|
221
|
UUID groupUuid = group.getUuid();
|
222
|
taxonNameDao.delete(acherontiaLachesis);
|
223
|
|
224
|
Iterator<TaxonBase> taxa= taxonBases.iterator();
|
225
|
TaxonBase taxon = taxa.next();
|
226
|
UUID taxonUuid = taxon.getUuid();
|
227
|
|
228
|
//int numbOfTaxa = taxonDao.count(TaxonBase.class);
|
229
|
List<TaxonBase> taxaList = taxonDao.getAllTaxonBases(100, 0);
|
230
|
|
231
|
acherontiaLachesis = taxonNameDao.findByUuid(UUID.fromString("497a9955-5c5a-4f2b-b08c-2135d336d633"));
|
232
|
taxon = taxonDao.findByUuid(taxonUuid);
|
233
|
group = homotypicalGroupDao.findByUuid(groupUuid);
|
234
|
group = HibernateProxyHelper.deproxy(group, HomotypicalGroup.class);
|
235
|
assertNull("There should be no taxonName with the deleted uuid", acherontiaLachesis);
|
236
|
assertNull("There should be no taxon with the deleted uuid", taxon);
|
237
|
assertNull("There should be no homotypicalGroup with the deleted uuid", group);
|
238
|
|
239
|
}
|
240
|
|
241
|
/* (non-Javadoc)
|
242
|
* @see eu.etaxonomy.cdm.test.integration.CdmIntegrationTest#createTestData()
|
243
|
*/
|
244
|
@Override
|
245
|
public void createTestDataSet() throws FileNotFoundException {
|
246
|
// TODO Auto-generated method stub
|
247
|
|
248
|
}
|
249
|
}
|