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.name;
|
11
|
|
12
|
import static org.junit.Assert.assertEquals;
|
13
|
import static org.junit.Assert.assertNull;
|
14
|
|
15
|
import java.lang.reflect.Method;
|
16
|
|
17
|
import org.apache.log4j.Logger;
|
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.TeamOrPersonBase;
|
24
|
import eu.etaxonomy.cdm.model.common.DefaultTermInitializer;
|
25
|
import eu.etaxonomy.cdm.model.name.INonViralName;
|
26
|
import eu.etaxonomy.cdm.model.name.IZoologicalName;
|
27
|
import eu.etaxonomy.cdm.model.name.Rank;
|
28
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
29
|
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
|
30
|
|
31
|
/**
|
32
|
* @author a.mueller
|
33
|
*
|
34
|
*/
|
35
|
public class ZooNameNoMarkerCacheStrategyTest extends NameCacheStrategyTestBase {
|
36
|
@SuppressWarnings("unused")
|
37
|
private static final Logger logger = Logger.getLogger(ZooNameNoMarkerCacheStrategyTest.class);
|
38
|
|
39
|
private ZooNameDefaultCacheStrategy strategy;
|
40
|
private IZoologicalName familyName;
|
41
|
private IZoologicalName subGenusName;
|
42
|
private IZoologicalName speciesName;
|
43
|
private TaxonNameBase<?,ZooNameDefaultCacheStrategy> subSpeciesName;
|
44
|
private TeamOrPersonBase<?> author;
|
45
|
private TeamOrPersonBase<?> exAuthor;
|
46
|
private TeamOrPersonBase<?> basAuthor;
|
47
|
private TeamOrPersonBase<?> exBasAuthor;
|
48
|
|
49
|
private final String familyNameString = "Familia";
|
50
|
private final String genusNameString = "Genus";
|
51
|
private final String speciesNameString = "Abies alba";
|
52
|
private final String subSpeciesNameString = "Abies alba beta";
|
53
|
private final String subSpeciesNameStringToParse = "Abies alba subsp. beta";
|
54
|
|
55
|
private final String authorString = "L.";
|
56
|
private final String exAuthorString = "Exaut.";
|
57
|
private final String basAuthorString = "Basio, A.";
|
58
|
private final String exBasAuthorString = "ExBas. N.";
|
59
|
|
60
|
private final Integer publicationYear = 1928;
|
61
|
private final Integer originalPublicationYear = 1860;
|
62
|
|
63
|
|
64
|
|
65
|
/**
|
66
|
* @throws java.lang.Exception
|
67
|
*/
|
68
|
@BeforeClass
|
69
|
public static void setUpBeforeClass() {
|
70
|
DefaultTermInitializer vocabularyStore = new DefaultTermInitializer();
|
71
|
vocabularyStore.initialize();
|
72
|
}
|
73
|
|
74
|
/**
|
75
|
* @throws java.lang.Exception
|
76
|
*/
|
77
|
@Before
|
78
|
public void setUp() throws Exception {
|
79
|
strategy = ZooNameNoMarkerCacheStrategy.NewInstance();
|
80
|
familyName = TaxonNameFactory.PARSED_ZOOLOGICAL(familyNameString, Rank.FAMILY());
|
81
|
|
82
|
subGenusName = TaxonNameFactory.NewZoologicalInstance(Rank.SUBGENUS());
|
83
|
subGenusName.setGenusOrUninomial("Genus");
|
84
|
subGenusName.setInfraGenericEpithet("InfraGenericPart");
|
85
|
|
86
|
speciesName = TaxonNameFactory.PARSED_ZOOLOGICAL(speciesNameString);
|
87
|
subSpeciesName =(TaxonNameBase) TaxonNameFactory.PARSED_ZOOLOGICAL(subSpeciesNameStringToParse);
|
88
|
subSpeciesName.setCacheStrategy(strategy);
|
89
|
|
90
|
author = Person.NewInstance();
|
91
|
author.setNomenclaturalTitle(authorString);
|
92
|
exAuthor = Person.NewInstance();
|
93
|
exAuthor.setNomenclaturalTitle(exAuthorString);
|
94
|
basAuthor = Person.NewInstance();
|
95
|
basAuthor.setNomenclaturalTitle(basAuthorString);
|
96
|
exBasAuthor = Person.NewInstance();
|
97
|
exBasAuthor.setNomenclaturalTitle(exBasAuthorString);
|
98
|
}
|
99
|
|
100
|
|
101
|
/********* TEST *******************************************/
|
102
|
|
103
|
@Test
|
104
|
public final void testGetNameCache() {
|
105
|
assertEquals(subSpeciesNameString, subSpeciesName.getNameCache());
|
106
|
assertNull(subSpeciesNameString, strategy.getNameCache(null));
|
107
|
}
|
108
|
|
109
|
/**
|
110
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.BotanicNameDefaultCacheStrategy#getFullNameCache(eu.etaxonomy.cdm.model.common.CdmBase)}.
|
111
|
*/
|
112
|
@Test
|
113
|
public final void testGetTitleCache() {
|
114
|
assertNull(subSpeciesNameString, strategy.getTitleCache(null));
|
115
|
subSpeciesName.setCombinationAuthorship(author);
|
116
|
subSpeciesName.setExCombinationAuthorship(exAuthor);
|
117
|
subSpeciesName.setBasionymAuthorship(basAuthor);
|
118
|
subSpeciesName.setExBasionymAuthorship(exBasAuthor);
|
119
|
subSpeciesName.setPublicationYear(publicationYear);
|
120
|
subSpeciesName.setOriginalPublicationYear(originalPublicationYear);
|
121
|
|
122
|
assertEquals("Abies alba beta", strategy.getNameCache(subSpeciesName));
|
123
|
|
124
|
assertEquals("Abies alba beta" + " (" + exBasAuthorString + " ex " + basAuthorString + ", " + originalPublicationYear +")" + " " + exAuthorString + " ex " + authorString + ", " + publicationYear, strategy.getTitleCache(subSpeciesName));
|
125
|
|
126
|
//Autonym,
|
127
|
subSpeciesName.setInfraSpecificEpithet("alba");
|
128
|
subSpeciesName.setCombinationAuthorship(author);
|
129
|
subSpeciesName.setBasionymAuthorship(null);
|
130
|
subSpeciesName.setExCombinationAuthorship(null);
|
131
|
subSpeciesName.setExBasionymAuthorship(null);
|
132
|
//old
|
133
|
//assertEquals("Abies alba alba", strategy.getNameCache(subSpeciesName));
|
134
|
//assertEquals("Abies alba L. subsp. alba", strategy.getTitleCache(subSpeciesName));
|
135
|
//new we now assume that there are no autonyms in zoology (source: they do not exist in Fauna Europaea)
|
136
|
assertEquals("Abies alba alba", strategy.getNameCache(subSpeciesName));
|
137
|
assertEquals("Abies alba alba (1860) L., 1928", strategy.getTitleCache(subSpeciesName));
|
138
|
|
139
|
}
|
140
|
|
141
|
/**
|
142
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.BotanicNameDefaultCacheStrategy#getAuthorCache(eu.etaxonomy.cdm.model.common.CdmBase)}.
|
143
|
*/
|
144
|
@Test
|
145
|
public final void testGetAuthorshipCache() {
|
146
|
subSpeciesName.setCombinationAuthorship(author);
|
147
|
assertEquals(authorString, strategy.getAuthorshipCache(subSpeciesName));
|
148
|
subSpeciesName.setPublicationYear(publicationYear);
|
149
|
assertEquals(authorString + ", " + publicationYear, strategy.getAuthorshipCache(subSpeciesName));
|
150
|
|
151
|
subSpeciesName.setExCombinationAuthorship(exAuthor);
|
152
|
assertEquals( exAuthorString + " ex " + authorString + ", " + publicationYear , strategy.getAuthorshipCache(subSpeciesName));
|
153
|
|
154
|
subSpeciesName.setBasionymAuthorship(basAuthor);
|
155
|
assertEquals("(" + basAuthorString + ")" + " " + exAuthorString + " ex " + authorString + ", " + publicationYear , strategy.getAuthorshipCache(subSpeciesName));
|
156
|
subSpeciesName.setOriginalPublicationYear(originalPublicationYear);
|
157
|
assertEquals("(" + basAuthorString + ", " + originalPublicationYear + ")" + " " + exAuthorString + " ex " + authorString + ", " + publicationYear , strategy.getAuthorshipCache(subSpeciesName));
|
158
|
|
159
|
subSpeciesName.setExBasionymAuthorship(exBasAuthor);
|
160
|
assertEquals("(" + exBasAuthorString + " ex " + basAuthorString + ", " + originalPublicationYear + ")" + " " + exAuthorString + " ex " + authorString + ", " + publicationYear , strategy.getAuthorshipCache(subSpeciesName));
|
161
|
|
162
|
//cache
|
163
|
subSpeciesName.setAuthorshipCache(authorString);
|
164
|
assertEquals("AuthorshipCache must be updated", authorString, subSpeciesName.getAuthorshipCache());
|
165
|
assertEquals("TitleCache must be updated", "Abies alba beta " + authorString, subSpeciesName.getTitleCache());
|
166
|
subSpeciesName.setProtectedAuthorshipCache(false);
|
167
|
//TODO make this not needed
|
168
|
subSpeciesName.setTitleCache(null, false);
|
169
|
assertEquals("TitleCache must be updated", "Abies alba beta " + "(ExBas. N. ex Basio, A., 1860) Exaut. ex L., 1928", subSpeciesName.getTitleCache());
|
170
|
|
171
|
assertNull("Authorship cache for null must return null", strategy.getAuthorshipCache(null));
|
172
|
|
173
|
}
|
174
|
|
175
|
/**
|
176
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.BotanicNameDefaultCacheStrategy#getUninomialNameCache(eu.etaxonomy.cdm.model.name.BotanicalName)}.
|
177
|
*/
|
178
|
@Test
|
179
|
public final void testGetGenusOrUninomialNameCache() {
|
180
|
assertEquals(familyNameString, strategy.getNameCache(familyName));
|
181
|
}
|
182
|
|
183
|
/**
|
184
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.BotanicNameDefaultCacheStrategy#getInfraGenusNameCache(eu.etaxonomy.cdm.model.name.BotanicalName)}.
|
185
|
*/
|
186
|
@Test
|
187
|
public final void testGetInfraGenusTaggedNameCache() {
|
188
|
String methodName = "getInfraGenusTaggedNameCache";
|
189
|
Method method = getMethod(NonViralNameDefaultCacheStrategy.class, methodName, INonViralName.class);
|
190
|
|
191
|
this.getStringValue(method, strategy, subGenusName);
|
192
|
assertEquals("Genus (InfraGenericPart)", strategy.getNameCache(subGenusName));
|
193
|
}
|
194
|
|
195
|
/**
|
196
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.BotanicNameDefaultCacheStrategy#getSpeciesNameCache(eu.etaxonomy.cdm.model.name.BotanicalName)}.
|
197
|
*/
|
198
|
@Test
|
199
|
public final void testGetSpeciesNameCache() {
|
200
|
//test correct overriding for ZooNameDefaultCacheStrategy
|
201
|
assertEquals(speciesNameString, strategy.getNameCache(speciesName));
|
202
|
}
|
203
|
|
204
|
/**
|
205
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.BotanicNameDefaultCacheStrategy#getInfraSpeciesNameCache(eu.etaxonomy.cdm.model.name.BotanicalName)}.
|
206
|
*/
|
207
|
@Test
|
208
|
public final void testGetInfraSpeciesNameCache() {
|
209
|
assertEquals("Abies alba beta", strategy.getNameCache(subSpeciesName));
|
210
|
}
|
211
|
|
212
|
|
213
|
/**
|
214
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.BotanicNameDefaultCacheStrategy#getInfraSpeciesNameCache(eu.etaxonomy.cdm.model.name.BotanicalName)}.
|
215
|
*/
|
216
|
@Test
|
217
|
public final void testAutonyms() {
|
218
|
subSpeciesName.setInfraSpecificEpithet("alba");
|
219
|
subSpeciesName.setCombinationAuthorship(author);
|
220
|
//new: we now assume that there are no autonyms in zoology (source: they do not exist in Fauna Europaea)
|
221
|
assertEquals("Abies alba alba", strategy.getNameCache(subSpeciesName));
|
222
|
assertEquals("Abies alba alba L.", strategy.getTitleCache(subSpeciesName));
|
223
|
}
|
224
|
|
225
|
|
226
|
}
|