Project

General

Profile

Download (33.2 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.model.agent.Person;
24
import eu.etaxonomy.cdm.model.agent.Team;
25
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
26
import eu.etaxonomy.cdm.model.common.DefaultTermInitializer;
27
import eu.etaxonomy.cdm.model.name.BotanicalName;
28
import eu.etaxonomy.cdm.model.name.HybridRelationshipType;
29
import eu.etaxonomy.cdm.model.name.NameRelationshipType;
30
import eu.etaxonomy.cdm.model.name.NonViralName;
31
import eu.etaxonomy.cdm.model.name.Rank;
32
import eu.etaxonomy.cdm.model.name.ZoologicalName;
33
import eu.etaxonomy.cdm.model.reference.Reference;
34
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
35
import eu.etaxonomy.cdm.strategy.cache.HTMLTagRules;
36
import eu.etaxonomy.cdm.strategy.cache.TagEnum;
37
import eu.etaxonomy.cdm.strategy.cache.TaggedCacheHelper;
38
import eu.etaxonomy.cdm.strategy.cache.TaggedText;
39

    
40
/**
41
 * @author a.mueller
42
 * @created 26.11.2008
43
 */
44
public class NonViralNameDefaultCacheStrategyTest extends NameCacheStrategyTestBase{
45
    @SuppressWarnings("unused")
46
	private static final Logger logger = Logger.getLogger(NonViralNameDefaultCacheStrategyTest.class);
47

    
48
    private NonViralNameDefaultCacheStrategy<NonViralName> strategy;
49

    
50
    private static final String familyNameString = "Familia";
51
    private static final String genusNameString = "Genus";
52
    private static final String speciesNameString = "Abies alba";
53
    private static final String subSpeciesNameString = "Abies alba subsp. beta";
54
    private static final String appendedPhraseString = "app phrase";
55

    
56
    private static final String authorString = "L.";
57
    private static final String exAuthorString = "Exaut.";
58
    private static final String basAuthorString = "Basio, A.";
59
    private static final String exBasAuthorString = "ExBas. N.";
60

    
61
    private static final String referenceTitle = "My Reference";
62

    
63
    private BotanicalName familyName;
64
    private BotanicalName genusName;
65
    private BotanicalName subGenusName;
66
    private BotanicalName speciesName;
67
    private BotanicalName subSpeciesName;
68
    private TeamOrPersonBase<?> author;
69
    private TeamOrPersonBase<?> exAuthor;
70
    private TeamOrPersonBase<?> basAuthor;
71
    private TeamOrPersonBase<?> exBasAuthor;
72
    private Reference citationRef;
73

    
74
    @BeforeClass
75
    public static void setUpBeforeClass() {
76
        DefaultTermInitializer vocabularyStore = new DefaultTermInitializer();
77
        vocabularyStore.initialize();
78
    }
79

    
80
    /**
81
     * @throws java.lang.Exception
82
     */
83
    @Before
84
    public void setUp() throws Exception {
85
        strategy = NonViralNameDefaultCacheStrategy.NewInstance();
86
        familyName = BotanicalName.PARSED_NAME(familyNameString, Rank.FAMILY());
87
        genusName = BotanicalName.PARSED_NAME(genusNameString, Rank.GENUS());
88

    
89
        subGenusName = BotanicalName.NewInstance(Rank.SUBGENUS());
90
        subGenusName.setGenusOrUninomial("Genus");
91
        subGenusName.setInfraGenericEpithet("InfraGenericPart");
92

    
93
        speciesName = BotanicalName.PARSED_NAME(speciesNameString);
94
        subSpeciesName = BotanicalName.PARSED_NAME(subSpeciesNameString);
95

    
96
        author = Person.NewInstance();
97
        author.setNomenclaturalTitle(authorString);
98
        exAuthor = Person.NewInstance();
99
        exAuthor.setNomenclaturalTitle(exAuthorString);
100
        basAuthor = Person.NewInstance();
101
        basAuthor.setNomenclaturalTitle(basAuthorString);
102
        exBasAuthor = Person.NewInstance();
103
        exBasAuthor.setNomenclaturalTitle(exBasAuthorString);
104

    
105
        citationRef = ReferenceFactory.newGeneric();
106
        citationRef.setTitleCache(referenceTitle, true);
107

    
108
    }
109

    
110
//**************************** TESTS **************************************************
111

    
112
    /**
113
     * Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#getTitleCache(eu.etaxonomy.cdm.model.name.NonViralName)}.
114
     */
115
    @Test
116
    public void testGetTitleCache() {
117
        Assert.assertEquals(speciesNameString, speciesName.getTitleCache());
118
        //TODO not yet completed
119
    }
120

    
121
    /**
122
     * Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#getFullTitleCache(eu.etaxonomy.cdm.model.name.NonViralName)}.
123
     */
124
    @Test
125
    public void testGetFullTitleCache() {
126
        subSpeciesName.setNomenclaturalReference(citationRef);
127
        Assert.assertEquals(subSpeciesNameString + ", " +  referenceTitle, subSpeciesName.getFullTitleCache());
128
        //TODO not yet completed
129
    }
130

    
131
    @Test
132
    public void testGattungsAutonyme() {
133
    	BotanicalName botName = BotanicalName.NewInstance(Rank.SECTION_BOTANY());
134
		String strTaraxacum = "Traxacum";
135
		botName.setGenusOrUninomial(strTaraxacum);
136
		botName.setInfraGenericEpithet(strTaraxacum);
137
		botName.setAuthorshipCache("Author");
138
		Assert.assertFalse(botName.getFullTitleCache().contains("bot."));
139
		//TODO #4288
140
		System.out.println(botName.getFullTitleCache());
141
    }
142

    
143

    
144

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

    
165
        //unranked taxa
166
        String unrankedCache;
167
        BotanicalName unrankedName = BotanicalName.NewInstance(Rank.INFRASPECIFICTAXON());
168
        unrankedName.setGenusOrUninomial("Genus");
169
        NonViralNameDefaultCacheStrategy<BotanicalName> strategy = NonViralNameDefaultCacheStrategy.NewInstance();
170
            //infraspecific
171
        unrankedName.setInfraSpecificEpithet("infraspecific");
172
        unrankedName.setSpecificEpithet("species");
173
        unrankedCache = strategy.getNameCache(unrankedName);
174

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

    
177
            //infrageneric
178
        unrankedName.setRank(Rank.INFRAGENERICTAXON());
179
        unrankedName.setInfraSpecificEpithet(null);
180
        unrankedName.setSpecificEpithet(null);
181
        unrankedName.setInfraGenericEpithet("Infrageneric");
182
        unrankedCache = strategy.getNameCache(unrankedName);
183
        Assert.assertEquals("Correct unranked cache expected", "Genus [unranked] Infrageneric", unrankedCache);
184

    
185
        //bot. specific ranks
186
        botName = BotanicalName.NewInstance(Rank.SECTION_BOTANY());
187
        botName.setGenusOrUninomial("Genus");
188
        botName.setInfraGenericEpithet("Infragenus");
189
        Assert.assertEquals("", "Genus sect. Infragenus", botName.getNameCache());
190
        botName.setRank(Rank.SUBSECTION_BOTANY());
191
        Assert.assertEquals("", "Genus subsect. Infragenus", botName.getNameCache());
192

    
193
        //zool. specific ranks (we don't have markers here therefore no problem should exist
194
        ZoologicalName zooName = ZoologicalName.NewInstance(Rank.SECTION_ZOOLOGY());
195
        zooName.setGenusOrUninomial("Genus");
196
        zooName.setInfraGenericEpithet("Infragenus");
197
        Assert.assertEquals("", "Genus", zooName.getNameCache());
198
        zooName.setRank(Rank.SUBSECTION_ZOOLOGY());
199
        Assert.assertEquals("", "Genus", zooName.getNameCache());
200

    
201
    }
202

    
203
    /**
204
     * Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#getNameCache(eu.etaxonomy.cdm.model.name.NonViralName)}.
205
     */
206
    @Test
207
    public void testNameCacheWithInfraGenericEpithet() {
208
        speciesName.setInfraGenericEpithet("Infraabies");
209
        assertEquals("Species Name should be Abies (Infraabies) alba", "Abies (Infraabies) alba", speciesName.getNameCache());
210

    
211
        BotanicalName botName = BotanicalName.NewInstance(Rank.VARIETY());
212
        botName.setGenusOrUninomial("Lepidocaryum");
213
        botName.setInfraGenericEpithet("Infralepi");
214
        botName.setSpecificEpithet("tenue");
215
        botName.setInfraSpecificEpithet("tenue");
216
        assertEquals("Name cache should be Lepidocaryum (Infralepi) tenue var. tenue", "Lepidocaryum (Infralepi) tenue var. tenue", botName.getNameCache());
217

    
218
        botName.setInfraGenericEpithet(" ");
219
        //Note: This test may fail if aspectj doesn't work correctly
220
        assertEquals("Empty infrageneric epithet must be neglegted", "Lepidocaryum tenue var. tenue", botName.getNameCache());
221
    }
222

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

    
249
    /**
250
     * Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#getAuthorshipCache(eu.etaxonomy.cdm.model.name.NonViralName)}.
251
     */
252
    @Test
253
    public void testHybridNames() {
254
        //Note \u00D7 : hybrid sign (multiplication sign)
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
        speciesName.setBinomHybrid(true);
260
        //Note: This test may fail if aspectj doesn't work correctly
261
        Assert.assertEquals("Should be Abies \u00D7alba L.", "Abies \u00D7alba L.", speciesName.getTitleCache());
262
        speciesName.setMonomHybrid(true);
263
        Assert.assertEquals("Should be '\u00D7Abies \u00D7alba L.'", "\u00D7Abies \u00D7alba L.", speciesName.getTitleCache());
264

    
265
        Assert.assertEquals("Should be 'Genus'", "Genus", genusName.getTitleCache());
266
        genusName.setMonomHybrid(true);
267
        Assert.assertEquals("Should be '\u00D7Genus'", "\u00D7Genus", genusName.getTitleCache());
268

    
269
        Assert.assertEquals("Should be 'Abies alba subsp. beta'", subSpeciesNameString, subSpeciesName.getTitleCache());
270
        subSpeciesName.setTrinomHybrid(true);
271
        Assert.assertEquals("Should be 'Abies alba subsp. \u00D7beta'", "Abies alba subsp. \u00D7beta", subSpeciesName.getTitleCache());
272
        subSpeciesName.setMonomHybrid(true);
273
        Assert.assertEquals("Should be '\u00D7Abies alba subsp. \u00D7beta'", "\u00D7Abies alba subsp. \u00D7beta", subSpeciesName.getTitleCache());
274
    }
275

    
276
    @Test
277
    public void testHybridFormula(){
278
        this.speciesName.setCombinationAuthorship(author);
279
        Assert.assertEquals(author.getNomenclaturalTitle(), speciesName.getAuthorshipCache());
280
        Assert.assertEquals("Should be 'Abies alba L.'", "Abies alba L.", speciesName.getTitleCache());
281

    
282
        NonViralName hybridName = NonViralName.NewInstance(Rank.SPECIES());
283
        NonViralName secondParent = NonViralName.NewInstance(Rank.SPECIES());
284

    
285
        secondParent.setTitleCache("Second parent Mill.", true);
286
        hybridName.addHybridParent(speciesName, HybridRelationshipType.FIRST_PARENT(), null);
287
        hybridName.addHybridParent(secondParent, HybridRelationshipType.SECOND_PARENT(), null);
288
        hybridName.setHybridFormula(true);
289

    
290
        Assert.assertEquals("", "Abies alba L. \u00D7 Second parent Mill.", hybridName.getTitleCache());
291

    
292
    }
293

    
294
    //TODO add more tests when specification is clearer
295
    @Test
296
    public void testOriginalSpelling() {
297
    	NameRelationshipType origSpellingType = NameRelationshipType.ORIGINAL_SPELLING();
298
    	NonViralName<?> originalName = (NonViralName<?>)speciesName.clone();
299
    	originalName.setSpecificEpithet("alpa");
300
    	Assert.assertEquals("Preconditions are wrong", "Abies alpa", originalName.getNameCache());
301

    
302
    	speciesName.addRelationshipFromName(originalName, origSpellingType, null);
303
    	Assert.assertEquals("Abies alba 'alpa'", speciesName.getNameCache());
304
    	originalName.setGenusOrUninomial("Apies");
305

    
306
    	speciesName.setNameCache(null, false);
307
    	//TODO update cache of current name (species name)
308
    	Assert.assertEquals("Abies alba 'Apies alpa'", speciesName.getNameCache());
309

    
310
    	//TODO add more tests when specification of exact behaviour is clearer
311
    }
312

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

    
332
        subSpeciesName.setProtectedNameCache(true);
333
        subSpeciesName.setSpecificEpithet("gamma");
334
        Assert.assertEquals("Expected full title cache has error", "Abies alba (Basio, A.) L., GenericRef", subSpeciesName.getFullTitleCache());
335
        Assert.assertEquals("Expected full title cache has error", "Abies alba (Basio, A.) L.", subSpeciesName.getTitleCache());
336
        Assert.assertEquals("Expected full title cache has error", "Abies alba", subSpeciesName.getNameCache());
337
        //make original status
338
        subSpeciesName.setRank(Rank.SUBSPECIES());
339
        Assert.assertEquals("Expected full title cache has error", "Abies alba (Basio, A.) L., GenericRef", subSpeciesName.getFullTitleCache());
340

    
341
        //author change
342
        author.setNomenclaturalTitle("M.");
343
        Assert.assertEquals("Expected full title cache has error", "(Basio, A.) M.", subSpeciesName.getAuthorshipCache());
344
        Assert.assertEquals("Expected full title cache has error", "Abies alba (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
345
        Assert.assertEquals("Expected full title cache has error", "Abies alba (Basio, A.) M.", subSpeciesName.getTitleCache());
346

    
347
        //protectedTitleCache
348
        subSpeciesName.setProtectedTitleCache(true);
349
        subSpeciesName.setProtectedNameCache(false);
350
        subSpeciesName.setGenusOrUninomial("Pinus");
351
        subSpeciesName.setSpecificEpithet("alba");
352
        Assert.assertEquals("Expected full title cache has error", "Pinus alba subsp. beta", subSpeciesName.getNameCache());
353
        Assert.assertEquals("Expected full title cache has error", "Abies alba (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
354
        Assert.assertEquals("Expected full title cache has error", "Abies alba (Basio, A.) M.", subSpeciesName.getTitleCache());
355

    
356
        subSpeciesName.setTitleCache("Pinus beta C.", true);
357
        Assert.assertEquals("Expected full title cache has error", "Pinus beta C., GenericRef", subSpeciesName.getFullTitleCache());
358
        subSpeciesName.setProtectedTitleCache(false);
359

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

    
362
        //protected full title cache set
363
        subSpeciesName.setFullTitleCache("ABC");
364
        Assert.assertEquals("Expected full title cache has error", "ABC", subSpeciesName.getFullTitleCache());
365
        subSpeciesName.setProtectedFullTitleCache(false);
366
        Assert.assertEquals("Expected full title cache has error", "Pinus alba subsp. beta (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
367

    
368
        //protected title cache set
369
        subSpeciesName.setProtectedTitleCache(false);
370
        Assert.assertEquals("Expected full title cache has error", "Pinus alba subsp. beta (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
371

    
372
        //protectedNameCache set
373
        subSpeciesName.setProtectedNameCache(true);
374
        Assert.assertEquals("Expected full title cache has error", "Pinus alba subsp. beta (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
375
        subSpeciesName.setNameCache("P. alba subsp. beta");
376
        Assert.assertEquals("Expected full title cache has error", "P. alba subsp. beta (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
377

    
378
        subSpeciesName.setGenusOrUninomial("A.");
379
        subSpeciesName.setProtectedNameCache(false);
380
        Assert.assertEquals("Expected full title cache has error", "A. alba subsp. beta (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
381
        subSpeciesName.setNameCache("P. alba subsp. beta");
382
        Assert.assertEquals("Expected full title cache has error", "P. alba subsp. beta (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
383

    
384
        //protected authorship
385
        subSpeciesName.setProtectedAuthorshipCache(true);
386
        Assert.assertEquals("Expected full title cache has error", "P. alba subsp. beta (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
387
        subSpeciesName.setAuthorshipCache("Ciard.");
388
        Assert.assertEquals("Expected full title cache has error", "P. alba subsp. beta Ciard., GenericRef", subSpeciesName.getFullTitleCache());
389

    
390
        author.setNomenclaturalTitle("X.");
391
        subSpeciesName.setProtectedAuthorshipCache(false);
392
        Assert.assertEquals("Expected full title cache has error", "P. alba subsp. beta (Basio, A.) X., GenericRef", subSpeciesName.getFullTitleCache());
393

    
394
        //clear
395
        subSpeciesName.setProtectedNameCache(false);
396
        Assert.assertEquals("Expected full title cache has error", "A. alba subsp. beta (Basio, A.) X., GenericRef", subSpeciesName.getFullTitleCache());
397

    
398
        //appended phrase
399
        subSpeciesName.setProtectedNameCache(true);
400
        Assert.assertEquals("Expected full title cache has error", "A. alba subsp. beta (Basio, A.) X., GenericRef", subSpeciesName.getFullTitleCache());
401
        subSpeciesName.setAppendedPhrase("app phrase");
402
        Assert.assertEquals("Expected full title cache has error", "A. alba subsp. beta (Basio, A.) X., GenericRef", subSpeciesName.getFullTitleCache());
403
        subSpeciesName.setProtectedNameCache(false);
404
        Assert.assertEquals("Expected full title cache has error", "A. alba subsp. beta app phrase (Basio, A.) X., GenericRef", subSpeciesName.getFullTitleCache());
405
        subSpeciesName.setAppendedPhrase("app2 phrase2");
406
        subSpeciesName.setProtectedNameCache(true);
407
        Assert.assertNull("NameCache should be null", subSpeciesName.getNameCache());
408
        subSpeciesName.setProtectedNameCache(false);
409
        subSpeciesName.setAppendedPhrase(null);
410

    
411

    
412
        //ref + nomRef
413
        Reference book = ReferenceFactory.newBook();
414
        book.setTitle("Booktitle");
415
        Assert.assertNotNull("TitleCache should not be null", subSpeciesName.getTitleCache());
416
        subSpeciesName.setNomenclaturalReference(book);
417
        subSpeciesName.setNomenclaturalMicroReference("22");
418
        Assert.assertEquals("Expected full title cache has error", "A. alba subsp. beta (Basio, A.) X., Booktitle: 22", subSpeciesName.getFullTitleCache());
419
        subSpeciesName.setProtectedTitleCache(true);
420
        Assert.assertNotNull("TitleCache should not be null", subSpeciesName.getTitleCache());
421

    
422
        //year
423
        ZoologicalName zooName = ZoologicalName.NewInstance(Rank.SPECIES());
424
        zooName.setGenusOrUninomial("Homo");
425
        zooName.setSpecificEpithet("sapiens");
426
        zooName.setBasionymAuthorship(basAuthor);
427
        zooName.setCombinationAuthorship(author);
428
        zooName.setNomenclaturalReference(book);
429
        zooName.setNomenclaturalMicroReference("22");
430
        Assert.assertEquals("Expected full title cache has error", "Homo sapiens (Basio, A.) X., Booktitle: 22", zooName.getFullTitleCache());
431

    
432
        zooName.setOriginalPublicationYear(1922);
433
        zooName.setPublicationYear(1948);
434
        Assert.assertEquals("Expected full title cache has error", "Homo sapiens (Basio, A., 1922) X., 1948, Booktitle: 22", zooName.getFullTitleCache());
435
        zooName.setOriginalPublicationYear(1923);
436
        zooName.setProtectedAuthorshipCache(true);
437
        Assert.assertNull("AuthorshipCache should be null", zooName.getAuthorshipCache());
438
        zooName.setProtectedAuthorshipCache(false);
439
        Assert.assertNotNull("AuthorshipCache should not be null", zooName.getAuthorshipCache());
440
        zooName.setPublicationYear(1949);
441
        zooName.setProtectedAuthorshipCache(true);
442
        Assert.assertNull("AuthorshipCache should be null", zooName.getAuthorshipCache());
443

    
444

    
445

    
446

    
447
    }
448

    
449
    /**
450
     * Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#setNameAuthorSeperator(java.lang.String)}.
451
     */
452
    @Test
453
    public void testGetSetNameAuthorSeperator() {
454
        String authorSeparator = "authorSeparator";
455
        strategy.setNameAuthorSeperator(authorSeparator);
456
        assertEquals(authorSeparator, strategy.getNameAuthorSeperator());
457
        strategy.setNameAuthorSeperator(null);
458
        assertNull(strategy.getNameAuthorSeperator());
459
    }
460

    
461
    /**
462
     * Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#setBasionymStart(java.lang.String)}.
463
     * Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#getBasionymStart()}.
464
     */
465
    @Test
466
    public void testGetSetBasionymStart() {
467
        String basStart = "start";
468
        strategy.setBasionymStart(basStart);
469
        assertEquals(basStart, strategy.getBasionymStart());
470
        strategy.setBasionymStart(null);
471
        assertNull(strategy.getBasionymStart());
472
    }
473

    
474
    /**
475
     * Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#setBasionymEnd(java.lang.String)}.
476
     * Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#getBasionymEnd()}.
477
    */
478
    @Test
479
    public void testGetSetBasionymEnd() {
480
        String basEnd = "end";
481
        strategy.setBasionymEnd(basEnd);
482
        assertEquals(basEnd, strategy.getBasionymEnd());
483
        strategy.setBasionymEnd(null);
484
        assertNull(strategy.getBasionymEnd());
485
    }
486

    
487
    /**
488
     * Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#setExAuthorSeperator(java.lang.String)}.
489
     * Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#getExAuthorSeperator()}.
490
     */
491
    @Test
492
    public void testGetSetExAuthorSeperator() {
493
        String exAuthorSeparator = "exAuthorSeparator";
494
        strategy.setExAuthorSeperator(exAuthorSeparator);
495
        assertEquals(exAuthorSeparator, strategy.getExAuthorSeperator());
496
        strategy.setExAuthorSeperator(null);
497
        assertNull(strategy.getExAuthorSeperator());
498
    }
499

    
500
    /**
501
     * Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#setBasionymAuthorCombinationAuthorSeperator(java.lang.CharSequence)}.
502
     * Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#getBasionymAuthorCombinationAuthorSeperator()}.
503
     */
504
    @Test
505
    public void testSetBasionymAuthorCombinationAuthorSeperator() {
506
        String basComSeparator = "basComSeparator";
507
        strategy.setBasionymAuthorCombinationAuthorSeperator(basComSeparator);
508
        assertEquals(basComSeparator, strategy.getBasionymAuthorCombinationAuthorSeperator());
509
        strategy.setBasionymAuthorCombinationAuthorSeperator(null);
510
        assertNull(strategy.getBasionymAuthorCombinationAuthorSeperator());
511
    }
512

    
513
    @Test
514
    public void testGetInfraGenericNames(){
515
        String author = "Anyauthor";
516
        NonViralName nonViralName = NonViralName.NewInstance(Rank.SUBGENUS());
517
        nonViralName.setGenusOrUninomial("Genus");
518
        nonViralName.setInfraGenericEpithet("subgenus");
519
        nonViralName.setAuthorshipCache(author);
520

    
521
        //test ordinary infrageneric
522
        List<TaggedText> subGenusNameCacheTagged = strategy.getInfraGenusTaggedNameCache(nonViralName);
523
        String subGenusNameCache = TaggedCacheHelper.createString(subGenusNameCacheTagged);
524
        assertEquals("Subgenus name should be 'Genus subg. subgenus'.", "Genus subg. subgenus", subGenusNameCache);
525
        String subGenusTitle = strategy.getTitleCache(nonViralName);
526
        assertEquals("Subgenus name should be 'Genus subg. subgenus Anyauthor'.", "Genus subg. subgenus Anyauthor", subGenusTitle);
527

    
528
        //test species aggregates and species groups
529
        nonViralName.setRank(Rank.SPECIESAGGREGATE());
530
        nonViralName.setSpecificEpithet("myspecies");
531
        nonViralName.setInfraGenericEpithet(null);
532
        nonViralName.setAuthorshipCache(null);
533

    
534
        List<TaggedText> aggrNameCacheTagged = strategy.getInfraGenusTaggedNameCache(nonViralName);
535

    
536
        String aggrNameCache = TaggedCacheHelper.createString(aggrNameCacheTagged);
537
        assertEquals("Species aggregate name should be 'Genus myspecies aggr.'.", "Genus myspecies aggr.", aggrNameCache);
538
        String aggrNameTitle = strategy.getTitleCache(nonViralName);
539
        Assert.assertTrue("Species aggregate should not include author information.", aggrNameTitle.indexOf(author) == -1);
540
        assertEquals("Species aggregate name should be 'Genus myspecies aggr.'.", "Genus myspecies aggr.", aggrNameTitle);
541
        nonViralName.setRank(Rank.SPECIESGROUP());
542
        String groupNameTitle = strategy.getTitleCache(nonViralName);
543
        assertEquals("Species group name should be 'Genus myspecies species group'.", "Genus myspecies species group", groupNameTitle);
544

    
545
        //test species aggregates and species groups with infrageneric information
546
        //TODO check if groups do ever have infrageneric epithets
547
        nonViralName.setRank(Rank.SPECIESAGGREGATE());
548
        nonViralName.setSpecificEpithet("myspecies");
549
        nonViralName.setInfraGenericEpithet("Infragenus");
550

    
551

    
552
        aggrNameCacheTagged = strategy.getInfraGenusTaggedNameCache(nonViralName);
553
        aggrNameCache = TaggedCacheHelper.createString(aggrNameCacheTagged);
554
        assertEquals("Species aggregate name should be 'Genus (Infragenus) myspecies aggr.'.", "Genus (Infragenus) myspecies aggr.", aggrNameCache);
555

    
556
        aggrNameTitle = strategy.getTitleCache(nonViralName);
557
        Assert.assertTrue("Species aggregate should not include author information.", aggrNameTitle.indexOf(author) == -1);
558
        assertEquals("Species aggregate name should be 'Genus (Infragenus) myspecies aggr.'.", "Genus (Infragenus) myspecies aggr.", aggrNameTitle);
559

    
560
        nonViralName.setRank(Rank.SPECIESGROUP());
561
        groupNameTitle = strategy.getTitleCache(nonViralName);
562
        assertEquals("Species group name should be 'Genus (Infragenus) myspecies species group'.", "Genus (Infragenus) myspecies species group", groupNameTitle);
563

    
564
        //aggregates with author and nom.ref. information #4288
565
        nonViralName.setRank(Rank.SPECIESAGGREGATE());
566
        nonViralName.setSpecificEpithet("myspecies");
567
        nonViralName.setInfraGenericEpithet(null);
568
        nonViralName.setAuthorshipCache("L.");
569

    
570
        aggrNameCacheTagged = strategy.getTaggedTitle(nonViralName);
571
        aggrNameCache = TaggedCacheHelper.createString(aggrNameCacheTagged);
572
        assertEquals("Species aggregate name should be 'Genus myspecies L.'.", "Genus myspecies L.", aggrNameCache);
573

    
574
    }
575

    
576
    /**
577
     * Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy#getTaggedName(eu.etaxonomy.cdm.model.name.NonViralName)}.
578
     */
579
    @Test
580
    public void testGetTaggedNameSpeciesAggregate() {
581
        BotanicalName speciesAggregate = BotanicalName.NewInstance(Rank.SPECIESAGGREGATE());
582
        speciesAggregate.setGenusOrUninomial("Mygenus");
583
        speciesAggregate.setSpecificEpithet("myspecies");
584
        List<TaggedText> taggedName = strategy.getTaggedName(speciesAggregate);
585
        Assert.assertEquals("1rd tag must be genus epithet", "Mygenus", taggedName.get(0).getText());
586
        Assert.assertEquals("2rd tag must be species epithet", "myspecies", taggedName.get(1).getText());
587
        Assert.assertEquals("3rd tag must be aggregate marker", "aggr.",taggedName.get(2).getText());
588
    }
589

    
590

    
591
    @Test
592
    public void testGetTaggedNameSubspecies(){
593
        List<TaggedText> taggedName = strategy.getTaggedName(subSpeciesName);
594
        Assert.assertEquals("First tag should be 'Abies'", "Abies", taggedName.get(0).getText());
595
        Assert.assertEquals("Second tag should be 'alba'", "alba", taggedName.get(1).getText());
596
        Assert.assertEquals("Third tag should be subspecies rank, and rank abbreviatioin should be subsp.", "subsp.", taggedName.get(2).getText());
597
        Assert.assertEquals("Fourth tag should be 'beta'", "beta", taggedName.get(3).getText());
598
        //to be continued
599

    
600
    }
601

    
602
    @Test
603
    public void testTitleCacheHtmlTagged(){
604
    	HTMLTagRules rules = new HTMLTagRules().addRule(TagEnum.name, "i");
605
    	Assert.assertEquals("<i>Abies alba</i>", strategy.getTitleCache(speciesName, rules));
606
    	rules.addRule(TagEnum.name, "b");
607
    	Assert.assertEquals("<b><i>Abies alba</i></b>", strategy.getTitleCache(speciesName, rules));
608
    	speciesName.setCombinationAuthorship(author);
609
    	Assert.assertEquals("<b><i>Abies alba</i></b> L.", strategy.getTitleCache(speciesName, rules));
610
    	rules.addRule(TagEnum.authors, "i");
611
    	Assert.assertEquals("<b><i>Abies alba</i></b> <i>L.</i>", strategy.getTitleCache(speciesName, rules));
612
    	rules = new HTMLTagRules().addRule(TagEnum.name, "i").addRule(TagEnum.name, "b").addRule(TagEnum.authors, "b");
613
    	Assert.assertEquals("<b><i>Abies alba</i> L.</b>", strategy.getTitleCache(speciesName, rules));
614

    
615
    }
616

    
617
    @Test //#2888
618
    public void testAutonymWithExAuthor(){
619
    	BotanicalName name = BotanicalName.NewInstance(Rank.FORM());
620
    	name.setGenusOrUninomial("Euphorbia");
621
    	name.setSpecificEpithet("atropurpurea");
622
    	name.setInfraSpecificEpithet("atropurpurea");
623
    	Team combTeam = Team.NewTitledInstance("Combauthor", "Combauthor");
624
    	name.setCombinationAuthorship(combTeam);
625
    	Team exCombTeam = Team.NewTitledInstance("Excomb", "Excomb");
626
    	name.setExCombinationAuthorship(exCombTeam);
627

    
628
    	Assert.assertEquals("", "Euphorbia atropurpurea Excomb ex Combauthor f. atropurpurea", name.getTitleCache());
629
    }
630

    
631

    
632
}
(3-3/5)