merge-update from trunk
[cdmlib.git] / cdmlib-model / src / test / java / eu / etaxonomy / cdm / strategy / parser / NonViralNameParserImplTest.java
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.parser;
11
12 import static org.junit.Assert.assertEquals;
13 import static org.junit.Assert.assertFalse;
14 import static org.junit.Assert.assertNotNull;
15 import static org.junit.Assert.assertNull;
16 import static org.junit.Assert.assertTrue;
17
18 import java.lang.reflect.InvocationTargetException;
19 import java.lang.reflect.Method;
20 import java.util.List;
21 import java.util.regex.Matcher;
22 import java.util.regex.Pattern;
23
24 import org.apache.log4j.Logger;
25 import org.junit.Assert;
26 import org.junit.Before;
27 import org.junit.BeforeClass;
28 import org.junit.Test;
29
30 import eu.etaxonomy.cdm.model.agent.INomenclaturalAuthor;
31 import eu.etaxonomy.cdm.model.agent.Person;
32 import eu.etaxonomy.cdm.model.agent.Team;
33 import eu.etaxonomy.cdm.model.common.DefaultTermInitializer;
34 import eu.etaxonomy.cdm.model.name.BotanicalName;
35 import eu.etaxonomy.cdm.model.name.HybridRelationship;
36 import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
37 import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
38 import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
39 import eu.etaxonomy.cdm.model.name.NonViralName;
40 import eu.etaxonomy.cdm.model.name.Rank;
41 import eu.etaxonomy.cdm.model.name.ZoologicalName;
42 import eu.etaxonomy.cdm.model.reference.IArticle;
43 import eu.etaxonomy.cdm.model.reference.IBook;
44 import eu.etaxonomy.cdm.model.reference.IBookSection;
45 import eu.etaxonomy.cdm.model.reference.IJournal;
46 import eu.etaxonomy.cdm.model.reference.INomenclaturalReference;
47 import eu.etaxonomy.cdm.model.reference.IVolumeReference;
48 import eu.etaxonomy.cdm.model.reference.Reference;
49 import eu.etaxonomy.cdm.model.reference.ReferenceType;
50 import eu.etaxonomy.cdm.strategy.exceptions.StringNotParsableException;
51 /**
52 * @author a.mueller
53 *
54 */
55 public class NonViralNameParserImplTest {
56 private static final NomenclaturalCode ICBN = NomenclaturalCode.ICNAFP;
57 private static final NomenclaturalCode ICZN = NomenclaturalCode.ICZN;
58
59 private static final Logger logger = Logger.getLogger(NonViralNameParserImplTest.class);
60
61 final private String strNameFamily = "Asteraceae";
62 final private String strNameGenus = "Abies Mueller";
63 final private String strNameGenusUnicode = "Abies M\u00FCller";
64 final private String strNameAbies1 = "Abies alba";
65 final private String strNameAbiesSub1 = "Abies alba subsp. beta";
66 final private String strNameAbiesAuthor1 = "Abies alba Mueller";
67 final private String strNameAbiesAuthor1Unicode = "Abies alba M\u00FCller";
68 final private String strNameAbiesBasionymAuthor1 = "Abies alba (Ciardelli) D'Mueller";
69 final private String strNameAbiesBasionymAuthor1Unicode = "Abies alba (Ciardelli) D'M\u00FCller";
70 final private String strNameAbiesBasionymExAuthor1 ="Abies alba (Ciardelli ex Doering) D'Mueller ex. de Greuther";
71 final private String strNameAbiesBasionymExAuthor1Unicode ="Abies alba (Ciardelli ex D\u00F6ring) D'M\u00FCller ex. de Greuther";
72 final private String strNameTeam1 = "Abies alba Mueller & L.";
73 final private String strNameZoo1 = "Abies alba Mueller & L., 1822";
74 final private String strNameZoo2 = "Abies alba (Mueller, 1822) Ciardelli, 2002";
75
76 final private String strNameEmpty = "";
77 final private String strNameNull = null;
78
79 private NonViralNameParserImpl parser ;
80 private NomenclaturalCode botanicCode;
81
82 /**
83 * @throws java.lang.Exception
84 */
85 @BeforeClass
86 public static void setUpBeforeClass() throws Exception {
87 DefaultTermInitializer termInitializer = new DefaultTermInitializer();
88 termInitializer.initialize();
89 }
90
91
92 /**
93 * @throws java.lang.Exception
94 */
95 @Before
96 public void setUp() throws Exception {
97 parser = NonViralNameParserImpl.NewInstance();
98 botanicCode = ICBN;
99 }
100
101
102 /*************** TEST *********************************************/
103
104 /**
105 * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#NEW_INSTANCE()}.
106 */
107 @Test
108 public final void testNewInstance() {
109 assertNotNull(parser);
110 }
111
112 /**
113 * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#TaxonNameParserBotanicalNameImpl()}.
114 */
115 @Test
116 public final void testTaxonNameParserBotanicalNameImpl() {
117 logger.warn("Not yet implemented"); // TODO
118 }
119
120 @Test
121 public final void testTeamSeperation(){
122 Rank speciesRank = Rank.SPECIES();
123 NonViralName<?> name;
124
125 // String strNameWith1AUthorAndCommaSepEditon = "Abies alba Mill., Sp. Pl., ed. 3: 455. 1987";
126 // name = parser.parseReferencedName(strNameWith1AUthorAndCommaSepEditon, botanicCode, speciesRank);
127 // Assert.assertFalse("No problems should exist", name.hasProblem());
128 // Assert.assertEquals("Name should not include reference part", "Abies alba Mill.", name.getTitleCache());
129 // Assert.assertEquals("Mill., Sp. Pl., ed. 3. 1987", name.getNomenclaturalReference().getTitleCache());
130 //
131 //
132 // String strNameWith2Authors = "Abies alba L. & Mill., Sp. Pl., ed. 3: 455. 1987";
133 // name = parser.parseReferencedName(strNameWith2Authors, botanicCode, speciesRank);
134 // Assert.assertFalse("No problems should exist", name.hasProblem());
135 // Assert.assertEquals("Name should not include reference part", "Abies alba L. & Mill.", name.getTitleCache());
136 // Assert.assertEquals("Name should have authorteam with 2 authors", 2, ((Team)name.getCombinationAuthorTeam()).getTeamMembers().size());
137 // Assert.assertEquals("L. & Mill., Sp. Pl., ed. 3. 1987", name.getNomenclaturalReference().getTitleCache());
138
139 String strNameWith3Authors = "Abies alba Mess., L. & Mill., Sp. Pl., ed. 3: 455. 1987";
140 name = parser.parseReferencedName(strNameWith3Authors, botanicCode, speciesRank);
141 Assert.assertFalse("No problems should exist", name.hasProblem());
142 Assert.assertEquals("Name should not include reference part", "Abies alba Mess., L. & Mill.", name.getTitleCache());
143 Assert.assertEquals("Name should have authorship with 2 authors", 3, ((Team)name.getCombinationAuthorTeam()).getTeamMembers().size());
144 Assert.assertEquals("Mess., L. & Mill., Sp. Pl., ed. 3. 1987", name.getNomenclaturalReference().getTitleCache());
145
146 }
147
148 /**
149 * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#parseSimpleName(java.lang.String, eu.etaxonomy.cdm.model.name.Rank)}.
150 */
151 @Test
152 public final void testParseSimpleName() {
153
154 //Uninomials
155 ZoologicalName milichiidae = (ZoologicalName)parser.parseSimpleName("Milichiidae", NomenclaturalCode.ICZN, null);
156 assertEquals("Family rank expected", Rank.FAMILY(), milichiidae.getRank());
157 BotanicalName crepidinae = (BotanicalName)parser.parseSimpleName("Crepidinae", ICBN, null);
158 assertEquals("Family rank expected", Rank.SUBTRIBE(), crepidinae.getRank());
159 BotanicalName abies = (BotanicalName)parser.parseSimpleName("Abies", ICBN, null);
160 assertEquals("Family rank expected", Rank.GENUS(), abies.getRank());
161
162 abies.addParsingProblem(ParserProblem.CheckRank);
163 parser.parseSimpleName(abies, "Abies", abies.getRank(), true);
164 assertTrue(abies.getParsingProblems().contains(ParserProblem.CheckRank));
165
166 BotanicalName rosa = (BotanicalName)parser.parseSimpleName("Rosaceae", ICBN, null);
167 assertTrue("Rosaceae have rank family", rosa.getRank().equals(Rank.FAMILY()));
168 assertTrue("Rosaceae must have a rank warning", rosa.hasProblem(ParserProblem.CheckRank));
169 parser.parseSimpleName(rosa, "Rosaceaex", abies.getRank(), true);
170 assertEquals("Rosaceaex have rank genus", Rank.GENUS(), rosa.getRank());
171 assertTrue("Rosaceaex must have a rank warning", rosa.hasProblem(ParserProblem.CheckRank));
172
173 //repeat but remove warning after first parse
174 rosa = (BotanicalName)parser.parseSimpleName("Rosaceae", ICBN, null);
175 assertTrue("Rosaceae have rank family", rosa.getRank().equals(Rank.FAMILY()));
176 assertTrue("Rosaceae must have a rank warning", rosa.hasProblem(ParserProblem.CheckRank));
177 rosa.removeParsingProblem(ParserProblem.CheckRank);
178 parser.parseSimpleName(rosa, "Rosaceaex", rosa.getRank(), true);
179 assertEquals("Rosaceaex have rank family", Rank.FAMILY(), rosa.getRank());
180 assertFalse("Rosaceaex must have no rank warning", rosa.hasProblem(ParserProblem.CheckRank));
181
182
183 }
184
185 /**
186 * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#parseSubGenericFullName(java.lang.String)}.
187 */
188 @Test
189 public final void testParseSubGenericFullName() {
190 logger.warn("Not yet implemented"); // TODO
191 }
192
193 /**
194 * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#parseSubGenericSimpleName(java.lang.String)}.
195 */
196 @Test
197 public final void testParseSubGenericSimpleName() {
198 logger.warn("Not yet implemented"); // TODO
199 }
200
201 /**
202 * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#parseFullName(java.lang.String, eu.etaxonomy.cdm.model.name.Rank)}.
203 */
204 @Test
205 public final void testParseFullNameUnicode() {
206
207 NonViralName<?> nameAuthor = parser.parseFullName(strNameAbiesAuthor1Unicode, null, Rank.SPECIES());
208 assertEquals("Abies", nameAuthor.getGenusOrUninomial());
209 assertEquals("alba", nameAuthor.getSpecificEpithet());
210 assertEquals("M\u00FCller", nameAuthor.getCombinationAuthorTeam().getNomenclaturalTitle());
211
212 NonViralName<?> nameBasionymAuthor = parser.parseFullName(strNameAbiesBasionymAuthor1Unicode, null, Rank.SPECIES());
213 assertEquals("Abies", nameBasionymAuthor.getGenusOrUninomial());
214 assertEquals("alba", nameBasionymAuthor.getSpecificEpithet());
215 assertEquals("D'M\u00FCller", nameBasionymAuthor.getCombinationAuthorTeam().getNomenclaturalTitle());
216 INomenclaturalAuthor basionymTeam = nameBasionymAuthor.getBasionymAuthorTeam();
217 assertEquals("Ciardelli", basionymTeam.getNomenclaturalTitle());
218
219 NonViralName<?> nameBasionymExAuthor = parser.parseFullName(strNameAbiesBasionymExAuthor1Unicode, null, Rank.SPECIES());
220 assertEquals("Abies", nameBasionymExAuthor.getGenusOrUninomial());
221 assertEquals("alba", nameBasionymExAuthor.getSpecificEpithet());
222 assertEquals("D'M\u00FCller", nameBasionymExAuthor.getExCombinationAuthorTeam().getNomenclaturalTitle());
223 assertEquals("de Greuther", nameBasionymExAuthor.getCombinationAuthorTeam().getNomenclaturalTitle());
224 INomenclaturalAuthor basionymTeam2 = nameBasionymExAuthor.getExBasionymAuthorTeam();
225 assertEquals("Ciardelli", basionymTeam2.getNomenclaturalTitle());
226 INomenclaturalAuthor exBasionymTeam2 = nameBasionymExAuthor.getBasionymAuthorTeam();
227 assertEquals("D\u00F6ring", exBasionymTeam2.getNomenclaturalTitle());
228
229 BotanicalName nameBasionymExAuthor2 = (BotanicalName)parser.parseFullName("Washingtonia filifera (Linden ex Andre) H.Wendl. ex de Bary", null, Rank.SPECIES());
230 assertEquals("Washingtonia", nameBasionymExAuthor2.getGenusOrUninomial());
231 assertEquals("filifera", nameBasionymExAuthor2.getSpecificEpithet());
232 assertEquals("H.Wendl.", nameBasionymExAuthor2.getExCombinationAuthorTeam().getNomenclaturalTitle());
233 assertEquals("de Bary", nameBasionymExAuthor2.getCombinationAuthorTeam().getNomenclaturalTitle());
234 INomenclaturalAuthor basionymTeam3 = nameBasionymExAuthor2.getBasionymAuthorTeam();
235 assertEquals("Andre", basionymTeam3.getNomenclaturalTitle());
236 INomenclaturalAuthor exBasionymTeam3 = nameBasionymExAuthor2.getExBasionymAuthorTeam();
237 assertEquals("Linden", exBasionymTeam3.getNomenclaturalTitle());
238 String title = nameBasionymExAuthor2.getTitleCache();
239 assertEquals("Washingtonia filifera (Linden ex Andre) H.Wendl. ex de Bary", title);
240
241 }
242
243
244 /**
245 * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#parseFullName(java.lang.String, eu.etaxonomy.cdm.model.name.Rank)}.
246 */
247 @Test
248 public final void testParseFullName() {
249 try {
250 Method parseMethod = parser.getClass().getDeclaredMethod("parseFullName", String.class, NomenclaturalCode.class, Rank.class);
251 testName_StringNomcodeRank(parseMethod);
252 } catch (Exception e) {
253 e.printStackTrace();
254 assertTrue(false);
255 }
256
257 //Team
258 NonViralName<?> nameTeam1 = parser.parseFullName(strNameTeam1);
259 assertEquals( "Abies", nameTeam1.getGenusOrUninomial());
260 assertEquals( "alba", nameTeam1.getSpecificEpithet());
261 assertEquals("Mueller & L.", nameTeam1.getCombinationAuthorTeam().getNomenclaturalTitle());
262 assertTrue(nameTeam1.getCombinationAuthorTeam() instanceof Team);
263 Team team = (Team)nameTeam1.getCombinationAuthorTeam();
264 assertEquals("Mueller", team.getTeamMembers().get(0).getNomenclaturalTitle());
265 assertEquals("L.", team.getTeamMembers().get(1).getNomenclaturalTitle());
266
267 //ZooName
268 ZoologicalName nameZoo1 = (ZoologicalName)parser.parseFullName(strNameZoo1);
269 assertEquals( "Abies", nameZoo1.getGenusOrUninomial());
270 assertEquals( "alba", nameZoo1.getSpecificEpithet());
271 assertEquals("Mueller & L.", nameZoo1.getCombinationAuthorTeam().getNomenclaturalTitle());
272 assertEquals(NomenclaturalCode.ICZN, nameZoo1.getNomenclaturalCode() );
273 assertEquals(Integer.valueOf(1822), nameZoo1.getPublicationYear());
274 assertTrue(nameZoo1.getCombinationAuthorTeam() instanceof Team);
275 Team teamZoo = (Team)nameZoo1.getCombinationAuthorTeam();
276 assertEquals("Mueller", teamZoo.getTeamMembers().get(0).getNomenclaturalTitle());
277 assertEquals("L.", teamZoo.getTeamMembers().get(1).getNomenclaturalTitle());
278
279 ZoologicalName nameZoo2 = (ZoologicalName)parser.parseFullName(strNameZoo2);
280 assertEquals(Integer.valueOf(2002), nameZoo2.getPublicationYear());
281 assertEquals(Integer.valueOf(1822), nameZoo2.getOriginalPublicationYear());
282 assertEquals("Mueller", nameZoo2.getBasionymAuthorTeam().getNomenclaturalTitle());
283 assertEquals("Ciardelli", nameZoo2.getCombinationAuthorTeam().getNomenclaturalTitle());
284
285 //Autonym
286 BotanicalName autonymName = (BotanicalName)parser.parseFullName("Abies alba Mill. var. alba", ICBN, null);
287 assertFalse("Autonym should be parsable", autonymName.hasProblem());
288
289
290 //empty
291 NonViralName<?> nameEmpty = parser.parseFullName(strNameEmpty);
292 assertNotNull(nameEmpty);
293 assertEquals("", nameEmpty.getTitleCache());
294
295 //null
296 NonViralName<?> nameNull = parser.parseFullName(strNameNull);
297 assertNull(nameNull);
298
299 //some authors
300 String fullNameString = "Abies alba (Greuther & L'Hiver & al. ex M\u00FCller & Schmidt)Clark ex Ciardelli";
301 NonViralName<?> authorname = (BotanicalName)parser.parseFullName(fullNameString);
302 assertFalse(authorname.hasProblem());
303 assertEquals("Basionym author should have 3 authors", 3, ((Team)authorname.getExBasionymAuthorTeam()).getTeamMembers().size());
304
305 }
306
307 /**
308 * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#parseFullName(java.lang.String, eu.etaxonomy.cdm.model.name.Rank)}.
309 */
310 @Test
311 public final void testHybrids() {
312 try {
313 Method parseMethod = parser.getClass().getDeclaredMethod("parseFullName", String.class, NomenclaturalCode.class, Rank.class);
314 testName_StringNomcodeRank(parseMethod);
315 } catch (Exception e) {
316 e.printStackTrace();
317 assertTrue(false);
318 }
319
320 //Species hybrid
321 // NonViralName nameTeam1 = parser.parseFullName("Aegilops \u00D7insulae-cypri H. Scholz");
322 NonViralName<?> name1 = parser.parseFullName("Aegilops \u00D7insulae Scholz", botanicCode, null);
323 assertTrue("Name must have binom hybrid bit set", name1.isBinomHybrid());
324 assertFalse("Name must not have monom hybrid bit set", name1.isMonomHybrid());
325 assertFalse("Name must not have trinom hybrid bit set", name1.isTrinomHybrid());
326 assertEquals("Species epithet must be 'insulae'", "insulae", name1.getSpecificEpithet());
327
328 //Uninomial hybrid
329 name1 = parser.parseFullName("x Aegilops Scholz", botanicCode, null);
330 assertTrue("Name must have monom hybrid bit set", name1.isMonomHybrid());
331 assertFalse("Name must not have binom hybrid bit set", name1.isBinomHybrid());
332 assertFalse("Name must not have trinom hybrid bit set", name1.isTrinomHybrid());
333 assertEquals("Uninomial must be 'Aegilops'", "Aegilops", name1.getGenusOrUninomial());
334
335 //Species hybrid
336 name1 = parser.parseFullName("Aegilops insulae subsp. X abies Scholz", botanicCode, null);
337 assertFalse("Name must not have monom hybrid bit set", name1.isMonomHybrid());
338 assertFalse("Name must not have binom hybrid bit set", name1.isBinomHybrid());
339 assertTrue("Name must have trinom hybrid bit set", name1.isTrinomHybrid());
340 assertEquals("Infraspecific epithet must be 'abies'", "abies", name1.getInfraSpecificEpithet());
341
342
343 }
344
345 /**
346 * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#parseFullName(java.lang.String, eu.etaxonomy.cdm.model.name.Rank)}.
347 */
348 @Test
349 public final void testUnrankedNames() {
350 try {
351 Method parseMethod = parser.getClass().getDeclaredMethod("parseFullName", String.class, NomenclaturalCode.class, Rank.class);
352 testName_StringNomcodeRank(parseMethod);
353 } catch (Exception e) {
354 e.printStackTrace();
355 assertTrue(false);
356 }
357
358 //unranked infraspecific
359 String infraspecificUnranked = "Genus species [unranked] infraspecific";
360 NonViralName<?> name = parser.parseFullName(infraspecificUnranked);
361 assertEquals( "Genus", name.getGenusOrUninomial());
362 assertEquals( "species", name.getSpecificEpithet());
363 assertEquals( "infraspecific", name.getInfraSpecificEpithet());
364 assertEquals( "Unranked rank should be parsed", Rank.INFRASPECIFICTAXON(), name.getRank());
365
366 //unranked infrageneric
367 String infraGenericUnranked = "Genus [unranked] Infragen";
368 NonViralName<?> name2 = parser.parseFullName(infraGenericUnranked);
369 assertEquals( "Genus", name2.getGenusOrUninomial());
370 assertEquals( null, name2.getSpecificEpithet());
371 assertEquals( "Infragen", name2.getInfraGenericEpithet());
372 assertEquals( "Unranked rank should be parsed", Rank.INFRAGENERICTAXON(), name2.getRank());
373
374 }
375
376
377 /**
378 * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#parseFullName(java.lang.String, eu.etaxonomy.cdm.model.name.Rank)}.
379 */
380 @Test
381 public final void testHybridFormulars() {
382 try {
383 Method parseMethod = parser.getClass().getDeclaredMethod("parseFullName", String.class, NomenclaturalCode.class, Rank.class);
384 testName_StringNomcodeRank(parseMethod);
385 } catch (Exception e) {
386 e.printStackTrace();
387 assertTrue(false);
388 }
389
390 //Species hybrid
391 String hybridCache = "Abies alba \u00D7 Pinus bus";
392 NonViralName<?> name1 = parser.parseFullName(hybridCache, botanicCode, null);
393 assertTrue("Name must have hybrid formula bit set", name1.isHybridFormula());
394 assertEquals("Name must have 2 hybrid parents", 2, name1.getHybridChildRelations().size());
395 assertEquals("Title cache must be correct", hybridCache, name1.getTitleCache());
396 List<HybridRelationship> orderedRels = name1.getOrderedChildRelationships();
397 assertEquals("Name must have 2 hybrid parents in ordered list", 2, orderedRels.size());
398 NonViralName<?> firstParent = orderedRels.get(0).getParentName();
399 assertEquals("Name must have Abies alba as first hybrid parent", "Abies alba", firstParent.getTitleCache());
400 NonViralName<?> secondParent = orderedRels.get(1).getParentName();
401 assertEquals("Name must have Pinus bus as second hybrid parent", "Pinus bus", secondParent.getTitleCache());
402 assertEquals("Hybrid name must have the lowest rank ('species') as rank", Rank.SPECIES(), name1.getRank());
403 assertNull("Name must not have a genus eptithet", name1.getGenusOrUninomial());
404 assertNull("Name must not have a specific eptithet", name1.getSpecificEpithet());
405
406
407 //x-sign
408 hybridCache = "Abies alba x Pinus bus";
409 name1 = parser.parseFullName(hybridCache, botanicCode, null);
410 assertFalse("Name must be parsable", name1.hasProblem());
411 assertTrue("Name must have hybrid formula bit set", name1.isHybridFormula());
412
413 //Subspecies first hybrid
414 name1 = parser.parseFullName("Abies alba subsp. beta \u00D7 Pinus bus", botanicCode, null);
415 assertTrue("Name must have hybrid formula bit set", name1.isHybridFormula());
416 assertEquals("Name must have 2 hybrid parents", 2, name1.getHybridChildRelations().size());
417 assertEquals("Title cache must be correct", "Abies alba subsp. beta \u00D7 Pinus bus", name1.getTitleCache());
418 orderedRels = name1.getOrderedChildRelationships();
419 assertEquals("Name must have 2 hybrid parents in ordered list", 2, orderedRels.size());
420 firstParent = orderedRels.get(0).getParentName();
421 assertEquals("Name must have Abies alba subsp. beta as first hybrid parent", "Abies alba subsp. beta", firstParent.getTitleCache());
422 secondParent = orderedRels.get(1).getParentName();
423 assertEquals("Name must have Pinus bus as second hybrid parent", "Pinus bus", secondParent.getTitleCache());
424 assertEquals("Hybrid name must have the lower rank ('subspecies') as rank", Rank.SUBSPECIES(), name1.getRank());
425
426 //variety second hybrid
427 name1 = parser.parseFullName("Abies alba \u00D7 Pinus bus var. beta", botanicCode, null);
428 assertTrue("Name must have hybrid formula bit set", name1.isHybridFormula());
429 assertEquals("Name must have 2 hybrid parents", 2, name1.getHybridChildRelations().size());
430 assertEquals("Title cache must be correct", "Abies alba \u00D7 Pinus bus var. beta", name1.getTitleCache());
431 assertEquals("Hybrid name must have the lower rank ('variety') as rank", Rank.VARIETY(), name1.getRank());
432
433 //hybrids with authors
434 name1 = parser.parseFullName("Abies alba L. \u00D7 Pinus bus Mill.", botanicCode, null);
435 assertTrue("Name must have hybrid formula bit set", name1.isHybridFormula());
436 assertEquals("Name must have 2 hybrid parents", 2, name1.getHybridChildRelations().size());
437 assertEquals("Title cache must be correct", "Abies alba L. \u00D7 Pinus bus Mill.", name1.getTitleCache());
438 orderedRels = name1.getOrderedChildRelationships();
439 assertEquals("Name must have 2 hybrid parents in ordered list", 2, orderedRels.size());
440 firstParent = orderedRels.get(0).getParentName();
441 assertEquals("Name must have Abies alba L. as first hybrid parent", "Abies alba L.", firstParent.getTitleCache());
442 secondParent = orderedRels.get(1).getParentName();
443 assertEquals("Name must have Pinus bus Mill. as second hybrid parent", "Pinus bus Mill.", secondParent.getTitleCache());
444 assertEquals("Hybrid name must have the lower rank ('species') as rank", Rank.SPECIES(), name1.getRank());
445
446 }
447
448
449 private void testName_StringNomcodeRank(Method parseMethod)
450 throws InvocationTargetException, IllegalAccessException {
451 NonViralName<?> name1 = (NonViralName<?>)parseMethod.invoke(parser, strNameAbies1, null, Rank.SPECIES());
452 //parser.parseFullName(strNameAbies1, null, Rank.SPECIES());
453 assertEquals("Abies", name1.getGenusOrUninomial());
454 assertEquals("alba", name1.getSpecificEpithet());
455
456 NonViralName<?> nameAuthor = (NonViralName<?>)parseMethod.invoke(parser, strNameAbiesAuthor1, null, Rank.SPECIES());
457 assertEquals("Abies", nameAuthor.getGenusOrUninomial());
458 assertEquals("alba", nameAuthor.getSpecificEpithet());
459 assertEquals("Mueller", nameAuthor.getCombinationAuthorTeam().getNomenclaturalTitle());
460
461 NonViralName<?> nameBasionymAuthor = (NonViralName<?>)parseMethod.invoke(parser, strNameAbiesBasionymAuthor1, null, Rank.SPECIES());
462 assertEquals("Abies", nameBasionymAuthor.getGenusOrUninomial());
463 assertEquals("alba", nameBasionymAuthor.getSpecificEpithet());
464 assertEquals("D'Mueller", nameBasionymAuthor.getCombinationAuthorTeam().getNomenclaturalTitle());
465 assertEquals("Ciardelli", nameBasionymAuthor.getBasionymAuthorTeam().getNomenclaturalTitle());
466
467 NonViralName<?> nameBasionymExAuthor = (NonViralName<?>)parseMethod.invoke(parser, strNameAbiesBasionymExAuthor1, null, Rank.SPECIES());
468 assertEquals("Abies", nameBasionymExAuthor.getGenusOrUninomial());
469 assertEquals("alba", nameBasionymExAuthor.getSpecificEpithet());
470 assertEquals("D'Mueller", nameBasionymExAuthor.getExCombinationAuthorTeam().getNomenclaturalTitle());
471 assertEquals("de Greuther", nameBasionymExAuthor.getCombinationAuthorTeam().getNomenclaturalTitle());
472 assertEquals("Ciardelli", nameBasionymExAuthor.getExBasionymAuthorTeam().getNomenclaturalTitle());
473 assertEquals("Doering", nameBasionymExAuthor.getBasionymAuthorTeam().getNomenclaturalTitle());
474
475 NonViralName<?> name2 = (NonViralName<?>)parseMethod.invoke(parser, strNameAbiesSub1, null, Rank.SPECIES());
476 assertEquals("Abies", name2.getGenusOrUninomial());
477 assertEquals("alba", name2.getSpecificEpithet());
478 assertEquals("beta", name2.getInfraSpecificEpithet());
479 assertEquals(Rank.SUBSPECIES(), name2.getRank());
480
481
482 // unparseable *********
483 String problemString = "sdfjlös wer eer wer";
484 NonViralName<?> nameProblem = (NonViralName<?>)parseMethod.invoke(parser, problemString, null, Rank.SPECIES());
485 List<ParserProblem> list = nameProblem.getParsingProblems();
486 assertTrue(nameProblem.getParsingProblem()!=0);
487 assertEquals(problemString, nameProblem.getTitleCache());
488 }
489
490
491 /**
492 * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#parseReferencedName(NonViralName, java.lang.String, eu.etaxonomy.cdm.model.name.Rank, boolean)(, )}.
493 */
494 @Test
495 public final void testParseNomStatus() {
496 //nom. ambig.
497 String strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. ambig.";
498 NonViralName<?> nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
499 assertFullRefStandard(nameTestStatus);
500 assertTrue(nameTestStatus.getStatus().size()== 1);
501 assertEquals( NomenclaturalStatusType.AMBIGUOUS(), nameTestStatus.getStatus().iterator().next().getType());
502
503 //nom. dub.
504 strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. dub.";
505 nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
506 assertFullRefStandard(nameTestStatus);
507 assertTrue(nameTestStatus.getStatus().size()== 1);
508 assertEquals( NomenclaturalStatusType.DOUBTFUL(), nameTestStatus.getStatus().iterator().next().getType());
509
510 //nom. confus.
511 strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. confus.";
512 nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
513 assertFullRefStandard(nameTestStatus);
514 assertTrue(nameTestStatus.getStatus().size()== 1);
515 assertEquals( NomenclaturalStatusType.CONFUSUM(), nameTestStatus.getStatus().iterator().next().getType());
516
517 //nom. illeg.
518 strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. illeg.";
519 nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
520 assertFullRefStandard(nameTestStatus);
521 assertTrue(nameTestStatus.getStatus().size()== 1);
522 assertEquals( NomenclaturalStatusType.ILLEGITIMATE(), nameTestStatus.getStatus().iterator().next().getType());
523
524 //nom. superfl.
525 strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. superfl.";
526 nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
527 assertFullRefStandard(nameTestStatus);
528 assertTrue(nameTestStatus.getStatus().size()== 1);
529 assertEquals( NomenclaturalStatusType.SUPERFLUOUS(), nameTestStatus.getStatus().iterator().next().getType());
530
531 //nom. rej.
532 strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. rej.";
533 nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
534 assertFullRefStandard(nameTestStatus);
535 assertTrue(nameTestStatus.getStatus().size()== 1);
536 assertEquals( NomenclaturalStatusType.REJECTED(), nameTestStatus.getStatus().iterator().next().getType());
537
538 //nom. utique rej.
539 strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. utique rej.";
540 nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
541 assertFullRefStandard(nameTestStatus);
542 assertTrue(nameTestStatus.getStatus().size()== 1);
543 assertEquals( NomenclaturalStatusType.UTIQUE_REJECTED(), nameTestStatus.getStatus().iterator().next().getType());
544
545 //nom. cons. prop.
546 strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. cons. prop.";
547 nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
548 assertFullRefStandard(nameTestStatus);
549 assertTrue(nameTestStatus.getStatus().size()== 1);
550 assertEquals( NomenclaturalStatusType.CONSERVED_PROP(), nameTestStatus.getStatus().iterator().next().getType());
551
552 //nom. orth. cons. prop.
553 strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. orth. cons. prop.";
554 nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
555 assertFullRefStandard(nameTestStatus);
556 assertTrue(nameTestStatus.getStatus().size()== 1);
557 assertEquals( NomenclaturalStatusType.ORTHOGRAPHY_CONSERVED_PROP(), nameTestStatus.getStatus().iterator().next().getType());
558
559 //nom. legit.
560 strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. legit.";
561 nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
562 assertFullRefStandard(nameTestStatus);
563 assertTrue(nameTestStatus.getStatus().size()== 1);
564 assertEquals( NomenclaturalStatusType.LEGITIMATE(), nameTestStatus.getStatus().iterator().next().getType());
565
566 //nom. altern.
567 strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. altern.";
568 nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
569 assertFullRefStandard(nameTestStatus);
570 assertTrue(nameTestStatus.getStatus().size()== 1);
571 assertEquals( NomenclaturalStatusType.ALTERNATIVE(), nameTestStatus.getStatus().iterator().next().getType());
572
573 //nom. alternativ.
574 strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. alternativ.";
575 nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
576 assertFullRefStandard(nameTestStatus);
577 assertTrue(nameTestStatus.getStatus().size()== 1);
578 assertEquals( NomenclaturalStatusType.ALTERNATIVE(), nameTestStatus.getStatus().iterator().next().getType());
579
580 //nom. nov.
581 strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. nov.";
582 nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
583 assertFullRefStandard(nameTestStatus);
584 assertTrue(nameTestStatus.getStatus().size()== 1);
585 assertEquals( NomenclaturalStatusType.NOVUM(), nameTestStatus.getStatus().iterator().next().getType());
586
587 //nom. utique rej. prop.
588 strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. utique rej. prop.";
589 nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
590 assertFullRefStandard(nameTestStatus);
591 assertTrue(nameTestStatus.getStatus().size()== 1);
592 assertEquals( NomenclaturalStatusType.UTIQUE_REJECTED_PROP(), nameTestStatus.getStatus().iterator().next().getType());
593
594 //nom. orth. cons.
595 strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. orth. cons.";
596 nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
597 assertFullRefStandard(nameTestStatus);
598 assertTrue(nameTestStatus.getStatus().size()== 1);
599 assertEquals( NomenclaturalStatusType.ORTHOGRAPHY_CONSERVED(), nameTestStatus.getStatus().iterator().next().getType());
600
601 //nom. rej. prop.
602 strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. rej. prop.";
603 nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
604 assertFullRefStandard(nameTestStatus);
605 assertTrue(nameTestStatus.getStatus().size()== 1);
606 assertEquals( NomenclaturalStatusType.REJECTED_PROP(), nameTestStatus.getStatus().iterator().next().getType());
607
608 //nom. cons.
609 strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. cons.";
610 nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
611 assertFullRefStandard(nameTestStatus);
612 assertTrue(nameTestStatus.getStatus().size()== 1);
613 assertEquals( NomenclaturalStatusType.CONSERVED(), nameTestStatus.getStatus().iterator().next().getType());
614
615 //nom. sanct.
616 strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. sanct.";
617 nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
618 assertFullRefStandard(nameTestStatus);
619 assertTrue(nameTestStatus.getStatus().size()== 1);
620 assertEquals( NomenclaturalStatusType.SANCTIONED(), nameTestStatus.getStatus().iterator().next().getType());
621
622 //nom. inval.
623 strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. inval.";
624 nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
625 assertFullRefStandard(nameTestStatus);
626 assertTrue(nameTestStatus.getStatus().size()== 1);
627 assertEquals( NomenclaturalStatusType.INVALID(), nameTestStatus.getStatus().iterator().next().getType());
628
629 //nom. nud.
630 strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. nud.";
631 nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
632 assertFullRefStandard(nameTestStatus);
633 assertTrue(nameTestStatus.getStatus().size()== 1);
634 assertEquals( NomenclaturalStatusType.NUDUM(), nameTestStatus.getStatus().iterator().next().getType());
635
636 //comb. inval.
637 strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, comb. inval.";
638 nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
639 assertFullRefStandard(nameTestStatus);
640 assertTrue(nameTestStatus.getStatus().size()== 1);
641 assertEquals( NomenclaturalStatusType.COMBINATION_INVALID(), nameTestStatus.getStatus().iterator().next().getType());
642
643 //comb. illeg.
644 strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, comb. illeg.";
645 nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
646 assertFullRefStandard(nameTestStatus);
647 assertTrue(nameTestStatus.getStatus().size()== 1);
648 assertEquals( NomenclaturalStatusType.COMBINATION_ILLEGITIMATE(), nameTestStatus.getStatus().iterator().next().getType());
649
650 //nom. provis.
651 strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. provis.";
652 nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
653 assertFullRefStandard(nameTestStatus);
654 assertTrue(nameTestStatus.getStatus().size()== 1);
655 assertEquals( NomenclaturalStatusType.PROVISIONAL(), nameTestStatus.getStatus().iterator().next().getType());
656
657 //nom. valid
658 strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. valid";
659 nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
660 assertFullRefStandard(nameTestStatus);
661 assertTrue(nameTestStatus.getStatus().size()== 1);
662 assertEquals( NomenclaturalStatusType.VALID(), nameTestStatus.getStatus().iterator().next().getType());
663
664 //nom. subnud.
665 strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. subnud.";
666 nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
667 assertFullRefStandard(nameTestStatus);
668 assertTrue(nameTestStatus.getStatus().size()== 1);
669 assertEquals( NomenclaturalStatusType.SUBNUDUM(), nameTestStatus.getStatus().iterator().next().getType());
670
671 //opus. utique oppr.
672 strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, opus. utique oppr.";
673 nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
674 assertFullRefStandard(nameTestStatus);
675 assertTrue(nameTestStatus.getStatus().size()== 1);
676 assertEquals( NomenclaturalStatusType.OPUS_UTIQUE_OPPR(), nameTestStatus.getStatus().iterator().next().getType());
677
678 }
679
680 /**
681 * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#parseReferencedName(NonViralName, java.lang.String, eu.etaxonomy.cdm.model.name.Rank, boolean)(, )}.
682 */
683 @Test
684 public final void testParseReferencedName() {
685 try {
686 Method parseMethod = parser.getClass().getDeclaredMethod("parseReferencedName", String.class, NomenclaturalCode.class, Rank.class);
687 testName_StringNomcodeRank(parseMethod);
688 } catch (Exception e) {
689 e.printStackTrace();
690 assertTrue(false);
691 }
692
693
694 //null
695 String strNull = null;
696 Rank rankSpecies = Rank.SPECIES();
697 NonViralName<?> nameNull = parser.parseReferencedName(strNull, null, rankSpecies);
698 assertNull(nameNull);
699
700 //Empty
701 String strEmpty = "";
702 NonViralName<?> nameEmpty = parser.parseReferencedName(strEmpty, null, rankSpecies);
703 assertFalse(nameEmpty.hasProblem());
704 assertEquals(strEmpty, nameEmpty.getFullTitleCache());
705 assertNull(nameEmpty.getNomenclaturalMicroReference());
706
707
708 //Whitespaces
709 String strFullWhiteSpcaceAndDot = "Abies alba Mill., Sp. Pl. 4: 455 . 1987 .";
710 NonViralName<?> namefullWhiteSpcaceAndDot = parser.parseReferencedName(strFullWhiteSpcaceAndDot, null, rankSpecies);
711 assertFullRefStandard(namefullWhiteSpcaceAndDot);
712 assertTrue(((Reference<?>)namefullWhiteSpcaceAndDot.getNomenclaturalReference()).getType().equals(eu.etaxonomy.cdm.model.reference.ReferenceType.Book));
713 assertEquals( "Abies alba Mill., Sp. Pl. 4: 455. 1987", namefullWhiteSpcaceAndDot.getFullTitleCache());
714
715 //Book
716 String fullReference = "Abies alba Mill., Sp. Pl. 4: 455. 1987";
717 NonViralName<?> name1 = parser.parseReferencedName(fullReference, null, rankSpecies);
718 assertFullRefStandard(name1);
719 assertTrue(((Reference<?>)name1.getNomenclaturalReference()).getType().equals(eu.etaxonomy.cdm.model.reference.ReferenceType.Book));
720 assertEquals(fullReference, name1.getFullTitleCache());
721 assertTrue("Name author and reference author should be the same", name1.getCombinationAuthorTeam() == ((Reference<?>)name1.getNomenclaturalReference()).getAuthorship());
722
723 //Book Section
724 fullReference = "Abies alba Mill. in Otto, Sp. Pl. 4(6): 455. 1987";
725 NonViralName<?> name2 = parser.parseReferencedName(fullReference + ".", null, rankSpecies);
726 assertFullRefNameStandard(name2);
727 assertEquals(fullReference, name2.getFullTitleCache());
728 assertFalse(name2.hasProblem());
729 INomenclaturalReference ref = name2.getNomenclaturalReference();
730 assertEquals(eu.etaxonomy.cdm.model.reference.ReferenceType.BookSection, ((Reference<?>)ref).getType());
731 IBookSection bookSection = (IBookSection) ref;
732 IBook inBook = bookSection.getInBook();
733 assertNotNull(inBook);
734 assertNotNull(inBook.getAuthorship());
735 assertEquals("Otto", inBook.getAuthorship().getTitleCache());
736 assertEquals("Otto, Sp. Pl. 4(6)", inBook.getTitleCache());
737 assertEquals("Sp. Pl.", inBook.getTitle());
738 assertEquals("4(6)", inBook.getVolume());
739 assertTrue("Name author and reference author should be the same", name2.getCombinationAuthorTeam() == ((Reference<?>)name2.getNomenclaturalReference()).getAuthorship());
740
741 //Article
742 fullReference = "Abies alba Mill. in Sp. Pl. 4(6): 455. 1987";
743 NonViralName<?> name3 = parser.parseReferencedName(fullReference, null, rankSpecies);
744 assertFullRefNameStandard(name3);
745 name3.setTitleCache(null);
746 assertEquals(fullReference, name3.getFullTitleCache());
747 assertFalse(name3.hasProblem());
748 ref = name3.getNomenclaturalReference();
749 assertEquals(eu.etaxonomy.cdm.model.reference.ReferenceType.Article, ref.getType());
750 //Article article = (Article)ref;
751 IJournal journal = ((IArticle)ref).getInJournal();
752 assertNotNull(journal);
753 //assertEquals("Sp. Pl. 4(6)", inBook.getTitleCache());
754 assertEquals("Sp. Pl.",((Reference<?>) journal).getTitleCache());
755 assertEquals("Sp. Pl.", journal.getTitle());
756 assertEquals("4(6)",((IArticle)ref).getVolume());
757 assertTrue("Name author and reference author should be the same", name3.getCombinationAuthorTeam() == name3.getNomenclaturalReference().getAuthorship());
758
759 //SoftArticle - having "," on position > 4
760 String journalTitle = "Bull. Soc. Bot.France. Louis., Roi";
761 String yearPart = " 1987 - 1989";
762 String parsedYear = "1987-1989";
763 String fullReferenceWithoutYear = "Abies alba Mill. in " + journalTitle + " 4(6): 455.";
764 fullReference = fullReferenceWithoutYear + yearPart;
765 String fullReferenceWithEnd = fullReference + ".";
766 NonViralName<?> name4 = parser.parseReferencedName(fullReferenceWithEnd, null, rankSpecies);
767 assertFalse(name4.hasProblem());
768 assertFullRefNameStandard(name4);
769 assertEquals(fullReferenceWithoutYear + " " + parsedYear, name4.getFullTitleCache());
770 ref = name4.getNomenclaturalReference();
771 assertEquals(ReferenceType.Article, ref.getType());
772 //article = (Article)ref;
773 assertEquals(parsedYear, ref.getYear());
774 journal = ((IArticle)ref).getInJournal();
775 assertNotNull(journal);
776 assertEquals(journalTitle, ((Reference<?>) journal).getTitleCache());
777 assertEquals(journalTitle, journal.getTitle());
778 assertEquals("4(6)", ((IArticle)ref).getVolume());
779
780 //Zoo name
781 String strNotParsableZoo = "Abies alba M., 1923, Sp. P. xxwer4352, nom. inval.";
782 ZoologicalName nameZooRefNotParsabel = (ZoologicalName)parser.parseReferencedName(strNotParsableZoo, null, null);
783 assertTrue(nameZooRefNotParsabel.hasProblem());
784 List<ParserProblem> list = nameZooRefNotParsabel.getParsingProblems();
785 assertTrue("List must contain detail and year warning ", list.contains(ParserProblem.CheckDetailOrYear));
786 assertEquals(21, nameZooRefNotParsabel.getProblemStarts());
787 assertEquals(37, nameZooRefNotParsabel.getProblemEnds());
788 assertTrue(nameZooRefNotParsabel.getNomenclaturalReference().hasProblem());
789 list = nameZooRefNotParsabel.getNomenclaturalReference().getParsingProblems();
790 assertTrue("List must contain detail and year warning ", list.contains(ParserProblem.CheckDetailOrYear));
791
792 assertEquals(NomenclaturalCode.ICZN, nameZooRefNotParsabel.getNomenclaturalCode());
793 assertEquals(Integer.valueOf(1923), nameZooRefNotParsabel.getPublicationYear());
794 assertEquals(1, nameZooRefNotParsabel.getStatus().size());
795
796 String strZooNameSineYear = "Homo sapiens L., 1758, Sp. An. 3: 345";
797 ZoologicalName nameZooNameSineYear = (ZoologicalName)parser.parseReferencedName(strZooNameSineYear);
798 assertFalse(nameZooNameSineYear.hasProblem());
799 assertEquals("Name without reference year must have year", (Integer)1758, nameZooNameSineYear.getPublicationYear());
800 assertEquals("Name without reference year must have year", "1758", nameZooNameSineYear.getNomenclaturalReference().getYear());
801
802 String strZooNameNewCombination = "Homo sapiens (L., 1758) Mill., 1830, Sp. An. 3: 345";
803 ZoologicalName nameZooNameNewCombination = (ZoologicalName)parser.parseReferencedName(strZooNameNewCombination);
804 assertTrue(nameZooNameNewCombination.hasProblem());
805 list = nameZooNameNewCombination.getParsingProblems();
806 assertTrue("List must contain new combination has publication warning ", list.contains(ParserProblem.NewCombinationHasPublication));
807 assertEquals(35, nameZooNameNewCombination.getProblemStarts());
808 assertEquals(51, nameZooNameNewCombination.getProblemEnds());
809
810
811 //Special MicroRefs
812 String strSpecDetail1 = "Abies alba Mill. in Sp. Pl. 4(6): [455]. 1987";
813 NonViralName<?> nameSpecDet1 = parser.parseReferencedName(strSpecDetail1 + ".", null, rankSpecies);
814 assertFalse(nameSpecDet1.hasProblem());
815 assertEquals(strSpecDetail1, nameSpecDet1.getFullTitleCache());
816 assertEquals("[455]", nameSpecDet1.getNomenclaturalMicroReference());
817
818 //Special MicroRefs
819 String strSpecDetail2 = "Abies alba Mill. in Sp. Pl. 4(6): couv. 2. 1987";
820 NonViralName<?> nameSpecDet2 = parser.parseReferencedName(strSpecDetail2 + ".", null, rankSpecies);
821 assertFalse(nameSpecDet2.hasProblem());
822 assertEquals(strSpecDetail2, nameSpecDet2.getFullTitleCache());
823 assertEquals("couv. 2", nameSpecDet2.getNomenclaturalMicroReference());
824
825 //Special MicroRefs
826 String strSpecDetail3 = "Abies alba Mill. in Sp. Pl. 4(6): fig. 455. 1987";
827 NonViralName<?> nameSpecDet3 = parser.parseReferencedName(strSpecDetail3 + ".", null, rankSpecies);
828 assertFalse(nameSpecDet3.hasProblem());
829 assertEquals(strSpecDetail3, nameSpecDet3.getFullTitleCache());
830 assertEquals("fig. 455", nameSpecDet3.getNomenclaturalMicroReference());
831
832 //Special MicroRefs
833 String strSpecDetail4 = "Abies alba Mill. in Sp. Pl. 4(6): fig. 455-567. 1987";
834 fullReference = strSpecDetail4 + ".";
835 NonViralName<?> nameSpecDet4 = parser.parseReferencedName(fullReference, null, rankSpecies);
836 assertFalse(nameSpecDet4.hasProblem());
837 assertEquals(strSpecDetail4, nameSpecDet4.getFullTitleCache());
838 assertEquals("fig. 455-567", nameSpecDet4.getNomenclaturalMicroReference());
839
840
841 //Special MicroRefs
842 String strSpecDetail5 = "Abies alba Mill. in Sp. Pl. 4(6): Gard n\u00B0 4. 1987";
843 fullReference = strSpecDetail5 + ".";
844 NonViralName<?> nameSpecDet5 = parser.parseReferencedName(fullReference, null, rankSpecies);
845 assertFalse(nameSpecDet5.hasProblem());
846 assertEquals(strSpecDetail5, nameSpecDet5.getFullTitleCache());
847 assertEquals("Gard n\u00B0 4", nameSpecDet5.getNomenclaturalMicroReference());
848
849 //Special MicroRefs
850 String strSpecDetail6 = "Abies alba Mill. in Sp. Pl. 4(6): 455a. 1987";
851 fullReference = strSpecDetail6 + ".";
852 NonViralName<?> nameSpecDet6 = parser.parseReferencedName(fullReference, null, rankSpecies);
853 assertFalse(nameSpecDet6.hasProblem());
854 assertEquals(strSpecDetail6, nameSpecDet6.getFullTitleCache());
855 assertEquals("455a", nameSpecDet6.getNomenclaturalMicroReference());
856
857 //Special MicroRefs
858 String strSpecDetail7 = "Abies alba Mill. in Sp. Pl. 4(6): pp.455-457. 1987";
859 fullReference = strSpecDetail7 + ".";
860 NonViralName<?> nameSpecDet7 = parser.parseReferencedName(fullReference, null, rankSpecies);
861 assertFalse(nameSpecDet7.hasProblem());
862 assertEquals(strSpecDetail7, nameSpecDet7.getFullTitleCache());
863 assertEquals("pp.455-457", nameSpecDet7.getNomenclaturalMicroReference());
864
865 //Special MicroRefs
866 String strSpecDetail8 = "Abies alba Mill. in Sp. Pl. 4(6): ppp.455-457. 1987";
867 NonViralName<?> nameSpecDet8 = parser.parseReferencedName(strSpecDetail8, null, rankSpecies);
868 assertTrue(nameSpecDet8.hasProblem());
869 assertEquals(20, nameSpecDet8.getProblemStarts()); //TODO better start behind :
870 assertEquals(51, nameSpecDet8.getProblemEnds()); //TODO better stop after -457
871
872
873 //Special MicroRefs
874 String strSpecDetail9 = "Abies alba Mill. in Sp. Pl. 4(6): pp. 455 - 457. 1987";
875 NonViralName<?> nameSpecDet9 = parser.parseReferencedName(strSpecDetail9, null, rankSpecies);
876 assertFalse(nameSpecDet9.hasProblem());
877 assertEquals(strSpecDetail9, nameSpecDet9.getFullTitleCache());
878 assertEquals("pp. 455 - 457", nameSpecDet9.getNomenclaturalMicroReference());
879
880 //Special MicroRefs
881 String strSpecDetail10 = "Abies alba Mill. in Sp. Pl. 4(6): p 455. 1987";
882 NonViralName<?> nameSpecDet10 = parser.parseReferencedName(strSpecDetail10, null, rankSpecies);
883 assertFalse(nameSpecDet10.hasProblem());
884 assertEquals(strSpecDetail10, nameSpecDet10.getFullTitleCache());
885 assertEquals("p 455", nameSpecDet10.getNomenclaturalMicroReference());
886
887 //Special MicroRefs
888 String strSpecDetail11 = "Abies alba Mill. in Sp. Pl. 4(6): p. 455 - 457. 1987";
889 NonViralName<?> nameSpecDet11 = parser.parseReferencedName(strSpecDetail11, null, rankSpecies);
890 assertTrue(nameSpecDet11.hasProblem());
891 list = nameSpecDet11.getParsingProblems();
892 assertTrue("Problem is Detail. Must be pp.", list.contains(ParserProblem.CheckDetailOrYear));
893 assertEquals(20, nameSpecDet8.getProblemStarts()); //TODO better start behind :
894 assertEquals(51, nameSpecDet8.getProblemEnds()); //TODO better stop after - 457
895
896
897 //no volume, no edition
898 String strNoVolume = "Abies alba Mill., Sp. Pl.: 455. 1987";
899 NonViralName<?> nameNoVolume = parser.parseReferencedName(strNoVolume, null, rankSpecies);
900 assertFalse(nameNoVolume.hasProblem());
901 assertEquals(strNoVolume, nameNoVolume.getFullTitleCache());
902 assertEquals(null, ((IVolumeReference)(nameNoVolume.getNomenclaturalReference())).getVolume());
903 assertEquals(null, ((IBook)nameNoVolume.getNomenclaturalReference()).getEdition());
904
905 //volume, no edition
906 strNoVolume = "Abies alba Mill., Sp. Pl. 2: 455. 1987";
907 nameNoVolume = parser.parseReferencedName(strNoVolume, null, rankSpecies);
908 assertFalse(nameNoVolume.hasProblem());
909 assertEquals(strNoVolume, nameNoVolume.getFullTitleCache());
910 assertEquals("2", ((IVolumeReference)(nameNoVolume.getNomenclaturalReference())).getVolume());
911 assertEquals(null, ((IBook)(nameNoVolume.getNomenclaturalReference())).getEdition());
912
913 //no volume, edition
914 strNoVolume = "Abies alba Mill., Sp. Pl., ed. 3: 455. 1987";
915 nameNoVolume = parser.parseReferencedName(strNoVolume, null, rankSpecies);
916 assertFalse(nameNoVolume.hasProblem());
917 assertEquals(strNoVolume, nameNoVolume.getFullTitleCache());
918 assertEquals(null, ((IVolumeReference)(nameNoVolume.getNomenclaturalReference())).getVolume());
919 assertEquals("3", ((IBook)(nameNoVolume.getNomenclaturalReference())).getEdition());
920
921 //volume, edition
922 strNoVolume = "Abies alba Mill., Sp. Pl. ed. 3, 4(5): 455. 1987";
923 nameNoVolume = parser.parseReferencedName(strNoVolume, null, rankSpecies);
924 assertFalse(nameNoVolume.hasProblem());
925 assertEquals(strNoVolume.replace(" ed.", ", ed."), nameNoVolume.getFullTitleCache());
926 assertEquals("4(5)", ((IVolumeReference)(nameNoVolume.getNomenclaturalReference())).getVolume());
927 assertEquals("3", ((IBook)(nameNoVolume.getNomenclaturalReference())).getEdition());
928
929 String strUnparsableInRef = "Abies alba Mill. in -er46: 455. 1987";
930 NonViralName<?> nameUnparsableInRef = parser.parseReferencedName(strUnparsableInRef, null, rankSpecies);
931 assertTrue(nameUnparsableInRef.hasProblem());
932 list = nameUnparsableInRef.getParsingProblems();
933 assertTrue("Unparsable title", list.contains(ParserProblem.UnparsableReferenceTitle));
934 assertEquals(strUnparsableInRef, nameUnparsableInRef.getFullTitleCache());
935 assertEquals(20, nameUnparsableInRef.getProblemStarts());
936 assertEquals(25, nameUnparsableInRef.getProblemEnds());
937
938
939 //volume, edition
940 String strNoSeparator = "Abies alba Mill. Sp. Pl. ed. 3, 4(5): 455. 1987";
941 NonViralName<?> nameNoSeparator = parser.parseReferencedName(strNoSeparator, ICBN, rankSpecies);
942 assertTrue(nameNoSeparator.hasProblem());
943 list = nameNoSeparator.getParsingProblems();
944 assertTrue("Problem is missing name-reference separator", list.contains(ParserProblem.NameReferenceSeparation));
945 assertEquals(strNoSeparator, nameNoSeparator.getFullTitleCache());
946 assertEquals(10, nameNoSeparator.getProblemStarts()); //TODO better start behind Mill. (?)
947 assertEquals(47, nameNoSeparator.getProblemEnds()); //TODO better stop before :
948
949 String strUnparsableInRef2 = "Hieracium pepsicum L., My Bookkkk 1. 1903";
950 NonViralName<?> nameUnparsableInRef2 = parser.parseReferencedName(strUnparsableInRef2, null, rankSpecies);
951 assertTrue(nameUnparsableInRef2.hasProblem());
952 list = nameUnparsableInRef2.getParsingProblems();
953 assertTrue("Problem detail", list.contains(ParserProblem.CheckDetailOrYear));
954 assertEquals(strUnparsableInRef2, nameUnparsableInRef2.getFullTitleCache());
955 assertEquals(23, nameUnparsableInRef2.getProblemStarts());
956 assertEquals(41, nameUnparsableInRef2.getProblemEnds());
957
958
959 String strUnparsableInRef3 = "Hieracium pespcim N., My Bookkkk 1. 1902";
960 NonViralName<?> nameUnparsableInRef3 = parser.parseReferencedName(strUnparsableInRef3, null, null);
961 assertTrue(nameUnparsableInRef3.hasProblem());
962 list = nameUnparsableInRef3.getParsingProblems();
963 assertTrue("Problem detail", list.contains(ParserProblem.CheckDetailOrYear));
964 assertEquals(strUnparsableInRef3, nameUnparsableInRef3.getFullTitleCache());
965 assertEquals(22, nameUnparsableInRef3.getProblemStarts());
966 assertEquals(40, nameUnparsableInRef3.getProblemEnds());
967
968 String strUnparsableInRef4 = "Hieracium pepsicum (Hsllreterto) L., My Bookkkk 1. 1903";
969 NonViralName<?> nameUnparsableInRef4 = parser.parseReferencedName(strUnparsableInRef4, null, null);
970 assertTrue(nameUnparsableInRef4.hasProblem());
971 list = nameUnparsableInRef4.getParsingProblems();
972 assertTrue("Problem detail", list.contains(ParserProblem.CheckDetailOrYear));
973 assertEquals(strUnparsableInRef4, nameUnparsableInRef4.getFullTitleCache());
974 assertEquals(37, nameUnparsableInRef4.getProblemStarts());
975 assertEquals(55, nameUnparsableInRef4.getProblemEnds());
976
977 String strSameName = "Hieracium pepcum (Hsllreterto) L., My Bokkk 1. 1903";
978 NonViralName<?> nameSameName = nameUnparsableInRef4;
979 parser.parseReferencedName(nameSameName, strSameName, null, true);
980 assertTrue(nameSameName.hasProblem());
981 list = nameSameName.getParsingProblems();
982 assertTrue("Problem detail", list.contains(ParserProblem.CheckDetailOrYear));
983 assertEquals(strSameName, nameSameName.getFullTitleCache());
984 assertEquals(35, nameSameName.getProblemStarts());
985 assertEquals(51, nameSameName.getProblemEnds());
986
987 String strGenusUnparse = "Hieracium L., jlklk";
988 NonViralName<?> nameGenusUnparse =
989 parser.parseReferencedName(strGenusUnparse, null, null);
990 assertTrue(nameGenusUnparse.hasProblem());
991 list = nameGenusUnparse.getParsingProblems();
992 assertTrue("Problem detail", list.contains(ParserProblem.CheckDetailOrYear));
993 assertTrue("Problem uninomial", list.contains(ParserProblem.CheckRank));
994 assertEquals(strGenusUnparse, nameGenusUnparse.getFullTitleCache());
995 assertEquals(0, nameGenusUnparse.getProblemStarts());
996 assertEquals(19, nameGenusUnparse.getProblemEnds());
997
998 String strGenusUnparse2 = "Hieracium L., Per Luigi: 44. 1987";
999 NonViralName<?> nameGenusUnparse2 =
1000 parser.parseReferencedName(strGenusUnparse2, null, Rank.FAMILY());
1001 assertFalse(nameGenusUnparse2.hasProblem());
1002 assertEquals(strGenusUnparse2, nameGenusUnparse2.getFullTitleCache());
1003 assertEquals(-1, nameGenusUnparse2.getProblemStarts());
1004 assertEquals(-1, nameGenusUnparse2.getProblemEnds());
1005
1006 String strBookSection2 = "Hieracium vulgatum subsp. acuminatum (Jord.) Zahn in Schinz & Keller, Fl. Schweiz, ed. 2, 2: 288. 1905-1907";
1007 String strBookSection2NoComma = "Hieracium vulgatum subsp. acuminatum (Jord.) Zahn in Schinz & Keller, Fl. Schweiz ed. 2, 2: 288. 1905-1907";
1008 NonViralName<?> nameBookSection2 =
1009 parser.parseReferencedName(strBookSection2, null, null);
1010 assertFalse(nameBookSection2.hasProblem());
1011 nameBookSection2.setFullTitleCache(null, false);
1012 assertEquals(strBookSection2NoComma.replace(" ed.", ", ed."), nameBookSection2.getFullTitleCache());
1013 assertEquals(-1, nameBookSection2.getProblemStarts());
1014 assertEquals(-1, nameBookSection2.getProblemEnds());
1015 assertNull((nameBookSection2.getNomenclaturalReference()).getDatePublished().getStart());
1016 assertEquals("1905-1907", ((IBookSection)nameBookSection2.getNomenclaturalReference()).getInBook().getDatePublished().getYear());
1017
1018
1019 String strBookSection = "Hieracium vulgatum subsp. acuminatum (Jord.) Zahn in Schinz & Keller, Fl. Schweiz ed. 2, 2: 288. 1905";
1020 NonViralName<?> nameBookSection =
1021 parser.parseReferencedName(strBookSection, null, null);
1022 assertFalse(nameBookSection.hasProblem());
1023 assertEquals(strBookSection.replace(" ed.", ", ed."), nameBookSection.getFullTitleCache());
1024 assertEquals(-1, nameBookSection.getProblemStarts());
1025 assertEquals(-1, nameBookSection.getProblemEnds());
1026 assertNull(((IBookSection)nameBookSection.getNomenclaturalReference()).getInBook().getDatePublished().getStart());
1027 assertEquals("1905", ((IBookSection)nameBookSection.getNomenclaturalReference()).getDatePublished().getYear());
1028
1029 String strXXXs = "Abies alba, Soer der 1987";
1030 NonViralName<?> problemName = parser.parseReferencedName(strXXXs, null, null);
1031 assertTrue(problemName.hasProblem());
1032 list = problemName.getParsingProblems();
1033 assertTrue("Problem must be name-reference separation", list.contains(ParserProblem.NameReferenceSeparation));
1034 parser.parseReferencedName(problemName, strBookSection, null, true);
1035 assertFalse(problemName.hasProblem());
1036
1037 problemName = parser.parseFullName(strXXXs, null, null);
1038 assertTrue(problemName.hasProblem());
1039 list = problemName.getParsingProblems();
1040 assertTrue("Name part must be unparsable", list.contains(ParserProblem.UnparsableNamePart));
1041
1042
1043 String testParsable = "Pithecellobium macrostachyum Benth.";
1044 assertTrue(isParsable(testParsable, ICBN));
1045
1046 testParsable = "Pithecellobium macrostachyum (Benth.)";
1047 assertTrue(isParsable(testParsable, ICBN));
1048
1049 testParsable = "Pithecellobium macrostachyum (Benth., 1845)";
1050 assertTrue(isParsable(testParsable, NomenclaturalCode.ICZN));
1051
1052 testParsable = "Pithecellobium macrostachyum L., Sp. Pl. 3: n\u00B0 123. 1753."; //00B0 is degree character
1053 assertTrue(isParsable(testParsable, ICBN));
1054
1055 testParsable = "Hieracium lachenalii subsp. acuminatum (Jord.) Zahn in Hegi, Ill. Fl. Mitt.-Eur. 6: 1285. 1929";
1056 assertTrue("Reference title should support special characters as separators like - and &", isParsable(testParsable, ICBN));
1057
1058 testParsable = "Hieracium lachenalii subsp. acuminatum (Jord.) Zahn in Hegi, Ill. Fl. Mitt.&Eur. 6: 1285. 1929";
1059 assertTrue("Reference title should support special characters as separators like - and &", isParsable(testParsable, ICBN));
1060
1061 testParsable = "Hieracium lachenalii subsp. acuminatum (Jord.) Zahn in Hegi, Ill. Fl. Mitt.-Eur.& 6: 1285. 1929";
1062 assertFalse("Reference title should not support special characters like - and & at the end of the title", isParsable(testParsable, ICBN));
1063 assertTrue("Problem must be reference title", getProblems(testParsable, ICBN).
1064 contains(ParserProblem.UnparsableReferenceTitle));
1065
1066 testParsable = "Hieracium lachenalii subsp. acuminatum (Jord.) Zahn in Hegi, Ill. Fl. Mitt.:Eur. 6: 1285. 1929";
1067 assertFalse("Reference title should not support detail separator", isParsable(testParsable, ICBN));
1068 assertTrue("Problem must be reference title", getProblems(testParsable, ICBN).
1069 contains(ParserProblem.UnparsableReferenceTitle));
1070
1071 testParsable = "Hieracium lachenalii subsp. acuminatum (Jord.) Zahn in Hegi, Ill. Fl. (Mitt.) 6: 1285. 1929";
1072 assertTrue("Reference title should support brackets", isParsable(testParsable, ICBN));
1073
1074 testParsable = "Hieracium lachenalii subsp. acuminatum (Jord.) Zahn in Hegi, Ill. Fl. (Mitt.) 6: 1285. 1929";
1075 assertTrue("Reference title should support brackets", isParsable(testParsable, ICBN));
1076
1077 testParsable = "Hieracium lachenalii Zahn, nom. illeg.";
1078 assertTrue("Reference should not be obligatory if a nom status exist", isParsable(testParsable, ICBN));
1079
1080 testParsable = "Hieracium lachenalii, nom. illeg.";
1081 assertTrue("Authorship should not be obligatory if followed by nom status", isParsable(testParsable, ICBN));
1082
1083 testParsable = "Hieracium lachenalii, Ill. Fl. (Mitt.) 6: 1285. 1929";
1084 assertFalse("Author is obligatory if followed by reference", isParsable(testParsable, ICBN));
1085 assertTrue("Problem must be name-reference separation", getProblems(testParsable, ICBN).
1086 contains(ParserProblem.NameReferenceSeparation));
1087
1088 testParsable = "Hieracium lachenalii in Hegi, Ill. Fl. (Mitt.) 6: 1285. 1929";
1089 assertFalse("Author is obligatory if followed by reference", isParsable(testParsable, ICBN));
1090 assertTrue("Problem must be name-reference separation", getProblems(testParsable, ICBN).
1091 contains(ParserProblem.NameReferenceSeparation));
1092
1093 testParsable = "Abies alba Mill. var. alba";
1094 assertTrue("Autonym problem", isParsable(testParsable, ICBN));
1095
1096 testParsable = "Scleroblitum abc Ulbr. in Engler & Prantl, Nat. Pflanzenfam., ed. 2, 16c: 495. 1934.";
1097 assertTrue("Volume with subdivision", isParsable(testParsable, ICBN));
1098
1099
1100 testParsable = "Hieracium antarcticum d'Urv. in M\u00E9m. Soc. Linn. Paris 4: 608. 1826";
1101 // testParsable = "Hieracium antarcticum Urv. in M\u00E9m. Soc. Linn. Paris 4: 608. 1826";
1102 assertTrue("Name with apostrophe is not parsable", isParsable(testParsable, ICBN));
1103
1104 testParsable = "Cichorium intybus subsp. glaucum (Hoffmanns. & Link) Tzvelev in Komarov, Fl. SSSR 29: 17. 1964";
1105 assertTrue("Reference containing a word in uppercase is not parsable", isParsable(testParsable, ICBN));
1106
1107
1108 }
1109
1110
1111 /**
1112 * Test author with name parts van, von, de, de la, d', da, del.
1113 * See also http://dev.e-taxonomy.eu/trac/ticket/3373
1114 */
1115 @Test
1116 public final void testComposedAuthorNames(){
1117
1118 //van author (see https://dev.e-taxonomy.eu/trac/ticket/3373)
1119 String testParsable = "Aphelocoma unicolor subsp. griscomi van Rossem, 1928";
1120 assertTrue("Author with 'van' should be parsable", isParsable(testParsable, ICZN));
1121
1122 //von author (see https://dev.e-taxonomy.eu/trac/ticket/3373)
1123 testParsable = "Aphelocoma unicolor subsp. griscomi von Rossem, 1928";
1124 assertTrue("Author with 'von' should be parsable", isParsable(testParsable, ICZN));
1125
1126 //de author (see https://dev.e-taxonomy.eu/trac/ticket/3373)
1127 testParsable = "Aphelocoma unicolor subsp. griscomi de Rossem, 1928";
1128 assertTrue("Author with 'de' should be parsable", isParsable(testParsable, ICZN));
1129
1130 //de la author (see https://dev.e-taxonomy.eu/trac/ticket/3373)
1131 testParsable = "Aphelocoma unicolor subsp. griscomi de la Rossem, 1928";
1132 assertTrue("Author with 'de la' should be parsable", isParsable(testParsable, ICZN));
1133
1134 //d' author (see https://dev.e-taxonomy.eu/trac/ticket/3373)
1135 testParsable = "Aphelocoma unicolor subsp. griscomi d'Rossem, 1928";
1136 assertTrue("Author with \"'d'\" should be parsable", isParsable(testParsable, ICZN));
1137
1138 //da author (see https://dev.e-taxonomy.eu/trac/ticket/3373)
1139 testParsable = "Aphelocoma unicolor subsp. griscomi da Rossem, 1928";
1140 assertTrue("Author with 'da' should be parsable", isParsable(testParsable, ICZN));
1141
1142 //del author (see https://dev.e-taxonomy.eu/trac/ticket/3373)
1143 testParsable = "Aphelocoma unicolor subsp. griscomi del Rossem, 1928";
1144 assertTrue("Author with 'del' should be parsable", isParsable(testParsable, ICZN));
1145
1146 }
1147
1148
1149
1150 /**
1151 * @param testParsable
1152 * @param icbn
1153 * @return
1154 */
1155 private List<ParserProblem> getProblems(String string, NomenclaturalCode code) {
1156 List<ParserProblem> result;
1157 result = parser.parseReferencedName(string, code, null).getParsingProblems();
1158 return result;
1159 }
1160
1161 private boolean isParsable(String string, NomenclaturalCode code){
1162 NonViralName<?> name = parser.parseReferencedName(string, code, null);
1163 return ! name.hasProblem();
1164 }
1165
1166 private void assertFullRefNameStandard(NonViralName<?> name){
1167 assertEquals("Abies", name.getGenusOrUninomial());
1168 assertEquals("alba", name.getSpecificEpithet());
1169 assertEquals("Mill.", name.getAuthorshipCache());
1170 assertEquals("455", name.getNomenclaturalMicroReference());
1171 assertNotNull(name.getNomenclaturalReference());
1172 }
1173
1174 private void assertFullRefStandard(NonViralName<?> name){
1175 assertEquals("Abies", name.getGenusOrUninomial());
1176 assertEquals("alba", name.getSpecificEpithet());
1177 assertEquals("Mill.", name.getAuthorshipCache());
1178 assertEquals("455", name.getNomenclaturalMicroReference());
1179 assertNotNull(name.getNomenclaturalReference());
1180 INomenclaturalReference ref = (INomenclaturalReference)name.getNomenclaturalReference();
1181 assertEquals("1987", ref.getYear());
1182 assertEquals("Sp. Pl.", ref.getTitle());
1183 }
1184
1185
1186 @Test
1187 public void testNeverEndingParsing(){
1188 //some full titles result in never ending parsing process https://dev.e-taxonomy.eu/trac/ticket/1556
1189
1190 String irinaExample = "Milichiidae Sharp, 1899, Insects. Part II. Hymenopteracontinued (Tubulifera and Aculeata), Coleoptera, Strepsiptera, Lepidoptera, Diptera, Aphaniptera, Thysanoptera, Hemiptera, Anoplura 6: 504. 1899";
1191 // irinaExample = "Milichiidae Sharp, 1899, Insects. Part II. Uiuis Iuiui Hymenopteracontinued (Tubulifera and Aculeata), Coleoptera, Strepsiptera, Lepidoptera, Diptera, Aphaniptera, Thysanoptera, Hemiptera, Anoplura 6: 504. 1899";
1192 NonViralName<?> nvn = this.parser.parseReferencedName(irinaExample, NomenclaturalCode.ICZN, null);
1193 int parsingProblem = nvn.getParsingProblem();
1194 Assert.assertEquals("Name should have only rank warning", 1, parsingProblem);
1195 Assert.assertEquals("Titlecache", "Milichiidae Sharp, 1899", nvn.getTitleCache());
1196 Assert.assertEquals("If this line reached everything should be ok", "Milichiidae", nvn.getGenusOrUninomial());
1197
1198 String anotherExample = "Scorzonera hispanica var. brevifolia Boiss. & Balansa in Boissier, Diagn. Pl. Orient., ser. 2 6: 119. 1859.";
1199 nvn = this.parser.parseReferencedName(anotherExample, ICBN, null);
1200 parsingProblem = nvn.getParsingProblem();
1201 Assert.assertEquals("Problem should be 0", 0, parsingProblem);
1202 Assert.assertEquals("Titlecache", "Scorzonera hispanica var. brevifolia Boiss. & Balansa", nvn.getTitleCache());
1203 Assert.assertEquals("If this line reached everything should be ok", "Scorzonera", nvn.getGenusOrUninomial());
1204
1205 String unparsable = "Taraxacum nevskii L., Trudy Bot. Inst. Nauk S.S.S.R., Ser. 1, Fl. Sist. Vyssh. Rast. 4: 293. 1937.";
1206 // String unparsableA = "Taraxacum nevskii L. in Trudy Bot. Inst. Nauk: 293. 1937.";
1207 nvn = this.parser.parseReferencedName(unparsable, ICBN, null);
1208 Assert.assertEquals("Titlecache", "Taraxacum nevskii L.", nvn.getTitleCache());
1209 Assert.assertEquals("If this line reached everything should be ok", "Taraxacum", nvn.getGenusOrUninomial());
1210 parsingProblem = nvn.getParsingProblem();
1211 Assert.assertEquals("Name should no warnings or errors", 0, parsingProblem);
1212
1213 String unparsable2 = "Hieracium pxxx Dahlst., Kongl. Svenska Vetensk. Acad. Handl. ser. 2, 26(3): 255. 1894";
1214 // String unparsable2A = "Hieracium pxxx Dahlst., Kongl Svenska Vetensk Acad Handl, 26: 255. 1894.";
1215 nvn = this.parser.parseReferencedName(unparsable2, ICBN, null);
1216 Assert.assertEquals("Titlecache", "Hieracium pxxx Dahlst.", nvn.getTitleCache());
1217 Assert.assertEquals("If this line reached everything should be ok", "Hieracium", nvn.getGenusOrUninomial());
1218 parsingProblem = nvn.getParsingProblem();
1219 Assert.assertEquals("Name should no warnings or errors", 0, parsingProblem);
1220
1221
1222 String again = "Adiantum emarginatum Bory ex. Willd., Species Plantarum, ed. 4,5,1: 449,450. 1810";
1223 nvn = this.parser.parseReferencedName(again, ICBN, null);
1224 Assert.assertEquals("Titlecache", "Adiantum emarginatum Bory ex Willd.", nvn.getTitleCache());
1225 Assert.assertEquals("If this line reached everything should be ok", "Adiantum", nvn.getGenusOrUninomial());
1226
1227 }
1228
1229 @Test
1230 public final void testSeriesPart(){
1231 Pattern seriesPattern = Pattern.compile(NonViralNameParserImpl.pSeriesPart);
1232 Matcher matcher = seriesPattern.matcher("ser. 2");
1233 Assert.assertTrue("", matcher.matches());
1234 }
1235
1236 /**
1237 * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#fullTeams(java.lang.String)}.
1238 */
1239 @Test
1240 public final void testFullTeams() {
1241 logger.warn("Not yet implemented"); // TODO
1242 }
1243
1244 /**
1245 * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#authorTeamAndEx(java.lang.String)}.
1246 * @throws StringNotParsableException
1247 */
1248 @Test
1249 public final void testParseAuthorsTaxonNameString() throws StringNotParsableException {
1250 NonViralName<?> nvn = ZoologicalName.NewInstance(null);
1251 parser.parseAuthors(nvn, "Eckweiler & ten Hagen, 2003");
1252 Team team = (Team)nvn.getCombinationAuthorTeam();
1253 Assert.assertNotNull("Comb. author must not be null", team);
1254 Assert.assertEquals("Must be team with 2 members", 2, team.getTeamMembers().size());
1255 Assert.assertEquals("Second member must be 'ten Hagen'", "ten Hagen", team.getTeamMembers().get(1).getTitleCache());
1256
1257 //Crosson du Cormier, 1964
1258 ZoologicalName zooName = ZoologicalName.NewInstance(null);
1259 parser.parseAuthors(zooName, "Crosson du Cormier, 1964");
1260 Person person = (Person)zooName.getCombinationAuthorTeam();
1261 Assert.assertNotNull("Comb. author must not be null", person);
1262 Assert.assertEquals("Persons title must be 'Crosson du Cormier'", "Crosson du Cormier", person.getTitleCache());
1263 Assert.assertEquals("Year must be 1964", Integer.valueOf(1964), zooName.getPublicationYear() );
1264
1265 //(van der Hoeven, 1839)
1266 zooName = ZoologicalName.NewInstance(null);
1267 parser.parseAuthors(zooName, "(van der Hoeven, 1839)");
1268 Assert.assertNull("Combination author must be null", zooName.getCombinationAuthorTeam());
1269 person = (Person)zooName.getBasionymAuthorTeam();
1270 Assert.assertNotNull("Basionym author must not be null", person);
1271 Assert.assertEquals("Persons title must be 'van der Hoeven'", "van der Hoeven", person.getTitleCache());
1272 Assert.assertEquals("Year must be 1839", Integer.valueOf(1839), zooName.getOriginalPublicationYear() );
1273
1274 //le Doux, 1931
1275 zooName = ZoologicalName.NewInstance(null);
1276 parser.parseAuthors(zooName, "le Doux, 1931");
1277 person = (Person)zooName.getCombinationAuthorTeam();
1278 Assert.assertNotNull("Comb. author must not be null", person);
1279 Assert.assertEquals("Persons title must be 'le Doux'", "le Doux", person.getTitleCache());
1280 Assert.assertEquals("Year must be 1931", Integer.valueOf(1931), zooName.getPublicationYear() );
1281
1282
1283 }
1284
1285 /**
1286 * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#authorTeamAndEx(java.lang.String)}.
1287 */
1288 @Test
1289 public final void testAuthorTeamAndEx() {
1290 logger.warn("Not yet implemented"); // TODO
1291 }
1292
1293 /**
1294 * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#authorTeam(java.lang.String)}.
1295 */
1296 @Test
1297 public final void testAuthorTeam() {
1298 logger.warn("Not yet implemented"); // TODO
1299 }
1300
1301 /**
1302 * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#parseCultivar(java.lang.String)}.
1303 */
1304 @Test
1305 public final void testParseCultivar() {
1306 logger.warn("Not yet implemented"); // TODO
1307 }
1308
1309 // @Ignore // please add this test once #2750 is fixed
1310 @Test
1311 public final void testNomenclaturalStatus() {
1312 BotanicalName name = BotanicalName.NewInstance(Rank.FAMILY(), "Acanthopale", null, null, null, null, null, null, null);
1313 name.addStatus(NomenclaturalStatus.NewInstance(NomenclaturalStatusType.ALTERNATIVE()));
1314
1315 BotanicalName name2 = BotanicalName.NewInstance(Rank.FAMILY());
1316
1317 parser.parseReferencedName(name2, name.getFullTitleCache(), name2.getRank(), true);
1318
1319 parser.parseReferencedName(name2, name.getFullTitleCache(), name2.getRank(), true);
1320
1321 Assert.assertEquals("Title cache should be same. No duplication of nom. status should take place", name.getFullTitleCache(), name2.getFullTitleCache());
1322
1323
1324 }
1325
1326 }