Project

General

Profile

Download (188 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.strategy.parser;
10

    
11
import static org.junit.Assert.assertEquals;
12
import static org.junit.Assert.assertFalse;
13
import static org.junit.Assert.assertNotNull;
14
import static org.junit.Assert.assertNull;
15
import static org.junit.Assert.assertTrue;
16

    
17
import java.lang.reflect.InvocationTargetException;
18
import java.lang.reflect.Method;
19
import java.util.List;
20
import java.util.regex.Matcher;
21
import java.util.regex.Pattern;
22

    
23
import org.apache.log4j.Logger;
24
import org.joda.time.DateTime;
25
import org.joda.time.Duration;
26
import org.junit.Assert;
27
import org.junit.Before;
28
import org.junit.Ignore;
29
import org.junit.Test;
30

    
31
import eu.etaxonomy.cdm.common.UTF8;
32
import eu.etaxonomy.cdm.model.agent.Person;
33
import eu.etaxonomy.cdm.model.agent.Team;
34
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
35
import eu.etaxonomy.cdm.model.common.TimePeriod;
36
import eu.etaxonomy.cdm.model.name.HybridRelationship;
37
import eu.etaxonomy.cdm.model.name.IBotanicalName;
38
import eu.etaxonomy.cdm.model.name.INonViralName;
39
import eu.etaxonomy.cdm.model.name.IZoologicalName;
40
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
41
import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
42
import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
43
import eu.etaxonomy.cdm.model.name.Rank;
44
import eu.etaxonomy.cdm.model.name.TaxonName;
45
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
46
import eu.etaxonomy.cdm.model.reference.IArticle;
47
import eu.etaxonomy.cdm.model.reference.IBook;
48
import eu.etaxonomy.cdm.model.reference.IBookSection;
49
import eu.etaxonomy.cdm.model.reference.IJournal;
50
import eu.etaxonomy.cdm.model.reference.INomenclaturalReference;
51
import eu.etaxonomy.cdm.model.reference.IVolumeReference;
52
import eu.etaxonomy.cdm.model.reference.Reference;
53
import eu.etaxonomy.cdm.model.reference.ReferenceType;
54
import eu.etaxonomy.cdm.strategy.exceptions.StringNotParsableException;
55
import eu.etaxonomy.cdm.test.TermTestBase;
56

    
57
/**
58
 * Tests for {@link NonViralNameParserImpl}.
59
 *
60
 * @author a.mueller
61
 */
62
public class NonViralNameParserImplTest extends TermTestBase {
63

    
64
    private static final NomenclaturalCode ICNAFP = NomenclaturalCode.ICNAFP;
65
    private static final NomenclaturalCode ICZN = NomenclaturalCode.ICZN;
66

    
67
    private static final String SEP = TimePeriod.SEP;
68

    
69
    private static final Logger logger = Logger.getLogger(NonViralNameParserImplTest.class);
70

    
71
    final private String strNameAbies1 = "Abies alba";
72
    final private String strNameAbiesSub1 = "Abies alba subsp. beta";
73
    final private String strNameAbiesAuthor1 = "Abies alba Mueller";
74
    final private String strNameAbiesAuthor1Unicode = "Abies alba M\u00FCller";
75
    final private String strNameAbiesBasionymAuthor1 = "Abies alba (Ciardelli) D'Mueller";
76
    final private String strNameAbiesBasionymAuthor1Unicode = "Abies alba (Ciardelli) D'M\u00FCller";
77
    final private String strNameAbiesBasionymExAuthor1 ="Abies alba (Ciardelli ex Doering) D'Mueller ex. de Greuther";
78
    final private String strNameAbiesBasionymExAuthor1Unicode ="Abies alba (Ciardelli ex D\u00F6ring) D'M\u00FCller ex. de Greuther";
79
    final private String strNameTeam1 = "Abies alba Mueller & L.";
80
    final private String strNameZoo1 = "Abies alba Mueller & L., 1822";
81
    final private String strNameZoo2 = "Abies alba (Mueller, 1822) Ciardelli, 2002";
82
    final private String strNameZoo3 = "Marmota marmota normalis Ciardelli, 2002";
83
    final private String strNameZoo4 = "Marmota marmota subsp. normalis Ciardelli, 2002";
84
    final private String strNameZoo5 = "Marmota marmota var. normalis Ciardelli, 2002";
85

    
86
    final private String strNameEmpty = "";
87
    final private String strNameNull = null;
88

    
89
    private NonViralNameParserImpl parser ;
90
    private NomenclaturalCode botanicCode;
91

    
92
    @Before
93
    public void setUp() throws Exception {
94
        parser = NonViralNameParserImpl.NewInstance();
95
        botanicCode = ICNAFP;
96
    }
97

    
98
/*************** TEST *********************************************/
99

    
100
    @Test
101
    public final void testNewInstance() {
102
        assertNotNull(parser);
103
    }
104

    
105
    @Test
106
    public final void testTaxonNameParserBotanicalNameImpl() {
107
        logger.warn("Not yet implemented"); // TODO
108
    }
109

    
110
    @Test
111
    public final void testTeamSeperation(){
112
        Rank speciesRank = Rank.SPECIES();
113
        INonViralName name;
114

    
115
//      String strNameWith1AUthorAndCommaSepEditon = "Abies alba Mill., Sp. Pl., ed. 3: 455. 1987";
116
//      name = parser.parseReferencedName(strNameWith1AUthorAndCommaSepEditon, botanicCode, speciesRank);
117
//      Assert.assertFalse("No problems should exist", name.hasProblem());
118
//      Assert.assertEquals("Name should not include reference part", "Abies alba Mill.", name.getTitleCache());
119
//      Assert.assertEquals("Mill., Sp. Pl., ed. 3. 1987", name.getNomenclaturalReference().getTitleCache());
120
//
121
//
122
//      String strNameWith2Authors = "Abies alba L. & Mill., Sp. Pl., ed. 3: 455. 1987";
123
//      name = parser.parseReferencedName(strNameWith2Authors, botanicCode, speciesRank);
124
//      Assert.assertFalse("No problems should exist", name.hasProblem());
125
//      Assert.assertEquals("Name should not include reference part", "Abies alba L. & Mill.", name.getTitleCache());
126
//      Assert.assertEquals("Name should have authorteam with 2 authors", 2, ((Team)name.getCombinationAuthorship()).getTeamMembers().size());
127
//      Assert.assertEquals("L. & Mill., Sp. Pl., ed. 3. 1987", name.getNomenclaturalReference().getTitleCache());
128

    
129
        String strNameWith3Authors = "Abies alba Mess., L. & Mill., Sp. Pl., ed. 3: 455. 1987";
130
        name = parser.parseReferencedName(strNameWith3Authors, botanicCode, speciesRank);
131
        Assert.assertFalse("No problems should exist", name.hasProblem());
132
        Assert.assertEquals("Name should not include reference part", "Abies alba Mess., L. & Mill.", name.getTitleCache());
133
        Assert.assertEquals("Name should have authorship with 2 authors", 3, ((Team)name.getCombinationAuthorship()).getTeamMembers().size());
134
        Assert.assertEquals("Mess., L. & Mill. 1987: Sp. Pl., ed. 3", name.getNomenclaturalReference().getTitleCache());
135
    }
136

    
137
    @Test
138
    public final void testParseSimpleName() {
139

    
140
        //Uninomials
141
        IZoologicalName milichiidae = (IZoologicalName)parser.parseSimpleName("Milichiidae", NomenclaturalCode.ICZN, null);
142
        assertEquals("Family rank expected", Rank.FAMILY(), milichiidae.getRank());
143
        IBotanicalName crepidinae = (IBotanicalName)parser.parseSimpleName("Crepidinae", ICNAFP, null);
144
        assertEquals("Family rank expected", Rank.SUBTRIBE(), crepidinae.getRank());
145
        IBotanicalName abies = (IBotanicalName)parser.parseSimpleName("Abies", ICNAFP, null);
146
        assertEquals("Family rank expected", Rank.GENUS(), abies.getRank());
147

    
148
        abies.addParsingProblem(ParserProblem.CheckRank);
149
        parser.parseSimpleName(abies, "Abies", abies.getRank(), true);
150
        assertTrue(abies.getParsingProblems().contains(ParserProblem.CheckRank));
151

    
152
        IBotanicalName rosa = (IBotanicalName)parser.parseSimpleName("Rosaceae", ICNAFP, null);
153
        assertTrue("Rosaceae have rank family", rosa.getRank().equals(Rank.FAMILY()));
154
        assertTrue("Rosaceae must have a rank warning", rosa.hasProblem(ParserProblem.CheckRank));
155
        parser.parseSimpleName(rosa, "Rosaceaex", abies.getRank(), true);
156
        assertEquals("Rosaceaex have rank genus", Rank.GENUS(), rosa.getRank());
157
        assertTrue("Rosaceaex must have a rank warning", rosa.hasProblem(ParserProblem.CheckRank));
158

    
159
        //repeat but remove warning after first parse
160
        rosa = (IBotanicalName)parser.parseSimpleName("Rosaceae", ICNAFP, null);
161
        assertTrue("Rosaceae have rank family", rosa.getRank().equals(Rank.FAMILY()));
162
        assertTrue("Rosaceae must have a rank warning", rosa.hasProblem(ParserProblem.CheckRank));
163
        rosa.removeParsingProblem(ParserProblem.CheckRank);
164
        parser.parseSimpleName(rosa, "Rosaceaex", rosa.getRank(), true);
165
        assertEquals("Rosaceaex have rank family", Rank.FAMILY(), rosa.getRank());
166
        assertFalse("Rosaceaex must have no rank warning", rosa.hasProblem(ParserProblem.CheckRank));
167
    }
168

    
169
    @Test
170
    public final void testParseSubGenericFullName() {
171
        String zooSpeciesWithSubgenus = "Bacanius (Mullerister) rombophorus (Aube, 1843)";
172
        //zoo as fullName
173
        IZoologicalName zooName = parser.parseReferencedName(zooSpeciesWithSubgenus, NomenclaturalCode.ICZN, Rank.SPECIES());
174
        Assert.assertTrue(zooName.getParsingProblems().isEmpty());
175
        Assert.assertEquals("Mullerister", zooName.getInfraGenericEpithet());
176
        Assert.assertEquals(Integer.valueOf(1843), zooName.getOriginalPublicationYear());
177
        //zoo as referenced name
178
        zooName = (IZoologicalName)parser.parseFullName(zooSpeciesWithSubgenus, NomenclaturalCode.ICZN, Rank.SPECIES());
179
        Assert.assertTrue(zooName.getParsingProblems().isEmpty());
180
        Assert.assertEquals("Mullerister", zooName.getInfraGenericEpithet());
181
        Assert.assertEquals(Integer.valueOf(1843), zooName.getOriginalPublicationYear());
182

    
183
        //bot as full Name
184
        String botSpeciesWithSubgenus = "Bacanius (Mullerister) rombophorus (Aube) Mill.";
185
        IBotanicalName botName = (IBotanicalName)parser.parseFullName(botSpeciesWithSubgenus, NomenclaturalCode.ICNAFP, Rank.GENUS());
186
        Assert.assertTrue(botName.getParsingProblems().isEmpty());
187
        Assert.assertEquals("Mullerister", botName.getInfraGenericEpithet());
188
        Assert.assertEquals("rombophorus", botName.getSpecificEpithet());
189
        Assert.assertEquals("Aube", botName.getBasionymAuthorship().getTitleCache());
190

    
191
        //bot as referenced Name
192
        botName = parser.parseReferencedName(botSpeciesWithSubgenus, NomenclaturalCode.ICNAFP, Rank.GENUS());
193
        Assert.assertTrue(botName.getParsingProblems().isEmpty());
194
        Assert.assertEquals("Mullerister", botName.getInfraGenericEpithet());
195
        Assert.assertEquals("rombophorus", botName.getSpecificEpithet());
196
        Assert.assertEquals("Aube", botName.getBasionymAuthorship().getTitleCache());
197

    
198
        //bot without author
199
        String botSpeciesWithSubgenusWithoutAuthor = "Bacanius (Mullerister) rombophorus";
200
        botName = parser.parseReferencedName(botSpeciesWithSubgenusWithoutAuthor, NomenclaturalCode.ICNAFP, Rank.GENUS());
201
        Assert.assertTrue(botName.getParsingProblems().isEmpty());
202
        Assert.assertEquals("Mullerister", botName.getInfraGenericEpithet());
203
        Assert.assertEquals("rombophorus", botName.getSpecificEpithet());
204
        Assert.assertEquals("", botName.getAuthorshipCache());
205
    }
206

    
207
    @Test
208
    public final void testParseSubGenericSimpleName() {
209
        logger.warn("Not yet implemented"); // TODO
210
    }
211

    
212
    @Test
213
    public final void testParseFullNameUnicode() {
214

    
215
        INonViralName nameAuthor = parser.parseFullName(strNameAbiesAuthor1Unicode, null, Rank.SPECIES());
216
        assertEquals("Abies", nameAuthor.getGenusOrUninomial());
217
        assertEquals("alba", nameAuthor.getSpecificEpithet());
218
        assertEquals("M\u00FCller", nameAuthor.getCombinationAuthorship().getNomenclaturalTitleCache());
219

    
220
        INonViralName nameBasionymAuthor = parser.parseFullName(strNameAbiesBasionymAuthor1Unicode, null, Rank.SPECIES());
221
        assertEquals("Abies", nameBasionymAuthor.getGenusOrUninomial());
222
        assertEquals("alba", nameBasionymAuthor.getSpecificEpithet());
223
        assertEquals("D'M\u00FCller", nameBasionymAuthor.getCombinationAuthorship().getNomenclaturalTitleCache());
224
        TeamOrPersonBase<?> basionymTeam = nameBasionymAuthor.getBasionymAuthorship();
225
        assertEquals("Ciardelli", basionymTeam.getNomenclaturalTitleCache());
226

    
227
        INonViralName nameBasionymExAuthor = parser.parseFullName(strNameAbiesBasionymExAuthor1Unicode, null, Rank.SPECIES());
228
        assertEquals("Abies", nameBasionymExAuthor.getGenusOrUninomial());
229
        assertEquals("alba", nameBasionymExAuthor.getSpecificEpithet());
230
        assertEquals("D'M\u00FCller", nameBasionymExAuthor.getExCombinationAuthorship().getNomenclaturalTitleCache());
231
        assertEquals("de Greuther", nameBasionymExAuthor.getCombinationAuthorship().getNomenclaturalTitleCache());
232
        TeamOrPersonBase<?> basionymTeam2 = nameBasionymExAuthor.getExBasionymAuthorship();
233
        assertEquals("Ciardelli", basionymTeam2.getNomenclaturalTitleCache());
234
        TeamOrPersonBase<?> exBasionymTeam2 = nameBasionymExAuthor.getBasionymAuthorship();
235
        assertEquals("D\u00F6ring", exBasionymTeam2.getNomenclaturalTitleCache());
236

    
237
        IBotanicalName nameBasionymExAuthor2 = (IBotanicalName)parser.parseFullName("Washingtonia filifera (Linden ex Andre) H.Wendl. ex de Bary", null, Rank.SPECIES());
238
        assertEquals("Washingtonia", nameBasionymExAuthor2.getGenusOrUninomial());
239
        assertEquals("filifera", nameBasionymExAuthor2.getSpecificEpithet());
240
        assertEquals("H.Wendl.", nameBasionymExAuthor2.getExCombinationAuthorship().getNomenclaturalTitleCache());
241
        assertEquals("de Bary", nameBasionymExAuthor2.getCombinationAuthorship().getNomenclaturalTitleCache());
242
        TeamOrPersonBase<?> basionymTeam3 = nameBasionymExAuthor2.getBasionymAuthorship();
243
        assertEquals("Andre", basionymTeam3.getNomenclaturalTitleCache());
244
        TeamOrPersonBase<?> exBasionymTeam3 = nameBasionymExAuthor2.getExBasionymAuthorship();
245
        assertEquals("Linden", exBasionymTeam3.getNomenclaturalTitleCache());
246
        String title = nameBasionymExAuthor2.getTitleCache();
247
        assertEquals("Washingtonia filifera (Linden ex Andre) H.Wendl. ex de Bary", title);
248
    }
249

    
250
    @Test
251
    public final void testParseFullName() {
252
        try {
253
            Method parseMethod = parser.getClass().getDeclaredMethod("parseFullName", String.class, NomenclaturalCode.class, Rank.class);
254
            testName_StringNomcodeRank(parseMethod);
255
        } catch (Exception e) {
256
            e.printStackTrace();
257
            assertTrue(false);
258
        }
259

    
260
        //Team
261
        INonViralName nameTeam1 = parser.parseFullName(strNameTeam1);
262
        assertEquals( "Abies", nameTeam1.getGenusOrUninomial());
263
        assertEquals( "alba", nameTeam1.getSpecificEpithet());
264
        assertEquals("Mueller & L.",  nameTeam1.getCombinationAuthorship().getNomenclaturalTitleCache());
265
        assertTrue(nameTeam1.getCombinationAuthorship() instanceof Team);
266
        Team team = (Team)nameTeam1.getCombinationAuthorship();
267
        assertEquals("Mueller", team.getTeamMembers().get(0).getNomenclaturalTitleCache());
268
        assertEquals("L.", team.getTeamMembers().get(1).getNomenclaturalTitleCache());
269

    
270
        //ZooName
271
        IZoologicalName nameZoo1 = (IZoologicalName)parser.parseFullName(strNameZoo1);
272
        assertEquals( "Abies", nameZoo1.getGenusOrUninomial());
273
        assertEquals( "alba", nameZoo1.getSpecificEpithet());
274
        assertEquals("Mueller & L.",  nameZoo1.getCombinationAuthorship().getNomenclaturalTitleCache());
275
        assertEquals(NomenclaturalCode.ICZN, nameZoo1.getNameType() );
276
        assertEquals(Integer.valueOf(1822), nameZoo1.getPublicationYear());
277
        assertTrue(nameZoo1.getCombinationAuthorship() instanceof Team);
278
        Team teamZoo = (Team)nameZoo1.getCombinationAuthorship();
279
        assertEquals("Mueller", teamZoo.getTeamMembers().get(0).getNomenclaturalTitleCache());
280
        assertEquals("L.", teamZoo.getTeamMembers().get(1).getNomenclaturalTitleCache());
281

    
282
        IZoologicalName nameZoo2 = (IZoologicalName)parser.parseFullName(strNameZoo2);
283
        assertEquals(Integer.valueOf(2002), nameZoo2.getPublicationYear());
284
        assertEquals(Integer.valueOf(1822), nameZoo2.getOriginalPublicationYear());
285
        assertEquals("Mueller",  nameZoo2.getBasionymAuthorship().getNomenclaturalTitleCache());
286
        assertEquals("Ciardelli",  nameZoo2.getCombinationAuthorship().getNomenclaturalTitleCache());
287

    
288
        //subsp
289
        IZoologicalName nameZoo3 = (IZoologicalName)parser.parseFullName(strNameZoo3);
290
        assertEquals("Ciardelli",  nameZoo3.getCombinationAuthorship().getNomenclaturalTitleCache());
291
        assertFalse("Subsp. without marker should be parsable", nameZoo3.hasProblem());
292
        assertEquals("Variety should be recognized", Rank.SUBSPECIES(), nameZoo3.getRank());
293

    
294
        IZoologicalName nameZoo4 = (IZoologicalName)parser.parseFullName(strNameZoo4);
295
        assertEquals("Ciardelli",  nameZoo4.getCombinationAuthorship().getNomenclaturalTitleCache());
296
        assertFalse("Subsp. without marker should be parsable", nameZoo4.hasProblem());
297
        assertEquals("Variety should be recognized", Rank.SUBSPECIES(), nameZoo4.getRank());
298

    
299
        IZoologicalName nameZoo5 = (IZoologicalName)parser.parseFullName(strNameZoo5);
300
        assertEquals("Ciardelli",  nameZoo5.getCombinationAuthorship().getNomenclaturalTitleCache());
301
        assertFalse("Subsp. without marker should be parsable", nameZoo5.hasProblem());
302
        assertEquals("Variety should be recognized", Rank.VARIETY(), nameZoo5.getRank());
303

    
304
        //empty
305
        INonViralName nameEmpty = parser.parseFullName(strNameEmpty);
306
        assertNotNull(nameEmpty);
307
        assertEquals("", nameEmpty.getTitleCache());
308

    
309
        //null
310
        INonViralName nameNull = parser.parseFullName(strNameNull);
311
        assertNull(nameNull);
312

    
313
        //some authors
314
        String fullNameString = "Abies alba (Greuther & L'Hiver & al. ex M\u00FCller & Schmidt)Clark ex Ciardelli";
315
        INonViralName authorname = parser.parseFullName(fullNameString);
316
        assertFalse(authorname.hasProblem());
317
        assertEquals("Basionym author should have 3 authors", 2, ((Team)authorname.getExBasionymAuthorship()).getTeamMembers().size());
318
        Assert.assertTrue("ExbasionymAuthorship must have more members'", ((Team)authorname.getExBasionymAuthorship()).isHasMoreMembers());
319

    
320
        //author with 2 capitals
321
        fullNameString = "Campanula rhodensis A. DC.";
322
        INonViralName name = parser.parseFullName(fullNameString);
323
        assertFalse(name.hasProblem());
324

    
325
        //author with no space  #5618
326
        fullNameString = "Gordonia moaensis (Vict.)H. Keng";
327
        name = parser.parseFullName(fullNameString);
328
        assertFalse(name.hasProblem());
329
        assertNotNull(name.getCombinationAuthorship());
330
        assertEquals("H. Keng", name.getCombinationAuthorship().getNomenclaturalTitleCache());
331

    
332
        //name without combination  author  , only to check if above fix for #5618 works correctly
333
        fullNameString = "Gordonia moaensis (Vict.)";
334
        name = parser.parseFullName(fullNameString);
335
        assertFalse(name.hasProblem());
336
        assertNull(name.getCombinationAuthorship());
337
        assertNotNull(name.getBasionymAuthorship());
338
        assertEquals("Vict.", name.getBasionymAuthorship().getNomenclaturalTitleCache());
339

    
340
    }
341

    
342
    @Test
343
    public final void testAutonyms(){
344
        TaxonName autonymName;
345
        //infraspecific
346
        autonymName = (TaxonName)parser.parseFullName("Abies alba Mill. var. alba", ICNAFP, null);
347
        assertFalse("Autonym should be parsable", autonymName.hasProblem());
348
        autonymName = parser.parseReferencedName("Abies alba Mill. var. alba", ICNAFP, null);
349
        assertFalse("Autonym should be parsable", autonymName.hasProblem());
350
        //infrageneric
351
        autonymName = (TaxonName)parser.parseFullName("Abies Mill. sect. Abies", ICNAFP, null);
352
        assertFalse("Genus autonym should be parsable", autonymName.hasProblem());
353
        assertEquals("Rank should be section (bot.)", Rank.SECTION_BOTANY(), autonymName.getRank());
354
        autonymName = parser.parseReferencedName("Achnanthes Bory sect. Achnanthes", ICNAFP, null);
355
        assertFalse("Genus autonym should be parsable", autonymName.hasProblem());
356
        assertEquals("Rank should be section (bot.)", Rank.SECTION_BOTANY(), autonymName.getRank());
357
    }
358

    
359
    @Test
360
    public final void testEtAl() throws StringNotParsableException {
361
        //some authors
362
        String fullNameString = "Abies alba Greuther, Hiver & al.";
363
        INonViralName authorname = parser.parseFullName(fullNameString);
364
        assertFalse(authorname.hasProblem());
365
        assertEquals("Basionym author should have 2 authors", 2, ((Team)authorname.getCombinationAuthorship()).getTeamMembers().size());
366
        assertTrue("Basionym author team should have more authors", ((Team)authorname.getCombinationAuthorship()).isHasMoreMembers()  );
367

    
368
        //et al.
369
        INonViralName nvn = TaxonNameFactory.NewZoologicalInstance(null);
370
        parser.parseAuthors(nvn, "Eckweiler, Hand et al., 2003");
371
        Team team = (Team)nvn.getCombinationAuthorship();
372
        Assert.assertNotNull("Comb. author must not be null", team);
373
        Assert.assertEquals("Must be team with 2 members", 2, team.getTeamMembers().size());
374
        Assert.assertEquals("Second member must be 'Hand'", "Hand", team.getTeamMembers().get(1).getTitleCache());
375
        Assert.assertTrue("Team must have more members'", team.isHasMoreMembers());
376
    }
377

    
378
    @Test
379
    public final void testMultipleAuthors() {
380
        //multiple authors for inReference
381
        String fullTitleString = "Abies alba L. in Mill., Gregor & Behr., Sp. Pl. 173: 384. 1982.";
382
        INonViralName multipleAuthorRefName = parser.parseReferencedName(fullTitleString, NomenclaturalCode.ICNAFP, Rank.SPECIES());
383
        assertFalse(multipleAuthorRefName.hasProblem());
384
        assertTrue("Combination author should be a person", multipleAuthorRefName.getCombinationAuthorship() instanceof Person);
385
        assertEquals("Combination author should be L.", "L.", ((Person)multipleAuthorRefName.getCombinationAuthorship()).getNomenclaturalTitleCache());
386
        Reference nomRef = multipleAuthorRefName.getNomenclaturalReference();
387
        Assert.assertNotNull("nomRef must have inRef", nomRef.getInReference());
388
        Reference inRef = nomRef.getInReference();
389
        String abbrevTitle = inRef.getAbbrevTitle();
390
        assertEquals("InRef title should be Sp. Pl.", "Sp. Pl.", abbrevTitle);
391
        assertTrue(inRef.getAuthorship() instanceof Team);
392
        Team team = (Team)inRef.getAuthorship();
393
        assertEquals(3, team.getTeamMembers().size());
394

    
395
//        multiple authors in Name
396
        fullTitleString = "Abies alba Mill., Aber & Schwedt";
397
        INonViralName multipleAuthorName = parser.parseReferencedName(fullTitleString, NomenclaturalCode.ICNAFP, Rank.SPECIES());
398
        assertFalse(multipleAuthorName.hasProblem());
399
        assertTrue("Combination author should be a team", multipleAuthorName.getCombinationAuthorship() instanceof Team);
400
        team = (Team)multipleAuthorName.getCombinationAuthorship();
401
        assertEquals(3, team.getTeamMembers().size());
402
        assertEquals("Second team member should be Aber", "Aber", team.getTeamMembers().get(1).getTitleCache());
403

    
404
//      multiple authors in Name with reference
405
        fullTitleString = "Abies alba Mill., Aber & Schwedt in L., Sp. Pl. 173: 384. 1982.";
406
        multipleAuthorName = parser.parseReferencedName(fullTitleString, NomenclaturalCode.ICNAFP, Rank.SPECIES());
407
        assertFalse(multipleAuthorName.hasProblem());
408
        assertTrue("Combination author should be a team", multipleAuthorName.getCombinationAuthorship() instanceof Team);
409
        team = (Team)multipleAuthorName.getCombinationAuthorship();
410
        assertEquals(3, team.getTeamMembers().size());
411
        assertEquals("Second team member should be Aber", "Aber", team.getTeamMembers().get(1).getTitleCache());
412
        nomRef = multipleAuthorName.getNomenclaturalReference();
413
        Assert.assertNotNull("nomRef must have inRef", nomRef.getInReference());
414
        inRef = nomRef.getInReference();
415
        abbrevTitle = inRef.getAbbrevTitle();
416
        assertEquals("InRef title should be Sp. Pl.", "Sp. Pl.", abbrevTitle);
417
        assertTrue(inRef.getAuthorship() instanceof Person);
418
        Person person = (Person)inRef.getAuthorship();
419
        assertEquals("Book author should be L.", "L.", person.getNomenclaturalTitleCache());
420

    
421

    
422
        fullTitleString = "Abies alba Mill., Aber & Schwedt, Sp. Pl. 173: 384. 1982.";
423
        multipleAuthorName = parser.parseReferencedName(fullTitleString, NomenclaturalCode.ICNAFP, Rank.SPECIES());
424
        assertFalse(multipleAuthorName.hasProblem());
425
        assertTrue("Combination author should be a team", multipleAuthorName.getCombinationAuthorship() instanceof Team);
426
        team = (Team)multipleAuthorName.getCombinationAuthorship();
427
        assertEquals(3, team.getTeamMembers().size());
428
        assertEquals("Second team member should be Aber", "Aber", team.getTeamMembers().get(1).getTitleCache());
429
        nomRef = multipleAuthorName.getNomenclaturalReference();
430
        Assert.assertNull("nomRef must not have inRef as it is a book itself", nomRef.getInReference());
431
        abbrevTitle = nomRef.getAbbrevTitle();
432
        assertEquals("InRef title should be Sp. Pl.", "Sp. Pl.", abbrevTitle);
433
        assertTrue(nomRef.getAuthorship() instanceof Team);
434
        team = (Team)nomRef.getAuthorship();
435
        assertEquals(3, team.getTeamMembers().size());
436
        assertEquals("Second team member should be Schwedt", "Schwedt", team.getTeamMembers().get(2).getTitleCache());
437

    
438
        //et al.
439
        INonViralName nvn = TaxonNameFactory.NewZoologicalInstance(null);
440
        parser.parseReferencedName (nvn, "Marmota marmota Eckweiler, Hand et al., 2003", Rank.SPECIES(),true);
441
        assertTrue("Combination author should be a team", nvn.getCombinationAuthorship() instanceof Team);
442
        team = (Team)nvn.getCombinationAuthorship();
443
        Assert.assertNotNull("Comb. author must not be null", team);
444
        Assert.assertEquals("Must be team with 2 members", 2, team.getTeamMembers().size());
445
        Assert.assertEquals("Second member must be 'Hand'", "Hand", team.getTeamMembers().get(1).getTitleCache());
446
        Assert.assertTrue("Team must have more members'", team.isHasMoreMembers());
447

    
448
    }
449

    
450
    @Test
451
    public final void testHybrids() {
452
        INonViralName name1;
453

    
454
        //Infrageneric hybrid
455
        name1 = parser.parseFullName("Aegilops nothosubg. Insulae Scholz", botanicCode, null);
456
        assertTrue("Name must have binom hybrid bit set", name1.isBinomHybrid());
457
        assertFalse("Name must not have monom hybrid bit set", name1.isMonomHybrid());
458
        assertFalse("Name must not have trinom hybrid bit set", name1.isTrinomHybrid());
459
        assertEquals("Infrageneric epithet must be 'Insulae'", "Insulae", name1.getInfraGenericEpithet());
460

    
461
        //Species hybrid
462
//      INonViralName nameTeam1 = parser.parseFullName("Aegilops \u00D7insulae-cypri H. Scholz");
463
        name1 = parser.parseFullName("Aegilops \u00D7insulae Scholz", botanicCode, null);
464
        assertTrue("Name must have binom hybrid bit set", name1.isBinomHybrid());
465
        assertFalse("Name must not have monom hybrid bit set", name1.isMonomHybrid());
466
        assertFalse("Name must not have trinom hybrid bit set", name1.isTrinomHybrid());
467
        assertEquals("Species epithet must be 'insulae'", "insulae", name1.getSpecificEpithet());
468

    
469
        name1 = parser.parseFullName("Aegilops \u00D7 insulae Scholz", botanicCode, null);
470
        assertTrue("Name must have binom hybrid bit set", name1.isBinomHybrid());
471
        assertFalse("Name must not have monom hybrid bit set", name1.isMonomHybrid());
472
        assertFalse("Name must not have trinom hybrid bit set", name1.isTrinomHybrid());
473
        assertEquals("Species epithet must be 'insulae'", "insulae", name1.getSpecificEpithet());
474

    
475
        //Uninomial hybrid
476
        name1 = parser.parseFullName("x Aegilops Scholz", botanicCode, null);
477
        assertTrue("Name must have monom hybrid bit set", name1.isMonomHybrid());
478
        assertFalse("Name must not have binom hybrid bit set", name1.isBinomHybrid());
479
        assertFalse("Name must not have trinom hybrid bit set", name1.isTrinomHybrid());
480
        assertEquals("Uninomial must be 'Aegilops'", "Aegilops", name1.getGenusOrUninomial());
481

    
482
        //Subspecies hybrid with hybrid sign
483
        //maybe false: see https://dev.e-taxonomy.eu/redmine/issues/3868
484
        name1 = parser.parseFullName("Aegilops insulae subsp. X abies Scholz", botanicCode, null);
485
        assertFalse("Name must not have monom hybrid bit set", name1.isMonomHybrid());
486
        assertFalse("Name must not have binom hybrid bit set", name1.isBinomHybrid());
487
        assertTrue("Name must have trinom hybrid bit set", name1.isTrinomHybrid());
488
        assertEquals("Infraspecific epithet must be 'abies'", "abies", name1.getInfraSpecificEpithet());
489

    
490
        //Subspecies hybrid with notho / n
491
        name1 = parser.parseFullName("Aegilops insulae nothosubsp. abies Scholz", botanicCode, null);
492
        assertFalse("Name must not have monom hybrid bit set", name1.isMonomHybrid());
493
        assertFalse("Name must not have binom hybrid bit set", name1.isBinomHybrid());
494
        assertFalse("Name must not be protected", name1.isProtectedTitleCache());
495
        assertTrue("Name must have trinom hybrid bit set", name1.isTrinomHybrid());
496
        assertEquals("Infraspecific epithet must be 'abies'", "abies", name1.getInfraSpecificEpithet());
497

    
498
        name1 = parser.parseFullName("Aegilops insulae nsubsp. abies Scholz", botanicCode, null);
499
        assertFalse("Name must not have monom hybrid bit set", name1.isMonomHybrid());
500
        assertFalse("Name must not have binom hybrid bit set", name1.isBinomHybrid());
501
        assertFalse("Name must not be protected", name1.isProtectedTitleCache());
502
        assertTrue("Name must have trinom hybrid bit set", name1.isTrinomHybrid());
503
        assertEquals("Infraspecific epithet must be 'abies'", "abies", name1.getInfraSpecificEpithet());
504

    
505
        //
506
        String nameStr = "Dactylorhiza \u00D7incarnata nothosubsp. versicolor";
507
        name1 = parser.parseFullName(nameStr);
508
        assertFalse("Name must not have monom hybrid bit set", name1.isMonomHybrid());
509
        assertTrue("Name must have binom hybrid bit set", name1.isBinomHybrid());
510
        assertTrue("Name must have trinom hybrid bit set", name1.isTrinomHybrid());
511
        assertFalse("Name must not be protected", name1.isProtectedTitleCache());
512
        assertEquals(nameStr, name1.getTitleCache());  //we expect the cache strategy to create the same result
513

    
514
        nameStr = "Dactylorhiza \u00D7incarnata nothosubsp. versicolor";
515
        name1 = parser.parseFullName(nameStr);
516
        assertFalse("Name must not have monom hybrid bit set", name1.isMonomHybrid());
517
        assertTrue("Name must have binom hybrid bit set", name1.isBinomHybrid());
518
        assertTrue("Name must have trinom hybrid bit set", name1.isTrinomHybrid());
519
        assertFalse("Name must not be protected", name1.isProtectedTitleCache());
520
        assertEquals(nameStr, name1.getTitleCache());  //we expect the cache strategy to create the same result
521

    
522
        //nothovar.
523
        nameStr = "Dactylorhiza incarnata nothovar. versicolor";
524
        name1 = parser.parseFullName(nameStr);
525
        assertFalse("Name must not have monom hybrid bit set", name1.isMonomHybrid());
526
        assertFalse("Name must not have binom hybrid bit set", name1.isBinomHybrid());
527
        assertTrue("Name must have trinom hybrid bit set", name1.isTrinomHybrid());
528
        assertFalse("Name must not be protected", name1.isProtectedTitleCache());
529
        assertEquals(nameStr, name1.getNameCache());  //we expect the cache strategy to create the same result
530

    
531
        //hybrid autonym #6656
532
        nameStr = "Ophrys \u00D7kastelli E. Klein nothosubsp. kastelli";
533
        name1 = parser.parseFullName(nameStr);
534
        assertFalse("Name must not have monom hybrid bit set", name1.isMonomHybrid());
535
        assertTrue("Name must have binom hybrid bit set", name1.isBinomHybrid());
536
        assertTrue("Name must have trinom hybrid bit set", name1.isTrinomHybrid());
537
        assertFalse("Name must not be protected", name1.isProtectedTitleCache());
538
        assertEquals(nameStr, name1.getTitleCache()); //we expect the cache strategy to create the same result
539

    
540
        name1 = parser.parseReferencedName(nameStr);
541
        assertFalse("Name must not have monom hybrid bit set", name1.isMonomHybrid());
542
        assertTrue("Name must have binom hybrid bit set", name1.isBinomHybrid());
543
        assertTrue("Name must have trinom hybrid bit set", name1.isTrinomHybrid());
544
        assertFalse("Name must not be protected", name1.isProtectedTitleCache());
545
        assertEquals(nameStr, name1.getTitleCache()); //we expect the cache strategy to create the same result
546

    
547
        //remove space since #7094
548
        parser.setRemoveSpaceAfterDot(true);
549
        name1 = parser.parseReferencedName(nameStr);
550
        assertEquals(nameStr.replace("E. Kl", "E.Kl"), name1.getTitleCache()); //we expect the cache strategy to create the same result
551
        parser.setRemoveSpaceAfterDot(false);
552
    }
553

    
554
    @Test
555
    public final void testHybridFormulars() {
556
        try {
557
            Method parseMethod = parser.getClass().getDeclaredMethod("parseFullName", String.class, NomenclaturalCode.class, Rank.class);
558
            testName_StringNomcodeRank(parseMethod);
559
        } catch (Exception e) {
560
            e.printStackTrace();
561
            assertTrue(false);
562
        }
563

    
564
        //Species hybrid
565
        String hybridCache = "Abies alba "+UTF8.HYBRID+" Pinus bus";
566
        INonViralName name1 = parser.parseFullName(hybridCache, botanicCode, null);
567
        assertTrue("Name must have hybrid formula bit set", name1.isHybridFormula());
568
        assertEquals("Name must have 2 hybrid parents", 2, name1.getHybridChildRelations().size());
569
        assertEquals("Title cache must be correct", hybridCache, name1.getTitleCache());
570
        List<HybridRelationship> orderedRels = name1.getOrderedChildRelationships();
571
        assertEquals("Name must have 2 hybrid parents in ordered list", 2, orderedRels.size());
572
        TaxonName firstParent = orderedRels.get(0).getParentName();
573
        assertEquals("Name must have Abies alba as first hybrid parent", "Abies alba", firstParent.getTitleCache());
574
        TaxonName secondParent = orderedRels.get(1).getParentName();
575
        assertEquals("Name must have Pinus bus as second hybrid parent", "Pinus bus", secondParent.getTitleCache());
576
        assertEquals("Hybrid name must have the lowest rank ('species') as rank", Rank.SPECIES(), name1.getRank());
577
        assertNull("Name must not have a genus eptithet", name1.getGenusOrUninomial());
578
        assertNull("Name must not have a specific eptithet", name1.getSpecificEpithet());
579
        assertFalse("Name must not have parsing problems", name1.hasProblem());
580

    
581
        name1 = parser.parseReferencedName(hybridCache, botanicCode, null);
582
        assertFalse("Name must not have parsing problems", name1.hasProblem());
583

    
584
        //x-sign
585
        hybridCache = "Abies alba x Pinus bus";
586
        name1 = parser.parseFullName(hybridCache, botanicCode, null);
587
        assertFalse("Name must be parsable", name1.hasProblem());
588
        assertTrue("Name must have hybrid formula bit set", name1.isHybridFormula());
589
        assertFalse("Name must not have parsing problems", name1.hasProblem());
590

    
591
        //Genus //#6030
592
        hybridCache = "Orchis "+UTF8.HYBRID+" Platanthera";
593
        name1 = parser.parseFullName(hybridCache, botanicCode, null);
594
        assertFalse("Name must be parsable", name1.hasProblem());
595
        assertTrue("Name must have hybrid formula bit set", name1.isHybridFormula());
596
        assertFalse("Name must not have parsing problems", name1.hasProblem());
597
        assertEquals("Title cache must be correct", hybridCache, name1.getTitleCache());
598
        orderedRels = name1.getOrderedChildRelationships();
599
        assertEquals("Name must have 2 hybrid parents in ordered list", 2, orderedRels.size());
600
        firstParent = orderedRels.get(0).getParentName();
601
        assertEquals("Name must have Orchis as first hybrid parent", "Orchis", firstParent.getTitleCache());
602
        secondParent = orderedRels.get(1).getParentName();
603
        assertEquals("Name must have Platanthera as second hybrid parent", "Platanthera", secondParent.getTitleCache());
604
        assertEquals("Hybrid name must have genus as rank", Rank.GENUS(), name1.getRank());
605

    
606
        name1 = parser.parseReferencedName(hybridCache, botanicCode, null);
607
        assertFalse("Name must not have parsing problems", name1.hasProblem());
608

    
609
        //Subspecies first hybrid
610
        name1 = parser.parseFullName("Abies alba subsp. beta "+UTF8.HYBRID+" Pinus bus", botanicCode, null);
611
        assertTrue("Name must have hybrid formula bit set", name1.isHybridFormula());
612
        assertEquals("Name must have 2 hybrid parents", 2, name1.getHybridChildRelations().size());
613
        assertEquals("Title cache must be correct", "Abies alba subsp. beta "+UTF8.HYBRID+" Pinus bus", name1.getTitleCache());
614
        orderedRels = name1.getOrderedChildRelationships();
615
        assertEquals("Name must have 2 hybrid parents in ordered list", 2, orderedRels.size());
616
        firstParent = orderedRels.get(0).getParentName();
617
        assertEquals("Name must have Abies alba subsp. beta as first hybrid parent", "Abies alba subsp. beta", firstParent.getTitleCache());
618
        secondParent = orderedRels.get(1).getParentName();
619
        assertEquals("Name must have Pinus bus as second hybrid parent", "Pinus bus", secondParent.getTitleCache());
620
        assertEquals("Hybrid name must have the lower rank ('subspecies') as rank", Rank.SUBSPECIES(), name1.getRank());
621

    
622
        //variety second hybrid
623
        name1 = parser.parseFullName("Abies alba \u00D7 Pinus bus  var. beta", botanicCode, null);
624
        assertTrue("Name must have hybrid formula bit set", name1.isHybridFormula());
625
        assertEquals("Name must have 2 hybrid parents", 2, name1.getHybridChildRelations().size());
626
        assertEquals("Title cache must be correct", "Abies alba \u00D7 Pinus bus var. beta", name1.getTitleCache());
627
        assertEquals("Hybrid name must have the lower rank ('variety') as rank", Rank.VARIETY(), name1.getRank());
628

    
629
        //hybrids with authors  //happens but questionable
630
        name1 = parser.parseFullName("Abies alba L. \u00D7 Pinus bus Mill.", botanicCode, null);
631
        assertTrue("Name must have hybrid formula bit set", name1.isHybridFormula());
632
        assertEquals("Name must have 2 hybrid parents", 2, name1.getHybridChildRelations().size());
633
        assertEquals("Title cache must be correct", "Abies alba L. \u00D7 Pinus bus Mill.", name1.getTitleCache());
634
        orderedRels = name1.getOrderedChildRelationships();
635
        assertEquals("Name must have 2 hybrid parents in ordered list", 2, orderedRels.size());
636
        firstParent = orderedRels.get(0).getParentName();
637
        assertEquals("Name must have Abies alba L. as first hybrid parent", "Abies alba L.", firstParent.getTitleCache());
638
        secondParent = orderedRels.get(1).getParentName();
639
        assertEquals("Name must have Pinus bus Mill. as second hybrid parent", "Pinus bus Mill.", secondParent.getTitleCache());
640
        assertEquals("Hybrid name must have the lower rank ('species') as rank", Rank.SPECIES(), name1.getRank());
641

    
642
        //abbreviated genus hybrid formula #6410 / #5983
643
        String nameStr = "Nepenthes mirabilis \u00D7 N. alata";
644
        name1 = parser.parseFullName(nameStr, botanicCode, null);
645
        assertTrue("Name must have hybrid formula bit set", name1.isHybridFormula());
646
        assertEquals("Name must have 2 hybrid parents", 2, name1.getHybridChildRelations().size());
647
        //could also be N. or no genus at all, depends on formatter
648
        assertEquals("Title cache must be correct", "Nepenthes mirabilis \u00D7 Nepenthes alata", name1.getTitleCache());
649
        orderedRels = name1.getOrderedChildRelationships();
650
        assertEquals("Name must have 2 hybrid parents in ordered list", 2, orderedRels.size());
651
        firstParent = orderedRels.get(0).getParentName();
652
        //to be discussed as usually they should be ordered alphabetically
653
        assertEquals("Name must have Nepenthes mirabilis as first hybrid parent", "Nepenthes mirabilis", firstParent.getTitleCache());
654
        secondParent = orderedRels.get(1).getParentName();
655
        assertEquals("Name must have Nepenthes alata as second hybrid parent", "Nepenthes alata", secondParent.getTitleCache());
656
        assertEquals("Hybrid name must have the lower rank ('species') as rank", Rank.SPECIES(), name1.getRank());
657

    
658
        //missing genus hybrid formula #5983
659
        nameStr = "Nepenthes mirabilis \u00D7 alata";
660
        name1 = parser.parseFullName(nameStr, botanicCode, null);
661
        assertTrue("Name must have hybrid formula bit set", name1.isHybridFormula());
662
        assertEquals("Name must have 2 hybrid parents", 2, name1.getHybridChildRelations().size());
663
        //could also be N. or no genus at all, depends on formatter
664
        assertEquals("Title cache must be correct", "Nepenthes mirabilis \u00D7 Nepenthes alata", name1.getTitleCache());
665
        orderedRels = name1.getOrderedChildRelationships();
666
        assertEquals("Name must have 2 hybrid parents in ordered list", 2, orderedRels.size());
667
        firstParent = orderedRels.get(0).getParentName();
668
        //to be discussed as usually they should be ordered alphabetically
669
        assertEquals("Name must have Nepenthes mirabilis as first hybrid parent", "Nepenthes mirabilis", firstParent.getTitleCache());
670
        secondParent = orderedRels.get(1).getParentName();
671
        assertEquals("Name must have Nepenthes alata as second hybrid parent", "Nepenthes alata", secondParent.getTitleCache());
672
        assertEquals("Hybrid name must have the lower rank ('species') as rank", Rank.SPECIES(), name1.getRank());
673

    
674
        //#5983 subsp. with species and missing genus
675
        nameStr = "Orchis coriophora subsp. fragrans \u00D7 sancta";
676
        name1 = parser.parseFullName(nameStr, botanicCode, null);
677
        assertTrue("Name must have hybrid formula bit set", name1.isHybridFormula());
678
        assertEquals("Name must have 2 hybrid parents", 2, name1.getHybridChildRelations().size());
679
        //could also be N. or no genus at all, depends on formatter
680
        assertEquals("Title cache must be correct", "Orchis coriophora subsp. fragrans \u00D7 Orchis sancta", name1.getTitleCache());
681
        orderedRels = name1.getOrderedChildRelationships();
682
        assertEquals("Name must have 2 hybrid parents in ordered list", 2, orderedRels.size());
683
        firstParent = orderedRels.get(0).getParentName();
684
        assertEquals("Name must have Orchis coriophora subsp. fragrans as first hybrid parent", "Orchis coriophora subsp. fragrans", firstParent.getTitleCache());
685
        secondParent = orderedRels.get(1).getParentName();
686
        assertEquals("Name must have Orchis sancta as second hybrid parent", "Orchis sancta", secondParent.getTitleCache());
687
        assertEquals("Hybrid name must have the lower rank ('subspecies') as rank", Rank.SUBSPECIES(), name1.getRank());
688

    
689
        //2 subspecies with missing genus part #5983
690
        nameStr = "Orchis morio subsp. syriaca \u00D7 papilionacea subsp. schirvanica";
691
        name1 = parser.parseFullName(nameStr, botanicCode, null);
692
        assertTrue("Name must have hybrid formula bit set", name1.isHybridFormula());
693
        assertEquals("Name must have 2 hybrid parents", 2, name1.getHybridChildRelations().size());
694
        //could also be N. or no genus at all, depends on formatter
695
        assertEquals("Title cache must be correct", "Orchis morio subsp. syriaca \u00D7 Orchis papilionacea subsp. schirvanica", name1.getTitleCache());
696
        orderedRels = name1.getOrderedChildRelationships();
697
        assertEquals("Name must have 2 hybrid parents in ordered list", 2, orderedRels.size());
698
        firstParent = orderedRels.get(0).getParentName();
699
        assertEquals("Name must have Orchis morio subsp. syriaca as first hybrid parent", "Orchis morio subsp. syriaca", firstParent.getTitleCache());
700
        secondParent = orderedRels.get(1).getParentName();
701
        assertEquals("Name must have Orchis papilionacea subsp. schirvanica as second hybrid parent", "Orchis papilionacea subsp. schirvanica", secondParent.getTitleCache());
702
        assertEquals("Hybrid name must have the lower rank ('subspecies') as rank", Rank.SUBSPECIES(), name1.getRank());
703

    
704
        //subspecies and variety with missing genus part
705
        nameStr = "Orchis morio subsp. syriaca \u00D7 papilionacea var. schirvanica";
706
        name1 = parser.parseFullName(nameStr, botanicCode, null);
707
        assertTrue("Name must have hybrid formula bit set", name1.isHybridFormula());
708
        assertEquals("Name must have 2 hybrid parents", 2, name1.getHybridChildRelations().size());
709
        //could also be N. or no genus at all, depends on formatter
710
        assertEquals("Title cache must be correct", "Orchis morio subsp. syriaca \u00D7 Orchis papilionacea var. schirvanica", name1.getTitleCache());
711
        orderedRels = name1.getOrderedChildRelationships();
712
        assertEquals("Name must have 2 hybrid parents in ordered list", 2, orderedRels.size());
713
        firstParent = orderedRels.get(0).getParentName();
714
        assertEquals("Name must have Orchis morio subsp. syriaca as first hybrid parent", "Orchis morio subsp. syriaca", firstParent.getTitleCache());
715
        secondParent = orderedRels.get(1).getParentName();
716
        assertEquals("Name must have Orchis papilionacea var. schirvanica as second hybrid parent", "Orchis papilionacea var. schirvanica", secondParent.getTitleCache());
717
        assertEquals("Hybrid name must have the lower rank ('variety') as rank", Rank.VARIETY(), name1.getRank());
718

    
719
        //subspecies and variety with genus part
720
        nameStr = "Orchis morio subsp. syriaca \u00D7 Test papilionacea var. schirvanica";
721
        name1 = parser.parseFullName(nameStr, botanicCode, null);
722
        assertTrue("Name must have hybrid formula bit set", name1.isHybridFormula());
723
        assertEquals("Name must have 2 hybrid parents", 2, name1.getHybridChildRelations().size());
724
        //could also be N. or no genus at all, depends on formatter
725
        assertEquals("Title cache must be correct", "Orchis morio subsp. syriaca \u00D7 Test papilionacea var. schirvanica", name1.getTitleCache());
726
        orderedRels = name1.getOrderedChildRelationships();
727
        assertEquals("Name must have 2 hybrid parents in ordered list", 2, orderedRels.size());
728
        firstParent = orderedRels.get(0).getParentName();
729
        assertEquals("Name must have Orchis morio subsp. syriaca as first hybrid parent", "Orchis morio subsp. syriaca", firstParent.getTitleCache());
730
        secondParent = orderedRels.get(1).getParentName();
731
        assertEquals("Name must have Orchis papilionacea var. schirvanica as second hybrid parent", "Test papilionacea var. schirvanica", secondParent.getTitleCache());
732
        assertEquals("Hybrid name must have the lower rank ('variety') as rank", Rank.VARIETY(), name1.getRank());
733

    
734
        //2 subspecies with missing genus and species part #5983
735
        nameStr = "Orchis morio subsp. syriaca \u00D7 subsp. schirvanica";
736
        name1 = parser.parseFullName(nameStr, botanicCode, null);
737
        assertTrue("Name must have hybrid formula bit set", name1.isHybridFormula());
738
        assertEquals("Name must have 2 hybrid parents", 2, name1.getHybridChildRelations().size());
739
        //could also be N. or no genus at all, depends on formatter
740
        assertEquals("Title cache must be correct", "Orchis morio subsp. syriaca \u00D7 Orchis morio subsp. schirvanica", name1.getTitleCache());
741
        orderedRels = name1.getOrderedChildRelationships();
742
        assertEquals("Name must have 2 hybrid parents in ordered list", 2, orderedRels.size());
743
        firstParent = orderedRels.get(0).getParentName();
744
        assertEquals("Name must have Orchis morio subsp. syriaca as first hybrid parent", "Orchis morio subsp. syriaca", firstParent.getTitleCache());
745
        secondParent = orderedRels.get(1).getParentName();
746
        assertEquals("Name must have Orchis morio subsp. schirvanica as second hybrid parent", "Orchis morio subsp. schirvanica", secondParent.getTitleCache());
747
        assertEquals("Hybrid name must have the lower rank ('subspecies') as rank", Rank.SUBSPECIES(), name1.getRank());
748

    
749
        //subspecies and variety with missing genus and species part #5983
750
        nameStr = "Orchis morio subsp. syriaca \u00D7 var. schirvanica";
751
        name1 = parser.parseFullName(nameStr, botanicCode, null);
752
        assertTrue("Name must have hybrid formula bit set", name1.isHybridFormula());
753
        assertEquals("Name must have 2 hybrid parents", 2, name1.getHybridChildRelations().size());
754
        //could also be N. or no genus at all, depends on formatter
755
        assertEquals("Title cache must be correct", "Orchis morio subsp. syriaca \u00D7 Orchis morio var. schirvanica", name1.getTitleCache());
756
        orderedRels = name1.getOrderedChildRelationships();
757
        assertEquals("Name must have 2 hybrid parents in ordered list", 2, orderedRels.size());
758
        firstParent = orderedRels.get(0).getParentName();
759
        assertEquals("Name must have Orchis morio subsp. syriaca as first hybrid parent", "Orchis morio subsp. syriaca", firstParent.getTitleCache());
760
        secondParent = orderedRels.get(1).getParentName();
761
        assertEquals("Name must have Orchis morio subsp. schirvanica as second hybrid parent", "Orchis morio var. schirvanica", secondParent.getTitleCache());
762
        assertEquals("Hybrid name must have the lower rank ('variety') as rank", Rank.VARIETY(), name1.getRank());
763
    }
764

    
765
    @Test
766
    public final void testUninomials() {
767
        String uninomial = "Anserineae";  //this, in reality is a tribe but the parser should recognize a suborder as the suborder ending -ineae is more specific then the tribe ending -eae
768
        INonViralName name = parser.parseFullName(uninomial, botanicCode, null);
769
        assertEquals(Rank.SUBORDER(), name.getRank());
770
    }
771

    
772
    @Test
773
    public final void testUnrankedNames() {
774
        try {
775
            Method parseMethod = parser.getClass().getDeclaredMethod("parseFullName", String.class, NomenclaturalCode.class, Rank.class);
776
            testName_StringNomcodeRank(parseMethod);
777
        } catch (Exception e) {
778
            e.printStackTrace();
779
            assertTrue(false);
780
        }
781

    
782
        //unranked infraspecific
783
        String infraspecificUnranked = "Genus species [unranked] infraspecific";
784
        INonViralName name = parser.parseFullName(infraspecificUnranked);
785
        assertEquals( "Genus", name.getGenusOrUninomial());
786
        assertEquals( "species", name.getSpecificEpithet());
787
        assertEquals( "infraspecific", name.getInfraSpecificEpithet());
788
        assertEquals( "Unranked rank should be parsed", Rank.INFRASPECIFICTAXON(), name.getRank());
789

    
790
        //'ranglos' infraspecific
791
        infraspecificUnranked = "Genus species [ranglos] infraspecific";
792
        name = parser.parseFullName(infraspecificUnranked);
793
        assertEquals( "Genus", name.getGenusOrUninomial());
794
        assertEquals( "species", name.getSpecificEpithet());
795
        assertEquals( "infraspecific", name.getInfraSpecificEpithet());
796
        assertEquals( "Unranked rank should be parsed", Rank.INFRASPECIFICTAXON(), name.getRank());
797

    
798
        //unranked infrageneric
799
        String infraGenericUnranked = "Genus [unranked] Infragen";
800
        INonViralName name2 = parser.parseFullName(infraGenericUnranked);
801
        assertEquals( "Genus", name2.getGenusOrUninomial());
802
        assertEquals( null, name2.getSpecificEpithet());
803
        assertEquals( "Infragen", name2.getInfraGenericEpithet());
804
        assertEquals( "Unranked rank should be parsed", Rank.INFRAGENERICTAXON(), name2.getRank());
805

    
806
        //unranked infrageneric
807
        infraGenericUnranked = "Genus [ranglos] Infragen";
808
         name2 = parser.parseFullName(infraGenericUnranked);
809
        assertEquals( "Genus", name2.getGenusOrUninomial());
810
        assertEquals( null, name2.getSpecificEpithet());
811
        assertEquals( "Infragen", name2.getInfraGenericEpithet());
812
        assertEquals( "Ranglos rank should be parsed", Rank.INFRAGENERICTAXON(), name2.getRank());
813

    
814
    }
815

    
816
    @Test
817
    public final void testOldRanks() {
818
        try {
819
            Method parseMethod = parser.getClass().getDeclaredMethod("parseFullName", String.class, NomenclaturalCode.class, Rank.class);
820
            testName_StringNomcodeRank(parseMethod);
821
        } catch (Exception e) {
822
            e.printStackTrace();
823
            assertTrue(false);
824
        }
825

    
826
        //proles
827
        String infraspecificUnranked = "Genus species proles infraspecific";
828
        INonViralName name = parser.parseFullName(infraspecificUnranked);
829
        assertEquals( "Genus", name.getGenusOrUninomial());
830
        assertEquals( "species", name.getSpecificEpithet());
831
        assertEquals( "infraspecific", name.getInfraSpecificEpithet());
832
        assertEquals( "Proles should be parsed", Rank.PROLES(), name.getRank());
833

    
834
        //sublusus
835
        infraspecificUnranked = "Genus species sublusus infraspecific";
836
        name = parser.parseFullName(infraspecificUnranked);
837
        assertEquals( "Genus", name.getGenusOrUninomial());
838
        assertEquals( "species", name.getSpecificEpithet());
839
        assertEquals( "infraspecific", name.getInfraSpecificEpithet());
840
        assertEquals( "Sublusus should be parsed", Rank.SUBLUSUS(), name.getRank());
841

    
842
        //race
843
        infraspecificUnranked = "Genus species race infraspecific";
844
        name = parser.parseFullName(infraspecificUnranked);
845
        assertEquals( "Genus", name.getGenusOrUninomial());
846
        assertEquals( "species", name.getSpecificEpithet());
847
        assertEquals( "infraspecific", name.getInfraSpecificEpithet());
848
        assertEquals( "Race should be parsed", Rank.RACE(), name.getRank());
849
    }
850

    
851
    @Test
852
    public final void testTemp(){
853

    
854
//        String nameStr = "Mentha aquatica L. x Mentha spicata L.";
855
//        INonViralName name = parser.parseFullName(nameStr, botanicCode, null);
856
//        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
857
//        assertFalse( name.getHybridChildRelations().isEmpty());
858
//        for (HybridRelationship rel : name.getHybridChildRelations()){
859
//            TaxonName parent = rel.getParentName();
860
//            System.out.println(parent.getTitleCache());
861
//        }
862
    }
863

    
864
    @Test
865
    public final void testHybridsRemoval(){
866
        //if the parser input already has hybridrelationships they need to be removed
867
        //Create input
868
        String hybridCache = "Abies alba "+UTF8.HYBRID+" Pinus bus";
869
        INonViralName name1 = parser.parseFullName(hybridCache, botanicCode, null);
870
        assertFalse("Name must not have parsing problems", name1.hasProblem());
871
        assertTrue("", name1.getHybridChildRelations().size() == 2);
872

    
873
        hybridCache = "Abieta albana "+UTF8.HYBRID+" Pinuta custa";
874
        boolean makeEmpty = true;
875
        parser.parseFullName(name1, hybridCache, Rank.SPECIES(), makeEmpty);
876
        assertEquals("After parsing another string there should still be 2 parents, but different ones", 2, name1.getHybridChildRelations().size());
877
        assertFalse("Name must not have parsing problems", name1.hasProblem());
878

    
879

    
880
        hybridCache = "Calendula arvensis Mill.";
881
        makeEmpty = true;
882
        parser.parseFullName(name1, hybridCache, Rank.SPECIES(), makeEmpty);
883
        assertTrue("", name1.getHybridChildRelations().isEmpty());
884
        assertFalse("Name must not have parsing problems", name1.hasProblem());
885

    
886

    
887
        //AND the same for reference parsing
888
        hybridCache = "Abies alba "+UTF8.HYBRID+" Pinus bus";
889
        name1 = parser.parseReferencedName(hybridCache, botanicCode, null);
890
        assertFalse("Name must not have parsing problems", name1.hasProblem());
891
        assertTrue("", name1.getHybridChildRelations().size() == 2);
892

    
893
        hybridCache = "Abieta albana "+UTF8.HYBRID+" Pinuta custa";
894
        makeEmpty = true;
895
        parser.parseReferencedName(name1, hybridCache, Rank.SPECIES(), makeEmpty);
896
        assertEquals("After parsing another string there should still be 2 parents, but different ones", 2, name1.getHybridChildRelations().size());
897
        assertFalse("Name must not have parsing problems", name1.hasProblem());
898

    
899
        hybridCache = "Calendula arvensis Mill.";
900
        makeEmpty = true;
901
        parser.parseReferencedName(name1, hybridCache, Rank.SPECIES(), makeEmpty);
902
        assertTrue("", name1.getHybridChildRelations().isEmpty());
903
        assertFalse("Name must not have parsing problems", name1.hasProblem());
904
    }
905

    
906
    private void testName_StringNomcodeRank(Method parseMethod)
907
            throws InvocationTargetException, IllegalAccessException  {
908
        INonViralName name1 = (INonViralName)parseMethod.invoke(parser, strNameAbies1, null, Rank.SPECIES());
909
        //parser.parseFullName(strNameAbies1, null, Rank.SPECIES());
910
        assertEquals("Abies", name1.getGenusOrUninomial());
911
        assertEquals("alba", name1.getSpecificEpithet());
912

    
913
        INonViralName nameAuthor = (INonViralName)parseMethod.invoke(parser, strNameAbiesAuthor1, null, Rank.SPECIES());
914
        assertEquals("Abies", nameAuthor.getGenusOrUninomial());
915
        assertEquals("alba", nameAuthor.getSpecificEpithet());
916
        assertEquals("Mueller", nameAuthor.getCombinationAuthorship().getNomenclaturalTitleCache());
917

    
918
        INonViralName nameBasionymAuthor = (INonViralName)parseMethod.invoke(parser, strNameAbiesBasionymAuthor1, null, Rank.SPECIES());
919
        assertEquals("Abies", nameBasionymAuthor.getGenusOrUninomial());
920
        assertEquals("alba", nameBasionymAuthor.getSpecificEpithet());
921
        assertEquals("D'Mueller", nameBasionymAuthor.getCombinationAuthorship().getNomenclaturalTitleCache());
922
        assertEquals("Ciardelli", nameBasionymAuthor.getBasionymAuthorship().getNomenclaturalTitleCache());
923

    
924
        INonViralName nameBasionymExAuthor = (INonViralName)parseMethod.invoke(parser, strNameAbiesBasionymExAuthor1, null, Rank.SPECIES());
925
        assertEquals("Abies", nameBasionymExAuthor.getGenusOrUninomial());
926
        assertEquals("alba", nameBasionymExAuthor.getSpecificEpithet());
927
        assertEquals("D'Mueller", nameBasionymExAuthor.getExCombinationAuthorship().getNomenclaturalTitleCache());
928
        assertEquals("de Greuther", nameBasionymExAuthor.getCombinationAuthorship().getNomenclaturalTitleCache());
929
        assertEquals("Ciardelli", nameBasionymExAuthor.getExBasionymAuthorship().getNomenclaturalTitleCache());
930
        assertEquals("Doering", nameBasionymExAuthor.getBasionymAuthorship().getNomenclaturalTitleCache());
931

    
932
        INonViralName name2 = (INonViralName)parseMethod.invoke(parser, strNameAbiesSub1, null, Rank.SPECIES());
933
        assertEquals("Abies", name2.getGenusOrUninomial());
934
        assertEquals("alba", name2.getSpecificEpithet());
935
        assertEquals("beta", name2.getInfraSpecificEpithet());
936
        assertEquals(Rank.SUBSPECIES(), name2.getRank());
937

    
938

    
939
        // unparseable *********
940
        String problemString = "sdfjlös wer eer wer";
941
        INonViralName nameProblem = (INonViralName)parseMethod.invoke(parser, problemString, null, Rank.SPECIES());
942
        List<ParserProblem> list = nameProblem.getParsingProblems();
943
        assertTrue(nameProblem.getParsingProblem()!=0);
944
        assertEquals(problemString, nameProblem.getTitleCache());
945
    }
946

    
947

    
948
    /**
949
     * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#parseReferencedName(NonViralName, java.lang.String, eu.etaxonomy.cdm.model.name.Rank, boolean)(, )}.
950
     */
951
    @Test
952
    public final void testParseNomStatus() {
953
        //nom. ambig.
954
        String strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. ambig.";
955
        INonViralName nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
956
        assertFullRefStandard(nameTestStatus);
957
        assertTrue(nameTestStatus.getStatus().size()== 1);
958
        assertEquals( NomenclaturalStatusType.AMBIGUOUS(), nameTestStatus.getStatus().iterator().next().getType());
959

    
960
        //nom. inval.
961
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. inval.";
962
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
963
        assertFullRefStandard(nameTestStatus);
964
        assertTrue(nameTestStatus.getStatus().size()== 1);
965
        assertEquals( NomenclaturalStatusType.INVALID(), nameTestStatus.getStatus().iterator().next().getType());
966

    
967
        //nom. dub.
968
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. dub.";
969
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
970
        assertFullRefStandard(nameTestStatus);
971
        assertTrue(nameTestStatus.getStatus().size()== 1);
972
        assertEquals( NomenclaturalStatusType.DOUBTFUL(), nameTestStatus.getStatus().iterator().next().getType());
973

    
974
        //nom. confus.
975
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. confus.";
976
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
977
        assertFullRefStandard(nameTestStatus);
978
        assertTrue(nameTestStatus.getStatus().size()== 1);
979
        assertEquals( NomenclaturalStatusType.CONFUSUM(), nameTestStatus.getStatus().iterator().next().getType());
980

    
981
        //nom. illeg.
982
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. illeg.";
983
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
984
        assertFullRefStandard(nameTestStatus);
985
        assertTrue(nameTestStatus.getStatus().size()== 1);
986
        assertEquals( NomenclaturalStatusType.ILLEGITIMATE(), nameTestStatus.getStatus().iterator().next().getType());
987

    
988
        //nom. superfl.
989
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. superfl.";
990
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
991
        assertFullRefStandard(nameTestStatus);
992
        assertTrue(nameTestStatus.getStatus().size()== 1);
993
        assertEquals( NomenclaturalStatusType.SUPERFLUOUS(), nameTestStatus.getStatus().iterator().next().getType());
994

    
995
        //nom. rej.
996
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. rej.";
997
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
998
        assertFullRefStandard(nameTestStatus);
999
        assertTrue(nameTestStatus.getStatus().size()== 1);
1000
        assertEquals( NomenclaturalStatusType.REJECTED(), nameTestStatus.getStatus().iterator().next().getType());
1001

    
1002
        //nom. utique rej.
1003
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. utique rej.";
1004
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
1005
        assertFullRefStandard(nameTestStatus);
1006
        assertTrue(nameTestStatus.getStatus().size()== 1);
1007
        assertEquals( NomenclaturalStatusType.UTIQUE_REJECTED(), nameTestStatus.getStatus().iterator().next().getType());
1008

    
1009
        //nom. cons. prop.
1010
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. cons. prop.";
1011
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
1012
        assertFullRefStandard(nameTestStatus);
1013
        assertTrue(nameTestStatus.getStatus().size()== 1);
1014
        assertEquals( NomenclaturalStatusType.CONSERVED_PROP(), nameTestStatus.getStatus().iterator().next().getType());
1015

    
1016
        //nom. orth. cons. prop.
1017
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, orth. cons. prop.";
1018
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
1019
        assertFullRefStandard(nameTestStatus);
1020
        assertTrue(nameTestStatus.getStatus().size()== 1);
1021
        assertEquals( NomenclaturalStatusType.ORTHOGRAPHY_CONSERVED_PROP(), nameTestStatus.getStatus().iterator().next().getType());
1022

    
1023
        //nom. cons. prop.
1024
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. cons. des.";
1025
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
1026
        assertFullRefStandard(nameTestStatus);
1027
        assertTrue(nameTestStatus.getStatus().size()== 1);
1028
        assertEquals( NomenclaturalStatusType.CONSERVED_DESIG(), nameTestStatus.getStatus().iterator().next().getType());
1029

    
1030
        //nom. legit.
1031
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. legit.";
1032
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
1033
        assertFullRefStandard(nameTestStatus);
1034
        assertTrue(nameTestStatus.getStatus().size()== 1);
1035
        assertEquals( NomenclaturalStatusType.LEGITIMATE(), nameTestStatus.getStatus().iterator().next().getType());
1036

    
1037
        //nom. altern.
1038
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. altern.";
1039
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
1040
        assertFullRefStandard(nameTestStatus);
1041
        assertTrue(nameTestStatus.getStatus().size()== 1);
1042
        assertEquals( NomenclaturalStatusType.ALTERNATIVE(), nameTestStatus.getStatus().iterator().next().getType());
1043

    
1044
        //nom. alternativ.
1045
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. alternativ.";
1046
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
1047
        assertFullRefStandard(nameTestStatus);
1048
        assertTrue(nameTestStatus.getStatus().size()== 1);
1049
        assertEquals( NomenclaturalStatusType.ALTERNATIVE(), nameTestStatus.getStatus().iterator().next().getType());
1050

    
1051
        //nom. nov.
1052
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. nov.";
1053
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
1054
        assertFullRefStandard(nameTestStatus);
1055
        assertTrue(nameTestStatus.getStatus().size()== 1);
1056
        assertEquals( NomenclaturalStatusType.NOVUM(), nameTestStatus.getStatus().iterator().next().getType());
1057

    
1058
        //nom. utique rej. prop.
1059
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. utique rej. prop.";
1060
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
1061
        assertFullRefStandard(nameTestStatus);
1062
        assertTrue(nameTestStatus.getStatus().size()== 1);
1063
        assertEquals( NomenclaturalStatusType.UTIQUE_REJECTED_PROP(), nameTestStatus.getStatus().iterator().next().getType());
1064

    
1065
        //nom. orth. cons.
1066
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, orth. cons.";
1067
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
1068
        assertFullRefStandard(nameTestStatus);
1069
        assertTrue(nameTestStatus.getStatus().size()== 1);
1070
        assertEquals( NomenclaturalStatusType.ORTHOGRAPHY_CONSERVED(), nameTestStatus.getStatus().iterator().next().getType());
1071

    
1072
        //nom. rej. prop.
1073
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. rej. prop.";
1074
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
1075
        assertFullRefStandard(nameTestStatus);
1076
        assertTrue(nameTestStatus.getStatus().size()== 1);
1077
        assertEquals( NomenclaturalStatusType.REJECTED_PROP(), nameTestStatus.getStatus().iterator().next().getType());
1078

    
1079
        //nom. cons.
1080
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. cons.";
1081
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
1082
        assertFullRefStandard(nameTestStatus);
1083
        assertTrue(nameTestStatus.getStatus().size()== 1);
1084
        assertEquals( NomenclaturalStatusType.CONSERVED(), nameTestStatus.getStatus().iterator().next().getType());
1085

    
1086
        //nom. sanct.
1087
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. sanct.";
1088
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
1089
        assertFullRefStandard(nameTestStatus);
1090
        assertTrue(nameTestStatus.getStatus().size()== 1);
1091
        assertEquals( NomenclaturalStatusType.SANCTIONED(), nameTestStatus.getStatus().iterator().next().getType());
1092

    
1093
        //nom. nud.
1094
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. nud.";
1095
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
1096
        assertFullRefStandard(nameTestStatus);
1097
        assertTrue(nameTestStatus.getStatus().size()== 1);
1098
        assertEquals( NomenclaturalStatusType.NUDUM(), nameTestStatus.getStatus().iterator().next().getType());
1099

    
1100
        //comb. inval.
1101
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, comb. inval.";
1102
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
1103
        assertFullRefStandard(nameTestStatus);
1104
        assertTrue(nameTestStatus.getStatus().size()== 1);
1105
        assertEquals( NomenclaturalStatusType.COMBINATION_INVALID(), nameTestStatus.getStatus().iterator().next().getType());
1106

    
1107
        //comb. illeg.
1108
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, comb. illeg.";
1109
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
1110
        assertFullRefStandard(nameTestStatus);
1111
        assertTrue(nameTestStatus.getStatus().size()== 1);
1112
        assertEquals( NomenclaturalStatusType.COMBINATION_ILLEGITIMATE(), nameTestStatus.getStatus().iterator().next().getType());
1113

    
1114
        //nom. provis.
1115
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. provis.";
1116
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
1117
        assertFullRefStandard(nameTestStatus);
1118
        assertTrue(nameTestStatus.getStatus().size()== 1);
1119
        assertEquals( NomenclaturalStatusType.PROVISIONAL(), nameTestStatus.getStatus().iterator().next().getType());
1120

    
1121
        //nom. val.
1122
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. val.";
1123
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
1124
        assertFullRefStandard(nameTestStatus);
1125
        assertTrue(nameTestStatus.getStatus().size()== 1);
1126
        assertEquals( NomenclaturalStatusType.VALID(), nameTestStatus.getStatus().iterator().next().getType());
1127

    
1128
        //nom. subnud.
1129
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. subnud.";
1130
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
1131
        assertFullRefStandard(nameTestStatus);
1132
        assertTrue(nameTestStatus.getStatus().size()== 1);
1133
        assertEquals( NomenclaturalStatusType.SUBNUDUM(), nameTestStatus.getStatus().iterator().next().getType());
1134

    
1135
        //opus. utique oppr.
1136
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, op. utique oppr.";
1137
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
1138
        assertFullRefStandard(nameTestStatus);
1139
        assertTrue(nameTestStatus.getStatus().size()== 1);
1140
        assertEquals( NomenclaturalStatusType.OPUS_UTIQUE_OPPR(), nameTestStatus.getStatus().iterator().next().getType());
1141

    
1142
        //comb. nov.
1143
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, comb. nov.";
1144
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
1145
        assertFullRefStandard(nameTestStatus);
1146
        assertTrue(nameTestStatus.getStatus().size()== 1);
1147
        assertEquals( NomenclaturalStatusType.COMB_NOV(), nameTestStatus.getStatus().iterator().next().getType());
1148

    
1149
        //orth. rej.
1150
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, orth. rej.";
1151
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
1152
        assertFullRefStandard(nameTestStatus);
1153
        assertTrue(nameTestStatus.getStatus().size()== 1);
1154
        assertEquals( NomenclaturalStatusType.ORTHOGRAPHY_REJECTED(), nameTestStatus.getStatus().iterator().next().getType());
1155

    
1156
        //ined.
1157
        strTestStatus = "Houstonia macvaughii (Terrell), ined.";
1158
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
1159
        assertEquals("Houstonia", nameTestStatus.getGenusOrUninomial());
1160
        assertEquals("macvaughii", nameTestStatus.getSpecificEpithet());
1161
        assertEquals("(Terrell)", nameTestStatus.getAuthorshipCache());
1162
        assertEquals(1, nameTestStatus.getStatus().size());
1163
        assertEquals( NomenclaturalStatusType.INED(), nameTestStatus.getStatus().iterator().next().getType());
1164

    
1165
        //not yet parsed "not avail."
1166
    }
1167

    
1168
    /**
1169
     * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#parseReferencedName(NonViralName, java.lang.String, eu.etaxonomy.cdm.model.name.Rank, boolean)(, )}.
1170
     */
1171
    @Test
1172
    public final void testParseReferencedName() {
1173
        try {
1174
            Method parseMethod = parser.getClass().getDeclaredMethod("parseReferencedName", String.class, NomenclaturalCode.class, Rank.class);
1175
            testName_StringNomcodeRank(parseMethod);
1176
        } catch (Exception e) {
1177
            e.printStackTrace();
1178
            assertTrue(false);
1179
        }
1180

    
1181
        //null
1182
        String strNull = null;
1183
        Rank rankSpecies = Rank.SPECIES();
1184
        INonViralName nameNull = parser.parseReferencedName(strNull, null, rankSpecies);
1185
        assertNull(nameNull);
1186

    
1187
        //Empty
1188
        String strEmpty = "";
1189
        INonViralName nameEmpty = parser.parseReferencedName(strEmpty, null, rankSpecies);
1190
        assertFalse(nameEmpty.hasProblem());
1191
        assertEquals(strEmpty, nameEmpty.getFullTitleCache());
1192
        assertNull(nameEmpty.getNomenclaturalMicroReference());
1193

    
1194

    
1195
        //Whitespaces
1196
        String strFullWhiteSpcaceAndDot = "Abies alba Mill.,  Sp.   Pl.  4:  455 .  1987 .";
1197
        INonViralName namefullWhiteSpcaceAndDot = parser.parseReferencedName(strFullWhiteSpcaceAndDot, null, rankSpecies);
1198
        assertFullRefStandard(namefullWhiteSpcaceAndDot);
1199
        assertTrue(namefullWhiteSpcaceAndDot.getNomenclaturalReference().getType().equals(eu.etaxonomy.cdm.model.reference.ReferenceType.Book));
1200
        assertEquals( "Abies alba Mill., Sp. Pl. 4: 455. 1987", namefullWhiteSpcaceAndDot.getFullTitleCache());
1201

    
1202
        //Book
1203
        String fullReference = "Abies alba Mill., Sp. Pl. 4: 455. 1987";
1204
        INonViralName name1 = parser.parseReferencedName(fullReference, null, rankSpecies);
1205
        assertFullRefStandard(name1);
1206
        assertTrue(name1.getNomenclaturalReference().getType().equals(eu.etaxonomy.cdm.model.reference.ReferenceType.Book));
1207
        assertEquals(fullReference, name1.getFullTitleCache());
1208
        assertTrue("Name author and reference author should be the same", name1.getCombinationAuthorship() == name1.getNomenclaturalReference().getAuthorship());
1209

    
1210
        //Book Section
1211
        fullReference = "Abies alba Mill. in Otto, Sp. Pl. 4(6): 455. 1987";
1212
        INonViralName name2 = parser.parseReferencedName(fullReference + ".", null, rankSpecies);
1213
        assertFullRefNameStandard(name2);
1214
        assertEquals(fullReference, name2.getFullTitleCache());
1215
        assertFalse(name2.hasProblem());
1216
        INomenclaturalReference ref = name2.getNomenclaturalReference();
1217
        assertEquals(ReferenceType.BookSection, ((Reference)ref).getType());
1218
        IBookSection bookSection = (IBookSection) ref;
1219
        IBook inBook = bookSection.getInBook();
1220
        assertNotNull(inBook);
1221
        assertNotNull(inBook.getAuthorship());
1222
        assertEquals("Otto", inBook.getAuthorship().getTitleCache());
1223
        assertEquals("Otto: Sp. Pl. 4(6)", inBook.getTitleCache());
1224
        assertEquals("Sp. Pl.", inBook.getAbbrevTitle());
1225
        assertEquals("4(6)", inBook.getVolume());
1226
        assertTrue("Name author and reference author should be the same", name2.getCombinationAuthorship() == name2.getNomenclaturalReference().getAuthorship());
1227

    
1228
        //Article
1229
        fullReference = "Abies alba Mill. in Sp. Pl. 4(6): 455. 1987";
1230
        INonViralName name3 = parser.parseReferencedName(fullReference, null, rankSpecies);
1231
        assertFullRefNameStandard(name3);
1232
        name3.setTitleCache(null);
1233
        assertEquals(fullReference, name3.getFullTitleCache());
1234
        assertFalse(name3.hasProblem());
1235
        ref = name3.getNomenclaturalReference();
1236
        assertEquals(eu.etaxonomy.cdm.model.reference.ReferenceType.Article, ref.getType());
1237
        //Article article = (Article)ref;
1238
        IJournal journal = ((IArticle)ref).getInJournal();
1239
        assertNotNull(journal);
1240
        //assertEquals("Sp. Pl. 4(6)", inBook.getTitleCache());
1241
        assertEquals("Sp. Pl.",((Reference) journal).getTitleCache());
1242
        assertEquals("Sp. Pl.", journal.getAbbrevTitle());
1243
        assertEquals("4(6)",((IArticle)ref).getVolume());
1244
        assertTrue("Name author and reference author should be the same", name3.getCombinationAuthorship() == name3.getNomenclaturalReference().getAuthorship());
1245

    
1246
        //Article with volume range
1247
        fullReference = "Abies alba Mill. in Sp. Pl. 4(1-2): 455. 1987";
1248
        INonViralName name3a = parser.parseReferencedName(fullReference, null, rankSpecies);
1249
        name3a.setTitleCache(null);
1250
        assertEquals(fullReference, name3a.getFullTitleCache());
1251
        assertFalse(name3a.hasProblem());
1252
        ref = name3a.getNomenclaturalReference();
1253
        assertEquals(eu.etaxonomy.cdm.model.reference.ReferenceType.Article, ref.getType());
1254
        assertEquals("4(1-2)",((IArticle)ref).getVolume());
1255

    
1256
        //SoftArticle - having "," on position > 4
1257
        String journalTitle = "Bull. Soc. Bot.France. Louis., Roi";
1258
        String yearPart = " 1987 - 1989";
1259
        String parsedYear = "1987-1989";
1260
        String parsedYearFormatted = "1987"+SEP+"1989";
1261
        String fullReferenceWithoutYear = "Abies alba Mill. in " + journalTitle + " 4(6): 455.";
1262
        fullReference = fullReferenceWithoutYear + yearPart;
1263
        String fullReferenceWithEnd = fullReference + ".";
1264
        INonViralName name4 = parser.parseReferencedName(fullReferenceWithEnd, null, rankSpecies);
1265
        assertFalse(name4.hasProblem());
1266
        assertFullRefNameStandard(name4);
1267
        assertEquals(fullReferenceWithoutYear + " " + parsedYearFormatted, name4.getFullTitleCache());
1268
        ref = name4.getNomenclaturalReference();
1269
        assertEquals(ReferenceType.Article, ref.getType());
1270
        //article = (Article)ref;
1271
        assertEquals(parsedYearFormatted, ref.getYear());
1272
        journal = ((IArticle)ref).getInJournal();
1273
        assertNotNull(journal);
1274
        assertEquals(journalTitle, ((Reference) journal).getTitleCache());
1275
        assertEquals(journalTitle, journal.getAbbrevTitle());
1276
        assertEquals("4(6)", ((IArticle)ref).getVolume());
1277

    
1278
        //Zoo name
1279
        String strNotParsableZoo = "Abies alba M., 1923, Sp. P. xxwer4352, nom. inval.";
1280
        IZoologicalName nameZooRefNotParsabel = parser.parseReferencedName(strNotParsableZoo, null, null);
1281
        assertTrue(nameZooRefNotParsabel.hasProblem());
1282
        List<ParserProblem> list = nameZooRefNotParsabel.getParsingProblems();
1283
        assertTrue("List must contain detail and year warning ", list.contains(ParserProblem.CheckDetailOrYear));
1284
        assertEquals(21, nameZooRefNotParsabel.getProblemStarts());
1285
        assertEquals(37, nameZooRefNotParsabel.getProblemEnds());
1286
        assertTrue(nameZooRefNotParsabel.getNomenclaturalReference().hasProblem());
1287
        list = nameZooRefNotParsabel.getNomenclaturalReference().getParsingProblems();
1288
        assertTrue("List must contain detail and year warning ", list.contains(ParserProblem.CheckDetailOrYear));
1289

    
1290
        assertEquals(NomenclaturalCode.ICZN, nameZooRefNotParsabel.getNameType());
1291
        assertEquals(Integer.valueOf(1923), nameZooRefNotParsabel.getPublicationYear());
1292
        assertEquals(1, nameZooRefNotParsabel.getStatus().size());
1293

    
1294
        String strZooNameSineYear = "Homo sapiens L., 1758, Sp. An. 3: 345";
1295
        IZoologicalName nameZooNameSineYear = parser.parseReferencedName(strZooNameSineYear);
1296
        assertFalse(nameZooNameSineYear.hasProblem());
1297
        assertEquals("Name without reference year must have year", (Integer)1758, nameZooNameSineYear.getPublicationYear());
1298
        assertEquals("Name without reference year must have year", "1758", nameZooNameSineYear.getNomenclaturalReference().getYear());
1299

    
1300
        String strZooNameNewCombination = "Homo sapiens (L., 1758) Mill., 1830, Sp. An. 3: 345";
1301
        IZoologicalName nameZooNameNewCombination = parser.parseReferencedName(strZooNameNewCombination);
1302
        assertTrue(nameZooNameNewCombination.hasProblem());
1303
        list = nameZooNameNewCombination.getParsingProblems();
1304
        assertTrue("List must contain new combination has publication warning ", list.contains(ParserProblem.NewCombinationHasPublication));
1305
        assertEquals(35, nameZooNameNewCombination.getProblemStarts());
1306
        assertEquals(51, nameZooNameNewCombination.getProblemEnds());
1307

    
1308
        //Special MicroRefs
1309
        String strSpecDetail1 = "Abies alba Mill. in Sp. Pl. 4(6): [455]. 1987";
1310
        INonViralName nameSpecDet1 = parser.parseReferencedName(strSpecDetail1 + ".", null, rankSpecies);
1311
        assertFalse(nameSpecDet1.hasProblem());
1312
        assertEquals(strSpecDetail1, nameSpecDet1.getFullTitleCache());
1313
        assertEquals("[455]", nameSpecDet1.getNomenclaturalMicroReference());
1314

    
1315
        //Special MicroRefs
1316
        String strSpecDetail2 = "Abies alba Mill. in Sp. Pl. 4(6): couv. 2. 1987";
1317
        INonViralName nameSpecDet2 = parser.parseReferencedName(strSpecDetail2 + ".", null, rankSpecies);
1318
        assertFalse(nameSpecDet2.hasProblem());
1319
        assertEquals(strSpecDetail2, nameSpecDet2.getFullTitleCache());
1320
        assertEquals("couv. 2", nameSpecDet2.getNomenclaturalMicroReference());
1321

    
1322
        //Special MicroRefs
1323
        String strSpecDetail3 = "Abies alba Mill. in Sp. Pl. 4(6): fig. 455. 1987";
1324
        INonViralName nameSpecDet3 = parser.parseReferencedName(strSpecDetail3 + ".", null, rankSpecies);
1325
        assertFalse(nameSpecDet3.hasProblem());
1326
        assertEquals(strSpecDetail3, nameSpecDet3.getFullTitleCache());
1327
        assertEquals("fig. 455", nameSpecDet3.getNomenclaturalMicroReference());
1328

    
1329
        //Special MicroRefs
1330
        String strSpecDetail4 = "Abies alba Mill. in Sp. Pl. 4(6): fig. 455-567. 1987";
1331
        fullReference = strSpecDetail4 + ".";
1332
        INonViralName nameSpecDet4 = parser.parseReferencedName(fullReference, null, rankSpecies);
1333
        assertFalse(nameSpecDet4.hasProblem());
1334
        assertEquals(strSpecDetail4, nameSpecDet4.getFullTitleCache());
1335
        assertEquals("fig. 455-567", nameSpecDet4.getNomenclaturalMicroReference());
1336

    
1337
        //Special MicroRefs
1338
        String strSpecDetail5 = "Abies alba Mill. in Sp. Pl. 4(6): Gard n\u00B0 4. 1987";
1339
        fullReference = strSpecDetail5 + ".";
1340
        INonViralName nameSpecDet5 = parser.parseReferencedName(fullReference, null, rankSpecies);
1341
        assertFalse(nameSpecDet5.hasProblem());
1342
        assertEquals(strSpecDetail5, nameSpecDet5.getFullTitleCache());
1343
        assertEquals("Gard n\u00B0 4", nameSpecDet5.getNomenclaturalMicroReference());
1344

    
1345
        //Special MicroRefs
1346
        String strSpecDetail6 = "Abies alba Mill. in Sp. Pl. 4(6): 455a. 1987";
1347
        fullReference = strSpecDetail6 + ".";
1348
        INonViralName nameSpecDet6 = parser.parseReferencedName(fullReference, null, rankSpecies);
1349
        assertFalse(nameSpecDet6.hasProblem());
1350
        assertEquals(strSpecDetail6, nameSpecDet6.getFullTitleCache());
1351
        assertEquals("455a", nameSpecDet6.getNomenclaturalMicroReference());
1352

    
1353
        //Special MicroRefs
1354
        String strSpecDetail7 = "Abies alba Mill. in Sp. Pl. 4(6): pp.455-457. 1987";
1355
        fullReference = strSpecDetail7 + ".";
1356
        INonViralName nameSpecDet7 = parser.parseReferencedName(fullReference, null, rankSpecies);
1357
        assertFalse(nameSpecDet7.hasProblem());
1358
        assertEquals(strSpecDetail7, nameSpecDet7.getFullTitleCache());
1359
        assertEquals("pp.455-457", nameSpecDet7.getNomenclaturalMicroReference());
1360

    
1361
        //Special MicroRefs
1362
        String strSpecDetail8 = "Abies alba Mill. in Sp. Pl. 4(6): ppp.455-457. 1987";
1363
        INonViralName nameSpecDet8 = parser.parseReferencedName(strSpecDetail8, null, rankSpecies);
1364
        assertTrue(nameSpecDet8.hasProblem());
1365
        assertEquals(20, nameSpecDet8.getProblemStarts()); //TODO better start behind :
1366
        assertEquals(51, nameSpecDet8.getProblemEnds());   //TODO better stop after -457
1367

    
1368

    
1369
        //Special MicroRefs
1370
        String strSpecDetail9 = "Abies alba Mill. in Sp. Pl. 4(6): pp. 455 - 457. 1987";
1371
        INonViralName nameSpecDet9 = parser.parseReferencedName(strSpecDetail9, null, rankSpecies);
1372
        assertFalse(nameSpecDet9.hasProblem());
1373
        assertEquals(strSpecDetail9, nameSpecDet9.getFullTitleCache());
1374
        assertEquals("pp. 455 - 457", nameSpecDet9.getNomenclaturalMicroReference());
1375

    
1376
        //Special MicroRefs
1377
        String strSpecDetail10 = "Abies alba Mill. in Sp. Pl. 4(6): p 455. 1987";
1378
        INonViralName nameSpecDet10 = parser.parseReferencedName(strSpecDetail10, null, rankSpecies);
1379
        assertFalse(nameSpecDet10.hasProblem());
1380
        assertEquals(strSpecDetail10, nameSpecDet10.getFullTitleCache());
1381
        assertEquals("p 455", nameSpecDet10.getNomenclaturalMicroReference());
1382

    
1383
        //Special MicroRefs
1384
        String strSpecDetail11 = "Abies alba Mill. in Sp. Pl. 4(6): p. 455 - 457. 1987";
1385
        INonViralName nameSpecDet11 = parser.parseReferencedName(strSpecDetail11, null, rankSpecies);
1386
        assertTrue(nameSpecDet11.hasProblem());
1387
        list = nameSpecDet11.getParsingProblems();
1388
        assertTrue("Problem is Detail. Must be pp.", list.contains(ParserProblem.CheckDetailOrYear));
1389
        assertEquals(20, nameSpecDet8.getProblemStarts()); //TODO better start behind :
1390
        assertEquals(51, nameSpecDet8.getProblemEnds());   //TODO better stop after - 457
1391

    
1392

    
1393
        //no volume, no edition
1394
        String strNoVolume = "Abies alba Mill., Sp. Pl.: 455. 1987";
1395
        INonViralName nameNoVolume = parser.parseReferencedName(strNoVolume, null, rankSpecies);
1396
        assertFalse(nameNoVolume.hasProblem());
1397
        assertEquals(strNoVolume, nameNoVolume.getFullTitleCache());
1398
        assertEquals(null, ((IVolumeReference)(nameNoVolume.getNomenclaturalReference())).getVolume());
1399
        assertEquals(null, ((IBook)nameNoVolume.getNomenclaturalReference()).getEdition());
1400

    
1401
        //volume, no edition
1402
        strNoVolume = "Abies alba Mill., Sp. Pl. 2: 455. 1987";
1403
        nameNoVolume = parser.parseReferencedName(strNoVolume, null, rankSpecies);
1404
        assertFalse(nameNoVolume.hasProblem());
1405
        assertEquals(strNoVolume, nameNoVolume.getFullTitleCache());
1406
        assertEquals("2", ((IVolumeReference)(nameNoVolume.getNomenclaturalReference())).getVolume());
1407
        assertEquals(null, ((IBook)(nameNoVolume.getNomenclaturalReference())).getEdition());
1408

    
1409
        //no volume, edition
1410
        strNoVolume = "Abies alba Mill., Sp. Pl., ed. 3: 455. 1987";
1411
        nameNoVolume = parser.parseReferencedName(strNoVolume, null, rankSpecies);
1412
        assertFalse(nameNoVolume.hasProblem());
1413
        assertEquals(strNoVolume, nameNoVolume.getFullTitleCache());
1414
        assertEquals(null, ((IVolumeReference)(nameNoVolume.getNomenclaturalReference())).getVolume());
1415
        assertEquals("3", ((IBook)(nameNoVolume.getNomenclaturalReference())).getEdition());
1416

    
1417
        //volume, edition
1418
        strNoVolume = "Abies alba Mill., Sp. Pl. ed. 3, 4(5): 455. 1987";
1419
        nameNoVolume = parser.parseReferencedName(strNoVolume, null, rankSpecies);
1420
        assertFalse(nameNoVolume.hasProblem());
1421
        assertEquals(strNoVolume.replace(" ed.", ", ed."), nameNoVolume.getFullTitleCache());
1422
        assertEquals("4(5)", ((IVolumeReference)(nameNoVolume.getNomenclaturalReference())).getVolume());
1423
        assertEquals("3", ((IBook)(nameNoVolume.getNomenclaturalReference())).getEdition());
1424

    
1425
        String strUnparsableInRef = "Abies alba Mill. in -er46: 455. 1987";
1426
        INonViralName nameUnparsableInRef = parser.parseReferencedName(strUnparsableInRef, null, rankSpecies);
1427
        assertTrue(nameUnparsableInRef.hasProblem());
1428
        list = nameUnparsableInRef.getParsingProblems();
1429
        assertTrue("Unparsable title", list.contains(ParserProblem.UnparsableReferenceTitle));
1430
        assertEquals(strUnparsableInRef, nameUnparsableInRef.getFullTitleCache());
1431
        assertEquals(20, nameUnparsableInRef.getProblemStarts());
1432
        assertEquals(25, nameUnparsableInRef.getProblemEnds());
1433

    
1434

    
1435
        //volume, edition
1436
        String strNoSeparator = "Abies alba Mill. Sp. Pl. ed. 3, 4(5): 455. 1987";
1437
        INonViralName nameNoSeparator = parser.parseReferencedName(strNoSeparator, ICNAFP, rankSpecies);
1438
        assertTrue(nameNoSeparator.hasProblem());
1439
        list = nameNoSeparator.getParsingProblems();
1440
        assertTrue("Problem is missing name-reference separator", list.contains(ParserProblem.NameReferenceSeparation));
1441
        assertEquals(strNoSeparator, nameNoSeparator.getFullTitleCache());
1442
        assertEquals(10, nameNoSeparator.getProblemStarts()); //TODO better start behind Mill. (?)
1443
        assertEquals(47, nameNoSeparator.getProblemEnds());   //TODO better stop before :
1444

    
1445
        String strUnparsableInRef2 = "Hieracium pepsicum L., My Bookkkk 1. 1903";
1446
        INonViralName nameUnparsableInRef2 = parser.parseReferencedName(strUnparsableInRef2, null, rankSpecies);
1447
        assertTrue(nameUnparsableInRef2.hasProblem());
1448
        list = nameUnparsableInRef2.getParsingProblems();
1449
        assertTrue("Problem detail", list.contains(ParserProblem.CheckDetailOrYear));
1450
        assertEquals(strUnparsableInRef2, nameUnparsableInRef2.getFullTitleCache());
1451
        assertEquals(23, nameUnparsableInRef2.getProblemStarts());
1452
        assertEquals(41, nameUnparsableInRef2.getProblemEnds());
1453

    
1454

    
1455
        String strUnparsableInRef3 = "Hieracium pespcim N., My Bookkkk 1. 1902";
1456
        INonViralName nameUnparsableInRef3 = parser.parseReferencedName(strUnparsableInRef3, null, null);
1457
        assertTrue(nameUnparsableInRef3.hasProblem());
1458
        list = nameUnparsableInRef3.getParsingProblems();
1459
        assertTrue("Problem detail", list.contains(ParserProblem.CheckDetailOrYear));
1460
        assertEquals(strUnparsableInRef3, nameUnparsableInRef3.getFullTitleCache());
1461
        assertEquals(22, nameUnparsableInRef3.getProblemStarts());
1462
        assertEquals(40, nameUnparsableInRef3.getProblemEnds());
1463

    
1464
        String strUnparsableInRef4 = "Hieracium pepsicum (Hsllreterto) L., My Bookkkk 1. 1903";
1465
        INonViralName nameUnparsableInRef4 = parser.parseReferencedName(strUnparsableInRef4, null, null);
1466
        assertTrue(nameUnparsableInRef4.hasProblem());
1467
        list = nameUnparsableInRef4.getParsingProblems();
1468
        assertTrue("Problem detail", list.contains(ParserProblem.CheckDetailOrYear));
1469
        assertEquals(strUnparsableInRef4, nameUnparsableInRef4.getFullTitleCache());
1470
        assertEquals(37, nameUnparsableInRef4.getProblemStarts());
1471
        assertEquals(55, nameUnparsableInRef4.getProblemEnds());
1472

    
1473
        String strSameName = "Hieracium pepcum (Hsllreterto) L., My Bokkk 1. 1903";
1474
        INonViralName nameSameName = nameUnparsableInRef4;
1475
        parser.parseReferencedName(nameSameName, strSameName, null, true);
1476
        assertTrue(nameSameName.hasProblem());
1477
        list = nameSameName.getParsingProblems();
1478
        assertTrue("Problem detail", list.contains(ParserProblem.CheckDetailOrYear));
1479
        assertEquals(strSameName, nameSameName.getFullTitleCache());
1480
        assertEquals(35, nameSameName.getProblemStarts());
1481
        assertEquals(51, nameSameName.getProblemEnds());
1482

    
1483
        String strGenusUnparse = "Hieracium L., jlklk";
1484
        INonViralName nameGenusUnparse =
1485
            parser.parseReferencedName(strGenusUnparse, null, null);
1486
        assertTrue(nameGenusUnparse.hasProblem());
1487
        list = nameGenusUnparse.getParsingProblems();
1488
        assertTrue("Problem detail", list.contains(ParserProblem.CheckDetailOrYear));
1489
        assertTrue("Problem uninomial", list.contains(ParserProblem.CheckRank));
1490
        assertEquals(strGenusUnparse, nameGenusUnparse.getFullTitleCache());
1491
        assertEquals(0, nameGenusUnparse.getProblemStarts());
1492
        assertEquals(19, nameGenusUnparse.getProblemEnds());
1493

    
1494
        String strGenusUnparse2 = "Hieracium L., Per Luigi: 44. 1987";
1495
        INonViralName nameGenusUnparse2 =
1496
            parser.parseReferencedName(strGenusUnparse2, null, Rank.FAMILY());
1497
        assertFalse(nameGenusUnparse2.hasProblem());
1498
        assertEquals(strGenusUnparse2, nameGenusUnparse2.getFullTitleCache());
1499
        assertEquals(-1, nameGenusUnparse2.getProblemStarts());
1500
        assertEquals(-1, nameGenusUnparse2.getProblemEnds());
1501

    
1502
        String strBookSection2 = "Hieracium vulgatum subsp. acuminatum (Jord.) Zahn in Schinz & Keller, Fl. Schweiz, ed. 2, 2: 288. 1905-1907";
1503
        String strBookSection2NoComma = "Hieracium vulgatum subsp. acuminatum (Jord.) Zahn in Schinz & Keller, Fl. Schweiz ed. 2, 2: 288. 1905-1907";
1504
        INonViralName nameBookSection2 =
1505
              parser.parseReferencedName(strBookSection2, null, null);
1506
        assertFalse(nameBookSection2.hasProblem());
1507
        nameBookSection2.setFullTitleCache(null, false);
1508
        assertEquals(strBookSection2NoComma.replace(" ed.", ", ed.").replace("-",SEP), nameBookSection2.getFullTitleCache());
1509
        assertEquals(-1, nameBookSection2.getProblemStarts());
1510
        assertEquals(-1, nameBookSection2.getProblemEnds());
1511
        assertNull((nameBookSection2.getNomenclaturalReference()).getDatePublished().getStart());
1512
        assertEquals("1905"+SEP+"1907", ((IBookSection)nameBookSection2.getNomenclaturalReference()).getInBook().getDatePublished().getYear());
1513

    
1514
        String strBookSection = "Hieracium vulgatum subsp. acuminatum (Jord.) Zahn in Schinz & Keller, Fl. Schweiz ed. 2, 2: 288. 1905";
1515
        INonViralName nameBookSection =
1516
            parser.parseReferencedName(strBookSection, null, null);
1517
        assertFalse(nameBookSection.hasProblem());
1518
        assertEquals(strBookSection.replace(" ed.", ", ed."), nameBookSection.getFullTitleCache());
1519
        assertEquals(-1, nameBookSection.getProblemStarts());
1520
        assertEquals(-1, nameBookSection.getProblemEnds());
1521
        assertNull(((IBookSection)nameBookSection.getNomenclaturalReference()).getInBook().getDatePublished().getStart());
1522
        assertEquals("1905", ((IBookSection)nameBookSection.getNomenclaturalReference()).getDatePublished().getYear());
1523

    
1524
        String strXXXs = "Abies alba, Soer der 1987";
1525
        INonViralName problemName = parser.parseReferencedName(strXXXs, null, null);
1526
        assertTrue(problemName.hasProblem());
1527
        list = problemName.getParsingProblems();
1528
        assertTrue("Problem must be name-reference separation", list.contains(ParserProblem.NameReferenceSeparation));
1529
        parser.parseReferencedName(problemName, strBookSection, null, true);
1530
        assertFalse(problemName.hasProblem());
1531

    
1532
        problemName = parser.parseFullName(strXXXs, null, null);
1533
        assertTrue(problemName.hasProblem());
1534
        list = problemName.getParsingProblems();
1535
        assertTrue("Name part must be unparsable", list.contains(ParserProblem.UnparsableNamePart));
1536

    
1537

    
1538
        String testParsable = "Pithecellobium macrostachyum Benth.";
1539
        assertTrue(isParsable(testParsable, ICNAFP));
1540

    
1541
        testParsable = "Pithecellobium macrostachyum (Benth.)";
1542
        assertTrue(isParsable(testParsable, ICNAFP));
1543

    
1544
        testParsable = "Pithecellobium macrostachyum (Benth., 1845)";
1545
        assertTrue(isParsable(testParsable, NomenclaturalCode.ICZN));
1546

    
1547
        testParsable = "Pithecellobium macrostachyum L., Sp. Pl. 3: n\u00B0 123. 1753."; //00B0 is degree character
1548
        assertTrue(isParsable(testParsable, ICNAFP));
1549

    
1550
        testParsable = "Hieracium lachenalii subsp. acuminatum (Jord.) Zahn in Hegi, Ill. Fl. Mitt.-Eur. 6: 1285. 1929";
1551
        assertTrue("Reference title should support special characters as separators like - and &", isParsable(testParsable, ICNAFP));
1552

    
1553
        testParsable = "Hieracium lachenalii subsp. acuminatum (Jord.) Zahn in Hegi, Ill. Fl. Mitt.&Eur. 6: 1285. 1929";
1554
        assertTrue("Reference title should support special characters as separators like - and &", isParsable(testParsable, ICNAFP));
1555

    
1556
        testParsable = "Hieracium lachenalii subsp. acuminatum (Jord.) Zahn in Hegi, Ill. Fl. Mitt.-Eur.& 6: 1285. 1929";
1557
        assertFalse("Reference title should not support special characters like - and & at the end of the title", isParsable(testParsable, ICNAFP));
1558
        assertTrue("Problem must be reference title", getProblems(testParsable, ICNAFP).
1559
                contains(ParserProblem.UnparsableReferenceTitle));
1560

    
1561
        testParsable = "Hieracium lachenalii subsp. acuminatum (Jord.) Zahn in Hegi, Ill. Fl. Mitt.:Eur. 6: 1285. 1929";
1562
        assertFalse("Reference title should not support detail separator", isParsable(testParsable, ICNAFP));
1563
        assertTrue("Problem must be reference title", getProblems(testParsable, ICNAFP).
1564
                contains(ParserProblem.UnparsableReferenceTitle));
1565

    
1566
        testParsable = "Hieracium lachenalii subsp. acuminatum (Jord.) Zahn in Hegi, Ill. Fl. (Mitt.) 6: 1285. 1929";
1567
        assertTrue("Reference title should support brackets", isParsable(testParsable, ICNAFP));
1568

    
1569
        testParsable = "Hieracium lachenalii subsp. acuminatum (Jord.) Zahn in Hegi, Ill. Fl. (Mitt.) 6: 1285. 1929";
1570
        assertTrue("Reference title should support brackets", isParsable(testParsable, ICNAFP));
1571

    
1572
        testParsable = "Hieracium lachenalii Zahn, nom. illeg.";
1573
        assertTrue("Reference should not be obligatory if a nom status exist", isParsable(testParsable, ICNAFP));
1574

    
1575
        testParsable = "Hieracium lachenalii, nom. illeg.";
1576
        assertTrue("Authorship should not be obligatory if followed by nom status", isParsable(testParsable, ICNAFP));
1577

    
1578
        testParsable = "Hieracium lachenalii, Ill. Fl. (Mitt.) 6: 1285. 1929";
1579
        assertFalse("Author is obligatory if followed by reference", isParsable(testParsable, ICNAFP));
1580
        assertTrue("Problem must be name-reference separation", getProblems(testParsable, ICNAFP).
1581
                contains(ParserProblem.NameReferenceSeparation));
1582

    
1583
        testParsable = "Hieracium lachenalii in Hegi, Ill. Fl. (Mitt.) 6: 1285. 1929";
1584
        assertFalse("Author is obligatory if followed by reference", isParsable(testParsable, ICNAFP));
1585
        assertTrue("Problem must be name-reference separation", getProblems(testParsable, ICNAFP).
1586
                contains(ParserProblem.NameReferenceSeparation));
1587

    
1588
        testParsable = "Abies alba Mill. var. alba";
1589
        assertTrue("Autonym problem", isParsable(testParsable, ICNAFP));
1590

    
1591
        testParsable = "Scleroblitum abc Ulbr. in Engler & Prantl, Nat. Pflanzenfam., ed. 2, 16c: 495. 1934.";
1592
        assertTrue("Volume with subdivision", isParsable(testParsable, ICNAFP));
1593

    
1594

    
1595
        testParsable = "Hieracium antarcticum d'Urv. in M\u00E9m. Soc. Linn. Paris 4: 608. 1826";
1596
//      testParsable = "Hieracium antarcticum Urv. in M\u00E9m. Soc. Linn. Paris 4: 608. 1826";
1597
        assertTrue("Name with apostrophe is not parsable", isParsable(testParsable, ICNAFP));
1598

    
1599
        testParsable = "Cichorium intybus subsp. glaucum (Hoffmanns. & Link) Tzvelev in Komarov, Fl. SSSR 29: 17. 1964";
1600
        assertTrue("Reference containing a word in uppercase is not parsable", isParsable(testParsable, ICNAFP));
1601

    
1602

    
1603
    }
1604

    
1605

    
1606
    /**
1607
     * Test author with name parts van, von, de, de la, d', da, del.
1608
     * See also https://dev.e-taxonomy.eu/redmine/issues/3373
1609
     */
1610
    @Test
1611
    public final void  testComposedAuthorNames(){
1612

    
1613
        //van author (see https://dev.e-taxonomy.eu/redmine/issues/3373)
1614
        String testParsable = "Aphelocoma unicolor subsp. griscomi van Rossem, 1928";
1615
        assertTrue("Author with 'van' should be parsable", isParsable(testParsable, ICZN));
1616

    
1617
        //von author (see https://dev.e-taxonomy.eu/redmine/issues/3373)
1618
        testParsable = "Aphelocoma unicolor subsp. griscomi von Rossem, 1928";
1619
        assertTrue("Author with 'von' should be parsable", isParsable(testParsable, ICZN));
1620

    
1621
        //de author (see https://dev.e-taxonomy.eu/redmine/issues/3373)
1622
        testParsable = "Aphelocoma unicolor subsp. griscomi de Rossem, 1928";
1623
        assertTrue("Author with 'de' should be parsable", isParsable(testParsable, ICZN));
1624

    
1625
        //de la author (see https://dev.e-taxonomy.eu/redmine/issues/3373)
1626
        testParsable = "Aphelocoma unicolor subsp. griscomi de la Rossem, 1928";
1627
        assertTrue("Author with 'de la' should be parsable", isParsable(testParsable, ICZN));
1628

    
1629
        //d' author (see https://dev.e-taxonomy.eu/redmine/issues/3373)
1630
        testParsable = "Aphelocoma unicolor subsp. griscomi d'Rossem, 1928";
1631
        assertTrue("Author with \"'d'\" should be parsable", isParsable(testParsable, ICZN));
1632

    
1633
        //da author (see https://dev.e-taxonomy.eu/redmine/issues/3373)
1634
        testParsable = "Aphelocoma unicolor subsp. griscomi da Rossem, 1928";
1635
        assertTrue("Author with 'da' should be parsable", isParsable(testParsable, ICZN));
1636

    
1637
        //del author (see https://dev.e-taxonomy.eu/redmine/issues/3373)
1638
        testParsable = "Aphelocoma unicolor subsp. griscomi del Rossem, 1928";
1639
        assertTrue("Author with 'del' should be parsable", isParsable(testParsable, ICZN));
1640

    
1641
        //O' author (see https://dev.e-taxonomy.eu/redmine/issues/4759)
1642
        testParsable = "Aphelocoma unicolor subsp. griscomi O'Connor, 1928";
1643
        assertTrue("Author with 'O'' should be parsable", isParsable(testParsable, ICZN));
1644

    
1645
        //del author (see https://dev.e-taxonomy.eu/redmine/issues/4759)
1646
        testParsable = "Aphelocoma unicolor subsp. griscomi zur Strassen, 1928";
1647
        assertTrue("Author with 'zur' should be parsable", isParsable(testParsable, ICZN));
1648

    
1649
    }
1650

    
1651

    
1652

    
1653
    /**
1654
     * @param testParsable
1655
     * @param icbn
1656
     * @return
1657
     */
1658
    private List<ParserProblem> getProblems(String string, NomenclaturalCode code) {
1659
        List<ParserProblem> result = parser.parseReferencedName(string, code, null).getParsingProblems();
1660
        return result;
1661
    }
1662

    
1663
    private boolean isParsable(String string, NomenclaturalCode code){
1664
        INonViralName name = parser.parseReferencedName(string, code, null);
1665
        return ! name.hasProblem();
1666
    }
1667

    
1668
    private void assertFullRefNameStandard(INonViralName name){
1669
        assertEquals("Abies", name.getGenusOrUninomial());
1670
        assertEquals("alba", name.getSpecificEpithet());
1671
        assertEquals("Mill.", name.getAuthorshipCache());
1672
        assertEquals("455", name.getNomenclaturalMicroReference());
1673
        assertNotNull(name.getNomenclaturalReference());
1674
    }
1675

    
1676
    private void assertFullRefStandard(INonViralName name){
1677
        assertEquals("Abies", name.getGenusOrUninomial());
1678
        assertEquals("alba", name.getSpecificEpithet());
1679
        assertEquals("Mill.", name.getAuthorshipCache());
1680
        assertEquals("455", name.getNomenclaturalMicroReference());
1681
        assertNotNull(name.getNomenclaturalReference());
1682
        INomenclaturalReference ref = name.getNomenclaturalReference();
1683
        assertEquals("1987", ref.getYear());
1684
        assertEquals("Sp. Pl.", ref.getAbbrevTitle());
1685
    }
1686

    
1687

    
1688
    @Test
1689
    public void testNeverEndingParsing(){
1690
        //some full titles result in never ending parsing process https://dev.e-taxonomy.eu/redmine/issues/1556
1691

    
1692
        String irinaExample = "Milichiidae Sharp, 1899, Insects. Part II. Hymenopteracontinued (Tubulifera and Aculeata), Coleoptera, Strepsiptera, Lepidoptera, Diptera, Aphaniptera, Thysanoptera, Hemiptera, Anoplura 6: 504. 1899";
1693
//      irinaExample = "Milichiidae Sharp, 1899, Insects. Part II. Uiuis Iuiui Hymenopteracontinued (Tubulifera and Aculeata), Coleoptera, Strepsiptera, Lepidoptera, Diptera, Aphaniptera, Thysanoptera, Hemiptera, Anoplura 6: 504. 1899";
1694
        INonViralName nvn = this.parser.parseReferencedName(irinaExample, NomenclaturalCode.ICZN, null);
1695
        int parsingProblem = nvn.getParsingProblem();
1696
        Assert.assertEquals("Name should have only rank warning", 1, parsingProblem);
1697
        Assert.assertEquals("Titlecache", "Milichiidae Sharp, 1899", nvn.getTitleCache());
1698
        Assert.assertEquals("If this line reached everything should be ok", "Milichiidae", nvn.getGenusOrUninomial());
1699

    
1700
        String anotherExample = "Scorzonera hispanica var. brevifolia Boiss. & Balansa in Boissier, Diagn. Pl. Orient., ser. 2 6: 119. 1859.";
1701
        nvn = this.parser.parseReferencedName(anotherExample, ICNAFP, null);
1702
        parsingProblem = nvn.getParsingProblem();
1703
        Assert.assertEquals("Problem should be 0", 0, parsingProblem);
1704
        Assert.assertEquals("Titlecache", "Scorzonera hispanica var. brevifolia Boiss. & Balansa", nvn.getTitleCache());
1705
        Assert.assertEquals("If this line reached everything should be ok", "Scorzonera", nvn.getGenusOrUninomial());
1706

    
1707
        String unparsable = "Taraxacum nevskii L., Trudy Bot. Inst. Nauk S.S.S.R., Ser. 1, Fl. Sist. Vyssh. Rast. 4: 293. 1937.";
1708
//      String unparsableA = "Taraxacum nevskii L. in Trudy Bot. Inst. Nauk: 293. 1937.";
1709
        nvn = this.parser.parseReferencedName(unparsable, ICNAFP, null);
1710
        Assert.assertEquals("Titlecache", "Taraxacum nevskii L.", nvn.getTitleCache());
1711
        Assert.assertEquals("If this line reached everything should be ok", "Taraxacum", nvn.getGenusOrUninomial());
1712
        parsingProblem = nvn.getParsingProblem();
1713
        Assert.assertEquals("Name should no warnings or errors", 0, parsingProblem);
1714

    
1715
        String unparsable2 = "Hieracium pxxx Dahlst., Kongl. Svenska Vetensk. Acad. Handl. ser. 2, 26(3): 255. 1894";
1716
//      String unparsable2A = "Hieracium pxxx Dahlst., Kongl Svenska Vetensk Acad Handl, 26: 255. 1894.";
1717
        nvn = this.parser.parseReferencedName(unparsable2, ICNAFP, null);
1718
        Assert.assertEquals("Titlecache", "Hieracium pxxx Dahlst.", nvn.getTitleCache());
1719
        Assert.assertEquals("If this line reached everything should be ok", "Hieracium", nvn.getGenusOrUninomial());
1720
        parsingProblem = nvn.getParsingProblem();
1721
        Assert.assertEquals("Name should no warnings or errors", 0, parsingProblem);
1722

    
1723

    
1724
        String again = "Adiantum emarginatum Bory ex. Willd., Species Plantarum, ed. 4,5,1: 449,450. 1810";
1725
        nvn = this.parser.parseReferencedName(again, ICNAFP, null);
1726
        Assert.assertEquals("Titlecache", "Adiantum emarginatum Bory ex Willd.", nvn.getTitleCache());
1727
        Assert.assertEquals("If this line reached everything should be ok", "Adiantum", nvn.getGenusOrUninomial());
1728

    
1729
    }
1730

    
1731

    
1732
    @Test
1733
    public final void testSeries(){
1734
        String parseStr = "Mazus pumilus (Burm.f.) Steenis in Nova Guinea, n.s., 9: 31. 1958";
1735
        INonViralName name = parser.parseReferencedName(parseStr);
1736
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1737
        Reference nomRef = name.getNomenclaturalReference();
1738
        Assert.assertFalse("Reference should be parsable", nomRef.isProtectedTitleCache());
1739

    
1740
        assertEquals(ReferenceType.Article, nomRef.getType());
1741
        assertEquals(name.getNomenclaturalMicroReference(), "31");
1742
        assertEquals("Nova Guinea", nomRef.getInJournal().getAbbrevTitle());
1743
        assertEquals("n.s.", nomRef.getSeriesPart());
1744
    }
1745

    
1746
    @Test
1747
    @Ignore
1748
    public final void testRussian(){
1749
        String parseStr = "Cortusa turkestanica Losinsk. in Тр. Бот. инст. Aкад. наук СССР, сер. 1, 3: 239. 1936";
1750
        INonViralName name = parser.parseReferencedName(parseStr);
1751
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1752
        Reference nomRef = name.getNomenclaturalReference();
1753
        Assert.assertFalse("Reference should be parsable", nomRef.isProtectedTitleCache());
1754

    
1755
        assertEquals(ReferenceType.Article, nomRef.getType());
1756
        assertEquals(name.getNomenclaturalMicroReference(), "239");
1757
        assertEquals("Тр. Бот. инст. Aкад. наук СССР", nomRef.getInJournal().getAbbrevTitle());
1758
        assertEquals("сер. 1", nomRef.getSeriesPart());
1759
    }
1760

    
1761
    @Test
1762
    public final void testDetails(){
1763
        //s.p.
1764
        String parseStr = "Xiphion filifolium var. latifolium Baker, Gard. Chron. 1876: s.p.. 1876";
1765
        INonViralName name = parser.parseReferencedName(parseStr);
1766
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1767
        Reference nomRef = name.getNomenclaturalReference();
1768
        assertEquals(ReferenceType.Book, nomRef.getType());
1769
        assertEquals(name.getNomenclaturalMicroReference(), "s.p.");
1770

    
1771
        //roman
1772
        parseStr = "Ophrys lutea subsp. pseudospeculum (DC.) Kergu\u00e9len, Collect. Partim. Nat. 8: xv. 1993";
1773
        name = parser.parseReferencedName(parseStr);
1774
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1775
        nomRef = name.getNomenclaturalReference();
1776
        assertEquals(ReferenceType.Book, nomRef.getType());
1777
        assertEquals(name.getNomenclaturalMicroReference(), "xv");
1778

    
1779
        //n. 1
1780
        parseStr = "Olea gallica Mill., Gard. Dict. ed. 8: n. 1. 1768";
1781
        name = parser.parseReferencedName(parseStr);
1782
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1783
        nomRef = name.getNomenclaturalReference();
1784
        assertEquals(ReferenceType.Book, nomRef.getType());
1785
        assertEquals(name.getNomenclaturalMicroReference(), "n. 1");
1786

    
1787
        parseStr = "Lavandula canariensis Mill., Gard. Dict. ed. 8: Lavandula no. 4. 1768";
1788
        name = parser.parseReferencedName(parseStr);
1789
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1790
        nomRef = name.getNomenclaturalReference();
1791
        assertEquals(ReferenceType.Book, nomRef.getType());
1792
        assertEquals(name.getNomenclaturalMicroReference(), "Lavandula no. 4");
1793

    
1794
        parseStr = "Aceras anthropomorphum (Pers.) Sm. in Rees, Cycl. 39(1): Aceras n. 2. 1818";
1795
        name = parser.parseReferencedName(parseStr);
1796
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1797
        nomRef = name.getNomenclaturalReference();
1798
        assertEquals(ReferenceType.BookSection, nomRef.getType());
1799
        assertEquals(name.getNomenclaturalMicroReference(), "Aceras n. 2");
1800

    
1801
        parseStr = "Chlorolepis Nutt. in Trans. Amer. Philos. Soc., n.s., 7: errata. 1841";
1802
        name = parser.parseReferencedName(parseStr);
1803
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1804
        nomRef = name.getNomenclaturalReference();
1805
        assertEquals(ReferenceType.Article, nomRef.getType());
1806
        assertEquals(name.getNomenclaturalMicroReference(), "errata");
1807

    
1808
        parseStr = "Yermoloffia B\u00e9l., Voy. Indes Or.: t. s.n.. 1846";
1809
        name = parser.parseReferencedName(parseStr);
1810
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1811
        nomRef = name.getNomenclaturalReference();
1812
        assertEquals(ReferenceType.Book, nomRef.getType());
1813
        assertEquals(name.getNomenclaturalMicroReference(), "t. s.n.");
1814

    
1815
        parseStr = "Gagea mauritanica Durieu, Expl. Sci. Alg\u00e9rie, Atlas: t. 45bis, f. 4. 1850";
1816
        name = parser.parseReferencedName(parseStr);
1817
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1818
        nomRef = name.getNomenclaturalReference();
1819
        assertEquals(ReferenceType.Book, nomRef.getType());
1820
        assertEquals(name.getNomenclaturalMicroReference(), "t. 45bis, f. 4");
1821

    
1822
        parseStr = "Orchis latifolia f. blyttii Rchb. f. in Reichenbach, Icon. Fl. Germ. Helv. 13-14: 60, t. 59, f. III. 1851";
1823
        name = parser.parseReferencedName(parseStr);
1824
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1825
        nomRef = name.getNomenclaturalReference();
1826
        assertEquals(ReferenceType.BookSection, nomRef.getType());
1827
        assertEquals(name.getNomenclaturalMicroReference(), "60, t. 59, f. III");
1828

    
1829
        parseStr = "Ephedra alata var. decaisnei Stapf in Denkschr. Kaiserl. Akad. Wiss., Wien. Math.-Naturwiss. Kl. 56(2): t. 1/1. 1889";
1830
        name = parser.parseReferencedName(parseStr);
1831
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1832
        nomRef = name.getNomenclaturalReference();
1833
        assertEquals(ReferenceType.Article, nomRef.getType());
1834
        assertEquals(name.getNomenclaturalMicroReference(), "t. 1/1");
1835
    }
1836

    
1837
    @Test
1838
    public final void testEditionVolumeSeries(){
1839
        //ed. 2, 2(1)
1840
        String parseStr = "Sieberia albida (L.) Spreng., Anleit. Kenntn. Gew., ed. 2, 2(1): 282. 1817";
1841
        INonViralName name = parser.parseReferencedName(parseStr);
1842
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1843
        Reference nomRef = name.getNomenclaturalReference();
1844
        Assert.assertFalse("nom.ref. should be parsable", nomRef.isProtectedTitleCache());
1845
        assertEquals(ReferenceType.Book, nomRef.getType());
1846
        assertEquals("2", nomRef.getEdition());
1847
        assertEquals("2(1)", nomRef.getVolume());
1848

    
1849
        parseStr = "Gagea glacialis var. joannis (Grossh.) Grossh., Fl. Kavkaza, ed. 2, 2: 105. 1940";
1850
        name = parser.parseReferencedName(parseStr);
1851
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1852
        nomRef = name.getNomenclaturalReference();
1853
        Assert.assertFalse("nom.ref. should be parsable", nomRef.isProtectedTitleCache());
1854
        assertEquals(ReferenceType.Book, nomRef.getType());
1855
        assertEquals("2", nomRef.getEdition());
1856
        assertEquals("2", nomRef.getVolume());
1857

    
1858
        //14-15
1859
        parseStr = "Semele gayae (Webb & Berthel.) Svent. & Kunkel, Cuad. Bot. Canaria 14-15: 81. 1972";
1860
        name = parser.parseReferencedName(parseStr);
1861
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1862
        nomRef = name.getNomenclaturalReference();
1863
        Assert.assertFalse("nom.ref. should be parsable", nomRef.isProtectedTitleCache());
1864
        assertEquals(ReferenceType.Book, nomRef.getType());
1865
        assertEquals("14-15", nomRef.getVolume());
1866

    
1867
        //35-37(2)
1868
        parseStr = "Lavandula multifida var. heterotricha Sauvage in Bull. Soc. Sci. Nat. Maroc 35-37(2): 392. 1947";
1869
        name = parser.parseReferencedName(parseStr);
1870
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1871
        nomRef = name.getNomenclaturalReference();
1872
        Assert.assertFalse("nom.ref. should be parsable", nomRef.isProtectedTitleCache());
1873
        assertEquals(ReferenceType.Article, nomRef.getType());
1874
        assertNull(nomRef.getEdition());
1875
        assertEquals("35-37(2)", nomRef.getVolume());
1876

    
1877
        //Sér. 7
1878
        parseStr = "Oxynepeta involucrata Bunge, M\u00E9m. Acad. Imp. Sci. Saint P\u00E9tersbourg, S\u00E9r. 7, 21(1): 59. 1878";
1879
        name = parser.parseReferencedName(parseStr);
1880
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1881
        nomRef = name.getNomenclaturalReference();
1882
        Assert.assertFalse("nom.ref. should be parsable", nomRef.isProtectedTitleCache());
1883
        assertEquals(ReferenceType.Book, nomRef.getType());
1884
        assertNull(nomRef.getEdition());
1885
        assertEquals("21(1)", nomRef.getVolume());
1886
        //Currently we do not put the series part into the series field, this may change in future
1887
//        assertEquals("Sér. 7", nomRef.getSeriesPart());
1888

    
1889
        //Suppl. 1
1890
        parseStr = "Dissorhynchium Schauer, Nov. Actorum Acad. Caes. Leop.-Carol. Nat. Cur. 19(Suppl. 1): 434. 1843";
1891
        name = parser.parseReferencedName(parseStr);
1892
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1893
        nomRef = name.getNomenclaturalReference();
1894
        Assert.assertFalse("nom.ref. should be parsable", nomRef.isProtectedTitleCache());
1895
        assertEquals(ReferenceType.Book, nomRef.getType());
1896
        assertNull(nomRef.getEdition());
1897
        assertEquals("19(Suppl. 1)", nomRef.getVolume());
1898

    
1899
        //54*B*
1900
        parseStr = "Thymus chaubardii var. boeoticus (Heinr. Braun) Ronniger in Beih. Bot. Centralbl. 54B: 662. 1936";
1901
        name = parser.parseReferencedName(parseStr);
1902
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1903
        nomRef = name.getNomenclaturalReference();
1904
        Assert.assertFalse("nom.ref. should be parsable", nomRef.isProtectedTitleCache());
1905
        assertEquals(ReferenceType.Article, nomRef.getType());
1906
        assertNull(nomRef.getEdition());
1907
        assertEquals("54B", nomRef.getVolume());
1908

    
1909

    
1910
        //1, Erg.
1911
        Pattern seriesPattern = Pattern.compile(NonViralNameParserImplRegExBase.volume);
1912
        Matcher matcher = seriesPattern.matcher("12(1, Erg.)");
1913
        Assert.assertTrue("12(1, Erg.) should match", matcher.matches());
1914

    
1915
        parseStr = "Scilla amethystina Vis. in Flora Abt Awer Ser 12(1, Erg.): 11. 1829";
1916
        name = parser.parseReferencedName(parseStr);
1917
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1918
        nomRef = name.getNomenclaturalReference();
1919
        Assert.assertFalse("nom.ref. should be parsable", nomRef.isProtectedTitleCache());
1920
        assertEquals(ReferenceType.Article, nomRef.getType());
1921
        assertNull(nomRef.getEdition());
1922
        assertEquals("12(1, Erg.)", nomRef.getVolume());
1923

    
1924
        // jubilee ed.
1925
        parseStr = "Orchis sambucina var. bracteata (M. Schulze) Harz, Fl. Deutschl., jubilee ed., 4: 271. 1895";
1926
        name = parser.parseReferencedName(parseStr);
1927
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1928
        nomRef = name.getNomenclaturalReference();
1929
        Assert.assertFalse("nom.ref. should be parsable", nomRef.isProtectedTitleCache());
1930
        assertEquals(ReferenceType.Book, nomRef.getType());
1931
        assertEquals("jubilee ed.",nomRef.getEdition());
1932
        assertEquals("4", nomRef.getVolume());
1933
        assertEquals(parseStr, name.getFullTitleCache());
1934

    
1935
        //nouv. ed.
1936
        parseStr = "Fraxinus polemonifolia Poir. in Duhamel du Monceau, Trait\u00E9 Arbr. Arbust., nouv. ed., 4: 66. 1809";
1937
        name = parser.parseReferencedName(parseStr);
1938
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1939
        nomRef = name.getNomenclaturalReference();
1940
        Assert.assertFalse("nom.ref. should be parsable", nomRef.isProtectedTitleCache());
1941
        assertEquals(ReferenceType.BookSection, nomRef.getType());
1942
        assertEquals("nouv. ed.",nomRef.getInReference().getEdition());
1943
        assertEquals("4", nomRef.getInReference().getVolume());
1944
        assertEquals(parseStr, name.getFullTitleCache());
1945

    
1946
        //ed. 3B
1947
        parseStr = "Juncus supinus var. kochii (F. W. Schultz) Syme in Smith, Engl. Bot., ed. 3B, 10: 33. 1870";
1948
        name = parser.parseReferencedName(parseStr);
1949
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1950
        nomRef = name.getNomenclaturalReference();
1951
        Assert.assertFalse("nom.ref. should be parsable", nomRef.isProtectedTitleCache());
1952
        assertEquals(ReferenceType.BookSection, nomRef.getType());
1953
        //maybe we remove ed. for this case in future
1954
        assertEquals("ed. 3B",nomRef.getInReference().getEdition());
1955
        assertEquals("10", nomRef.getInReference().getVolume());
1956
        assertEquals(parseStr, name.getFullTitleCache());
1957

    
1958
        //ed. 15 bis
1959
        parseStr = "Solanum persicum Willd. ex Roem. & Schult., Syst. Veg., ed. 15 bis, 4: 662. 1819";
1960
        name = parser.parseReferencedName(parseStr);
1961
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1962
        nomRef = name.getNomenclaturalReference();
1963
        Assert.assertFalse("nom.ref. should be parsable", nomRef.isProtectedTitleCache());
1964
        assertEquals(ReferenceType.Book, nomRef.getType());
1965
        //maybe we remove ed. for this case in future
1966
        assertEquals("ed. 15 bis",nomRef.getEdition());
1967
        assertEquals("4", nomRef.getVolume());
1968
        assertEquals(parseStr, name.getFullTitleCache());
1969

    
1970

    
1971
//        Epipactis helleborine subsp. ohwii (Fukuy.) H. J. Su in Fl. Taiwan, ed. 2, 5: 861. 2000
1972
    }
1973

    
1974
    @Test
1975
    public final void testTitleBrackets(){
1976
        //Bot. Zhurn. (Moscow & Leningrad)
1977
        String parseStr = "Juncus subcompressus Zakirov & Novopokr. in Bot. Zhurn. (Moscow & Leningrad) 36(1): 77. 1951";
1978
        TaxonName name = parser.parseReferencedName(parseStr);
1979
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1980
        Reference nomRef = name.getNomenclaturalReference();
1981
        Assert.assertFalse("nom.ref. should be parsable", nomRef.isProtectedTitleCache());
1982
        assertEquals(ReferenceType.Article, nomRef.getType());
1983
        assertEquals("Bot. Zhurn. (Moscow & Leningrad)", nomRef.getInReference().getAbbrevTitle());
1984
        assertNull(nomRef.getEdition());
1985
        assertEquals("36(1)", nomRef.getVolume());
1986
    }
1987

    
1988
    @Test
1989
    public final void testTitleSpecials(){
1990
        //Pt. 2  (currently handled as series part, may change in future
1991
        String parseStr = "Iris pumila subsp. sintenisiiformis Prod\u00E1n in Ann. Sci. Univ. Jassy, Pt. 2, Sci. Nat. 27: 89. 1941";
1992
        TaxonName name = parser.parseReferencedName(parseStr);
1993
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1994
        Reference nomRef = name.getNomenclaturalReference();
1995
        Assert.assertFalse("nom.ref. should be parsable", nomRef.isProtectedTitleCache());
1996
        assertEquals(ReferenceType.Article, nomRef.getType());
1997
        assertEquals("Ann. Sci. Univ. Jassy, Pt. 2, Sci. Nat.", nomRef.getInReference().getAbbrevTitle());
1998
        assertNull(nomRef.getEdition());
1999
        assertEquals("27", nomRef.getVolume());
2000

    
2001
        //same as Pt. 2, "Sect. xx" handled as series part but may change
2002
        parseStr = "Quercus boissieri var. microphylla (A. Camus) Zohary in Bull. Res. Council Israel, Sect. D, Bot. 9: 169. 1961";
2003
        name = parser.parseReferencedName(parseStr);
2004
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2005
        nomRef = name.getNomenclaturalReference();
2006
        Assert.assertFalse("nom.ref. should be parsable", nomRef.isProtectedTitleCache());
2007
        assertEquals(ReferenceType.Article, nomRef.getType());
2008
        assertEquals("Bull. Res. Council Israel, Sect. D, Bot.", nomRef.getInReference().getAbbrevTitle());
2009
        assertNull(nomRef.getEdition());
2010
        assertEquals("9", nomRef.getVolume());
2011

    
2012
        //see above
2013
        parseStr = "Fimbristylis dichotoma var. annua (All.) T. Koyama in J. Fac. Sci. Univ. Tokyo, Sect. 3, Bot. 8: 111. 1961";
2014
        name = parser.parseReferencedName(parseStr);
2015
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2016
        nomRef = name.getNomenclaturalReference();
2017
        Assert.assertFalse("nom.ref. should be parsable", nomRef.isProtectedTitleCache());
2018
        assertEquals(ReferenceType.Article, nomRef.getType());
2019
        assertEquals("J. Fac. Sci. Univ. Tokyo, Sect. 3, Bot.", nomRef.getInReference().getAbbrevTitle());
2020
        assertNull(nomRef.getEdition());
2021
        assertEquals("8", nomRef.getVolume());
2022

    
2023

    
2024
        // "- "
2025
        parseStr = "Theresia tulipilfoia (M. Bieb.) Klatt in Hamburger Garten- Blumenzeitung 16: 438. 1860";
2026
        name = parser.parseReferencedName(parseStr);
2027
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2028
        nomRef = name.getNomenclaturalReference();
2029
        Assert.assertFalse("nom.ref. should be parsable", nomRef.isProtectedTitleCache());
2030
        assertEquals(ReferenceType.Article, nomRef.getType());
2031
        assertEquals("Hamburger Garten- Blumenzeitung", nomRef.getInReference().getAbbrevTitle());
2032
        assertNull(nomRef.getEdition());
2033
        assertEquals("16", nomRef.getVolume());
2034

    
2035
        parseStr = "Hyssopus officinalis var. pilifer Pant. in Verh. Vereins Natur- Heilk. Presburg, n.s., 2: 61. 1874";
2036
        name = parser.parseReferencedName(parseStr);
2037
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2038
        nomRef = name.getNomenclaturalReference();
2039
        Assert.assertFalse("nom.ref. should be parsable", nomRef.isProtectedTitleCache());
2040
        assertEquals(ReferenceType.Article, nomRef.getType());
2041
        //, n.s., is not necessarily part of the title in future
2042
        assertEquals("Verh. Vereins Natur- Heilk. Presburg", nomRef.getInReference().getAbbrevTitle());
2043
        assertNull(nomRef.getEdition());
2044
        assertEquals("n.s.", nomRef.getSeriesPart());
2045
        assertEquals("2", nomRef.getVolume());
2046

    
2047
          //Note: space in E+M, no space in IPNI; is it really a book?
2048
        parseStr = "Amaryllis dubia Houtt., Handl. Pl.- Kruidk. 12: 181. 1780";
2049
        name = parser.parseReferencedName(parseStr);
2050
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2051
        nomRef = name.getNomenclaturalReference();
2052
        Assert.assertFalse("nom.ref. should be parsable", nomRef.isProtectedTitleCache());
2053
        assertEquals(ReferenceType.Book, nomRef.getType());
2054
        assertEquals("Handl. Pl.- Kruidk.", nomRef.getAbbrevTitle());
2055
        assertNull(nomRef.getEdition());
2056
        assertEquals("12", nomRef.getVolume());
2057

    
2058
        // "..."
2059
        parseStr = "Chamaesyce biramensis (Urb.) Alain in Contr. Ocas. Mus. Hist. Nat. Colegio \"De La Salle\" 11: 12. 1952";
2060
        name = parser.parseReferencedName(parseStr);
2061
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2062
        nomRef = name.getNomenclaturalReference();
2063
        Assert.assertFalse("nom.ref. should be parsable", nomRef.isProtectedTitleCache());
2064
        assertEquals(ReferenceType.Article, nomRef.getType());
2065
        assertEquals("Contr. Ocas. Mus. Hist. Nat. Colegio \"De La Salle\"", nomRef.getInReference().getAbbrevTitle());
2066
        assertNull(nomRef.getEdition());
2067
        assertEquals("11", nomRef.getVolume());
2068

    
2069
        //' & '
2070
        parseStr = "Mannaphorus Raf. in Amer. Monthly Mag. & Crit. Rev. 1: 175. 1818";
2071
        name = parser.parseReferencedName(parseStr);
2072
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2073
        nomRef = name.getNomenclaturalReference();
2074
        Assert.assertFalse("nom.ref. should be parsable", nomRef.isProtectedTitleCache());
2075
        assertEquals(ReferenceType.Article, nomRef.getType());
2076
        assertEquals("Amer. Monthly Mag. & Crit. Rev.", nomRef.getInReference().getAbbrevTitle());
2077
        assertNull(nomRef.getEdition());
2078
        assertEquals("1", nomRef.getVolume());
2079

    
2080
        //only for debugging
2081
        boolean  matches;
2082
        matches = "Flo & Amer. Fauna. Ab.".matches (NonViralNameParserImplRegExBase.referenceTitleFirstPart + "*");
2083
        Assert.assertTrue("referenceTitleFirstPart", matches);
2084

    
2085
        matches = "Fl. Amer. & Fauna. Ab. 101".matches (NonViralNameParserImplRegExBase.pSoftArticleReference);
2086
        Assert.assertTrue("pSoftArticleReference", matches);
2087
        //only for debugging end
2088

    
2089
        parseStr = "Corallorhiza trifida subsp. virescens (Drejer) L\u00F8jtnant in Fl. & Fauna (Esbjerg) 101: 71. 1996";
2090
        name = parser.parseReferencedName(parseStr);
2091
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2092
        nomRef = name.getNomenclaturalReference();
2093
        Assert.assertFalse("nom.ref. should be parsable", nomRef.isProtectedTitleCache());
2094
        assertEquals(ReferenceType.Article, nomRef.getType());
2095
        assertEquals("Fl. & Fauna (Esbjerg)", nomRef.getInReference().getAbbrevTitle());
2096
        assertNull(nomRef.getEdition());
2097
        assertEquals("101", nomRef.getVolume());
2098

    
2099
        parseStr = "Crocus isauricus Siehe ex Bowles, Handb. Crocus & Colch.: 126. 1924";
2100
        name = parser.parseReferencedName(parseStr);
2101
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2102
        nomRef = name.getNomenclaturalReference();
2103
        Assert.assertFalse("nom.ref. should be parsable", nomRef.isProtectedTitleCache());
2104
        assertEquals(ReferenceType.Book, nomRef.getType());
2105
        assertEquals("Handb. Crocus & Colch.", nomRef.getAbbrevTitle());
2106
        assertNull(nomRef.getEdition());
2107
        assertNull(nomRef.getVolume());
2108

    
2109
        parseStr = "Ornithogalum bifolium (L.) Neck. in Hist. & Commentat. Acad. Elect. Sci. Theod.-Palat. 2: 461. 1770";
2110
        name = parser.parseReferencedName(parseStr);
2111
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2112
        nomRef = name.getNomenclaturalReference();
2113
        Assert.assertFalse("nom.ref. should be parsable", nomRef.isProtectedTitleCache());
2114
        assertEquals(ReferenceType.Article, nomRef.getType());
2115
        assertEquals("Hist. & Commentat. Acad. Elect. Sci. Theod.-Palat.", nomRef.getInReference().getAbbrevTitle());
2116
        assertNull(nomRef.getEdition());
2117
        assertEquals("2", nomRef.getVolume());
2118

    
2119
    }
2120

    
2121
    @Test
2122
    public final void testArticlePattern(){
2123
        Pattern articlePattern = Pattern.compile(NonViralNameParserImplRegExBase.pArticleReference);
2124
        Matcher matcher = articlePattern.matcher("Acta Bot. Hung. 46 (1-2)");
2125
        Assert.assertTrue("", matcher.matches());
2126
        matcher = articlePattern.matcher("Nova Guinea Bla 9");
2127
        Assert.assertTrue("", matcher.matches());
2128
        matcher = articlePattern.matcher("Nova Guinea Bla , n.s., 9");
2129
        Assert.assertTrue("", matcher.matches());
2130
    }
2131

    
2132

    
2133
    @Test
2134
    public final void testSeriesPart(){
2135
        Pattern seriesPattern = Pattern.compile(NonViralNameParserImplRegExBase.pSeriesPart);
2136
        Matcher matcher = seriesPattern.matcher(", ser. 2,");
2137
        Assert.assertTrue("", matcher.matches());
2138

    
2139
        matcher = seriesPattern.matcher("n.s.");
2140
        Assert.assertTrue("", matcher.matches());
2141

    
2142
//        matcher = seriesPattern.matcher("a.s.");
2143
//        Assert.assertTrue("", matcher.matches());
2144

    
2145
        //do NOT match edition  //but there are such cases like "Vilm. Blumengärtn. ed. 3" according to TL-2
2146
        matcher = seriesPattern.matcher("ed. 4");
2147
        Assert.assertFalse("", matcher.matches());
2148

    
2149
        matcher = seriesPattern.matcher("Ser. C");
2150
        Assert.assertTrue("", matcher.matches());
2151

    
2152
        matcher = seriesPattern.matcher("S\u00E9r. B 1");
2153
        Assert.assertTrue("", matcher.matches());
2154

    
2155
        matcher = seriesPattern.matcher("Jerusalem Ser.");
2156
        Assert.assertTrue("", matcher.matches());
2157

    
2158
        matcher = seriesPattern.matcher("nov. Ser.");
2159
        Assert.assertTrue("", matcher.matches());
2160
    }
2161

    
2162
    @Test
2163
    public final void testFullTeams() {
2164
        logger.warn("Not yet implemented"); // TODO
2165
    }
2166

    
2167
    @Test
2168
    public final void testParseAuthorsTaxonNameString() throws StringNotParsableException {
2169
        INonViralName nvn = TaxonNameFactory.NewZoologicalInstance(null);
2170
        parser.parseAuthors(nvn, "Eckweiler & ten Hagen, 2003");
2171
        Team team = (Team)nvn.getCombinationAuthorship();
2172
        Assert.assertNotNull("Comb. author must not be null", team);
2173
        Assert.assertEquals("Must be team with 2 members", 2, team.getTeamMembers().size());
2174
        Assert.assertEquals("Second member must be 'ten Hagen'", "ten Hagen", team.getTeamMembers().get(1).getTitleCache());
2175

    
2176
        //Crosson du Cormier, 1964
2177
        IZoologicalName zooName = TaxonNameFactory.NewZoologicalInstance(null);
2178
        parser.parseAuthors(zooName, "Crosson du Cormier, 1964");
2179
        Person person = (Person)zooName.getCombinationAuthorship();
2180
        Assert.assertNotNull("Comb. author must not be null", person);
2181
        Assert.assertEquals("Persons title must be 'Crosson du Cormier'", "Crosson du Cormier", person.getTitleCache());
2182
        Assert.assertEquals("Year must be 1964", Integer.valueOf(1964), zooName.getPublicationYear() );
2183

    
2184
        //(van der Hoeven, 1839)
2185
        zooName = TaxonNameFactory.NewZoologicalInstance(null);
2186
        parser.parseAuthors(zooName, "(van der Hoeven, 1839)");
2187
        Assert.assertNull("Combination author must be null", zooName.getCombinationAuthorship());
2188
        person = (Person)zooName.getBasionymAuthorship();
2189
        Assert.assertNotNull("Basionym author must not be null", person);
2190
        Assert.assertEquals("Persons title must be 'van der Hoeven'", "van der Hoeven", person.getTitleCache());
2191
        Assert.assertEquals("Year must be 1839", Integer.valueOf(1839), zooName.getOriginalPublicationYear() );
2192

    
2193
        //le Doux, 1931
2194
        zooName = TaxonNameFactory.NewZoologicalInstance(null);
2195
        parser.parseAuthors(zooName, "le Doux, 1931");
2196
        person = (Person)zooName.getCombinationAuthorship();
2197
        Assert.assertNotNull("Comb. author must not be null", person);
2198
        Assert.assertEquals("Persons title must be 'le Doux'", "le Doux", person.getTitleCache());
2199
        Assert.assertEquals("Year must be 1931", Integer.valueOf(1931), zooName.getPublicationYear() );
2200

    
2201

    
2202
    }
2203

    
2204
    @Test  //#4764
2205
    public void testParseSection(){
2206
        //this test does not really test problematic cases where sect.idInVoc = "sect." instead of "sect.(bot.)"
2207
        //however, by changing the csv file entry to sect. just for testing it can be used as a functional test
2208
        String sectionNameStr = "Taraxacum sect. Testtaxa M\u00fcller, Incredible Taxa: 12. 2016";
2209
        INonViralName sectionName = parser.parseReferencedName(sectionNameStr, NomenclaturalCode.ICNAFP, null);
2210
        int parsingProblem = sectionName.getParsingProblem();
2211
        Assert.assertEquals("Problem should be 0", 0, parsingProblem);
2212
        Rank rank = sectionName.getRank();
2213
        Assert.assertEquals("", Rank.SECTION_BOTANY(), rank  );
2214
    }
2215

    
2216
    //#6577
2217
    @Test
2218
    public final void testParseSpNov(){
2219
        //Canabio, issue with space
2220
        INonViralName name = parser.parseFullName("Iresine sp. nov. 1");
2221
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2222
        Assert.assertEquals("sp. nov. 1", name.getSpecificEpithet());
2223

    
2224
        name = parser.parseFullName("Gomphichis sp. 22");
2225
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2226
        Assert.assertEquals("sp. 22", name.getSpecificEpithet());
2227

    
2228
        name = parser.parseFullName("Phleum sp. nov.");
2229
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2230
        Assert.assertEquals("sp. nov.", name.getSpecificEpithet());
2231

    
2232
        name = parser.parseFullName("Phleum sp.");
2233
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2234
        Assert.assertEquals("sp.", name.getSpecificEpithet());
2235

    
2236
    }
2237

    
2238

    
2239
    @Test  //#5072
2240
    public final void testLongRunningParsingCapitals(){
2241
        DateTime start = DateTime.now();
2242
        String nameStr = "Nazeris fujianensis JIAYAO HU, LIZHEN LI, MEIJUN ZHAO,2010";  //name from CoL that created problems
2243
        INonViralName name = parser.parseReferencedName(nameStr, NomenclaturalCode.ICZN, null);
2244
        DateTime end = DateTime.now();
2245
        Duration duration = new Duration(start, end);
2246
        long seconds = duration.getStandardSeconds();
2247
        //this is the critical part of the test that must not be changed
2248
        Assert.assertTrue("Parsing of name should take less then 3 seconds but took " + seconds, seconds < 3);
2249

    
2250
    }
2251

    
2252
    @Test  //#5072
2253
    //http://www.regular-expressions.info/catastrophic.html
2254
    public final void testLongRunningParsing(){
2255

    
2256
        //name only
2257
        String nameStr = "Dictyocoela berillonum R.S. Terry, J.E. Sm., R.G. Sharpe, T. Rigaud, D.T.J. Littlewood, J.E. Ironside, D. Rollinson & D. Bou";
2258
        DateTime start = DateTime.now();
2259
        INonViralName name = parser.parseReferencedName(nameStr, NomenclaturalCode.ICNAFP, null);
2260
        DateTime end = DateTime.now();
2261
        Duration duration = new Duration(start, end);
2262
        long seconds = duration.getStandardSeconds();
2263
        //this is the critical part of the test that must not be changed
2264
        Assert.assertTrue("Parsing of name should take less then 3 seconds but took " + seconds, seconds < 3);
2265
        //the following may be discussed
2266
        Assert.assertFalse("Name should parse without problems",name.hasProblem());
2267

    
2268

    
2269
        //with reference
2270
        nameStr = "Dictyocoela berillonum R.S. Terry, J.E. Sm., R.G. Sharpe, T. Rigaud, D.T.J. Littlewood, J.E. Ironside, D. Rollinson & D. Bou in Species Fauna Atlantica Of Blues Animals 3: p.345. 1758.";
2271
        start = DateTime.now();
2272
        name = parser.parseReferencedName(nameStr, NomenclaturalCode.ICNAFP, null);
2273
        end = DateTime.now();
2274
        duration = new Duration(start, end);
2275
        seconds = duration.getStandardSeconds();
2276
        //this is the critical part of the test that must not be changed
2277
        Assert.assertTrue("Parsing of name should take less then 3 seconds but took " + seconds, seconds < 3);
2278
        //the following may be discussed
2279
        Assert.assertFalse("Name should parse without problems",name.hasProblem());
2280
    }
2281

    
2282
    @Test  //#5072
2283
    public final void testLongRunningParsingAuthors(){
2284
        //http://www.regular-expressions.info/catastrophic.html
2285
        //
2286
        //Länge des Nachnamens macht keinen Unterschied
2287
        //Anzahl der "AuthorParts scheint entscheidend
2288
        // & am Ende macht es langsamger (16s), als nur ","(6s))
2289

    
2290
        String authorStr = "R.S. Terry J.E. Sm. R.G. Sharpe T. Rigaud T.H. Rigseaud D.T. Li, R.G. Sharpe, T. Rigaud, D.T.J. Littlewood & D. Bou";
2291
        TeamOrPersonBase[] authorArray = new TeamOrPersonBase[4];
2292
        try {
2293
            DateTime start = DateTime.now();
2294
            parser.fullAuthors(authorStr, authorArray, new Integer[]{1800, null, null, null}, NomenclaturalCode.ICNAFP);
2295
            DateTime end = DateTime.now();
2296
            Duration duration = new Duration(start, end);
2297
            long seconds = duration.getStandardSeconds();
2298
//            System.out.println(seconds);
2299
            //this is the critical part of the test that must not be changed
2300
            Assert.assertTrue("Parsing of name should take less then 3 seconds but took " + seconds, seconds < 3);
2301
        } catch (StringNotParsableException e) {
2302
            e.printStackTrace();
2303
            Assert.fail("Authors should be parsable");
2304
        }
2305

    
2306
    }
2307

    
2308

    
2309
    /**
2310
     * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#AuthorshipAndEx(java.lang.String)}.
2311
     */
2312
    @Test
2313
    public final void testAuthorshipAndEx() {
2314
        logger.warn("Not yet implemented"); // TODO
2315
    }
2316

    
2317
    /**
2318
     * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#Authorship(java.lang.String)}.
2319
     */
2320
    @Test
2321
    public final void testAuthorship() {
2322
        logger.warn("Not yet implemented"); // TODO
2323
    }
2324

    
2325
    @Test
2326
    public final void testParseCultivar() {
2327

    
2328
        TaxonName name;
2329

    
2330
        //cultivar
2331
        String cultivar = "Abies 'Albus'";
2332
        name = (TaxonName)parser.parseFullName(cultivar);
2333
        Assert.assertEquals("Abies", name.getGenusOrUninomial());
2334
        Assert.assertEquals("Albus", name.getCultivarName());
2335
        Assert.assertEquals("Abies 'Albus'", name.getNameCache());
2336
        Assert.assertEquals(Rank.uuidCultivar, name.getRank().getUuid());
2337

    
2338
        cultivar = "Abies 'Beryl, Viscountess Cowdray'";
2339
        name = (TaxonName)parser.parseFullName(cultivar);
2340
        Assert.assertEquals("Abies", name.getGenusOrUninomial());
2341
        Assert.assertEquals("Beryl, Viscountess Cowdray", name.getCultivarName());
2342
        Assert.assertEquals("Abies 'Beryl, Viscountess Cowdray'", name.getNameCache());
2343
        Assert.assertEquals(Rank.uuidCultivar, name.getRank().getUuid());
2344

    
2345
        cultivar = "Abies 'Jeanne d’Arc'";
2346
        name = (TaxonName)parser.parseFullName(cultivar);
2347
        Assert.assertEquals("Abies", name.getGenusOrUninomial());
2348
        Assert.assertEquals("Jeanne d’Arc", name.getCultivarName());
2349
        Assert.assertEquals("Abies 'Jeanne d’Arc'", name.getNameCache());
2350
        Assert.assertEquals(Rank.uuidCultivar, name.getRank().getUuid());
2351

    
2352
        cultivar = "Abies 'Oh Boy!'";
2353
        name = (TaxonName)parser.parseFullName(cultivar);
2354
        Assert.assertEquals("Abies", name.getGenusOrUninomial());
2355
        Assert.assertEquals("Oh Boy!", name.getCultivarName());
2356
        Assert.assertEquals("Abies 'Oh Boy!'", name.getNameCache());
2357
        Assert.assertEquals(Rank.uuidCultivar, name.getRank().getUuid());
2358

    
2359
        cultivar = "Abies 'E.A. Bowles'";
2360
        name = (TaxonName)parser.parseFullName(cultivar);
2361
        Assert.assertEquals("Abies", name.getGenusOrUninomial());
2362
        Assert.assertEquals("E.A. Bowles", name.getCultivarName());
2363
        Assert.assertEquals("Abies 'E.A. Bowles'", name.getNameCache());
2364
        Assert.assertEquals(Rank.uuidCultivar, name.getRank().getUuid());
2365

    
2366
        cultivar = "Abies 'ENT/100'";
2367
        name = (TaxonName)parser.parseFullName(cultivar);
2368
        Assert.assertEquals("Abies", name.getGenusOrUninomial());
2369
        Assert.assertEquals("ENT/100", name.getCultivarName());
2370
        Assert.assertEquals("Abies 'ENT/100'", name.getNameCache());
2371
        Assert.assertEquals(Rank.uuidCultivar, name.getRank().getUuid());
2372

    
2373
        cultivar = "Abies 'Go-go  Dancer'";
2374
        name = (TaxonName)parser.parseFullName(cultivar);
2375
        Assert.assertEquals("Abies", name.getGenusOrUninomial());
2376
        Assert.assertEquals("Go-go Dancer", name.getCultivarName());
2377
        Assert.assertEquals("Abies 'Go-go Dancer'", name.getNameCache());
2378
        Assert.assertEquals(Rank.uuidCultivar, name.getRank().getUuid());
2379

    
2380
        cultivar = "Abies 'ENT\\100'";
2381
        name = (TaxonName)parser.parseFullName(cultivar);
2382
        Assert.assertEquals("Abies", name.getGenusOrUninomial());
2383
        Assert.assertEquals("ENT\\100", name.getCultivarName());
2384
        Assert.assertEquals("Abies 'ENT\\100'", name.getNameCache());
2385
        Assert.assertEquals(Rank.uuidCultivar, name.getRank().getUuid());
2386

    
2387
        cultivar = "Abies alba 'Albus'";
2388
        name = (TaxonName)parser.parseFullName(cultivar);
2389
        Assert.assertEquals("Abies", name.getGenusOrUninomial());
2390
        Assert.assertEquals("alba", name.getSpecificEpithet());
2391
        Assert.assertEquals("Albus", name.getCultivarName());
2392
        Assert.assertEquals("Abies alba 'Albus'", name.getNameCache());
2393
        Assert.assertEquals(Rank.uuidCultivar, name.getRank().getUuid());
2394

    
2395
        //cultivar group
2396
        String group = "Abies Albus Group";
2397
        name = (TaxonName)parser.parseFullName(group);
2398
        Assert.assertEquals("Abies", name.getGenusOrUninomial());
2399
        Assert.assertNull(name.getSpecificEpithet());
2400
        Assert.assertEquals("Albus Group", name.getCultivarGroup());
2401
        Assert.assertEquals("Abies Albus Group", name.getNameCache());
2402
        Assert.assertEquals(Rank.uuidCultivarGroup, name.getRank().getUuid());
2403

    
2404
        group = "Abies Albus Gp";
2405
        name = (TaxonName)parser.parseFullName(group);
2406
        Assert.assertEquals("Abies", name.getGenusOrUninomial());
2407
        Assert.assertNull(name.getSpecificEpithet());
2408
        Assert.assertEquals("Albus Gp", name.getCultivarGroup());
2409
        Assert.assertEquals("Abies Albus Gp", name.getNameCache());
2410
        Assert.assertEquals(Rank.uuidCultivarGroup, name.getRank().getUuid());
2411

    
2412
        group = "Abies Gruppo Albus";
2413
        name = (TaxonName)parser.parseFullName(group);
2414
        Assert.assertEquals("Abies", name.getGenusOrUninomial());
2415
        Assert.assertNull(name.getSpecificEpithet());
2416
        Assert.assertEquals("Gruppo Albus", name.getCultivarGroup());
2417
        Assert.assertEquals("Abies Gruppo Albus", name.getNameCache());
2418
        Assert.assertEquals(Rank.uuidCultivarGroup, name.getRank().getUuid());
2419

    
2420
        //grex
2421
        String grex = "Abies Albus grex";
2422
        name = (TaxonName)parser.parseFullName(grex);
2423
        Assert.assertEquals("Abies", name.getGenusOrUninomial());
2424
        Assert.assertNull(name.getSpecificEpithet());
2425
        Assert.assertEquals("Albus grex", name.getCultivarGroup());
2426
        Assert.assertEquals("Abies Albus grex", name.getNameCache());
2427
        Assert.assertEquals(Rank.uuidGrex, name.getRank().getUuid());
2428

    
2429
        grex = "Abies Albus Second grex";
2430
        name = (TaxonName)parser.parseFullName(grex);
2431
        Assert.assertEquals("Abies", name.getGenusOrUninomial());
2432
        Assert.assertNull(name.getSpecificEpithet());
2433
        Assert.assertEquals("Albus Second grex", name.getCultivarGroup());
2434
        Assert.assertEquals("Abies Albus Second grex", name.getNameCache());
2435
        Assert.assertEquals(Rank.uuidGrex, name.getRank().getUuid());
2436

    
2437
        //combined
2438
        String combined = "Abies (Albus Gruppo) 'Pretty'";
2439
        name = (TaxonName)parser.parseFullName(combined);
2440
        Assert.assertEquals("Abies", name.getGenusOrUninomial());
2441
        Assert.assertNull(name.getSpecificEpithet());
2442
        Assert.assertEquals("Pretty", name.getCultivarName());
2443
        Assert.assertEquals("Albus Gruppo", name.getCultivarGroup());
2444
        Assert.assertEquals(combined, name.getNameCache());
2445
        Assert.assertEquals(Rank.uuidCultivar, name.getRank().getUuid());
2446

    
2447
        combined = "Abies White grex (Albus Gruppo) 'Pretty'";
2448
        name = (TaxonName)parser.parseFullName(combined);
2449
        Assert.assertEquals("Abies", name.getGenusOrUninomial());
2450
        Assert.assertNull(name.getSpecificEpithet());
2451
        Assert.assertEquals("Pretty", name.getCultivarName());
2452
        Assert.assertEquals("White grex Albus Gruppo", name.getCultivarGroup());
2453
        Assert.assertEquals(combined, name.getNameCache());
2454
        Assert.assertEquals(Rank.uuidCultivar, name.getRank().getUuid());
2455

    
2456
        combined = "Abies White grex Albus Gruppo";
2457
        name = (TaxonName)parser.parseFullName(combined);
2458
        Assert.assertEquals("Abies", name.getGenusOrUninomial());
2459
        Assert.assertNull(name.getSpecificEpithet());
2460
        Assert.assertEquals("White grex Albus Gruppo", name.getCultivarGroup());
2461
        Assert.assertEquals(combined, name.getNameCache());
2462
        Assert.assertEquals(Rank.uuidCultivarGroup, name.getRank().getUuid());
2463

    
2464
        //incorrect combinations
2465
        combined = "Abies White grex (Albus Gruppo)";
2466
        name = (TaxonName)parser.parseFullName(combined);
2467
        Assert.assertTrue(name.isProtectedTitleCache());
2468
        Assert.assertNull(name.getGenusOrUninomial());
2469
        Assert.assertNull(name.getSpecificEpithet());
2470
        Assert.assertNull(name.getCultivarName());
2471
        Assert.assertNull(name.getCultivarGroup());
2472
        Assert.assertEquals(combined, name.getNameCache());
2473
        Assert.assertNull(name.getRank());
2474

    
2475
        combined = "Abies Albus Gruppo 'Pretty'";
2476
        name = (TaxonName)parser.parseFullName(combined);
2477
        Assert.assertTrue(name.isProtectedTitleCache());
2478
        Assert.assertNull(name.getGenusOrUninomial());
2479
        Assert.assertNull(name.getSpecificEpithet());
2480
        Assert.assertNull(name.getCultivarName());
2481
        Assert.assertNull(name.getCultivarGroup());
2482
        Assert.assertEquals(combined, name.getNameCache());
2483
        Assert.assertNull(name.getRank());
2484
    }
2485

    
2486
    @Test
2487
    public final void testNomenclaturalStatus() {
2488
        IBotanicalName name = TaxonNameFactory.NewBotanicalInstance(Rank.FAMILY(), "Acanthopale", null, null, null, null, null, null, null);
2489
        name.addStatus(NomenclaturalStatus.NewInstance(NomenclaturalStatusType.ALTERNATIVE()));
2490
        IBotanicalName name2 = TaxonNameFactory.NewBotanicalInstance(Rank.FAMILY());
2491
        parser.parseReferencedName(name2, name.getFullTitleCache(), name2.getRank(), true);
2492
        parser.parseReferencedName(name2, name.getFullTitleCache(), name2.getRank(), true);
2493
        Assert.assertEquals("Title cache should be same. No duplication of nom. status should take place", name.getFullTitleCache(), name2.getFullTitleCache());
2494
    }
2495

    
2496
    @Test
2497
    public final void testSpecificAuthors(){
2498
        //McVaugh
2499
        INonViralName name = parser.parseFullName("Psidium longipes var. orbiculare (O.Berg) McVaugh");
2500
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2501
        TeamOrPersonBase<?> combinationAuthor = name.getCombinationAuthorship();
2502
        assertEquals( "McVaugh", combinationAuthor.getNomenclaturalTitleCache());
2503
        TeamOrPersonBase<?> basionymAuthor = name.getBasionymAuthorship();
2504
        assertEquals( "O.Berg", basionymAuthor.getNomenclaturalTitleCache());
2505

    
2506
//      Campanula rhodensis A. DC.
2507

    
2508
    }
2509

    
2510
    @Test
2511
    public final void testBookSectionAuthors(){
2512
        INonViralName name;
2513
        Reference nomRef;
2514
        String title;
2515
        String str;
2516

    
2517
        str = "Pancratium sickenbergeri Asch. & Schweinf. in Barbey-Boissier & Barbey, Herb. Levant: 158. 1882";
2518
        str = "Pancratium sickenbergeri Asch. & Schweinf. in Barbey-Boissier & Barbey, Herb. Levant: 158. 1882";
2519
        name = parser.parseReferencedName(str);
2520
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2521
        TeamOrPersonBase<?> combinationAuthor = name.getCombinationAuthorship();
2522
        assertEquals( "Asch. & Schweinf.", combinationAuthor.getNomenclaturalTitleCache());
2523
        nomRef = name.getNomenclaturalReference();
2524
        assertEquals(ReferenceType.BookSection, nomRef.getType());
2525
        assertEquals( "Barbey-Boissier & Barbey", nomRef.getInReference().getAuthorship().getNomenclaturalTitleCache());
2526
        title = nomRef.getInReference().getAbbrevTitle();
2527
        assertEquals( "Herb. Levant", title);
2528

    
2529
        name = parser.parseReferencedName("Luzula multiflora subsp. pallescens (Sw.) Reichg. in Van Ooststroom & al., Fl. Neerl. 1: 208. 1964");
2530
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2531
        assertEquals( "Reichg.", name.getCombinationAuthorship().getNomenclaturalTitleCache());
2532
        nomRef = name.getNomenclaturalReference();
2533
        assertEquals(ReferenceType.BookSection, nomRef.getType());
2534
        assertEquals( "Van Ooststroom & al.", nomRef.getInReference().getAuthorship().getNomenclaturalTitleCache());
2535
        title = nomRef.getInReference().getAbbrevTitle();
2536
        assertEquals( "Fl. Neerl.", title);
2537

    
2538
        str = "Salvia pratensis var. albiflora T. Durand in De Wildeman & Durand, Prodr. Fl. Belg. 3: 663. 1899";
2539
        name = parser.parseReferencedName(str);
2540
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2541
        assertEquals( "T. Durand", name.getCombinationAuthorship().getNomenclaturalTitleCache());
2542
        nomRef = name.getNomenclaturalReference();
2543
        assertEquals(ReferenceType.BookSection, nomRef.getType());
2544
        assertEquals( "De Wildeman & Durand", nomRef.getInReference().getAuthorship().getNomenclaturalTitleCache());
2545
        title = nomRef.getInReference().getAbbrevTitle();
2546
        assertEquals( "Prodr. Fl. Belg.", title);
2547

    
2548
        str = "Bravoa Lex. in La Llave & Lexarza, Nov. Veg. Desc. 1: 6. 1824";
2549
        name = parser.parseReferencedName(str);
2550
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2551
        assertEquals( "Lex.", name.getCombinationAuthorship().getNomenclaturalTitleCache());
2552
        nomRef = name.getNomenclaturalReference();
2553
        assertEquals(ReferenceType.BookSection, nomRef.getType());
2554
        assertEquals( "La Llave & Lexarza", nomRef.getInReference().getAuthorship().getNomenclaturalTitleCache());
2555
        title = nomRef.getInReference().getAbbrevTitle();
2556
        assertEquals( "Nov. Veg. Desc.", title);
2557

    
2558
        str = "Thymus trachselianus var. vallicola Heinr. Braun in Dalla Torre & Sarnthein, Fl. Tirol 6(3): 204. 1912";
2559
        name = parser.parseReferencedName(str);
2560
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2561
        nomRef = name.getNomenclaturalReference();
2562
        assertEquals(ReferenceType.BookSection, nomRef.getType());
2563
        assertEquals( "Dalla Torre & Sarnthein", nomRef.getInReference().getAuthorship().getNomenclaturalTitleCache());
2564
        title = nomRef.getInReference().getAbbrevTitle();
2565
        assertEquals( "Fl. Tirol", title);
2566

    
2567
        //see #openIssues
2568
//        str = "Iris xiphium var. lusitanica (Ker Gawl.) Franco in Amaral Franco & Rocha Afonso, Nova Fl. Portugal 3: 135. 1994";
2569
//        name = parser.parseReferencedName(str);
2570
//        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2571
//        nomRef = name.getNomenclaturalReference();
2572
//        assertEquals(ReferenceType.BookSection, nomRef.getType());
2573
//        assertEquals( "Amaral Franco & Rocha Afonso", nomRef.getInReference().getAuthorship().getNomenclaturalTitleCache());
2574
//        title = nomRef.getInReference().getAbbrevTitle();
2575
//        assertEquals( "Nova Fl. Portugal", title);
2576
//
2577
//        str = "Fritillaria mutabilis Kamari in Strid & Kit Tan, Mount. Fl. Greece 2: 679. 1991";
2578
//        name = parser.parseReferencedName(str);
2579
//        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2580
//        nomRef = name.getNomenclaturalReference();
2581
//        assertEquals(ReferenceType.BookSection, nomRef.getType());
2582
//        assertEquals( "Strid & Kit Tan", nomRef.getInReference().getAuthorship().getNomenclaturalTitleCache());
2583
//        title = nomRef.getInReference().getAbbrevTitle();
2584
//        assertEquals( "Mount. Fl. Greece", title);
2585

    
2586
    }
2587

    
2588
    @Test
2589
    public final void testDatePublished(){
2590

    
2591
        INonViralName name = parser.parseReferencedName("Calamintha transsilvanica (J\u00e1v.) So\u00f3 in Acta Bot. Acad. Sci. Hung. 23: 382. 1977 publ. 1978");
2592
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2593
        Reference nomRef = name.getNomenclaturalReference();
2594
        assertEquals(ReferenceType.Article, nomRef.getType());
2595
        assertEquals("1978 [\"1977\"]", nomRef.getDatePublished().toString());
2596

    
2597
        name = parser.parseReferencedName("Calamintha transsilvanica (J\u00e1v.) So\u00f3 in Acta Bot. Acad. Sci. Hung. 23: 382. 4 Apr 1977");
2598
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2599
        nomRef = name.getNomenclaturalReference();
2600
        assertEquals(ReferenceType.Article, nomRef.getType());
2601
        assertEquals("4 Apr 1977", nomRef.getDatePublished().toString());
2602
        assertEquals(Integer.valueOf(4), nomRef.getDatePublished().getStartMonth());
2603

    
2604
        name = parser.parseReferencedName("Calamintha transsilvanica (J\u00e1v.) So\u00f3 in Acta Bot. Acad. Sci. Hung. 23: 382. Feb-Apr 1977");
2605
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2606
        nomRef = name.getNomenclaturalReference();
2607
        assertEquals(ReferenceType.Article, nomRef.getType());
2608
        assertEquals("Feb"+SEP+"Apr 1977", nomRef.getDatePublished().toString());
2609
        assertEquals(Integer.valueOf(2), nomRef.getDatePublished().getStartMonth());
2610
        assertEquals(Integer.valueOf(4), nomRef.getDatePublished().getEndMonth());
2611
        assertEquals(Integer.valueOf(1977), nomRef.getDatePublished().getStartYear());
2612
        assertEquals(Integer.valueOf(1977), nomRef.getDatePublished().getEndYear());
2613
        assertNull(nomRef.getDatePublished().getStartDay());
2614
        assertNull(nomRef.getDatePublished().getEndDay());
2615
    }
2616

    
2617

    
2618
    @Test
2619
    public final void testExistingProblems(){
2620
        //Canabio, issue with space
2621
        INonViralName name = parser.parseReferencedName("Machaonia erythrocarpa var. hondurensis (Standl.) Borhidi"
2622
                + " in Acta Bot. Hung. 46 (1-2): 30. 2004");
2623
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2624
        TeamOrPersonBase<?> combinationAuthor = name.getCombinationAuthorship();
2625
        assertEquals( "Borhidi", combinationAuthor.getNomenclaturalTitleCache());
2626
        Reference nomRef = name.getNomenclaturalReference();
2627
        assertEquals(ReferenceType.Article, nomRef.getType());
2628
        assertEquals("46 (1-2)", nomRef.getVolume());
2629

    
2630
        //Canabio, detail with fig.
2631
        name = parser.parseReferencedName("Didymaea floribunda Rzed."
2632
                + " in Bol. Soc. Bot. Mex. 44: 72, fig. 1. 1983");
2633
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2634
        combinationAuthor = name.getCombinationAuthorship();
2635
        assertEquals( "Rzed.", combinationAuthor.getNomenclaturalTitleCache());
2636
        nomRef = name.getNomenclaturalReference();
2637
        assertEquals(ReferenceType.Article, nomRef.getType());
2638
        assertEquals("44", nomRef.getVolume());
2639
        assertEquals("72, fig. 1", name.getNomenclaturalMicroReference());
2640

    
2641
        //fig with a-c and without dot
2642
        name = parser.parseReferencedName("Deppea guerrerensis Dwyer & Lorence"
2643
                + " in Allertonia 4: 428. fig 4a-c. 1988");  //
2644
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2645
        combinationAuthor = name.getCombinationAuthorship();
2646
        assertEquals( "Dwyer & Lorence", combinationAuthor.getNomenclaturalTitleCache());
2647
        nomRef = name.getNomenclaturalReference();
2648
        assertEquals(ReferenceType.Article, nomRef.getType());
2649
        assertEquals("4", nomRef.getVolume());
2650
        assertEquals("428. fig 4a-c", name.getNomenclaturalMicroReference());
2651

    
2652
        //issue with EN_DASH (3–4)
2653
        name = parser.parseReferencedName("Arachnothryx tacanensis (Lundell) Borhidi"
2654
              + " in Acta Bot. Hung. 33 (3" + UTF8.EN_DASH + "4): 303. 1987");
2655
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2656
        combinationAuthor = name.getCombinationAuthorship();
2657
        assertEquals( "Borhidi", combinationAuthor.getNomenclaturalTitleCache());
2658
        nomRef = name.getNomenclaturalReference();
2659
        assertEquals(ReferenceType.Article, nomRef.getType());
2660
        assertEquals("33 (3" + UTF8.EN_DASH + "4)", nomRef.getVolume());
2661
        assertEquals("303", name.getNomenclaturalMicroReference());
2662

    
2663
        //fig with f.
2664
        name = parser.parseReferencedName("Stenotis Terrell"
2665
                + " in Sida 19(4): 901" + UTF8.EN_DASH + "911, f. 1" + UTF8.EN_DASH + "2. 2001");
2666
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2667
        combinationAuthor = name.getCombinationAuthorship();
2668
        assertEquals( "Terrell", combinationAuthor.getNomenclaturalTitleCache());
2669
        nomRef = name.getNomenclaturalReference();
2670
        assertEquals(ReferenceType.Article, nomRef.getType());
2671
        assertEquals("19(4)", nomRef.getVolume());
2672
        assertEquals("901" + UTF8.EN_DASH + "911, f. 1" + UTF8.EN_DASH + "2", name.getNomenclaturalMicroReference());
2673

    
2674
        //detail with figs
2675
        name = parser.parseReferencedName("Randia sonorensis Wiggins"
2676
                + " in Contr. Dudley Herb. 3: 75, figs 4-6. 1940");
2677
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2678
        combinationAuthor = name.getCombinationAuthorship();
2679
        assertEquals( "Wiggins", combinationAuthor.getNomenclaturalTitleCache());
2680
        nomRef = name.getNomenclaturalReference();
2681
        assertEquals(ReferenceType.Article, nomRef.getType());
2682
        assertEquals("3", nomRef.getVolume());
2683
        assertEquals("75, figs 4-6", name.getNomenclaturalMicroReference());
2684

    
2685
        //detail with pl. and figs
2686
        name = parser.parseReferencedName("Randia sonorensis Wiggins"
2687
                + " in Contr. Dudley Herb. 3: 75, pl. 19, figs 4-6. 1940");
2688
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2689
        combinationAuthor = name.getCombinationAuthorship();
2690
        assertEquals( "Wiggins", combinationAuthor.getNomenclaturalTitleCache());
2691
        nomRef = name.getNomenclaturalReference();
2692
        assertEquals(ReferenceType.Article, nomRef.getType());
2693
        assertEquals("3", nomRef.getVolume());
2694
        assertEquals("75, pl. 19, figs 4-6", name.getNomenclaturalMicroReference());
2695

    
2696
        //pl
2697
        name = parser.parseReferencedName("Carapichea  Aubl."
2698
                + " in Hist. Pl. Guiane 1: 167, pl. 64. 1775");
2699
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2700
        combinationAuthor = name.getCombinationAuthorship();
2701
        assertEquals( "Aubl.", combinationAuthor.getNomenclaturalTitleCache());
2702
        nomRef = name.getNomenclaturalReference();
2703
        assertEquals(ReferenceType.Article, nomRef.getType());
2704
        assertEquals("1", nomRef.getVolume());
2705
        assertEquals("167, pl. 64", name.getNomenclaturalMicroReference());
2706

    
2707
        //fig with ,
2708
        name = parser.parseReferencedName("Hoffmannia ixtlanensis Lorence"
2709
                + " in Novon 4: 121. fig. 2a, b. 1994");
2710
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2711
        combinationAuthor = name.getCombinationAuthorship();
2712
        assertEquals( "Lorence", combinationAuthor.getNomenclaturalTitleCache());
2713
        nomRef = name.getNomenclaturalReference();
2714
        assertEquals(ReferenceType.Article, nomRef.getType());
2715
        assertEquals("4", nomRef.getVolume());
2716
        assertEquals("121. fig. 2a, b", name.getNomenclaturalMicroReference());
2717

    
2718
        //detail with , to number
2719
        name = parser.parseReferencedName("Deppea martinez-calderonii Lorence"
2720
                + " in Allertonia 4: 399. figs 1e, 2. 1988");
2721
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2722
        combinationAuthor = name.getCombinationAuthorship();
2723
        assertEquals( "Lorence", combinationAuthor.getNomenclaturalTitleCache());
2724
        nomRef = name.getNomenclaturalReference();
2725
        assertEquals(ReferenceType.Article, nomRef.getType());
2726
        assertEquals("4", nomRef.getVolume());
2727
        assertEquals("399. figs 1e, 2", name.getNomenclaturalMicroReference());
2728

    
2729
        //(Suppl.)
2730
        name = parser.parseReferencedName("Manettia costaricensis  Wernham"
2731
                + " in J. Bot. 57(Suppl.): 38. 1919");
2732
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2733
        combinationAuthor = name.getCombinationAuthorship();
2734
        assertEquals( "Wernham", combinationAuthor.getNomenclaturalTitleCache());
2735
        nomRef = name.getNomenclaturalReference();
2736
        assertEquals(ReferenceType.Article, nomRef.getType());
2737
        assertEquals("57(Suppl.)", nomRef.getVolume());
2738
        assertEquals("38", name.getNomenclaturalMicroReference());
2739

    
2740
        //NY.
2741
        name = parser.parseReferencedName("Crusea psyllioides (Kunth) W.R. Anderson"
2742
                + " in Mem. NY. Bot. Gard. 22: 75. 1972");
2743
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2744
        combinationAuthor = name.getCombinationAuthorship();
2745
        assertEquals( "W.R. Anderson", combinationAuthor.getNomenclaturalTitleCache());
2746
        nomRef = name.getNomenclaturalReference();
2747
        assertEquals(ReferenceType.Article, nomRef.getType());
2748
        assertEquals("22", nomRef.getVolume());
2749
        assertEquals("75", name.getNomenclaturalMicroReference());
2750

    
2751
        //apostroph word in title
2752
        name = parser.parseReferencedName("Sabicea glabrescens Benth."
2753
                + " in Hooker's J. Bot. Kew Gard. Misc. 3: 219. 1841");
2754
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2755
        combinationAuthor = name.getCombinationAuthorship();
2756
        assertEquals( "Benth.", combinationAuthor.getNomenclaturalTitleCache());
2757
        nomRef = name.getNomenclaturalReference();
2758
        assertEquals(ReferenceType.Article, nomRef.getType());
2759
        assertEquals("3", nomRef.getVolume());
2760
        assertEquals("219", name.getNomenclaturalMicroReference());
2761

    
2762
        // place published e.g. (Hannover)
2763
        name = parser.parseReferencedName("Pittoniotis trichantha Griseb."
2764
                  + " in Bonplandia (Hannover) 6 (1): 8. 1858");
2765
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2766
        combinationAuthor = name.getCombinationAuthorship();
2767
        assertEquals( "Griseb.", combinationAuthor.getNomenclaturalTitleCache());
2768
        nomRef = name.getNomenclaturalReference();
2769
        assertEquals(ReferenceType.Article, nomRef.getType());
2770
        assertEquals("6 (1)", nomRef.getVolume());
2771
        assertEquals("8", name.getNomenclaturalMicroReference());
2772

    
2773
        //komplex / incorrect year without quotation marks
2774
        name = parser.parseReferencedName("Javorkaea Borhidi & Jarai-Koml."
2775
                + " in Acta Bot. Hung. 29(1\u20134): 16, f. 1\u20132, t. 1-8. 1983 [1984]");
2776
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2777
        combinationAuthor = name.getCombinationAuthorship();
2778
        assertEquals( "Borhidi & Jarai-Koml.", combinationAuthor.getNomenclaturalTitleCache());
2779
        nomRef = name.getNomenclaturalReference();
2780
        assertEquals(ReferenceType.Article, nomRef.getType());
2781
        assertEquals("29(1\u20134)", nomRef.getVolume());
2782
        assertEquals("16, f. 1\u20132, t. 1-8", name.getNomenclaturalMicroReference());
2783
        assertEquals("1983 [1984]", nomRef.getDatePublishedString());
2784
//        assertEquals("1984", nomRef.getYear()); //was like this, but is not necessarily correct, see #7429
2785

    
2786
        //incorrect year with \u201e \u201f  (s. eu.etaxonomy.cdm.common.UTF8.ENGLISH_QUOT_START
2787
        name = parser.parseReferencedName("Javorkaea Borhidi & Jarai-Koml."
2788
                + " in Acta Bot. Hung. 29(1-4): 16, f. 1-2. \u201e1983\u201f [1984]");
2789
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2790
        combinationAuthor = name.getCombinationAuthorship();
2791
        assertEquals( "Borhidi & Jarai-Koml.", combinationAuthor.getNomenclaturalTitleCache());
2792
        nomRef = name.getNomenclaturalReference();
2793
        assertEquals(ReferenceType.Article, nomRef.getType());
2794
        assertEquals("29(1-4)", nomRef.getVolume());
2795
        assertEquals("16, f. 1-2", name.getNomenclaturalMicroReference());
2796
        assertEquals("1984 [\"1983\"]", nomRef.getDatePublishedString());
2797
        assertEquals("1984", nomRef.getYear());
2798

    
2799
        //incorrect year with "
2800
        name = parser.parseReferencedName("Javorkaea Borhidi & Jarai-Koml."
2801
                + " in Acta Bot. Hung. 29(1-4): 16, f. 1-2. \"1983\" [1984]");
2802
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2803
        combinationAuthor = name.getCombinationAuthorship();
2804
        assertEquals( "Borhidi & Jarai-Koml.", combinationAuthor.getNomenclaturalTitleCache());
2805
        nomRef = name.getNomenclaturalReference();
2806
        assertEquals(ReferenceType.Article, nomRef.getType());
2807
        assertEquals("29(1-4)", nomRef.getVolume());
2808
        assertEquals("16, f. 1-2", name.getNomenclaturalMicroReference());
2809
        //changed from "1983" [1984] to 1984 ["1983"] after implementing #7429
2810
        assertEquals("1984 [\"1983\"]", nomRef.getDatePublishedString());
2811
        assertEquals("1984", nomRef.getYear());
2812

    
2813
        //fig. a
2814
        name = parser.parseReferencedName("Psychotria capitata  Ruiz & Pav."
2815
                + " in Fl. Peruv. 2: 59, pl. 206, fig. a. 1799");
2816
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2817
        combinationAuthor = name.getCombinationAuthorship();
2818
        assertEquals( "Ruiz & Pav.", combinationAuthor.getNomenclaturalTitleCache());
2819
        nomRef = name.getNomenclaturalReference();
2820
        assertEquals(ReferenceType.Article, nomRef.getType());
2821
        assertEquals("2", nomRef.getVolume());
2822
        assertEquals("59, pl. 206, fig. a", name.getNomenclaturalMicroReference());
2823

    
2824
        //442A.
2825
        name = parser.parseReferencedName("Rogiera elegans Planch."
2826
                + " in Fl. Serres Jard. Eur. 5: 442A. 1849");
2827
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2828
        combinationAuthor = name.getCombinationAuthorship();
2829
        assertEquals( "Planch.", combinationAuthor.getNomenclaturalTitleCache());
2830
        nomRef = name.getNomenclaturalReference();
2831
        assertEquals(ReferenceType.Article, nomRef.getType());
2832
        assertEquals("5", nomRef.getVolume());
2833
        assertEquals("442A", name.getNomenclaturalMicroReference());
2834

    
2835
        //f
2836
        name = parser.parseReferencedName("Coussarea imitans L.O. Williams"
2837
                + " in Phytologia 26 (6): 488-489, f. 1973");
2838
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2839
        combinationAuthor = name.getCombinationAuthorship();
2840
        assertEquals( "L.O. Williams", combinationAuthor.getNomenclaturalTitleCache());
2841
        nomRef = name.getNomenclaturalReference();
2842
        assertEquals(ReferenceType.Article, nomRef.getType());
2843
        assertEquals("26 (6)", nomRef.getVolume());
2844
        assertEquals("488-489, f", name.getNomenclaturalMicroReference());
2845

    
2846
        //Phys.-Med.
2847
        name = parser.parseReferencedName("Coccocypselum cordifolium Nees & Mart."
2848
                + " in Nova Acta Phys.-Med. Acad. Caes.\u2013Leop. Nat. Cur. 12: 14. 1824");
2849
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2850
        combinationAuthor = name.getCombinationAuthorship();
2851
        assertEquals( "Nees & Mart.", combinationAuthor.getNomenclaturalTitleCache());
2852
        nomRef = name.getNomenclaturalReference();
2853
        assertEquals(ReferenceType.Article, nomRef.getType());
2854
        assertEquals("Nova Acta Phys.-Med. Acad. Caes.\u2013Leop. Nat. Cur.", nomRef.getInReference().getAbbrevTitle());
2855
        assertEquals("12", nomRef.getVolume());
2856
        assertEquals("14", name.getNomenclaturalMicroReference());
2857
        assertEquals("1824", nomRef.getYear());
2858

    
2859
        //(ed. 10)  wanted?
2860
//        Syst. Nat. (ed. 10) 2: 930. 1759
2861
//        name = parser.parseReferencedName("Erithalis fruticosa L."
2862
//                + ", Syst. Nat. ed. 10, 2: 930. 1759");
2863
//        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2864
//        combinationAuthor = name.getCombinationAuthorship();
2865
//        assertEquals( "L.", combinationAuthor.getNomenclaturalTitleCache());
2866
//        nomRef = (Reference)name.getNomenclaturalReference();
2867
//        assertEquals(ReferenceType.Book, nomRef.getType());
2868
//        assertEquals("2", nomRef.getVolume());
2869
//        assertEquals("10", nomRef.getEdition());
2870
//        assertEquals("930", name.getNomenclaturalMicroReference());
2871
//        assertEquals("1759", nomRef.getYear());
2872

    
2873
        //issue with letter "(1a)"
2874
        name = parser.parseReferencedName("Arthraerua (Kuntze) Schinz,"
2875
                + " Nat. Pflanzenfam. 3(1a): 109. 1893");
2876
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2877
        combinationAuthor = name.getCombinationAuthorship();
2878
        assertEquals( "Schinz", combinationAuthor.getNomenclaturalTitleCache());
2879
        nomRef = name.getNomenclaturalReference();
2880
        Assert.assertFalse("Reference should be parsable", nomRef.isProtectedTitleCache());
2881
        assertEquals(ReferenceType.Book, nomRef.getType());
2882
        assertEquals("Nat. Pflanzenfam.", nomRef.getAbbrevTitle());
2883
        assertEquals("3(1a)", nomRef.getVolume());
2884
        assertEquals("109", name.getNomenclaturalMicroReference());
2885
        assertEquals("1893", nomRef.getYear());
2886

    
2887
        //Accent graph in author name #6057
2888
        name = parser.parseReferencedName("Sedum plicatum O`Brian");
2889
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2890
        assertEquals( "O`Brian", name.getCombinationAuthorship().getNomenclaturalTitleCache());
2891

    
2892
        //-e-  #6060
2893
        name = parser.parseReferencedName("Thamniopsis stenodictyon (Sehnem) Oliveira-e-Silva & O.Yano");
2894
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2895
        Team team = (Team)name.getCombinationAuthorship();
2896
        assertEquals( "Oliveira-e-Silva", team.getTeamMembers().get(0).getNomenclaturalTitleCache());
2897

    
2898
        //Vorabdr.
2899
        name = parser.parseReferencedName("Ophrys hystera  Kreutz & Ruedi Peter in J. Eur. Orchideen 30(Vorabdr.): 128. 1997");
2900
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2901
        assertEquals( "30(Vorabdr.)", name.getNomenclaturalReference().getVolume());
2902

    
2903
        //#6100  jun.
2904
        String nameStr = "Swida \u00D7 friedlanderi (W.H.Wagner jun.) Holub";
2905
        name = parser.parseFullName(nameStr, botanicCode, null);  //fails with missing botanicCode, see open issues
2906
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2907
        assertEquals( "W.H.Wagner jun.", name.getBasionymAuthorship().getTitleCache());
2908

    
2909
        //#6100 bis /ter
2910
        nameStr = "Schistidium aquaticum (R.Br.ter) Ochyra";
2911
        name = parser.parseFullName(nameStr);
2912
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2913
        assertEquals( "R.Br.ter", name.getBasionymAuthorship().getTitleCache());
2914

    
2915
        nameStr = "Grimmia mitchellii R.Br.bis";
2916
        name = parser.parseFullName(nameStr);
2917
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2918
        assertEquals( "R.Br.bis", name.getCombinationAuthorship().getTitleCache());
2919

    
2920
        //forma #6100
2921
        nameStr = "Xerocomus parasiticus forma piperatoides (J. Blum) R. Mazza";
2922
        name = parser.parseFullName(nameStr);
2923
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2924
        assertEquals( "piperatoides", name.getInfraSpecificEpithet());
2925
        assertEquals( Rank.FORM(), name.getRank());
2926

    
2927
        //subgen. #6100
2928
        nameStr = "Aliciella subgen. Gilmania (H.Mason & A.D.Grant) J.M.Porter";
2929
        name = parser.parseFullName(nameStr);
2930
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2931
        assertEquals( "Gilmania", name.getInfraGenericEpithet());
2932
        assertEquals( Rank.SUBGENUS(), name.getRank());
2933

    
2934
        //subgen. #6100
2935
        nameStr = "Aliciella subgen. Gilmania J.M.Porter";
2936
        name = parser.parseFullName(nameStr);
2937
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2938
        assertEquals( "Gilmania", name.getInfraGenericEpithet());
2939
        assertEquals( Rank.SUBGENUS(), name.getRank());
2940
        assertEquals( "J.M.Porter", name.getCombinationAuthorship().getTitleCache());
2941

    
2942
        //la Croix #6100
2943
        nameStr = "Eulophia ovalis var. bainesii (Rolfe) P.J.Cribb & la Croix";
2944
        name = parser.parseFullName(nameStr);
2945
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2946
        assertEquals( "P.J.Cribb & la Croix", name.getCombinationAuthorship().getTitleCache());
2947

    
2948
        //I = Yi #6100
2949
        nameStr = "Parasenecio hwangshanicus (P.I Mao) C.I Peng";
2950
        name = parser.parseFullName(nameStr);
2951
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2952
        assertEquals("I (=Yi) should be an accepted ending", "C.I Peng", name.getCombinationAuthorship().getTitleCache());
2953
        assertEquals("I (=Yi) should be an accepted ending", "P.I Mao", name.getBasionymAuthorship().getTitleCache());
2954

    
2955
        //´t Hart #6100
2956
        nameStr = "Sedum decipiens (Baker) Thiede & \u00B4t Hart";   //still does not work with "´", don't know what the difference is, see openIssues()
2957
        name = parser.parseFullName(nameStr);
2958
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2959
        assertEquals("All types of quotation marks should be accepted, though better match it to standard ' afterwards",
2960
                "Thiede & \u00B4t Hart", name.getCombinationAuthorship().getTitleCache());
2961

    
2962
        //Man in 't Veld  #6100
2963
        nameStr = "Phytophthora multivesiculata Ilieva, Man in 't Veld, Veenbaas-Rijks & Pieters";
2964
        name = parser.parseFullName(nameStr);
2965
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2966
        assertEquals("Ilieva, Man in 't Veld, Veenbaas-Rijks & Pieters",
2967
                name.getCombinationAuthorship().getTitleCache());
2968
        assertEquals("Ilieva, Man in 't Veld, Veenbaas-Rijks & Pieters",
2969
                name.getCombinationAuthorship().getNomenclaturalTitleCache());
2970

    
2971
        nameStr = "Thymus \u00D7 herberoi De la Torre, Vicedo, Alonso & Paya";
2972
        name = parser.parseFullName(nameStr);
2973
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2974
        //TODO may become ... Alonso & al. again in future
2975
        assertEquals("Thymus \u00D7herberoi De la Torre, Vicedo, Alonso & Paya", name.getTitleCache());
2976
        assertEquals("De la Torre, Vicedo, Alonso & Paya",
2977
                name.getCombinationAuthorship().getTitleCache());
2978
        assertEquals("De la Torre, Vicedo, Alonso & Paya",
2979
                name.getCombinationAuthorship().getNomenclaturalTitleCache());
2980

    
2981
        //Sant'Anna
2982
        nameStr = "Coelosphaerium evidenter-marginatum M.T.P.Azevedo & Sant'Anna";
2983
        name = parser.parseFullName(nameStr);
2984
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2985
        assertEquals("M.T.P.Azevedo & Sant'Anna", name.getCombinationAuthorship().getTitleCache());
2986

    
2987
        //Heft
2988
        nameStr = "Nepenthes deaniana Macfarl. in Engl., Mein Pflanzenr. IV. 111 (Heft 36): 57. 1908.";
2989
        name = parser.parseReferencedName(nameStr);
2990
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2991
        Reference ref = name.getNomenclaturalReference();
2992
        Assert.assertFalse("Reference should be parsable", ref.hasProblem());
2993
        //or even better IV. 111 (Heft 36), but this is currently not implemented
2994
        assertEquals("111 (Heft 36)", ref.getInReference().getVolume());
2995

    
2996
        //journal with commata at pos 4
2997
        nameStr = "Bufonia kotschyana subsp. densa Chrtek & Krisa in Acta Univ.Carol., Biol. 43(2): 105. 1999";
2998
        name = parser.parseReferencedName(nameStr);
2999
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
3000
        String author = name.getAuthorshipCache();
3001
        assertEquals("Chrtek & Krisa", author);
3002
        ref = name.getNomenclaturalReference();
3003
        Assert.assertNotNull("Nomenclatural reference should be an article and therefore have an in reference", ref.getInReference());
3004
        Assert.assertEquals(ReferenceType.Journal, ref.getInReference().getType());
3005

    
3006
        //Adansonia #9014, #9551
3007
        nameStr = "Casearia annamensis (Gagnep.) Lescot & Sleumer in Adansonia, n.s., 10: 290. 1970";
3008
        name = parser.parseReferencedName(nameStr);
3009
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
3010
        ref = name.getNomenclaturalReference();
3011
        Assert.assertEquals(ReferenceType.Article, ref.getType());
3012
        Assert.assertNotNull("Nomenclatural reference should be an article and therefore have an in reference", ref.getInReference());
3013
        Assert.assertEquals(ReferenceType.Journal, ref.getInReference().getType());
3014
        Assert.assertEquals("Adansonia", ref.getInReference().getAbbrevTitle());
3015

    
3016
        //, Bot., sér. 4 #9014, #9551
3017
        String ser = "s"+UTF8.SMALL_E_ACUTE+"r";
3018
        nameStr = "Asteropeia amblyocarpa Tul. in Ann. Sci. Nat., Bot., "+ser+". 4, 8: 81. 1857";
3019
        name = parser.parseReferencedName(nameStr);
3020
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
3021
        ref = name.getNomenclaturalReference();
3022
        Assert.assertEquals(ReferenceType.Article, ref.getType());
3023
        Assert.assertNotNull("Nomenclatural reference should be an article and therefore have an in reference", ref.getInReference());
3024
        Assert.assertEquals(ReferenceType.Journal, ref.getInReference().getType());
3025
        Assert.assertEquals("Ann. Sci. Nat., Bot.", ref.getInReference().getAbbrevTitle());
3026
        Assert.assertEquals(ser+". 4", ref.getSeriesPart());
3027
    }
3028

    
3029
    @Test
3030
    public final void explicitJournalTitles(){
3031
        //PhytoKeys #9550
3032
        String nameStr = "Pseudopodospermum baeticum (DC.) Zaika & al. in PhytoKeys 137: 68. 2020";
3033
        TaxonName name = parser.parseReferencedName(nameStr);
3034
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
3035
        Reference ref = name.getNomenclaturalReference();
3036
        Assert.assertNotNull("Nomenclatural reference should be an article and therefore have an in reference", ref.getInReference());
3037
        Assert.assertEquals(ReferenceType.Journal, ref.getInReference().getType());
3038
        Assert.assertEquals("PhytoKeys", ref.getInReference().getAbbrevTitle());
3039

    
3040
        //PLoS ONE #9550 //remaining issue: ", e82692" #9552
3041
//        nameStr = "Pseudopodospermum baeticum (DC.) Zaika & al. in PLoS ONE 8(12), e82692: 17. 2013";
3042
        nameStr = "Pseudopodospermum baeticum (DC.) Zaika & al. in PLoS ONE 8(12): 17. 2013";
3043
        name = parser.parseReferencedName(nameStr);
3044
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
3045
        ref = name.getNomenclaturalReference();
3046
        Assert.assertNotNull("Nomenclatural reference should be an article and therefore have an in reference", ref.getInReference());
3047
        Assert.assertEquals(ReferenceType.Journal, ref.getInReference().getType());
3048
        Assert.assertEquals("PLoS ONE", ref.getInReference().getAbbrevTitle());
3049
    }
3050

    
3051
    @Test
3052
    //#3666
3053
    public final void testOriginalSpelling(){
3054

    
3055
        String nameStr = "Abies alba Mill, Sp. Pl. 2: 333. 1751 [as \"alpa\"]";
3056
        TaxonName name = parser.parseReferencedName(nameStr);
3057
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
3058
        Reference ref = name.getNomenclaturalReference();
3059
        Assert.assertFalse("Reference should be parsable", ref.isProtectedTitleCache());
3060
        TaxonName originalName = name.getNomenclaturalSource().getNameUsedInSource();
3061
        Assert.assertNotNull("An original spelling should exist", originalName);
3062
        Assert.assertFalse("Namecache should not be parsable", originalName.isProtectedNameCache());
3063
        Assert.assertEquals("Abies alpa", originalName.getNameCache());
3064
        Assert.assertEquals("Sp. Pl.", name.getNomenclaturalSource().getCitation().getAbbrevTitle());
3065
        Assert.assertEquals("1751", name.getNomenclaturalSource().getCitation().getYear());
3066

    
3067
        //without ref
3068
        nameStr = "Abies alba Mill [as \"alpa\"]";
3069
        name = parser.parseReferencedName(nameStr);
3070
        originalName = name.getNomenclaturalSource().getNameUsedInSource();
3071
        Assert.assertFalse("Namecache should not be parsable", originalName.isProtectedNameCache());
3072
        Assert.assertEquals("Abies alpa", originalName.getNameCache());
3073

    
3074
        //without author
3075
        nameStr = "Abies alba [as \"alpa\"]";
3076
        name = parser.parseReferencedName(nameStr);
3077
        originalName = name.getNomenclaturalSource().getNameUsedInSource();
3078
        Assert.assertFalse("Namecache should not be parsable", originalName.isProtectedNameCache());
3079
        Assert.assertEquals("Abies alpa", originalName.getNameCache());
3080

    
3081
        //with status
3082
        nameStr = "Abies alba Mill, Sp. Pl. 2: 333. 1751 [as \"alpa\"], nom. inval.";
3083
        name = parser.parseReferencedName(nameStr);
3084
        originalName = name.getNomenclaturalSource().getNameUsedInSource();
3085
        Assert.assertFalse("Namecache should not be parsable", originalName.isProtectedNameCache());
3086
        Assert.assertEquals("Abies alpa", originalName.getNameCache());
3087
        Assert.assertEquals(1, name.getStatus().size());
3088

    
3089
        nameStr = "Abies alba Mill, Sp. Pl. 2: 333. 1751 [as \"Abies alpa\"]";
3090
        name = parser.parseReferencedName(nameStr);
3091
        originalName = name.getNomenclaturalSource().getNameUsedInSource();
3092
        Assert.assertFalse("Namecache should not be parsable", originalName.isProtectedNameCache());
3093
        Assert.assertEquals("Abies alpa", originalName.getNameCache());
3094

    
3095
        nameStr = "Abies alba Mill, Sp. Pl. 2: 333. 1751 [as \"Apies alpa\"]";
3096
        name = parser.parseReferencedName(nameStr);
3097
        originalName = name.getNomenclaturalSource().getNameUsedInSource();
3098
        Assert.assertFalse("Namecache should not be parsable", originalName.isProtectedNameCache());
3099
        Assert.assertEquals("Apies alpa", originalName.getNameCache());
3100

    
3101
        nameStr = "Abies alba Mill, Sp. Pl. 2: 333. 1751 [as \"Apies\"]";
3102
        name = parser.parseReferencedName(nameStr);
3103
        originalName = name.getNomenclaturalSource().getNameUsedInSource();
3104
        Assert.assertFalse("Namecache should not be parsable", originalName.isProtectedNameCache());
3105
        Assert.assertEquals("Apies alba", originalName.getNameCache());
3106

    
3107
        nameStr = "Abies alba subsp. beta Mill, Sp. Pl. 2: 333. 1751 [as \"peta\"]";
3108
        name = parser.parseReferencedName(nameStr);
3109
        originalName = name.getNomenclaturalSource().getNameUsedInSource();
3110
        Assert.assertFalse("Namecache should not be parsable", originalName.isProtectedNameCache());
3111
        Assert.assertEquals("Abies alba subsp. peta", originalName.getNameCache());
3112

    
3113
        nameStr = "Abies alba subsp. beta Mill, Sp. Pl. 2: 333. 1751 [as \"alpa subsp. peta\"]";
3114
        name = parser.parseReferencedName(nameStr);
3115
        originalName = name.getNomenclaturalSource().getNameUsedInSource();
3116
        Assert.assertFalse("Namecache should not be parsable", originalName.isProtectedNameCache());
3117
        Assert.assertEquals("Abies alpa subsp. peta", originalName.getNameCache());
3118

    
3119
        //unparsable
3120
        nameStr = "Abies alba Mill, Sp. Pl. 2: 333. 1751 [as \"alpa Err\"]";
3121
        Assert.assertTrue("Reference should notbe parsable", parser.parseReferencedName(nameStr).getNomenclaturalReference().isProtectedTitleCache());
3122

    
3123
    }
3124

    
3125
    @Test
3126
    public final void testHort(){
3127
        String nameStr = "Epidendrum ciliare var. minor hort. ex Stein";
3128
        TaxonName name = parser.parseReferencedName(nameStr);
3129
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
3130
        Assert.assertEquals("Epidendrum ciliare var. minor", name.getNameCache());
3131
        Assert.assertEquals("hort.", name.getExCombinationAuthorship().getNomenclaturalTitleCache());
3132
        Assert.assertEquals("Stein", name.getCombinationAuthorship().getNomenclaturalTitleCache());
3133
    }
3134

    
3135
    @Test
3136
    @Ignore
3137
    public final void openIssues(){
3138
        //#6100  jun.
3139
        String nameStr = "Swida \u00D7 friedlanderi (W.H.Wagner jun.) Holub";
3140
        INonViralName name = parser.parseFullName(nameStr, botanicCode, null);
3141
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
3142
        assertEquals( "W.H.Wagner jun.", name.getBasionymAuthorship().getTitleCache());
3143
        name = parser.parseFullName(nameStr);  //fails for some reasons without botanicCode given, as anyBotanicFullName is not recognized, strange because other very similar names such as Thymus \u00D7 herberoi De la Torre, Vicedo, Alonso & Paya do not fail
3144
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
3145
        assertEquals( "W.H.Wagner jun.", name.getBasionymAuthorship().getTitleCache());
3146

    
3147
        //´t Hart #6100
3148
        nameStr = "Sedum decipiens (Baker) Thiede & \u00B4t Hart";   //still does not work with "´" if compiled by maven, don't know what the difference is
3149
        name = parser.parseFullName(nameStr);
3150
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
3151
        assertEquals("All types of quotation marks should be accepted, though better match it to standard ' afterwards",
3152
                "Thiede & \u00B4t Hart", name.getCombinationAuthorship().getTitleCache());
3153
        nameStr = "Sedum decipiens (Baker) Thiede & ´t Hart";   //does not work if compiled with maven
3154
        name = parser.parseFullName(nameStr);
3155
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
3156
        assertEquals("All types of quotation marks should be accepted, though better match it to standard ' afterwards",
3157
                "Thiede & ´t Hart", name.getCombinationAuthorship().getTitleCache());
3158

    
3159
        //should be recognized as book section (see testBookSectionAuthors)
3160
        String str = "Iris xiphium var. lusitanica (Ker Gawl.) Franco in Amaral Franco & Rocha Afonso, Nova Fl. Portugal 3: 135. 1994";
3161
        name = parser.parseReferencedName(str);
3162
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
3163
        Reference nomRef = name.getNomenclaturalReference();
3164
        assertEquals(ReferenceType.BookSection, nomRef.getType());
3165
        assertEquals( "Amaral Franco & Rocha Afonso", nomRef.getInReference().getAuthorship().getNomenclaturalTitleCache());
3166
        assertEquals( "Nova Fl. Portugal", nomRef.getInReference().getAbbrevTitle());
3167

    
3168
        //same
3169
        str = "Fritillaria mutabilis Kamari in Strid & Kit Tan, Mount. Fl. Greece 2: 679. 1991";
3170
        name = parser.parseReferencedName(str);
3171
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
3172
        nomRef = name.getNomenclaturalReference();
3173
        assertEquals(ReferenceType.BookSection, nomRef.getType());
3174
        assertEquals( "Strid & Kit Tan", nomRef.getInReference().getAuthorship().getNomenclaturalTitleCache());
3175
        assertEquals( "Mount. Fl. Greece", nomRef.getInReference().getAbbrevTitle());
3176
    }
3177
}
(2-2/4)