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.assertNull;
|
14
|
|
15
|
import java.util.List;
|
16
|
|
17
|
import org.junit.Assert;
|
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.BotanicalName;
|
28
|
import eu.etaxonomy.cdm.model.name.HybridRelationshipType;
|
29
|
import eu.etaxonomy.cdm.model.name.NonViralName;
|
30
|
import eu.etaxonomy.cdm.model.name.Rank;
|
31
|
import eu.etaxonomy.cdm.model.name.ZoologicalName;
|
32
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
33
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
34
|
|
35
|
/**
|
36
|
* @author a.mueller
|
37
|
* @created 26.11.2008
|
38
|
* @version 1.0
|
39
|
*/
|
40
|
public class NonViralNameDefaultCacheStrategyTest {
|
41
|
private static final Logger logger = Logger.getLogger(NonViralNameDefaultCacheStrategyTest.class);
|
42
|
|
43
|
private NonViralNameDefaultCacheStrategy strategy;
|
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 static final String referenceTitle = "My Reference";
|
57
|
|
58
|
private BotanicalName familyName;
|
59
|
private BotanicalName genusName;
|
60
|
private BotanicalName subGenusName;
|
61
|
private BotanicalName speciesName;
|
62
|
private BotanicalName subSpeciesName;
|
63
|
private INomenclaturalAuthor author;
|
64
|
private INomenclaturalAuthor exAuthor;
|
65
|
private INomenclaturalAuthor basAuthor;
|
66
|
private INomenclaturalAuthor exBasAuthor;
|
67
|
private Reference citationRef;
|
68
|
|
69
|
@BeforeClass
|
70
|
public static void setUpBeforeClass() {
|
71
|
DefaultTermInitializer vocabularyStore = new DefaultTermInitializer();
|
72
|
vocabularyStore.initialize();
|
73
|
}
|
74
|
|
75
|
/**
|
76
|
* @throws java.lang.Exception
|
77
|
*/
|
78
|
@Before
|
79
|
public void setUp() throws Exception {
|
80
|
strategy = NonViralNameDefaultCacheStrategy.NewInstance();
|
81
|
familyName = BotanicalName.PARSED_NAME(familyNameString, Rank.FAMILY());
|
82
|
genusName = BotanicalName.PARSED_NAME(genusNameString, Rank.GENUS());
|
83
|
|
84
|
subGenusName = BotanicalName.NewInstance(Rank.SUBGENUS());
|
85
|
subGenusName.setGenusOrUninomial("Genus");
|
86
|
subGenusName.setInfraGenericEpithet("InfraGenericPart");
|
87
|
|
88
|
speciesName = BotanicalName.PARSED_NAME(speciesNameString);
|
89
|
subSpeciesName = BotanicalName.PARSED_NAME(subSpeciesNameString);
|
90
|
|
91
|
author = Person.NewInstance();
|
92
|
author.setNomenclaturalTitle(authorString);
|
93
|
exAuthor = Person.NewInstance();
|
94
|
exAuthor.setNomenclaturalTitle(exAuthorString);
|
95
|
basAuthor = Person.NewInstance();
|
96
|
basAuthor.setNomenclaturalTitle(basAuthorString);
|
97
|
exBasAuthor = Person.NewInstance();
|
98
|
exBasAuthor.setNomenclaturalTitle(exBasAuthorString);
|
99
|
|
100
|
citationRef = ReferenceFactory.newGeneric();
|
101
|
citationRef.setTitleCache(referenceTitle, true);
|
102
|
|
103
|
}
|
104
|
|
105
|
//**************************** TESTS **************************************************
|
106
|
|
107
|
/**
|
108
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#getTitleCache(eu.etaxonomy.cdm.model.name.NonViralName)}.
|
109
|
*/
|
110
|
@Test
|
111
|
public void testGetTitleCache() {
|
112
|
Assert.assertEquals(speciesNameString, speciesName.getTitleCache());
|
113
|
//TODO not yet completed
|
114
|
}
|
115
|
|
116
|
/**
|
117
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#getFullTitleCache(eu.etaxonomy.cdm.model.name.NonViralName)}.
|
118
|
*/
|
119
|
@Test
|
120
|
public void testGetFullTitleCache() {
|
121
|
subSpeciesName.setNomenclaturalReference(citationRef);
|
122
|
Assert.assertEquals(subSpeciesNameString + ", " + referenceTitle, subSpeciesName.getFullTitleCache());
|
123
|
//TODO not yet completed
|
124
|
}
|
125
|
|
126
|
|
127
|
/**
|
128
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#getNameCache(eu.etaxonomy.cdm.model.name.NonViralName)}.
|
129
|
*/
|
130
|
@Test
|
131
|
public void testGetNameCache() {
|
132
|
assertEquals("Species Name should be Abies alba", speciesNameString, speciesName.getNameCache());
|
133
|
speciesName.setNameCache("Any species");
|
134
|
assertEquals("Species Name should be Any species", "Any species", speciesName.getNameCache());
|
135
|
assertEquals("Species Name should be Any species", "Any species", speciesName.getTitleCache());
|
136
|
assertEquals("subSpeciesNameString should be correct", subSpeciesNameString, subSpeciesName.getNameCache());
|
137
|
BotanicalName botName = BotanicalName.NewInstance(Rank.VARIETY());
|
138
|
botName.setGenusOrUninomial("Lepidocaryum");
|
139
|
botName.setSpecificEpithet("tenue");
|
140
|
botName.setInfraSpecificEpithet("tenue");
|
141
|
assertEquals("", "Lepidocaryum tenue var. tenue", botName.getNameCache());
|
142
|
BotanicalName specName = BotanicalName.NewInstance(Rank.SPECIES());
|
143
|
specName.setGenusOrUninomial("Genus");
|
144
|
specName.setSpecificEpithet("");
|
145
|
assertEquals("Empty species string must not result in trailing whitespace", "Genus", specName.getNameCache());
|
146
|
|
147
|
//unranked taxa
|
148
|
String unrankedCache;
|
149
|
BotanicalName unrankedName = BotanicalName.NewInstance(Rank.INFRASPECIFICTAXON());
|
150
|
unrankedName.setGenusOrUninomial("Genus");
|
151
|
NonViralNameDefaultCacheStrategy<BotanicalName> strategy = NonViralNameDefaultCacheStrategy.NewInstance();
|
152
|
//infraspecific
|
153
|
unrankedName.setInfraSpecificEpithet("infraspecific");
|
154
|
unrankedName.setSpecificEpithet("species");
|
155
|
unrankedCache = strategy.getNameCache(unrankedName);
|
156
|
|
157
|
Assert.assertEquals("Correct unranked cache expected", "Genus species [infraspec.] infraspecific", unrankedCache);
|
158
|
|
159
|
//infrageneric
|
160
|
unrankedName.setRank(Rank.INFRAGENERICTAXON());
|
161
|
unrankedName.setInfraSpecificEpithet(null);
|
162
|
unrankedName.setSpecificEpithet(null);
|
163
|
unrankedName.setInfraGenericEpithet("Infrageneric");
|
164
|
unrankedCache = strategy.getNameCache(unrankedName);
|
165
|
Assert.assertEquals("Correct unranked cache expected", "Genus [infragen.] Infrageneric", unrankedCache);
|
166
|
|
167
|
|
168
|
}
|
169
|
|
170
|
/**
|
171
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#getNameCache(eu.etaxonomy.cdm.model.name.NonViralName)}.
|
172
|
*/
|
173
|
@Test
|
174
|
public void testNameCacheWithInfraGenericEpithet() {
|
175
|
speciesName.setInfraGenericEpithet("Infraabies");
|
176
|
assertEquals("Species Name should be Abies (Infraabies) alba", "Abies (Infraabies) alba", speciesName.getNameCache());
|
177
|
|
178
|
BotanicalName botName = BotanicalName.NewInstance(Rank.VARIETY());
|
179
|
botName.setGenusOrUninomial("Lepidocaryum");
|
180
|
botName.setInfraGenericEpithet("Infralepi");
|
181
|
botName.setSpecificEpithet("tenue");
|
182
|
botName.setInfraSpecificEpithet("tenue");
|
183
|
assertEquals("Name cache should be Lepidocaryum (Infralepi) tenue var. tenue", "Lepidocaryum (Infralepi) tenue var. tenue", botName.getNameCache());
|
184
|
|
185
|
botName.setInfraGenericEpithet(" ");
|
186
|
//Note: This test may fail if aspectj doesn't work correctly
|
187
|
assertEquals("Empty infrageneric epithet must be neglegted", "Lepidocaryum tenue var. tenue", botName.getNameCache());
|
188
|
}
|
189
|
|
190
|
/**
|
191
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#getAuthorshipCache(eu.etaxonomy.cdm.model.name.NonViralName)}.
|
192
|
*/
|
193
|
@Test
|
194
|
public void testGetAuthorshipCache() {
|
195
|
this.speciesName.setCombinationAuthorTeam(author);
|
196
|
assertEquals(author.getNomenclaturalTitle(), speciesName.getAuthorshipCache());
|
197
|
this.speciesName.setBasionymAuthorTeam(basAuthor);
|
198
|
String expected = strategy.getBasionymStart()+ basAuthor.getNomenclaturalTitle()+strategy.getBasionymEnd()+strategy.getBasionymAuthorCombinationAuthorSeperator()+author.getNomenclaturalTitle();
|
199
|
assertEquals(expected, speciesName.getAuthorshipCache());
|
200
|
String authorshipcache = "authorshipcache";
|
201
|
speciesName.setAuthorshipCache(authorshipcache);
|
202
|
assertEquals(authorshipcache, speciesName.getAuthorshipCache());
|
203
|
speciesName.setCombinationAuthorTeam(exAuthor);
|
204
|
assertEquals(authorshipcache, speciesName.getAuthorshipCache()); //cache is protected
|
205
|
assertEquals(speciesNameString + " " + authorshipcache, speciesName.getFullTitleCache());
|
206
|
//unprotected
|
207
|
speciesName.setProtectedAuthorshipCache(false);
|
208
|
String atomizedAuthorCache = strategy.getBasionymStart()+ basAuthor.getNomenclaturalTitle()+strategy.getBasionymEnd()+strategy.getBasionymAuthorCombinationAuthorSeperator()+exAuthor.getNomenclaturalTitle();
|
209
|
assertEquals(atomizedAuthorCache, speciesName.getAuthorshipCache());
|
210
|
String atomizedTitleCache = speciesNameString + " "+ strategy.getBasionymStart()+ basAuthor.getNomenclaturalTitle()+strategy.getBasionymEnd()+strategy.getBasionymAuthorCombinationAuthorSeperator()+exAuthor.getNomenclaturalTitle();
|
211
|
//Note: This test may fail if aspectj doesn't work correctly
|
212
|
assertEquals(atomizedTitleCache, speciesName.getTitleCache());
|
213
|
assertEquals(atomizedTitleCache, speciesName.getFullTitleCache());
|
214
|
}
|
215
|
|
216
|
/**
|
217
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#getAuthorshipCache(eu.etaxonomy.cdm.model.name.NonViralName)}.
|
218
|
*/
|
219
|
@Test
|
220
|
public void testHybridNames() {
|
221
|
//Note \u00D7 : hybrid sign (multiplication sign)
|
222
|
this.speciesName.setCombinationAuthorTeam(author);
|
223
|
Assert.assertEquals(author.getNomenclaturalTitle(), speciesName.getAuthorshipCache());
|
224
|
Assert.assertEquals("Should be Abies alba L.", "Abies alba L.", speciesName.getTitleCache());
|
225
|
|
226
|
speciesName.setBinomHybrid(true);
|
227
|
//Note: This test may fail if aspectj doesn't work correctly
|
228
|
Assert.assertEquals("Should be Abies \u00D7alba L.", "Abies \u00D7alba L.", speciesName.getTitleCache());
|
229
|
speciesName.setMonomHybrid(true);
|
230
|
Assert.assertEquals("Should be '\u00D7Abies \u00D7alba L.'", "\u00D7Abies \u00D7alba L.", speciesName.getTitleCache());
|
231
|
|
232
|
Assert.assertEquals("Should be 'Genus'", "Genus", genusName.getTitleCache());
|
233
|
genusName.setMonomHybrid(true);
|
234
|
Assert.assertEquals("Should be '\u00D7Genus'", "\u00D7Genus", genusName.getTitleCache());
|
235
|
|
236
|
Assert.assertEquals("Should be 'Abies alba subsp. beta'", subSpeciesNameString, subSpeciesName.getTitleCache());
|
237
|
subSpeciesName.setTrinomHybrid(true);
|
238
|
Assert.assertEquals("Should be 'Abies alba subsp. \u00D7beta'", "Abies alba subsp. \u00D7beta", subSpeciesName.getTitleCache());
|
239
|
subSpeciesName.setMonomHybrid(true);
|
240
|
Assert.assertEquals("Should be '\u00D7Abies alba subsp. \u00D7beta'", "\u00D7Abies alba subsp. \u00D7beta", subSpeciesName.getTitleCache());
|
241
|
}
|
242
|
|
243
|
@Test
|
244
|
public void testHybridFormula(){
|
245
|
this.speciesName.setCombinationAuthorTeam(author);
|
246
|
Assert.assertEquals(author.getNomenclaturalTitle(), speciesName.getAuthorshipCache());
|
247
|
Assert.assertEquals("Should be 'Abies alba L.'", "Abies alba L.", speciesName.getTitleCache());
|
248
|
|
249
|
NonViralName hybridName = NonViralName.NewInstance(Rank.SPECIES());
|
250
|
NonViralName secondParent = NonViralName.NewInstance(Rank.SPECIES());
|
251
|
|
252
|
secondParent.setTitleCache("Second parent Mill.", true);
|
253
|
hybridName.addHybridParent(speciesName, HybridRelationshipType.FIRST_PARENT(), null);
|
254
|
hybridName.addHybridParent(secondParent, HybridRelationshipType.SECOND_PARENT(), null);
|
255
|
hybridName.setHybridFormula(true);
|
256
|
|
257
|
Assert.assertEquals("", "Abies alba L. \u00D7 Second parent Mill.", hybridName.getTitleCache());
|
258
|
|
259
|
}
|
260
|
|
261
|
@Test
|
262
|
public void testCacheListener() {
|
263
|
Reference ref = ReferenceFactory.newGeneric();
|
264
|
ref.setTitleCache("GenericRef",true);
|
265
|
this.subSpeciesName.setNomenclaturalReference(ref);
|
266
|
Assert.assertEquals("Expected full title cache has error", "Abies alba subsp. beta, GenericRef", subSpeciesName.getFullTitleCache());
|
267
|
subSpeciesName.setCombinationAuthorTeam(author);
|
268
|
subSpeciesName.setBasionymAuthorTeam(basAuthor);
|
269
|
Assert.assertEquals("Expected full title cache has error", "Abies alba subsp. beta (Basio, A.) L., GenericRef", subSpeciesName.getFullTitleCache());
|
270
|
//cascade name change to fullTitleCache
|
271
|
subSpeciesName.setRank(Rank.SPECIES());
|
272
|
subSpeciesName.setProtectedNameCache(true);
|
273
|
Assert.assertNull("name cache should be null", subSpeciesName.getNameCache());
|
274
|
subSpeciesName.setProtectedNameCache(false);
|
275
|
Assert.assertNotNull("name cache should not be null", subSpeciesName.getNameCache());
|
276
|
Assert.assertEquals("Expected full title cache has error", "Abies alba (Basio, A.) L., GenericRef", subSpeciesName.getFullTitleCache());
|
277
|
Assert.assertEquals("Expected full title cache has error", "Abies alba (Basio, A.) L.", subSpeciesName.getTitleCache());
|
278
|
Assert.assertEquals("Expected full title cache has error", "Abies alba", subSpeciesName.getNameCache());
|
279
|
|
280
|
subSpeciesName.setProtectedNameCache(true);
|
281
|
subSpeciesName.setSpecificEpithet("gamma");
|
282
|
Assert.assertEquals("Expected full title cache has error", "Abies alba (Basio, A.) L., GenericRef", subSpeciesName.getFullTitleCache());
|
283
|
Assert.assertEquals("Expected full title cache has error", "Abies alba (Basio, A.) L.", subSpeciesName.getTitleCache());
|
284
|
Assert.assertEquals("Expected full title cache has error", "Abies alba", subSpeciesName.getNameCache());
|
285
|
//make original status
|
286
|
subSpeciesName.setRank(Rank.SUBSPECIES());
|
287
|
Assert.assertEquals("Expected full title cache has error", "Abies alba (Basio, A.) L., GenericRef", subSpeciesName.getFullTitleCache());
|
288
|
|
289
|
//author change
|
290
|
author.setNomenclaturalTitle("M.");
|
291
|
Assert.assertEquals("Expected full title cache has error", "(Basio, A.) M.", subSpeciesName.getAuthorshipCache());
|
292
|
Assert.assertEquals("Expected full title cache has error", "Abies alba (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
|
293
|
Assert.assertEquals("Expected full title cache has error", "Abies alba (Basio, A.) M.", subSpeciesName.getTitleCache());
|
294
|
|
295
|
//protectedTitleCache
|
296
|
subSpeciesName.setProtectedTitleCache(true);
|
297
|
subSpeciesName.setProtectedNameCache(false);
|
298
|
subSpeciesName.setGenusOrUninomial("Pinus");
|
299
|
subSpeciesName.setSpecificEpithet("alba");
|
300
|
Assert.assertEquals("Expected full title cache has error", "Pinus alba subsp. beta", subSpeciesName.getNameCache());
|
301
|
Assert.assertEquals("Expected full title cache has error", "Abies alba (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
|
302
|
Assert.assertEquals("Expected full title cache has error", "Abies alba (Basio, A.) M.", subSpeciesName.getTitleCache());
|
303
|
|
304
|
subSpeciesName.setTitleCache("Pinus beta C.", true);
|
305
|
Assert.assertEquals("Expected full title cache has error", "Pinus beta C., GenericRef", subSpeciesName.getFullTitleCache());
|
306
|
subSpeciesName.setProtectedTitleCache(false);
|
307
|
|
308
|
Assert.assertEquals("Expected full title cache has error", "Pinus alba subsp. beta (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
|
309
|
|
310
|
//protected full title cache set
|
311
|
subSpeciesName.setFullTitleCache("ABC");
|
312
|
Assert.assertEquals("Expected full title cache has error", "ABC", subSpeciesName.getFullTitleCache());
|
313
|
subSpeciesName.setProtectedFullTitleCache(false);
|
314
|
Assert.assertEquals("Expected full title cache has error", "Pinus alba subsp. beta (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
|
315
|
|
316
|
//protected title cache set
|
317
|
subSpeciesName.setProtectedTitleCache(false);
|
318
|
Assert.assertEquals("Expected full title cache has error", "Pinus alba subsp. beta (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
|
319
|
|
320
|
//protectedNameCache set
|
321
|
subSpeciesName.setProtectedNameCache(true);
|
322
|
Assert.assertEquals("Expected full title cache has error", "Pinus alba subsp. beta (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
|
323
|
subSpeciesName.setNameCache("P. alba subsp. beta");
|
324
|
Assert.assertEquals("Expected full title cache has error", "P. alba subsp. beta (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
|
325
|
|
326
|
subSpeciesName.setGenusOrUninomial("A.");
|
327
|
subSpeciesName.setProtectedNameCache(false);
|
328
|
Assert.assertEquals("Expected full title cache has error", "A. alba subsp. beta (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
|
329
|
subSpeciesName.setNameCache("P. alba subsp. beta");
|
330
|
Assert.assertEquals("Expected full title cache has error", "P. alba subsp. beta (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
|
331
|
|
332
|
//protected authorship
|
333
|
subSpeciesName.setProtectedAuthorshipCache(true);
|
334
|
Assert.assertEquals("Expected full title cache has error", "P. alba subsp. beta (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
|
335
|
subSpeciesName.setAuthorshipCache("Ciard.");
|
336
|
Assert.assertEquals("Expected full title cache has error", "P. alba subsp. beta Ciard., GenericRef", subSpeciesName.getFullTitleCache());
|
337
|
|
338
|
author.setNomenclaturalTitle("X.");
|
339
|
subSpeciesName.setProtectedAuthorshipCache(false);
|
340
|
Assert.assertEquals("Expected full title cache has error", "P. alba subsp. beta (Basio, A.) X., GenericRef", subSpeciesName.getFullTitleCache());
|
341
|
|
342
|
//clear
|
343
|
subSpeciesName.setProtectedNameCache(false);
|
344
|
Assert.assertEquals("Expected full title cache has error", "A. alba subsp. beta (Basio, A.) X., GenericRef", subSpeciesName.getFullTitleCache());
|
345
|
|
346
|
//appended phrase
|
347
|
subSpeciesName.setProtectedNameCache(true);
|
348
|
Assert.assertEquals("Expected full title cache has error", "A. alba subsp. beta (Basio, A.) X., GenericRef", subSpeciesName.getFullTitleCache());
|
349
|
subSpeciesName.setAppendedPhrase("app phrase");
|
350
|
Assert.assertEquals("Expected full title cache has error", "A. alba subsp. beta (Basio, A.) X., GenericRef", subSpeciesName.getFullTitleCache());
|
351
|
subSpeciesName.setProtectedNameCache(false);
|
352
|
Assert.assertEquals("Expected full title cache has error", "A. alba subsp. beta app phrase (Basio, A.) X., GenericRef", subSpeciesName.getFullTitleCache());
|
353
|
subSpeciesName.setAppendedPhrase("app2 phrase2");
|
354
|
subSpeciesName.setProtectedNameCache(true);
|
355
|
Assert.assertNull("NameCache should be null", subSpeciesName.getNameCache());
|
356
|
subSpeciesName.setProtectedNameCache(false);
|
357
|
subSpeciesName.setAppendedPhrase(null);
|
358
|
|
359
|
|
360
|
//ref + nomRef
|
361
|
Reference book = ReferenceFactory.newBook();
|
362
|
book.setTitle("Booktitle");
|
363
|
Assert.assertNotNull("TitleCache should not be null", subSpeciesName.getTitleCache());
|
364
|
subSpeciesName.setNomenclaturalReference(book);
|
365
|
subSpeciesName.setNomenclaturalMicroReference("22");
|
366
|
Assert.assertEquals("Expected full title cache has error", "A. alba subsp. beta (Basio, A.) X., Booktitle: 22", subSpeciesName.getFullTitleCache());
|
367
|
subSpeciesName.setProtectedTitleCache(true);
|
368
|
Assert.assertNotNull("TitleCache should not be null", subSpeciesName.getTitleCache());
|
369
|
|
370
|
//year
|
371
|
ZoologicalName zooName = ZoologicalName.NewInstance(Rank.SPECIES());
|
372
|
zooName.setGenusOrUninomial("Homo");
|
373
|
zooName.setSpecificEpithet("sapiens");
|
374
|
zooName.setBasionymAuthorTeam(basAuthor);
|
375
|
zooName.setCombinationAuthorTeam(author);
|
376
|
zooName.setNomenclaturalReference(book);
|
377
|
zooName.setNomenclaturalMicroReference("22");
|
378
|
Assert.assertEquals("Expected full title cache has error", "Homo sapiens (Basio, A.) X., Booktitle: 22", zooName.getFullTitleCache());
|
379
|
|
380
|
zooName.setOriginalPublicationYear(1922);
|
381
|
zooName.setPublicationYear(1948);
|
382
|
Assert.assertEquals("Expected full title cache has error", "Homo sapiens (Basio, A., 1922) X., 1948, Booktitle: 22", zooName.getFullTitleCache());
|
383
|
zooName.setOriginalPublicationYear(1923);
|
384
|
zooName.setProtectedAuthorshipCache(true);
|
385
|
Assert.assertNull("AuthorshipCache should be null", zooName.getAuthorshipCache());
|
386
|
zooName.setProtectedAuthorshipCache(false);
|
387
|
Assert.assertNotNull("AuthorshipCache should not be null", zooName.getAuthorshipCache());
|
388
|
zooName.setPublicationYear(1949);
|
389
|
zooName.setProtectedAuthorshipCache(true);
|
390
|
Assert.assertNull("AuthorshipCache should be null", zooName.getAuthorshipCache());
|
391
|
|
392
|
|
393
|
|
394
|
|
395
|
}
|
396
|
|
397
|
/**
|
398
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#setNameAuthorSeperator(java.lang.String)}.
|
399
|
*/
|
400
|
@Test
|
401
|
public void testGetSetNameAuthorSeperator() {
|
402
|
String authorSeparator = "authorSeparator";
|
403
|
strategy.setNameAuthorSeperator(authorSeparator);
|
404
|
assertEquals(authorSeparator, strategy.getNameAuthorSeperator());
|
405
|
strategy.setNameAuthorSeperator(null);
|
406
|
assertNull(strategy.getNameAuthorSeperator());
|
407
|
}
|
408
|
|
409
|
/**
|
410
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#setBasionymStart(java.lang.String)}.
|
411
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#getBasionymStart()}.
|
412
|
*/
|
413
|
@Test
|
414
|
public void testGetSetBasionymStart() {
|
415
|
String basStart = "start";
|
416
|
strategy.setBasionymStart(basStart);
|
417
|
assertEquals(basStart, strategy.getBasionymStart());
|
418
|
strategy.setBasionymStart(null);
|
419
|
assertNull(strategy.getBasionymStart());
|
420
|
}
|
421
|
|
422
|
/**
|
423
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#setBasionymEnd(java.lang.String)}.
|
424
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#getBasionymEnd()}.
|
425
|
*/
|
426
|
@Test
|
427
|
public void testGetSetBasionymEnd() {
|
428
|
String basEnd = "end";
|
429
|
strategy.setBasionymEnd(basEnd);
|
430
|
assertEquals(basEnd, strategy.getBasionymEnd());
|
431
|
strategy.setBasionymEnd(null);
|
432
|
assertNull(strategy.getBasionymEnd());
|
433
|
}
|
434
|
|
435
|
/**
|
436
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#setExAuthorSeperator(java.lang.String)}.
|
437
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#getExAuthorSeperator()}.
|
438
|
*/
|
439
|
@Test
|
440
|
public void testGetSetExAuthorSeperator() {
|
441
|
String exAuthorSeparator = "exAuthorSeparator";
|
442
|
strategy.setExAuthorSeperator(exAuthorSeparator);
|
443
|
assertEquals(exAuthorSeparator, strategy.getExAuthorSeperator());
|
444
|
strategy.setExAuthorSeperator(null);
|
445
|
assertNull(strategy.getExAuthorSeperator());
|
446
|
}
|
447
|
|
448
|
/**
|
449
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#setBasionymAuthorCombinationAuthorSeperator(java.lang.CharSequence)}.
|
450
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#getBasionymAuthorCombinationAuthorSeperator()}.
|
451
|
*/
|
452
|
@Test
|
453
|
public void testSetBasionymAuthorCombinationAuthorSeperator() {
|
454
|
String basComSeparator = "basComSeparator";
|
455
|
strategy.setBasionymAuthorCombinationAuthorSeperator(basComSeparator);
|
456
|
assertEquals(basComSeparator, strategy.getBasionymAuthorCombinationAuthorSeperator());
|
457
|
strategy.setBasionymAuthorCombinationAuthorSeperator(null);
|
458
|
assertNull(strategy.getBasionymAuthorCombinationAuthorSeperator());
|
459
|
}
|
460
|
|
461
|
@Test
|
462
|
public void testGetInfraGenericNames(){
|
463
|
String author = "Anyauthor";
|
464
|
NonViralName nonViralName = NonViralName.NewInstance(Rank.SUBGENUS());
|
465
|
nonViralName.setGenusOrUninomial("Genus");
|
466
|
nonViralName.setInfraGenericEpithet("subgenus");
|
467
|
nonViralName.setAuthorshipCache(author);
|
468
|
|
469
|
//test ordinary infrageneric
|
470
|
String subGenusNameCache = strategy.getInfraGenusNameCache(nonViralName);
|
471
|
assertEquals("Subgenus name should be 'Genus subg. subgenus'.", "Genus subg. subgenus", subGenusNameCache);
|
472
|
String subGenusTitle = strategy.getTitleCache(nonViralName);
|
473
|
assertEquals("Subgenus name should be 'Genus subg. subgenus Anyauthor'.", "Genus subg. subgenus Anyauthor", subGenusTitle);
|
474
|
|
475
|
//test species aggregates and species groups
|
476
|
nonViralName.setRank(Rank.SPECIESAGGREGATE());
|
477
|
nonViralName.setSpecificEpithet("myspecies");
|
478
|
nonViralName.setInfraGenericEpithet(null);
|
479
|
String aggrNameCache = strategy.getInfraGenusNameCache(nonViralName);
|
480
|
assertEquals("Species aggregate name should be 'Genus myspecies aggr.'.", "Genus myspecies aggr.", aggrNameCache);
|
481
|
String aggrNameTitle = strategy.getTitleCache(nonViralName);
|
482
|
Assert.assertTrue("Species aggregate should not include author information.", aggrNameTitle.indexOf(author) == -1);
|
483
|
assertEquals("Species aggregate name should be 'Genus myspecies aggr.'.", "Genus myspecies aggr.", aggrNameTitle);
|
484
|
nonViralName.setRank(Rank.SPECIESGROUP());
|
485
|
String groupNameTitle = strategy.getTitleCache(nonViralName);
|
486
|
assertEquals("Species group name should be 'Genus myspecies species group'.", "Genus myspecies species group", groupNameTitle);
|
487
|
|
488
|
//test species aggregates and species groups with infrageneric information
|
489
|
//TODO check if groups do ever have infrageneric epithets
|
490
|
nonViralName.setRank(Rank.SPECIESAGGREGATE());
|
491
|
nonViralName.setSpecificEpithet("myspecies");
|
492
|
nonViralName.setInfraGenericEpithet("Infragenus");
|
493
|
aggrNameCache = strategy.getInfraGenusNameCache(nonViralName);
|
494
|
assertEquals("Species aggregate name should be 'Genus (Infragenus) myspecies aggr.'.", "Genus (Infragenus) myspecies aggr.", aggrNameCache);
|
495
|
|
496
|
aggrNameTitle = strategy.getTitleCache(nonViralName);
|
497
|
Assert.assertTrue("Species aggregate should not include author information.", aggrNameTitle.indexOf(author) == -1);
|
498
|
assertEquals("Species aggregate name should be 'Genus (Infragenus) myspecies aggr.'.", "Genus (Infragenus) myspecies aggr.", aggrNameTitle);
|
499
|
|
500
|
nonViralName.setRank(Rank.SPECIESGROUP());
|
501
|
groupNameTitle = strategy.getTitleCache(nonViralName);
|
502
|
assertEquals("Species group name should be 'Genus (Infragenus) myspecies species group'.", "Genus (Infragenus) myspecies species group", groupNameTitle);
|
503
|
|
504
|
|
505
|
}
|
506
|
|
507
|
/**
|
508
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#getTaggedName(eu.etaxonomy.cdm.model.name.NonViralName)}.
|
509
|
*/
|
510
|
@Test
|
511
|
public void testGetTaggedNameSpeciesAggregate() {
|
512
|
BotanicalName speciesAggregate = BotanicalName.NewInstance(Rank.SPECIESAGGREGATE());
|
513
|
speciesAggregate.setGenusOrUninomial("Mygenus");
|
514
|
speciesAggregate.setSpecificEpithet("myspecies");
|
515
|
List<Object> taggedName = strategy.getTaggedName(speciesAggregate);
|
516
|
Assert.assertEquals("1rd tag must be genus epithet", "Mygenus", taggedName.get(0));
|
517
|
Assert.assertEquals("2rd tag must be species epithet", "myspecies", taggedName.get(1));
|
518
|
Assert.assertEquals("3rd tag must be aggregate marker", "aggr.",taggedName.get(2));
|
519
|
}
|
520
|
|
521
|
|
522
|
@Test
|
523
|
public void testGetTaggedNameSubspecies(){
|
524
|
List taggedName = strategy.getTaggedName(subSpeciesName);
|
525
|
Assert.assertEquals("First tag should be 'Abies'", "Abies", taggedName.get(0));
|
526
|
Assert.assertEquals("Second tag should be 'alba'", "alba", taggedName.get(1));
|
527
|
Assert.assertEquals("Third tag should be subspecies rank", Rank.SUBSPECIES(), taggedName.get(2));
|
528
|
Assert.assertEquals("Third tag should be subspecies rank, and rank abbreviatioin should be subsp.", "subsp.", ((Rank)taggedName.get(2)).getAbbreviation() );
|
529
|
Assert.assertEquals("Fourth tag should be 'beta'", "beta", taggedName.get(3));
|
530
|
//to be continued
|
531
|
|
532
|
}
|
533
|
|
534
|
|
535
|
}
|