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.common.DefaultTermInitializer;
|
26
|
import eu.etaxonomy.cdm.model.name.BotanicalName;
|
27
|
import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
|
28
|
import eu.etaxonomy.cdm.model.name.Rank;
|
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.Taxon;
|
33
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
34
|
import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl;
|
35
|
|
36
|
/**
|
37
|
* @author a.mueller
|
38
|
* @created 21.09.2009
|
39
|
*/
|
40
|
public class TaxonBaseDefaultCacheStrategyTest {
|
41
|
@SuppressWarnings("unused")
|
42
|
private static final Logger logger = Logger.getLogger(TaxonBaseDefaultCacheStrategyTest.class);
|
43
|
|
44
|
private final String expectedNameTitleCache = "Abies alba (L.) Mill.";
|
45
|
private final String expectedNameCache = "Abies alba";
|
46
|
private BotanicalName name;
|
47
|
private Reference sec;
|
48
|
|
49
|
/**
|
50
|
* @throws java.lang.Exception
|
51
|
*/
|
52
|
@BeforeClass
|
53
|
public static void setUpBeforeClass() throws Exception {
|
54
|
DefaultTermInitializer vocabularyStore = new DefaultTermInitializer();
|
55
|
vocabularyStore.initialize();
|
56
|
}
|
57
|
|
58
|
/**
|
59
|
* @throws java.lang.Exception
|
60
|
*/
|
61
|
@AfterClass
|
62
|
public static void tearDownAfterClass() throws Exception {
|
63
|
}
|
64
|
|
65
|
/**
|
66
|
* @throws java.lang.Exception
|
67
|
*/
|
68
|
@Before
|
69
|
public void setUp() throws Exception {
|
70
|
name = BotanicalName.NewInstance(Rank.SPECIES());
|
71
|
name.setGenusOrUninomial("Abies");
|
72
|
name.setSpecificEpithet("alba");
|
73
|
Person combinationAuthor = Person.NewInstance();
|
74
|
combinationAuthor.setNomenclaturalTitle("Mill.");
|
75
|
Person basionymAuthor = Person.NewInstance();
|
76
|
basionymAuthor.setNomenclaturalTitle("L.");
|
77
|
|
78
|
name.setCombinationAuthorship(combinationAuthor);
|
79
|
name.setBasionymAuthorship(basionymAuthor);
|
80
|
assertEquals("Namecache should be Abies alba", expectedNameCache, name.getNameCache());
|
81
|
assertEquals("Titlecache should be Abies alba (Mill.) L.", expectedNameTitleCache, name.getTitleCache());
|
82
|
sec = ReferenceFactory.newBook();
|
83
|
sec.setTitle("Sp.Pl.");
|
84
|
}
|
85
|
|
86
|
/**
|
87
|
* @throws java.lang.Exception
|
88
|
*/
|
89
|
@After
|
90
|
public void tearDown() throws Exception {
|
91
|
}
|
92
|
|
93
|
//******************************* TESTS ********************************************************
|
94
|
|
95
|
/**
|
96
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.taxon.TaxonBaseDefaultCacheStrategy#getTitleCache(eu.etaxonomy.cdm.model.taxon.TaxonBase)}.
|
97
|
*/
|
98
|
@Test
|
99
|
public void testGetTitleCache() {
|
100
|
TaxonBase<?> taxonBase = Taxon.NewInstance(name, sec);
|
101
|
assertEquals("Taxon titlecache is wrong", expectedNameTitleCache + " sec. Sp.Pl.", taxonBase.getTitleCache());
|
102
|
//without sec.
|
103
|
taxonBase.setSec(null);
|
104
|
assertEquals("Taxon titlecache is wrong", expectedNameTitleCache + " sec. ???", taxonBase.getTitleCache());
|
105
|
//appended phrase without sec.
|
106
|
String appendedPhrase = "aff. 'schippii'";
|
107
|
taxonBase.setAppendedPhrase(appendedPhrase);
|
108
|
assertEquals("Taxon titlecache is wrong", expectedNameTitleCache + " aff. 'schippii'", taxonBase.getTitleCache());
|
109
|
//appended phrase with sec.
|
110
|
taxonBase.setSec(sec);
|
111
|
assertEquals("Taxon titlecache is wrong", expectedNameTitleCache + " aff. 'schippii' sec. Sp.Pl.", taxonBase.getTitleCache());
|
112
|
//use name cache
|
113
|
taxonBase.setUseNameCache(true);
|
114
|
assertEquals("Taxon titlecache is wrong", expectedNameCache + " aff. 'schippii' sec. Sp.Pl.", taxonBase.getTitleCache());
|
115
|
taxonBase.setDoubtful(true);
|
116
|
assertEquals("Taxon titlecache is wrong", "?" + expectedNameCache + " aff. 'schippii' sec. Sp.Pl.", taxonBase.getTitleCache());
|
117
|
//with nom status
|
118
|
taxonBase.setAppendedPhrase(null);
|
119
|
taxonBase.setUseNameCache(false);
|
120
|
taxonBase.setDoubtful(false);
|
121
|
name.addStatus(NomenclaturalStatusType.ILLEGITIMATE(), null, null);
|
122
|
assertEquals("Taxon titlecache is wrong", expectedNameTitleCache + ", nom. illeg., sec. Sp.Pl.", taxonBase.getTitleCache());
|
123
|
}
|
124
|
|
125
|
//test missing "&" in title cache #3822
|
126
|
@Test
|
127
|
public void testAndInTitleCache() {
|
128
|
TaxonBase<?> taxonBase = Taxon.NewInstance(name, sec);
|
129
|
Team team = Team.NewInstance();
|
130
|
team.addTeamMember((Person)name.getCombinationAuthorship());
|
131
|
team.addTeamMember((Person)name.getBasionymAuthorship());
|
132
|
name.setCombinationAuthorship(team);
|
133
|
System.out.println(taxonBase.generateTitle());
|
134
|
assertEquals("Abies alba (L.) Mill. \u0026 L. sec. Sp.Pl.", taxonBase.generateTitle());
|
135
|
|
136
|
name = BotanicalName.NewInstance(null);
|
137
|
NonViralNameParserImpl.NewInstance().parseFullName(name, "Cichorium glandulosum Boiss. \u0026 A. Huet", null, true);
|
138
|
Taxon taxon = Taxon.NewInstance(name, sec);
|
139
|
assertEquals("Cichorium glandulosum Boiss. \u0026 A. Huet sec. Sp.Pl.", taxon.getTitleCache());
|
140
|
}
|
141
|
|
142
|
@Test
|
143
|
public void testProtectedTitleCache(){
|
144
|
TaxonBase<?> taxonBase = Taxon.NewInstance(name, sec);
|
145
|
taxonBase.setTitleCache("abc", true);
|
146
|
taxonBase.setDoubtful(true);
|
147
|
Assert.assertEquals("abc", taxonBase.getTitleCache());
|
148
|
}
|
149
|
|
150
|
@Test
|
151
|
public void testMicroReference(){
|
152
|
TaxonBase<?> taxonBase = Taxon.NewInstance(name, sec);
|
153
|
String secMicroRef = "p. 553";
|
154
|
taxonBase.setSecMicroReference(secMicroRef);
|
155
|
assertEquals("Taxon titlecache is wrong", expectedNameTitleCache + " sec. Sp.Pl.: " + secMicroRef,
|
156
|
taxonBase.getTitleCache());
|
157
|
|
158
|
|
159
|
}
|
160
|
}
|