Project

General

Profile

Download (34.1 KB) Statistics
| Branch: | Tag: | Revision:
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.Test;
21

    
22
import eu.etaxonomy.cdm.common.UTF8;
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.name.HybridRelationshipType;
27
import eu.etaxonomy.cdm.model.name.IBotanicalName;
28
import eu.etaxonomy.cdm.model.name.INonViralName;
29
import eu.etaxonomy.cdm.model.name.IZoologicalName;
30
import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
31
import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
32
import eu.etaxonomy.cdm.model.name.Rank;
33
import eu.etaxonomy.cdm.model.name.TaxonName;
34
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
35
import eu.etaxonomy.cdm.model.reference.Reference;
36
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
37
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
import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl;
42
import eu.etaxonomy.cdm.strategy.parser.TimePeriodParser;
43

    
44
/**
45
 * @author a.mueller
46
 * @since 26.11.2008
47
 */
48
public class TaxonNameDefaultCacheStrategyTest extends NameCacheStrategyTestBase {
49

    
50
    @SuppressWarnings("unused")
51
	private static final Logger logger = Logger.getLogger(TaxonNameDefaultCacheStrategyTest.class);
52

    
53
    private TaxonNameDefaultCacheStrategy strategy;
54

    
55
    private static final String familyNameString = "Familia";
56
    private static final String genusNameString = "Genus";
57
    private static final String speciesNameString = "Abies alba";
58
    private static final String subSpeciesNameString = "Abies alba subsp. beta";
59

    
60
    private static final String authorString = "L.";
61
    private static final String exAuthorString = "Exaut.";
62
    private static final String basAuthorString = "Basio, A.";
63
    private static final String exBasAuthorString = "ExBas. N.";
64

    
65
    private static final String referenceTitle = "My Reference";
66

    
67
    private IBotanicalName familyName;
68
    private IBotanicalName genusName;
69
    private IBotanicalName subGenusName;
70
    private TaxonName speciesName;
71
    private TaxonName subSpeciesName;
72
    private TeamOrPersonBase<?> author;
73
    private TeamOrPersonBase<?> exAuthor;
74
    private TeamOrPersonBase<?> basAuthor;
75
    private TeamOrPersonBase<?> exBasAuthor;
76
    private Reference citationRef;
77

    
78
    @Before
79
    public void setUp() throws Exception {
80
        strategy = TaxonNameDefaultCacheStrategy.NewInstance();
81
        familyName = TaxonNameFactory.PARSED_BOTANICAL(familyNameString, Rank.FAMILY());
82
        genusName = TaxonNameFactory.PARSED_BOTANICAL(genusNameString, Rank.GENUS());
83

    
84
        subGenusName = TaxonNameFactory.NewBotanicalInstance(Rank.SUBGENUS());
85
        subGenusName.setGenusOrUninomial("Genus");
86
        subGenusName.setInfraGenericEpithet("InfraGenericPart");
87

    
88
        speciesName = TaxonNameFactory.PARSED_BOTANICAL(speciesNameString);
89
        subSpeciesName = TaxonNameFactory.PARSED_BOTANICAL(subSpeciesNameString);
90

    
91
        author = Person.NewInstance();
92
        author.setNomenclaturalTitle(authorString);
93
        exAuthor = Person.NewInstance();
94
        exAuthor.setNomenclaturalTitle(exAuthorString);
95
        basAuthor = Person.NewInstance();
96
        basAuthor.setNomenclaturalTitle(basAuthorString);
97
        exBasAuthor = Person.NewInstance();
98
        exBasAuthor.setNomenclaturalTitle(exBasAuthorString);
99

    
100
        citationRef = ReferenceFactory.newGeneric();
101
        citationRef.setTitleCache(referenceTitle, true);
102
    }
103

    
104
//**************************** TESTS **************************************************
105

    
106
    @Test
107
    public void testGetTitleCache() {
108
        Assert.assertEquals(speciesNameString, speciesName.getTitleCache());
109
        //TODO not yet completed
110
    }
111

    
112
    @Test
113
    public void testGetFullTitleCache() {
114
        subSpeciesName.setNomenclaturalReference(citationRef);
115
        Assert.assertEquals(subSpeciesNameString + ", " +  referenceTitle, subSpeciesName.getFullTitleCache());
116
        //TODO not yet completed
117
    }
118

    
119
    @Test
120
    public void testGattungsAutonyme() {
121
    	IBotanicalName botName = TaxonNameFactory.NewBotanicalInstance(Rank.SECTION_BOTANY());
122
		String strTaraxacum = "Traxacum";
123
		botName.setGenusOrUninomial(strTaraxacum);
124
		botName.setInfraGenericEpithet(strTaraxacum);
125
		botName.setAuthorshipCache("Author");
126
		Assert.assertFalse(botName.getFullTitleCache().contains("bot."));
127
		//TODO #4288
128
//		System.out.println(botName.getFullTitleCache());
129
    }
130

    
131
    @Test
132
    public void testGetNameCache() {
133
        assertEquals("Species Name should be Abies alba", speciesNameString, speciesName.getNameCache());
134
        speciesName.setNameCache("Any species");
135
        assertEquals("Species Name should be Any species", "Any species", speciesName.getNameCache());
136
        assertEquals("Species Name should be Any species", "Any species", speciesName.getTitleCache());
137
        assertEquals("subSpeciesNameString should be correct", subSpeciesNameString, subSpeciesName.getNameCache());
138
        IBotanicalName botName = TaxonNameFactory.NewBotanicalInstance(Rank.VARIETY());
139
        botName.setGenusOrUninomial("Lepidocaryum");
140
        botName.setSpecificEpithet("tenue");
141
        botName.setInfraSpecificEpithet("tenue");
142
        assertEquals("", "Lepidocaryum tenue var. tenue", botName.getNameCache());
143
        IBotanicalName specName = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
144
        specName.setGenusOrUninomial("Genus");
145
        specName.setSpecificEpithet("");
146
        assertEquals("Empty species string must not result in trailing whitespace", "Genus", specName.getNameCache());
147

    
148
        //unranked taxa
149
        String unrankedCache;
150
        TaxonName unrankedName = TaxonNameFactory.NewBotanicalInstance(Rank.INFRASPECIFICTAXON());
151
        unrankedName.setGenusOrUninomial("Genus");
152
        TaxonNameDefaultCacheStrategy strategy = TaxonNameDefaultCacheStrategy.NewInstance();
153
            //infraspecific
154
        unrankedName.setInfraSpecificEpithet("infraspecific");
155
        unrankedName.setSpecificEpithet("species");
156
        unrankedCache = strategy.getNameCache(unrankedName);
157

    
158
        Assert.assertEquals("Correct unranked cache expected", "Genus species [infraspec.] infraspecific", unrankedCache);
159

    
160
            //infrageneric
161
        unrankedName.setRank(Rank.INFRAGENERICTAXON());
162
        unrankedName.setInfraSpecificEpithet(null);
163
        unrankedName.setSpecificEpithet(null);
164
        unrankedName.setInfraGenericEpithet("Infrageneric");
165
        unrankedCache = strategy.getNameCache(unrankedName);
166
        Assert.assertEquals("Correct unranked cache expected", "Genus [unranked] Infrageneric", unrankedCache);
167

    
168
        //bot. specific ranks
169
        botName = TaxonNameFactory.NewBotanicalInstance(Rank.SECTION_BOTANY());
170
        botName.setGenusOrUninomial("Genus");
171
        botName.setInfraGenericEpithet("Infragenus");
172
        Assert.assertEquals("", "Genus sect. Infragenus", botName.getNameCache());
173
        botName.setRank(Rank.SUBSECTION_BOTANY());
174
        Assert.assertEquals("", "Genus subsect. Infragenus", botName.getNameCache());
175

    
176
        //zool. specific ranks (we don't have markers here therefore no problem should exist
177
        IZoologicalName zooName = TaxonNameFactory.NewZoologicalInstance(Rank.SECTION_ZOOLOGY());
178
        zooName.setGenusOrUninomial("Genus");
179
        zooName.setInfraGenericEpithet("Infragenus");
180
        Assert.assertEquals("", "Genus", zooName.getNameCache());
181
        zooName.setRank(Rank.SUBSECTION_ZOOLOGY());
182
        Assert.assertEquals("", "Genus", zooName.getNameCache());
183
    }
184

    
185
    @Test
186
    public void testNameCacheWithInfraGenericEpithet() {
187
        speciesName.setInfraGenericEpithet("Infraabies");
188
        assertEquals("Species Name should be Abies (Infraabies) alba", "Abies (Infraabies) alba", speciesName.getNameCache());
189

    
190
        IBotanicalName botName = TaxonNameFactory.NewBotanicalInstance(Rank.VARIETY());
191
        botName.setGenusOrUninomial("Lepidocaryum");
192
        botName.setInfraGenericEpithet("Infralepi");
193
        botName.setSpecificEpithet("tenue");
194
        botName.setInfraSpecificEpithet("tenue");
195
        assertEquals("Name cache should be Lepidocaryum (Infralepi) tenue var. tenue", "Lepidocaryum (Infralepi) tenue var. tenue", botName.getNameCache());
196

    
197
        botName.setInfraGenericEpithet(" ");
198
        //Note: This test may fail if aspectj doesn't work correctly
199
        assertEquals("Empty infrageneric epithet must be neglegted", "Lepidocaryum tenue var. tenue", botName.getNameCache());
200
    }
201

    
202
    @Test
203
    public void testGetAuthorshipCache() {
204
        this.speciesName.setCombinationAuthorship(author);
205
        assertEquals(author.getNomenclaturalTitle(), speciesName.getAuthorshipCache());
206
        this.speciesName.setBasionymAuthorship(basAuthor);
207
        String expected = strategy.getBasionymStart()+ basAuthor.getNomenclaturalTitle()+strategy.getBasionymEnd()+strategy.getBasionymAuthorCombinationAuthorSeperator()+author.getNomenclaturalTitle();
208
        assertEquals(expected, speciesName.getAuthorshipCache());
209
        String authorshipcache = "authorshipcache";
210
        speciesName.setAuthorshipCache(authorshipcache);
211
        assertEquals(authorshipcache, speciesName.getAuthorshipCache());
212
        speciesName.setCombinationAuthorship(exAuthor);
213
        assertEquals(authorshipcache, speciesName.getAuthorshipCache()); //cache is protected
214
        assertEquals(speciesNameString + " " + authorshipcache, speciesName.getFullTitleCache());
215
        //unprotected
216
        speciesName.setProtectedAuthorshipCache(false);
217
        String atomizedAuthorCache = strategy.getBasionymStart()+ basAuthor.getNomenclaturalTitle()+strategy.getBasionymEnd()+strategy.getBasionymAuthorCombinationAuthorSeperator()+exAuthor.getNomenclaturalTitle();
218
        assertEquals(atomizedAuthorCache, speciesName.getAuthorshipCache());
219
        String atomizedTitleCache = speciesNameString + " "+ strategy.getBasionymStart()+ basAuthor.getNomenclaturalTitle()+strategy.getBasionymEnd()+strategy.getBasionymAuthorCombinationAuthorSeperator()+exAuthor.getNomenclaturalTitle();
220
        //Note: This test may fail if aspectj doesn't work correctly
221
        assertEquals(atomizedTitleCache, speciesName.getTitleCache());
222
        assertEquals(atomizedTitleCache, speciesName.getFullTitleCache());
223
    }
224

    
225
    @Test
226
    public void testHybridNames() {
227
        //Note \u00D7 : hybrid sign (multiplication sign)
228
        this.speciesName.setCombinationAuthorship(author);
229
        Assert.assertEquals(author.getNomenclaturalTitle(), speciesName.getAuthorshipCache());
230
        Assert.assertEquals("Should be Abies alba L.", "Abies alba L.", speciesName.getTitleCache());
231

    
232
        speciesName.setBinomHybrid(true);
233
        //Note: This test may fail if aspectj doesn't work correctly
234
        Assert.assertEquals("Should be Abies \u00D7alba L.", "Abies \u00D7alba L.", speciesName.getTitleCache());
235
        speciesName.setMonomHybrid(true);
236
        Assert.assertEquals("Should be '\u00D7Abies \u00D7alba L.'", "\u00D7Abies \u00D7alba L.", speciesName.getTitleCache());
237

    
238
        Assert.assertEquals("Should be 'Genus'", "Genus", genusName.getTitleCache());
239
        genusName.setMonomHybrid(true);
240
        Assert.assertEquals("Should be '\u00D7Genus'", "\u00D7Genus", genusName.getTitleCache());
241

    
242
        Assert.assertEquals("Should be 'Abies alba subsp. beta'", subSpeciesNameString, subSpeciesName.getTitleCache());
243
        subSpeciesName.setTrinomHybrid(true);
244
        Assert.assertEquals("Should be 'Abies alba nothosubsp. beta or nbeta'", "Abies alba nothosubsp. beta", subSpeciesName.getTitleCache());
245
        subSpeciesName.setMonomHybrid(true);
246
        Assert.assertEquals("Should be '\u00D7Abies alba nothosubsp. beta'", "\u00D7Abies alba nothosubsp. beta", subSpeciesName.getTitleCache());
247

    
248
        Assert.assertEquals("Should be 'Genus subg. InfraGenericPart'", "Genus subg. InfraGenericPart", subGenusName.getTitleCache());
249
        subGenusName.setBinomHybrid(true);
250
        Assert.assertEquals("Should be 'Genus nothosubg. InfraGenericPart'", "Genus nothosubg. InfraGenericPart", subGenusName.getTitleCache());
251
    }
252

    
253
    @Test
254
    public void testHybridFormula(){
255
        this.speciesName.setCombinationAuthorship(author);
256
        Assert.assertEquals(author.getNomenclaturalTitle(), speciesName.getAuthorshipCache());
257
        Assert.assertEquals("Should be 'Abies alba L.'", "Abies alba L.", speciesName.getTitleCache());
258

    
259
        INonViralName hybridName = TaxonNameFactory.NewNonViralInstance(Rank.SPECIES());
260
        INonViralName secondParent = TaxonNameFactory.NewNonViralInstance(Rank.SPECIES());
261

    
262
        secondParent.setTitleCache("Second parent Mill.", true);
263
        hybridName.addHybridParent(speciesName, HybridRelationshipType.FIRST_PARENT(), null);
264
        hybridName.addHybridParent(secondParent, HybridRelationshipType.SECOND_PARENT(), null);
265
        hybridName.setHybridFormula(true);
266

    
267
        Assert.assertEquals("", "Abies alba L. \u00D7 Second parent Mill.", hybridName.getTitleCache());
268
        //Note: handling of empty nameCache of parents may change in future
269
        Assert.assertEquals("", "Abies alba \u00D7", hybridName.getNameCache());
270
        secondParent.setGenusOrUninomial("Second");
271
        secondParent.setSpecificEpithet("parent");
272
        hybridName.setNameCache(null, false);
273
        Assert.assertEquals("", "Abies alba \u00D7 Second parent", hybridName.getNameCache());
274

    
275
    }
276

    
277
    //TODO add more tests when specification is clearer
278
    //3665
279
    @Test
280
    public void testOriginalSpelling() {
281

    
282
        TaxonName originalName = speciesName.clone();
283
    	originalName.setSpecificEpithet("alpa");
284
    	Assert.assertEquals("Preconditions are wrong", "Abies alpa", originalName.getTitleCache());
285
        Assert.assertEquals("Name cache should not show original spelling", "Abies alpa", originalName.getNameCache());
286

    
287
    	speciesName.setOriginalSpelling(originalName);
288
    	Assert.assertEquals("Abies alba [as \"alpa\"]", speciesName.getFullTitleCache());
289
        Assert.assertEquals("Abies alba", speciesName.getTitleCache());
290
        Assert.assertEquals("Name cache should not show original spelling", "Abies alba", speciesName.getNameCache());
291

    
292
    	originalName.setGenusOrUninomial("Apies");
293
    	speciesName.setNameCache(null, false);
294
    	//TODO update cache of current name (species name)
295
    	Assert.assertEquals("Abies alba [as \"Apies alpa\"]", speciesName.getFullTitleCache());
296
        Assert.assertEquals("Abies alba", speciesName.getTitleCache());
297
        Assert.assertEquals("Name cache should not show original spelling", "Abies alba", speciesName.getNameCache());
298

    
299
    	//#3665
300
    	INonViralName correctName = NonViralNameParserImpl.NewInstance().parseFullName("Nepenthes glabrata J.R.Turnbull & A.T.Middleton");
301
    	TaxonName originalSpelling = (TaxonName)NonViralNameParserImpl.NewInstance().parseFullName("Nepenthes glabratus");
302
    	correctName.setOriginalSpelling(originalSpelling);
303
    	Assert.assertEquals("Nepenthes glabrata", correctName.getNameCache());
304
    	Assert.assertEquals("Nepenthes glabrata J.R.Turnbull & A.T.Middleton", correctName.getTitleCache());
305
    	Assert.assertEquals("Nepenthes glabrata J.R.Turnbull & A.T.Middleton [as \"glabratus\"]", correctName.getFullTitleCache());
306

    
307
    	correctName.setNomenclaturalReference(citationRef);
308
        Assert.assertEquals("Nepenthes glabrata J.R.Turnbull & A.T.Middleton, My Reference [as \"glabratus\"]", correctName.getFullTitleCache());
309
        citationRef.setProtectedTitleCache(false);
310
        citationRef.setTitle("Sp. Pl.");
311
        citationRef.setDatePublished(TimePeriodParser.parseStringVerbatim("1988"));
312
        correctName.setFullTitleCache(null, false);
313
        Assert.assertEquals("Nepenthes glabrata J.R.Turnbull & A.T.Middleton, Sp. Pl. 1988 [as \"glabratus\"]", correctName.getFullTitleCache());
314
        correctName.addStatus(NomenclaturalStatus.NewInstance(NomenclaturalStatusType.ILLEGITIMATE()));
315
        correctName.setFullTitleCache(null, false);
316
        Assert.assertEquals("Nepenthes glabrata J.R.Turnbull & A.T.Middleton, Sp. Pl. 1988 [as \"glabratus\"], nom. illeg.", correctName.getFullTitleCache());
317

    
318
    	//TODO add more tests when specification of exact behaviour is clearer
319
    }
320

    
321
    @Test
322
    public void testCacheListener() {
323
        Reference ref = ReferenceFactory.newGeneric();
324
        ref.setTitleCache("GenericRef",true);
325
        this.subSpeciesName.setNomenclaturalReference(ref);
326
        Assert.assertEquals("Expected full title cache has error", "Abies alba subsp. beta, GenericRef", subSpeciesName.getFullTitleCache());
327
        subSpeciesName.setCombinationAuthorship(author);
328
        subSpeciesName.setBasionymAuthorship(basAuthor);
329
        Assert.assertEquals("Expected full title cache has error", "Abies alba subsp. beta (Basio, A.) L., GenericRef", subSpeciesName.getFullTitleCache());
330
        //cascade name change to fullTitleCache
331
        subSpeciesName.setRank(Rank.SPECIES());
332
        subSpeciesName.setProtectedNameCache(true);
333
        Assert.assertNull("name cache should be null", subSpeciesName.getNameCache());
334
        subSpeciesName.setProtectedNameCache(false);
335
        Assert.assertNotNull("name cache should not be null", subSpeciesName.getNameCache());
336
        Assert.assertEquals("Expected full title cache has error", "Abies alba (Basio, A.) L., GenericRef", subSpeciesName.getFullTitleCache());
337
        Assert.assertEquals("Expected full title cache has error", "Abies alba (Basio, A.) L.", subSpeciesName.getTitleCache());
338
        Assert.assertEquals("Expected full title cache has error", "Abies alba", subSpeciesName.getNameCache());
339

    
340
        subSpeciesName.setProtectedNameCache(true);
341
        subSpeciesName.setSpecificEpithet("gamma");
342
        Assert.assertEquals("Expected full title cache has error", "Abies alba (Basio, A.) L., GenericRef", subSpeciesName.getFullTitleCache());
343
        Assert.assertEquals("Expected full title cache has error", "Abies alba (Basio, A.) L.", subSpeciesName.getTitleCache());
344
        Assert.assertEquals("Expected full title cache has error", "Abies alba", subSpeciesName.getNameCache());
345
        //make original status
346
        subSpeciesName.setRank(Rank.SUBSPECIES());
347
        Assert.assertEquals("Expected full title cache has error", "Abies alba (Basio, A.) L., GenericRef", subSpeciesName.getFullTitleCache());
348

    
349
        //author change
350
        author.setNomenclaturalTitle("M.");
351
        Assert.assertEquals("Expected full title cache has error", "(Basio, A.) M.", subSpeciesName.getAuthorshipCache());
352
        Assert.assertEquals("Expected full title cache has error", "Abies alba (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
353
        Assert.assertEquals("Expected full title cache has error", "Abies alba (Basio, A.) M.", subSpeciesName.getTitleCache());
354

    
355
        //protectedTitleCache
356
        subSpeciesName.setProtectedTitleCache(true);
357
        subSpeciesName.setProtectedNameCache(false);
358
        subSpeciesName.setGenusOrUninomial("Pinus");
359
        subSpeciesName.setSpecificEpithet("alba");
360
        Assert.assertEquals("Expected full title cache has error", "Pinus alba subsp. beta", subSpeciesName.getNameCache());
361
        Assert.assertEquals("Expected full title cache has error", "Abies alba (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
362
        Assert.assertEquals("Expected full title cache has error", "Abies alba (Basio, A.) M.", subSpeciesName.getTitleCache());
363

    
364
        subSpeciesName.setTitleCache("Pinus beta C.", true);
365
        Assert.assertEquals("Expected full title cache has error", "Pinus beta C., GenericRef", subSpeciesName.getFullTitleCache());
366
        subSpeciesName.setProtectedTitleCache(false);
367

    
368
        Assert.assertEquals("Expected full title cache has error", "Pinus alba subsp. beta (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
369

    
370
        //protected full title cache set
371
        subSpeciesName.setFullTitleCache("ABC");
372
        Assert.assertEquals("Expected full title cache has error", "ABC", subSpeciesName.getFullTitleCache());
373
        subSpeciesName.setProtectedFullTitleCache(false);
374
        Assert.assertEquals("Expected full title cache has error", "Pinus alba subsp. beta (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
375

    
376
        //protected title cache set
377
        subSpeciesName.setProtectedTitleCache(false);
378
        Assert.assertEquals("Expected full title cache has error", "Pinus alba subsp. beta (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
379

    
380
        //protectedNameCache set
381
        subSpeciesName.setProtectedNameCache(true);
382
        Assert.assertEquals("Expected full title cache has error", "Pinus alba subsp. beta (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
383
        subSpeciesName.setNameCache("P. alba subsp. beta");
384
        Assert.assertEquals("Expected full title cache has error", "P. alba subsp. beta (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
385

    
386
        subSpeciesName.setGenusOrUninomial("A.");
387
        subSpeciesName.setProtectedNameCache(false);
388
        Assert.assertEquals("Expected full title cache has error", "A. alba subsp. beta (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
389
        subSpeciesName.setNameCache("P. alba subsp. beta");
390
        Assert.assertEquals("Expected full title cache has error", "P. alba subsp. beta (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
391

    
392
        //protected authorship
393
        subSpeciesName.setProtectedAuthorshipCache(true);
394
        Assert.assertEquals("Expected full title cache has error", "P. alba subsp. beta (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
395
        subSpeciesName.setAuthorshipCache("Ciard.");
396
        Assert.assertEquals("Expected full title cache has error", "P. alba subsp. beta Ciard., GenericRef", subSpeciesName.getFullTitleCache());
397

    
398
        author.setNomenclaturalTitle("X.");
399
        subSpeciesName.setProtectedAuthorshipCache(false);
400
        Assert.assertEquals("Expected full title cache has error", "P. alba subsp. beta (Basio, A.) X., GenericRef", subSpeciesName.getFullTitleCache());
401

    
402
        //clear
403
        subSpeciesName.setProtectedNameCache(false);
404
        Assert.assertEquals("Expected full title cache has error", "A. alba subsp. beta (Basio, A.) X., GenericRef", subSpeciesName.getFullTitleCache());
405

    
406
        //appended phrase
407
        subSpeciesName.setProtectedNameCache(true);
408
        Assert.assertEquals("Expected full title cache has error", "A. alba subsp. beta (Basio, A.) X., GenericRef", subSpeciesName.getFullTitleCache());
409
        subSpeciesName.setAppendedPhrase("app phrase");
410
        Assert.assertEquals("Expected full title cache has error", "A. alba subsp. beta (Basio, A.) X., GenericRef", subSpeciesName.getFullTitleCache());
411
        subSpeciesName.setProtectedNameCache(false);
412
        Assert.assertEquals("Expected full title cache has error", "A. alba subsp. beta app phrase (Basio, A.) X., GenericRef", subSpeciesName.getFullTitleCache());
413
        subSpeciesName.setAppendedPhrase("app2 phrase2");
414
        subSpeciesName.setProtectedNameCache(true);
415
        Assert.assertNull("NameCache should be null", subSpeciesName.getNameCache());
416
        subSpeciesName.setProtectedNameCache(false);
417
        subSpeciesName.setAppendedPhrase(null);
418

    
419
        //ref + nomRef
420
        Reference book = ReferenceFactory.newBook();
421
        book.setTitle("Booktitle");
422
        Assert.assertNotNull("TitleCache should not be null", subSpeciesName.getTitleCache());
423
        subSpeciesName.setNomenclaturalReference(book);
424
        subSpeciesName.setNomenclaturalMicroReference("22");
425
        Assert.assertEquals("Expected full title cache has error", "A. alba subsp. beta (Basio, A.) X., Booktitle: 22", subSpeciesName.getFullTitleCache());
426
        subSpeciesName.setProtectedTitleCache(true);
427
        Assert.assertNotNull("TitleCache should not be null", subSpeciesName.getTitleCache());
428

    
429
        //year
430
        IZoologicalName zooName = TaxonNameFactory.NewZoologicalInstance(Rank.SPECIES());
431
        zooName.setGenusOrUninomial("Homo");
432
        zooName.setSpecificEpithet("sapiens");
433
        zooName.setBasionymAuthorship(basAuthor);
434
        zooName.setCombinationAuthorship(author);
435
        zooName.setNomenclaturalReference(book);
436
        zooName.setNomenclaturalMicroReference("22");
437
        Assert.assertEquals("Expected full title cache has error", "Homo sapiens (Basio, A.) X., Booktitle: 22", zooName.getFullTitleCache());
438

    
439
        zooName.setOriginalPublicationYear(1922);
440
        zooName.setPublicationYear(1948);
441
        Assert.assertEquals("Expected full title cache has error", "Homo sapiens (Basio, A., 1922) X., 1948, Booktitle: 22", zooName.getFullTitleCache());
442
        zooName.setOriginalPublicationYear(1923);
443
        zooName.setProtectedAuthorshipCache(true);
444
        Assert.assertNull("AuthorshipCache should be null", zooName.getAuthorshipCache());
445
        zooName.setProtectedAuthorshipCache(false);
446
        Assert.assertNotNull("AuthorshipCache should not be null", zooName.getAuthorshipCache());
447
        zooName.setPublicationYear(1949);
448
        zooName.setProtectedAuthorshipCache(true);
449
        Assert.assertNull("AuthorshipCache should be null", zooName.getAuthorshipCache());
450

    
451
    }
452

    
453
    @Test
454
    public void testGetSetNameAuthorSeperator() {
455
        String authorSeparator = "authorSeparator";
456
        strategy.setNameAuthorSeperator(authorSeparator);
457
        assertEquals(authorSeparator, strategy.getNameAuthorSeperator());
458
        strategy.setNameAuthorSeperator(null);
459
        assertNull(strategy.getNameAuthorSeperator());
460
    }
461

    
462
    @Test
463
    public void testGetSetBasionymStart() {
464
        String basStart = "start";
465
        strategy.setBasionymStart(basStart);
466
        assertEquals(basStart, strategy.getBasionymStart());
467
        strategy.setBasionymStart(null);
468
        assertNull(strategy.getBasionymStart());
469
    }
470

    
471
    @Test
472
    public void testGetSetBasionymEnd() {
473
        String basEnd = "end";
474
        strategy.setBasionymEnd(basEnd);
475
        assertEquals(basEnd, strategy.getBasionymEnd());
476
        strategy.setBasionymEnd(null);
477
        assertNull(strategy.getBasionymEnd());
478
    }
479

    
480
    @Test
481
    public void testGetSetExAuthorSeperator() {
482
        String exAuthorSeparator = "exAuthorSeparator";
483
        strategy.setExAuthorSeperator(exAuthorSeparator);
484
        assertEquals(exAuthorSeparator, strategy.getExAuthorSeperator());
485
        strategy.setExAuthorSeperator(null);
486
        assertNull(strategy.getExAuthorSeperator());
487
    }
488

    
489
    @Test
490
    public void testSetBasionymAuthorCombinationAuthorSeperator() {
491
        String basComSeparator = "basComSeparator";
492
        strategy.setBasionymAuthorCombinationAuthorSeperator(basComSeparator);
493
        assertEquals(basComSeparator, strategy.getBasionymAuthorCombinationAuthorSeperator());
494
        strategy.setBasionymAuthorCombinationAuthorSeperator(null);
495
        assertNull(strategy.getBasionymAuthorCombinationAuthorSeperator());
496
    }
497

    
498
    @Test
499
    public void testGetInfraGenericNames(){
500
        String author = "Anyauthor";
501
        TaxonName nonViralName = TaxonNameFactory.NewNonViralInstance(Rank.SUBGENUS());
502
        nonViralName.setGenusOrUninomial("Genus");
503
        nonViralName.setInfraGenericEpithet("subgenus");
504
        nonViralName.setAuthorshipCache(author);
505

    
506
        //test ordinary infrageneric
507
        List<TaggedText> subGenusNameCacheTagged = strategy.getInfraGenusTaggedNameCache(nonViralName);
508
        String subGenusNameCache = TaggedCacheHelper.createString(subGenusNameCacheTagged);
509
        assertEquals("Subgenus name should be 'Genus subg. subgenus'.", "Genus subg. subgenus", subGenusNameCache);
510
        String subGenusTitle = strategy.getTitleCache(nonViralName);
511
        assertEquals("Subgenus name should be 'Genus subg. subgenus Anyauthor'.", "Genus subg. subgenus Anyauthor", subGenusTitle);
512

    
513
        //test species aggregates and species groups
514
        nonViralName.setRank(Rank.SPECIESAGGREGATE());
515
        nonViralName.setSpecificEpithet("myspecies");
516
        nonViralName.setInfraGenericEpithet(null);
517
        nonViralName.setAuthorshipCache(null);
518

    
519
        List<TaggedText> aggrNameCacheTagged = strategy.getInfraGenusTaggedNameCache(nonViralName);
520

    
521
        String aggrNameCache = TaggedCacheHelper.createString(aggrNameCacheTagged);
522
        assertEquals("Species aggregate name should be 'Genus myspecies aggr.'.", "Genus myspecies aggr.", aggrNameCache);
523
        String aggrNameTitle = strategy.getTitleCache(nonViralName);
524
        Assert.assertTrue("Species aggregate should not include author information.", aggrNameTitle.indexOf(author) == -1);
525
        assertEquals("Species aggregate name should be 'Genus myspecies aggr.'.", "Genus myspecies aggr.", aggrNameTitle);
526
        nonViralName.setRank(Rank.SPECIESGROUP());
527
        String groupNameTitle = strategy.getTitleCache(nonViralName);
528
        assertEquals("Species group name should be 'Genus myspecies species group'.", "Genus myspecies species group", groupNameTitle);
529

    
530
        //test species aggregates and species groups with infrageneric information
531
        //TODO check if groups do ever have infrageneric epithets
532
        nonViralName.setRank(Rank.SPECIESAGGREGATE());
533
        nonViralName.setSpecificEpithet("myspecies");
534
        nonViralName.setInfraGenericEpithet("Infragenus");
535

    
536
        aggrNameCacheTagged = strategy.getInfraGenusTaggedNameCache(nonViralName);
537
        aggrNameCache = TaggedCacheHelper.createString(aggrNameCacheTagged);
538
        assertEquals("Species aggregate name should be 'Genus (Infragenus) myspecies aggr.'.", "Genus (Infragenus) myspecies aggr.", aggrNameCache);
539

    
540
        aggrNameTitle = strategy.getTitleCache(nonViralName);
541
        Assert.assertTrue("Species aggregate should not include author information.", aggrNameTitle.indexOf(author) == -1);
542
        assertEquals("Species aggregate name should be 'Genus (Infragenus) myspecies aggr.'.", "Genus (Infragenus) myspecies aggr.", aggrNameTitle);
543

    
544
        nonViralName.setRank(Rank.SPECIESGROUP());
545
        groupNameTitle = strategy.getTitleCache(nonViralName);
546
        assertEquals("Species group name should be 'Genus (Infragenus) myspecies species group'.", "Genus (Infragenus) myspecies species group", groupNameTitle);
547

    
548
        //aggregates with author and nom.ref. information #4288
549
        nonViralName.setRank(Rank.SPECIESAGGREGATE());
550
        nonViralName.setSpecificEpithet("myspecies");
551
        nonViralName.setInfraGenericEpithet(null);
552
        nonViralName.setAuthorshipCache("L.");
553

    
554
        aggrNameCacheTagged = strategy.getTaggedTitle(nonViralName);
555
        aggrNameCache = TaggedCacheHelper.createString(aggrNameCacheTagged);
556
        assertEquals("Species aggregate name should be 'Genus myspecies L.'.", "Genus myspecies L.", aggrNameCache);
557

    
558
    }
559

    
560
    @Test
561
    public void testGetTaggedNameSpeciesAggregate() {
562
        TaxonName speciesAggregate = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIESAGGREGATE());
563
        speciesAggregate.setGenusOrUninomial("Mygenus");
564
        speciesAggregate.setSpecificEpithet("myspecies");
565
        List<TaggedText> taggedName = strategy.getTaggedName(speciesAggregate);
566
        Assert.assertEquals("1rd tag must be genus epithet", "Mygenus", taggedName.get(0).getText());
567
        Assert.assertEquals("2rd tag must be species epithet", "myspecies", taggedName.get(1).getText());
568
        Assert.assertEquals("3rd tag must be aggregate marker", "aggr.",taggedName.get(2).getText());
569
    }
570

    
571
    @Test
572
    public void testGetTaggedNameSubspecies(){
573
        List<TaggedText> taggedName = strategy.getTaggedName(subSpeciesName);
574
        Assert.assertEquals("First tag should be 'Abies'", "Abies", taggedName.get(0).getText());
575
        Assert.assertEquals("Second tag should be 'alba'", "alba", taggedName.get(1).getText());
576
        Assert.assertEquals("Third tag should be subspecies rank, and rank abbreviatioin should be subsp.", "subsp.", taggedName.get(2).getText());
577
        Assert.assertEquals("Fourth tag should be 'beta'", "beta", taggedName.get(3).getText());
578
        //to be continued
579
    }
580

    
581
    @Test
582
    public void testTitleCacheHtmlTagged(){
583
    	HTMLTagRules rules = new HTMLTagRules().addRule(TagEnum.name, "i");
584
    	Assert.assertEquals("<i>Abies alba</i>", strategy.getTitleCache(speciesName, rules));
585
    	rules.addRule(TagEnum.name, "b");
586
    	Assert.assertEquals("<b><i>Abies alba</i></b>", strategy.getTitleCache(speciesName, rules));
587
    	speciesName.setCombinationAuthorship(author);
588
    	Assert.assertEquals("<b><i>Abies alba</i></b> L.", strategy.getTitleCache(speciesName, rules));
589
    	rules.addRule(TagEnum.authors, "i");
590
    	Assert.assertEquals("<b><i>Abies alba</i></b> <i>L.</i>", strategy.getTitleCache(speciesName, rules));
591
    	rules = new HTMLTagRules().addRule(TagEnum.name, "i").addRule(TagEnum.name, "b").addRule(TagEnum.authors, "b");
592
    	Assert.assertEquals("<b><i>Abies alba</i> L.</b>", strategy.getTitleCache(speciesName, rules));
593
    }
594

    
595
    @Test //#2888
596
    public void testAutonymWithExAuthor(){
597
    	IBotanicalName name = TaxonNameFactory.NewBotanicalInstance(Rank.FORM());
598
    	name.setGenusOrUninomial("Euphorbia");
599
    	name.setSpecificEpithet("atropurpurea");
600
    	name.setInfraSpecificEpithet("atropurpurea");
601
    	Team combTeam = Team.NewTitledInstance("Combauthor", "Combauthor");
602
    	name.setCombinationAuthorship(combTeam);
603
    	Team exCombTeam = Team.NewTitledInstance("Excomb", "Excomb");
604
    	name.setExCombinationAuthorship(exCombTeam);
605

    
606
    	Assert.assertEquals("", "Euphorbia atropurpurea Excomb ex Combauthor f. atropurpurea", name.getTitleCache());
607
    }
608

    
609
    @Test //#6656
610
    public void testAutonymHybrids(){
611
        IBotanicalName name = TaxonNameFactory.NewBotanicalInstance(Rank.SUBSPECIES());
612
        name.setGenusOrUninomial("Ophrys");
613
        name.setSpecificEpithet("kastelli");
614
        name.setInfraSpecificEpithet("kastelli");
615
        Team combTeam = Team.NewTitledInstance("E. Klein", "E. Klein");
616
        name.setCombinationAuthorship(combTeam);
617
        name.setBinomHybrid(true);
618
        name.setTrinomHybrid(true);
619

    
620
        String expected = String.format("Ophrys %skastelli E. Klein nothosubsp. kastelli", UTF8.HYBRID.toString());
621
        Assert.assertEquals("", expected, name.getTitleCache());
622
    }
623
}
(3-3/6)