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
|
package eu.etaxonomy.cdm.model.taxon;
|
10
|
|
11
|
import static org.junit.Assert.assertEquals;
|
12
|
import static org.junit.Assert.assertNotNull;
|
13
|
import static org.junit.Assert.assertNull;
|
14
|
import static org.junit.Assert.assertSame;
|
15
|
import static org.junit.Assert.assertTrue;
|
16
|
|
17
|
import org.apache.log4j.Logger;
|
18
|
import org.junit.Before;
|
19
|
import org.junit.Test;
|
20
|
|
21
|
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
|
22
|
import eu.etaxonomy.cdm.model.name.IBotanicalName;
|
23
|
import eu.etaxonomy.cdm.model.name.IZoologicalName;
|
24
|
import eu.etaxonomy.cdm.model.name.Rank;
|
25
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
26
|
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
|
27
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
28
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
29
|
import eu.etaxonomy.cdm.test.unit.EntityTestBase;
|
30
|
|
31
|
/**
|
32
|
* @author a.mueller
|
33
|
*/
|
34
|
public class TaxonBaseTest extends EntityTestBase {
|
35
|
|
36
|
@SuppressWarnings("unused")
|
37
|
private static final Logger logger = Logger.getLogger(TaxonBaseTest.class);
|
38
|
|
39
|
private Reference sec;
|
40
|
private IZoologicalName name1;
|
41
|
private IBotanicalName name2;
|
42
|
private Taxon rootT;
|
43
|
private Taxon taxon1;
|
44
|
private Synonym synonym1;
|
45
|
private Taxon freeT;
|
46
|
|
47
|
@Before
|
48
|
public void setUp() throws Exception {
|
49
|
sec= ReferenceFactory.newBook();
|
50
|
sec.setTitleCache("Schoenes saftiges Allg�u", true);
|
51
|
name1 = TaxonNameFactory.NewZoologicalInstance(Rank.SPECIES(),"Panthera",null,"onca",null,null,null,"p.1467", null);
|
52
|
HomotypicalGroup homotypicalGroup = HomotypicalGroup.NewInstance();
|
53
|
name2 = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES(),"Abies",null,"alba",null,null,null,"p.317", homotypicalGroup);
|
54
|
// taxa
|
55
|
taxon1 = Taxon.NewInstance(name1,sec);
|
56
|
synonym1 = Synonym.NewInstance(name2,sec);
|
57
|
freeT = Taxon.NewInstance(null, null);
|
58
|
}
|
59
|
|
60
|
/**************** TESTS **************************************/
|
61
|
|
62
|
@Test
|
63
|
public final void testGetName() {
|
64
|
assertEquals(name1.getTitleCache(), taxon1.getName().getTitleCache());
|
65
|
assertNull(freeT.getName());
|
66
|
}
|
67
|
//
|
68
|
// /**
|
69
|
// * Test method for {@link eu.etaxonomy.cdm.model.taxon.TaxonBase#setName(eu.etaxonomy.cdm.model.name.TaxonName)}.
|
70
|
// */
|
71
|
// @Test
|
72
|
// public final void testSetName() {
|
73
|
// assertNull(freeT.getName());
|
74
|
// freeT.setName(name2);
|
75
|
// assertNotNull(freeT.getName());
|
76
|
// assertSame(freeT.getName(), name2);
|
77
|
// assertTrue(name1.getTaxa().contains(taxon1));
|
78
|
// assertTrue(name2.getSynonyms().contains(synonym1));
|
79
|
// }
|
80
|
|
81
|
@Test
|
82
|
public final void testIsSetDoubtful() {
|
83
|
boolean oldValue;
|
84
|
oldValue = taxon1.isDoubtful();
|
85
|
taxon1.setDoubtful(!oldValue);
|
86
|
assertEquals(! oldValue, taxon1.isDoubtful());
|
87
|
taxon1.setDoubtful(oldValue);
|
88
|
assertEquals( oldValue, taxon1.isDoubtful());
|
89
|
}
|
90
|
|
91
|
@Test
|
92
|
public final void testGetSec() {
|
93
|
assertEquals(sec.getTitleCache(), taxon1.getSec().getTitleCache());
|
94
|
assertNull(freeT.getSec());
|
95
|
}
|
96
|
|
97
|
@Test
|
98
|
public final void testSetSec() {
|
99
|
assertNull(freeT.getSec());
|
100
|
freeT.setSec(sec);
|
101
|
assertNotNull(freeT.getSec());
|
102
|
assertSame(freeT.getSec(), sec);
|
103
|
}
|
104
|
|
105
|
@Test
|
106
|
public final void testClone(){
|
107
|
|
108
|
TaxonName test = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
109
|
String genus = "test";
|
110
|
String infraGenericEpithet = "test";
|
111
|
test.setGenusOrUninomial(genus);
|
112
|
test.setInfraGenericEpithet(infraGenericEpithet);
|
113
|
Reference secRef = ReferenceFactory.newArticle();
|
114
|
secRef.setTitle("Test ...");
|
115
|
freeT.setSec(secRef);
|
116
|
freeT.setName(test);
|
117
|
Taxon clone = freeT.clone();
|
118
|
assertSame(freeT.getSec(), clone.getSec()); //this was assertNull first, but we realized that it is not intuitive to remove the sec when cloning.
|
119
|
assertSame(freeT.getName(), clone.getName());
|
120
|
}
|
121
|
|
122
|
/*
|
123
|
* Moved from IdentifiableEntityTest to here due to #922
|
124
|
*/
|
125
|
@Test
|
126
|
public void testCompareTo() {
|
127
|
|
128
|
TaxonName abies = TaxonNameFactory.NewNonViralInstance(Rank.GENUS(), null);
|
129
|
abies.setNameCache("Abies");
|
130
|
abies.setTitleCache("Abies", true);
|
131
|
Reference sec = ReferenceFactory.newArticle();
|
132
|
sec.setTitle("Abies alba Ref");
|
133
|
|
134
|
Taxon abiesTaxon = Taxon.NewInstance(abies, sec);
|
135
|
|
136
|
TaxonName abiesMill = TaxonNameFactory.NewNonViralInstance(Rank.GENUS(), null);
|
137
|
abiesMill.setNameCache("Abies");
|
138
|
abiesMill.setTitleCache("Abies Mill.", true);
|
139
|
Taxon abiesMillTaxon = Taxon.NewInstance(abiesMill, sec);
|
140
|
|
141
|
int result = 0;
|
142
|
|
143
|
// "Abies" < "Abies Mill."
|
144
|
result = abies.compareToName(abiesMill);
|
145
|
assertTrue(result < 0);
|
146
|
|
147
|
abiesTaxon = abies.getTaxa().iterator().next();
|
148
|
|
149
|
assertTrue(abiesTaxon.compareToTaxon(abiesTaxon) == 0);
|
150
|
assertTrue(abiesMillTaxon.compareToTaxon(abiesTaxon) > 0);
|
151
|
assertTrue(abiesTaxon.compareToTaxon(abiesMillTaxon) < 0);
|
152
|
}
|
153
|
}
|