1 |
ce7c7aa3
|
Andreas Müller
|
/**
|
2 |
|
|
* Copyright (C) 2007 EDIT
|
3 |
90046bc4
|
Andreas Müller
|
* European Distributed Institute of Taxonomy
|
4 |
ce7c7aa3
|
Andreas Müller
|
* http://www.e-taxonomy.eu
|
5 |
90046bc4
|
Andreas Müller
|
*
|
6 |
ce7c7aa3
|
Andreas Müller
|
* 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.assertNotNull;
|
14 |
|
|
import static org.junit.Assert.assertNull;
|
15 |
|
|
|
16 |
|
|
import java.lang.reflect.Method;
|
17 |
|
|
import java.util.GregorianCalendar;
|
18 |
|
|
|
19 |
|
|
import org.apache.log4j.Logger;
|
20 |
|
|
import org.junit.Before;
|
21 |
|
|
import org.junit.BeforeClass;
|
22 |
|
|
import org.junit.Test;
|
23 |
|
|
|
24 |
|
|
import eu.etaxonomy.cdm.model.agent.Person;
|
25 |
|
|
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
|
26 |
|
|
import eu.etaxonomy.cdm.model.common.DefaultTermInitializer;
|
27 |
|
|
import eu.etaxonomy.cdm.model.common.TimePeriod;
|
28 |
|
|
import eu.etaxonomy.cdm.model.name.BotanicalName;
|
29 |
|
|
import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
|
30 |
|
|
import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
|
31 |
|
|
import eu.etaxonomy.cdm.model.name.NonViralName;
|
32 |
|
|
import eu.etaxonomy.cdm.model.name.Rank;
|
33 |
|
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
34 |
|
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
35 |
|
|
|
36 |
|
|
/**
|
37 |
|
|
* @author a.mueller
|
38 |
|
|
*
|
39 |
|
|
*/
|
40 |
|
|
public class BotanicNameCacheStrategyTest extends NameCacheStrategyTestBase{
|
41 |
|
|
private static final Logger logger = Logger.getLogger(BotanicNameCacheStrategyTest.class);
|
42 |
90046bc4
|
Andreas Müller
|
|
43 |
ce7c7aa3
|
Andreas Müller
|
private static final String familyNameString = "Familia";
|
44 |
|
|
private static final String genusNameString = "Genus";
|
45 |
|
|
private static final String speciesNameString = "Abies alba";
|
46 |
|
|
private static final String subSpeciesNameString = "Abies alba subsp. beta";
|
47 |
|
|
private static final String appendedPhraseString = "app phrase";
|
48 |
|
|
|
49 |
|
|
private static final String authorString = "L.";
|
50 |
|
|
private static final String exAuthorString = "Exaut.";
|
51 |
|
|
private static final String basAuthorString = "Basio, A.";
|
52 |
|
|
private static final String exBasAuthorString = "ExBas. N.";
|
53 |
|
|
|
54 |
|
|
private BotanicNameDefaultCacheStrategy strategy;
|
55 |
|
|
private BotanicalName familyName;
|
56 |
|
|
private BotanicalName genusName;
|
57 |
|
|
private BotanicalName subGenusName;
|
58 |
|
|
private BotanicalName speciesName;
|
59 |
|
|
private BotanicalName subSpeciesName;
|
60 |
|
|
private TeamOrPersonBase<?> author;
|
61 |
|
|
private TeamOrPersonBase<?> exAuthor;
|
62 |
|
|
private TeamOrPersonBase<?> basAuthor;
|
63 |
|
|
private TeamOrPersonBase<?> exBasAuthor;
|
64 |
90046bc4
|
Andreas Müller
|
private Reference citationRef;
|
65 |
ce7c7aa3
|
Andreas Müller
|
ReferenceFactory refFactory;
|
66 |
90046bc4
|
Andreas Müller
|
|
67 |
ce7c7aa3
|
Andreas Müller
|
/**
|
68 |
|
|
* @throws java.lang.Exception
|
69 |
|
|
*/
|
70 |
|
|
@BeforeClass
|
71 |
|
|
public static void setUpBeforeClass() {
|
72 |
|
|
DefaultTermInitializer vocabularyStore = new DefaultTermInitializer();
|
73 |
|
|
vocabularyStore.initialize();
|
74 |
|
|
}
|
75 |
|
|
|
76 |
|
|
/**
|
77 |
|
|
* @throws java.lang.Exception
|
78 |
|
|
*/
|
79 |
|
|
@Before
|
80 |
|
|
public void setUp() throws Exception {
|
81 |
|
|
strategy = BotanicNameDefaultCacheStrategy.NewInstance();
|
82 |
|
|
familyName = BotanicalName.PARSED_NAME(familyNameString, Rank.FAMILY());
|
83 |
|
|
genusName = BotanicalName.PARSED_NAME(genusNameString, Rank.GENUS());
|
84 |
90046bc4
|
Andreas Müller
|
|
85 |
ce7c7aa3
|
Andreas Müller
|
subGenusName = BotanicalName.NewInstance(Rank.SUBGENUS());
|
86 |
|
|
subGenusName.setGenusOrUninomial("Genus");
|
87 |
|
|
subGenusName.setInfraGenericEpithet("InfraGenericPart");
|
88 |
90046bc4
|
Andreas Müller
|
|
89 |
ce7c7aa3
|
Andreas Müller
|
speciesName = BotanicalName.PARSED_NAME(speciesNameString);
|
90 |
|
|
subSpeciesName = BotanicalName.PARSED_NAME(subSpeciesNameString);
|
91 |
|
|
|
92 |
|
|
author = Person.NewInstance();
|
93 |
|
|
author.setNomenclaturalTitle(authorString);
|
94 |
|
|
exAuthor = Person.NewInstance();
|
95 |
|
|
exAuthor.setNomenclaturalTitle(exAuthorString);
|
96 |
|
|
basAuthor = Person.NewInstance();
|
97 |
|
|
basAuthor.setNomenclaturalTitle(basAuthorString);
|
98 |
|
|
exBasAuthor = Person.NewInstance();
|
99 |
|
|
exBasAuthor.setNomenclaturalTitle(exBasAuthorString);
|
100 |
90046bc4
|
Andreas Müller
|
|
101 |
ce7c7aa3
|
Andreas Müller
|
citationRef = refFactory.newBook();
|
102 |
|
|
// Gard. Dict. ed. 8, no. 1. 1768.
|
103 |
|
|
citationRef.setTitle("Gard. Dict.");
|
104 |
|
|
//citationRef.setPlacePublished("");
|
105 |
|
|
citationRef.setVolume("1");
|
106 |
|
|
citationRef.setEdition("ed. 8");
|
107 |
|
|
GregorianCalendar testDate = new GregorianCalendar();
|
108 |
|
|
testDate.set(1968, 3, 2);
|
109 |
90046bc4
|
Andreas Müller
|
|
110 |
ce7c7aa3
|
Andreas Müller
|
TimePeriod period = TimePeriod.NewInstance(testDate);
|
111 |
90046bc4
|
Andreas Müller
|
|
112 |
ce7c7aa3
|
Andreas Müller
|
citationRef.setDatePublished(period);
|
113 |
90046bc4
|
Andreas Müller
|
|
114 |
ce7c7aa3
|
Andreas Müller
|
//speciesName.setNomenclaturalMicroReference("89");
|
115 |
|
|
NomenclaturalStatus nomStatus = NomenclaturalStatus.NewInstance(NomenclaturalStatusType.ILLEGITIMATE());
|
116 |
|
|
speciesName.addStatus(nomStatus);
|
117 |
90046bc4
|
Andreas Müller
|
|
118 |
ce7c7aa3
|
Andreas Müller
|
speciesName.setNomenclaturalReference(citationRef);
|
119 |
|
|
speciesName.setAppendedPhrase("app phrase");
|
120 |
90046bc4
|
Andreas Müller
|
|
121 |
ce7c7aa3
|
Andreas Müller
|
// subSpeciesName.setNomenclaturalReference(citationRef);
|
122 |
|
|
// subSpeciesName.setAppendedPhrase("app phrase");
|
123 |
|
|
}
|
124 |
|
|
|
125 |
90046bc4
|
Andreas Müller
|
|
126 |
ce7c7aa3
|
Andreas Müller
|
|
127 |
|
|
/********* TEST *******************************************/
|
128 |
|
|
|
129 |
|
|
/**
|
130 |
|
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.BotanicNameDefaultCacheStrategy#NewInstance()}.
|
131 |
|
|
*/
|
132 |
|
|
@Test
|
133 |
|
|
public final void testNewInstance() {
|
134 |
|
|
BotanicNameDefaultCacheStrategy<?> cacheStrategy = BotanicNameDefaultCacheStrategy.NewInstance();
|
135 |
|
|
assertNotNull(cacheStrategy);
|
136 |
|
|
}
|
137 |
|
|
|
138 |
|
|
/**
|
139 |
|
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.BotanicNameDefaultCacheStrategy#getNameCache(eu.etaxonomy.cdm.model.common.CdmBase)}.
|
140 |
|
|
*/
|
141 |
|
|
@Test
|
142 |
|
|
public final void testGetNameCache() {
|
143 |
|
|
assertEquals(subSpeciesNameString, subSpeciesName.getNameCache());
|
144 |
|
|
assertNull(subSpeciesNameString, strategy.getNameCache(null));
|
145 |
|
|
}
|
146 |
|
|
|
147 |
|
|
/**
|
148 |
|
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.BotanicNameDefaultCacheStrategy#getTitleCache(eu.etaxonomy.cdm.model.common.CdmBase)}.
|
149 |
|
|
*/
|
150 |
|
|
@Test
|
151 |
|
|
public final void testGetTitleCache() {
|
152 |
|
|
assertNull(subSpeciesNameString, strategy.getTitleCache(null));
|
153 |
|
|
subSpeciesName.setCombinationAuthorship(author);
|
154 |
|
|
subSpeciesName.setExCombinationAuthorship(exAuthor);
|
155 |
|
|
subSpeciesName.setBasionymAuthorship(basAuthor);
|
156 |
|
|
subSpeciesName.setExBasionymAuthorship(exBasAuthor);
|
157 |
|
|
assertEquals(subSpeciesNameString, strategy.getNameCache(subSpeciesName));
|
158 |
|
|
assertEquals(subSpeciesNameString + " (" + exBasAuthorString + " ex " + basAuthorString + ")" + " " + exAuthorString + " ex " + authorString , strategy.getTitleCache(subSpeciesName));
|
159 |
90046bc4
|
Andreas Müller
|
|
160 |
ce7c7aa3
|
Andreas Müller
|
subSpeciesName.setExCombinationAuthorship(null);
|
161 |
|
|
assertEquals(subSpeciesNameString + " (" + exBasAuthorString + " ex " + basAuthorString + ")" + " " + authorString , strategy.getTitleCache(subSpeciesName));
|
162 |
90046bc4
|
Andreas Müller
|
|
163 |
ce7c7aa3
|
Andreas Müller
|
subSpeciesName.setExBasionymAuthorship(null);
|
164 |
|
|
assertEquals(subSpeciesNameString + " (" + basAuthorString + ")" + " " + authorString , strategy.getTitleCache(subSpeciesName));
|
165 |
90046bc4
|
Andreas Müller
|
|
166 |
|
|
|
167 |
ce7c7aa3
|
Andreas Müller
|
//Autonym
|
168 |
|
|
subSpeciesName.setInfraSpecificEpithet("alba");
|
169 |
|
|
subSpeciesName.setCombinationAuthorship(author);
|
170 |
|
|
subSpeciesName.setBasionymAuthorship(null);
|
171 |
|
|
subSpeciesName.setExCombinationAuthorship(null);
|
172 |
|
|
subSpeciesName.setExBasionymAuthorship(null);
|
173 |
|
|
//changed 2009-09-04
|
174 |
|
|
assertEquals("Abies alba subsp. alba", strategy.getNameCache(subSpeciesName));
|
175 |
|
|
assertEquals("Abies alba L. subsp. alba", strategy.getTitleCache(subSpeciesName));
|
176 |
90046bc4
|
Andreas Müller
|
|
177 |
|
|
|
178 |
|
|
|
179 |
ce7c7aa3
|
Andreas Müller
|
}
|
180 |
|
|
|
181 |
|
|
/**
|
182 |
|
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.BotanicNameDefaultCacheStrategy#getFullTitleCache(eu.etaxonomy.cdm.model.common.CdmBase)}.
|
183 |
|
|
*/
|
184 |
|
|
@Test
|
185 |
|
|
public final void testGetFullTitleCache() {
|
186 |
|
|
assertNull("Full title cache of null object should return null", strategy.getFullTitleCache(null));
|
187 |
|
|
//NOTE: Unclear if the date part should contain the full date or only the year. Undefined Behaviour.
|
188 |
|
|
assertEquals("Abies alba app phrase, Gard. Dict., ed. 8, 1. 2.4.1968, nom. illeg.", strategy.getFullTitleCache(speciesName));
|
189 |
90046bc4
|
Andreas Müller
|
|
190 |
ce7c7aa3
|
Andreas Müller
|
// assertNull(subSpeciesNameString, strategy.getFullTitleCache(null));
|
191 |
|
|
// assertEquals("Abies alba app phrase L. Gard. Dict. ed. 8, 1. 1768, nom. illeg.", strategy.getFullTitleCache(speciesName));
|
192 |
|
|
}
|
193 |
|
|
|
194 |
|
|
/**
|
195 |
|
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.BotanicNameDefaultCacheStrategy#getAuthorCache(eu.etaxonomy.cdm.model.common.CdmBase)}.
|
196 |
|
|
*/
|
197 |
|
|
@Test
|
198 |
|
|
public final void testGetAuthorshipCache() {
|
199 |
|
|
subSpeciesName.setCombinationAuthorship(author);
|
200 |
|
|
assertEquals(authorString, strategy.getAuthorshipCache(subSpeciesName));
|
201 |
|
|
|
202 |
|
|
subSpeciesName.setExCombinationAuthorship(exAuthor);
|
203 |
|
|
assertEquals(exAuthorString + " ex " + authorString , strategy.getAuthorshipCache(subSpeciesName));
|
204 |
90046bc4
|
Andreas Müller
|
|
205 |
ce7c7aa3
|
Andreas Müller
|
subSpeciesName.setBasionymAuthorship(basAuthor);
|
206 |
|
|
assertEquals("(" + basAuthorString + ")" + " " + exAuthorString + " ex " + authorString , strategy.getAuthorshipCache(subSpeciesName));
|
207 |
|
|
|
208 |
|
|
subSpeciesName.setExBasionymAuthorship(exBasAuthor);
|
209 |
|
|
assertEquals("(" + exBasAuthorString + " ex " + basAuthorString + ")" + " " + exAuthorString + " ex " + authorString , strategy.getAuthorshipCache(subSpeciesName));
|
210 |
90046bc4
|
Andreas Müller
|
|
211 |
ce7c7aa3
|
Andreas Müller
|
assertNull(subSpeciesNameString, strategy.getAuthorshipCache(null));
|
212 |
|
|
}
|
213 |
90046bc4
|
Andreas Müller
|
|
214 |
ce7c7aa3
|
Andreas Müller
|
/**
|
215 |
|
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.BotanicNameDefaultCacheStrategy#getUninomialNameCache(eu.etaxonomy.cdm.model.name.BotanicalName)}.
|
216 |
|
|
*/
|
217 |
|
|
@Test
|
218 |
|
|
public final void testGetGenusOrUninomialNameCache() {
|
219 |
|
|
assertEquals(familyNameString, strategy.getNameCache(familyName));
|
220 |
|
|
}
|
221 |
|
|
|
222 |
|
|
/**
|
223 |
|
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.BotanicNameDefaultCacheStrategy#getInfraGenusNameCache(eu.etaxonomy.cdm.model.name.BotanicalName)}.
|
224 |
|
|
*/
|
225 |
|
|
@Test
|
226 |
|
|
public final void testGetInfraGenusTaggedNameCache() {
|
227 |
|
|
String methodName = "getInfraGenusTaggedNameCache";
|
228 |
|
|
Method method = getMethod(NonViralNameDefaultCacheStrategy.class, methodName, NonViralName.class);
|
229 |
|
|
this.getStringValue(method, strategy, subGenusName);
|
230 |
|
|
assertEquals("Genus subg. InfraGenericPart", strategy.getNameCache(subGenusName));
|
231 |
|
|
}
|
232 |
|
|
|
233 |
|
|
/**
|
234 |
|
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.BotanicNameDefaultCacheStrategy#getSpeciesNameCache(eu.etaxonomy.cdm.model.name.BotanicalName)}.
|
235 |
|
|
*/
|
236 |
|
|
@Test
|
237 |
|
|
public final void testGetSpeciesNameCache() {
|
238 |
|
|
String nameString = speciesNameString + " " + appendedPhraseString;
|
239 |
|
|
assertEquals(nameString, strategy.getNameCache(speciesName));
|
240 |
|
|
}
|
241 |
|
|
|
242 |
|
|
/**
|
243 |
|
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.BotanicNameDefaultCacheStrategy#getInfraSpeciesNameCache(eu.etaxonomy.cdm.model.name.BotanicalName)}.
|
244 |
|
|
*/
|
245 |
|
|
@Test
|
246 |
|
|
public final void testGetInfraSpeciesNameCache() {
|
247 |
|
|
assertEquals(subSpeciesNameString, strategy.getNameCache(subSpeciesName));
|
248 |
|
|
}
|
249 |
90046bc4
|
Andreas Müller
|
|
250 |
ce7c7aa3
|
Andreas Müller
|
|
251 |
|
|
/**
|
252 |
|
|
* Test method for {@link eu.etaxonomy.cdm.strategy.cache.name.BotanicNameDefaultCacheStrategy#getInfraSpeciesNameCache(eu.etaxonomy.cdm.model.name.BotanicalName)}.
|
253 |
|
|
*/
|
254 |
|
|
@Test
|
255 |
|
|
public final void testAutonyms() {
|
256 |
|
|
subSpeciesName.setInfraSpecificEpithet("alba");
|
257 |
|
|
subSpeciesName.setCombinationAuthorship(author);
|
258 |
|
|
//changed 2009-09-04
|
259 |
|
|
assertEquals("Abies alba subsp. alba", strategy.getNameCache(subSpeciesName));
|
260 |
|
|
assertEquals("Abies alba L. subsp. alba", strategy.getTitleCache(subSpeciesName));
|
261 |
|
|
}
|
262 |
90046bc4
|
Andreas Müller
|
|
263 |
|
|
@Override
|
264 |
|
|
protected Method getMethod(Class clazz, String methodName, Class paramClazzes){
|
265 |
ce7c7aa3
|
Andreas Müller
|
Method method;
|
266 |
|
|
try {
|
267 |
|
|
method = clazz.getDeclaredMethod(methodName, paramClazzes);
|
268 |
|
|
} catch (SecurityException e) {
|
269 |
|
|
logger.error("SecurityException " + e.getMessage());
|
270 |
|
|
return null;
|
271 |
|
|
} catch (NoSuchMethodException e) {
|
272 |
|
|
logger.error("NoSuchMethodException " + e.getMessage());
|
273 |
|
|
return null;
|
274 |
|
|
}
|
275 |
|
|
return method;
|
276 |
|
|
}
|
277 |
|
|
|
278 |
|
|
|
279 |
|
|
|
280 |
|
|
}
|