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.strategy.cache.name;
|
11
|
|
12
|
import static org.junit.Assert.assertEquals;
|
13
|
import static org.junit.Assert.assertNotNull;
|
14
|
import static org.junit.Assert.assertNull;
|
15
|
|
16
|
import java.lang.reflect.Method;
|
17
|
import java.util.GregorianCalendar;
|
18
|
|
19
|
import org.apache.log4j.Logger;
|
20
|
import org.junit.Before;
|
21
|
import org.junit.BeforeClass;
|
22
|
import org.junit.Test;
|
23
|
|
24
|
import eu.etaxonomy.cdm.model.agent.Person;
|
25
|
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
|
26
|
import eu.etaxonomy.cdm.model.common.DefaultTermInitializer;
|
27
|
import eu.etaxonomy.cdm.model.common.VerbatimTimePeriod;
|
28
|
import eu.etaxonomy.cdm.model.name.INonViralName;
|
29
|
import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
|
30
|
import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
|
31
|
import eu.etaxonomy.cdm.model.name.Rank;
|
32
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
33
|
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
|
34
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
35
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
36
|
|
37
|
/**
|
38
|
* @author a.mueller
|
39
|
*
|
40
|
*/
|
41
|
public class BotanicNameCacheStrategyTest extends NameCacheStrategyTestBase{
|
42
|
private static final Logger logger = Logger.getLogger(BotanicNameCacheStrategyTest.class);
|
43
|
|
44
|
private static final String familyNameString = "Familia";
|
45
|
private static final String genusNameString = "Genus";
|
46
|
private static final String speciesNameString = "Abies alba";
|
47
|
private static final String subSpeciesNameString = "Abies alba subsp. beta";
|
48
|
private static final String appendedPhraseString = "app phrase";
|
49
|
|
50
|
private static final String authorString = "L.";
|
51
|
private static final String exAuthorString = "Exaut.";
|
52
|
private static final String basAuthorString = "Basio, A.";
|
53
|
private static final String exBasAuthorString = "ExBas. N.";
|
54
|
|
55
|
private TaxonNameDefaultCacheStrategy strategy;
|
56
|
private TaxonName familyName;
|
57
|
private TaxonName genusName;
|
58
|
private TaxonName subGenusName;
|
59
|
private TaxonName speciesName;
|
60
|
private TaxonName subSpeciesName;
|
61
|
private TeamOrPersonBase<?> author;
|
62
|
private TeamOrPersonBase<?> exAuthor;
|
63
|
private TeamOrPersonBase<?> basAuthor;
|
64
|
private TeamOrPersonBase<?> exBasAuthor;
|
65
|
private Reference citationRef;
|
66
|
ReferenceFactory refFactory;
|
67
|
|
68
|
/**
|
69
|
* @throws java.lang.Exception
|
70
|
*/
|
71
|
@BeforeClass
|
72
|
public static void setUpBeforeClass() {
|
73
|
DefaultTermInitializer vocabularyStore = new DefaultTermInitializer();
|
74
|
vocabularyStore.initialize();
|
75
|
}
|
76
|
|
77
|
/**
|
78
|
* @throws java.lang.Exception
|
79
|
*/
|
80
|
@Before
|
81
|
public void setUp() throws Exception {
|
82
|
strategy = TaxonNameDefaultCacheStrategy.NewInstance();
|
83
|
familyName = TaxonNameFactory.PARSED_BOTANICAL(familyNameString, Rank.FAMILY());
|
84
|
genusName = TaxonNameFactory.PARSED_BOTANICAL(genusNameString, Rank.GENUS());
|
85
|
|
86
|
subGenusName = TaxonNameFactory.NewBotanicalInstance(Rank.SUBGENUS());
|
87
|
subGenusName.setGenusOrUninomial("Genus");
|
88
|
subGenusName.setInfraGenericEpithet("InfraGenericPart");
|
89
|
|
90
|
speciesName = TaxonNameFactory.PARSED_BOTANICAL(speciesNameString);
|
91
|
subSpeciesName = TaxonNameFactory.PARSED_BOTANICAL(subSpeciesNameString);
|
92
|
|
93
|
author = Person.NewInstance();
|
94
|
author.setNomenclaturalTitle(authorString);
|
95
|
exAuthor = Person.NewInstance();
|
96
|
exAuthor.setNomenclaturalTitle(exAuthorString);
|
97
|
basAuthor = Person.NewInstance();
|
98
|
basAuthor.setNomenclaturalTitle(basAuthorString);
|
99
|
exBasAuthor = Person.NewInstance();
|
100
|
exBasAuthor.setNomenclaturalTitle(exBasAuthorString);
|
101
|
|
102
|
citationRef = refFactory.newBook();
|
103
|
// Gard. Dict. ed. 8, no. 1. 1768.
|
104
|
citationRef.setTitle("Gard. Dict.");
|
105
|
//citationRef.setPlacePublished("");
|
106
|
citationRef.setVolume("1");
|
107
|
citationRef.setEdition("ed. 8");
|
108
|
GregorianCalendar testDate = new GregorianCalendar();
|
109
|
testDate.set(1968, 3, 2);
|
110
|
|
111
|
VerbatimTimePeriod period = VerbatimTimePeriod.NewVerbatimInstance(testDate);
|
112
|
|
113
|
citationRef.setDatePublished(period);
|
114
|
|
115
|
//speciesName.setNomenclaturalMicroReference("89");
|
116
|
NomenclaturalStatus nomStatus = NomenclaturalStatus.NewInstance(NomenclaturalStatusType.ILLEGITIMATE());
|
117
|
speciesName.addStatus(nomStatus);
|
118
|
|
119
|
speciesName.setNomenclaturalReference(citationRef);
|
120
|
speciesName.setAppendedPhrase("app phrase");
|
121
|
|
122
|
// subSpeciesName.setNomenclaturalReference(citationRef);
|
123
|
// subSpeciesName.setAppendedPhrase("app phrase");
|
124
|
}
|
125
|
|
126
|
|
127
|
|
128
|
/********* TEST *******************************************/
|
129
|
|
130
|
/**
|
131
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.BotanicNameDefaultCacheStrategy#NewInstance()}.
|
132
|
*/
|
133
|
@Test
|
134
|
public final void testNewInstance() {
|
135
|
TaxonNameDefaultCacheStrategy cacheStrategy = TaxonNameDefaultCacheStrategy.NewInstance();
|
136
|
assertNotNull(cacheStrategy);
|
137
|
}
|
138
|
|
139
|
/**
|
140
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.BotanicNameDefaultCacheStrategy#getNameCache(eu.etaxonomy.cdm.model.common.CdmBase)}.
|
141
|
*/
|
142
|
@Test
|
143
|
public final void testGetNameCache() {
|
144
|
assertEquals(subSpeciesNameString, subSpeciesName.getNameCache());
|
145
|
assertNull(subSpeciesNameString, strategy.getNameCache(null));
|
146
|
}
|
147
|
|
148
|
/**
|
149
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.BotanicNameDefaultCacheStrategy#getTitleCache(eu.etaxonomy.cdm.model.common.CdmBase)}.
|
150
|
*/
|
151
|
@Test
|
152
|
public final void testGetTitleCache() {
|
153
|
assertNull(subSpeciesNameString, strategy.getTitleCache(null));
|
154
|
subSpeciesName.setCombinationAuthorship(author);
|
155
|
subSpeciesName.setExCombinationAuthorship(exAuthor);
|
156
|
subSpeciesName.setBasionymAuthorship(basAuthor);
|
157
|
subSpeciesName.setExBasionymAuthorship(exBasAuthor);
|
158
|
assertEquals(subSpeciesNameString, strategy.getNameCache(subSpeciesName));
|
159
|
assertEquals(subSpeciesNameString + " (" + exBasAuthorString + " ex " + basAuthorString + ")" + " " + exAuthorString + " ex " + authorString , strategy.getTitleCache(subSpeciesName));
|
160
|
|
161
|
subSpeciesName.setExCombinationAuthorship(null);
|
162
|
assertEquals(subSpeciesNameString + " (" + exBasAuthorString + " ex " + basAuthorString + ")" + " " + authorString , strategy.getTitleCache(subSpeciesName));
|
163
|
|
164
|
subSpeciesName.setExBasionymAuthorship(null);
|
165
|
assertEquals(subSpeciesNameString + " (" + basAuthorString + ")" + " " + authorString , strategy.getTitleCache(subSpeciesName));
|
166
|
|
167
|
|
168
|
//Autonym
|
169
|
subSpeciesName.setInfraSpecificEpithet("alba");
|
170
|
subSpeciesName.setCombinationAuthorship(author);
|
171
|
subSpeciesName.setBasionymAuthorship(null);
|
172
|
subSpeciesName.setExCombinationAuthorship(null);
|
173
|
subSpeciesName.setExBasionymAuthorship(null);
|
174
|
//changed 2009-09-04
|
175
|
assertEquals("Abies alba subsp. alba", strategy.getNameCache(subSpeciesName));
|
176
|
assertEquals("Abies alba L. subsp. alba", strategy.getTitleCache(subSpeciesName));
|
177
|
|
178
|
|
179
|
|
180
|
}
|
181
|
|
182
|
@Test
|
183
|
public final void testGetFullTitleCache() {
|
184
|
assertNull("Full title cache of null object should return null", strategy.getFullTitleCache(null));
|
185
|
//NOTE: Unclear if the date part should contain the full date or only the year. Undefined Behaviour.
|
186
|
assertEquals("Abies alba app phrase, Gard. Dict., ed. 8, 1. 2.4.1968, nom. illeg.", strategy.getFullTitleCache(speciesName));
|
187
|
|
188
|
// assertNull(subSpeciesNameString, strategy.getFullTitleCache(null));
|
189
|
// assertEquals("Abies alba app phrase L. Gard. Dict. ed. 8, 1. 1768, nom. illeg.", strategy.getFullTitleCache(speciesName));
|
190
|
}
|
191
|
|
192
|
@Test
|
193
|
public final void testGetAuthorshipCache() {
|
194
|
subSpeciesName.setCombinationAuthorship(author);
|
195
|
assertEquals(authorString, strategy.getAuthorshipCache(subSpeciesName));
|
196
|
|
197
|
subSpeciesName.setExCombinationAuthorship(exAuthor);
|
198
|
assertEquals(exAuthorString + " ex " + authorString , strategy.getAuthorshipCache(subSpeciesName));
|
199
|
|
200
|
subSpeciesName.setBasionymAuthorship(basAuthor);
|
201
|
assertEquals("(" + basAuthorString + ")" + " " + exAuthorString + " ex " + authorString , strategy.getAuthorshipCache(subSpeciesName));
|
202
|
|
203
|
subSpeciesName.setExBasionymAuthorship(exBasAuthor);
|
204
|
assertEquals("(" + exBasAuthorString + " ex " + basAuthorString + ")" + " " + exAuthorString + " ex " + authorString , strategy.getAuthorshipCache(subSpeciesName));
|
205
|
|
206
|
assertNull(subSpeciesNameString, strategy.getAuthorshipCache(null));
|
207
|
}
|
208
|
|
209
|
@Test
|
210
|
public final void testGetGenusOrUninomialNameCache() {
|
211
|
assertEquals(familyNameString, strategy.getNameCache(familyName));
|
212
|
}
|
213
|
|
214
|
@Test
|
215
|
public final void testGetInfraGenusTaggedNameCache() {
|
216
|
String methodName = "getInfraGenusTaggedNameCache";
|
217
|
Method method = getMethod(TaxonNameDefaultCacheStrategy.class, methodName, INonViralName.class);
|
218
|
this.getStringValue(method, strategy, subGenusName);
|
219
|
assertEquals("Genus subg. InfraGenericPart", strategy.getNameCache(subGenusName));
|
220
|
}
|
221
|
|
222
|
@Test
|
223
|
public final void testGetSpeciesNameCache() {
|
224
|
String nameString = speciesNameString + " " + appendedPhraseString;
|
225
|
assertEquals(nameString, strategy.getNameCache(speciesName));
|
226
|
}
|
227
|
|
228
|
@Test
|
229
|
public final void testGetInfraSpeciesNameCache() {
|
230
|
assertEquals(subSpeciesNameString, strategy.getNameCache(subSpeciesName));
|
231
|
}
|
232
|
|
233
|
@Test
|
234
|
public final void testAutonyms() {
|
235
|
subSpeciesName.setInfraSpecificEpithet("alba");
|
236
|
subSpeciesName.setCombinationAuthorship(author);
|
237
|
//changed 2009-09-04
|
238
|
assertEquals("Abies alba subsp. alba", strategy.getNameCache(subSpeciesName));
|
239
|
assertEquals("Abies alba L. subsp. alba", strategy.getTitleCache(subSpeciesName));
|
240
|
}
|
241
|
|
242
|
@Override
|
243
|
protected Method getMethod(Class clazz, String methodName, Class paramClazzes){
|
244
|
Method method;
|
245
|
try {
|
246
|
method = clazz.getDeclaredMethod(methodName, paramClazzes);
|
247
|
} catch (SecurityException e) {
|
248
|
logger.error("SecurityException " + e.getMessage());
|
249
|
return null;
|
250
|
} catch (NoSuchMethodException e) {
|
251
|
logger.error("NoSuchMethodException " + e.getMessage());
|
252
|
return null;
|
253
|
}
|
254
|
return method;
|
255
|
}
|
256
|
|
257
|
|
258
|
|
259
|
}
|