Project

General

Profile

Download (4.94 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
	@Test
88
	public void testGetTitleCache() {
89
		TaxonBase taxonBase = Taxon.NewInstance(name, sec);
90
		taxonBase.setCacheStrategy(shortStrategy);
91
		assertEquals("Taxon titlecache is wrong", expectedNameTitleCache + " sec. Sp.Pl.", taxonBase.getTitleCache());
92
		String appendedPhrase = "aff. 'schippii'";
93
		taxonBase.setAppendedPhrase(appendedPhrase);
94
		assertEquals("Taxon titlecache is wrong", expectedNameTitleCache + " aff. 'schippii' sec. Sp.Pl.", taxonBase.getTitleCache());
95
		taxonBase.setUseNameCache(true);
96
		assertEquals("Taxon titlecache is wrong", expectedNameCache + " aff. 'schippii' sec. Sp.Pl.", taxonBase.getTitleCache());
97
	}
98

    
99
   @Test
100
    public void testGetTitleCacheWithoutName() {
101
        TaxonBase taxonBase = Taxon.NewInstance(null, sec);
102
        taxonBase.setCacheStrategy(shortStrategy);
103
        assertEquals("Taxon titlecache is wrong", "??? sec. Sp.Pl.", taxonBase.getTitleCache());
104
   }
105

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

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

    
123
    @Test
124
    public void testMicroReference(){
125
        TaxonBase<?> taxonBase = Taxon.NewInstance(name, sec);
126
        String secMicroRef = "p. 553";
127
        taxonBase.setSecMicroReference(secMicroRef);
128
        assertEquals("Taxon titlecache is wrong", expectedNameTitleCache + " sec. Sp.Pl.: " + secMicroRef,
129
                taxonBase.getTitleCache());
130
    }
131

    
132
	@Test
133
	public void testProtectedTitleCache(){
134
	    TaxonBase<?> taxonBase = Taxon.NewInstance(name, sec);
135
        taxonBase.setTitleCache("abc", true);
136
        taxonBase.setDoubtful(true);
137
        Assert.assertEquals("abc", taxonBase.getTitleCache());
138
	}
139
}
(2-2/2)