1 |
c31bb763
|
Andreas Müller
|
/**
|
2 |
|
|
* Copyright (C) 2007 EDIT
|
3 |
70ba3ccf
|
Andreas Müller
|
* European Distributed Institute of Taxonomy
|
4 |
c31bb763
|
Andreas Müller
|
* http://www.e-taxonomy.eu
|
5 |
70ba3ccf
|
Andreas Müller
|
*
|
6 |
c31bb763
|
Andreas Müller
|
* 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 |
70ba3ccf
|
Andreas Müller
|
|
10 |
9479da48
|
Andreas Müller
|
package eu.etaxonomy.cdm.model.taxon;
|
11 |
|
|
|
12 |
ece46ca8
|
Andreas Kohlbecker
|
import static org.junit.Assert.assertEquals;
|
13 |
|
|
import static org.junit.Assert.assertFalse;
|
14 |
|
|
import static org.junit.Assert.assertNotNull;
|
15 |
58b9953c
|
Katja Luther
|
import static org.junit.Assert.assertSame;
|
16 |
ece46ca8
|
Andreas Kohlbecker
|
import static org.junit.Assert.assertTrue;
|
17 |
70ba3ccf
|
Andreas Müller
|
|
18 |
9479da48
|
Andreas Müller
|
import java.util.Set;
|
19 |
|
|
|
20 |
82165148
|
Andreas Müller
|
import org.apache.log4j.Logger;
|
21 |
3c0b88b2
|
Andreas Müller
|
import org.junit.Assert;
|
22 |
9479da48
|
Andreas Müller
|
import org.junit.Before;
|
23 |
f6765014
|
ben.clark
|
import org.junit.BeforeClass;
|
24 |
9479da48
|
Andreas Müller
|
import org.junit.Test;
|
25 |
70ba3ccf
|
Andreas Müller
|
import org.springframework.beans.BeanUtils;
|
26 |
9479da48
|
Andreas Müller
|
|
27 |
|
|
import eu.etaxonomy.cdm.model.agent.Person;
|
28 |
f6765014
|
ben.clark
|
import eu.etaxonomy.cdm.model.common.DefaultTermInitializer;
|
29 |
35c9c0ba
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.description.TaxonDescription;
|
30 |
a57618a4
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
|
31 |
e6d7b501
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.name.IBotanicalName;
|
32 |
d7919b1c
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.name.IZoologicalName;
|
33 |
9479da48
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.name.Rank;
|
34 |
9dc896c9
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
35 |
033fa0b2
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
|
36 |
45528416
|
Katja Luther
|
//import eu.etaxonomy.cdm.model.reference.Book;
|
37 |
1d36aa54
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
38 |
45528416
|
Katja Luther
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
39 |
3fd06fea
|
Andreas Müller
|
import eu.etaxonomy.cdm.test.unit.EntityTestBase;
|
40 |
9479da48
|
Andreas Müller
|
|
41 |
3fd06fea
|
Andreas Müller
|
public class TaxonTest extends EntityTestBase {
|
42 |
e5605065
|
Andreas Müller
|
@SuppressWarnings("unused")
|
43 |
|
|
private static final Logger logger = Logger.getLogger(TaxonTest.class);
|
44 |
70ba3ccf
|
Andreas Müller
|
|
45 |
90046bc4
|
Andreas Müller
|
private Reference sec;
|
46 |
|
|
private Reference misSec;
|
47 |
d7919b1c
|
Andreas Müller
|
private IZoologicalName name1;
|
48 |
e6d7b501
|
Andreas Müller
|
private IBotanicalName name2;
|
49 |
9479da48
|
Andreas Müller
|
private Taxon rootT;
|
50 |
|
|
private Taxon child1;
|
51 |
|
|
private Taxon child2;
|
52 |
|
|
private Synonym syn1;
|
53 |
|
|
private Synonym syn2;
|
54 |
e6d7b501
|
Andreas Müller
|
private IBotanicalName name3;
|
55 |
|
|
private IBotanicalName name4;
|
56 |
9479da48
|
Andreas Müller
|
private Taxon freeT;
|
57 |
2b3f61c4
|
Andreas Müller
|
private Taxon misTaxon1;
|
58 |
|
|
private Taxon misTaxon2;
|
59 |
70ba3ccf
|
Andreas Müller
|
|
60 |
f6765014
|
ben.clark
|
@BeforeClass
|
61 |
|
|
public static void setUpBeforeClass() {
|
62 |
|
|
DefaultTermInitializer vocabularyStore = new DefaultTermInitializer();
|
63 |
|
|
vocabularyStore.initialize();
|
64 |
|
|
}
|
65 |
70ba3ccf
|
Andreas Müller
|
|
66 |
9479da48
|
Andreas Müller
|
@Before
|
67 |
f6765014
|
ben.clark
|
public void setUp() throws Exception {
|
68 |
9479da48
|
Andreas Müller
|
Person linne =new Person("Carl", "Linné", "L.");
|
69 |
30881276
|
Andreas Müller
|
sec= ReferenceFactory.newBook();
|
70 |
f89911d1
|
Andreas Müller
|
sec.setAuthorship(linne);
|
71 |
892efc69
|
Andreas Kohlbecker
|
sec.setTitleCache("Schönes saftiges Allgäu", true);
|
72 |
30881276
|
Andreas Müller
|
misSec = ReferenceFactory.newBook();
|
73 |
892efc69
|
Andreas Kohlbecker
|
misSec.setTitleCache("Stupid book", true);
|
74 |
70ba3ccf
|
Andreas Müller
|
|
75 |
033fa0b2
|
Andreas Müller
|
name1 = TaxonNameFactory.NewZoologicalInstance(Rank.SPECIES(),"Panthera",null,"onca",null,linne,null,"p.1467", null);
|
76 |
fe34a9eb
|
Andreas Müller
|
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 |
b18c6379
|
Andreas Müller
|
rootT = Taxon.NewInstance(name1,sec);
|
80 |
|
|
freeT = Taxon.NewInstance(name4,sec);
|
81 |
9479da48
|
Andreas Müller
|
// taxonomic children
|
82 |
b18c6379
|
Andreas Müller
|
child1 = Taxon.NewInstance(name2,sec);
|
83 |
|
|
child2 = Taxon.NewInstance(name3,sec);
|
84 |
70ba3ccf
|
Andreas Müller
|
|
85 |
a5d07df0
|
Andreas Müller
|
// Classification newTree = Classification.NewInstance("testTree");
|
86 |
|
|
// newTree.addParentChild(rootT, child1, sec, "p.998");
|
87 |
|
|
// newTree.addParentChild(rootT, child2, sec, "p.987");
|
88 |
70ba3ccf
|
Andreas Müller
|
|
89 |
9479da48
|
Andreas Müller
|
// synonymy
|
90 |
|
|
syn1=Synonym.NewInstance(name1,sec);
|
91 |
|
|
syn2=Synonym.NewInstance(name2,sec);
|
92 |
fbeefcaf
|
Andreas Müller
|
child1.addSynonym(syn1, SynonymType.HETEROTYPIC_SYNONYM_OF());
|
93 |
|
|
child2.addSynonym(syn2, SynonymType.HOMOTYPIC_SYNONYM_OF());
|
94 |
2b3f61c4
|
Andreas Müller
|
//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 |
9479da48
|
Andreas Müller
|
}
|
100 |
|
|
|
101 |
|
|
@Test
|
102 |
|
|
public void testGenerateTitle() {
|
103 |
a400a105
|
m.doering
|
assertTrue(rootT.generateTitle().startsWith(rootT.getName().getTitleCache()));
|
104 |
9479da48
|
Andreas Müller
|
}
|
105 |
|
|
|
106 |
2b3f61c4
|
Andreas Müller
|
@Test
|
107 |
|
|
public void testIsMisappliedName() {
|
108 |
30881276
|
Andreas Müller
|
assertFalse(child2.isMisapplication());
|
109 |
|
|
assertFalse(rootT.isMisapplication());
|
110 |
|
|
assertTrue(misTaxon1.isMisapplication());
|
111 |
|
|
assertTrue(misTaxon2.isMisapplication());
|
112 |
2b3f61c4
|
Andreas Müller
|
}
|
113 |
70ba3ccf
|
Andreas Müller
|
|
114 |
9479da48
|
Andreas Müller
|
@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 |
fbeefcaf
|
Andreas Müller
|
freeT.addSynonym(syn1, SynonymType.HETEROTYPIC_SYNONYM_OF());
|
131 |
9479da48
|
Andreas Müller
|
assertTrue(freeT.getSynonyms().contains(syn1));
|
132 |
f476ff86
|
Andreas Müller
|
assertTrue(syn1.getAcceptedTaxon().equals(freeT));
|
133 |
9479da48
|
Andreas Müller
|
assertFalse(freeT.getSynonyms().contains(syn2));
|
134 |
|
|
}
|
135 |
70ba3ccf
|
Andreas Müller
|
|
136 |
35c9c0ba
|
Andreas Müller
|
@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 |
82165148
|
Andreas Müller
|
|
147 |
|
|
/**
|
148 |
|
|
* Test method for {@link eu.etaxonomy.cdm.model.taxon.Taxon#getTaxonRelations()}.
|
149 |
|
|
*/
|
150 |
|
|
@Test
|
151 |
|
|
public void testGetTaxonRelations() {
|
152 |
ece46ca8
|
Andreas Kohlbecker
|
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 |
82165148
|
Andreas Müller
|
}
|
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 |
ece46ca8
|
Andreas Kohlbecker
|
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 |
82165148
|
Andreas Müller
|
}
|
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 |
ece46ca8
|
Andreas Kohlbecker
|
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 |
6837d5b7
|
Andreas Kohlbecker
|
assertEquals("There should be exactly one taxon relationships", 1, taxon.getTaxonRelations().size());
|
186 |
82165148
|
Andreas Müller
|
}
|
187 |
|
|
|
188 |
f476ff86
|
Andreas Müller
|
@Test
|
189 |
|
|
public void testAddHomotypicSynonymName(){
|
190 |
9dc896c9
|
Andreas Müller
|
TaxonName taxonName = TaxonNameFactory.NewBotanicalInstance(null);
|
191 |
f476ff86
|
Andreas Müller
|
Taxon taxon = Taxon.NewInstance(taxonName, null);
|
192 |
9dc896c9
|
Andreas Müller
|
TaxonName synonymName1 = TaxonNameFactory.NewBotanicalInstance(null);
|
193 |
f476ff86
|
Andreas Müller
|
// 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 |
9dc896c9
|
Andreas Müller
|
TaxonName taxonName = TaxonNameFactory.NewBotanicalInstance(null);
|
204 |
f476ff86
|
Andreas Müller
|
Taxon taxon = Taxon.NewInstance(taxonName, null);
|
205 |
9dc896c9
|
Andreas Müller
|
TaxonName synonymName1 = TaxonNameFactory.NewBotanicalInstance(null);
|
206 |
f476ff86
|
Andreas Müller
|
Synonym synonym = Synonym.NewInstance(synonymName1, null);
|
207 |
|
|
// add a synonym to the taxon
|
208 |
|
|
taxon.addHomotypicSynonym(synonym);
|
209 |
|
|
//synonym type must be homotypic
|
210 |
fbeefcaf
|
Andreas Müller
|
Assert.assertEquals("Synonym must be homotypic", SynonymType.HOMOTYPIC_SYNONYM_OF(), synonym.getType());
|
211 |
f476ff86
|
Andreas Müller
|
// 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 |
a57618a4
|
Andreas Müller
|
@Test
|
219 |
|
|
public void testAddRemoveSynonymInSameGroup(){
|
220 |
9dc896c9
|
Andreas Müller
|
TaxonName taxonName = TaxonNameFactory.NewBotanicalInstance(null);
|
221 |
a57618a4
|
Andreas Müller
|
Taxon taxon = Taxon.NewInstance(taxonName, null);
|
222 |
9dc896c9
|
Andreas Müller
|
TaxonName synonymName1 = TaxonNameFactory.NewBotanicalInstance(null);
|
223 |
|
|
TaxonName synonymName2 = TaxonNameFactory.NewBotanicalInstance(null);
|
224 |
70ba3ccf
|
Andreas Müller
|
|
225 |
a57618a4
|
Andreas Müller
|
// add a synonym to the taxon
|
226 |
f476ff86
|
Andreas Müller
|
Synonym synonym1 = taxon.addHeterotypicSynonymName(synonymName1);
|
227 |
a57618a4
|
Andreas Müller
|
// get the homotypic group of that synonym
|
228 |
|
|
HomotypicalGroup homotypicGroupOfSynonym = synonym1.getHomotypicGroup();
|
229 |
|
|
// add another synonym into the homotypic group we just created
|
230 |
f476ff86
|
Andreas Müller
|
Synonym synonym2 = taxon.addHeterotypicSynonymName(synonymName2, null, null, homotypicGroupOfSynonym);
|
231 |
a57618a4
|
Andreas Müller
|
// everything is fine
|
232 |
f97ff6bc
|
Andreas Müller
|
Assert.assertEquals("We should have two synonyms in the group", 2, taxon.getSynonymsInGroup(homotypicGroupOfSynonym).size());
|
233 |
70ba3ccf
|
Andreas Müller
|
|
234 |
a57618a4
|
Andreas Müller
|
// removing the synonym from the taxon
|
235 |
|
|
taxon.removeSynonym(synonym2);
|
236 |
70ba3ccf
|
Andreas Müller
|
|
237 |
a57618a4
|
Andreas Müller
|
// get the homotypical group via the methods in Taxon
|
238 |
|
|
HomotypicalGroup homotypicGroupViaTaxon = taxon.getHeterotypicSynonymyGroups().iterator().next();
|
239 |
70ba3ccf
|
Andreas Müller
|
|
240 |
a57618a4
|
Andreas Müller
|
// the group is for sure the same as the synonyms one
|
241 |
f476ff86
|
Andreas Müller
|
Assert.assertSame("Accessing the homotypic group via the taxon methods should result in the same object",
|
242 |
|
|
homotypicGroupOfSynonym, homotypicGroupViaTaxon);
|
243 |
70ba3ccf
|
Andreas Müller
|
|
244 |
|
|
// although it might be correct that the synonym is not deleted from the taxonomic group
|
245 |
a57618a4
|
Andreas Müller
|
// 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 |
70ba3ccf
|
Andreas Müller
|
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 |
a57618a4
|
Andreas Müller
|
}
|
250 |
70ba3ccf
|
Andreas Müller
|
|
251 |
|
|
|
252 |
58b9953c
|
Katja Luther
|
@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 |
9479da48
|
Andreas Müller
|
|
260 |
70ba3ccf
|
Andreas Müller
|
@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 |
9479da48
|
Andreas Müller
|
}
|