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.assertNotNull;
|
14
|
import static org.junit.Assert.assertNull;
|
15
|
import static org.junit.Assert.assertSame;
|
16
|
import static org.junit.Assert.assertTrue;
|
17
|
|
18
|
import org.apache.log4j.Logger;
|
19
|
import org.junit.After;
|
20
|
import org.junit.Before;
|
21
|
import org.junit.BeforeClass;
|
22
|
import org.junit.Test;
|
23
|
|
24
|
import eu.etaxonomy.cdm.model.common.DefaultTermInitializer;
|
25
|
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
|
26
|
import eu.etaxonomy.cdm.model.name.IBotanicalName;
|
27
|
import eu.etaxonomy.cdm.model.name.IZoologicalName;
|
28
|
import eu.etaxonomy.cdm.model.name.Rank;
|
29
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
30
|
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
|
31
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
32
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
33
|
import eu.etaxonomy.cdm.test.unit.EntityTestBase;
|
34
|
|
35
|
/**
|
36
|
* @author a.mueller
|
37
|
*
|
38
|
*/
|
39
|
public class TaxonBaseTest extends EntityTestBase {
|
40
|
@SuppressWarnings("unused")
|
41
|
private static final Logger logger = Logger.getLogger(TaxonBaseTest.class);
|
42
|
|
43
|
private Reference sec;
|
44
|
private IZoologicalName name1;
|
45
|
private IBotanicalName name2;
|
46
|
private Taxon rootT;
|
47
|
private Taxon taxon1;
|
48
|
private Synonym synonym1;
|
49
|
private Taxon freeT;
|
50
|
|
51
|
@BeforeClass
|
52
|
public static void setUpBeforeClass() {
|
53
|
DefaultTermInitializer vocabularyStore = new DefaultTermInitializer();
|
54
|
vocabularyStore.initialize();
|
55
|
}
|
56
|
|
57
|
/**
|
58
|
* @throws java.lang.Exception
|
59
|
*/
|
60
|
@Before
|
61
|
public void setUp() throws Exception {
|
62
|
sec= ReferenceFactory.newBook();
|
63
|
sec.setTitleCache("Schoenes saftiges Allg�u", true);
|
64
|
name1 = TaxonNameFactory.NewZoologicalInstance(Rank.SPECIES(),"Panthera",null,"onca",null,null,null,"p.1467", null);
|
65
|
HomotypicalGroup homotypicalGroup = HomotypicalGroup.NewInstance();
|
66
|
name2 = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES(),"Abies",null,"alba",null,null,null,"p.317", homotypicalGroup);
|
67
|
// taxa
|
68
|
taxon1 = Taxon.NewInstance(name1,sec);
|
69
|
synonym1 = Synonym.NewInstance(name2,sec);
|
70
|
freeT = Taxon.NewInstance(null, null);
|
71
|
}
|
72
|
|
73
|
/**
|
74
|
* @throws java.lang.Exception
|
75
|
*/
|
76
|
@After
|
77
|
public void tearDown() throws Exception {
|
78
|
}
|
79
|
|
80
|
/**************** TESTS **************************************/
|
81
|
|
82
|
/**
|
83
|
* Test method for {@link eu.etaxonomy.cdm.model.taxon.TaxonBase#getName()}.
|
84
|
*/
|
85
|
@Test
|
86
|
public final void testGetName() {
|
87
|
assertEquals(name1.getTitleCache(), taxon1.getName().getTitleCache());
|
88
|
assertNull(freeT.getName());
|
89
|
}
|
90
|
//
|
91
|
// /**
|
92
|
// * Test method for {@link eu.etaxonomy.cdm.model.taxon.TaxonBase#setName(eu.etaxonomy.cdm.model.name.TaxonName)}.
|
93
|
// */
|
94
|
// @Test
|
95
|
// public final void testSetName() {
|
96
|
// assertNull(freeT.getName());
|
97
|
// freeT.setName(name2);
|
98
|
// assertNotNull(freeT.getName());
|
99
|
// assertSame(freeT.getName(), name2);
|
100
|
// assertTrue(name1.getTaxa().contains(taxon1));
|
101
|
// assertTrue(name2.getSynonyms().contains(synonym1));
|
102
|
// }
|
103
|
|
104
|
/**
|
105
|
* Test method for {@link eu.etaxonomy.cdm.model.taxon.TaxonBase#isDoubtful()}.
|
106
|
*/
|
107
|
@Test
|
108
|
public final void testIsDoubtful() {
|
109
|
boolean oldValue;
|
110
|
oldValue = taxon1.isDoubtful();
|
111
|
taxon1.setDoubtful(!oldValue);
|
112
|
assertEquals(! oldValue, taxon1.isDoubtful());
|
113
|
taxon1.setDoubtful(oldValue);
|
114
|
assertEquals( oldValue, taxon1.isDoubtful());
|
115
|
}
|
116
|
|
117
|
/**
|
118
|
* Test method for {@link eu.etaxonomy.cdm.model.taxon.TaxonBase#setDoubtful(boolean)}.
|
119
|
*/
|
120
|
@Test
|
121
|
public final void testSetDoubtful() {
|
122
|
//covered by testIsDoubtful
|
123
|
}
|
124
|
|
125
|
/**
|
126
|
* Test method for {@link eu.etaxonomy.cdm.model.taxon.TaxonBase#getSec()}.
|
127
|
*/
|
128
|
@Test
|
129
|
public final void testGetSec() {
|
130
|
assertEquals(sec.getTitleCache(), taxon1.getSec().getTitleCache());
|
131
|
assertNull(freeT.getSec());
|
132
|
}
|
133
|
|
134
|
/**
|
135
|
* Test method for {@link eu.etaxonomy.cdm.model.taxon.TaxonBase#setSec(eu.etaxonomy.cdm.model.reference.Reference)}.
|
136
|
*/
|
137
|
@Test
|
138
|
public final void testSetSec() {
|
139
|
assertNull(freeT.getSec());
|
140
|
freeT.setSec(sec);
|
141
|
assertNotNull(freeT.getSec());
|
142
|
assertSame(freeT.getSec(), sec);
|
143
|
}
|
144
|
|
145
|
@Test
|
146
|
|
147
|
public final void testClone(){
|
148
|
|
149
|
TaxonName test = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
150
|
String genus = "test";
|
151
|
String infraGenericEpithet = "test";
|
152
|
test.setGenusOrUninomial(genus);
|
153
|
test.setInfraGenericEpithet(infraGenericEpithet);
|
154
|
Reference secRef = ReferenceFactory.newArticle();
|
155
|
secRef.setTitle("Test ...");
|
156
|
freeT.setSec(secRef);
|
157
|
freeT.setName(test);
|
158
|
Taxon clone = (Taxon)freeT.clone();
|
159
|
assertSame(freeT.getSec(), clone.getSec());
|
160
|
assertSame(freeT.getName(), clone.getName());
|
161
|
}
|
162
|
|
163
|
/*
|
164
|
* Moved from IdentifiableEntityTest to here due to #922
|
165
|
*/
|
166
|
@Test
|
167
|
public void testCompareTo() {
|
168
|
|
169
|
TaxonName abies = TaxonNameFactory.NewNonViralInstance(Rank.GENUS(), null);
|
170
|
abies.setNameCache("Abies");
|
171
|
abies.setTitleCache("Abies", true);
|
172
|
Reference sec = ReferenceFactory.newArticle();
|
173
|
sec.setTitle("Abies alba Ref");
|
174
|
|
175
|
Taxon abiesTaxon = Taxon.NewInstance(abies, sec);
|
176
|
|
177
|
TaxonName abiesMill = TaxonNameFactory.NewNonViralInstance(Rank.GENUS(), null);
|
178
|
abiesMill.setNameCache("Abies");
|
179
|
abiesMill.setTitleCache("Abies Mill.", true);
|
180
|
Taxon abiesMillTaxon = Taxon.NewInstance(abiesMill, sec);
|
181
|
|
182
|
int result = 0;
|
183
|
|
184
|
// "Abies" < "Abies Mill."
|
185
|
result = abies.compareToName(abiesMill);
|
186
|
assertTrue(result < 0);
|
187
|
|
188
|
abiesTaxon = abies.getTaxa().iterator().next();
|
189
|
|
190
|
assertTrue(abiesTaxon.compareToTaxon(abiesTaxon) == 0);
|
191
|
|
192
|
assertTrue(abiesMillTaxon.compareToTaxon(abiesTaxon) > 0);
|
193
|
|
194
|
assertTrue(abiesTaxon.compareToTaxon(abiesMillTaxon) < 0);
|
195
|
|
196
|
|
197
|
}
|
198
|
}
|