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
|
|
17
|
import org.apache.log4j.Logger;
|
18
|
import org.junit.After;
|
19
|
import org.junit.Before;
|
20
|
import org.junit.BeforeClass;
|
21
|
import org.junit.Test;
|
22
|
|
23
|
import eu.etaxonomy.cdm.model.common.DefaultTermInitializer;
|
24
|
import eu.etaxonomy.cdm.model.name.BotanicalName;
|
25
|
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
|
26
|
import eu.etaxonomy.cdm.model.name.Rank;
|
27
|
import eu.etaxonomy.cdm.model.name.ZoologicalName;
|
28
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
29
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
30
|
import eu.etaxonomy.cdm.test.unit.EntityTestBase;
|
31
|
|
32
|
/**
|
33
|
* @author a.mueller
|
34
|
*
|
35
|
*/
|
36
|
public class TaxonBaseTest extends EntityTestBase {
|
37
|
@SuppressWarnings("unused")
|
38
|
private static final Logger logger = Logger.getLogger(TaxonBaseTest.class);
|
39
|
|
40
|
private Reference sec;
|
41
|
private ZoologicalName name1;
|
42
|
private BotanicalName name2;
|
43
|
private Taxon rootT;
|
44
|
private Taxon taxon1;
|
45
|
private Synonym synonym1;
|
46
|
private Taxon freeT;
|
47
|
|
48
|
@BeforeClass
|
49
|
public static void setUpBeforeClass() {
|
50
|
DefaultTermInitializer vocabularyStore = new DefaultTermInitializer();
|
51
|
vocabularyStore.initialize();
|
52
|
}
|
53
|
|
54
|
/**
|
55
|
* @throws java.lang.Exception
|
56
|
*/
|
57
|
@Before
|
58
|
public void setUp() throws Exception {
|
59
|
sec= ReferenceFactory.newBook();
|
60
|
sec.setTitleCache("Schoenes saftiges Allg�u", true);
|
61
|
name1 = ZoologicalName.NewInstance(Rank.SPECIES(),"Panthera",null,"onca",null,null,null,"p.1467", null);
|
62
|
HomotypicalGroup homotypicalGroup = HomotypicalGroup.NewInstance();
|
63
|
name2 = BotanicalName.NewInstance(Rank.SPECIES(),"Abies",null,"alba",null,null,null,"p.317", homotypicalGroup);
|
64
|
// taxa
|
65
|
taxon1 = Taxon.NewInstance(name1,sec);
|
66
|
synonym1 = Synonym.NewInstance(name2,sec);
|
67
|
freeT = Taxon.NewInstance(null, null);
|
68
|
}
|
69
|
|
70
|
/**
|
71
|
* @throws java.lang.Exception
|
72
|
*/
|
73
|
@After
|
74
|
public void tearDown() throws Exception {
|
75
|
}
|
76
|
|
77
|
/**************** TESTS **************************************/
|
78
|
|
79
|
/**
|
80
|
* Test method for {@link eu.etaxonomy.cdm.model.taxon.TaxonBase#getName()}.
|
81
|
*/
|
82
|
@Test
|
83
|
public final void testGetName() {
|
84
|
assertEquals(name1.getTitleCache(), taxon1.getName().getTitleCache());
|
85
|
assertNull(freeT.getName());
|
86
|
}
|
87
|
//
|
88
|
// /**
|
89
|
// * Test method for {@link eu.etaxonomy.cdm.model.taxon.TaxonBase#setName(eu.etaxonomy.cdm.model.name.TaxonNameBase)}.
|
90
|
// */
|
91
|
// @Test
|
92
|
// public final void testSetName() {
|
93
|
// assertNull(freeT.getName());
|
94
|
// freeT.setName(name2);
|
95
|
// assertNotNull(freeT.getName());
|
96
|
// assertSame(freeT.getName(), name2);
|
97
|
// assertTrue(name1.getTaxa().contains(taxon1));
|
98
|
// assertTrue(name2.getSynonyms().contains(synonym1));
|
99
|
// }
|
100
|
|
101
|
/**
|
102
|
* Test method for {@link eu.etaxonomy.cdm.model.taxon.TaxonBase#isDoubtful()}.
|
103
|
*/
|
104
|
@Test
|
105
|
public final void testIsDoubtful() {
|
106
|
boolean oldValue;
|
107
|
oldValue = taxon1.isDoubtful();
|
108
|
taxon1.setDoubtful(!oldValue);
|
109
|
assertEquals(! oldValue, taxon1.isDoubtful());
|
110
|
taxon1.setDoubtful(oldValue);
|
111
|
assertEquals( oldValue, taxon1.isDoubtful());
|
112
|
}
|
113
|
|
114
|
/**
|
115
|
* Test method for {@link eu.etaxonomy.cdm.model.taxon.TaxonBase#setDoubtful(boolean)}.
|
116
|
*/
|
117
|
@Test
|
118
|
public final void testSetDoubtful() {
|
119
|
//covered by testIsDoubtful
|
120
|
}
|
121
|
|
122
|
/**
|
123
|
* Test method for {@link eu.etaxonomy.cdm.model.taxon.TaxonBase#getSec()}.
|
124
|
*/
|
125
|
@Test
|
126
|
public final void testGetSec() {
|
127
|
assertEquals(sec.getTitleCache(), taxon1.getSec().getTitleCache());
|
128
|
assertNull(freeT.getSec());
|
129
|
}
|
130
|
|
131
|
/**
|
132
|
* Test method for {@link eu.etaxonomy.cdm.model.taxon.TaxonBase#setSec(eu.etaxonomy.cdm.model.reference.Reference)}.
|
133
|
*/
|
134
|
@Test
|
135
|
public final void testSetSec() {
|
136
|
assertNull(freeT.getSec());
|
137
|
freeT.setSec(sec);
|
138
|
assertNotNull(freeT.getSec());
|
139
|
assertSame(freeT.getSec(), sec);
|
140
|
}
|
141
|
|
142
|
@Test
|
143
|
|
144
|
public final void testClone(){
|
145
|
|
146
|
BotanicalName test = BotanicalName.NewInstance(Rank.SPECIES());
|
147
|
String genus = "test";
|
148
|
String infraGenericEpithet = "test";
|
149
|
test.setGenusOrUninomial(genus);
|
150
|
test.setInfraGenericEpithet(infraGenericEpithet);
|
151
|
Reference secRef = ReferenceFactory.newArticle();
|
152
|
secRef.setTitle("Test ...");
|
153
|
freeT.setSec(secRef);
|
154
|
freeT.setName(test);
|
155
|
Taxon clone = (Taxon)freeT.clone();
|
156
|
assertNull(clone.getSec());
|
157
|
assertSame(freeT.getName(), clone.getName());
|
158
|
}
|
159
|
}
|