1 |
b5eda83f
|
Andreas Müller
|
/**
|
2 |
c31bb763
|
Andreas Müller
|
* Copyright (C) 2007 EDIT
|
3 |
90046bc4
|
Andreas Müller
|
* European Distributed Institute of Taxonomy
|
4 |
c31bb763
|
Andreas Müller
|
* http://www.e-taxonomy.eu
|
5 |
90046bc4
|
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 |
90046bc4
|
Andreas Müller
|
|
10 |
b5eda83f
|
Andreas Müller
|
package eu.etaxonomy.cdm.model.taxon;
|
11 |
|
|
|
12 |
1d36aa54
|
Andreas Müller
|
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 |
b5b4a36c
|
Andreas Müller
|
import static org.junit.Assert.assertTrue;
|
17 |
b5eda83f
|
Andreas Müller
|
|
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 |
ee91bcd9
|
ben.clark
|
import eu.etaxonomy.cdm.model.common.DefaultTermInitializer;
|
25 |
b18c6379
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
|
26 |
e6d7b501
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.name.IBotanicalName;
|
27 |
d7919b1c
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.name.IZoologicalName;
|
28 |
b5eda83f
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.name.Rank;
|
29 |
9dc896c9
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
30 |
033fa0b2
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
|
31 |
1d36aa54
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
32 |
45528416
|
Katja Luther
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
33 |
3fd06fea
|
Andreas Müller
|
import eu.etaxonomy.cdm.test.unit.EntityTestBase;
|
34 |
b5eda83f
|
Andreas Müller
|
|
35 |
|
|
/**
|
36 |
|
|
* @author a.mueller
|
37 |
|
|
*
|
38 |
|
|
*/
|
39 |
3fd06fea
|
Andreas Müller
|
public class TaxonBaseTest extends EntityTestBase {
|
40 |
e67d8e36
|
Andreas Müller
|
@SuppressWarnings("unused")
|
41 |
b5eda83f
|
Andreas Müller
|
private static final Logger logger = Logger.getLogger(TaxonBaseTest.class);
|
42 |
90046bc4
|
Andreas Müller
|
|
43 |
|
|
private Reference sec;
|
44 |
d7919b1c
|
Andreas Müller
|
private IZoologicalName name1;
|
45 |
e6d7b501
|
Andreas Müller
|
private IBotanicalName name2;
|
46 |
b5eda83f
|
Andreas Müller
|
private Taxon rootT;
|
47 |
|
|
private Taxon taxon1;
|
48 |
608eada2
|
Andreas Müller
|
private Synonym synonym1;
|
49 |
b5eda83f
|
Andreas Müller
|
private Taxon freeT;
|
50 |
90046bc4
|
Andreas Müller
|
|
51 |
b5eda83f
|
Andreas Müller
|
@BeforeClass
|
52 |
ee91bcd9
|
ben.clark
|
public static void setUpBeforeClass() {
|
53 |
|
|
DefaultTermInitializer vocabularyStore = new DefaultTermInitializer();
|
54 |
|
|
vocabularyStore.initialize();
|
55 |
b5eda83f
|
Andreas Müller
|
}
|
56 |
|
|
|
57 |
|
|
/**
|
58 |
|
|
* @throws java.lang.Exception
|
59 |
|
|
*/
|
60 |
|
|
@Before
|
61 |
|
|
public void setUp() throws Exception {
|
62 |
e67d8e36
|
Andreas Müller
|
sec= ReferenceFactory.newBook();
|
63 |
892efc69
|
Andreas Kohlbecker
|
sec.setTitleCache("Schoenes saftiges Allg�u", true);
|
64 |
033fa0b2
|
Andreas Müller
|
name1 = TaxonNameFactory.NewZoologicalInstance(Rank.SPECIES(),"Panthera",null,"onca",null,null,null,"p.1467", null);
|
65 |
b18c6379
|
Andreas Müller
|
HomotypicalGroup homotypicalGroup = HomotypicalGroup.NewInstance();
|
66 |
fe34a9eb
|
Andreas Müller
|
name2 = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES(),"Abies",null,"alba",null,null,null,"p.317", homotypicalGroup);
|
67 |
b5eda83f
|
Andreas Müller
|
// taxa
|
68 |
b18c6379
|
Andreas Müller
|
taxon1 = Taxon.NewInstance(name1,sec);
|
69 |
|
|
synonym1 = Synonym.NewInstance(name2,sec);
|
70 |
b5eda83f
|
Andreas Müller
|
freeT = Taxon.NewInstance(null, null);
|
71 |
|
|
}
|
72 |
|
|
|
73 |
|
|
/**
|
74 |
|
|
* @throws java.lang.Exception
|
75 |
|
|
*/
|
76 |
|
|
@After
|
77 |
|
|
public void tearDown() throws Exception {
|
78 |
|
|
}
|
79 |
90046bc4
|
Andreas Müller
|
|
80 |
b5eda83f
|
Andreas Müller
|
/**************** 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 |
6f7d91bd
|
Andreas Müller
|
//
|
91 |
|
|
// /**
|
92 |
9dc896c9
|
Andreas Müller
|
// * Test method for {@link eu.etaxonomy.cdm.model.taxon.TaxonBase#setName(eu.etaxonomy.cdm.model.name.TaxonName)}.
|
93 |
6f7d91bd
|
Andreas Müller
|
// */
|
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 |
b5eda83f
|
Andreas Müller
|
|
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 |
90046bc4
|
Andreas Müller
|
oldValue = taxon1.isDoubtful();
|
111 |
b5eda83f
|
Andreas Müller
|
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 |
1d36aa54
|
Andreas Müller
|
* Test method for {@link eu.etaxonomy.cdm.model.taxon.TaxonBase#setSec(eu.etaxonomy.cdm.model.reference.Reference)}.
|
136 |
b5eda83f
|
Andreas Müller
|
*/
|
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 |
90046bc4
|
Andreas Müller
|
|
145 |
58b9953c
|
Katja Luther
|
@Test
|
146 |
90046bc4
|
Andreas Müller
|
|
147 |
58b9953c
|
Katja Luther
|
public final void testClone(){
|
148 |
90046bc4
|
Andreas Müller
|
|
149 |
9dc896c9
|
Andreas Müller
|
TaxonName test = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
150 |
58b9953c
|
Katja Luther
|
String genus = "test";
|
151 |
|
|
String infraGenericEpithet = "test";
|
152 |
|
|
test.setGenusOrUninomial(genus);
|
153 |
|
|
test.setInfraGenericEpithet(infraGenericEpithet);
|
154 |
90046bc4
|
Andreas Müller
|
Reference secRef = ReferenceFactory.newArticle();
|
155 |
58b9953c
|
Katja Luther
|
secRef.setTitle("Test ...");
|
156 |
|
|
freeT.setSec(secRef);
|
157 |
|
|
freeT.setName(test);
|
158 |
|
|
Taxon clone = (Taxon)freeT.clone();
|
159 |
eefe8728
|
Andreas Müller
|
assertSame(freeT.getSec(), clone.getSec());
|
160 |
58b9953c
|
Katja Luther
|
assertSame(freeT.getName(), clone.getName());
|
161 |
|
|
}
|
162 |
b5b4a36c
|
Andreas Müller
|
|
163 |
|
|
/*
|
164 |
|
|
* Moved from IdentifiableEntityTest to here due to #922
|
165 |
|
|
*/
|
166 |
|
|
@Test
|
167 |
|
|
public void testCompareTo() {
|
168 |
|
|
|
169 |
db183545
|
Andreas Müller
|
TaxonName abies = TaxonNameFactory.NewNonViralInstance(Rank.GENUS(), null);
|
170 |
b5b4a36c
|
Andreas Müller
|
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 |
9dc896c9
|
Andreas Müller
|
TaxonName abiesMill = TaxonNameFactory.NewNonViralInstance(Rank.GENUS(), null);
|
178 |
b5b4a36c
|
Andreas Müller
|
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 |
b5eda83f
|
Andreas Müller
|
}
|