Project

General

Profile

Download (7.46 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
package eu.etaxonomy.cdm.strategy.cache.taxon;
10

    
11
import static org.junit.Assert.assertEquals;
12

    
13
import org.apache.log4j.Logger;
14
import org.junit.Assert;
15
import org.junit.Before;
16
import org.junit.Test;
17

    
18
import eu.etaxonomy.cdm.model.agent.Person;
19
import eu.etaxonomy.cdm.model.agent.Team;
20
import eu.etaxonomy.cdm.model.name.IBotanicalName;
21
import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
22
import eu.etaxonomy.cdm.model.name.Rank;
23
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
24
//import eu.etaxonomy.cdm.model.reference.Book;
25
import eu.etaxonomy.cdm.model.reference.Reference;
26
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
27
import eu.etaxonomy.cdm.model.taxon.Synonym;
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
import eu.etaxonomy.cdm.test.TermTestBase;
32

    
33
/**
34
 * @author a.mueller
35
 * @since 21.09.2009
36
 */
37
public class TaxonBaseDefaultCacheStrategyTest extends TermTestBase {
38

    
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
	private IBotanicalName name;
45
	private Reference sec;
46

    
47
	@Before
48
	public void setUp() throws Exception {
49
		name = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
50
		name.setGenusOrUninomial("Abies");
51
		name.setSpecificEpithet("alba");
52
		Person combinationAuthor = Person.NewInstance();
53
		combinationAuthor.setNomenclaturalTitle("Mill.");
54
		Person basionymAuthor = Person.NewInstance();
55
		basionymAuthor.setNomenclaturalTitle("L.");
56

    
57
		name.setCombinationAuthorship(combinationAuthor);
58
		name.setBasionymAuthorship(basionymAuthor);
59
		assertEquals("Namecache should be Abies alba", expectedNameCache, name.getNameCache());
60
		assertEquals("Titlecache should be Abies alba (Mill.) L.", expectedNameTitleCache, name.getTitleCache());
61
		sec = ReferenceFactory.newBook();
62
		sec.setTitle("Sp.Pl.");
63
	}
64

    
65
//******************************* TESTS ********************************************************
66

    
67
	@Test
68
	public void testGetTitleCache() {
69
		TaxonBase<?> taxonBase = Taxon.NewInstance(name, sec);
70
		assertEquals("Taxon titlecache is wrong", expectedNameTitleCache + " sec. Sp.Pl.", taxonBase.getTitleCache());
71
		//without sec.
72
		taxonBase.setSec(null);
73
		assertEquals("Taxon titlecache is wrong", expectedNameTitleCache + " sec. ???", taxonBase.getTitleCache());
74
		//appended phrase without sec.
75
		String appendedPhrase = "aff. 'schippii'";
76
		taxonBase.setAppendedPhrase(appendedPhrase);
77
		assertEquals("Taxon titlecache is wrong", expectedNameTitleCache + " aff. 'schippii'", taxonBase.getTitleCache());
78
		//appended phrase with sec.
79
		taxonBase.setSec(sec);
80
		assertEquals("Taxon titlecache is wrong", expectedNameTitleCache + " aff. 'schippii' sec. Sp.Pl.", taxonBase.getTitleCache());
81
		//use name cache
82
		taxonBase.setUseNameCache(true);
83
		assertEquals("Taxon titlecache is wrong", expectedNameCache + " aff. 'schippii' sec. Sp.Pl.", taxonBase.getTitleCache());
84
		taxonBase.setDoubtful(true);
85
        assertEquals("Taxon titlecache is wrong", "?" + expectedNameCache + " aff. 'schippii' sec. Sp.Pl.", taxonBase.getTitleCache());
86
        //with nom status
87
        taxonBase.setAppendedPhrase(null);
88
        taxonBase.setUseNameCache(false);
89
        taxonBase.setDoubtful(false);
90
        name.addStatus(NomenclaturalStatusType.ILLEGITIMATE(), null, null);
91
        assertEquals("Taxon titlecache is wrong", expectedNameTitleCache + ", nom. illeg., sec. Sp.Pl.", taxonBase.getTitleCache());
92
	}
93

    
94
	//same as for accepted taxa but with syn. sec. instead of sec.
95
    @Test
96
    public void testSynSec() {
97
        Synonym taxonBase = Synonym.NewInstance(name, sec);
98
        assertEquals("Taxon titlecache is wrong", expectedNameTitleCache + " syn. sec. Sp.Pl.", taxonBase.getTitleCache());
99
        //without sec.
100
        taxonBase.setSec(null);
101
        assertEquals("Taxon titlecache is wrong", expectedNameTitleCache + " syn. sec. ???", taxonBase.getTitleCache());
102
        //appended phrase without sec.
103
        String appendedPhrase = "aff. 'schippii'";
104
        taxonBase.setAppendedPhrase(appendedPhrase);
105
        assertEquals("Taxon titlecache is wrong", expectedNameTitleCache + " aff. 'schippii'", taxonBase.getTitleCache());
106
        //appended phrase with sec.
107
        taxonBase.setSec(sec);
108
        assertEquals("Taxon titlecache is wrong", expectedNameTitleCache + " aff. 'schippii' syn. sec. Sp.Pl.", taxonBase.getTitleCache());
109
        //use name cache
110
        taxonBase.setUseNameCache(true);
111
        assertEquals("Taxon titlecache is wrong", expectedNameCache + " aff. 'schippii' syn. sec. Sp.Pl.", taxonBase.getTitleCache());
112
        taxonBase.setDoubtful(true);
113
        assertEquals("Taxon titlecache is wrong", "?" + expectedNameCache + " aff. 'schippii' syn. sec. Sp.Pl.", taxonBase.getTitleCache());
114
        //with nom status
115
        taxonBase.setAppendedPhrase(null);
116
        taxonBase.setUseNameCache(false);
117
        taxonBase.setDoubtful(false);
118
        name.addStatus(NomenclaturalStatusType.ILLEGITIMATE(), null, null);
119
        assertEquals("Taxon titlecache is wrong", expectedNameTitleCache + ", nom. illeg., syn. sec. Sp.Pl.", taxonBase.getTitleCache());
120
    }
121

    
122
   @Test
123
    public void testGetTitleCacheWithoutName() {
124
        TaxonBase<?> taxonBase = Taxon.NewInstance(null, sec);
125
        assertEquals("Taxon titlecache is wrong", "??? sec. Sp.Pl.", taxonBase.getTitleCache());
126
    }
127

    
128
	//test missing "&" in title cache  #3822
129
	@Test
130
	public void testAndInTitleCache() {
131
		TaxonBase<?> taxonBase = Taxon.NewInstance(name, sec);
132
		Team team = Team.NewInstance();
133
		team.addTeamMember((Person)name.getCombinationAuthorship());
134
		team.addTeamMember((Person)name.getBasionymAuthorship());
135
		name.setCombinationAuthorship(team);
136
//		System.out.println(taxonBase.generateTitle());
137
		assertEquals("Abies alba (L.) Mill. \u0026 L. sec. Sp.Pl.", taxonBase.generateTitle());
138

    
139
		name = TaxonNameFactory.NewBotanicalInstance(null);
140
		NonViralNameParserImpl.NewInstance().parseFullName(name, "Cichorium glandulosum Boiss. \u0026 A. Huet", null, true);
141
		Taxon taxon = Taxon.NewInstance(name, sec);
142
		assertEquals("Cichorium glandulosum Boiss. \u0026 A. Huet sec. Sp.Pl.", taxon.getTitleCache());
143
	}
144

    
145
    @Test
146
	public void testProtectedTitleCache(){
147
	    TaxonBase<?> taxonBase = Taxon.NewInstance(name, sec);
148
        taxonBase.setTitleCache("abc", true);
149
        taxonBase.setDoubtful(true);
150
        Assert.assertEquals("abc", taxonBase.getTitleCache());
151
	}
152

    
153
    @Test
154
    public void testProtectedSecTitleCache(){
155
        TaxonBase<?> taxonBase = Taxon.NewInstance(name, sec);
156
        sec.setTitleCache("My protected sec ref", true);
157
        taxonBase.setDoubtful(true);
158
        taxonBase.setSecMicroReference("123");
159
        Assert.assertEquals("?Abies alba (L.) Mill. sec. My protected sec ref: 123", taxonBase.getTitleCache());
160
    }
161

    
162
    @Test
163
    public void testMicroReference(){
164
        TaxonBase<?> taxonBase = Taxon.NewInstance(name, sec);
165
        String secMicroRef = "p. 553";
166
        taxonBase.setSecMicroReference(secMicroRef);
167
        assertEquals("Taxon titlecache is wrong", expectedNameTitleCache + " sec. Sp.Pl.: " + secMicroRef,
168
                taxonBase.getTitleCache());
169
    }
170
}
(1-1/2)