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.model.taxon;
|
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.assertSame;
|
16
|
import static org.junit.Assert.assertTrue;
|
17
|
|
18
|
import java.util.Set;
|
19
|
|
20
|
import org.apache.log4j.Logger;
|
21
|
import org.junit.Assert;
|
22
|
import org.junit.Before;
|
23
|
import org.junit.BeforeClass;
|
24
|
import org.junit.Test;
|
25
|
import org.springframework.beans.BeanUtils;
|
26
|
|
27
|
import eu.etaxonomy.cdm.model.agent.Person;
|
28
|
import eu.etaxonomy.cdm.model.common.DefaultTermInitializer;
|
29
|
import eu.etaxonomy.cdm.model.description.TaxonDescription;
|
30
|
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
|
31
|
import eu.etaxonomy.cdm.model.name.IBotanicalName;
|
32
|
import eu.etaxonomy.cdm.model.name.IZoologicalName;
|
33
|
import eu.etaxonomy.cdm.model.name.Rank;
|
34
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
35
|
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
|
36
|
//import eu.etaxonomy.cdm.model.reference.Book;
|
37
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
38
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
39
|
import eu.etaxonomy.cdm.test.unit.EntityTestBase;
|
40
|
|
41
|
public class TaxonTest extends EntityTestBase {
|
42
|
@SuppressWarnings("unused")
|
43
|
private static final Logger logger = Logger.getLogger(TaxonTest.class);
|
44
|
|
45
|
private Reference sec;
|
46
|
private Reference misSec;
|
47
|
private IZoologicalName name1;
|
48
|
private IBotanicalName name2;
|
49
|
private Taxon rootT;
|
50
|
private Taxon child1;
|
51
|
private Taxon child2;
|
52
|
private Synonym syn1;
|
53
|
private Synonym syn2;
|
54
|
private IBotanicalName name3;
|
55
|
private IBotanicalName name4;
|
56
|
private Taxon freeT;
|
57
|
private Taxon misTaxon1;
|
58
|
private Taxon misTaxon2;
|
59
|
|
60
|
@BeforeClass
|
61
|
public static void setUpBeforeClass() {
|
62
|
DefaultTermInitializer vocabularyStore = new DefaultTermInitializer();
|
63
|
vocabularyStore.initialize();
|
64
|
}
|
65
|
|
66
|
@Before
|
67
|
public void setUp() throws Exception {
|
68
|
Person linne =new Person("Carl", "Linné", "L.");
|
69
|
sec= ReferenceFactory.newBook();
|
70
|
sec.setAuthorship(linne);
|
71
|
sec.setTitleCache("Schönes saftiges Allgäu", true);
|
72
|
misSec = ReferenceFactory.newBook();
|
73
|
misSec.setTitleCache("Stupid book", true);
|
74
|
|
75
|
name1 = TaxonNameFactory.NewZoologicalInstance(Rank.SPECIES(),"Panthera",null,"onca",null,linne,null,"p.1467", null);
|
76
|
name2 = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES(),"Abies",null,"alba",null,linne,null,"p.317", null);
|
77
|
name3 = TaxonNameFactory.NewBotanicalInstance(Rank.SUBSPECIES(),"Polygala",null,"vulgaris","alpina",linne,null,"p.191", null);
|
78
|
name4 = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES(),"Cichoria",null,"carminata",null,linne,null,"p.14", null);
|
79
|
rootT = Taxon.NewInstance(name1,sec);
|
80
|
freeT = Taxon.NewInstance(name4,sec);
|
81
|
// taxonomic children
|
82
|
child1 = Taxon.NewInstance(name2,sec);
|
83
|
child2 = Taxon.NewInstance(name3,sec);
|
84
|
|
85
|
// Classification newTree = Classification.NewInstance("testTree");
|
86
|
// newTree.addParentChild(rootT, child1, sec, "p.998");
|
87
|
// newTree.addParentChild(rootT, child2, sec, "p.987");
|
88
|
|
89
|
// synonymy
|
90
|
syn1=Synonym.NewInstance(name1,sec);
|
91
|
syn2=Synonym.NewInstance(name2,sec);
|
92
|
child1.addSynonym(syn1, SynonymType.HETEROTYPIC_SYNONYM_OF());
|
93
|
child2.addSynonym(syn2, SynonymType.HOMOTYPIC_SYNONYM_OF());
|
94
|
//misaplication
|
95
|
misTaxon1 = Taxon.NewInstance(name4, misSec);
|
96
|
misTaxon2 = Taxon.NewInstance(name4, misSec);
|
97
|
rootT.addMisappliedName(misTaxon1, null, "99");
|
98
|
child1.addMisappliedName(misTaxon2, null, "44");
|
99
|
}
|
100
|
|
101
|
@Test
|
102
|
public void testGenerateTitle() {
|
103
|
assertTrue(rootT.generateTitle().startsWith(rootT.getName().getTitleCache()));
|
104
|
}
|
105
|
|
106
|
@Test
|
107
|
public void testIsMisappliedName() {
|
108
|
assertFalse(child2.isMisapplication());
|
109
|
assertFalse(rootT.isMisapplication());
|
110
|
assertTrue(misTaxon1.isMisapplication());
|
111
|
assertTrue(misTaxon2.isMisapplication());
|
112
|
}
|
113
|
|
114
|
@Test
|
115
|
public void testGetSynonyms() {
|
116
|
assertTrue(child1.getSynonyms().contains(syn1));
|
117
|
assertTrue(child2.getSynonyms().contains(syn2));
|
118
|
assertTrue(rootT.getSynonyms().isEmpty());
|
119
|
}
|
120
|
|
121
|
@Test
|
122
|
public void testGetSynonymNames() {
|
123
|
assertTrue(child1.getSynonymNames().contains(name1));
|
124
|
assertTrue(child2.getSynonymNames().contains(name2));
|
125
|
assertTrue(rootT.getSynonymNames().isEmpty());
|
126
|
}
|
127
|
|
128
|
@Test
|
129
|
public void testAddSynonym() {
|
130
|
freeT.addSynonym(syn1, SynonymType.HETEROTYPIC_SYNONYM_OF());
|
131
|
assertTrue(freeT.getSynonyms().contains(syn1));
|
132
|
assertTrue(syn1.getAcceptedTaxon().equals(freeT));
|
133
|
assertFalse(freeT.getSynonyms().contains(syn2));
|
134
|
}
|
135
|
|
136
|
@Test
|
137
|
public void testAddAndRemoveDescriptionTaxonDescription() {
|
138
|
TaxonDescription desc = TaxonDescription.NewInstance();
|
139
|
rootT.addDescription(desc); //test if reflection method in addDescription() works
|
140
|
assertTrue("The description has not properly been added to the taxon", rootT.getDescriptions().contains(desc));
|
141
|
assertEquals("The taxon has not properly been added to the description", rootT, desc.getTaxon());
|
142
|
rootT.removeDescription(desc); //test if reflection method in removeDescription() works
|
143
|
assertFalse("The description has not properly been removed from the taxon", rootT.getDescriptions().contains(desc));
|
144
|
assertEquals("The taxon has not properly been removed from the description", null, desc.getTaxon());
|
145
|
}
|
146
|
|
147
|
/**
|
148
|
* Test method for {@link eu.etaxonomy.cdm.model.taxon.Taxon#getTaxonRelations()}.
|
149
|
*/
|
150
|
@Test
|
151
|
public void testGetTaxonRelations() {
|
152
|
Taxon taxon = Taxon.NewInstance(null, null);
|
153
|
taxon.addTaxonRelation(Taxon.NewInstance(null, null), TaxonRelationshipType.CONTRADICTION(), null, null);
|
154
|
Set<TaxonRelationship> relationships = taxon.getTaxonRelations();
|
155
|
assertTrue("There should be exactly one relationship", relationships.size() == 1);
|
156
|
}
|
157
|
|
158
|
/**
|
159
|
* Test method for {@link eu.etaxonomy.cdm.model.taxon.Taxon#removeTaxonRelation(eu.etaxonomy.cdm.model.taxon.TaxonRelationship)}.
|
160
|
*/
|
161
|
@Test
|
162
|
public void testRemoveTaxonRelation() {
|
163
|
Taxon taxon = Taxon.NewInstance(null, null);
|
164
|
taxon.addTaxonRelation(Taxon.NewInstance(null, null), TaxonRelationshipType.CONTRADICTION(), null, null);
|
165
|
assertTrue("There should be exactly one taxon relationship", taxon.getTaxonRelations().size() == 1);
|
166
|
TaxonRelationship relationship = (TaxonRelationship) taxon.getTaxonRelations().toArray()[0];
|
167
|
assertNotNull("Relationship should not be null", relationship);
|
168
|
taxon.removeTaxonRelation(relationship);
|
169
|
assertTrue("There should be no taxon relationships", taxon.getTaxonRelations().size() == 0);
|
170
|
}
|
171
|
|
172
|
/**
|
173
|
* Test method for {@link eu.etaxonomy.cdm.model.taxon.Taxon#addTaxonRelation(eu.etaxonomy.cdm.model.taxon.TaxonRelationship)}.
|
174
|
*/
|
175
|
@Test
|
176
|
public void testAddTaxonRelationTaxonRelationship() {
|
177
|
Taxon taxon = Taxon.NewInstance(null, null);
|
178
|
taxon.addTaxonRelation(Taxon.NewInstance(null, null), TaxonRelationshipType.CONTRADICTION(), null, null);
|
179
|
assertTrue("There should be exactly one taxon relationship", taxon.getTaxonRelations().size() == 1);
|
180
|
TaxonRelationship relationship = (TaxonRelationship) taxon.getTaxonRelations().toArray()[0];
|
181
|
assertNotNull("Relationship should not be null", relationship);
|
182
|
taxon.removeTaxonRelation(relationship);
|
183
|
assertTrue("There should be no taxon relationships", taxon.getTaxonRelations().size() == 0);
|
184
|
taxon.addTaxonRelation(relationship);
|
185
|
assertEquals("There should be exactly one taxon relationships", 1, taxon.getTaxonRelations().size());
|
186
|
}
|
187
|
|
188
|
@Test
|
189
|
public void testAddHomotypicSynonymName(){
|
190
|
TaxonName taxonName = TaxonNameFactory.NewBotanicalInstance(null);
|
191
|
Taxon taxon = Taxon.NewInstance(taxonName, null);
|
192
|
TaxonName synonymName1 = TaxonNameFactory.NewBotanicalInstance(null);
|
193
|
// add a synonym to the taxon
|
194
|
Synonym synonym1 = taxon.addHomotypicSynonymName(synonymName1);
|
195
|
// get the homotypic group of that synonym
|
196
|
HomotypicalGroup homotypicGroupOfSynonym = synonym1.getHomotypicGroup();
|
197
|
// everything is fine
|
198
|
Assert.assertEquals("We should have two names in the homotypic group",
|
199
|
2, homotypicGroupOfSynonym.getTypifiedNames().size());
|
200
|
}
|
201
|
@Test
|
202
|
public void testAddHomotypicSynonym(){
|
203
|
TaxonName taxonName = TaxonNameFactory.NewBotanicalInstance(null);
|
204
|
Taxon taxon = Taxon.NewInstance(taxonName, null);
|
205
|
TaxonName synonymName1 = TaxonNameFactory.NewBotanicalInstance(null);
|
206
|
Synonym synonym = Synonym.NewInstance(synonymName1, null);
|
207
|
// add a synonym to the taxon
|
208
|
taxon.addHomotypicSynonym(synonym);
|
209
|
//synonym type must be homotypic
|
210
|
Assert.assertEquals("Synonym must be homotypic", SynonymType.HOMOTYPIC_SYNONYM_OF(), synonym.getType());
|
211
|
// get the homotypic group of that synonym
|
212
|
HomotypicalGroup homotypicGroupOfSynonym = synonym.getHomotypicGroup();
|
213
|
// everything is fine
|
214
|
Assert.assertEquals("We should have two names in the homotypic group",
|
215
|
2, homotypicGroupOfSynonym.getTypifiedNames().size());
|
216
|
}
|
217
|
|
218
|
@Test
|
219
|
public void testAddRemoveSynonymInSameGroup(){
|
220
|
TaxonName taxonName = TaxonNameFactory.NewBotanicalInstance(null);
|
221
|
Taxon taxon = Taxon.NewInstance(taxonName, null);
|
222
|
TaxonName synonymName1 = TaxonNameFactory.NewBotanicalInstance(null);
|
223
|
TaxonName synonymName2 = TaxonNameFactory.NewBotanicalInstance(null);
|
224
|
|
225
|
// add a synonym to the taxon
|
226
|
Synonym synonym1 = taxon.addHeterotypicSynonymName(synonymName1);
|
227
|
// get the homotypic group of that synonym
|
228
|
HomotypicalGroup homotypicGroupOfSynonym = synonym1.getHomotypicGroup();
|
229
|
// add another synonym into the homotypic group we just created
|
230
|
Synonym synonym2 = taxon.addHeterotypicSynonymName(synonymName2, null, null, homotypicGroupOfSynonym);
|
231
|
// everything is fine
|
232
|
Assert.assertEquals("We should have two synonyms in the group", 2, taxon.getSynonymsInGroup(homotypicGroupOfSynonym).size());
|
233
|
|
234
|
// removing the synonym from the taxon
|
235
|
taxon.removeSynonym(synonym2);
|
236
|
|
237
|
// get the homotypical group via the methods in Taxon
|
238
|
HomotypicalGroup homotypicGroupViaTaxon = taxon.getHeterotypicSynonymyGroups().iterator().next();
|
239
|
|
240
|
// the group is for sure the same as the synonyms one
|
241
|
Assert.assertSame("Accessing the homotypic group via the taxon methods should result in the same object",
|
242
|
homotypicGroupOfSynonym, homotypicGroupViaTaxon);
|
243
|
|
244
|
// although it might be correct that the synonym is not deleted from the taxonomic group
|
245
|
// we would not expect it to be here, since we just deleted it from the taxon and are accessing synonyms
|
246
|
// via methods in Taxon
|
247
|
Assert.assertEquals("When accessing the homotypic groups via taxon we would not expect the synonym we just deleted",
|
248
|
1, taxon.getSynonymsInGroup(homotypicGroupViaTaxon).size());
|
249
|
}
|
250
|
|
251
|
|
252
|
@Test
|
253
|
public void testClone(){
|
254
|
Taxon clone = (Taxon)child2.clone();
|
255
|
assertNotNull(clone);
|
256
|
assertEquals(0,clone.getTaxonNodes().size());
|
257
|
assertSame(clone.getName(), child2.getName());
|
258
|
}
|
259
|
|
260
|
@Test
|
261
|
public void beanTests(){
|
262
|
// #5307 Test that BeanUtils does not fail
|
263
|
BeanUtils.getPropertyDescriptors(Taxon.class);
|
264
|
BeanUtils.getPropertyDescriptors(Synonym.class);
|
265
|
}
|
266
|
|
267
|
}
|