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.apache.log4j.Logger;
|
18
|
import org.junit.Assert;
|
19
|
import org.junit.Before;
|
20
|
import org.junit.BeforeClass;
|
21
|
import org.junit.Test;
|
22
|
|
23
|
import eu.etaxonomy.cdm.model.agent.Person;
|
24
|
import eu.etaxonomy.cdm.model.agent.Team;
|
25
|
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
|
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.NameRelationshipType;
|
30
|
import eu.etaxonomy.cdm.model.name.NonViralName;
|
31
|
import eu.etaxonomy.cdm.model.name.Rank;
|
32
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
33
|
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
|
34
|
import eu.etaxonomy.cdm.model.name.ZoologicalName;
|
35
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
36
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
37
|
import eu.etaxonomy.cdm.strategy.cache.HTMLTagRules;
|
38
|
import eu.etaxonomy.cdm.strategy.cache.TagEnum;
|
39
|
import eu.etaxonomy.cdm.strategy.cache.TaggedCacheHelper;
|
40
|
import eu.etaxonomy.cdm.strategy.cache.TaggedText;
|
41
|
|
42
|
/**
|
43
|
* @author a.mueller
|
44
|
* @created 26.11.2008
|
45
|
*/
|
46
|
public class NonViralNameDefaultCacheStrategyTest extends NameCacheStrategyTestBase{
|
47
|
@SuppressWarnings("unused")
|
48
|
private static final Logger logger = Logger.getLogger(NonViralNameDefaultCacheStrategyTest.class);
|
49
|
|
50
|
private NonViralNameDefaultCacheStrategy<NonViralName> strategy;
|
51
|
|
52
|
private static final String familyNameString = "Familia";
|
53
|
private static final String genusNameString = "Genus";
|
54
|
private static final String speciesNameString = "Abies alba";
|
55
|
private static final String subSpeciesNameString = "Abies alba subsp. beta";
|
56
|
private static final String appendedPhraseString = "app phrase";
|
57
|
|
58
|
private static final String authorString = "L.";
|
59
|
private static final String exAuthorString = "Exaut.";
|
60
|
private static final String basAuthorString = "Basio, A.";
|
61
|
private static final String exBasAuthorString = "ExBas. N.";
|
62
|
|
63
|
private static final String referenceTitle = "My Reference";
|
64
|
|
65
|
private BotanicalName familyName;
|
66
|
private BotanicalName genusName;
|
67
|
private BotanicalName subGenusName;
|
68
|
private BotanicalName speciesName;
|
69
|
private BotanicalName subSpeciesName;
|
70
|
private TeamOrPersonBase<?> author;
|
71
|
private TeamOrPersonBase<?> exAuthor;
|
72
|
private TeamOrPersonBase<?> basAuthor;
|
73
|
private TeamOrPersonBase<?> exBasAuthor;
|
74
|
private Reference citationRef;
|
75
|
|
76
|
@BeforeClass
|
77
|
public static void setUpBeforeClass() {
|
78
|
DefaultTermInitializer vocabularyStore = new DefaultTermInitializer();
|
79
|
vocabularyStore.initialize();
|
80
|
}
|
81
|
|
82
|
/**
|
83
|
* @throws java.lang.Exception
|
84
|
*/
|
85
|
@Before
|
86
|
public void setUp() throws Exception {
|
87
|
strategy = NonViralNameDefaultCacheStrategy.NewInstance();
|
88
|
familyName = TaxonNameBase.PARSED_BOTANICAL(familyNameString, Rank.FAMILY());
|
89
|
genusName = TaxonNameBase.PARSED_BOTANICAL(genusNameString, Rank.GENUS());
|
90
|
|
91
|
subGenusName = TaxonNameFactory.NewBotanicalInstance(Rank.SUBGENUS());
|
92
|
subGenusName.setGenusOrUninomial("Genus");
|
93
|
subGenusName.setInfraGenericEpithet("InfraGenericPart");
|
94
|
|
95
|
speciesName = TaxonNameBase.PARSED_BOTANICAL(speciesNameString);
|
96
|
subSpeciesName = TaxonNameBase.PARSED_BOTANICAL(subSpeciesNameString);
|
97
|
|
98
|
author = Person.NewInstance();
|
99
|
author.setNomenclaturalTitle(authorString);
|
100
|
exAuthor = Person.NewInstance();
|
101
|
exAuthor.setNomenclaturalTitle(exAuthorString);
|
102
|
basAuthor = Person.NewInstance();
|
103
|
basAuthor.setNomenclaturalTitle(basAuthorString);
|
104
|
exBasAuthor = Person.NewInstance();
|
105
|
exBasAuthor.setNomenclaturalTitle(exBasAuthorString);
|
106
|
|
107
|
citationRef = ReferenceFactory.newGeneric();
|
108
|
citationRef.setTitleCache(referenceTitle, true);
|
109
|
|
110
|
}
|
111
|
|
112
|
//**************************** TESTS **************************************************
|
113
|
|
114
|
/**
|
115
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#getTitleCache(eu.etaxonomy.cdm.model.name.NonViralName)}.
|
116
|
*/
|
117
|
@Test
|
118
|
public void testGetTitleCache() {
|
119
|
Assert.assertEquals(speciesNameString, speciesName.getTitleCache());
|
120
|
//TODO not yet completed
|
121
|
}
|
122
|
|
123
|
/**
|
124
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#getFullTitleCache(eu.etaxonomy.cdm.model.name.NonViralName)}.
|
125
|
*/
|
126
|
@Test
|
127
|
public void testGetFullTitleCache() {
|
128
|
subSpeciesName.setNomenclaturalReference(citationRef);
|
129
|
Assert.assertEquals(subSpeciesNameString + ", " + referenceTitle, subSpeciesName.getFullTitleCache());
|
130
|
//TODO not yet completed
|
131
|
}
|
132
|
|
133
|
@Test
|
134
|
public void testGattungsAutonyme() {
|
135
|
BotanicalName botName = TaxonNameFactory.NewBotanicalInstance(Rank.SECTION_BOTANY());
|
136
|
String strTaraxacum = "Traxacum";
|
137
|
botName.setGenusOrUninomial(strTaraxacum);
|
138
|
botName.setInfraGenericEpithet(strTaraxacum);
|
139
|
botName.setAuthorshipCache("Author");
|
140
|
Assert.assertFalse(botName.getFullTitleCache().contains("bot."));
|
141
|
//TODO #4288
|
142
|
System.out.println(botName.getFullTitleCache());
|
143
|
}
|
144
|
|
145
|
|
146
|
|
147
|
/**
|
148
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#getNameCache(eu.etaxonomy.cdm.model.name.NonViralName)}.
|
149
|
*/
|
150
|
@Test
|
151
|
public void testGetNameCache() {
|
152
|
assertEquals("Species Name should be Abies alba", speciesNameString, speciesName.getNameCache());
|
153
|
speciesName.setNameCache("Any species");
|
154
|
assertEquals("Species Name should be Any species", "Any species", speciesName.getNameCache());
|
155
|
assertEquals("Species Name should be Any species", "Any species", speciesName.getTitleCache());
|
156
|
assertEquals("subSpeciesNameString should be correct", subSpeciesNameString, subSpeciesName.getNameCache());
|
157
|
BotanicalName botName = TaxonNameFactory.NewBotanicalInstance(Rank.VARIETY());
|
158
|
botName.setGenusOrUninomial("Lepidocaryum");
|
159
|
botName.setSpecificEpithet("tenue");
|
160
|
botName.setInfraSpecificEpithet("tenue");
|
161
|
assertEquals("", "Lepidocaryum tenue var. tenue", botName.getNameCache());
|
162
|
BotanicalName specName = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
163
|
specName.setGenusOrUninomial("Genus");
|
164
|
specName.setSpecificEpithet("");
|
165
|
assertEquals("Empty species string must not result in trailing whitespace", "Genus", specName.getNameCache());
|
166
|
|
167
|
//unranked taxa
|
168
|
String unrankedCache;
|
169
|
BotanicalName unrankedName = TaxonNameFactory.NewBotanicalInstance(Rank.INFRASPECIFICTAXON());
|
170
|
unrankedName.setGenusOrUninomial("Genus");
|
171
|
NonViralNameDefaultCacheStrategy<BotanicalName> strategy = NonViralNameDefaultCacheStrategy.NewInstance();
|
172
|
//infraspecific
|
173
|
unrankedName.setInfraSpecificEpithet("infraspecific");
|
174
|
unrankedName.setSpecificEpithet("species");
|
175
|
unrankedCache = strategy.getNameCache(unrankedName);
|
176
|
|
177
|
Assert.assertEquals("Correct unranked cache expected", "Genus species [infraspec.] infraspecific", unrankedCache);
|
178
|
|
179
|
//infrageneric
|
180
|
unrankedName.setRank(Rank.INFRAGENERICTAXON());
|
181
|
unrankedName.setInfraSpecificEpithet(null);
|
182
|
unrankedName.setSpecificEpithet(null);
|
183
|
unrankedName.setInfraGenericEpithet("Infrageneric");
|
184
|
unrankedCache = strategy.getNameCache(unrankedName);
|
185
|
Assert.assertEquals("Correct unranked cache expected", "Genus [unranked] Infrageneric", unrankedCache);
|
186
|
|
187
|
//bot. specific ranks
|
188
|
botName = TaxonNameFactory.NewBotanicalInstance(Rank.SECTION_BOTANY());
|
189
|
botName.setGenusOrUninomial("Genus");
|
190
|
botName.setInfraGenericEpithet("Infragenus");
|
191
|
Assert.assertEquals("", "Genus sect. Infragenus", botName.getNameCache());
|
192
|
botName.setRank(Rank.SUBSECTION_BOTANY());
|
193
|
Assert.assertEquals("", "Genus subsect. Infragenus", botName.getNameCache());
|
194
|
|
195
|
//zool. specific ranks (we don't have markers here therefore no problem should exist
|
196
|
ZoologicalName zooName = TaxonNameFactory.NewZoologicalInstance(Rank.SECTION_ZOOLOGY());
|
197
|
zooName.setGenusOrUninomial("Genus");
|
198
|
zooName.setInfraGenericEpithet("Infragenus");
|
199
|
Assert.assertEquals("", "Genus", zooName.getNameCache());
|
200
|
zooName.setRank(Rank.SUBSECTION_ZOOLOGY());
|
201
|
Assert.assertEquals("", "Genus", zooName.getNameCache());
|
202
|
|
203
|
}
|
204
|
|
205
|
/**
|
206
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#getNameCache(eu.etaxonomy.cdm.model.name.NonViralName)}.
|
207
|
*/
|
208
|
@Test
|
209
|
public void testNameCacheWithInfraGenericEpithet() {
|
210
|
speciesName.setInfraGenericEpithet("Infraabies");
|
211
|
assertEquals("Species Name should be Abies (Infraabies) alba", "Abies (Infraabies) alba", speciesName.getNameCache());
|
212
|
|
213
|
BotanicalName botName = TaxonNameFactory.NewBotanicalInstance(Rank.VARIETY());
|
214
|
botName.setGenusOrUninomial("Lepidocaryum");
|
215
|
botName.setInfraGenericEpithet("Infralepi");
|
216
|
botName.setSpecificEpithet("tenue");
|
217
|
botName.setInfraSpecificEpithet("tenue");
|
218
|
assertEquals("Name cache should be Lepidocaryum (Infralepi) tenue var. tenue", "Lepidocaryum (Infralepi) tenue var. tenue", botName.getNameCache());
|
219
|
|
220
|
botName.setInfraGenericEpithet(" ");
|
221
|
//Note: This test may fail if aspectj doesn't work correctly
|
222
|
assertEquals("Empty infrageneric epithet must be neglegted", "Lepidocaryum tenue var. tenue", botName.getNameCache());
|
223
|
}
|
224
|
|
225
|
/**
|
226
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#getAuthorshipCache(eu.etaxonomy.cdm.model.name.NonViralName)}.
|
227
|
*/
|
228
|
@Test
|
229
|
public void testGetAuthorshipCache() {
|
230
|
this.speciesName.setCombinationAuthorship(author);
|
231
|
assertEquals(author.getNomenclaturalTitle(), speciesName.getAuthorshipCache());
|
232
|
this.speciesName.setBasionymAuthorship(basAuthor);
|
233
|
String expected = strategy.getBasionymStart()+ basAuthor.getNomenclaturalTitle()+strategy.getBasionymEnd()+strategy.getBasionymAuthorCombinationAuthorSeperator()+author.getNomenclaturalTitle();
|
234
|
assertEquals(expected, speciesName.getAuthorshipCache());
|
235
|
String authorshipcache = "authorshipcache";
|
236
|
speciesName.setAuthorshipCache(authorshipcache);
|
237
|
assertEquals(authorshipcache, speciesName.getAuthorshipCache());
|
238
|
speciesName.setCombinationAuthorship(exAuthor);
|
239
|
assertEquals(authorshipcache, speciesName.getAuthorshipCache()); //cache is protected
|
240
|
assertEquals(speciesNameString + " " + authorshipcache, speciesName.getFullTitleCache());
|
241
|
//unprotected
|
242
|
speciesName.setProtectedAuthorshipCache(false);
|
243
|
String atomizedAuthorCache = strategy.getBasionymStart()+ basAuthor.getNomenclaturalTitle()+strategy.getBasionymEnd()+strategy.getBasionymAuthorCombinationAuthorSeperator()+exAuthor.getNomenclaturalTitle();
|
244
|
assertEquals(atomizedAuthorCache, speciesName.getAuthorshipCache());
|
245
|
String atomizedTitleCache = speciesNameString + " "+ strategy.getBasionymStart()+ basAuthor.getNomenclaturalTitle()+strategy.getBasionymEnd()+strategy.getBasionymAuthorCombinationAuthorSeperator()+exAuthor.getNomenclaturalTitle();
|
246
|
//Note: This test may fail if aspectj doesn't work correctly
|
247
|
assertEquals(atomizedTitleCache, speciesName.getTitleCache());
|
248
|
assertEquals(atomizedTitleCache, speciesName.getFullTitleCache());
|
249
|
}
|
250
|
|
251
|
/**
|
252
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#getAuthorshipCache(eu.etaxonomy.cdm.model.name.NonViralName)}.
|
253
|
*/
|
254
|
@Test
|
255
|
public void testHybridNames() {
|
256
|
//Note \u00D7 : hybrid sign (multiplication sign)
|
257
|
this.speciesName.setCombinationAuthorship(author);
|
258
|
Assert.assertEquals(author.getNomenclaturalTitle(), speciesName.getAuthorshipCache());
|
259
|
Assert.assertEquals("Should be Abies alba L.", "Abies alba L.", speciesName.getTitleCache());
|
260
|
|
261
|
speciesName.setBinomHybrid(true);
|
262
|
//Note: This test may fail if aspectj doesn't work correctly
|
263
|
Assert.assertEquals("Should be Abies \u00D7alba L.", "Abies \u00D7alba L.", speciesName.getTitleCache());
|
264
|
speciesName.setMonomHybrid(true);
|
265
|
Assert.assertEquals("Should be '\u00D7Abies \u00D7alba L.'", "\u00D7Abies \u00D7alba L.", speciesName.getTitleCache());
|
266
|
|
267
|
Assert.assertEquals("Should be 'Genus'", "Genus", genusName.getTitleCache());
|
268
|
genusName.setMonomHybrid(true);
|
269
|
Assert.assertEquals("Should be '\u00D7Genus'", "\u00D7Genus", genusName.getTitleCache());
|
270
|
|
271
|
Assert.assertEquals("Should be 'Abies alba subsp. beta'", subSpeciesNameString, subSpeciesName.getTitleCache());
|
272
|
subSpeciesName.setTrinomHybrid(true);
|
273
|
Assert.assertEquals("Should be 'Abies alba nothosubsp. beta or nbeta'", "Abies alba nothosubsp. beta", subSpeciesName.getTitleCache());
|
274
|
subSpeciesName.setMonomHybrid(true);
|
275
|
Assert.assertEquals("Should be '\u00D7Abies alba nothosubsp. beta'", "\u00D7Abies alba nothosubsp. beta", subSpeciesName.getTitleCache());
|
276
|
|
277
|
Assert.assertEquals("Should be 'Genus subg. InfraGenericPart'", "Genus subg. InfraGenericPart", subGenusName.getTitleCache());
|
278
|
subGenusName.setBinomHybrid(true);
|
279
|
Assert.assertEquals("Should be 'Genus nothosubg. InfraGenericPart'", "Genus nothosubg. InfraGenericPart", subGenusName.getTitleCache());
|
280
|
}
|
281
|
|
282
|
@Test
|
283
|
public void testHybridFormula(){
|
284
|
this.speciesName.setCombinationAuthorship(author);
|
285
|
Assert.assertEquals(author.getNomenclaturalTitle(), speciesName.getAuthorshipCache());
|
286
|
Assert.assertEquals("Should be 'Abies alba L.'", "Abies alba L.", speciesName.getTitleCache());
|
287
|
|
288
|
NonViralName<?> hybridName = TaxonNameFactory.NewNonViralInstance(Rank.SPECIES());
|
289
|
NonViralName<?> secondParent = TaxonNameFactory.NewNonViralInstance(Rank.SPECIES());
|
290
|
|
291
|
secondParent.setTitleCache("Second parent Mill.", true);
|
292
|
hybridName.addHybridParent(speciesName, HybridRelationshipType.FIRST_PARENT(), null);
|
293
|
hybridName.addHybridParent(secondParent, HybridRelationshipType.SECOND_PARENT(), null);
|
294
|
hybridName.setHybridFormula(true);
|
295
|
|
296
|
Assert.assertEquals("", "Abies alba L. \u00D7 Second parent Mill.", hybridName.getTitleCache());
|
297
|
|
298
|
}
|
299
|
|
300
|
//TODO add more tests when specification is clearer
|
301
|
@Test
|
302
|
public void testOriginalSpelling() {
|
303
|
NameRelationshipType origSpellingType = NameRelationshipType.ORIGINAL_SPELLING();
|
304
|
NonViralName<?> originalName = (NonViralName<?>)speciesName.clone();
|
305
|
originalName.setSpecificEpithet("alpa");
|
306
|
Assert.assertEquals("Preconditions are wrong", "Abies alpa", originalName.getNameCache());
|
307
|
|
308
|
speciesName.addRelationshipFromName(originalName, origSpellingType, null);
|
309
|
Assert.assertEquals("Abies alba 'alpa'", speciesName.getNameCache());
|
310
|
originalName.setGenusOrUninomial("Apies");
|
311
|
|
312
|
speciesName.setNameCache(null, false);
|
313
|
//TODO update cache of current name (species name)
|
314
|
Assert.assertEquals("Abies alba 'Apies alpa'", speciesName.getNameCache());
|
315
|
|
316
|
//TODO add more tests when specification of exact behaviour is clearer
|
317
|
}
|
318
|
|
319
|
@Test
|
320
|
public void testCacheListener() {
|
321
|
Reference ref = ReferenceFactory.newGeneric();
|
322
|
ref.setTitleCache("GenericRef",true);
|
323
|
this.subSpeciesName.setNomenclaturalReference(ref);
|
324
|
Assert.assertEquals("Expected full title cache has error", "Abies alba subsp. beta, GenericRef", subSpeciesName.getFullTitleCache());
|
325
|
subSpeciesName.setCombinationAuthorship(author);
|
326
|
subSpeciesName.setBasionymAuthorship(basAuthor);
|
327
|
Assert.assertEquals("Expected full title cache has error", "Abies alba subsp. beta (Basio, A.) L., GenericRef", subSpeciesName.getFullTitleCache());
|
328
|
//cascade name change to fullTitleCache
|
329
|
subSpeciesName.setRank(Rank.SPECIES());
|
330
|
subSpeciesName.setProtectedNameCache(true);
|
331
|
Assert.assertNull("name cache should be null", subSpeciesName.getNameCache());
|
332
|
subSpeciesName.setProtectedNameCache(false);
|
333
|
Assert.assertNotNull("name cache should not be null", subSpeciesName.getNameCache());
|
334
|
Assert.assertEquals("Expected full title cache has error", "Abies alba (Basio, A.) L., GenericRef", subSpeciesName.getFullTitleCache());
|
335
|
Assert.assertEquals("Expected full title cache has error", "Abies alba (Basio, A.) L.", subSpeciesName.getTitleCache());
|
336
|
Assert.assertEquals("Expected full title cache has error", "Abies alba", subSpeciesName.getNameCache());
|
337
|
|
338
|
subSpeciesName.setProtectedNameCache(true);
|
339
|
subSpeciesName.setSpecificEpithet("gamma");
|
340
|
Assert.assertEquals("Expected full title cache has error", "Abies alba (Basio, A.) L., GenericRef", subSpeciesName.getFullTitleCache());
|
341
|
Assert.assertEquals("Expected full title cache has error", "Abies alba (Basio, A.) L.", subSpeciesName.getTitleCache());
|
342
|
Assert.assertEquals("Expected full title cache has error", "Abies alba", subSpeciesName.getNameCache());
|
343
|
//make original status
|
344
|
subSpeciesName.setRank(Rank.SUBSPECIES());
|
345
|
Assert.assertEquals("Expected full title cache has error", "Abies alba (Basio, A.) L., GenericRef", subSpeciesName.getFullTitleCache());
|
346
|
|
347
|
//author change
|
348
|
author.setNomenclaturalTitle("M.");
|
349
|
Assert.assertEquals("Expected full title cache has error", "(Basio, A.) M.", subSpeciesName.getAuthorshipCache());
|
350
|
Assert.assertEquals("Expected full title cache has error", "Abies alba (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
|
351
|
Assert.assertEquals("Expected full title cache has error", "Abies alba (Basio, A.) M.", subSpeciesName.getTitleCache());
|
352
|
|
353
|
//protectedTitleCache
|
354
|
subSpeciesName.setProtectedTitleCache(true);
|
355
|
subSpeciesName.setProtectedNameCache(false);
|
356
|
subSpeciesName.setGenusOrUninomial("Pinus");
|
357
|
subSpeciesName.setSpecificEpithet("alba");
|
358
|
Assert.assertEquals("Expected full title cache has error", "Pinus alba subsp. beta", subSpeciesName.getNameCache());
|
359
|
Assert.assertEquals("Expected full title cache has error", "Abies alba (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
|
360
|
Assert.assertEquals("Expected full title cache has error", "Abies alba (Basio, A.) M.", subSpeciesName.getTitleCache());
|
361
|
|
362
|
subSpeciesName.setTitleCache("Pinus beta C.", true);
|
363
|
Assert.assertEquals("Expected full title cache has error", "Pinus beta C., GenericRef", subSpeciesName.getFullTitleCache());
|
364
|
subSpeciesName.setProtectedTitleCache(false);
|
365
|
|
366
|
Assert.assertEquals("Expected full title cache has error", "Pinus alba subsp. beta (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
|
367
|
|
368
|
//protected full title cache set
|
369
|
subSpeciesName.setFullTitleCache("ABC");
|
370
|
Assert.assertEquals("Expected full title cache has error", "ABC", subSpeciesName.getFullTitleCache());
|
371
|
subSpeciesName.setProtectedFullTitleCache(false);
|
372
|
Assert.assertEquals("Expected full title cache has error", "Pinus alba subsp. beta (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
|
373
|
|
374
|
//protected title cache set
|
375
|
subSpeciesName.setProtectedTitleCache(false);
|
376
|
Assert.assertEquals("Expected full title cache has error", "Pinus alba subsp. beta (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
|
377
|
|
378
|
//protectedNameCache set
|
379
|
subSpeciesName.setProtectedNameCache(true);
|
380
|
Assert.assertEquals("Expected full title cache has error", "Pinus alba subsp. beta (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
|
381
|
subSpeciesName.setNameCache("P. alba subsp. beta");
|
382
|
Assert.assertEquals("Expected full title cache has error", "P. alba subsp. beta (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
|
383
|
|
384
|
subSpeciesName.setGenusOrUninomial("A.");
|
385
|
subSpeciesName.setProtectedNameCache(false);
|
386
|
Assert.assertEquals("Expected full title cache has error", "A. alba subsp. beta (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
|
387
|
subSpeciesName.setNameCache("P. alba subsp. beta");
|
388
|
Assert.assertEquals("Expected full title cache has error", "P. alba subsp. beta (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
|
389
|
|
390
|
//protected authorship
|
391
|
subSpeciesName.setProtectedAuthorshipCache(true);
|
392
|
Assert.assertEquals("Expected full title cache has error", "P. alba subsp. beta (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
|
393
|
subSpeciesName.setAuthorshipCache("Ciard.");
|
394
|
Assert.assertEquals("Expected full title cache has error", "P. alba subsp. beta Ciard., GenericRef", subSpeciesName.getFullTitleCache());
|
395
|
|
396
|
author.setNomenclaturalTitle("X.");
|
397
|
subSpeciesName.setProtectedAuthorshipCache(false);
|
398
|
Assert.assertEquals("Expected full title cache has error", "P. alba subsp. beta (Basio, A.) X., GenericRef", subSpeciesName.getFullTitleCache());
|
399
|
|
400
|
//clear
|
401
|
subSpeciesName.setProtectedNameCache(false);
|
402
|
Assert.assertEquals("Expected full title cache has error", "A. alba subsp. beta (Basio, A.) X., GenericRef", subSpeciesName.getFullTitleCache());
|
403
|
|
404
|
//appended phrase
|
405
|
subSpeciesName.setProtectedNameCache(true);
|
406
|
Assert.assertEquals("Expected full title cache has error", "A. alba subsp. beta (Basio, A.) X., GenericRef", subSpeciesName.getFullTitleCache());
|
407
|
subSpeciesName.setAppendedPhrase("app phrase");
|
408
|
Assert.assertEquals("Expected full title cache has error", "A. alba subsp. beta (Basio, A.) X., GenericRef", subSpeciesName.getFullTitleCache());
|
409
|
subSpeciesName.setProtectedNameCache(false);
|
410
|
Assert.assertEquals("Expected full title cache has error", "A. alba subsp. beta app phrase (Basio, A.) X., GenericRef", subSpeciesName.getFullTitleCache());
|
411
|
subSpeciesName.setAppendedPhrase("app2 phrase2");
|
412
|
subSpeciesName.setProtectedNameCache(true);
|
413
|
Assert.assertNull("NameCache should be null", subSpeciesName.getNameCache());
|
414
|
subSpeciesName.setProtectedNameCache(false);
|
415
|
subSpeciesName.setAppendedPhrase(null);
|
416
|
|
417
|
|
418
|
//ref + nomRef
|
419
|
Reference book = ReferenceFactory.newBook();
|
420
|
book.setTitle("Booktitle");
|
421
|
Assert.assertNotNull("TitleCache should not be null", subSpeciesName.getTitleCache());
|
422
|
subSpeciesName.setNomenclaturalReference(book);
|
423
|
subSpeciesName.setNomenclaturalMicroReference("22");
|
424
|
Assert.assertEquals("Expected full title cache has error", "A. alba subsp. beta (Basio, A.) X., Booktitle: 22", subSpeciesName.getFullTitleCache());
|
425
|
subSpeciesName.setProtectedTitleCache(true);
|
426
|
Assert.assertNotNull("TitleCache should not be null", subSpeciesName.getTitleCache());
|
427
|
|
428
|
//year
|
429
|
ZoologicalName zooName = TaxonNameFactory.NewZoologicalInstance(Rank.SPECIES());
|
430
|
zooName.setGenusOrUninomial("Homo");
|
431
|
zooName.setSpecificEpithet("sapiens");
|
432
|
zooName.setBasionymAuthorship(basAuthor);
|
433
|
zooName.setCombinationAuthorship(author);
|
434
|
zooName.setNomenclaturalReference(book);
|
435
|
zooName.setNomenclaturalMicroReference("22");
|
436
|
Assert.assertEquals("Expected full title cache has error", "Homo sapiens (Basio, A.) X., Booktitle: 22", zooName.getFullTitleCache());
|
437
|
|
438
|
zooName.setOriginalPublicationYear(1922);
|
439
|
zooName.setPublicationYear(1948);
|
440
|
Assert.assertEquals("Expected full title cache has error", "Homo sapiens (Basio, A., 1922) X., 1948, Booktitle: 22", zooName.getFullTitleCache());
|
441
|
zooName.setOriginalPublicationYear(1923);
|
442
|
zooName.setProtectedAuthorshipCache(true);
|
443
|
Assert.assertNull("AuthorshipCache should be null", zooName.getAuthorshipCache());
|
444
|
zooName.setProtectedAuthorshipCache(false);
|
445
|
Assert.assertNotNull("AuthorshipCache should not be null", zooName.getAuthorshipCache());
|
446
|
zooName.setPublicationYear(1949);
|
447
|
zooName.setProtectedAuthorshipCache(true);
|
448
|
Assert.assertNull("AuthorshipCache should be null", zooName.getAuthorshipCache());
|
449
|
|
450
|
|
451
|
|
452
|
|
453
|
}
|
454
|
|
455
|
/**
|
456
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#setNameAuthorSeperator(java.lang.String)}.
|
457
|
*/
|
458
|
@Test
|
459
|
public void testGetSetNameAuthorSeperator() {
|
460
|
String authorSeparator = "authorSeparator";
|
461
|
strategy.setNameAuthorSeperator(authorSeparator);
|
462
|
assertEquals(authorSeparator, strategy.getNameAuthorSeperator());
|
463
|
strategy.setNameAuthorSeperator(null);
|
464
|
assertNull(strategy.getNameAuthorSeperator());
|
465
|
}
|
466
|
|
467
|
/**
|
468
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#setBasionymStart(java.lang.String)}.
|
469
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#getBasionymStart()}.
|
470
|
*/
|
471
|
@Test
|
472
|
public void testGetSetBasionymStart() {
|
473
|
String basStart = "start";
|
474
|
strategy.setBasionymStart(basStart);
|
475
|
assertEquals(basStart, strategy.getBasionymStart());
|
476
|
strategy.setBasionymStart(null);
|
477
|
assertNull(strategy.getBasionymStart());
|
478
|
}
|
479
|
|
480
|
/**
|
481
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#setBasionymEnd(java.lang.String)}.
|
482
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#getBasionymEnd()}.
|
483
|
*/
|
484
|
@Test
|
485
|
public void testGetSetBasionymEnd() {
|
486
|
String basEnd = "end";
|
487
|
strategy.setBasionymEnd(basEnd);
|
488
|
assertEquals(basEnd, strategy.getBasionymEnd());
|
489
|
strategy.setBasionymEnd(null);
|
490
|
assertNull(strategy.getBasionymEnd());
|
491
|
}
|
492
|
|
493
|
/**
|
494
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#setExAuthorSeperator(java.lang.String)}.
|
495
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#getExAuthorSeperator()}.
|
496
|
*/
|
497
|
@Test
|
498
|
public void testGetSetExAuthorSeperator() {
|
499
|
String exAuthorSeparator = "exAuthorSeparator";
|
500
|
strategy.setExAuthorSeperator(exAuthorSeparator);
|
501
|
assertEquals(exAuthorSeparator, strategy.getExAuthorSeperator());
|
502
|
strategy.setExAuthorSeperator(null);
|
503
|
assertNull(strategy.getExAuthorSeperator());
|
504
|
}
|
505
|
|
506
|
/**
|
507
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#setBasionymAuthorCombinationAuthorSeperator(java.lang.CharSequence)}.
|
508
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#getBasionymAuthorCombinationAuthorSeperator()}.
|
509
|
*/
|
510
|
@Test
|
511
|
public void testSetBasionymAuthorCombinationAuthorSeperator() {
|
512
|
String basComSeparator = "basComSeparator";
|
513
|
strategy.setBasionymAuthorCombinationAuthorSeperator(basComSeparator);
|
514
|
assertEquals(basComSeparator, strategy.getBasionymAuthorCombinationAuthorSeperator());
|
515
|
strategy.setBasionymAuthorCombinationAuthorSeperator(null);
|
516
|
assertNull(strategy.getBasionymAuthorCombinationAuthorSeperator());
|
517
|
}
|
518
|
|
519
|
@Test
|
520
|
public void testGetInfraGenericNames(){
|
521
|
String author = "Anyauthor";
|
522
|
NonViralName<?> nonViralName = TaxonNameFactory.NewNonViralInstance(Rank.SUBGENUS());
|
523
|
nonViralName.setGenusOrUninomial("Genus");
|
524
|
nonViralName.setInfraGenericEpithet("subgenus");
|
525
|
nonViralName.setAuthorshipCache(author);
|
526
|
|
527
|
//test ordinary infrageneric
|
528
|
List<TaggedText> subGenusNameCacheTagged = strategy.getInfraGenusTaggedNameCache(nonViralName);
|
529
|
String subGenusNameCache = TaggedCacheHelper.createString(subGenusNameCacheTagged);
|
530
|
assertEquals("Subgenus name should be 'Genus subg. subgenus'.", "Genus subg. subgenus", subGenusNameCache);
|
531
|
String subGenusTitle = strategy.getTitleCache(nonViralName);
|
532
|
assertEquals("Subgenus name should be 'Genus subg. subgenus Anyauthor'.", "Genus subg. subgenus Anyauthor", subGenusTitle);
|
533
|
|
534
|
//test species aggregates and species groups
|
535
|
nonViralName.setRank(Rank.SPECIESAGGREGATE());
|
536
|
nonViralName.setSpecificEpithet("myspecies");
|
537
|
nonViralName.setInfraGenericEpithet(null);
|
538
|
nonViralName.setAuthorshipCache(null);
|
539
|
|
540
|
List<TaggedText> aggrNameCacheTagged = strategy.getInfraGenusTaggedNameCache(nonViralName);
|
541
|
|
542
|
String aggrNameCache = TaggedCacheHelper.createString(aggrNameCacheTagged);
|
543
|
assertEquals("Species aggregate name should be 'Genus myspecies aggr.'.", "Genus myspecies aggr.", aggrNameCache);
|
544
|
String aggrNameTitle = strategy.getTitleCache(nonViralName);
|
545
|
Assert.assertTrue("Species aggregate should not include author information.", aggrNameTitle.indexOf(author) == -1);
|
546
|
assertEquals("Species aggregate name should be 'Genus myspecies aggr.'.", "Genus myspecies aggr.", aggrNameTitle);
|
547
|
nonViralName.setRank(Rank.SPECIESGROUP());
|
548
|
String groupNameTitle = strategy.getTitleCache(nonViralName);
|
549
|
assertEquals("Species group name should be 'Genus myspecies species group'.", "Genus myspecies species group", groupNameTitle);
|
550
|
|
551
|
//test species aggregates and species groups with infrageneric information
|
552
|
//TODO check if groups do ever have infrageneric epithets
|
553
|
nonViralName.setRank(Rank.SPECIESAGGREGATE());
|
554
|
nonViralName.setSpecificEpithet("myspecies");
|
555
|
nonViralName.setInfraGenericEpithet("Infragenus");
|
556
|
|
557
|
|
558
|
aggrNameCacheTagged = strategy.getInfraGenusTaggedNameCache(nonViralName);
|
559
|
aggrNameCache = TaggedCacheHelper.createString(aggrNameCacheTagged);
|
560
|
assertEquals("Species aggregate name should be 'Genus (Infragenus) myspecies aggr.'.", "Genus (Infragenus) myspecies aggr.", aggrNameCache);
|
561
|
|
562
|
aggrNameTitle = strategy.getTitleCache(nonViralName);
|
563
|
Assert.assertTrue("Species aggregate should not include author information.", aggrNameTitle.indexOf(author) == -1);
|
564
|
assertEquals("Species aggregate name should be 'Genus (Infragenus) myspecies aggr.'.", "Genus (Infragenus) myspecies aggr.", aggrNameTitle);
|
565
|
|
566
|
nonViralName.setRank(Rank.SPECIESGROUP());
|
567
|
groupNameTitle = strategy.getTitleCache(nonViralName);
|
568
|
assertEquals("Species group name should be 'Genus (Infragenus) myspecies species group'.", "Genus (Infragenus) myspecies species group", groupNameTitle);
|
569
|
|
570
|
//aggregates with author and nom.ref. information #4288
|
571
|
nonViralName.setRank(Rank.SPECIESAGGREGATE());
|
572
|
nonViralName.setSpecificEpithet("myspecies");
|
573
|
nonViralName.setInfraGenericEpithet(null);
|
574
|
nonViralName.setAuthorshipCache("L.");
|
575
|
|
576
|
aggrNameCacheTagged = strategy.getTaggedTitle(nonViralName);
|
577
|
aggrNameCache = TaggedCacheHelper.createString(aggrNameCacheTagged);
|
578
|
assertEquals("Species aggregate name should be 'Genus myspecies L.'.", "Genus myspecies L.", aggrNameCache);
|
579
|
|
580
|
}
|
581
|
|
582
|
/**
|
583
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#getTaggedName(eu.etaxonomy.cdm.model.name.NonViralName)}.
|
584
|
*/
|
585
|
@Test
|
586
|
public void testGetTaggedNameSpeciesAggregate() {
|
587
|
BotanicalName speciesAggregate = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIESAGGREGATE());
|
588
|
speciesAggregate.setGenusOrUninomial("Mygenus");
|
589
|
speciesAggregate.setSpecificEpithet("myspecies");
|
590
|
List<TaggedText> taggedName = strategy.getTaggedName(speciesAggregate);
|
591
|
Assert.assertEquals("1rd tag must be genus epithet", "Mygenus", taggedName.get(0).getText());
|
592
|
Assert.assertEquals("2rd tag must be species epithet", "myspecies", taggedName.get(1).getText());
|
593
|
Assert.assertEquals("3rd tag must be aggregate marker", "aggr.",taggedName.get(2).getText());
|
594
|
}
|
595
|
|
596
|
|
597
|
@Test
|
598
|
public void testGetTaggedNameSubspecies(){
|
599
|
List<TaggedText> taggedName = strategy.getTaggedName(subSpeciesName);
|
600
|
Assert.assertEquals("First tag should be 'Abies'", "Abies", taggedName.get(0).getText());
|
601
|
Assert.assertEquals("Second tag should be 'alba'", "alba", taggedName.get(1).getText());
|
602
|
Assert.assertEquals("Third tag should be subspecies rank, and rank abbreviatioin should be subsp.", "subsp.", taggedName.get(2).getText());
|
603
|
Assert.assertEquals("Fourth tag should be 'beta'", "beta", taggedName.get(3).getText());
|
604
|
//to be continued
|
605
|
|
606
|
}
|
607
|
|
608
|
@Test
|
609
|
public void testTitleCacheHtmlTagged(){
|
610
|
HTMLTagRules rules = new HTMLTagRules().addRule(TagEnum.name, "i");
|
611
|
Assert.assertEquals("<i>Abies alba</i>", strategy.getTitleCache(speciesName, rules));
|
612
|
rules.addRule(TagEnum.name, "b");
|
613
|
Assert.assertEquals("<b><i>Abies alba</i></b>", strategy.getTitleCache(speciesName, rules));
|
614
|
speciesName.setCombinationAuthorship(author);
|
615
|
Assert.assertEquals("<b><i>Abies alba</i></b> L.", strategy.getTitleCache(speciesName, rules));
|
616
|
rules.addRule(TagEnum.authors, "i");
|
617
|
Assert.assertEquals("<b><i>Abies alba</i></b> <i>L.</i>", strategy.getTitleCache(speciesName, rules));
|
618
|
rules = new HTMLTagRules().addRule(TagEnum.name, "i").addRule(TagEnum.name, "b").addRule(TagEnum.authors, "b");
|
619
|
Assert.assertEquals("<b><i>Abies alba</i> L.</b>", strategy.getTitleCache(speciesName, rules));
|
620
|
|
621
|
}
|
622
|
|
623
|
@Test //#2888
|
624
|
public void testAutonymWithExAuthor(){
|
625
|
BotanicalName name = TaxonNameFactory.NewBotanicalInstance(Rank.FORM());
|
626
|
name.setGenusOrUninomial("Euphorbia");
|
627
|
name.setSpecificEpithet("atropurpurea");
|
628
|
name.setInfraSpecificEpithet("atropurpurea");
|
629
|
Team combTeam = Team.NewTitledInstance("Combauthor", "Combauthor");
|
630
|
name.setCombinationAuthorship(combTeam);
|
631
|
Team exCombTeam = Team.NewTitledInstance("Excomb", "Excomb");
|
632
|
name.setExCombinationAuthorship(exCombTeam);
|
633
|
|
634
|
Assert.assertEquals("", "Euphorbia atropurpurea Excomb ex Combauthor f. atropurpurea", name.getTitleCache());
|
635
|
}
|
636
|
|
637
|
|
638
|
}
|