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