Project

General

Profile

Download (8.18 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.taxon;
11

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

    
14
import org.apache.log4j.Logger;
15
import org.junit.After;
16
import org.junit.AfterClass;
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.common.DefaultTermInitializer;
25
import eu.etaxonomy.cdm.model.name.IBotanicalName;
26
import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
27
import eu.etaxonomy.cdm.model.name.Rank;
28
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
29
//import eu.etaxonomy.cdm.model.reference.Book;
30
import eu.etaxonomy.cdm.model.reference.Reference;
31
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
32
import eu.etaxonomy.cdm.model.taxon.Synonym;
33
import eu.etaxonomy.cdm.model.taxon.Taxon;
34
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
35
import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl;
36

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

    
45
	private final String expectedNameTitleCache = "Abies alba (L.) Mill.";
46
	private final String expectedNameCache = "Abies alba";
47
	private IBotanicalName name;
48
	private Reference sec;
49

    
50
	/**
51
	 * @throws java.lang.Exception
52
	 */
53
	@BeforeClass
54
	public static void setUpBeforeClass() throws Exception {
55
        DefaultTermInitializer vocabularyStore = new DefaultTermInitializer();
56
        vocabularyStore.initialize();
57
	}
58

    
59
	/**
60
	 * @throws java.lang.Exception
61
	 */
62
	@AfterClass
63
	public static void tearDownAfterClass() throws Exception {
64
	}
65

    
66
	/**
67
	 * @throws java.lang.Exception
68
	 */
69
	@Before
70
	public void setUp() throws Exception {
71
		name = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
72
		name.setGenusOrUninomial("Abies");
73
		name.setSpecificEpithet("alba");
74
		Person combinationAuthor = Person.NewInstance();
75
		combinationAuthor.setNomenclaturalTitle("Mill.");
76
		Person basionymAuthor = Person.NewInstance();
77
		basionymAuthor.setNomenclaturalTitle("L.");
78

    
79
		name.setCombinationAuthorship(combinationAuthor);
80
		name.setBasionymAuthorship(basionymAuthor);
81
		assertEquals("Namecache should be Abies alba", expectedNameCache, name.getNameCache());
82
		assertEquals("Titlecache should be Abies alba (Mill.) L.", expectedNameTitleCache, name.getTitleCache());
83
		sec = ReferenceFactory.newBook();
84
		sec.setTitle("Sp.Pl.");
85
	}
86

    
87
	/**
88
	 * @throws java.lang.Exception
89
	 */
90
	@After
91
	public void tearDown() throws Exception {
92
	}
93

    
94
//******************************* TESTS ********************************************************
95

    
96
    /**
97
	 * Test method for {@link eu.etaxonomy.cdm.strategy.cache.taxon.TaxonBaseDefaultCacheStrategy#getTitleCache(eu.etaxonomy.cdm.model.taxon.TaxonBase)}.
98
	 */
99
	@Test
100
	public void testGetTitleCache() {
101
		TaxonBase<?> taxonBase = Taxon.NewInstance(name, sec);
102
		assertEquals("Taxon titlecache is wrong", expectedNameTitleCache + " sec. Sp.Pl.", taxonBase.getTitleCache());
103
		//without sec.
104
		taxonBase.setSec(null);
105
		assertEquals("Taxon titlecache is wrong", expectedNameTitleCache + " sec. ???", taxonBase.getTitleCache());
106
		//appended phrase without sec.
107
		String appendedPhrase = "aff. 'schippii'";
108
		taxonBase.setAppendedPhrase(appendedPhrase);
109
		assertEquals("Taxon titlecache is wrong", expectedNameTitleCache + " aff. 'schippii'", taxonBase.getTitleCache());
110
		//appended phrase with sec.
111
		taxonBase.setSec(sec);
112
		assertEquals("Taxon titlecache is wrong", expectedNameTitleCache + " aff. 'schippii' sec. Sp.Pl.", taxonBase.getTitleCache());
113
		//use name cache
114
		taxonBase.setUseNameCache(true);
115
		assertEquals("Taxon titlecache is wrong", expectedNameCache + " aff. 'schippii' sec. Sp.Pl.", taxonBase.getTitleCache());
116
		taxonBase.setDoubtful(true);
117
        assertEquals("Taxon titlecache is wrong", "?" + expectedNameCache + " aff. 'schippii' sec. Sp.Pl.", taxonBase.getTitleCache());
118
        //with nom status
119
        taxonBase.setAppendedPhrase(null);
120
        taxonBase.setUseNameCache(false);
121
        taxonBase.setDoubtful(false);
122
        name.addStatus(NomenclaturalStatusType.ILLEGITIMATE(), null, null);
123
        assertEquals("Taxon titlecache is wrong", expectedNameTitleCache + ", nom. illeg., sec. Sp.Pl.", taxonBase.getTitleCache());
124
	}
125

    
126
	//same as for accepted taxa but with syn. sec. instead of sec.
127
    @Test
128
    public void testSynSec() {
129
        Synonym taxonBase = Synonym.NewInstance(name, sec);
130
        assertEquals("Taxon titlecache is wrong", expectedNameTitleCache + " syn. sec. Sp.Pl.", taxonBase.getTitleCache());
131
        //without sec.
132
        taxonBase.setSec(null);
133
        assertEquals("Taxon titlecache is wrong", expectedNameTitleCache + " syn. sec. ???", taxonBase.getTitleCache());
134
        //appended phrase without sec.
135
        String appendedPhrase = "aff. 'schippii'";
136
        taxonBase.setAppendedPhrase(appendedPhrase);
137
        assertEquals("Taxon titlecache is wrong", expectedNameTitleCache + " aff. 'schippii'", taxonBase.getTitleCache());
138
        //appended phrase with sec.
139
        taxonBase.setSec(sec);
140
        assertEquals("Taxon titlecache is wrong", expectedNameTitleCache + " aff. 'schippii' syn. sec. Sp.Pl.", taxonBase.getTitleCache());
141
        //use name cache
142
        taxonBase.setUseNameCache(true);
143
        assertEquals("Taxon titlecache is wrong", expectedNameCache + " aff. 'schippii' syn. sec. Sp.Pl.", taxonBase.getTitleCache());
144
        taxonBase.setDoubtful(true);
145
        assertEquals("Taxon titlecache is wrong", "?" + expectedNameCache + " aff. 'schippii' syn. sec. Sp.Pl.", taxonBase.getTitleCache());
146
        //with nom status
147
        taxonBase.setAppendedPhrase(null);
148
        taxonBase.setUseNameCache(false);
149
        taxonBase.setDoubtful(false);
150
        name.addStatus(NomenclaturalStatusType.ILLEGITIMATE(), null, null);
151
        assertEquals("Taxon titlecache is wrong", expectedNameTitleCache + ", nom. illeg., syn. sec. Sp.Pl.", taxonBase.getTitleCache());
152
    }
153

    
154
   @Test
155
    public void testGetTitleCacheWithoutName() {
156
        TaxonBase<?> taxonBase = Taxon.NewInstance(null, sec);
157
        assertEquals("Taxon titlecache is wrong", "??? sec. Sp.Pl.", taxonBase.getTitleCache());
158
    }
159

    
160
	//test missing "&" in title cache  #3822
161
	@Test
162
	public void testAndInTitleCache() {
163
		TaxonBase<?> taxonBase = Taxon.NewInstance(name, sec);
164
		Team team = Team.NewInstance();
165
		team.addTeamMember((Person)name.getCombinationAuthorship());
166
		team.addTeamMember((Person)name.getBasionymAuthorship());
167
		name.setCombinationAuthorship(team);
168
//		System.out.println(taxonBase.generateTitle());
169
		assertEquals("Abies alba (L.) Mill. \u0026 L. sec. Sp.Pl.", taxonBase.generateTitle());
170

    
171
		name = TaxonNameFactory.NewBotanicalInstance(null);
172
		NonViralNameParserImpl.NewInstance().parseFullName(name, "Cichorium glandulosum Boiss. \u0026 A. Huet", null, true);
173
		Taxon taxon = Taxon.NewInstance(name, sec);
174
		assertEquals("Cichorium glandulosum Boiss. \u0026 A. Huet sec. Sp.Pl.", taxon.getTitleCache());
175
	}
176

    
177
    @Test
178
	public void testProtectedTitleCache(){
179
	    TaxonBase<?> taxonBase = Taxon.NewInstance(name, sec);
180
        taxonBase.setTitleCache("abc", true);
181
        taxonBase.setDoubtful(true);
182
        Assert.assertEquals("abc", taxonBase.getTitleCache());
183
	}
184

    
185
    @Test
186
    public void testProtectedSecTitleCache(){
187
        TaxonBase<?> taxonBase = Taxon.NewInstance(name, sec);
188
        sec.setTitleCache("My protected sec ref", true);
189
        taxonBase.setDoubtful(true);
190
        taxonBase.setSecMicroReference("123");
191
        Assert.assertEquals("?Abies alba (L.) Mill. sec. My protected sec ref: 123", taxonBase.getTitleCache());
192
    }
193

    
194
    @Test
195
    public void testMicroReference(){
196
        TaxonBase<?> taxonBase = Taxon.NewInstance(name, sec);
197
        String secMicroRef = "p. 553";
198
        taxonBase.setSecMicroReference(secMicroRef);
199
        assertEquals("Taxon titlecache is wrong", expectedNameTitleCache + " sec. Sp.Pl.: " + secMicroRef,
200
                taxonBase.getTitleCache());
201
    }
202
}
(1-1/2)