Project

General

Profile

Download (4.53 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10

    
11
package eu.etaxonomy.cdm.strategy.cache.taxon;
12

    
13
import static org.junit.Assert.assertEquals;
14

    
15
import org.apache.log4j.Logger;
16
import org.junit.After;
17
import org.junit.Assert;
18
import org.junit.Before;
19
import org.junit.BeforeClass;
20
import org.junit.Test;
21

    
22
import eu.etaxonomy.cdm.model.agent.Person;
23
import eu.etaxonomy.cdm.model.agent.Team;
24
import eu.etaxonomy.cdm.model.name.BotanicalName;
25
import eu.etaxonomy.cdm.model.name.Rank;
26
import eu.etaxonomy.cdm.model.reference.Reference;
27
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
28
import eu.etaxonomy.cdm.model.taxon.Taxon;
29
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
30
import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl;
31

    
32
/**
33
 * @author a.mueller
34
 * @created 09.09.2015
35
 * NOTE: This test is currently more or less a copy of {@link TaxonBaseDefaultCacheStrategyTest}
36
 * It does NOT yet test the specifics of the class under test.
37
 *
38
 */
39
public class TaxonShortSecCacheStrategyTest {
40
	@SuppressWarnings("unused")
41
	private static final Logger logger = Logger.getLogger(TaxonShortSecCacheStrategyTest.class);
42

    
43
	private final String expectedNameTitleCache = "Abies alba (L.) Mill.";
44
	private final String expectedNameCache = "Abies alba";
45
	private BotanicalName name;
46
	private Reference<?> sec;
47
	private static ITaxonCacheStrategy shortStrategy;
48

    
49
	/**
50
	 * @throws java.lang.Exception
51
	 */
52
	@BeforeClass
53
	public static void setUpBeforeClass() throws Exception {
54
	    shortStrategy = new TaxonBaseShortSecCacheStrategy<TaxonBase>();
55
	}
56

    
57
	/**
58
	 * @throws java.lang.Exception
59
	 */
60
	@Before
61
	public void setUp() throws Exception {
62
		name = BotanicalName.NewInstance(Rank.SPECIES());
63
		name.setGenusOrUninomial("Abies");
64
		name.setSpecificEpithet("alba");
65
		Person combinationAuthor = Person.NewInstance();
66
		combinationAuthor.setNomenclaturalTitle("Mill.");
67
		Person basionymAuthor = Person.NewInstance();
68
		basionymAuthor.setNomenclaturalTitle("L.");
69

    
70
		name.setCombinationAuthorship(combinationAuthor);
71
		name.setBasionymAuthorship(basionymAuthor);
72
		assertEquals("Namecache should be Abies alba", expectedNameCache, name.getNameCache());
73
		assertEquals("Titlecache should be Abies alba (Mill.) L.", expectedNameTitleCache, name.getTitleCache());
74
		sec = ReferenceFactory.newBook();
75
		sec.setTitle("Sp.Pl.");
76
	}
77

    
78
	/**
79
	 * @throws java.lang.Exception
80
	 */
81
	@After
82
	public void tearDown() throws Exception {
83
	}
84

    
85
//******************************* TESTS ********************************************************
86

    
87
	/**
88
	 * Test method for {@link eu.etaxonomy.cdm.strategy.cache.taxon.TaxonBaseDefaultCacheStrategy#getTitleCache(eu.etaxonomy.cdm.model.taxon.TaxonBase)}.
89
	 */
90
	@Test
91
	public void testGetTitleCache() {
92
		TaxonBase taxonBase = Taxon.NewInstance(name, sec);
93
		taxonBase.setCacheStrategy(shortStrategy);
94
		assertEquals("Taxon titlecache is wrong", expectedNameTitleCache + " sec. Sp.Pl.", taxonBase.getTitleCache());
95
		String appendedPhrase = "aff. 'schippii'";
96
		taxonBase.setAppendedPhrase(appendedPhrase);
97
		assertEquals("Taxon titlecache is wrong", expectedNameTitleCache + " aff. 'schippii' sec. Sp.Pl.", taxonBase.getTitleCache());
98
		taxonBase.setUseNameCache(true);
99
		assertEquals("Taxon titlecache is wrong", expectedNameCache + " aff. 'schippii' sec. Sp.Pl.", taxonBase.getTitleCache());
100

    
101

    
102
	}
103

    
104
	//test missing "&" in title cache  #3822
105
	@Test
106
	public void testAndInTitleCache() {
107
		TaxonBase<?> taxonBase = Taxon.NewInstance(name, sec);
108
		Team team = Team.NewInstance();
109
		team.addTeamMember((Person)name.getCombinationAuthorship());
110
		team.addTeamMember((Person)name.getBasionymAuthorship());
111
		name.setCombinationAuthorship(team);
112
		System.out.println(taxonBase.generateTitle());
113
		assertEquals("Abies alba (L.) Mill. \u0026 L. sec. Sp.Pl.", taxonBase.generateTitle());
114

    
115
		name = BotanicalName.NewInstance(null);
116
		NonViralNameParserImpl.NewInstance().parseFullName(name, "Cichorium glandulosum Boiss. \u0026 A. Huet", null, true);
117
		Taxon taxon = Taxon.NewInstance(name, sec);
118
		assertEquals("Cichorium glandulosum Boiss. \u0026 A. Huet sec. Sp.Pl.", taxon.getTitleCache());
119

    
120
	}
121

    
122
	@Test
123
	public void testProtectedTitleCache(){
124
	    TaxonBase<?> taxonBase = Taxon.NewInstance(name, sec);
125
        taxonBase.setProtectedTitleCache(true);
126
        taxonBase.setTitleCache("abc");
127
        taxonBase.setDoubtful(true);
128
        Assert.assertEquals("abc", taxonBase.getTitleCache());
129
	}
130
}
(2-2/2)