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