Project

General

Profile

Download (4.55 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.AfterClass;
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.name.BotanicalName;
26
import eu.etaxonomy.cdm.model.name.Rank;
27
//import eu.etaxonomy.cdm.model.reference.Book;
28
import eu.etaxonomy.cdm.model.reference.Reference;
29
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
30
import eu.etaxonomy.cdm.model.taxon.Taxon;
31
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
32
import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl;
33

    
34
/**
35
 * @author a.mueller
36
 * @created 21.09.2009
37
 */
38
public class TaxonBaseDefaultCacheStrategyTest {
39
	@SuppressWarnings("unused")
40
	private static final Logger logger = Logger.getLogger(TaxonBaseDefaultCacheStrategyTest.class);
41

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

    
47
	/**
48
	 * @throws java.lang.Exception
49
	 */
50
	@BeforeClass
51
	public static void setUpBeforeClass() throws Exception {
52
	}
53

    
54
	/**
55
	 * @throws java.lang.Exception
56
	 */
57
	@AfterClass
58
	public static void tearDownAfterClass() throws Exception {
59
	}
60

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

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

    
82
	/**
83
	 * @throws java.lang.Exception
84
	 */
85
	@After
86
	public void tearDown() throws Exception {
87
	}
88

    
89
//******************************* TESTS ********************************************************
90

    
91
	/**
92
	 * Test method for {@link eu.etaxonomy.cdm.strategy.cache.taxon.TaxonBaseDefaultCacheStrategy#getTitleCache(eu.etaxonomy.cdm.model.taxon.TaxonBase)}.
93
	 */
94
	@Test
95
	public void testGetTitleCache() {
96
		TaxonBase<?> taxonBase = Taxon.NewInstance(name, sec);
97
		assertEquals("Taxon titlecache is wrong", expectedNameTitleCache + " sec. Sp.Pl.", taxonBase.getTitleCache());
98
		String appendedPhrase = "aff. 'schippii'";
99
		taxonBase.setAppendedPhrase(appendedPhrase);
100
		assertEquals("Taxon titlecache is wrong", expectedNameTitleCache + " aff. 'schippii' sec. Sp.Pl.", taxonBase.getTitleCache());
101
		taxonBase.setUseNameCache(true);
102
		assertEquals("Taxon titlecache is wrong", expectedNameCache + " aff. 'schippii' sec. Sp.Pl.", taxonBase.getTitleCache());
103
		taxonBase.setDoubtful(true);
104
        assertEquals("Taxon titlecache is wrong", "?" + expectedNameCache + " aff. 'schippii' sec. Sp.Pl.", taxonBase.getTitleCache());
105
	}
106

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

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

    
123
	}
124

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