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