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.InvocationTargetException;
|
17
|
import java.lang.reflect.Method;
|
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.name.NonViralName;
|
28
|
import eu.etaxonomy.cdm.model.name.Rank;
|
29
|
import eu.etaxonomy.cdm.model.name.ZoologicalName;
|
30
|
|
31
|
/**
|
32
|
* @author a.mueller
|
33
|
*
|
34
|
*/
|
35
|
public class ZoologicalNameCacheStrategyTest {
|
36
|
private static final Logger logger = Logger.getLogger(ZoologicalNameCacheStrategyTest.class);
|
37
|
|
38
|
private ZooNameDefaultCacheStrategy strategy;
|
39
|
private ZoologicalName familyName;
|
40
|
private ZoologicalName genusName;
|
41
|
private ZoologicalName subGenusName;
|
42
|
private ZoologicalName speciesName;
|
43
|
private ZoologicalName subSpeciesName;
|
44
|
private INomenclaturalAuthor author;
|
45
|
private INomenclaturalAuthor exAuthor;
|
46
|
private INomenclaturalAuthor basAuthor;
|
47
|
private INomenclaturalAuthor exBasAuthor;
|
48
|
|
49
|
private final String familyNameString = "Familia";
|
50
|
private final String genusNameString = "Genus";
|
51
|
private final String speciesNameString = "Abies alba";
|
52
|
private final String subSpeciesNameString = "Abies alba subsp. beta";
|
53
|
|
54
|
private final String authorString = "L.";
|
55
|
private final String exAuthorString = "Exaut.";
|
56
|
private final String basAuthorString = "Basio, A.";
|
57
|
private final String exBasAuthorString = "ExBas. N.";
|
58
|
|
59
|
private final Integer publicationYear = 1928;
|
60
|
private final Integer originalPublicationYear = 1860;
|
61
|
|
62
|
|
63
|
|
64
|
/**
|
65
|
* @throws java.lang.Exception
|
66
|
*/
|
67
|
@BeforeClass
|
68
|
public static void setUpBeforeClass() {
|
69
|
DefaultTermInitializer vocabularyStore = new DefaultTermInitializer();
|
70
|
vocabularyStore.initialize();
|
71
|
}
|
72
|
|
73
|
/**
|
74
|
* @throws java.lang.Exception
|
75
|
*/
|
76
|
@Before
|
77
|
public void setUp() throws Exception {
|
78
|
strategy = ZooNameDefaultCacheStrategy.NewInstance();
|
79
|
familyName = ZoologicalName.PARSED_NAME(familyNameString, Rank.FAMILY());
|
80
|
genusName = ZoologicalName.PARSED_NAME(genusNameString, Rank.GENUS());
|
81
|
|
82
|
subGenusName = ZoologicalName.NewInstance(Rank.SUBGENUS());
|
83
|
subGenusName.setGenusOrUninomial("Genus");
|
84
|
subGenusName.setInfraGenericEpithet("InfraGenericPart");
|
85
|
|
86
|
speciesName = ZoologicalName.PARSED_NAME(speciesNameString);
|
87
|
subSpeciesName = ZoologicalName.PARSED_NAME(subSpeciesNameString);
|
88
|
|
89
|
author = Person.NewInstance();
|
90
|
author.setNomenclaturalTitle(authorString);
|
91
|
exAuthor = Person.NewInstance();
|
92
|
exAuthor.setNomenclaturalTitle(exAuthorString);
|
93
|
basAuthor = Person.NewInstance();
|
94
|
basAuthor.setNomenclaturalTitle(basAuthorString);
|
95
|
exBasAuthor = Person.NewInstance();
|
96
|
exBasAuthor.setNomenclaturalTitle(exBasAuthorString);
|
97
|
}
|
98
|
|
99
|
|
100
|
/********* TEST *******************************************/
|
101
|
|
102
|
/**
|
103
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.BotanicNameDefaultCacheStrategy#NewInstance()}.
|
104
|
*/
|
105
|
@Test
|
106
|
public final void testNewInstance() {
|
107
|
assertNotNull(strategy);
|
108
|
}
|
109
|
|
110
|
/**
|
111
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.BotanicNameDefaultCacheStrategy#getNameCache(eu.etaxonomy.cdm.model.common.CdmBase)}.
|
112
|
*/
|
113
|
@Test
|
114
|
public final void testGetNameCache() {
|
115
|
assertEquals(subSpeciesNameString, subSpeciesName.getNameCache());
|
116
|
assertNull(subSpeciesNameString, strategy.getNameCache(null));
|
117
|
}
|
118
|
|
119
|
/**
|
120
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.BotanicNameDefaultCacheStrategy#getFullNameCache(eu.etaxonomy.cdm.model.common.CdmBase)}.
|
121
|
*/
|
122
|
@Test
|
123
|
public final void testGetTitleCache() {
|
124
|
assertNull(subSpeciesNameString, strategy.getTitleCache(null));
|
125
|
subSpeciesName.setCombinationAuthorTeam(author);
|
126
|
subSpeciesName.setExCombinationAuthorTeam(exAuthor);
|
127
|
subSpeciesName.setBasionymAuthorTeam(basAuthor);
|
128
|
subSpeciesName.setExBasionymAuthorTeam(exBasAuthor);
|
129
|
subSpeciesName.setPublicationYear(publicationYear);
|
130
|
subSpeciesName.setOriginalPublicationYear(originalPublicationYear);
|
131
|
|
132
|
assertEquals(subSpeciesNameString, strategy.getNameCache(subSpeciesName));
|
133
|
assertEquals(subSpeciesNameString + " (" + exBasAuthorString + " ex " + basAuthorString + ", " + originalPublicationYear +")" + " " + exAuthorString + " ex " + authorString + ", " + publicationYear, strategy.getTitleCache(subSpeciesName));
|
134
|
|
135
|
//Autonym,
|
136
|
subSpeciesName.setInfraSpecificEpithet("alba");
|
137
|
subSpeciesName.setCombinationAuthorTeam(author);
|
138
|
subSpeciesName.setBasionymAuthorTeam(null);
|
139
|
subSpeciesName.setExCombinationAuthorTeam(null);
|
140
|
subSpeciesName.setExBasionymAuthorTeam(null);
|
141
|
//old
|
142
|
//assertEquals("Abies alba alba", strategy.getNameCache(subSpeciesName));
|
143
|
//assertEquals("Abies alba L. subsp. alba", strategy.getTitleCache(subSpeciesName));
|
144
|
//new we now assume that there are no autonyms in zoology (source: they do not exist in Fauna Europaea)
|
145
|
assertEquals("Abies alba subsp. alba", strategy.getNameCache(subSpeciesName));
|
146
|
assertEquals("Abies alba subsp. alba (1860) L., 1928", strategy.getTitleCache(subSpeciesName));
|
147
|
|
148
|
}
|
149
|
|
150
|
/**
|
151
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.BotanicNameDefaultCacheStrategy#getAuthorCache(eu.etaxonomy.cdm.model.common.CdmBase)}.
|
152
|
*/
|
153
|
@Test
|
154
|
public final void testGetAuthorshipCache() {
|
155
|
subSpeciesName.setCombinationAuthorTeam(author);
|
156
|
assertEquals(authorString, strategy.getAuthorshipCache(subSpeciesName));
|
157
|
subSpeciesName.setPublicationYear(publicationYear);
|
158
|
assertEquals(authorString + ", " + publicationYear, strategy.getAuthorshipCache(subSpeciesName));
|
159
|
|
160
|
subSpeciesName.setExCombinationAuthorTeam(exAuthor);
|
161
|
assertEquals( exAuthorString + " ex " + authorString + ", " + publicationYear , strategy.getAuthorshipCache(subSpeciesName));
|
162
|
|
163
|
subSpeciesName.setBasionymAuthorTeam(basAuthor);
|
164
|
assertEquals("(" + basAuthorString + ")" + " " + exAuthorString + " ex " + authorString + ", " + publicationYear , strategy.getAuthorshipCache(subSpeciesName));
|
165
|
subSpeciesName.setOriginalPublicationYear(originalPublicationYear);
|
166
|
assertEquals("(" + basAuthorString + ", " + originalPublicationYear + ")" + " " + exAuthorString + " ex " + authorString + ", " + publicationYear , strategy.getAuthorshipCache(subSpeciesName));
|
167
|
|
168
|
subSpeciesName.setExBasionymAuthorTeam(exBasAuthor);
|
169
|
assertEquals("(" + exBasAuthorString + " ex " + basAuthorString + ", " + originalPublicationYear + ")" + " " + exAuthorString + " ex " + authorString + ", " + publicationYear , strategy.getAuthorshipCache(subSpeciesName));
|
170
|
|
171
|
//cache
|
172
|
subSpeciesName.setAuthorshipCache(authorString);
|
173
|
assertEquals("AuthorshipCache must be updated", authorString, subSpeciesName.getAuthorshipCache());
|
174
|
assertEquals("TitleCache must be updated", "Abies alba subsp. beta " + authorString, subSpeciesName.getTitleCache());
|
175
|
subSpeciesName.setProtectedAuthorshipCache(false);
|
176
|
//TODO make this not needed
|
177
|
subSpeciesName.setTitleCache(null, false);
|
178
|
assertEquals("TitleCache must be updated", "Abies alba subsp. beta " + "(ExBas. N. ex Basio, A., 1860) Exaut. ex L., 1928", subSpeciesName.getTitleCache());
|
179
|
|
180
|
assertNull("Authorship cache for null must return null", strategy.getAuthorshipCache(null));
|
181
|
|
182
|
}
|
183
|
|
184
|
/**
|
185
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.BotanicNameDefaultCacheStrategy#getUninomialNameCache(eu.etaxonomy.cdm.model.name.BotanicalName)}.
|
186
|
*/
|
187
|
@Test
|
188
|
public final void testGetGenusOrUninomialNameCache() {
|
189
|
assertEquals(familyNameString, strategy.getNameCache(familyName));
|
190
|
}
|
191
|
|
192
|
/**
|
193
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.BotanicNameDefaultCacheStrategy#getInfraGenusNameCache(eu.etaxonomy.cdm.model.name.BotanicalName)}.
|
194
|
*/
|
195
|
@Test
|
196
|
public final void testGetInfraGenusNameCache() {
|
197
|
String methodName = "getInfraGenusNameCache";
|
198
|
Method method = getMethod(NonViralNameDefaultCacheStrategy.class, methodName, NonViralName.class);
|
199
|
|
200
|
this.getValue(method, strategy, subGenusName);
|
201
|
assertEquals("Genus subg. InfraGenericPart", strategy.getNameCache(subGenusName));
|
202
|
}
|
203
|
|
204
|
/**
|
205
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.BotanicNameDefaultCacheStrategy#getSpeciesNameCache(eu.etaxonomy.cdm.model.name.BotanicalName)}.
|
206
|
*/
|
207
|
@Test
|
208
|
public final void testGetSpeciesNameCache() {
|
209
|
assertEquals(speciesNameString, strategy.getNameCache(speciesName));
|
210
|
}
|
211
|
|
212
|
/**
|
213
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.BotanicNameDefaultCacheStrategy#getInfraSpeciesNameCache(eu.etaxonomy.cdm.model.name.BotanicalName)}.
|
214
|
*/
|
215
|
@Test
|
216
|
public final void testGetInfraSpeciesNameCache() {
|
217
|
assertEquals(subSpeciesNameString, strategy.getNameCache(subSpeciesName));
|
218
|
}
|
219
|
|
220
|
|
221
|
/**
|
222
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.BotanicNameDefaultCacheStrategy#getInfraSpeciesNameCache(eu.etaxonomy.cdm.model.name.BotanicalName)}.
|
223
|
*/
|
224
|
@Test
|
225
|
public final void testAutonyms() {
|
226
|
subSpeciesName.setInfraSpecificEpithet("alba");
|
227
|
subSpeciesName.setCombinationAuthorTeam(author);
|
228
|
//old
|
229
|
// assertEquals("Abies alba alba", strategy.getNameCache(subSpeciesName));
|
230
|
// assertEquals("Abies alba L. subsp. alba", strategy.getTitleCache(subSpeciesName));
|
231
|
//new
|
232
|
//new: we now assume that there are no autonyms in zoology (source: they do not exist in Fauna Europaea)
|
233
|
assertEquals("Abies alba subsp. alba", strategy.getNameCache(subSpeciesName));
|
234
|
assertEquals("Abies alba subsp. alba L.", strategy.getTitleCache(subSpeciesName));
|
235
|
}
|
236
|
|
237
|
|
238
|
|
239
|
|
240
|
|
241
|
|
242
|
protected Method getMethod(Class clazz, String methodName, Class paramClazzes){
|
243
|
Method method;
|
244
|
try {
|
245
|
method = clazz.getDeclaredMethod("getInfraGenusNameCache", paramClazzes);
|
246
|
} catch (SecurityException e) {
|
247
|
logger.error("SecurityException " + e.getMessage());
|
248
|
return null;
|
249
|
} catch (NoSuchMethodException e) {
|
250
|
logger.error("NoSuchMethodException " + e.getMessage());
|
251
|
return null;
|
252
|
}
|
253
|
return method;
|
254
|
}
|
255
|
|
256
|
protected String getValue(Method method, Object object,Object parameter){
|
257
|
try {
|
258
|
return (String)method.invoke(object, parameter);
|
259
|
} catch (IllegalArgumentException e) {
|
260
|
logger.error("IllegalArgumentException " + e.getMessage());
|
261
|
return null;
|
262
|
} catch (IllegalAccessException e) {
|
263
|
logger.error("IllegalAccessException " + e.getMessage());
|
264
|
return null;
|
265
|
} catch (InvocationTargetException e) {
|
266
|
logger.error("InvocationTargetException " + e.getMessage());
|
267
|
return null;
|
268
|
}
|
269
|
}
|
270
|
|
271
|
|
272
|
}
|