Merge branch 'release/5.18.0'
[cdmlib.git] / cdmlib-model / src / test / java / eu / etaxonomy / cdm / strategy / cache / name / TaxonNameDefaultCacheStrategyTest.java
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.common.UTF8;
24 import eu.etaxonomy.cdm.model.agent.Person;
25 import eu.etaxonomy.cdm.model.agent.Team;
26 import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
27 import eu.etaxonomy.cdm.model.name.HybridRelationshipType;
28 import eu.etaxonomy.cdm.model.name.IBotanicalName;
29 import eu.etaxonomy.cdm.model.name.INonViralName;
30 import eu.etaxonomy.cdm.model.name.IZoologicalName;
31 import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
32 import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
33 import eu.etaxonomy.cdm.model.name.Rank;
34 import eu.etaxonomy.cdm.model.name.TaxonName;
35 import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
36 import eu.etaxonomy.cdm.model.reference.Reference;
37 import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
38 import eu.etaxonomy.cdm.model.term.DefaultTermInitializer;
39 import eu.etaxonomy.cdm.strategy.cache.HTMLTagRules;
40 import eu.etaxonomy.cdm.strategy.cache.TagEnum;
41 import eu.etaxonomy.cdm.strategy.cache.TaggedCacheHelper;
42 import eu.etaxonomy.cdm.strategy.cache.TaggedText;
43 import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl;
44 import eu.etaxonomy.cdm.strategy.parser.TimePeriodParser;
45
46 /**
47 * @author a.mueller
48 * @since 26.11.2008
49 */
50 public class TaxonNameDefaultCacheStrategyTest extends NameCacheStrategyTestBase{
51 @SuppressWarnings("unused")
52 private static final Logger logger = Logger.getLogger(TaxonNameDefaultCacheStrategyTest.class);
53
54 private TaxonNameDefaultCacheStrategy strategy;
55
56 private static final String familyNameString = "Familia";
57 private static final String genusNameString = "Genus";
58 private static final String speciesNameString = "Abies alba";
59 private static final String subSpeciesNameString = "Abies alba subsp. beta";
60
61 private static final String authorString = "L.";
62 private static final String exAuthorString = "Exaut.";
63 private static final String basAuthorString = "Basio, A.";
64 private static final String exBasAuthorString = "ExBas. N.";
65
66 private static final String referenceTitle = "My Reference";
67
68 private IBotanicalName familyName;
69 private IBotanicalName genusName;
70 private IBotanicalName subGenusName;
71 private TaxonName speciesName;
72 private TaxonName subSpeciesName;
73 private TeamOrPersonBase<?> author;
74 private TeamOrPersonBase<?> exAuthor;
75 private TeamOrPersonBase<?> basAuthor;
76 private TeamOrPersonBase<?> exBasAuthor;
77 private Reference citationRef;
78
79 @BeforeClass
80 public static void setUpBeforeClass() {
81 DefaultTermInitializer vocabularyStore = new DefaultTermInitializer();
82 vocabularyStore.initialize();
83 }
84
85 @Before
86 public void setUp() throws Exception {
87 strategy = TaxonNameDefaultCacheStrategy.NewInstance();
88 familyName = TaxonNameFactory.PARSED_BOTANICAL(familyNameString, Rank.FAMILY());
89 genusName = TaxonNameFactory.PARSED_BOTANICAL(genusNameString, Rank.GENUS());
90
91 subGenusName = TaxonNameFactory.NewBotanicalInstance(Rank.SUBGENUS());
92 subGenusName.setGenusOrUninomial("Genus");
93 subGenusName.setInfraGenericEpithet("InfraGenericPart");
94
95 speciesName = TaxonNameFactory.PARSED_BOTANICAL(speciesNameString);
96 subSpeciesName = TaxonNameFactory.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.TaxonNameDefaultCacheStrategy#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.TaxonNameDefaultCacheStrategy#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 IBotanicalName 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.TaxonNameDefaultCacheStrategy#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 IBotanicalName 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 IBotanicalName 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 TaxonName unrankedName = TaxonNameFactory.NewBotanicalInstance(Rank.INFRASPECIFICTAXON());
170 unrankedName.setGenusOrUninomial("Genus");
171 TaxonNameDefaultCacheStrategy strategy = TaxonNameDefaultCacheStrategy.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 IZoologicalName 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 @Test
206 public void testNameCacheWithInfraGenericEpithet() {
207 speciesName.setInfraGenericEpithet("Infraabies");
208 assertEquals("Species Name should be Abies (Infraabies) alba", "Abies (Infraabies) alba", speciesName.getNameCache());
209
210 IBotanicalName botName = TaxonNameFactory.NewBotanicalInstance(Rank.VARIETY());
211 botName.setGenusOrUninomial("Lepidocaryum");
212 botName.setInfraGenericEpithet("Infralepi");
213 botName.setSpecificEpithet("tenue");
214 botName.setInfraSpecificEpithet("tenue");
215 assertEquals("Name cache should be Lepidocaryum (Infralepi) tenue var. tenue", "Lepidocaryum (Infralepi) tenue var. tenue", botName.getNameCache());
216
217 botName.setInfraGenericEpithet(" ");
218 //Note: This test may fail if aspectj doesn't work correctly
219 assertEquals("Empty infrageneric epithet must be neglegted", "Lepidocaryum tenue var. tenue", botName.getNameCache());
220 }
221
222 /**
223 * Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.TaxonNameDefaultCacheStrategy#getAuthorshipCache(eu.etaxonomy.cdm.model.name.NonViralName)}.
224 */
225 @Test
226 public void testGetAuthorshipCache() {
227 this.speciesName.setCombinationAuthorship(author);
228 assertEquals(author.getNomenclaturalTitle(), speciesName.getAuthorshipCache());
229 this.speciesName.setBasionymAuthorship(basAuthor);
230 String expected = strategy.getBasionymStart()+ basAuthor.getNomenclaturalTitle()+strategy.getBasionymEnd()+strategy.getBasionymAuthorCombinationAuthorSeperator()+author.getNomenclaturalTitle();
231 assertEquals(expected, speciesName.getAuthorshipCache());
232 String authorshipcache = "authorshipcache";
233 speciesName.setAuthorshipCache(authorshipcache);
234 assertEquals(authorshipcache, speciesName.getAuthorshipCache());
235 speciesName.setCombinationAuthorship(exAuthor);
236 assertEquals(authorshipcache, speciesName.getAuthorshipCache()); //cache is protected
237 assertEquals(speciesNameString + " " + authorshipcache, speciesName.getFullTitleCache());
238 //unprotected
239 speciesName.setProtectedAuthorshipCache(false);
240 String atomizedAuthorCache = strategy.getBasionymStart()+ basAuthor.getNomenclaturalTitle()+strategy.getBasionymEnd()+strategy.getBasionymAuthorCombinationAuthorSeperator()+exAuthor.getNomenclaturalTitle();
241 assertEquals(atomizedAuthorCache, speciesName.getAuthorshipCache());
242 String atomizedTitleCache = speciesNameString + " "+ strategy.getBasionymStart()+ basAuthor.getNomenclaturalTitle()+strategy.getBasionymEnd()+strategy.getBasionymAuthorCombinationAuthorSeperator()+exAuthor.getNomenclaturalTitle();
243 //Note: This test may fail if aspectj doesn't work correctly
244 assertEquals(atomizedTitleCache, speciesName.getTitleCache());
245 assertEquals(atomizedTitleCache, speciesName.getFullTitleCache());
246 }
247
248 /**
249 * Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.TaxonNameDefaultCacheStrategy#getAuthorshipCache(eu.etaxonomy.cdm.model.name.NonViralName)}.
250 */
251 @Test
252 public void testHybridNames() {
253 //Note \u00D7 : hybrid sign (multiplication sign)
254 this.speciesName.setCombinationAuthorship(author);
255 Assert.assertEquals(author.getNomenclaturalTitle(), speciesName.getAuthorshipCache());
256 Assert.assertEquals("Should be Abies alba L.", "Abies alba L.", speciesName.getTitleCache());
257
258 speciesName.setBinomHybrid(true);
259 //Note: This test may fail if aspectj doesn't work correctly
260 Assert.assertEquals("Should be Abies \u00D7alba L.", "Abies \u00D7alba L.", speciesName.getTitleCache());
261 speciesName.setMonomHybrid(true);
262 Assert.assertEquals("Should be '\u00D7Abies \u00D7alba L.'", "\u00D7Abies \u00D7alba L.", speciesName.getTitleCache());
263
264 Assert.assertEquals("Should be 'Genus'", "Genus", genusName.getTitleCache());
265 genusName.setMonomHybrid(true);
266 Assert.assertEquals("Should be '\u00D7Genus'", "\u00D7Genus", genusName.getTitleCache());
267
268 Assert.assertEquals("Should be 'Abies alba subsp. beta'", subSpeciesNameString, subSpeciesName.getTitleCache());
269 subSpeciesName.setTrinomHybrid(true);
270 Assert.assertEquals("Should be 'Abies alba nothosubsp. beta or nbeta'", "Abies alba nothosubsp. beta", subSpeciesName.getTitleCache());
271 subSpeciesName.setMonomHybrid(true);
272 Assert.assertEquals("Should be '\u00D7Abies alba nothosubsp. beta'", "\u00D7Abies alba nothosubsp. beta", subSpeciesName.getTitleCache());
273
274 Assert.assertEquals("Should be 'Genus subg. InfraGenericPart'", "Genus subg. InfraGenericPart", subGenusName.getTitleCache());
275 subGenusName.setBinomHybrid(true);
276 Assert.assertEquals("Should be 'Genus nothosubg. InfraGenericPart'", "Genus nothosubg. InfraGenericPart", subGenusName.getTitleCache());
277 }
278
279 @Test
280 public void testHybridFormula(){
281 this.speciesName.setCombinationAuthorship(author);
282 Assert.assertEquals(author.getNomenclaturalTitle(), speciesName.getAuthorshipCache());
283 Assert.assertEquals("Should be 'Abies alba L.'", "Abies alba L.", speciesName.getTitleCache());
284
285 INonViralName hybridName = TaxonNameFactory.NewNonViralInstance(Rank.SPECIES());
286 INonViralName secondParent = TaxonNameFactory.NewNonViralInstance(Rank.SPECIES());
287
288 secondParent.setTitleCache("Second parent Mill.", true);
289 hybridName.addHybridParent(speciesName, HybridRelationshipType.FIRST_PARENT(), null);
290 hybridName.addHybridParent(secondParent, HybridRelationshipType.SECOND_PARENT(), null);
291 hybridName.setHybridFormula(true);
292
293 Assert.assertEquals("", "Abies alba L. \u00D7 Second parent Mill.", hybridName.getTitleCache());
294 //Note: handling of empty nameCache of parents may change in future
295 Assert.assertEquals("", "Abies alba \u00D7", hybridName.getNameCache());
296 secondParent.setGenusOrUninomial("Second");
297 secondParent.setSpecificEpithet("parent");
298 hybridName.setNameCache(null, false);
299 Assert.assertEquals("", "Abies alba \u00D7 Second parent", hybridName.getNameCache());
300
301 }
302
303 //TODO add more tests when specification is clearer
304 //3665
305 @Test
306 public void testOriginalSpelling() {
307
308 TaxonName originalName = speciesName.clone();
309 originalName.setSpecificEpithet("alpa");
310 Assert.assertEquals("Preconditions are wrong", "Abies alpa", originalName.getTitleCache());
311 Assert.assertEquals("Name cache should not show original spelling", "Abies alpa", originalName.getNameCache());
312
313 speciesName.setOriginalSpelling(originalName);
314 Assert.assertEquals("Abies alba [as \"alpa\"]", speciesName.getFullTitleCache());
315 Assert.assertEquals("Abies alba", speciesName.getTitleCache());
316 Assert.assertEquals("Name cache should not show original spelling", "Abies alba", speciesName.getNameCache());
317
318 originalName.setGenusOrUninomial("Apies");
319 speciesName.setNameCache(null, false);
320 //TODO update cache of current name (species name)
321 Assert.assertEquals("Abies alba [as \"Apies alpa\"]", speciesName.getFullTitleCache());
322 Assert.assertEquals("Abies alba", speciesName.getTitleCache());
323 Assert.assertEquals("Name cache should not show original spelling", "Abies alba", speciesName.getNameCache());
324
325 //#3665
326 INonViralName correctName = NonViralNameParserImpl.NewInstance().parseFullName("Nepenthes glabrata J.R.Turnbull & A.T.Middleton");
327 TaxonName originalSpelling = (TaxonName)NonViralNameParserImpl.NewInstance().parseFullName("Nepenthes glabratus");
328 correctName.setOriginalSpelling(originalSpelling);
329 Assert.assertEquals("Nepenthes glabrata", correctName.getNameCache());
330 Assert.assertEquals("Nepenthes glabrata J.R.Turnbull & A.T.Middleton", correctName.getTitleCache());
331 Assert.assertEquals("Nepenthes glabrata J.R.Turnbull & A.T.Middleton [as \"glabratus\"]", correctName.getFullTitleCache());
332
333 correctName.setNomenclaturalReference(citationRef);
334 Assert.assertEquals("Nepenthes glabrata J.R.Turnbull & A.T.Middleton, My Reference [as \"glabratus\"]", correctName.getFullTitleCache());
335 citationRef.setProtectedTitleCache(false);
336 citationRef.setTitle("Sp. Pl.");
337 citationRef.setDatePublished(TimePeriodParser.parseStringVerbatim("1988"));
338 correctName.setFullTitleCache(null, false);
339 Assert.assertEquals("Nepenthes glabrata J.R.Turnbull & A.T.Middleton, Sp. Pl. 1988 [as \"glabratus\"]", correctName.getFullTitleCache());
340 correctName.addStatus(NomenclaturalStatus.NewInstance(NomenclaturalStatusType.ILLEGITIMATE()));
341 correctName.setFullTitleCache(null, false);
342 Assert.assertEquals("Nepenthes glabrata J.R.Turnbull & A.T.Middleton, Sp. Pl. 1988 [as \"glabratus\"], nom. illeg.", correctName.getFullTitleCache());
343
344 //TODO add more tests when specification of exact behaviour is clearer
345
346 }
347
348 @Test
349 public void testCacheListener() {
350 Reference ref = ReferenceFactory.newGeneric();
351 ref.setTitleCache("GenericRef",true);
352 this.subSpeciesName.setNomenclaturalReference(ref);
353 Assert.assertEquals("Expected full title cache has error", "Abies alba subsp. beta, GenericRef", subSpeciesName.getFullTitleCache());
354 subSpeciesName.setCombinationAuthorship(author);
355 subSpeciesName.setBasionymAuthorship(basAuthor);
356 Assert.assertEquals("Expected full title cache has error", "Abies alba subsp. beta (Basio, A.) L., GenericRef", subSpeciesName.getFullTitleCache());
357 //cascade name change to fullTitleCache
358 subSpeciesName.setRank(Rank.SPECIES());
359 subSpeciesName.setProtectedNameCache(true);
360 Assert.assertNull("name cache should be null", subSpeciesName.getNameCache());
361 subSpeciesName.setProtectedNameCache(false);
362 Assert.assertNotNull("name cache should not be null", subSpeciesName.getNameCache());
363 Assert.assertEquals("Expected full title cache has error", "Abies alba (Basio, A.) L., GenericRef", subSpeciesName.getFullTitleCache());
364 Assert.assertEquals("Expected full title cache has error", "Abies alba (Basio, A.) L.", subSpeciesName.getTitleCache());
365 Assert.assertEquals("Expected full title cache has error", "Abies alba", subSpeciesName.getNameCache());
366
367 subSpeciesName.setProtectedNameCache(true);
368 subSpeciesName.setSpecificEpithet("gamma");
369 Assert.assertEquals("Expected full title cache has error", "Abies alba (Basio, A.) L., GenericRef", subSpeciesName.getFullTitleCache());
370 Assert.assertEquals("Expected full title cache has error", "Abies alba (Basio, A.) L.", subSpeciesName.getTitleCache());
371 Assert.assertEquals("Expected full title cache has error", "Abies alba", subSpeciesName.getNameCache());
372 //make original status
373 subSpeciesName.setRank(Rank.SUBSPECIES());
374 Assert.assertEquals("Expected full title cache has error", "Abies alba (Basio, A.) L., GenericRef", subSpeciesName.getFullTitleCache());
375
376 //author change
377 author.setNomenclaturalTitle("M.");
378 Assert.assertEquals("Expected full title cache has error", "(Basio, A.) M.", subSpeciesName.getAuthorshipCache());
379 Assert.assertEquals("Expected full title cache has error", "Abies alba (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
380 Assert.assertEquals("Expected full title cache has error", "Abies alba (Basio, A.) M.", subSpeciesName.getTitleCache());
381
382 //protectedTitleCache
383 subSpeciesName.setProtectedTitleCache(true);
384 subSpeciesName.setProtectedNameCache(false);
385 subSpeciesName.setGenusOrUninomial("Pinus");
386 subSpeciesName.setSpecificEpithet("alba");
387 Assert.assertEquals("Expected full title cache has error", "Pinus alba subsp. beta", subSpeciesName.getNameCache());
388 Assert.assertEquals("Expected full title cache has error", "Abies alba (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
389 Assert.assertEquals("Expected full title cache has error", "Abies alba (Basio, A.) M.", subSpeciesName.getTitleCache());
390
391 subSpeciesName.setTitleCache("Pinus beta C.", true);
392 Assert.assertEquals("Expected full title cache has error", "Pinus beta C., GenericRef", subSpeciesName.getFullTitleCache());
393 subSpeciesName.setProtectedTitleCache(false);
394
395 Assert.assertEquals("Expected full title cache has error", "Pinus alba subsp. beta (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
396
397 //protected full title cache set
398 subSpeciesName.setFullTitleCache("ABC");
399 Assert.assertEquals("Expected full title cache has error", "ABC", subSpeciesName.getFullTitleCache());
400 subSpeciesName.setProtectedFullTitleCache(false);
401 Assert.assertEquals("Expected full title cache has error", "Pinus alba subsp. beta (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
402
403 //protected title cache set
404 subSpeciesName.setProtectedTitleCache(false);
405 Assert.assertEquals("Expected full title cache has error", "Pinus alba subsp. beta (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
406
407 //protectedNameCache set
408 subSpeciesName.setProtectedNameCache(true);
409 Assert.assertEquals("Expected full title cache has error", "Pinus alba subsp. beta (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
410 subSpeciesName.setNameCache("P. alba subsp. beta");
411 Assert.assertEquals("Expected full title cache has error", "P. alba subsp. beta (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
412
413 subSpeciesName.setGenusOrUninomial("A.");
414 subSpeciesName.setProtectedNameCache(false);
415 Assert.assertEquals("Expected full title cache has error", "A. alba subsp. beta (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
416 subSpeciesName.setNameCache("P. alba subsp. beta");
417 Assert.assertEquals("Expected full title cache has error", "P. alba subsp. beta (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
418
419 //protected authorship
420 subSpeciesName.setProtectedAuthorshipCache(true);
421 Assert.assertEquals("Expected full title cache has error", "P. alba subsp. beta (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
422 subSpeciesName.setAuthorshipCache("Ciard.");
423 Assert.assertEquals("Expected full title cache has error", "P. alba subsp. beta Ciard., GenericRef", subSpeciesName.getFullTitleCache());
424
425 author.setNomenclaturalTitle("X.");
426 subSpeciesName.setProtectedAuthorshipCache(false);
427 Assert.assertEquals("Expected full title cache has error", "P. alba subsp. beta (Basio, A.) X., GenericRef", subSpeciesName.getFullTitleCache());
428
429 //clear
430 subSpeciesName.setProtectedNameCache(false);
431 Assert.assertEquals("Expected full title cache has error", "A. alba subsp. beta (Basio, A.) X., GenericRef", subSpeciesName.getFullTitleCache());
432
433 //appended phrase
434 subSpeciesName.setProtectedNameCache(true);
435 Assert.assertEquals("Expected full title cache has error", "A. alba subsp. beta (Basio, A.) X., GenericRef", subSpeciesName.getFullTitleCache());
436 subSpeciesName.setAppendedPhrase("app phrase");
437 Assert.assertEquals("Expected full title cache has error", "A. alba subsp. beta (Basio, A.) X., GenericRef", subSpeciesName.getFullTitleCache());
438 subSpeciesName.setProtectedNameCache(false);
439 Assert.assertEquals("Expected full title cache has error", "A. alba subsp. beta app phrase (Basio, A.) X., GenericRef", subSpeciesName.getFullTitleCache());
440 subSpeciesName.setAppendedPhrase("app2 phrase2");
441 subSpeciesName.setProtectedNameCache(true);
442 Assert.assertNull("NameCache should be null", subSpeciesName.getNameCache());
443 subSpeciesName.setProtectedNameCache(false);
444 subSpeciesName.setAppendedPhrase(null);
445
446 //ref + nomRef
447 Reference book = ReferenceFactory.newBook();
448 book.setTitle("Booktitle");
449 Assert.assertNotNull("TitleCache should not be null", subSpeciesName.getTitleCache());
450 subSpeciesName.setNomenclaturalReference(book);
451 subSpeciesName.setNomenclaturalMicroReference("22");
452 Assert.assertEquals("Expected full title cache has error", "A. alba subsp. beta (Basio, A.) X., Booktitle: 22", subSpeciesName.getFullTitleCache());
453 subSpeciesName.setProtectedTitleCache(true);
454 Assert.assertNotNull("TitleCache should not be null", subSpeciesName.getTitleCache());
455
456 //year
457 IZoologicalName zooName = TaxonNameFactory.NewZoologicalInstance(Rank.SPECIES());
458 zooName.setGenusOrUninomial("Homo");
459 zooName.setSpecificEpithet("sapiens");
460 zooName.setBasionymAuthorship(basAuthor);
461 zooName.setCombinationAuthorship(author);
462 zooName.setNomenclaturalReference(book);
463 zooName.setNomenclaturalMicroReference("22");
464 Assert.assertEquals("Expected full title cache has error", "Homo sapiens (Basio, A.) X., Booktitle: 22", zooName.getFullTitleCache());
465
466 zooName.setOriginalPublicationYear(1922);
467 zooName.setPublicationYear(1948);
468 Assert.assertEquals("Expected full title cache has error", "Homo sapiens (Basio, A., 1922) X., 1948, Booktitle: 22", zooName.getFullTitleCache());
469 zooName.setOriginalPublicationYear(1923);
470 zooName.setProtectedAuthorshipCache(true);
471 Assert.assertNull("AuthorshipCache should be null", zooName.getAuthorshipCache());
472 zooName.setProtectedAuthorshipCache(false);
473 Assert.assertNotNull("AuthorshipCache should not be null", zooName.getAuthorshipCache());
474 zooName.setPublicationYear(1949);
475 zooName.setProtectedAuthorshipCache(true);
476 Assert.assertNull("AuthorshipCache should be null", zooName.getAuthorshipCache());
477
478
479
480
481 }
482
483 /**
484 * Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.TaxonNameDefaultCacheStrategy#setNameAuthorSeperator(java.lang.String)}.
485 */
486 @Test
487 public void testGetSetNameAuthorSeperator() {
488 String authorSeparator = "authorSeparator";
489 strategy.setNameAuthorSeperator(authorSeparator);
490 assertEquals(authorSeparator, strategy.getNameAuthorSeperator());
491 strategy.setNameAuthorSeperator(null);
492 assertNull(strategy.getNameAuthorSeperator());
493 }
494
495 /**
496 * Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.TaxonNameDefaultCacheStrategy#setBasionymStart(java.lang.String)}.
497 * Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.TaxonNameDefaultCacheStrategy#getBasionymStart()}.
498 */
499 @Test
500 public void testGetSetBasionymStart() {
501 String basStart = "start";
502 strategy.setBasionymStart(basStart);
503 assertEquals(basStart, strategy.getBasionymStart());
504 strategy.setBasionymStart(null);
505 assertNull(strategy.getBasionymStart());
506 }
507
508 /**
509 * Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.TaxonNameDefaultCacheStrategy#setBasionymEnd(java.lang.String)}.
510 * Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.TaxonNameDefaultCacheStrategy#getBasionymEnd()}.
511 */
512 @Test
513 public void testGetSetBasionymEnd() {
514 String basEnd = "end";
515 strategy.setBasionymEnd(basEnd);
516 assertEquals(basEnd, strategy.getBasionymEnd());
517 strategy.setBasionymEnd(null);
518 assertNull(strategy.getBasionymEnd());
519 }
520
521 /**
522 * Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.TaxonNameDefaultCacheStrategy#setExAuthorSeperator(java.lang.String)}.
523 * Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.TaxonNameDefaultCacheStrategy#getExAuthorSeperator()}.
524 */
525 @Test
526 public void testGetSetExAuthorSeperator() {
527 String exAuthorSeparator = "exAuthorSeparator";
528 strategy.setExAuthorSeperator(exAuthorSeparator);
529 assertEquals(exAuthorSeparator, strategy.getExAuthorSeperator());
530 strategy.setExAuthorSeperator(null);
531 assertNull(strategy.getExAuthorSeperator());
532 }
533
534 /**
535 * Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.TaxonNameDefaultCacheStrategy#setBasionymAuthorCombinationAuthorSeperator(java.lang.CharSequence)}.
536 * Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.TaxonNameDefaultCacheStrategy#getBasionymAuthorCombinationAuthorSeperator()}.
537 */
538 @Test
539 public void testSetBasionymAuthorCombinationAuthorSeperator() {
540 String basComSeparator = "basComSeparator";
541 strategy.setBasionymAuthorCombinationAuthorSeperator(basComSeparator);
542 assertEquals(basComSeparator, strategy.getBasionymAuthorCombinationAuthorSeperator());
543 strategy.setBasionymAuthorCombinationAuthorSeperator(null);
544 assertNull(strategy.getBasionymAuthorCombinationAuthorSeperator());
545 }
546
547 @Test
548 public void testGetInfraGenericNames(){
549 String author = "Anyauthor";
550 TaxonName nonViralName = TaxonNameFactory.NewNonViralInstance(Rank.SUBGENUS());
551 nonViralName.setGenusOrUninomial("Genus");
552 nonViralName.setInfraGenericEpithet("subgenus");
553 nonViralName.setAuthorshipCache(author);
554
555 //test ordinary infrageneric
556 List<TaggedText> subGenusNameCacheTagged = strategy.getInfraGenusTaggedNameCache(nonViralName);
557 String subGenusNameCache = TaggedCacheHelper.createString(subGenusNameCacheTagged);
558 assertEquals("Subgenus name should be 'Genus subg. subgenus'.", "Genus subg. subgenus", subGenusNameCache);
559 String subGenusTitle = strategy.getTitleCache(nonViralName);
560 assertEquals("Subgenus name should be 'Genus subg. subgenus Anyauthor'.", "Genus subg. subgenus Anyauthor", subGenusTitle);
561
562 //test species aggregates and species groups
563 nonViralName.setRank(Rank.SPECIESAGGREGATE());
564 nonViralName.setSpecificEpithet("myspecies");
565 nonViralName.setInfraGenericEpithet(null);
566 nonViralName.setAuthorshipCache(null);
567
568 List<TaggedText> aggrNameCacheTagged = strategy.getInfraGenusTaggedNameCache(nonViralName);
569
570 String aggrNameCache = TaggedCacheHelper.createString(aggrNameCacheTagged);
571 assertEquals("Species aggregate name should be 'Genus myspecies aggr.'.", "Genus myspecies aggr.", aggrNameCache);
572 String aggrNameTitle = strategy.getTitleCache(nonViralName);
573 Assert.assertTrue("Species aggregate should not include author information.", aggrNameTitle.indexOf(author) == -1);
574 assertEquals("Species aggregate name should be 'Genus myspecies aggr.'.", "Genus myspecies aggr.", aggrNameTitle);
575 nonViralName.setRank(Rank.SPECIESGROUP());
576 String groupNameTitle = strategy.getTitleCache(nonViralName);
577 assertEquals("Species group name should be 'Genus myspecies species group'.", "Genus myspecies species group", groupNameTitle);
578
579 //test species aggregates and species groups with infrageneric information
580 //TODO check if groups do ever have infrageneric epithets
581 nonViralName.setRank(Rank.SPECIESAGGREGATE());
582 nonViralName.setSpecificEpithet("myspecies");
583 nonViralName.setInfraGenericEpithet("Infragenus");
584
585
586 aggrNameCacheTagged = strategy.getInfraGenusTaggedNameCache(nonViralName);
587 aggrNameCache = TaggedCacheHelper.createString(aggrNameCacheTagged);
588 assertEquals("Species aggregate name should be 'Genus (Infragenus) myspecies aggr.'.", "Genus (Infragenus) myspecies aggr.", aggrNameCache);
589
590 aggrNameTitle = strategy.getTitleCache(nonViralName);
591 Assert.assertTrue("Species aggregate should not include author information.", aggrNameTitle.indexOf(author) == -1);
592 assertEquals("Species aggregate name should be 'Genus (Infragenus) myspecies aggr.'.", "Genus (Infragenus) myspecies aggr.", aggrNameTitle);
593
594 nonViralName.setRank(Rank.SPECIESGROUP());
595 groupNameTitle = strategy.getTitleCache(nonViralName);
596 assertEquals("Species group name should be 'Genus (Infragenus) myspecies species group'.", "Genus (Infragenus) myspecies species group", groupNameTitle);
597
598 //aggregates with author and nom.ref. information #4288
599 nonViralName.setRank(Rank.SPECIESAGGREGATE());
600 nonViralName.setSpecificEpithet("myspecies");
601 nonViralName.setInfraGenericEpithet(null);
602 nonViralName.setAuthorshipCache("L.");
603
604 aggrNameCacheTagged = strategy.getTaggedTitle(nonViralName);
605 aggrNameCache = TaggedCacheHelper.createString(aggrNameCacheTagged);
606 assertEquals("Species aggregate name should be 'Genus myspecies L.'.", "Genus myspecies L.", aggrNameCache);
607
608 }
609
610 /**
611 * Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.TaxonNameDefaultCacheStrategy#getTaggedName(eu.etaxonomy.cdm.model.name.NonViralName)}.
612 */
613 @Test
614 public void testGetTaggedNameSpeciesAggregate() {
615 TaxonName speciesAggregate = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIESAGGREGATE());
616 speciesAggregate.setGenusOrUninomial("Mygenus");
617 speciesAggregate.setSpecificEpithet("myspecies");
618 List<TaggedText> taggedName = strategy.getTaggedName(speciesAggregate);
619 Assert.assertEquals("1rd tag must be genus epithet", "Mygenus", taggedName.get(0).getText());
620 Assert.assertEquals("2rd tag must be species epithet", "myspecies", taggedName.get(1).getText());
621 Assert.assertEquals("3rd tag must be aggregate marker", "aggr.",taggedName.get(2).getText());
622 }
623
624
625 @Test
626 public void testGetTaggedNameSubspecies(){
627 List<TaggedText> taggedName = strategy.getTaggedName(subSpeciesName);
628 Assert.assertEquals("First tag should be 'Abies'", "Abies", taggedName.get(0).getText());
629 Assert.assertEquals("Second tag should be 'alba'", "alba", taggedName.get(1).getText());
630 Assert.assertEquals("Third tag should be subspecies rank, and rank abbreviatioin should be subsp.", "subsp.", taggedName.get(2).getText());
631 Assert.assertEquals("Fourth tag should be 'beta'", "beta", taggedName.get(3).getText());
632 //to be continued
633
634 }
635
636 @Test
637 public void testTitleCacheHtmlTagged(){
638 HTMLTagRules rules = new HTMLTagRules().addRule(TagEnum.name, "i");
639 Assert.assertEquals("<i>Abies alba</i>", strategy.getTitleCache(speciesName, rules));
640 rules.addRule(TagEnum.name, "b");
641 Assert.assertEquals("<b><i>Abies alba</i></b>", strategy.getTitleCache(speciesName, rules));
642 speciesName.setCombinationAuthorship(author);
643 Assert.assertEquals("<b><i>Abies alba</i></b> L.", strategy.getTitleCache(speciesName, rules));
644 rules.addRule(TagEnum.authors, "i");
645 Assert.assertEquals("<b><i>Abies alba</i></b> <i>L.</i>", strategy.getTitleCache(speciesName, rules));
646 rules = new HTMLTagRules().addRule(TagEnum.name, "i").addRule(TagEnum.name, "b").addRule(TagEnum.authors, "b");
647 Assert.assertEquals("<b><i>Abies alba</i> L.</b>", strategy.getTitleCache(speciesName, rules));
648
649 }
650
651 @Test //#2888
652 public void testAutonymWithExAuthor(){
653 IBotanicalName name = TaxonNameFactory.NewBotanicalInstance(Rank.FORM());
654 name.setGenusOrUninomial("Euphorbia");
655 name.setSpecificEpithet("atropurpurea");
656 name.setInfraSpecificEpithet("atropurpurea");
657 Team combTeam = Team.NewTitledInstance("Combauthor", "Combauthor");
658 name.setCombinationAuthorship(combTeam);
659 Team exCombTeam = Team.NewTitledInstance("Excomb", "Excomb");
660 name.setExCombinationAuthorship(exCombTeam);
661
662 Assert.assertEquals("", "Euphorbia atropurpurea Excomb ex Combauthor f. atropurpurea", name.getTitleCache());
663 }
664
665 @Test //#6656
666 public void testAutonymHybrids(){
667 IBotanicalName name = TaxonNameFactory.NewBotanicalInstance(Rank.SUBSPECIES());
668 name.setGenusOrUninomial("Ophrys");
669 name.setSpecificEpithet("kastelli");
670 name.setInfraSpecificEpithet("kastelli");
671 Team combTeam = Team.NewTitledInstance("E. Klein", "E. Klein");
672 name.setCombinationAuthorship(combTeam);
673 name.setBinomHybrid(true);
674 name.setTrinomHybrid(true);
675
676 String expected = String.format("Ophrys %skastelli E. Klein nothosubsp. kastelli", UTF8.HYBRID.toString());
677 Assert.assertEquals("", expected, name.getTitleCache());
678 }
679
680
681 }