Project

General

Profile

Download (37.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.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.common.DefaultTermInitializer;
28
import eu.etaxonomy.cdm.model.name.HybridRelationshipType;
29
import eu.etaxonomy.cdm.model.name.IBotanicalName;
30
import eu.etaxonomy.cdm.model.name.INonViralName;
31
import eu.etaxonomy.cdm.model.name.IZoologicalName;
32
import eu.etaxonomy.cdm.model.name.NameRelationshipType;
33
import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
34
import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
35
import eu.etaxonomy.cdm.model.name.Rank;
36
import eu.etaxonomy.cdm.model.name.TaxonName;
37
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
38
import eu.etaxonomy.cdm.model.reference.Reference;
39
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
40
import eu.etaxonomy.cdm.strategy.cache.HTMLTagRules;
41
import eu.etaxonomy.cdm.strategy.cache.TagEnum;
42
import eu.etaxonomy.cdm.strategy.cache.TaggedCacheHelper;
43
import eu.etaxonomy.cdm.strategy.cache.TaggedText;
44
import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl;
45
import eu.etaxonomy.cdm.strategy.parser.TimePeriodParser;
46

    
47
/**
48
 * @author a.mueller
49
 * @created 26.11.2008
50
 */
51
public class NonViralNameDefaultCacheStrategyTest extends NameCacheStrategyTestBase{
52
    @SuppressWarnings("unused")
53
	private static final Logger logger = Logger.getLogger(NonViralNameDefaultCacheStrategyTest.class);
54

    
55
    private NonViralNameDefaultCacheStrategy strategy;
56

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

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

    
67
    private static final String referenceTitle = "My Reference";
68

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

    
80
    @BeforeClass
81
    public static void setUpBeforeClass() {
82
        DefaultTermInitializer vocabularyStore = new DefaultTermInitializer();
83
        vocabularyStore.initialize();
84
    }
85

    
86
    /**
87
     * @throws java.lang.Exception
88
     */
89
    @Before
90
    public void setUp() throws Exception {
91
        strategy = NonViralNameDefaultCacheStrategy.NewInstance();
92
        familyName = TaxonNameFactory.PARSED_BOTANICAL(familyNameString, Rank.FAMILY());
93
        genusName = TaxonNameFactory.PARSED_BOTANICAL(genusNameString, Rank.GENUS());
94

    
95
        subGenusName = TaxonNameFactory.NewBotanicalInstance(Rank.SUBGENUS());
96
        subGenusName.setGenusOrUninomial("Genus");
97
        subGenusName.setInfraGenericEpithet("InfraGenericPart");
98

    
99
        speciesName = TaxonNameFactory.PARSED_BOTANICAL(speciesNameString);
100
        subSpeciesName = TaxonNameFactory.PARSED_BOTANICAL(subSpeciesNameString);
101

    
102
        author = Person.NewInstance();
103
        author.setNomenclaturalTitle(authorString);
104
        exAuthor = Person.NewInstance();
105
        exAuthor.setNomenclaturalTitle(exAuthorString);
106
        basAuthor = Person.NewInstance();
107
        basAuthor.setNomenclaturalTitle(basAuthorString);
108
        exBasAuthor = Person.NewInstance();
109
        exBasAuthor.setNomenclaturalTitle(exBasAuthorString);
110

    
111
        citationRef = ReferenceFactory.newGeneric();
112
        citationRef.setTitleCache(referenceTitle, true);
113

    
114
    }
115

    
116
//**************************** TESTS **************************************************
117

    
118
    /**
119
     * Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#getTitleCache(eu.etaxonomy.cdm.model.name.NonViralName)}.
120
     */
121
    @Test
122
    public void testGetTitleCache() {
123
        Assert.assertEquals(speciesNameString, speciesName.getTitleCache());
124
        //TODO not yet completed
125
    }
126

    
127
    /**
128
     * Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#getFullTitleCache(eu.etaxonomy.cdm.model.name.NonViralName)}.
129
     */
130
    @Test
131
    public void testGetFullTitleCache() {
132
        subSpeciesName.setNomenclaturalReference(citationRef);
133
        Assert.assertEquals(subSpeciesNameString + ", " +  referenceTitle, subSpeciesName.getFullTitleCache());
134
        //TODO not yet completed
135
    }
136

    
137
    @Test
138
    public void testGattungsAutonyme() {
139
    	IBotanicalName botName = TaxonNameFactory.NewBotanicalInstance(Rank.SECTION_BOTANY());
140
		String strTaraxacum = "Traxacum";
141
		botName.setGenusOrUninomial(strTaraxacum);
142
		botName.setInfraGenericEpithet(strTaraxacum);
143
		botName.setAuthorshipCache("Author");
144
		Assert.assertFalse(botName.getFullTitleCache().contains("bot."));
145
		//TODO #4288
146
		System.out.println(botName.getFullTitleCache());
147
    }
148

    
149

    
150

    
151
    /**
152
     * Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#getNameCache(eu.etaxonomy.cdm.model.name.NonViralName)}.
153
     */
154
    @Test
155
    public void testGetNameCache() {
156
        assertEquals("Species Name should be Abies alba", speciesNameString, speciesName.getNameCache());
157
        speciesName.setNameCache("Any species");
158
        assertEquals("Species Name should be Any species", "Any species", speciesName.getNameCache());
159
        assertEquals("Species Name should be Any species", "Any species", speciesName.getTitleCache());
160
        assertEquals("subSpeciesNameString should be correct", subSpeciesNameString, subSpeciesName.getNameCache());
161
        IBotanicalName botName = TaxonNameFactory.NewBotanicalInstance(Rank.VARIETY());
162
        botName.setGenusOrUninomial("Lepidocaryum");
163
        botName.setSpecificEpithet("tenue");
164
        botName.setInfraSpecificEpithet("tenue");
165
        assertEquals("", "Lepidocaryum tenue var. tenue", botName.getNameCache());
166
        IBotanicalName specName = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
167
        specName.setGenusOrUninomial("Genus");
168
        specName.setSpecificEpithet("");
169
        assertEquals("Empty species string must not result in trailing whitespace", "Genus", specName.getNameCache());
170

    
171
        //unranked taxa
172
        String unrankedCache;
173
        TaxonName unrankedName = TaxonNameFactory.NewBotanicalInstance(Rank.INFRASPECIFICTAXON());
174
        unrankedName.setGenusOrUninomial("Genus");
175
        NonViralNameDefaultCacheStrategy strategy = NonViralNameDefaultCacheStrategy.NewInstance();
176
            //infraspecific
177
        unrankedName.setInfraSpecificEpithet("infraspecific");
178
        unrankedName.setSpecificEpithet("species");
179
        unrankedCache = strategy.getNameCache(unrankedName);
180

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

    
183
            //infrageneric
184
        unrankedName.setRank(Rank.INFRAGENERICTAXON());
185
        unrankedName.setInfraSpecificEpithet(null);
186
        unrankedName.setSpecificEpithet(null);
187
        unrankedName.setInfraGenericEpithet("Infrageneric");
188
        unrankedCache = strategy.getNameCache(unrankedName);
189
        Assert.assertEquals("Correct unranked cache expected", "Genus [unranked] Infrageneric", unrankedCache);
190

    
191
        //bot. specific ranks
192
        botName = TaxonNameFactory.NewBotanicalInstance(Rank.SECTION_BOTANY());
193
        botName.setGenusOrUninomial("Genus");
194
        botName.setInfraGenericEpithet("Infragenus");
195
        Assert.assertEquals("", "Genus sect. Infragenus", botName.getNameCache());
196
        botName.setRank(Rank.SUBSECTION_BOTANY());
197
        Assert.assertEquals("", "Genus subsect. Infragenus", botName.getNameCache());
198

    
199
        //zool. specific ranks (we don't have markers here therefore no problem should exist
200
        IZoologicalName zooName = TaxonNameFactory.NewZoologicalInstance(Rank.SECTION_ZOOLOGY());
201
        zooName.setGenusOrUninomial("Genus");
202
        zooName.setInfraGenericEpithet("Infragenus");
203
        Assert.assertEquals("", "Genus", zooName.getNameCache());
204
        zooName.setRank(Rank.SUBSECTION_ZOOLOGY());
205
        Assert.assertEquals("", "Genus", zooName.getNameCache());
206

    
207
    }
208

    
209
    /**
210
     * Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#getNameCache(eu.etaxonomy.cdm.model.name.NonViralName)}.
211
     */
212
    @Test
213
    public void testNameCacheWithInfraGenericEpithet() {
214
        speciesName.setInfraGenericEpithet("Infraabies");
215
        assertEquals("Species Name should be Abies (Infraabies) alba", "Abies (Infraabies) alba", speciesName.getNameCache());
216

    
217
        IBotanicalName botName = TaxonNameFactory.NewBotanicalInstance(Rank.VARIETY());
218
        botName.setGenusOrUninomial("Lepidocaryum");
219
        botName.setInfraGenericEpithet("Infralepi");
220
        botName.setSpecificEpithet("tenue");
221
        botName.setInfraSpecificEpithet("tenue");
222
        assertEquals("Name cache should be Lepidocaryum (Infralepi) tenue var. tenue", "Lepidocaryum (Infralepi) tenue var. tenue", botName.getNameCache());
223

    
224
        botName.setInfraGenericEpithet(" ");
225
        //Note: This test may fail if aspectj doesn't work correctly
226
        assertEquals("Empty infrageneric epithet must be neglegted", "Lepidocaryum tenue var. tenue", botName.getNameCache());
227
    }
228

    
229
    /**
230
     * Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#getAuthorshipCache(eu.etaxonomy.cdm.model.name.NonViralName)}.
231
     */
232
    @Test
233
    public void testGetAuthorshipCache() {
234
        this.speciesName.setCombinationAuthorship(author);
235
        assertEquals(author.getNomenclaturalTitle(), speciesName.getAuthorshipCache());
236
        this.speciesName.setBasionymAuthorship(basAuthor);
237
        String expected = strategy.getBasionymStart()+ basAuthor.getNomenclaturalTitle()+strategy.getBasionymEnd()+strategy.getBasionymAuthorCombinationAuthorSeperator()+author.getNomenclaturalTitle();
238
        assertEquals(expected, speciesName.getAuthorshipCache());
239
        String authorshipcache = "authorshipcache";
240
        speciesName.setAuthorshipCache(authorshipcache);
241
        assertEquals(authorshipcache, speciesName.getAuthorshipCache());
242
        speciesName.setCombinationAuthorship(exAuthor);
243
        assertEquals(authorshipcache, speciesName.getAuthorshipCache()); //cache is protected
244
        assertEquals(speciesNameString + " " + authorshipcache, speciesName.getFullTitleCache());
245
        //unprotected
246
        speciesName.setProtectedAuthorshipCache(false);
247
        String atomizedAuthorCache = strategy.getBasionymStart()+ basAuthor.getNomenclaturalTitle()+strategy.getBasionymEnd()+strategy.getBasionymAuthorCombinationAuthorSeperator()+exAuthor.getNomenclaturalTitle();
248
        assertEquals(atomizedAuthorCache, speciesName.getAuthorshipCache());
249
        String atomizedTitleCache = speciesNameString + " "+ strategy.getBasionymStart()+ basAuthor.getNomenclaturalTitle()+strategy.getBasionymEnd()+strategy.getBasionymAuthorCombinationAuthorSeperator()+exAuthor.getNomenclaturalTitle();
250
        //Note: This test may fail if aspectj doesn't work correctly
251
        assertEquals(atomizedTitleCache, speciesName.getTitleCache());
252
        assertEquals(atomizedTitleCache, speciesName.getFullTitleCache());
253
    }
254

    
255
    /**
256
     * Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#getAuthorshipCache(eu.etaxonomy.cdm.model.name.NonViralName)}.
257
     */
258
    @Test
259
    public void testHybridNames() {
260
        //Note \u00D7 : hybrid sign (multiplication sign)
261
        this.speciesName.setCombinationAuthorship(author);
262
        Assert.assertEquals(author.getNomenclaturalTitle(), speciesName.getAuthorshipCache());
263
        Assert.assertEquals("Should be Abies alba L.", "Abies alba L.", speciesName.getTitleCache());
264

    
265
        speciesName.setBinomHybrid(true);
266
        //Note: This test may fail if aspectj doesn't work correctly
267
        Assert.assertEquals("Should be Abies \u00D7alba L.", "Abies \u00D7alba L.", speciesName.getTitleCache());
268
        speciesName.setMonomHybrid(true);
269
        Assert.assertEquals("Should be '\u00D7Abies \u00D7alba L.'", "\u00D7Abies \u00D7alba L.", speciesName.getTitleCache());
270

    
271
        Assert.assertEquals("Should be 'Genus'", "Genus", genusName.getTitleCache());
272
        genusName.setMonomHybrid(true);
273
        Assert.assertEquals("Should be '\u00D7Genus'", "\u00D7Genus", genusName.getTitleCache());
274

    
275
        Assert.assertEquals("Should be 'Abies alba subsp. beta'", subSpeciesNameString, subSpeciesName.getTitleCache());
276
        subSpeciesName.setTrinomHybrid(true);
277
        Assert.assertEquals("Should be 'Abies alba nothosubsp. beta or nbeta'", "Abies alba nothosubsp. beta", subSpeciesName.getTitleCache());
278
        subSpeciesName.setMonomHybrid(true);
279
        Assert.assertEquals("Should be '\u00D7Abies alba nothosubsp. beta'", "\u00D7Abies alba nothosubsp. beta", subSpeciesName.getTitleCache());
280

    
281
        Assert.assertEquals("Should be 'Genus subg. InfraGenericPart'", "Genus subg. InfraGenericPart", subGenusName.getTitleCache());
282
        subGenusName.setBinomHybrid(true);
283
        Assert.assertEquals("Should be 'Genus nothosubg. InfraGenericPart'", "Genus nothosubg. InfraGenericPart", subGenusName.getTitleCache());
284
    }
285

    
286
    @Test
287
    public void testHybridFormula(){
288
        this.speciesName.setCombinationAuthorship(author);
289
        Assert.assertEquals(author.getNomenclaturalTitle(), speciesName.getAuthorshipCache());
290
        Assert.assertEquals("Should be 'Abies alba L.'", "Abies alba L.", speciesName.getTitleCache());
291

    
292
        INonViralName hybridName = TaxonNameFactory.NewNonViralInstance(Rank.SPECIES());
293
        INonViralName secondParent = TaxonNameFactory.NewNonViralInstance(Rank.SPECIES());
294

    
295
        secondParent.setTitleCache("Second parent Mill.", true);
296
        hybridName.addHybridParent(speciesName, HybridRelationshipType.FIRST_PARENT(), null);
297
        hybridName.addHybridParent(secondParent, HybridRelationshipType.SECOND_PARENT(), null);
298
        hybridName.setHybridFormula(true);
299

    
300
        Assert.assertEquals("", "Abies alba L. \u00D7 Second parent Mill.", hybridName.getTitleCache());
301
        //Note: handling of empty nameCache of parents may change in future
302
        Assert.assertEquals("", "Abies alba \u00D7", hybridName.getNameCache());
303
        secondParent.setGenusOrUninomial("Second");
304
        secondParent.setSpecificEpithet("parent");
305
        hybridName.setNameCache(null, false);
306
        Assert.assertEquals("", "Abies alba \u00D7 Second parent", hybridName.getNameCache());
307

    
308
    }
309

    
310
    //TODO add more tests when specification is clearer
311
    //3665
312
    @Test
313
    public void testOriginalSpelling() {
314
    	NameRelationshipType origSpellingType = NameRelationshipType.ORIGINAL_SPELLING();
315
    	TaxonName originalName = (TaxonName)speciesName.clone();
316
    	originalName.setSpecificEpithet("alpa");
317
    	Assert.assertEquals("Preconditions are wrong", "Abies alpa", originalName.getTitleCache());
318
        Assert.assertEquals("Name cache should not show original spelling", "Abies alpa", originalName.getNameCache());
319

    
320
    	speciesName.addRelationshipFromName(originalName, origSpellingType, null);
321
    	Assert.assertEquals("Abies alba (as \u201calpa\u201d)", 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
    	originalName.setGenusOrUninomial("Apies");
326
    	speciesName.setNameCache(null, false);
327
    	//TODO update cache of current name (species name)
328
    	Assert.assertEquals("Abies alba (as \u201cApies alpa\u201d)", speciesName.getFullTitleCache());
329
        Assert.assertEquals("Abies alba", speciesName.getTitleCache());
330
        Assert.assertEquals("Name cache should not show original spelling", "Abies alba", speciesName.getNameCache());
331

    
332
    	//#3665
333
    	INonViralName correctName = NonViralNameParserImpl.NewInstance().parseFullName("Nepenthes glabrata J.R.Turnbull & A.T.Middleton");
334
    	TaxonName originalSpelling = (TaxonName)NonViralNameParserImpl.NewInstance().parseFullName("Nepenthes glabratus");
335
    	correctName.addRelationshipFromName(originalSpelling, origSpellingType, null);
336
    	Assert.assertEquals("Nepenthes glabrata", correctName.getNameCache());
337
    	Assert.assertEquals("Nepenthes glabrata J.R.Turnbull & A.T.Middleton", correctName.getTitleCache());
338
    	Assert.assertEquals("Nepenthes glabrata J.R.Turnbull & A.T.Middleton (as \u201cglabratus\u201d)", correctName.getFullTitleCache());
339

    
340
    	correctName.setNomenclaturalReference(citationRef);
341
        Assert.assertEquals("Nepenthes glabrata J.R.Turnbull & A.T.Middleton, My Reference (as \u201cglabratus\u201d)", correctName.getFullTitleCache());
342
        citationRef.setProtectedTitleCache(false);
343
        citationRef.setTitle("Sp. Pl.");
344
        citationRef.setDatePublished(TimePeriodParser.parseString("1988"));
345
        correctName.setFullTitleCache(null, false);
346
        Assert.assertEquals("Nepenthes glabrata J.R.Turnbull & A.T.Middleton, Sp. Pl. 1988 (as \u201cglabratus\u201d)", correctName.getFullTitleCache());
347
        correctName.addStatus(NomenclaturalStatus.NewInstance(NomenclaturalStatusType.ILLEGITIMATE()));
348
        correctName.setFullTitleCache(null, false);
349
        Assert.assertEquals("Nepenthes glabrata J.R.Turnbull & A.T.Middleton, Sp. Pl. 1988 (as \u201cglabratus\u201d), nom. illeg.", correctName.getFullTitleCache());
350

    
351
    	//TODO add more tests when specification of exact behaviour is clearer
352

    
353
    }
354

    
355
    @Test
356
    public void testCacheListener() {
357
        Reference ref = ReferenceFactory.newGeneric();
358
        ref.setTitleCache("GenericRef",true);
359
        this.subSpeciesName.setNomenclaturalReference(ref);
360
        Assert.assertEquals("Expected full title cache has error", "Abies alba subsp. beta, GenericRef", subSpeciesName.getFullTitleCache());
361
        subSpeciesName.setCombinationAuthorship(author);
362
        subSpeciesName.setBasionymAuthorship(basAuthor);
363
        Assert.assertEquals("Expected full title cache has error", "Abies alba subsp. beta (Basio, A.) L., GenericRef", subSpeciesName.getFullTitleCache());
364
        //cascade name change to fullTitleCache
365
        subSpeciesName.setRank(Rank.SPECIES());
366
        subSpeciesName.setProtectedNameCache(true);
367
        Assert.assertNull("name cache should be null", subSpeciesName.getNameCache());
368
        subSpeciesName.setProtectedNameCache(false);
369
        Assert.assertNotNull("name cache should not be null", subSpeciesName.getNameCache());
370
        Assert.assertEquals("Expected full title cache has error", "Abies alba (Basio, A.) L., GenericRef", subSpeciesName.getFullTitleCache());
371
        Assert.assertEquals("Expected full title cache has error", "Abies alba (Basio, A.) L.", subSpeciesName.getTitleCache());
372
        Assert.assertEquals("Expected full title cache has error", "Abies alba", subSpeciesName.getNameCache());
373

    
374
        subSpeciesName.setProtectedNameCache(true);
375
        subSpeciesName.setSpecificEpithet("gamma");
376
        Assert.assertEquals("Expected full title cache has error", "Abies alba (Basio, A.) L., GenericRef", subSpeciesName.getFullTitleCache());
377
        Assert.assertEquals("Expected full title cache has error", "Abies alba (Basio, A.) L.", subSpeciesName.getTitleCache());
378
        Assert.assertEquals("Expected full title cache has error", "Abies alba", subSpeciesName.getNameCache());
379
        //make original status
380
        subSpeciesName.setRank(Rank.SUBSPECIES());
381
        Assert.assertEquals("Expected full title cache has error", "Abies alba (Basio, A.) L., GenericRef", subSpeciesName.getFullTitleCache());
382

    
383
        //author change
384
        author.setNomenclaturalTitle("M.");
385
        Assert.assertEquals("Expected full title cache has error", "(Basio, A.) M.", subSpeciesName.getAuthorshipCache());
386
        Assert.assertEquals("Expected full title cache has error", "Abies alba (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
387
        Assert.assertEquals("Expected full title cache has error", "Abies alba (Basio, A.) M.", subSpeciesName.getTitleCache());
388

    
389
        //protectedTitleCache
390
        subSpeciesName.setProtectedTitleCache(true);
391
        subSpeciesName.setProtectedNameCache(false);
392
        subSpeciesName.setGenusOrUninomial("Pinus");
393
        subSpeciesName.setSpecificEpithet("alba");
394
        Assert.assertEquals("Expected full title cache has error", "Pinus alba subsp. beta", subSpeciesName.getNameCache());
395
        Assert.assertEquals("Expected full title cache has error", "Abies alba (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
396
        Assert.assertEquals("Expected full title cache has error", "Abies alba (Basio, A.) M.", subSpeciesName.getTitleCache());
397

    
398
        subSpeciesName.setTitleCache("Pinus beta C.", true);
399
        Assert.assertEquals("Expected full title cache has error", "Pinus beta C., GenericRef", subSpeciesName.getFullTitleCache());
400
        subSpeciesName.setProtectedTitleCache(false);
401

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

    
404
        //protected full title cache set
405
        subSpeciesName.setFullTitleCache("ABC");
406
        Assert.assertEquals("Expected full title cache has error", "ABC", subSpeciesName.getFullTitleCache());
407
        subSpeciesName.setProtectedFullTitleCache(false);
408
        Assert.assertEquals("Expected full title cache has error", "Pinus alba subsp. beta (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
409

    
410
        //protected title cache set
411
        subSpeciesName.setProtectedTitleCache(false);
412
        Assert.assertEquals("Expected full title cache has error", "Pinus alba subsp. beta (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
413

    
414
        //protectedNameCache set
415
        subSpeciesName.setProtectedNameCache(true);
416
        Assert.assertEquals("Expected full title cache has error", "Pinus alba subsp. beta (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
417
        subSpeciesName.setNameCache("P. alba subsp. beta");
418
        Assert.assertEquals("Expected full title cache has error", "P. alba subsp. beta (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
419

    
420
        subSpeciesName.setGenusOrUninomial("A.");
421
        subSpeciesName.setProtectedNameCache(false);
422
        Assert.assertEquals("Expected full title cache has error", "A. alba subsp. beta (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
423
        subSpeciesName.setNameCache("P. alba subsp. beta");
424
        Assert.assertEquals("Expected full title cache has error", "P. alba subsp. beta (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
425

    
426
        //protected authorship
427
        subSpeciesName.setProtectedAuthorshipCache(true);
428
        Assert.assertEquals("Expected full title cache has error", "P. alba subsp. beta (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
429
        subSpeciesName.setAuthorshipCache("Ciard.");
430
        Assert.assertEquals("Expected full title cache has error", "P. alba subsp. beta Ciard., GenericRef", subSpeciesName.getFullTitleCache());
431

    
432
        author.setNomenclaturalTitle("X.");
433
        subSpeciesName.setProtectedAuthorshipCache(false);
434
        Assert.assertEquals("Expected full title cache has error", "P. alba subsp. beta (Basio, A.) X., GenericRef", subSpeciesName.getFullTitleCache());
435

    
436
        //clear
437
        subSpeciesName.setProtectedNameCache(false);
438
        Assert.assertEquals("Expected full title cache has error", "A. alba subsp. beta (Basio, A.) X., GenericRef", subSpeciesName.getFullTitleCache());
439

    
440
        //appended phrase
441
        subSpeciesName.setProtectedNameCache(true);
442
        Assert.assertEquals("Expected full title cache has error", "A. alba subsp. beta (Basio, A.) X., GenericRef", subSpeciesName.getFullTitleCache());
443
        subSpeciesName.setAppendedPhrase("app phrase");
444
        Assert.assertEquals("Expected full title cache has error", "A. alba subsp. beta (Basio, A.) X., GenericRef", subSpeciesName.getFullTitleCache());
445
        subSpeciesName.setProtectedNameCache(false);
446
        Assert.assertEquals("Expected full title cache has error", "A. alba subsp. beta app phrase (Basio, A.) X., GenericRef", subSpeciesName.getFullTitleCache());
447
        subSpeciesName.setAppendedPhrase("app2 phrase2");
448
        subSpeciesName.setProtectedNameCache(true);
449
        Assert.assertNull("NameCache should be null", subSpeciesName.getNameCache());
450
        subSpeciesName.setProtectedNameCache(false);
451
        subSpeciesName.setAppendedPhrase(null);
452

    
453

    
454
        //ref + nomRef
455
        Reference book = ReferenceFactory.newBook();
456
        book.setTitle("Booktitle");
457
        Assert.assertNotNull("TitleCache should not be null", subSpeciesName.getTitleCache());
458
        subSpeciesName.setNomenclaturalReference(book);
459
        subSpeciesName.setNomenclaturalMicroReference("22");
460
        Assert.assertEquals("Expected full title cache has error", "A. alba subsp. beta (Basio, A.) X., Booktitle: 22", subSpeciesName.getFullTitleCache());
461
        subSpeciesName.setProtectedTitleCache(true);
462
        Assert.assertNotNull("TitleCache should not be null", subSpeciesName.getTitleCache());
463

    
464
        //year
465
        IZoologicalName zooName = TaxonNameFactory.NewZoologicalInstance(Rank.SPECIES());
466
        zooName.setGenusOrUninomial("Homo");
467
        zooName.setSpecificEpithet("sapiens");
468
        zooName.setBasionymAuthorship(basAuthor);
469
        zooName.setCombinationAuthorship(author);
470
        zooName.setNomenclaturalReference(book);
471
        zooName.setNomenclaturalMicroReference("22");
472
        Assert.assertEquals("Expected full title cache has error", "Homo sapiens (Basio, A.) X., Booktitle: 22", zooName.getFullTitleCache());
473

    
474
        zooName.setOriginalPublicationYear(1922);
475
        zooName.setPublicationYear(1948);
476
        Assert.assertEquals("Expected full title cache has error", "Homo sapiens (Basio, A., 1922) X., 1948, Booktitle: 22", zooName.getFullTitleCache());
477
        zooName.setOriginalPublicationYear(1923);
478
        zooName.setProtectedAuthorshipCache(true);
479
        Assert.assertNull("AuthorshipCache should be null", zooName.getAuthorshipCache());
480
        zooName.setProtectedAuthorshipCache(false);
481
        Assert.assertNotNull("AuthorshipCache should not be null", zooName.getAuthorshipCache());
482
        zooName.setPublicationYear(1949);
483
        zooName.setProtectedAuthorshipCache(true);
484
        Assert.assertNull("AuthorshipCache should be null", zooName.getAuthorshipCache());
485

    
486

    
487

    
488

    
489
    }
490

    
491
    /**
492
     * Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#setNameAuthorSeperator(java.lang.String)}.
493
     */
494
    @Test
495
    public void testGetSetNameAuthorSeperator() {
496
        String authorSeparator = "authorSeparator";
497
        strategy.setNameAuthorSeperator(authorSeparator);
498
        assertEquals(authorSeparator, strategy.getNameAuthorSeperator());
499
        strategy.setNameAuthorSeperator(null);
500
        assertNull(strategy.getNameAuthorSeperator());
501
    }
502

    
503
    /**
504
     * Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#setBasionymStart(java.lang.String)}.
505
     * Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#getBasionymStart()}.
506
     */
507
    @Test
508
    public void testGetSetBasionymStart() {
509
        String basStart = "start";
510
        strategy.setBasionymStart(basStart);
511
        assertEquals(basStart, strategy.getBasionymStart());
512
        strategy.setBasionymStart(null);
513
        assertNull(strategy.getBasionymStart());
514
    }
515

    
516
    /**
517
     * Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#setBasionymEnd(java.lang.String)}.
518
     * Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#getBasionymEnd()}.
519
    */
520
    @Test
521
    public void testGetSetBasionymEnd() {
522
        String basEnd = "end";
523
        strategy.setBasionymEnd(basEnd);
524
        assertEquals(basEnd, strategy.getBasionymEnd());
525
        strategy.setBasionymEnd(null);
526
        assertNull(strategy.getBasionymEnd());
527
    }
528

    
529
    /**
530
     * Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#setExAuthorSeperator(java.lang.String)}.
531
     * Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#getExAuthorSeperator()}.
532
     */
533
    @Test
534
    public void testGetSetExAuthorSeperator() {
535
        String exAuthorSeparator = "exAuthorSeparator";
536
        strategy.setExAuthorSeperator(exAuthorSeparator);
537
        assertEquals(exAuthorSeparator, strategy.getExAuthorSeperator());
538
        strategy.setExAuthorSeperator(null);
539
        assertNull(strategy.getExAuthorSeperator());
540
    }
541

    
542
    /**
543
     * Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#setBasionymAuthorCombinationAuthorSeperator(java.lang.CharSequence)}.
544
     * Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#getBasionymAuthorCombinationAuthorSeperator()}.
545
     */
546
    @Test
547
    public void testSetBasionymAuthorCombinationAuthorSeperator() {
548
        String basComSeparator = "basComSeparator";
549
        strategy.setBasionymAuthorCombinationAuthorSeperator(basComSeparator);
550
        assertEquals(basComSeparator, strategy.getBasionymAuthorCombinationAuthorSeperator());
551
        strategy.setBasionymAuthorCombinationAuthorSeperator(null);
552
        assertNull(strategy.getBasionymAuthorCombinationAuthorSeperator());
553
    }
554

    
555
    @Test
556
    public void testGetInfraGenericNames(){
557
        String author = "Anyauthor";
558
        TaxonName nonViralName = TaxonNameFactory.NewNonViralInstance(Rank.SUBGENUS());
559
        nonViralName.setGenusOrUninomial("Genus");
560
        nonViralName.setInfraGenericEpithet("subgenus");
561
        nonViralName.setAuthorshipCache(author);
562

    
563
        //test ordinary infrageneric
564
        List<TaggedText> subGenusNameCacheTagged = strategy.getInfraGenusTaggedNameCache(nonViralName);
565
        String subGenusNameCache = TaggedCacheHelper.createString(subGenusNameCacheTagged);
566
        assertEquals("Subgenus name should be 'Genus subg. subgenus'.", "Genus subg. subgenus", subGenusNameCache);
567
        String subGenusTitle = strategy.getTitleCache(nonViralName);
568
        assertEquals("Subgenus name should be 'Genus subg. subgenus Anyauthor'.", "Genus subg. subgenus Anyauthor", subGenusTitle);
569

    
570
        //test species aggregates and species groups
571
        nonViralName.setRank(Rank.SPECIESAGGREGATE());
572
        nonViralName.setSpecificEpithet("myspecies");
573
        nonViralName.setInfraGenericEpithet(null);
574
        nonViralName.setAuthorshipCache(null);
575

    
576
        List<TaggedText> aggrNameCacheTagged = strategy.getInfraGenusTaggedNameCache(nonViralName);
577

    
578
        String aggrNameCache = TaggedCacheHelper.createString(aggrNameCacheTagged);
579
        assertEquals("Species aggregate name should be 'Genus myspecies aggr.'.", "Genus myspecies aggr.", aggrNameCache);
580
        String aggrNameTitle = strategy.getTitleCache(nonViralName);
581
        Assert.assertTrue("Species aggregate should not include author information.", aggrNameTitle.indexOf(author) == -1);
582
        assertEquals("Species aggregate name should be 'Genus myspecies aggr.'.", "Genus myspecies aggr.", aggrNameTitle);
583
        nonViralName.setRank(Rank.SPECIESGROUP());
584
        String groupNameTitle = strategy.getTitleCache(nonViralName);
585
        assertEquals("Species group name should be 'Genus myspecies species group'.", "Genus myspecies species group", groupNameTitle);
586

    
587
        //test species aggregates and species groups with infrageneric information
588
        //TODO check if groups do ever have infrageneric epithets
589
        nonViralName.setRank(Rank.SPECIESAGGREGATE());
590
        nonViralName.setSpecificEpithet("myspecies");
591
        nonViralName.setInfraGenericEpithet("Infragenus");
592

    
593

    
594
        aggrNameCacheTagged = strategy.getInfraGenusTaggedNameCache(nonViralName);
595
        aggrNameCache = TaggedCacheHelper.createString(aggrNameCacheTagged);
596
        assertEquals("Species aggregate name should be 'Genus (Infragenus) myspecies aggr.'.", "Genus (Infragenus) myspecies aggr.", aggrNameCache);
597

    
598
        aggrNameTitle = strategy.getTitleCache(nonViralName);
599
        Assert.assertTrue("Species aggregate should not include author information.", aggrNameTitle.indexOf(author) == -1);
600
        assertEquals("Species aggregate name should be 'Genus (Infragenus) myspecies aggr.'.", "Genus (Infragenus) myspecies aggr.", aggrNameTitle);
601

    
602
        nonViralName.setRank(Rank.SPECIESGROUP());
603
        groupNameTitle = strategy.getTitleCache(nonViralName);
604
        assertEquals("Species group name should be 'Genus (Infragenus) myspecies species group'.", "Genus (Infragenus) myspecies species group", groupNameTitle);
605

    
606
        //aggregates with author and nom.ref. information #4288
607
        nonViralName.setRank(Rank.SPECIESAGGREGATE());
608
        nonViralName.setSpecificEpithet("myspecies");
609
        nonViralName.setInfraGenericEpithet(null);
610
        nonViralName.setAuthorshipCache("L.");
611

    
612
        aggrNameCacheTagged = strategy.getTaggedTitle(nonViralName);
613
        aggrNameCache = TaggedCacheHelper.createString(aggrNameCacheTagged);
614
        assertEquals("Species aggregate name should be 'Genus myspecies L.'.", "Genus myspecies L.", aggrNameCache);
615

    
616
    }
617

    
618
    /**
619
     * Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#getTaggedName(eu.etaxonomy.cdm.model.name.NonViralName)}.
620
     */
621
    @Test
622
    public void testGetTaggedNameSpeciesAggregate() {
623
        TaxonName speciesAggregate = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIESAGGREGATE());
624
        speciesAggregate.setGenusOrUninomial("Mygenus");
625
        speciesAggregate.setSpecificEpithet("myspecies");
626
        List<TaggedText> taggedName = strategy.getTaggedName(speciesAggregate);
627
        Assert.assertEquals("1rd tag must be genus epithet", "Mygenus", taggedName.get(0).getText());
628
        Assert.assertEquals("2rd tag must be species epithet", "myspecies", taggedName.get(1).getText());
629
        Assert.assertEquals("3rd tag must be aggregate marker", "aggr.",taggedName.get(2).getText());
630
    }
631

    
632

    
633
    @Test
634
    public void testGetTaggedNameSubspecies(){
635
        List<TaggedText> taggedName = strategy.getTaggedName(subSpeciesName);
636
        Assert.assertEquals("First tag should be 'Abies'", "Abies", taggedName.get(0).getText());
637
        Assert.assertEquals("Second tag should be 'alba'", "alba", taggedName.get(1).getText());
638
        Assert.assertEquals("Third tag should be subspecies rank, and rank abbreviatioin should be subsp.", "subsp.", taggedName.get(2).getText());
639
        Assert.assertEquals("Fourth tag should be 'beta'", "beta", taggedName.get(3).getText());
640
        //to be continued
641

    
642
    }
643

    
644
    @Test
645
    public void testTitleCacheHtmlTagged(){
646
    	HTMLTagRules rules = new HTMLTagRules().addRule(TagEnum.name, "i");
647
    	Assert.assertEquals("<i>Abies alba</i>", strategy.getTitleCache(speciesName, rules));
648
    	rules.addRule(TagEnum.name, "b");
649
    	Assert.assertEquals("<b><i>Abies alba</i></b>", strategy.getTitleCache(speciesName, rules));
650
    	speciesName.setCombinationAuthorship(author);
651
    	Assert.assertEquals("<b><i>Abies alba</i></b> L.", strategy.getTitleCache(speciesName, rules));
652
    	rules.addRule(TagEnum.authors, "i");
653
    	Assert.assertEquals("<b><i>Abies alba</i></b> <i>L.</i>", strategy.getTitleCache(speciesName, rules));
654
    	rules = new HTMLTagRules().addRule(TagEnum.name, "i").addRule(TagEnum.name, "b").addRule(TagEnum.authors, "b");
655
    	Assert.assertEquals("<b><i>Abies alba</i> L.</b>", strategy.getTitleCache(speciesName, rules));
656

    
657
    }
658

    
659
    @Test //#2888
660
    public void testAutonymWithExAuthor(){
661
    	IBotanicalName name = TaxonNameFactory.NewBotanicalInstance(Rank.FORM());
662
    	name.setGenusOrUninomial("Euphorbia");
663
    	name.setSpecificEpithet("atropurpurea");
664
    	name.setInfraSpecificEpithet("atropurpurea");
665
    	Team combTeam = Team.NewTitledInstance("Combauthor", "Combauthor");
666
    	name.setCombinationAuthorship(combTeam);
667
    	Team exCombTeam = Team.NewTitledInstance("Excomb", "Excomb");
668
    	name.setExCombinationAuthorship(exCombTeam);
669

    
670
    	Assert.assertEquals("", "Euphorbia atropurpurea Excomb ex Combauthor f. atropurpurea", name.getTitleCache());
671
    }
672

    
673
    @Test //#6656
674
    public void testAutonymHybrids(){
675
        IBotanicalName name = TaxonNameFactory.NewBotanicalInstance(Rank.SUBSPECIES());
676
        name.setGenusOrUninomial("Ophrys");
677
        name.setSpecificEpithet("kastelli");
678
        name.setInfraSpecificEpithet("kastelli");
679
        Team combTeam = Team.NewTitledInstance("E. Klein", "E. Klein");
680
        name.setCombinationAuthorship(combTeam);
681
        name.setBinomHybrid(true);
682
        name.setTrinomHybrid(true);
683

    
684
        String expected = String.format("Ophrys %skastelli E. Klein nothosubsp. kastelli", UTF8.HYBRID.toString());
685
        Assert.assertEquals("", expected, name.getTitleCache());
686
    }
687

    
688

    
689
}
(3-3/5)