Project

General

Profile

Download (33.6 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 [unranked] 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 nothosubsp. beta or nbeta'", "Abies alba nothosubsp. beta", subSpeciesName.getTitleCache());
272
        subSpeciesName.setMonomHybrid(true);
273
        Assert.assertEquals("Should be '\u00D7Abies alba nothosubsp. beta'", "\u00D7Abies alba nothosubsp. beta", subSpeciesName.getTitleCache());
274

    
275
        Assert.assertEquals("Should be 'Genus subg. InfraGenericPart'", "Genus subg. InfraGenericPart", subGenusName.getTitleCache());
276
        subGenusName.setBinomHybrid(true);
277
        Assert.assertEquals("Should be 'Genus nothosubg. InfraGenericPart'", "Genus nothosubg. InfraGenericPart", subGenusName.getTitleCache());
278
    }
279

    
280
    @Test
281
    public void testHybridFormula(){
282
        this.speciesName.setCombinationAuthorship(author);
283
        Assert.assertEquals(author.getNomenclaturalTitle(), speciesName.getAuthorshipCache());
284
        Assert.assertEquals("Should be 'Abies alba L.'", "Abies alba L.", speciesName.getTitleCache());
285

    
286
        NonViralName hybridName = NonViralName.NewInstance(Rank.SPECIES());
287
        NonViralName secondParent = NonViralName.NewInstance(Rank.SPECIES());
288

    
289
        secondParent.setTitleCache("Second parent Mill.", true);
290
        hybridName.addHybridParent(speciesName, HybridRelationshipType.FIRST_PARENT(), null);
291
        hybridName.addHybridParent(secondParent, HybridRelationshipType.SECOND_PARENT(), null);
292
        hybridName.setHybridFormula(true);
293

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

    
296
    }
297

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

    
306
    	speciesName.addRelationshipFromName(originalName, origSpellingType, null);
307
    	Assert.assertEquals("Abies alba 'alpa'", speciesName.getNameCache());
308
    	originalName.setGenusOrUninomial("Apies");
309

    
310
    	speciesName.setNameCache(null, false);
311
    	//TODO update cache of current name (species name)
312
    	Assert.assertEquals("Abies alba 'Apies alpa'", speciesName.getNameCache());
313

    
314
    	//TODO add more tests when specification of exact behaviour is clearer
315
    }
316

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

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

    
345
        //author change
346
        author.setNomenclaturalTitle("M.");
347
        Assert.assertEquals("Expected full title cache has error", "(Basio, A.) M.", subSpeciesName.getAuthorshipCache());
348
        Assert.assertEquals("Expected full title cache has error", "Abies alba (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
349
        Assert.assertEquals("Expected full title cache has error", "Abies alba (Basio, A.) M.", subSpeciesName.getTitleCache());
350

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

    
360
        subSpeciesName.setTitleCache("Pinus beta C.", true);
361
        Assert.assertEquals("Expected full title cache has error", "Pinus beta C., GenericRef", subSpeciesName.getFullTitleCache());
362
        subSpeciesName.setProtectedTitleCache(false);
363

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

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

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

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

    
382
        subSpeciesName.setGenusOrUninomial("A.");
383
        subSpeciesName.setProtectedNameCache(false);
384
        Assert.assertEquals("Expected full title cache has error", "A. alba subsp. beta (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
385
        subSpeciesName.setNameCache("P. alba subsp. beta");
386
        Assert.assertEquals("Expected full title cache has error", "P. alba subsp. beta (Basio, A.) M., GenericRef", subSpeciesName.getFullTitleCache());
387

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

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

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

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

    
415

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

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

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

    
448

    
449

    
450

    
451
    }
452

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

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

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

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

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

    
517
    @Test
518
    public void testGetInfraGenericNames(){
519
        String author = "Anyauthor";
520
        NonViralName nonViralName = NonViralName.NewInstance(Rank.SUBGENUS());
521
        nonViralName.setGenusOrUninomial("Genus");
522
        nonViralName.setInfraGenericEpithet("subgenus");
523
        nonViralName.setAuthorshipCache(author);
524

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

    
532
        //test species aggregates and species groups
533
        nonViralName.setRank(Rank.SPECIESAGGREGATE());
534
        nonViralName.setSpecificEpithet("myspecies");
535
        nonViralName.setInfraGenericEpithet(null);
536
        nonViralName.setAuthorshipCache(null);
537

    
538
        List<TaggedText> aggrNameCacheTagged = strategy.getInfraGenusTaggedNameCache(nonViralName);
539

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

    
549
        //test species aggregates and species groups with infrageneric information
550
        //TODO check if groups do ever have infrageneric epithets
551
        nonViralName.setRank(Rank.SPECIESAGGREGATE());
552
        nonViralName.setSpecificEpithet("myspecies");
553
        nonViralName.setInfraGenericEpithet("Infragenus");
554

    
555

    
556
        aggrNameCacheTagged = strategy.getInfraGenusTaggedNameCache(nonViralName);
557
        aggrNameCache = TaggedCacheHelper.createString(aggrNameCacheTagged);
558
        assertEquals("Species aggregate name should be 'Genus (Infragenus) myspecies aggr.'.", "Genus (Infragenus) myspecies aggr.", aggrNameCache);
559

    
560
        aggrNameTitle = strategy.getTitleCache(nonViralName);
561
        Assert.assertTrue("Species aggregate should not include author information.", aggrNameTitle.indexOf(author) == -1);
562
        assertEquals("Species aggregate name should be 'Genus (Infragenus) myspecies aggr.'.", "Genus (Infragenus) myspecies aggr.", aggrNameTitle);
563

    
564
        nonViralName.setRank(Rank.SPECIESGROUP());
565
        groupNameTitle = strategy.getTitleCache(nonViralName);
566
        assertEquals("Species group name should be 'Genus (Infragenus) myspecies species group'.", "Genus (Infragenus) myspecies species group", groupNameTitle);
567

    
568
        //aggregates with author and nom.ref. information #4288
569
        nonViralName.setRank(Rank.SPECIESAGGREGATE());
570
        nonViralName.setSpecificEpithet("myspecies");
571
        nonViralName.setInfraGenericEpithet(null);
572
        nonViralName.setAuthorshipCache("L.");
573

    
574
        aggrNameCacheTagged = strategy.getTaggedTitle(nonViralName);
575
        aggrNameCache = TaggedCacheHelper.createString(aggrNameCacheTagged);
576
        assertEquals("Species aggregate name should be 'Genus myspecies L.'.", "Genus myspecies L.", aggrNameCache);
577

    
578
    }
579

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

    
594

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

    
604
    }
605

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

    
619
    }
620

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

    
632
    	Assert.assertEquals("", "Euphorbia atropurpurea Excomb ex Combauthor f. atropurpurea", name.getTitleCache());
633
    }
634

    
635

    
636
}
(3-3/5)