Project

General

Profile

Download (137 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

    
10
package eu.etaxonomy.cdm.strategy.parser;
11

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

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

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

    
33
import eu.etaxonomy.cdm.common.UTF8;
34
import eu.etaxonomy.cdm.model.agent.INomenclaturalAuthor;
35
import eu.etaxonomy.cdm.model.agent.Person;
36
import eu.etaxonomy.cdm.model.agent.Team;
37
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
38
import eu.etaxonomy.cdm.model.common.DefaultTermInitializer;
39
import eu.etaxonomy.cdm.model.name.HybridRelationship;
40
import eu.etaxonomy.cdm.model.name.IBotanicalName;
41
import eu.etaxonomy.cdm.model.name.INonViralName;
42
import eu.etaxonomy.cdm.model.name.IZoologicalName;
43
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
44
import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
45
import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
46
import eu.etaxonomy.cdm.model.name.Rank;
47
import eu.etaxonomy.cdm.model.name.TaxonName;
48
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
49
import eu.etaxonomy.cdm.model.reference.IArticle;
50
import eu.etaxonomy.cdm.model.reference.IBook;
51
import eu.etaxonomy.cdm.model.reference.IBookSection;
52
import eu.etaxonomy.cdm.model.reference.IJournal;
53
import eu.etaxonomy.cdm.model.reference.INomenclaturalReference;
54
import eu.etaxonomy.cdm.model.reference.IReference;
55
import eu.etaxonomy.cdm.model.reference.IVolumeReference;
56
import eu.etaxonomy.cdm.model.reference.Reference;
57
import eu.etaxonomy.cdm.model.reference.ReferenceType;
58
import eu.etaxonomy.cdm.strategy.exceptions.StringNotParsableException;
59
/**
60
 * @author a.mueller
61
 *
62
 */
63
public class NonViralNameParserImplTest {
64
    private static final NomenclaturalCode ICNAFP = NomenclaturalCode.ICNAFP;
65
    private static final NomenclaturalCode ICZN = NomenclaturalCode.ICZN;
66

    
67
    private static final Logger logger = Logger.getLogger(NonViralNameParserImplTest.class);
68

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

    
84
    final private String strNameEmpty = "";
85
    final private String strNameNull = null;
86

    
87
    private NonViralNameParserImpl parser ;
88
    private NomenclaturalCode botanicCode;
89

    
90
    /**
91
     * @throws java.lang.Exception
92
     */
93
    @BeforeClass
94
    public static void setUpBeforeClass() throws Exception {
95
        DefaultTermInitializer termInitializer = new DefaultTermInitializer();
96
        termInitializer.initialize();
97
    }
98

    
99

    
100
    /**
101
     * @throws java.lang.Exception
102
     */
103
    @Before
104
    public void setUp() throws Exception {
105
        parser = NonViralNameParserImpl.NewInstance();
106
        botanicCode = ICNAFP;
107
    }
108

    
109

    
110
/*************** TEST *********************************************/
111

    
112
    /**
113
     * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#NEW_INSTANCE()}.
114
     */
115
    @Test
116
    public final void testNewInstance() {
117
        assertNotNull(parser);
118
    }
119

    
120
    /**
121
     * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#TaxonNameParserBotanicalNameImpl()}.
122
     */
123
    @Test
124
    public final void testTaxonNameParserBotanicalNameImpl() {
125
        logger.warn("Not yet implemented"); // TODO
126
    }
127

    
128
    @Test
129
    public final void testTeamSeperation(){
130
        Rank speciesRank = Rank.SPECIES();
131
        INonViralName name;
132

    
133
//      String strNameWith1AUthorAndCommaSepEditon = "Abies alba Mill., Sp. Pl., ed. 3: 455. 1987";
134
//      name = parser.parseReferencedName(strNameWith1AUthorAndCommaSepEditon, botanicCode, speciesRank);
135
//      Assert.assertFalse("No problems should exist", name.hasProblem());
136
//      Assert.assertEquals("Name should not include reference part", "Abies alba Mill.", name.getTitleCache());
137
//      Assert.assertEquals("Mill., Sp. Pl., ed. 3. 1987", name.getNomenclaturalReference().getTitleCache());
138
//
139
//
140
//      String strNameWith2Authors = "Abies alba L. & Mill., Sp. Pl., ed. 3: 455. 1987";
141
//      name = parser.parseReferencedName(strNameWith2Authors, botanicCode, speciesRank);
142
//      Assert.assertFalse("No problems should exist", name.hasProblem());
143
//      Assert.assertEquals("Name should not include reference part", "Abies alba L. & Mill.", name.getTitleCache());
144
//      Assert.assertEquals("Name should have authorteam with 2 authors", 2, ((Team)name.getCombinationAuthorship()).getTeamMembers().size());
145
//      Assert.assertEquals("L. & Mill., Sp. Pl., ed. 3. 1987", name.getNomenclaturalReference().getTitleCache());
146

    
147
        String strNameWith3Authors = "Abies alba Mess., L. & Mill., Sp. Pl., ed. 3: 455. 1987";
148
        name = parser.parseReferencedName(strNameWith3Authors, botanicCode, speciesRank);
149
        Assert.assertFalse("No problems should exist", name.hasProblem());
150
        Assert.assertEquals("Name should not include reference part", "Abies alba Mess., L. & Mill.", name.getTitleCache());
151
        Assert.assertEquals("Name should have authorship with 2 authors", 3, ((Team)name.getCombinationAuthorship()).getTeamMembers().size());
152
        Assert.assertEquals("Mess., L. & Mill., Sp. Pl., ed. 3. 1987", name.getNomenclaturalReference().getTitleCache());
153

    
154
    }
155

    
156
    /**
157
     * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#parseSimpleName(java.lang.String, eu.etaxonomy.cdm.model.name.Rank)}.
158
     */
159
    @Test
160
    public final void testParseSimpleName() {
161

    
162
        //Uninomials
163
        IZoologicalName milichiidae = (IZoologicalName)parser.parseSimpleName("Milichiidae", NomenclaturalCode.ICZN, null);
164
        assertEquals("Family rank expected", Rank.FAMILY(), milichiidae.getRank());
165
        IBotanicalName crepidinae = (IBotanicalName)parser.parseSimpleName("Crepidinae", ICNAFP, null);
166
        assertEquals("Family rank expected", Rank.SUBTRIBE(), crepidinae.getRank());
167
        IBotanicalName abies = (IBotanicalName)parser.parseSimpleName("Abies", ICNAFP, null);
168
        assertEquals("Family rank expected", Rank.GENUS(), abies.getRank());
169

    
170
        abies.addParsingProblem(ParserProblem.CheckRank);
171
        parser.parseSimpleName(abies, "Abies", abies.getRank(), true);
172
        assertTrue(abies.getParsingProblems().contains(ParserProblem.CheckRank));
173

    
174
        IBotanicalName rosa = (IBotanicalName)parser.parseSimpleName("Rosaceae", ICNAFP, null);
175
        assertTrue("Rosaceae have rank family", rosa.getRank().equals(Rank.FAMILY()));
176
        assertTrue("Rosaceae must have a rank warning", rosa.hasProblem(ParserProblem.CheckRank));
177
        parser.parseSimpleName(rosa, "Rosaceaex", abies.getRank(), true);
178
        assertEquals("Rosaceaex have rank genus", Rank.GENUS(), rosa.getRank());
179
        assertTrue("Rosaceaex must have a rank warning", rosa.hasProblem(ParserProblem.CheckRank));
180

    
181
        //repeat but remove warning after first parse
182
        rosa = (IBotanicalName)parser.parseSimpleName("Rosaceae", ICNAFP, null);
183
        assertTrue("Rosaceae have rank family", rosa.getRank().equals(Rank.FAMILY()));
184
        assertTrue("Rosaceae must have a rank warning", rosa.hasProblem(ParserProblem.CheckRank));
185
        rosa.removeParsingProblem(ParserProblem.CheckRank);
186
        parser.parseSimpleName(rosa, "Rosaceaex", rosa.getRank(), true);
187
        assertEquals("Rosaceaex have rank family", Rank.FAMILY(), rosa.getRank());
188
        assertFalse("Rosaceaex must have no rank warning", rosa.hasProblem(ParserProblem.CheckRank));
189

    
190
    }
191

    
192
    /**
193
     * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#parseSubGenericFullName(java.lang.String)}.
194
     */
195
    @Test
196
    public final void testParseSubGenericFullName() {
197
        String zooSpeciesWithSubgenus = "Bacanius (Mullerister) rombophorus (Aube, 1843)";
198
        //zoo as fullName
199
        IZoologicalName zooName = parser.parseReferencedName(zooSpeciesWithSubgenus, NomenclaturalCode.ICZN, Rank.SPECIES());
200
        Assert.assertTrue(zooName.getParsingProblems().isEmpty());
201
        Assert.assertEquals("Mullerister", zooName.getInfraGenericEpithet());
202
        Assert.assertEquals(Integer.valueOf(1843), zooName.getOriginalPublicationYear());
203
        //zoo as referenced name
204
        zooName = (IZoologicalName)parser.parseFullName(zooSpeciesWithSubgenus, NomenclaturalCode.ICZN, Rank.SPECIES());
205
        Assert.assertTrue(zooName.getParsingProblems().isEmpty());
206
        Assert.assertEquals("Mullerister", zooName.getInfraGenericEpithet());
207
        Assert.assertEquals(Integer.valueOf(1843), zooName.getOriginalPublicationYear());
208

    
209
        //bot as full Name
210
        String botSpeciesWithSubgenus = "Bacanius (Mullerister) rombophorus (Aube) Mill.";
211
        IBotanicalName botName = (IBotanicalName)parser.parseFullName(botSpeciesWithSubgenus, NomenclaturalCode.ICNAFP, Rank.GENUS());
212
        Assert.assertTrue(botName.getParsingProblems().isEmpty());
213
        Assert.assertEquals("Mullerister", botName.getInfraGenericEpithet());
214
        Assert.assertEquals("rombophorus", botName.getSpecificEpithet());
215
        Assert.assertEquals("Aube", botName.getBasionymAuthorship().getTitleCache());
216

    
217
        //bot as referenced Name
218
        botName = parser.parseReferencedName(botSpeciesWithSubgenus, NomenclaturalCode.ICNAFP, Rank.GENUS());
219
        Assert.assertTrue(botName.getParsingProblems().isEmpty());
220
        Assert.assertEquals("Mullerister", botName.getInfraGenericEpithet());
221
        Assert.assertEquals("rombophorus", botName.getSpecificEpithet());
222
        Assert.assertEquals("Aube", botName.getBasionymAuthorship().getTitleCache());
223

    
224
        //bot without author
225
        String botSpeciesWithSubgenusWithoutAuthor = "Bacanius (Mullerister) rombophorus";
226
        botName = parser.parseReferencedName(botSpeciesWithSubgenusWithoutAuthor, NomenclaturalCode.ICNAFP, Rank.GENUS());
227
        Assert.assertTrue(botName.getParsingProblems().isEmpty());
228
        Assert.assertEquals("Mullerister", botName.getInfraGenericEpithet());
229
        Assert.assertEquals("rombophorus", botName.getSpecificEpithet());
230
        Assert.assertEquals("", botName.getAuthorshipCache());
231
    }
232

    
233
    /**
234
     * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#parseSubGenericSimpleName(java.lang.String)}.
235
     */
236
    @Test
237
    public final void testParseSubGenericSimpleName() {
238
        logger.warn("Not yet implemented"); // TODO
239
    }
240

    
241
    /**
242
     * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#parseFullName(java.lang.String, eu.etaxonomy.cdm.model.name.Rank)}.
243
     */
244
    @Test
245
    public final void testParseFullNameUnicode() {
246

    
247
        INonViralName nameAuthor = parser.parseFullName(strNameAbiesAuthor1Unicode, null, Rank.SPECIES());
248
        assertEquals("Abies", nameAuthor.getGenusOrUninomial());
249
        assertEquals("alba", nameAuthor.getSpecificEpithet());
250
        assertEquals("M\u00FCller", nameAuthor.getCombinationAuthorship().getNomenclaturalTitle());
251

    
252
        INonViralName nameBasionymAuthor = parser.parseFullName(strNameAbiesBasionymAuthor1Unicode, null, Rank.SPECIES());
253
        assertEquals("Abies", nameBasionymAuthor.getGenusOrUninomial());
254
        assertEquals("alba", nameBasionymAuthor.getSpecificEpithet());
255
        assertEquals("D'M\u00FCller", nameBasionymAuthor.getCombinationAuthorship().getNomenclaturalTitle());
256
        INomenclaturalAuthor basionymTeam = nameBasionymAuthor.getBasionymAuthorship();
257
        assertEquals("Ciardelli", basionymTeam.getNomenclaturalTitle());
258

    
259
        INonViralName nameBasionymExAuthor = parser.parseFullName(strNameAbiesBasionymExAuthor1Unicode, null, Rank.SPECIES());
260
        assertEquals("Abies", nameBasionymExAuthor.getGenusOrUninomial());
261
        assertEquals("alba", nameBasionymExAuthor.getSpecificEpithet());
262
        assertEquals("D'M\u00FCller", nameBasionymExAuthor.getExCombinationAuthorship().getNomenclaturalTitle());
263
        assertEquals("de Greuther", nameBasionymExAuthor.getCombinationAuthorship().getNomenclaturalTitle());
264
        INomenclaturalAuthor basionymTeam2 = nameBasionymExAuthor.getExBasionymAuthorship();
265
        assertEquals("Ciardelli", basionymTeam2.getNomenclaturalTitle());
266
        INomenclaturalAuthor exBasionymTeam2 = nameBasionymExAuthor.getBasionymAuthorship();
267
        assertEquals("D\u00F6ring", exBasionymTeam2.getNomenclaturalTitle());
268

    
269
        IBotanicalName nameBasionymExAuthor2 = (IBotanicalName)parser.parseFullName("Washingtonia filifera (Linden ex Andre) H.Wendl. ex de Bary", null, Rank.SPECIES());
270
        assertEquals("Washingtonia", nameBasionymExAuthor2.getGenusOrUninomial());
271
        assertEquals("filifera", nameBasionymExAuthor2.getSpecificEpithet());
272
        assertEquals("H.Wendl.", nameBasionymExAuthor2.getExCombinationAuthorship().getNomenclaturalTitle());
273
        assertEquals("de Bary", nameBasionymExAuthor2.getCombinationAuthorship().getNomenclaturalTitle());
274
        INomenclaturalAuthor basionymTeam3 = nameBasionymExAuthor2.getBasionymAuthorship();
275
        assertEquals("Andre", basionymTeam3.getNomenclaturalTitle());
276
        INomenclaturalAuthor exBasionymTeam3 = nameBasionymExAuthor2.getExBasionymAuthorship();
277
        assertEquals("Linden", exBasionymTeam3.getNomenclaturalTitle());
278
        String title = nameBasionymExAuthor2.getTitleCache();
279
        assertEquals("Washingtonia filifera (Linden ex Andre) H.Wendl. ex de Bary", title);
280

    
281
    }
282

    
283

    
284
    /**
285
     * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#parseFullName(java.lang.String, eu.etaxonomy.cdm.model.name.Rank)}.
286
     */
287
    @Test
288
    public final void testParseFullName() {
289
        try {
290
            Method parseMethod = parser.getClass().getDeclaredMethod("parseFullName", String.class, NomenclaturalCode.class, Rank.class);
291
            testName_StringNomcodeRank(parseMethod);
292
        } catch (Exception e) {
293
            e.printStackTrace();
294
            assertTrue(false);
295
        }
296

    
297
        //Team
298
        INonViralName nameTeam1 = parser.parseFullName(strNameTeam1);
299
        assertEquals( "Abies", nameTeam1.getGenusOrUninomial());
300
        assertEquals( "alba", nameTeam1.getSpecificEpithet());
301
        assertEquals("Mueller & L.",  nameTeam1.getCombinationAuthorship().getNomenclaturalTitle());
302
        assertTrue(nameTeam1.getCombinationAuthorship() instanceof Team);
303
        Team team = (Team)nameTeam1.getCombinationAuthorship();
304
        assertEquals("Mueller", team.getTeamMembers().get(0).getNomenclaturalTitle());
305
        assertEquals("L.", team.getTeamMembers().get(1).getNomenclaturalTitle());
306

    
307
        //ZooName
308
        IZoologicalName nameZoo1 = (IZoologicalName)parser.parseFullName(strNameZoo1);
309
        assertEquals( "Abies", nameZoo1.getGenusOrUninomial());
310
        assertEquals( "alba", nameZoo1.getSpecificEpithet());
311
        assertEquals("Mueller & L.",  nameZoo1.getCombinationAuthorship().getNomenclaturalTitle());
312
        assertEquals(NomenclaturalCode.ICZN, nameZoo1.getNomenclaturalCode() );
313
        assertEquals(Integer.valueOf(1822), nameZoo1.getPublicationYear());
314
        assertTrue(nameZoo1.getCombinationAuthorship() instanceof Team);
315
        Team teamZoo = (Team)nameZoo1.getCombinationAuthorship();
316
        assertEquals("Mueller", teamZoo.getTeamMembers().get(0).getNomenclaturalTitle());
317
        assertEquals("L.", teamZoo.getTeamMembers().get(1).getNomenclaturalTitle());
318

    
319
        IZoologicalName nameZoo2 = (IZoologicalName)parser.parseFullName(strNameZoo2);
320
        assertEquals(Integer.valueOf(2002), nameZoo2.getPublicationYear());
321
        assertEquals(Integer.valueOf(1822), nameZoo2.getOriginalPublicationYear());
322
        assertEquals("Mueller",  nameZoo2.getBasionymAuthorship().getNomenclaturalTitle());
323
        assertEquals("Ciardelli",  nameZoo2.getCombinationAuthorship().getNomenclaturalTitle());
324

    
325
        //subsp
326
        IZoologicalName nameZoo3 = (IZoologicalName)parser.parseFullName(strNameZoo3);
327
        assertEquals("Ciardelli",  nameZoo3.getCombinationAuthorship().getNomenclaturalTitle());
328
        assertFalse("Subsp. without marker should be parsable", nameZoo3.hasProblem());
329
        assertEquals("Variety should be recognized", Rank.SUBSPECIES(), nameZoo3.getRank());
330

    
331
        IZoologicalName nameZoo4 = (IZoologicalName)parser.parseFullName(strNameZoo4);
332
        assertEquals("Ciardelli",  nameZoo4.getCombinationAuthorship().getNomenclaturalTitle());
333
        assertFalse("Subsp. without marker should be parsable", nameZoo4.hasProblem());
334
        assertEquals("Variety should be recognized", Rank.SUBSPECIES(), nameZoo4.getRank());
335

    
336
        IZoologicalName nameZoo5 = (IZoologicalName)parser.parseFullName(strNameZoo5);
337
        assertEquals("Ciardelli",  nameZoo5.getCombinationAuthorship().getNomenclaturalTitle());
338
        assertFalse("Subsp. without marker should be parsable", nameZoo5.hasProblem());
339
        assertEquals("Variety should be recognized", Rank.VARIETY(), nameZoo5.getRank());
340

    
341

    
342
        //Autonym
343
        IBotanicalName autonymName = (IBotanicalName)parser.parseFullName("Abies alba Mill. var. alba", ICNAFP, null);
344
        assertFalse("Autonym should be parsable", autonymName.hasProblem());
345

    
346

    
347
        //empty
348
        INonViralName nameEmpty = parser.parseFullName(strNameEmpty);
349
        assertNotNull(nameEmpty);
350
        assertEquals("", nameEmpty.getTitleCache());
351

    
352
        //null
353
        INonViralName nameNull = parser.parseFullName(strNameNull);
354
        assertNull(nameNull);
355

    
356
        //some authors
357
        String fullNameString = "Abies alba (Greuther & L'Hiver & al. ex M\u00FCller & Schmidt)Clark ex Ciardelli";
358
        INonViralName authorname = parser.parseFullName(fullNameString);
359
        assertFalse(authorname.hasProblem());
360
        assertEquals("Basionym author should have 3 authors", 2, ((Team)authorname.getExBasionymAuthorship()).getTeamMembers().size());
361
        Assert.assertTrue("ExbasionymAuthorship must have more members'", ((Team)authorname.getExBasionymAuthorship()).isHasMoreMembers());
362

    
363
        //author with 2 capitals
364
        fullNameString = "Campanula rhodensis A. DC.";
365
        INonViralName name = parser.parseFullName(fullNameString);
366
        assertFalse(name.hasProblem());
367

    
368
        //author with no space  #5618
369
        fullNameString = "Gordonia moaensis (Vict.)H. Keng";
370
        name = parser.parseFullName(fullNameString);
371
        assertFalse(name.hasProblem());
372
        assertNotNull(name.getCombinationAuthorship());
373
        assertEquals("H. Keng", name.getCombinationAuthorship().getNomenclaturalTitle());
374

    
375
        //name without combination  author  , only to check if above fix for #5618 works correctly
376
        fullNameString = "Gordonia moaensis (Vict.)";
377
        name = parser.parseFullName(fullNameString);
378
        assertFalse(name.hasProblem());
379
        assertNull(name.getCombinationAuthorship());
380
        assertNotNull(name.getBasionymAuthorship());
381
        assertEquals("Vict.", name.getBasionymAuthorship().getNomenclaturalTitle());
382

    
383
    }
384

    
385
    @Test
386
    public final void testEtAl() throws StringNotParsableException {
387
        //some authors
388
        String fullNameString = "Abies alba Greuther, Hiver & al.";
389
        INonViralName authorname = parser.parseFullName(fullNameString);
390
        assertFalse(authorname.hasProblem());
391
        assertEquals("Basionym author should have 2 authors", 2, ((Team)authorname.getCombinationAuthorship()).getTeamMembers().size());
392
        assertTrue("Basionym author team should have more authors", ((Team)authorname.getCombinationAuthorship()).isHasMoreMembers()  );
393

    
394
        //et al.
395
        INonViralName nvn = TaxonNameFactory.NewZoologicalInstance(null);
396
        parser.parseAuthors(nvn, "Eckweiler, Hand et al., 2003");
397
        Team team = (Team)nvn.getCombinationAuthorship();
398
        Assert.assertNotNull("Comb. author must not be null", team);
399
        Assert.assertEquals("Must be team with 2 members", 2, team.getTeamMembers().size());
400
        Assert.assertEquals("Second member must be 'Hand'", "Hand", team.getTeamMembers().get(1).getTitleCache());
401
        Assert.assertTrue("Team must have more members'", team.isHasMoreMembers());
402
    }
403

    
404
    @Test
405
    public final void testMultipleAuthors() {
406
        //multiple authors for inReference
407
        String fullTitleString = "Abies alba L. in Mill., Gregor & Behr., Sp. Pl. 173: 384. 1982.";
408
        INonViralName multipleAuthorRefName = parser.parseReferencedName(fullTitleString, NomenclaturalCode.ICNAFP, Rank.SPECIES());
409
        assertFalse(multipleAuthorRefName.hasProblem());
410
        assertTrue("Combination author should be a person", multipleAuthorRefName.getCombinationAuthorship() instanceof Person);
411
        assertEquals("Combination author should be L.", "L.", ((Person)multipleAuthorRefName.getCombinationAuthorship()).getNomenclaturalTitle());
412
        IReference nomRef = multipleAuthorRefName.getNomenclaturalReference();
413
        Assert.assertNotNull("nomRef must have inRef", ((Reference)nomRef).getInReference());
414
        Reference inRef = ((Reference)nomRef).getInReference();
415
        String abbrevTitle = inRef.getAbbrevTitle();
416
        assertEquals("InRef title should be Sp. Pl.", "Sp. Pl.", abbrevTitle);
417
        assertTrue(inRef.getAuthorship() instanceof Team);
418
        Team team = (Team)inRef.getAuthorship();
419
        assertEquals(3, team.getTeamMembers().size());
420

    
421
//        multiple authors in Name
422
        fullTitleString = "Abies alba Mill., Aber & Schwedt";
423
        INonViralName 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

    
430
//      multiple authors in Name with reference
431
        fullTitleString = "Abies alba Mill., Aber & Schwedt in L., Sp. Pl. 173: 384. 1982.";
432
        multipleAuthorName = parser.parseReferencedName(fullTitleString, NomenclaturalCode.ICNAFP, Rank.SPECIES());
433
        assertFalse(multipleAuthorName.hasProblem());
434
        assertTrue("Combination author should be a team", multipleAuthorName.getCombinationAuthorship() instanceof Team);
435
        team = (Team)multipleAuthorName.getCombinationAuthorship();
436
        assertEquals(3, team.getTeamMembers().size());
437
        assertEquals("Second team member should be Aber", "Aber", team.getTeamMembers().get(1).getTitleCache());
438
        nomRef = multipleAuthorName.getNomenclaturalReference();
439
        Assert.assertNotNull("nomRef must have inRef", ((Reference)nomRef).getInReference());
440
        inRef = ((Reference)nomRef).getInReference();
441
        abbrevTitle = inRef.getAbbrevTitle();
442
        assertEquals("InRef title should be Sp. Pl.", "Sp. Pl.", abbrevTitle);
443
        assertTrue(inRef.getAuthorship() instanceof Person);
444
        Person person = (Person)inRef.getAuthorship();
445
        assertEquals("Book author should be L.", "L.", person.getNomenclaturalTitle());
446

    
447

    
448
        fullTitleString = "Abies alba Mill., Aber & Schwedt, Sp. Pl. 173: 384. 1982.";
449
        multipleAuthorName = parser.parseReferencedName(fullTitleString, NomenclaturalCode.ICNAFP, Rank.SPECIES());
450
        assertFalse(multipleAuthorName.hasProblem());
451
        assertTrue("Combination author should be a team", multipleAuthorName.getCombinationAuthorship() instanceof Team);
452
        team = (Team)multipleAuthorName.getCombinationAuthorship();
453
        assertEquals(3, team.getTeamMembers().size());
454
        assertEquals("Second team member should be Aber", "Aber", team.getTeamMembers().get(1).getTitleCache());
455
        nomRef = multipleAuthorName.getNomenclaturalReference();
456
        Assert.assertNull("nomRef must not have inRef as it is a book itself", ((Reference)nomRef).getInReference());
457
        abbrevTitle = nomRef.getAbbrevTitle();
458
        assertEquals("InRef title should be Sp. Pl.", "Sp. Pl.", abbrevTitle);
459
        assertTrue(nomRef.getAuthorship() instanceof Team);
460
        team = (Team)nomRef.getAuthorship();
461
        assertEquals(3, team.getTeamMembers().size());
462
        assertEquals("Second team member should be Schwedt", "Schwedt", team.getTeamMembers().get(2).getTitleCache());
463

    
464
        //et al.
465
        INonViralName nvn = TaxonNameFactory.NewZoologicalInstance(null);
466
        parser.parseReferencedName (nvn, "Marmota marmota Eckweiler, Hand et al., 2003", Rank.SPECIES(),true);
467
        assertTrue("Combination author should be a team", nvn.getCombinationAuthorship() instanceof Team);
468
        team = (Team)nvn.getCombinationAuthorship();
469
        Assert.assertNotNull("Comb. author must not be null", team);
470
        Assert.assertEquals("Must be team with 2 members", 2, team.getTeamMembers().size());
471
        Assert.assertEquals("Second member must be 'Hand'", "Hand", team.getTeamMembers().get(1).getTitleCache());
472
        Assert.assertTrue("Team must have more members'", team.isHasMoreMembers());
473

    
474
    }
475

    
476
    /**
477
     * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#parseFullName(java.lang.String, eu.etaxonomy.cdm.model.name.Rank)}.
478
     */
479
    @Test
480
    public final void testHybrids() {
481
        INonViralName name1;
482

    
483

    
484
        //Infrageneric hybrid
485
        name1 = parser.parseFullName("Aegilops nothosubg. Insulae Scholz", botanicCode, null);
486
        assertTrue("Name must have binom hybrid bit set", name1.isBinomHybrid());
487
        assertFalse("Name must not have monom hybrid bit set", name1.isMonomHybrid());
488
        assertFalse("Name must not have trinom hybrid bit set", name1.isTrinomHybrid());
489
        assertEquals("Infrageneric epithet must be 'Insulae'", "Insulae", name1.getInfraGenericEpithet());
490

    
491
        //Species hybrid
492
//      INonViralName nameTeam1 = parser.parseFullName("Aegilops \u00D7insulae-cypri H. Scholz");
493
        name1 = parser.parseFullName("Aegilops \u00D7insulae Scholz", botanicCode, null);
494
        assertTrue("Name must have binom hybrid bit set", name1.isBinomHybrid());
495
        assertFalse("Name must not have monom hybrid bit set", name1.isMonomHybrid());
496
        assertFalse("Name must not have trinom hybrid bit set", name1.isTrinomHybrid());
497
        assertEquals("Species epithet must be 'insulae'", "insulae", name1.getSpecificEpithet());
498

    
499
        name1 = parser.parseFullName("Aegilops \u00D7 insulae Scholz", botanicCode, null);
500
        assertTrue("Name must have binom hybrid bit set", name1.isBinomHybrid());
501
        assertFalse("Name must not have monom hybrid bit set", name1.isMonomHybrid());
502
        assertFalse("Name must not have trinom hybrid bit set", name1.isTrinomHybrid());
503
        assertEquals("Species epithet must be 'insulae'", "insulae", name1.getSpecificEpithet());
504

    
505
        //Uninomial hybrid
506
        name1 = parser.parseFullName("x Aegilops Scholz", botanicCode, null);
507
        assertTrue("Name must have monom hybrid bit set", name1.isMonomHybrid());
508
        assertFalse("Name must not have binom hybrid bit set", name1.isBinomHybrid());
509
        assertFalse("Name must not have trinom hybrid bit set", name1.isTrinomHybrid());
510
        assertEquals("Uninomial must be 'Aegilops'", "Aegilops", name1.getGenusOrUninomial());
511

    
512
        //Subspecies hybrid with hybrid sign
513
        //maybe false: see http://dev.e-taxonomy.eu/trac/ticket/3868
514
        name1 = parser.parseFullName("Aegilops insulae subsp. X abies Scholz", botanicCode, null);
515
        assertFalse("Name must not have monom hybrid bit set", name1.isMonomHybrid());
516
        assertFalse("Name must not have binom hybrid bit set", name1.isBinomHybrid());
517
        assertTrue("Name must have trinom hybrid bit set", name1.isTrinomHybrid());
518
        assertEquals("Infraspecific epithet must be 'abies'", "abies", name1.getInfraSpecificEpithet());
519

    
520
        //Subspecies hybrid with notho / n
521
        name1 = parser.parseFullName("Aegilops insulae nothosubsp. abies Scholz", botanicCode, null);
522
        assertFalse("Name must not have monom hybrid bit set", name1.isMonomHybrid());
523
        assertFalse("Name must not have binom hybrid bit set", name1.isBinomHybrid());
524
        assertFalse("Name must not be protected", name1.isProtectedTitleCache());
525
        assertTrue("Name must have trinom hybrid bit set", name1.isTrinomHybrid());
526
        assertEquals("Infraspecific epithet must be 'abies'", "abies", name1.getInfraSpecificEpithet());
527

    
528
        name1 = parser.parseFullName("Aegilops insulae nsubsp. abies Scholz", botanicCode, null);
529
        assertFalse("Name must not have monom hybrid bit set", name1.isMonomHybrid());
530
        assertFalse("Name must not have binom hybrid bit set", name1.isBinomHybrid());
531
        assertFalse("Name must not be protected", name1.isProtectedTitleCache());
532
        assertTrue("Name must have trinom hybrid bit set", name1.isTrinomHybrid());
533
        assertEquals("Infraspecific epithet must be 'abies'", "abies", name1.getInfraSpecificEpithet());
534

    
535
        //
536
        String nameStr = "Dactylorhiza \u00D7incarnata nothosubsp. versicolor";
537
        name1 = parser.parseFullName(nameStr);
538
        assertFalse("Name must not have monom hybrid bit set", name1.isMonomHybrid());
539
        assertTrue("Name must have binom hybrid bit set", name1.isBinomHybrid());
540
        assertTrue("Name must have trinom hybrid bit set", name1.isTrinomHybrid());
541
        assertFalse("Name must not be protected", name1.isProtectedTitleCache());
542
        assertEquals(nameStr, name1.getTitleCache());  //we expect the cache strategy to create the same result
543

    
544
        nameStr = "Dactylorhiza \u00D7incarnata nothosubsp. versicolor";
545
        name1 = parser.parseFullName(nameStr);
546
        assertFalse("Name must not have monom hybrid bit set", name1.isMonomHybrid());
547
        assertTrue("Name must have binom hybrid bit set", name1.isBinomHybrid());
548
        assertTrue("Name must have trinom hybrid bit set", name1.isTrinomHybrid());
549
        assertFalse("Name must not be protected", name1.isProtectedTitleCache());
550
        assertEquals(nameStr, name1.getTitleCache());  //we expect the cache strategy to create the same result
551

    
552
        //nothovar.
553
        nameStr = "Dactylorhiza incarnata nothovar. versicolor";
554
        name1 = parser.parseFullName(nameStr);
555
        assertFalse("Name must not have monom hybrid bit set", name1.isMonomHybrid());
556
        assertFalse("Name must not have binom hybrid bit set", name1.isBinomHybrid());
557
        assertTrue("Name must have trinom hybrid bit set", name1.isTrinomHybrid());
558
        assertFalse("Name must not be protected", name1.isProtectedTitleCache());
559
        assertEquals(nameStr, name1.getNameCache());  //we expect the cache strategy to create the same result
560

    
561
        //hybrid autonym #6656
562
        nameStr = "Ophrys \u00D7kastelli E. Klein nothosubsp. kastelli";
563
        name1 = parser.parseFullName(nameStr);
564
        assertFalse("Name must not have monom hybrid bit set", name1.isMonomHybrid());
565
        assertTrue("Name must have binom hybrid bit set", name1.isBinomHybrid());
566
        assertTrue("Name must have trinom hybrid bit set", name1.isTrinomHybrid());
567
        assertFalse("Name must not be protected", name1.isProtectedTitleCache());
568
        assertEquals(nameStr, name1.getTitleCache()); //we expect the cache strategy to create the same result
569

    
570
        name1 = parser.parseReferencedName(nameStr);
571
        assertFalse("Name must not have monom hybrid bit set", name1.isMonomHybrid());
572
        assertTrue("Name must have binom hybrid bit set", name1.isBinomHybrid());
573
        assertTrue("Name must have trinom hybrid bit set", name1.isTrinomHybrid());
574
        assertFalse("Name must not be protected", name1.isProtectedTitleCache());
575
        assertEquals(nameStr, name1.getTitleCache()); //we expect the cache strategy to create the same result
576

    
577
        //remove space since #7094
578
        parser.setRemoveSpaceAfterDot(true);
579
        name1 = parser.parseReferencedName(nameStr);
580
        assertEquals(nameStr.replace("E. Kl", "E.Kl"), name1.getTitleCache()); //we expect the cache strategy to create the same result
581
        parser.setRemoveSpaceAfterDot(false);
582

    
583
    }
584

    
585
    /**
586
     * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#parseFullName(java.lang.String, eu.etaxonomy.cdm.model.name.Rank)}.
587
     */
588
    @Test
589
    public final void testUnrankedNames() {
590
        try {
591
            Method parseMethod = parser.getClass().getDeclaredMethod("parseFullName", String.class, NomenclaturalCode.class, Rank.class);
592
            testName_StringNomcodeRank(parseMethod);
593
        } catch (Exception e) {
594
            e.printStackTrace();
595
            assertTrue(false);
596
        }
597

    
598
        //unranked infraspecific
599
        String infraspecificUnranked = "Genus species [unranked] infraspecific";
600
        INonViralName name = parser.parseFullName(infraspecificUnranked);
601
        assertEquals( "Genus", name.getGenusOrUninomial());
602
        assertEquals( "species", name.getSpecificEpithet());
603
        assertEquals( "infraspecific", name.getInfraSpecificEpithet());
604
        assertEquals( "Unranked rank should be parsed", Rank.INFRASPECIFICTAXON(), name.getRank());
605

    
606
        //unranked infrageneric
607
        String infraGenericUnranked = "Genus [unranked] Infragen";
608
        INonViralName name2 = parser.parseFullName(infraGenericUnranked);
609
        assertEquals( "Genus", name2.getGenusOrUninomial());
610
        assertEquals( null, name2.getSpecificEpithet());
611
        assertEquals( "Infragen", name2.getInfraGenericEpithet());
612
        assertEquals( "Unranked rank should be parsed", Rank.INFRAGENERICTAXON(), name2.getRank());
613

    
614
    }
615

    
616

    
617
    /**
618
     * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#parseFullName(java.lang.String, eu.etaxonomy.cdm.model.name.Rank)}.
619
     */
620
    @Test
621
    public final void testHybridFormulars() {
622
        try {
623
            Method parseMethod = parser.getClass().getDeclaredMethod("parseFullName", String.class, NomenclaturalCode.class, Rank.class);
624
            testName_StringNomcodeRank(parseMethod);
625
        } catch (Exception e) {
626
            e.printStackTrace();
627
            assertTrue(false);
628
        }
629

    
630
        //Species hybrid
631
        String hybridCache = "Abies alba "+UTF8.HYBRID+" Pinus bus";
632
        INonViralName name1 = parser.parseFullName(hybridCache, botanicCode, null);
633
        assertTrue("Name must have hybrid formula bit set", name1.isHybridFormula());
634
        assertEquals("Name must have 2 hybrid parents", 2, name1.getHybridChildRelations().size());
635
        assertEquals("Title cache must be correct", hybridCache, name1.getTitleCache());
636
        List<HybridRelationship> orderedRels = name1.getOrderedChildRelationships();
637
        assertEquals("Name must have 2 hybrid parents in ordered list", 2, orderedRels.size());
638
        TaxonName firstParent = orderedRels.get(0).getParentName();
639
        assertEquals("Name must have Abies alba as first hybrid parent", "Abies alba", firstParent.getTitleCache());
640
        TaxonName secondParent = orderedRels.get(1).getParentName();
641
        assertEquals("Name must have Pinus bus as second hybrid parent", "Pinus bus", secondParent.getTitleCache());
642
        assertEquals("Hybrid name must have the lowest rank ('species') as rank", Rank.SPECIES(), name1.getRank());
643
        assertNull("Name must not have a genus eptithet", name1.getGenusOrUninomial());
644
        assertNull("Name must not have a specific eptithet", name1.getSpecificEpithet());
645
        assertFalse("Name must not have parsing problems", name1.hasProblem());
646

    
647
        name1 = parser.parseReferencedName(hybridCache, botanicCode, null);
648
        assertFalse("Name must not have parsing problems", name1.hasProblem());
649

    
650
        //x-sign
651
        hybridCache = "Abies alba x Pinus bus";
652
        name1 = parser.parseFullName(hybridCache, botanicCode, null);
653
        assertFalse("Name must be parsable", name1.hasProblem());
654
        assertTrue("Name must have hybrid formula bit set", name1.isHybridFormula());
655
        assertFalse("Name must not have parsing problems", name1.hasProblem());
656

    
657
        //Genus //#6030
658
        hybridCache = "Orchis "+UTF8.HYBRID+" Platanthera";
659
        name1 = parser.parseFullName(hybridCache, botanicCode, null);
660
        assertFalse("Name must be parsable", name1.hasProblem());
661
        assertTrue("Name must have hybrid formula bit set", name1.isHybridFormula());
662
        assertFalse("Name must not have parsing problems", name1.hasProblem());
663
        assertEquals("Title cache must be correct", hybridCache, name1.getTitleCache());
664
        orderedRels = name1.getOrderedChildRelationships();
665
        assertEquals("Name must have 2 hybrid parents in ordered list", 2, orderedRels.size());
666
        firstParent = orderedRels.get(0).getParentName();
667
        assertEquals("Name must have Orchis as first hybrid parent", "Orchis", firstParent.getTitleCache());
668
        secondParent = orderedRels.get(1).getParentName();
669
        assertEquals("Name must have Platanthera as second hybrid parent", "Platanthera", secondParent.getTitleCache());
670
        assertEquals("Hybrid name must have genus as rank", Rank.GENUS(), name1.getRank());
671

    
672
        name1 = parser.parseReferencedName(hybridCache, botanicCode, null);
673
        assertFalse("Name must not have parsing problems", name1.hasProblem());
674

    
675
        //Subspecies first hybrid
676
        name1 = parser.parseFullName("Abies alba subsp. beta "+UTF8.HYBRID+" Pinus bus", 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
        assertEquals("Title cache must be correct", "Abies alba subsp. beta "+UTF8.HYBRID+" Pinus bus", name1.getTitleCache());
680
        orderedRels = name1.getOrderedChildRelationships();
681
        assertEquals("Name must have 2 hybrid parents in ordered list", 2, orderedRels.size());
682
        firstParent = orderedRels.get(0).getParentName();
683
        assertEquals("Name must have Abies alba subsp. beta as first hybrid parent", "Abies alba subsp. beta", firstParent.getTitleCache());
684
        secondParent = orderedRels.get(1).getParentName();
685
        assertEquals("Name must have Pinus bus as second hybrid parent", "Pinus bus", secondParent.getTitleCache());
686
        assertEquals("Hybrid name must have the lower rank ('subspecies') as rank", Rank.SUBSPECIES(), name1.getRank());
687

    
688
        //variety second hybrid
689
        name1 = parser.parseFullName("Abies alba \u00D7 Pinus bus  var. beta", botanicCode, null);
690
        assertTrue("Name must have hybrid formula bit set", name1.isHybridFormula());
691
        assertEquals("Name must have 2 hybrid parents", 2, name1.getHybridChildRelations().size());
692
        assertEquals("Title cache must be correct", "Abies alba \u00D7 Pinus bus var. beta", name1.getTitleCache());
693
        assertEquals("Hybrid name must have the lower rank ('variety') as rank", Rank.VARIETY(), name1.getRank());
694

    
695
        //hybrids with authors  //happens but questionable
696
        name1 = parser.parseFullName("Abies alba L. \u00D7 Pinus bus Mill.", botanicCode, null);
697
        assertTrue("Name must have hybrid formula bit set", name1.isHybridFormula());
698
        assertEquals("Name must have 2 hybrid parents", 2, name1.getHybridChildRelations().size());
699
        assertEquals("Title cache must be correct", "Abies alba L. \u00D7 Pinus bus Mill.", name1.getTitleCache());
700
        orderedRels = name1.getOrderedChildRelationships();
701
        assertEquals("Name must have 2 hybrid parents in ordered list", 2, orderedRels.size());
702
        firstParent = orderedRels.get(0).getParentName();
703
        assertEquals("Name must have Abies alba L. as first hybrid parent", "Abies alba L.", firstParent.getTitleCache());
704
        secondParent = orderedRels.get(1).getParentName();
705
        assertEquals("Name must have Pinus bus Mill. as second hybrid parent", "Pinus bus Mill.", secondParent.getTitleCache());
706
        assertEquals("Hybrid name must have the lower rank ('species') as rank", Rank.SPECIES(), name1.getRank());
707

    
708
        //abbreviated genus hybrid formula #6410 / #5983
709
        String nameStr = "Nepenthes mirabilis \u00D7 N. alata";
710
        name1 = parser.parseFullName(nameStr, botanicCode, null);
711
        assertTrue("Name must have hybrid formula bit set", name1.isHybridFormula());
712
        assertEquals("Name must have 2 hybrid parents", 2, name1.getHybridChildRelations().size());
713
        //could also be N. or no genus at all, depends on formatter
714
        assertEquals("Title cache must be correct", "Nepenthes mirabilis \u00D7 Nepenthes alata", name1.getTitleCache());
715
        orderedRels = name1.getOrderedChildRelationships();
716
        assertEquals("Name must have 2 hybrid parents in ordered list", 2, orderedRels.size());
717
        firstParent = orderedRels.get(0).getParentName();
718
        //to be discussed as usually they should be ordered alphabetically
719
        assertEquals("Name must have Nepenthes mirabilis as first hybrid parent", "Nepenthes mirabilis", firstParent.getTitleCache());
720
        secondParent = orderedRels.get(1).getParentName();
721
        assertEquals("Name must have Nepenthes alata as second hybrid parent", "Nepenthes alata", secondParent.getTitleCache());
722
        assertEquals("Hybrid name must have the lower rank ('species') as rank", Rank.SPECIES(), name1.getRank());
723

    
724
        //missing genus hybrid formula #5983
725
        nameStr = "Nepenthes mirabilis \u00D7 alata";
726
        name1 = parser.parseFullName(nameStr, botanicCode, null);
727
        assertTrue("Name must have hybrid formula bit set", name1.isHybridFormula());
728
        assertEquals("Name must have 2 hybrid parents", 2, name1.getHybridChildRelations().size());
729
        //could also be N. or no genus at all, depends on formatter
730
        assertEquals("Title cache must be correct", "Nepenthes mirabilis \u00D7 Nepenthes alata", name1.getTitleCache());
731
        orderedRels = name1.getOrderedChildRelationships();
732
        assertEquals("Name must have 2 hybrid parents in ordered list", 2, orderedRels.size());
733
        firstParent = orderedRels.get(0).getParentName();
734
        //to be discussed as usually they should be ordered alphabetically
735
        assertEquals("Name must have Nepenthes mirabilis as first hybrid parent", "Nepenthes mirabilis", firstParent.getTitleCache());
736
        secondParent = orderedRels.get(1).getParentName();
737
        assertEquals("Name must have Nepenthes alata as second hybrid parent", "Nepenthes alata", secondParent.getTitleCache());
738
        assertEquals("Hybrid name must have the lower rank ('species') as rank", Rank.SPECIES(), name1.getRank());
739

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

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

    
770
        //subspecies and variety with missing genus part
771
        nameStr = "Orchis morio subsp. syriaca \u00D7 papilionacea var. schirvanica";
772
        name1 = parser.parseFullName(nameStr, botanicCode, null);
773
        assertTrue("Name must have hybrid formula bit set", name1.isHybridFormula());
774
        assertEquals("Name must have 2 hybrid parents", 2, name1.getHybridChildRelations().size());
775
        //could also be N. or no genus at all, depends on formatter
776
        assertEquals("Title cache must be correct", "Orchis morio subsp. syriaca \u00D7 Orchis papilionacea var. schirvanica", name1.getTitleCache());
777
        orderedRels = name1.getOrderedChildRelationships();
778
        assertEquals("Name must have 2 hybrid parents in ordered list", 2, orderedRels.size());
779
        firstParent = orderedRels.get(0).getParentName();
780
        assertEquals("Name must have Orchis morio subsp. syriaca as first hybrid parent", "Orchis morio subsp. syriaca", firstParent.getTitleCache());
781
        secondParent = orderedRels.get(1).getParentName();
782
        assertEquals("Name must have Orchis papilionacea var. schirvanica as second hybrid parent", "Orchis papilionacea var. schirvanica", secondParent.getTitleCache());
783
        assertEquals("Hybrid name must have the lower rank ('variety') as rank", Rank.VARIETY(), name1.getRank());
784

    
785
        //2 subspecies with missing genus and species part #5983
786
        nameStr = "Orchis morio subsp. syriaca \u00D7 subsp. schirvanica";
787
        name1 = parser.parseFullName(nameStr, botanicCode, null);
788
        assertTrue("Name must have hybrid formula bit set", name1.isHybridFormula());
789
        assertEquals("Name must have 2 hybrid parents", 2, name1.getHybridChildRelations().size());
790
        //could also be N. or no genus at all, depends on formatter
791
        assertEquals("Title cache must be correct", "Orchis morio subsp. syriaca \u00D7 Orchis morio subsp. schirvanica", name1.getTitleCache());
792
        orderedRels = name1.getOrderedChildRelationships();
793
        assertEquals("Name must have 2 hybrid parents in ordered list", 2, orderedRels.size());
794
        firstParent = orderedRels.get(0).getParentName();
795
        assertEquals("Name must have Orchis morio subsp. syriaca as first hybrid parent", "Orchis morio subsp. syriaca", firstParent.getTitleCache());
796
        secondParent = orderedRels.get(1).getParentName();
797
        assertEquals("Name must have Orchis morio subsp. schirvanica as second hybrid parent", "Orchis morio subsp. schirvanica", secondParent.getTitleCache());
798
        assertEquals("Hybrid name must have the lower rank ('subspecies') as rank", Rank.SUBSPECIES(), name1.getRank());
799

    
800
        //subspecies and variety with missing genus and species part #5983
801
        nameStr = "Orchis morio subsp. syriaca \u00D7 var. schirvanica";
802
        name1 = parser.parseFullName(nameStr, botanicCode, null);
803
        assertTrue("Name must have hybrid formula bit set", name1.isHybridFormula());
804
        assertEquals("Name must have 2 hybrid parents", 2, name1.getHybridChildRelations().size());
805
        //could also be N. or no genus at all, depends on formatter
806
        assertEquals("Title cache must be correct", "Orchis morio subsp. syriaca \u00D7 Orchis morio var. schirvanica", name1.getTitleCache());
807
        orderedRels = name1.getOrderedChildRelationships();
808
        assertEquals("Name must have 2 hybrid parents in ordered list", 2, orderedRels.size());
809
        firstParent = orderedRels.get(0).getParentName();
810
        assertEquals("Name must have Orchis morio subsp. syriaca as first hybrid parent", "Orchis morio subsp. syriaca", firstParent.getTitleCache());
811
        secondParent = orderedRels.get(1).getParentName();
812
        assertEquals("Name must have Orchis morio subsp. schirvanica as second hybrid parent", "Orchis morio var. schirvanica", secondParent.getTitleCache());
813
        assertEquals("Hybrid name must have the lower rank ('variety') as rank", Rank.VARIETY(), name1.getRank());
814

    
815

    
816
    }
817

    
818
    @Test
819
    public final void testTemp(){
820

    
821
//        String nameStr = "Mentha aquatica L. x Mentha spicata L.";
822
//        INonViralName name = parser.parseFullName(nameStr, botanicCode, null);
823
//        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
824
//        assertFalse( name.getHybridChildRelations().isEmpty());
825
//        for (HybridRelationship rel : name.getHybridChildRelations()){
826
//            TaxonName parent = rel.getParentName();
827
//            System.out.println(parent.getTitleCache());
828
//        }
829
    }
830

    
831

    
832
    @Test
833
    public final void testHybridsRemoval(){
834
        //if the parser input already has hybridrelationships they need to be removed
835
        //Create input
836
        String hybridCache = "Abies alba "+UTF8.HYBRID+" Pinus bus";
837
        INonViralName name1 = parser.parseFullName(hybridCache, botanicCode, null);
838
        assertFalse("Name must not have parsing problems", name1.hasProblem());
839
        assertTrue("", name1.getHybridChildRelations().size() == 2);
840

    
841
        hybridCache = "Abieta albana "+UTF8.HYBRID+" Pinuta custa";
842
        boolean makeEmpty = true;
843
        parser.parseFullName(name1, hybridCache, Rank.SPECIES(), makeEmpty);
844
        assertEquals("After parsing another string there should still be 2 parents, but different ones", 2, name1.getHybridChildRelations().size());
845
        assertFalse("Name must not have parsing problems", name1.hasProblem());
846

    
847

    
848
        hybridCache = "Calendula arvensis Mill.";
849
        makeEmpty = true;
850
        parser.parseFullName(name1, hybridCache, Rank.SPECIES(), makeEmpty);
851
        assertTrue("", name1.getHybridChildRelations().isEmpty());
852
        assertFalse("Name must not have parsing problems", name1.hasProblem());
853

    
854

    
855
        //AND the same for reference parsing
856
        hybridCache = "Abies alba "+UTF8.HYBRID+" Pinus bus";
857
        name1 = parser.parseReferencedName(hybridCache, botanicCode, null);
858
        assertFalse("Name must not have parsing problems", name1.hasProblem());
859
        assertTrue("", name1.getHybridChildRelations().size() == 2);
860

    
861
        hybridCache = "Abieta albana "+UTF8.HYBRID+" Pinuta custa";
862
        makeEmpty = true;
863
        parser.parseReferencedName(name1, hybridCache, Rank.SPECIES(), makeEmpty);
864
        assertEquals("After parsing another string there should still be 2 parents, but different ones", 2, name1.getHybridChildRelations().size());
865
        assertFalse("Name must not have parsing problems", name1.hasProblem());
866

    
867

    
868
        hybridCache = "Calendula arvensis Mill.";
869
        makeEmpty = true;
870
        parser.parseReferencedName(name1, hybridCache, Rank.SPECIES(), makeEmpty);
871
        assertTrue("", name1.getHybridChildRelations().isEmpty());
872
        assertFalse("Name must not have parsing problems", name1.hasProblem());
873
    }
874

    
875
    private void testName_StringNomcodeRank(Method parseMethod)
876
            throws InvocationTargetException, IllegalAccessException  {
877
        INonViralName name1 = (INonViralName)parseMethod.invoke(parser, strNameAbies1, null, Rank.SPECIES());
878
        //parser.parseFullName(strNameAbies1, null, Rank.SPECIES());
879
        assertEquals("Abies", name1.getGenusOrUninomial());
880
        assertEquals("alba", name1.getSpecificEpithet());
881

    
882
        INonViralName nameAuthor = (INonViralName)parseMethod.invoke(parser, strNameAbiesAuthor1, null, Rank.SPECIES());
883
        assertEquals("Abies", nameAuthor.getGenusOrUninomial());
884
        assertEquals("alba", nameAuthor.getSpecificEpithet());
885
        assertEquals("Mueller", nameAuthor.getCombinationAuthorship().getNomenclaturalTitle());
886

    
887
        INonViralName nameBasionymAuthor = (INonViralName)parseMethod.invoke(parser, strNameAbiesBasionymAuthor1, null, Rank.SPECIES());
888
        assertEquals("Abies", nameBasionymAuthor.getGenusOrUninomial());
889
        assertEquals("alba", nameBasionymAuthor.getSpecificEpithet());
890
        assertEquals("D'Mueller", nameBasionymAuthor.getCombinationAuthorship().getNomenclaturalTitle());
891
        assertEquals("Ciardelli", nameBasionymAuthor.getBasionymAuthorship().getNomenclaturalTitle());
892

    
893
        INonViralName nameBasionymExAuthor = (INonViralName)parseMethod.invoke(parser, strNameAbiesBasionymExAuthor1, null, Rank.SPECIES());
894
        assertEquals("Abies", nameBasionymExAuthor.getGenusOrUninomial());
895
        assertEquals("alba", nameBasionymExAuthor.getSpecificEpithet());
896
        assertEquals("D'Mueller", nameBasionymExAuthor.getExCombinationAuthorship().getNomenclaturalTitle());
897
        assertEquals("de Greuther", nameBasionymExAuthor.getCombinationAuthorship().getNomenclaturalTitle());
898
        assertEquals("Ciardelli", nameBasionymExAuthor.getExBasionymAuthorship().getNomenclaturalTitle());
899
        assertEquals("Doering", nameBasionymExAuthor.getBasionymAuthorship().getNomenclaturalTitle());
900

    
901
        INonViralName name2 = (INonViralName)parseMethod.invoke(parser, strNameAbiesSub1, null, Rank.SPECIES());
902
        assertEquals("Abies", name2.getGenusOrUninomial());
903
        assertEquals("alba", name2.getSpecificEpithet());
904
        assertEquals("beta", name2.getInfraSpecificEpithet());
905
        assertEquals(Rank.SUBSPECIES(), name2.getRank());
906

    
907

    
908
        // unparseable *********
909
        String problemString = "sdfjlös wer eer wer";
910
        INonViralName nameProblem = (INonViralName)parseMethod.invoke(parser, problemString, null, Rank.SPECIES());
911
        List<ParserProblem> list = nameProblem.getParsingProblems();
912
        assertTrue(nameProblem.getParsingProblem()!=0);
913
        assertEquals(problemString, nameProblem.getTitleCache());
914
    }
915

    
916

    
917
    /**
918
     * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#parseReferencedName(NonViralName, java.lang.String, eu.etaxonomy.cdm.model.name.Rank, boolean)(, )}.
919
     */
920
    @Test
921
    public final void testParseNomStatus() {
922
        //nom. ambig.
923
        String strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. ambig.";
924
        INonViralName nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
925
        assertFullRefStandard(nameTestStatus);
926
        assertTrue(nameTestStatus.getStatus().size()== 1);
927
        assertEquals( NomenclaturalStatusType.AMBIGUOUS(), nameTestStatus.getStatus().iterator().next().getType());
928

    
929
        //nom. inval.
930
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. inval.";
931
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
932
        assertFullRefStandard(nameTestStatus);
933
        assertTrue(nameTestStatus.getStatus().size()== 1);
934
        assertEquals( NomenclaturalStatusType.INVALID(), nameTestStatus.getStatus().iterator().next().getType());
935

    
936
        //nom. dub.
937
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. dub.";
938
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
939
        assertFullRefStandard(nameTestStatus);
940
        assertTrue(nameTestStatus.getStatus().size()== 1);
941
        assertEquals( NomenclaturalStatusType.DOUBTFUL(), nameTestStatus.getStatus().iterator().next().getType());
942

    
943
        //nom. confus.
944
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. confus.";
945
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
946
        assertFullRefStandard(nameTestStatus);
947
        assertTrue(nameTestStatus.getStatus().size()== 1);
948
        assertEquals( NomenclaturalStatusType.CONFUSUM(), nameTestStatus.getStatus().iterator().next().getType());
949

    
950
        //nom. illeg.
951
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. illeg.";
952
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
953
        assertFullRefStandard(nameTestStatus);
954
        assertTrue(nameTestStatus.getStatus().size()== 1);
955
        assertEquals( NomenclaturalStatusType.ILLEGITIMATE(), nameTestStatus.getStatus().iterator().next().getType());
956

    
957
        //nom. superfl.
958
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. superfl.";
959
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
960
        assertFullRefStandard(nameTestStatus);
961
        assertTrue(nameTestStatus.getStatus().size()== 1);
962
        assertEquals( NomenclaturalStatusType.SUPERFLUOUS(), nameTestStatus.getStatus().iterator().next().getType());
963

    
964
        //nom. rej.
965
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. rej.";
966
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
967
        assertFullRefStandard(nameTestStatus);
968
        assertTrue(nameTestStatus.getStatus().size()== 1);
969
        assertEquals( NomenclaturalStatusType.REJECTED(), nameTestStatus.getStatus().iterator().next().getType());
970

    
971
        //nom. utique rej.
972
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. utique rej.";
973
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
974
        assertFullRefStandard(nameTestStatus);
975
        assertTrue(nameTestStatus.getStatus().size()== 1);
976
        assertEquals( NomenclaturalStatusType.UTIQUE_REJECTED(), nameTestStatus.getStatus().iterator().next().getType());
977

    
978
        //nom. cons. prop.
979
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. cons. prop.";
980
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
981
        assertFullRefStandard(nameTestStatus);
982
        assertTrue(nameTestStatus.getStatus().size()== 1);
983
        assertEquals( NomenclaturalStatusType.CONSERVED_PROP(), nameTestStatus.getStatus().iterator().next().getType());
984

    
985
        //nom. orth. cons. prop.
986
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. orth. cons. prop.";
987
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
988
        assertFullRefStandard(nameTestStatus);
989
        assertTrue(nameTestStatus.getStatus().size()== 1);
990
        assertEquals( NomenclaturalStatusType.ORTHOGRAPHY_CONSERVED_PROP(), nameTestStatus.getStatus().iterator().next().getType());
991

    
992
        //nom. cons. prop.
993
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. cons. des.";
994
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
995
        assertFullRefStandard(nameTestStatus);
996
        assertTrue(nameTestStatus.getStatus().size()== 1);
997
        assertEquals( NomenclaturalStatusType.CONSERVED_DESIG(), nameTestStatus.getStatus().iterator().next().getType());
998

    
999
        //nom. legit.
1000
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. legit.";
1001
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
1002
        assertFullRefStandard(nameTestStatus);
1003
        assertTrue(nameTestStatus.getStatus().size()== 1);
1004
        assertEquals( NomenclaturalStatusType.LEGITIMATE(), nameTestStatus.getStatus().iterator().next().getType());
1005

    
1006
        //nom. altern.
1007
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. altern.";
1008
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
1009
        assertFullRefStandard(nameTestStatus);
1010
        assertTrue(nameTestStatus.getStatus().size()== 1);
1011
        assertEquals( NomenclaturalStatusType.ALTERNATIVE(), nameTestStatus.getStatus().iterator().next().getType());
1012

    
1013
        //nom. alternativ.
1014
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. alternativ.";
1015
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
1016
        assertFullRefStandard(nameTestStatus);
1017
        assertTrue(nameTestStatus.getStatus().size()== 1);
1018
        assertEquals( NomenclaturalStatusType.ALTERNATIVE(), nameTestStatus.getStatus().iterator().next().getType());
1019

    
1020
        //nom. nov.
1021
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. nov.";
1022
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
1023
        assertFullRefStandard(nameTestStatus);
1024
        assertTrue(nameTestStatus.getStatus().size()== 1);
1025
        assertEquals( NomenclaturalStatusType.NOVUM(), nameTestStatus.getStatus().iterator().next().getType());
1026

    
1027
        //nom. utique rej. prop.
1028
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. utique rej. prop.";
1029
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
1030
        assertFullRefStandard(nameTestStatus);
1031
        assertTrue(nameTestStatus.getStatus().size()== 1);
1032
        assertEquals( NomenclaturalStatusType.UTIQUE_REJECTED_PROP(), nameTestStatus.getStatus().iterator().next().getType());
1033

    
1034
        //nom. orth. cons.
1035
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. orth. cons.";
1036
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
1037
        assertFullRefStandard(nameTestStatus);
1038
        assertTrue(nameTestStatus.getStatus().size()== 1);
1039
        assertEquals( NomenclaturalStatusType.ORTHOGRAPHY_CONSERVED(), nameTestStatus.getStatus().iterator().next().getType());
1040

    
1041
        //nom. rej. prop.
1042
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. rej. prop.";
1043
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
1044
        assertFullRefStandard(nameTestStatus);
1045
        assertTrue(nameTestStatus.getStatus().size()== 1);
1046
        assertEquals( NomenclaturalStatusType.REJECTED_PROP(), nameTestStatus.getStatus().iterator().next().getType());
1047

    
1048
        //nom. cons.
1049
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. cons.";
1050
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
1051
        assertFullRefStandard(nameTestStatus);
1052
        assertTrue(nameTestStatus.getStatus().size()== 1);
1053
        assertEquals( NomenclaturalStatusType.CONSERVED(), nameTestStatus.getStatus().iterator().next().getType());
1054

    
1055
        //nom. sanct.
1056
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. sanct.";
1057
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
1058
        assertFullRefStandard(nameTestStatus);
1059
        assertTrue(nameTestStatus.getStatus().size()== 1);
1060
        assertEquals( NomenclaturalStatusType.SANCTIONED(), nameTestStatus.getStatus().iterator().next().getType());
1061

    
1062
        //nom. nud.
1063
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. nud.";
1064
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
1065
        assertFullRefStandard(nameTestStatus);
1066
        assertTrue(nameTestStatus.getStatus().size()== 1);
1067
        assertEquals( NomenclaturalStatusType.NUDUM(), nameTestStatus.getStatus().iterator().next().getType());
1068

    
1069
        //comb. inval.
1070
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, comb. inval.";
1071
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
1072
        assertFullRefStandard(nameTestStatus);
1073
        assertTrue(nameTestStatus.getStatus().size()== 1);
1074
        assertEquals( NomenclaturalStatusType.COMBINATION_INVALID(), nameTestStatus.getStatus().iterator().next().getType());
1075

    
1076
        //comb. illeg.
1077
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, comb. illeg.";
1078
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
1079
        assertFullRefStandard(nameTestStatus);
1080
        assertTrue(nameTestStatus.getStatus().size()== 1);
1081
        assertEquals( NomenclaturalStatusType.COMBINATION_ILLEGITIMATE(), nameTestStatus.getStatus().iterator().next().getType());
1082

    
1083
        //nom. provis.
1084
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. provis.";
1085
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
1086
        assertFullRefStandard(nameTestStatus);
1087
        assertTrue(nameTestStatus.getStatus().size()== 1);
1088
        assertEquals( NomenclaturalStatusType.PROVISIONAL(), nameTestStatus.getStatus().iterator().next().getType());
1089

    
1090
        //nom. val.
1091
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. val.";
1092
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
1093
        assertFullRefStandard(nameTestStatus);
1094
        assertTrue(nameTestStatus.getStatus().size()== 1);
1095
        assertEquals( NomenclaturalStatusType.VALID(), nameTestStatus.getStatus().iterator().next().getType());
1096

    
1097
        //nom. subnud.
1098
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. subnud.";
1099
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
1100
        assertFullRefStandard(nameTestStatus);
1101
        assertTrue(nameTestStatus.getStatus().size()== 1);
1102
        assertEquals( NomenclaturalStatusType.SUBNUDUM(), nameTestStatus.getStatus().iterator().next().getType());
1103

    
1104
        //opus. utique oppr.
1105
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, opus. utique oppr.";
1106
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
1107
        assertFullRefStandard(nameTestStatus);
1108
        assertTrue(nameTestStatus.getStatus().size()== 1);
1109
        assertEquals( NomenclaturalStatusType.OPUS_UTIQUE_OPPR(), nameTestStatus.getStatus().iterator().next().getType());
1110

    
1111
        //comb. nov.
1112
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, comb. nov.";
1113
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
1114
        assertFullRefStandard(nameTestStatus);
1115
        assertTrue(nameTestStatus.getStatus().size()== 1);
1116
        assertEquals( NomenclaturalStatusType.COMB_NOV(), nameTestStatus.getStatus().iterator().next().getType());
1117

    
1118
        //orth. rej.
1119
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, orth. rej.";
1120
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
1121
        assertFullRefStandard(nameTestStatus);
1122
        assertTrue(nameTestStatus.getStatus().size()== 1);
1123
        assertEquals( NomenclaturalStatusType.ORTHOGRAPHY_REJECTED(), nameTestStatus.getStatus().iterator().next().getType());
1124

    
1125
        //ined.
1126
        strTestStatus = "Houstonia macvaughii (Terrell), ined.";
1127
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
1128
        assertEquals("Houstonia", nameTestStatus.getGenusOrUninomial());
1129
        assertEquals("macvaughii", nameTestStatus.getSpecificEpithet());
1130
        assertEquals("(Terrell)", nameTestStatus.getAuthorshipCache());
1131
        assertEquals(1, nameTestStatus.getStatus().size());
1132
        assertEquals( NomenclaturalStatusType.INED(), nameTestStatus.getStatus().iterator().next().getType());
1133

    
1134
        //not yet parsed "not avail."
1135
    }
1136

    
1137
    /**
1138
     * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#parseReferencedName(NonViralName, java.lang.String, eu.etaxonomy.cdm.model.name.Rank, boolean)(, )}.
1139
     */
1140
    @Test
1141
    public final void testParseReferencedName() {
1142
        try {
1143
            Method parseMethod = parser.getClass().getDeclaredMethod("parseReferencedName", String.class, NomenclaturalCode.class, Rank.class);
1144
            testName_StringNomcodeRank(parseMethod);
1145
        } catch (Exception e) {
1146
            e.printStackTrace();
1147
            assertTrue(false);
1148
        }
1149

    
1150

    
1151
        //null
1152
        String strNull = null;
1153
        Rank rankSpecies = Rank.SPECIES();
1154
        INonViralName nameNull = parser.parseReferencedName(strNull, null, rankSpecies);
1155
        assertNull(nameNull);
1156

    
1157
        //Empty
1158
        String strEmpty = "";
1159
        INonViralName nameEmpty = parser.parseReferencedName(strEmpty, null, rankSpecies);
1160
        assertFalse(nameEmpty.hasProblem());
1161
        assertEquals(strEmpty, nameEmpty.getFullTitleCache());
1162
        assertNull(nameEmpty.getNomenclaturalMicroReference());
1163

    
1164

    
1165
        //Whitespaces
1166
        String strFullWhiteSpcaceAndDot = "Abies alba Mill.,  Sp.   Pl.  4:  455 .  1987 .";
1167
        INonViralName namefullWhiteSpcaceAndDot = parser.parseReferencedName(strFullWhiteSpcaceAndDot, null, rankSpecies);
1168
        assertFullRefStandard(namefullWhiteSpcaceAndDot);
1169
        assertTrue(namefullWhiteSpcaceAndDot.getNomenclaturalReference().getType().equals(eu.etaxonomy.cdm.model.reference.ReferenceType.Book));
1170
        assertEquals( "Abies alba Mill., Sp. Pl. 4: 455. 1987", namefullWhiteSpcaceAndDot.getFullTitleCache());
1171

    
1172
        //Book
1173
        String fullReference = "Abies alba Mill., Sp. Pl. 4: 455. 1987";
1174
        INonViralName name1 = parser.parseReferencedName(fullReference, null, rankSpecies);
1175
        assertFullRefStandard(name1);
1176
        assertTrue(name1.getNomenclaturalReference().getType().equals(eu.etaxonomy.cdm.model.reference.ReferenceType.Book));
1177
        assertEquals(fullReference, name1.getFullTitleCache());
1178
        assertTrue("Name author and reference author should be the same", name1.getCombinationAuthorship() == name1.getNomenclaturalReference().getAuthorship());
1179

    
1180
        //Book Section
1181
        fullReference = "Abies alba Mill. in Otto, Sp. Pl. 4(6): 455. 1987";
1182
        INonViralName name2 = parser.parseReferencedName(fullReference + ".", null, rankSpecies);
1183
        assertFullRefNameStandard(name2);
1184
        assertEquals(fullReference, name2.getFullTitleCache());
1185
        assertFalse(name2.hasProblem());
1186
        INomenclaturalReference ref = name2.getNomenclaturalReference();
1187
        assertEquals(ReferenceType.BookSection, ((Reference)ref).getType());
1188
        IBookSection bookSection = (IBookSection) ref;
1189
        IBook inBook = bookSection.getInBook();
1190
        assertNotNull(inBook);
1191
        assertNotNull(inBook.getAuthorship());
1192
        assertEquals("Otto", inBook.getAuthorship().getTitleCache());
1193
        assertEquals("Otto, Sp. Pl. 4(6)", inBook.getTitleCache());
1194
        assertEquals("Sp. Pl.", inBook.getAbbrevTitle());
1195
        assertEquals("4(6)", inBook.getVolume());
1196
        assertTrue("Name author and reference author should be the same", name2.getCombinationAuthorship() == name2.getNomenclaturalReference().getAuthorship());
1197

    
1198
        //Article
1199
        fullReference = "Abies alba Mill. in Sp. Pl. 4(6): 455. 1987";
1200
        INonViralName name3 = parser.parseReferencedName(fullReference, null, rankSpecies);
1201
        assertFullRefNameStandard(name3);
1202
        name3.setTitleCache(null);
1203
        assertEquals(fullReference, name3.getFullTitleCache());
1204
        assertFalse(name3.hasProblem());
1205
        ref = name3.getNomenclaturalReference();
1206
        assertEquals(eu.etaxonomy.cdm.model.reference.ReferenceType.Article, ref.getType());
1207
        //Article article = (Article)ref;
1208
        IJournal journal = ((IArticle)ref).getInJournal();
1209
        assertNotNull(journal);
1210
        //assertEquals("Sp. Pl. 4(6)", inBook.getTitleCache());
1211
        assertEquals("Sp. Pl.",((Reference) journal).getTitleCache());
1212
        assertEquals("Sp. Pl.", journal.getAbbrevTitle());
1213
        assertEquals("4(6)",((IArticle)ref).getVolume());
1214
        assertTrue("Name author and reference author should be the same", name3.getCombinationAuthorship() == name3.getNomenclaturalReference().getAuthorship());
1215

    
1216
        //Article with volume range
1217
        fullReference = "Abies alba Mill. in Sp. Pl. 4(1-2): 455. 1987";
1218
        INonViralName name3a = parser.parseReferencedName(fullReference, null, rankSpecies);
1219
        name3a.setTitleCache(null);
1220
        assertEquals(fullReference, name3a.getFullTitleCache());
1221
        assertFalse(name3a.hasProblem());
1222
        ref = name3a.getNomenclaturalReference();
1223
        assertEquals(eu.etaxonomy.cdm.model.reference.ReferenceType.Article, ref.getType());
1224
        assertEquals("4(1-2)",((IArticle)ref).getVolume());
1225

    
1226
        //SoftArticle - having "," on position > 4
1227
        String journalTitle = "Bull. Soc. Bot.France. Louis., Roi";
1228
        String yearPart = " 1987 - 1989";
1229
        String parsedYear = "1987-1989";
1230
        String fullReferenceWithoutYear = "Abies alba Mill. in " + journalTitle + " 4(6): 455.";
1231
        fullReference = fullReferenceWithoutYear + yearPart;
1232
        String fullReferenceWithEnd = fullReference + ".";
1233
        INonViralName name4 = parser.parseReferencedName(fullReferenceWithEnd, null, rankSpecies);
1234
        assertFalse(name4.hasProblem());
1235
        assertFullRefNameStandard(name4);
1236
        assertEquals(fullReferenceWithoutYear + " " + parsedYear, name4.getFullTitleCache());
1237
        ref = name4.getNomenclaturalReference();
1238
        assertEquals(ReferenceType.Article, ref.getType());
1239
        //article = (Article)ref;
1240
        assertEquals(parsedYear, ref.getYear());
1241
        journal = ((IArticle)ref).getInJournal();
1242
        assertNotNull(journal);
1243
        assertEquals(journalTitle, ((Reference) journal).getTitleCache());
1244
        assertEquals(journalTitle, journal.getAbbrevTitle());
1245
        assertEquals("4(6)", ((IArticle)ref).getVolume());
1246

    
1247
        //Zoo name
1248
        String strNotParsableZoo = "Abies alba M., 1923, Sp. P. xxwer4352, nom. inval.";
1249
        IZoologicalName nameZooRefNotParsabel = parser.parseReferencedName(strNotParsableZoo, null, null);
1250
        assertTrue(nameZooRefNotParsabel.hasProblem());
1251
        List<ParserProblem> list = nameZooRefNotParsabel.getParsingProblems();
1252
        assertTrue("List must contain detail and year warning ", list.contains(ParserProblem.CheckDetailOrYear));
1253
        assertEquals(21, nameZooRefNotParsabel.getProblemStarts());
1254
        assertEquals(37, nameZooRefNotParsabel.getProblemEnds());
1255
        assertTrue(nameZooRefNotParsabel.getNomenclaturalReference().hasProblem());
1256
        list = nameZooRefNotParsabel.getNomenclaturalReference().getParsingProblems();
1257
        assertTrue("List must contain detail and year warning ", list.contains(ParserProblem.CheckDetailOrYear));
1258

    
1259
        assertEquals(NomenclaturalCode.ICZN, nameZooRefNotParsabel.getNomenclaturalCode());
1260
        assertEquals(Integer.valueOf(1923), nameZooRefNotParsabel.getPublicationYear());
1261
        assertEquals(1, nameZooRefNotParsabel.getStatus().size());
1262

    
1263
        String strZooNameSineYear = "Homo sapiens L., 1758, Sp. An. 3: 345";
1264
        IZoologicalName nameZooNameSineYear = parser.parseReferencedName(strZooNameSineYear);
1265
        assertFalse(nameZooNameSineYear.hasProblem());
1266
        assertEquals("Name without reference year must have year", (Integer)1758, nameZooNameSineYear.getPublicationYear());
1267
        assertEquals("Name without reference year must have year", "1758", nameZooNameSineYear.getNomenclaturalReference().getYear());
1268

    
1269
        String strZooNameNewCombination = "Homo sapiens (L., 1758) Mill., 1830, Sp. An. 3: 345";
1270
        IZoologicalName nameZooNameNewCombination = parser.parseReferencedName(strZooNameNewCombination);
1271
        assertTrue(nameZooNameNewCombination.hasProblem());
1272
        list = nameZooNameNewCombination.getParsingProblems();
1273
        assertTrue("List must contain new combination has publication warning ", list.contains(ParserProblem.NewCombinationHasPublication));
1274
        assertEquals(35, nameZooNameNewCombination.getProblemStarts());
1275
        assertEquals(51, nameZooNameNewCombination.getProblemEnds());
1276

    
1277

    
1278
        //Special MicroRefs
1279
        String strSpecDetail1 = "Abies alba Mill. in Sp. Pl. 4(6): [455]. 1987";
1280
        INonViralName nameSpecDet1 = parser.parseReferencedName(strSpecDetail1 + ".", null, rankSpecies);
1281
        assertFalse(nameSpecDet1.hasProblem());
1282
        assertEquals(strSpecDetail1, nameSpecDet1.getFullTitleCache());
1283
        assertEquals("[455]", nameSpecDet1.getNomenclaturalMicroReference());
1284

    
1285
        //Special MicroRefs
1286
        String strSpecDetail2 = "Abies alba Mill. in Sp. Pl. 4(6): couv. 2. 1987";
1287
        INonViralName nameSpecDet2 = parser.parseReferencedName(strSpecDetail2 + ".", null, rankSpecies);
1288
        assertFalse(nameSpecDet2.hasProblem());
1289
        assertEquals(strSpecDetail2, nameSpecDet2.getFullTitleCache());
1290
        assertEquals("couv. 2", nameSpecDet2.getNomenclaturalMicroReference());
1291

    
1292
        //Special MicroRefs
1293
        String strSpecDetail3 = "Abies alba Mill. in Sp. Pl. 4(6): fig. 455. 1987";
1294
        INonViralName nameSpecDet3 = parser.parseReferencedName(strSpecDetail3 + ".", null, rankSpecies);
1295
        assertFalse(nameSpecDet3.hasProblem());
1296
        assertEquals(strSpecDetail3, nameSpecDet3.getFullTitleCache());
1297
        assertEquals("fig. 455", nameSpecDet3.getNomenclaturalMicroReference());
1298

    
1299
        //Special MicroRefs
1300
        String strSpecDetail4 = "Abies alba Mill. in Sp. Pl. 4(6): fig. 455-567. 1987";
1301
        fullReference = strSpecDetail4 + ".";
1302
        INonViralName nameSpecDet4 = parser.parseReferencedName(fullReference, null, rankSpecies);
1303
        assertFalse(nameSpecDet4.hasProblem());
1304
        assertEquals(strSpecDetail4, nameSpecDet4.getFullTitleCache());
1305
        assertEquals("fig. 455-567", nameSpecDet4.getNomenclaturalMicroReference());
1306

    
1307

    
1308
        //Special MicroRefs
1309
        String strSpecDetail5 = "Abies alba Mill. in Sp. Pl. 4(6): Gard n\u00B0 4. 1987";
1310
        fullReference = strSpecDetail5 + ".";
1311
        INonViralName nameSpecDet5 = parser.parseReferencedName(fullReference, null, rankSpecies);
1312
        assertFalse(nameSpecDet5.hasProblem());
1313
        assertEquals(strSpecDetail5, nameSpecDet5.getFullTitleCache());
1314
        assertEquals("Gard n\u00B0 4", nameSpecDet5.getNomenclaturalMicroReference());
1315

    
1316
        //Special MicroRefs
1317
        String strSpecDetail6 = "Abies alba Mill. in Sp. Pl. 4(6): 455a. 1987";
1318
        fullReference = strSpecDetail6 + ".";
1319
        INonViralName nameSpecDet6 = parser.parseReferencedName(fullReference, null, rankSpecies);
1320
        assertFalse(nameSpecDet6.hasProblem());
1321
        assertEquals(strSpecDetail6, nameSpecDet6.getFullTitleCache());
1322
        assertEquals("455a", nameSpecDet6.getNomenclaturalMicroReference());
1323

    
1324
        //Special MicroRefs
1325
        String strSpecDetail7 = "Abies alba Mill. in Sp. Pl. 4(6): pp.455-457. 1987";
1326
        fullReference = strSpecDetail7 + ".";
1327
        INonViralName nameSpecDet7 = parser.parseReferencedName(fullReference, null, rankSpecies);
1328
        assertFalse(nameSpecDet7.hasProblem());
1329
        assertEquals(strSpecDetail7, nameSpecDet7.getFullTitleCache());
1330
        assertEquals("pp.455-457", nameSpecDet7.getNomenclaturalMicroReference());
1331

    
1332
        //Special MicroRefs
1333
        String strSpecDetail8 = "Abies alba Mill. in Sp. Pl. 4(6): ppp.455-457. 1987";
1334
        INonViralName nameSpecDet8 = parser.parseReferencedName(strSpecDetail8, null, rankSpecies);
1335
        assertTrue(nameSpecDet8.hasProblem());
1336
        assertEquals(20, nameSpecDet8.getProblemStarts()); //TODO better start behind :
1337
        assertEquals(51, nameSpecDet8.getProblemEnds());   //TODO better stop after -457
1338

    
1339

    
1340
        //Special MicroRefs
1341
        String strSpecDetail9 = "Abies alba Mill. in Sp. Pl. 4(6): pp. 455 - 457. 1987";
1342
        INonViralName nameSpecDet9 = parser.parseReferencedName(strSpecDetail9, null, rankSpecies);
1343
        assertFalse(nameSpecDet9.hasProblem());
1344
        assertEquals(strSpecDetail9, nameSpecDet9.getFullTitleCache());
1345
        assertEquals("pp. 455 - 457", nameSpecDet9.getNomenclaturalMicroReference());
1346

    
1347
        //Special MicroRefs
1348
        String strSpecDetail10 = "Abies alba Mill. in Sp. Pl. 4(6): p 455. 1987";
1349
        INonViralName nameSpecDet10 = parser.parseReferencedName(strSpecDetail10, null, rankSpecies);
1350
        assertFalse(nameSpecDet10.hasProblem());
1351
        assertEquals(strSpecDetail10, nameSpecDet10.getFullTitleCache());
1352
        assertEquals("p 455", nameSpecDet10.getNomenclaturalMicroReference());
1353

    
1354
        //Special MicroRefs
1355
        String strSpecDetail11 = "Abies alba Mill. in Sp. Pl. 4(6): p. 455 - 457. 1987";
1356
        INonViralName nameSpecDet11 = parser.parseReferencedName(strSpecDetail11, null, rankSpecies);
1357
        assertTrue(nameSpecDet11.hasProblem());
1358
        list = nameSpecDet11.getParsingProblems();
1359
        assertTrue("Problem is Detail. Must be pp.", list.contains(ParserProblem.CheckDetailOrYear));
1360
        assertEquals(20, nameSpecDet8.getProblemStarts()); //TODO better start behind :
1361
        assertEquals(51, nameSpecDet8.getProblemEnds());   //TODO better stop after - 457
1362

    
1363

    
1364
        //no volume, no edition
1365
        String strNoVolume = "Abies alba Mill., Sp. Pl.: 455. 1987";
1366
        INonViralName nameNoVolume = parser.parseReferencedName(strNoVolume, null, rankSpecies);
1367
        assertFalse(nameNoVolume.hasProblem());
1368
        assertEquals(strNoVolume, nameNoVolume.getFullTitleCache());
1369
        assertEquals(null, ((IVolumeReference)(nameNoVolume.getNomenclaturalReference())).getVolume());
1370
        assertEquals(null, ((IBook)nameNoVolume.getNomenclaturalReference()).getEdition());
1371

    
1372
        //volume, no edition
1373
        strNoVolume = "Abies alba Mill., Sp. Pl. 2: 455. 1987";
1374
        nameNoVolume = parser.parseReferencedName(strNoVolume, null, rankSpecies);
1375
        assertFalse(nameNoVolume.hasProblem());
1376
        assertEquals(strNoVolume, nameNoVolume.getFullTitleCache());
1377
        assertEquals("2", ((IVolumeReference)(nameNoVolume.getNomenclaturalReference())).getVolume());
1378
        assertEquals(null, ((IBook)(nameNoVolume.getNomenclaturalReference())).getEdition());
1379

    
1380
        //no volume, edition
1381
        strNoVolume = "Abies alba Mill., Sp. Pl., ed. 3: 455. 1987";
1382
        nameNoVolume = parser.parseReferencedName(strNoVolume, null, rankSpecies);
1383
        assertFalse(nameNoVolume.hasProblem());
1384
        assertEquals(strNoVolume, nameNoVolume.getFullTitleCache());
1385
        assertEquals(null, ((IVolumeReference)(nameNoVolume.getNomenclaturalReference())).getVolume());
1386
        assertEquals("3", ((IBook)(nameNoVolume.getNomenclaturalReference())).getEdition());
1387

    
1388
        //volume, edition
1389
        strNoVolume = "Abies alba Mill., Sp. Pl. ed. 3, 4(5): 455. 1987";
1390
        nameNoVolume = parser.parseReferencedName(strNoVolume, null, rankSpecies);
1391
        assertFalse(nameNoVolume.hasProblem());
1392
        assertEquals(strNoVolume.replace(" ed.", ", ed."), nameNoVolume.getFullTitleCache());
1393
        assertEquals("4(5)", ((IVolumeReference)(nameNoVolume.getNomenclaturalReference())).getVolume());
1394
        assertEquals("3", ((IBook)(nameNoVolume.getNomenclaturalReference())).getEdition());
1395

    
1396
        String strUnparsableInRef = "Abies alba Mill. in -er46: 455. 1987";
1397
        INonViralName nameUnparsableInRef = parser.parseReferencedName(strUnparsableInRef, null, rankSpecies);
1398
        assertTrue(nameUnparsableInRef.hasProblem());
1399
        list = nameUnparsableInRef.getParsingProblems();
1400
        assertTrue("Unparsable title", list.contains(ParserProblem.UnparsableReferenceTitle));
1401
        assertEquals(strUnparsableInRef, nameUnparsableInRef.getFullTitleCache());
1402
        assertEquals(20, nameUnparsableInRef.getProblemStarts());
1403
        assertEquals(25, nameUnparsableInRef.getProblemEnds());
1404

    
1405

    
1406
        //volume, edition
1407
        String strNoSeparator = "Abies alba Mill. Sp. Pl. ed. 3, 4(5): 455. 1987";
1408
        INonViralName nameNoSeparator = parser.parseReferencedName(strNoSeparator, ICNAFP, rankSpecies);
1409
        assertTrue(nameNoSeparator.hasProblem());
1410
        list = nameNoSeparator.getParsingProblems();
1411
        assertTrue("Problem is missing name-reference separator", list.contains(ParserProblem.NameReferenceSeparation));
1412
        assertEquals(strNoSeparator, nameNoSeparator.getFullTitleCache());
1413
        assertEquals(10, nameNoSeparator.getProblemStarts()); //TODO better start behind Mill. (?)
1414
        assertEquals(47, nameNoSeparator.getProblemEnds());   //TODO better stop before :
1415

    
1416
        String strUnparsableInRef2 = "Hieracium pepsicum L., My Bookkkk 1. 1903";
1417
        INonViralName nameUnparsableInRef2 = parser.parseReferencedName(strUnparsableInRef2, null, rankSpecies);
1418
        assertTrue(nameUnparsableInRef2.hasProblem());
1419
        list = nameUnparsableInRef2.getParsingProblems();
1420
        assertTrue("Problem detail", list.contains(ParserProblem.CheckDetailOrYear));
1421
        assertEquals(strUnparsableInRef2, nameUnparsableInRef2.getFullTitleCache());
1422
        assertEquals(23, nameUnparsableInRef2.getProblemStarts());
1423
        assertEquals(41, nameUnparsableInRef2.getProblemEnds());
1424

    
1425

    
1426
        String strUnparsableInRef3 = "Hieracium pespcim N., My Bookkkk 1. 1902";
1427
        INonViralName nameUnparsableInRef3 = parser.parseReferencedName(strUnparsableInRef3, null, null);
1428
        assertTrue(nameUnparsableInRef3.hasProblem());
1429
        list = nameUnparsableInRef3.getParsingProblems();
1430
        assertTrue("Problem detail", list.contains(ParserProblem.CheckDetailOrYear));
1431
        assertEquals(strUnparsableInRef3, nameUnparsableInRef3.getFullTitleCache());
1432
        assertEquals(22, nameUnparsableInRef3.getProblemStarts());
1433
        assertEquals(40, nameUnparsableInRef3.getProblemEnds());
1434

    
1435
        String strUnparsableInRef4 = "Hieracium pepsicum (Hsllreterto) L., My Bookkkk 1. 1903";
1436
        INonViralName nameUnparsableInRef4 = parser.parseReferencedName(strUnparsableInRef4, null, null);
1437
        assertTrue(nameUnparsableInRef4.hasProblem());
1438
        list = nameUnparsableInRef4.getParsingProblems();
1439
        assertTrue("Problem detail", list.contains(ParserProblem.CheckDetailOrYear));
1440
        assertEquals(strUnparsableInRef4, nameUnparsableInRef4.getFullTitleCache());
1441
        assertEquals(37, nameUnparsableInRef4.getProblemStarts());
1442
        assertEquals(55, nameUnparsableInRef4.getProblemEnds());
1443

    
1444
        String strSameName = "Hieracium pepcum (Hsllreterto) L., My Bokkk 1. 1903";
1445
        INonViralName nameSameName = nameUnparsableInRef4;
1446
        parser.parseReferencedName(nameSameName, strSameName, null, true);
1447
        assertTrue(nameSameName.hasProblem());
1448
        list = nameSameName.getParsingProblems();
1449
        assertTrue("Problem detail", list.contains(ParserProblem.CheckDetailOrYear));
1450
        assertEquals(strSameName, nameSameName.getFullTitleCache());
1451
        assertEquals(35, nameSameName.getProblemStarts());
1452
        assertEquals(51, nameSameName.getProblemEnds());
1453

    
1454
        String strGenusUnparse = "Hieracium L., jlklk";
1455
        INonViralName nameGenusUnparse =
1456
            parser.parseReferencedName(strGenusUnparse, null, null);
1457
        assertTrue(nameGenusUnparse.hasProblem());
1458
        list = nameGenusUnparse.getParsingProblems();
1459
        assertTrue("Problem detail", list.contains(ParserProblem.CheckDetailOrYear));
1460
        assertTrue("Problem uninomial", list.contains(ParserProblem.CheckRank));
1461
        assertEquals(strGenusUnparse, nameGenusUnparse.getFullTitleCache());
1462
        assertEquals(0, nameGenusUnparse.getProblemStarts());
1463
        assertEquals(19, nameGenusUnparse.getProblemEnds());
1464

    
1465
        String strGenusUnparse2 = "Hieracium L., Per Luigi: 44. 1987";
1466
        INonViralName nameGenusUnparse2 =
1467
            parser.parseReferencedName(strGenusUnparse2, null, Rank.FAMILY());
1468
        assertFalse(nameGenusUnparse2.hasProblem());
1469
        assertEquals(strGenusUnparse2, nameGenusUnparse2.getFullTitleCache());
1470
        assertEquals(-1, nameGenusUnparse2.getProblemStarts());
1471
        assertEquals(-1, nameGenusUnparse2.getProblemEnds());
1472

    
1473
        String strBookSection2 = "Hieracium vulgatum subsp. acuminatum (Jord.) Zahn in Schinz & Keller, Fl. Schweiz, ed. 2, 2: 288. 1905-1907";
1474
        String strBookSection2NoComma = "Hieracium vulgatum subsp. acuminatum (Jord.) Zahn in Schinz & Keller, Fl. Schweiz ed. 2, 2: 288. 1905-1907";
1475
        INonViralName nameBookSection2 =
1476
            parser.parseReferencedName(strBookSection2, null, null);
1477
        assertFalse(nameBookSection2.hasProblem());
1478
        nameBookSection2.setFullTitleCache(null, false);
1479
        assertEquals(strBookSection2NoComma.replace(" ed.", ", ed."), nameBookSection2.getFullTitleCache());
1480
        assertEquals(-1, nameBookSection2.getProblemStarts());
1481
        assertEquals(-1, nameBookSection2.getProblemEnds());
1482
        assertNull((nameBookSection2.getNomenclaturalReference()).getDatePublished().getStart());
1483
        assertEquals("1905-1907", ((IBookSection)nameBookSection2.getNomenclaturalReference()).getInBook().getDatePublished().getYear());
1484

    
1485

    
1486
        String strBookSection = "Hieracium vulgatum subsp. acuminatum (Jord.) Zahn in Schinz & Keller, Fl. Schweiz ed. 2, 2: 288. 1905";
1487
        INonViralName nameBookSection =
1488
            parser.parseReferencedName(strBookSection, null, null);
1489
        assertFalse(nameBookSection.hasProblem());
1490
        assertEquals(strBookSection.replace(" ed.", ", ed."), nameBookSection.getFullTitleCache());
1491
        assertEquals(-1, nameBookSection.getProblemStarts());
1492
        assertEquals(-1, nameBookSection.getProblemEnds());
1493
        assertNull(((IBookSection)nameBookSection.getNomenclaturalReference()).getInBook().getDatePublished().getStart());
1494
        assertEquals("1905", ((IBookSection)nameBookSection.getNomenclaturalReference()).getDatePublished().getYear());
1495

    
1496
        String strXXXs = "Abies alba, Soer der 1987";
1497
        INonViralName problemName = parser.parseReferencedName(strXXXs, null, null);
1498
        assertTrue(problemName.hasProblem());
1499
        list = problemName.getParsingProblems();
1500
        assertTrue("Problem must be name-reference separation", list.contains(ParserProblem.NameReferenceSeparation));
1501
        parser.parseReferencedName(problemName, strBookSection, null, true);
1502
        assertFalse(problemName.hasProblem());
1503

    
1504
        problemName = parser.parseFullName(strXXXs, null, null);
1505
        assertTrue(problemName.hasProblem());
1506
        list = problemName.getParsingProblems();
1507
        assertTrue("Name part must be unparsable", list.contains(ParserProblem.UnparsableNamePart));
1508

    
1509

    
1510
        String testParsable = "Pithecellobium macrostachyum Benth.";
1511
        assertTrue(isParsable(testParsable, ICNAFP));
1512

    
1513
        testParsable = "Pithecellobium macrostachyum (Benth.)";
1514
        assertTrue(isParsable(testParsable, ICNAFP));
1515

    
1516
        testParsable = "Pithecellobium macrostachyum (Benth., 1845)";
1517
        assertTrue(isParsable(testParsable, NomenclaturalCode.ICZN));
1518

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

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

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

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

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

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

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

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

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

    
1550
        testParsable = "Hieracium lachenalii, Ill. Fl. (Mitt.) 6: 1285. 1929";
1551
        assertFalse("Author is obligatory if followed by reference", isParsable(testParsable, ICNAFP));
1552
        assertTrue("Problem must be name-reference separation", getProblems(testParsable, ICNAFP).
1553
                contains(ParserProblem.NameReferenceSeparation));
1554

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

    
1560
        testParsable = "Abies alba Mill. var. alba";
1561
        assertTrue("Autonym problem", isParsable(testParsable, ICNAFP));
1562

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

    
1566

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

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

    
1574

    
1575
    }
1576

    
1577

    
1578
    /**
1579
     * Test author with name parts van, von, de, de la, d', da, del.
1580
     * See also http://dev.e-taxonomy.eu/trac/ticket/3373
1581
     */
1582
    @Test
1583
    public final void  testComposedAuthorNames(){
1584

    
1585
        //van author (see https://dev.e-taxonomy.eu/trac/ticket/3373)
1586
        String testParsable = "Aphelocoma unicolor subsp. griscomi van Rossem, 1928";
1587
        assertTrue("Author with 'van' should be parsable", isParsable(testParsable, ICZN));
1588

    
1589
        //von author (see https://dev.e-taxonomy.eu/trac/ticket/3373)
1590
        testParsable = "Aphelocoma unicolor subsp. griscomi von Rossem, 1928";
1591
        assertTrue("Author with 'von' should be parsable", isParsable(testParsable, ICZN));
1592

    
1593
        //de author (see https://dev.e-taxonomy.eu/trac/ticket/3373)
1594
        testParsable = "Aphelocoma unicolor subsp. griscomi de Rossem, 1928";
1595
        assertTrue("Author with 'de' should be parsable", isParsable(testParsable, ICZN));
1596

    
1597
        //de la author (see https://dev.e-taxonomy.eu/trac/ticket/3373)
1598
        testParsable = "Aphelocoma unicolor subsp. griscomi de la Rossem, 1928";
1599
        assertTrue("Author with 'de la' should be parsable", isParsable(testParsable, ICZN));
1600

    
1601
        //d' author (see https://dev.e-taxonomy.eu/trac/ticket/3373)
1602
        testParsable = "Aphelocoma unicolor subsp. griscomi d'Rossem, 1928";
1603
        assertTrue("Author with \"'d'\" should be parsable", isParsable(testParsable, ICZN));
1604

    
1605
        //da author (see https://dev.e-taxonomy.eu/trac/ticket/3373)
1606
        testParsable = "Aphelocoma unicolor subsp. griscomi da Rossem, 1928";
1607
        assertTrue("Author with 'da' should be parsable", isParsable(testParsable, ICZN));
1608

    
1609
        //del author (see https://dev.e-taxonomy.eu/trac/ticket/3373)
1610
        testParsable = "Aphelocoma unicolor subsp. griscomi del Rossem, 1928";
1611
        assertTrue("Author with 'del' should be parsable", isParsable(testParsable, ICZN));
1612

    
1613
        //O' author (see https://dev.e-taxonomy.eu/trac/ticket/4759)
1614
        testParsable = "Aphelocoma unicolor subsp. griscomi O'Connor, 1928";
1615
        assertTrue("Author with 'O'' should be parsable", isParsable(testParsable, ICZN));
1616

    
1617
        //del author (see https://dev.e-taxonomy.eu/trac/ticket/4759)
1618
        testParsable = "Aphelocoma unicolor subsp. griscomi zur Strassen, 1928";
1619
        assertTrue("Author with 'zur' should be parsable", isParsable(testParsable, ICZN));
1620

    
1621
    }
1622

    
1623

    
1624

    
1625
    /**
1626
     * @param testParsable
1627
     * @param icbn
1628
     * @return
1629
     */
1630
    private List<ParserProblem> getProblems(String string, NomenclaturalCode code) {
1631
        List<ParserProblem> result = parser.parseReferencedName(string, code, null).getParsingProblems();
1632
        return result;
1633
    }
1634

    
1635
    private boolean isParsable(String string, NomenclaturalCode code){
1636
        INonViralName name = parser.parseReferencedName(string, code, null);
1637
        return ! name.hasProblem();
1638
    }
1639

    
1640
    private void assertFullRefNameStandard(INonViralName name){
1641
        assertEquals("Abies", name.getGenusOrUninomial());
1642
        assertEquals("alba", name.getSpecificEpithet());
1643
        assertEquals("Mill.", name.getAuthorshipCache());
1644
        assertEquals("455", name.getNomenclaturalMicroReference());
1645
        assertNotNull(name.getNomenclaturalReference());
1646
    }
1647

    
1648
    private void assertFullRefStandard(INonViralName name){
1649
        assertEquals("Abies", name.getGenusOrUninomial());
1650
        assertEquals("alba", name.getSpecificEpithet());
1651
        assertEquals("Mill.", name.getAuthorshipCache());
1652
        assertEquals("455", name.getNomenclaturalMicroReference());
1653
        assertNotNull(name.getNomenclaturalReference());
1654
        INomenclaturalReference ref = name.getNomenclaturalReference();
1655
        assertEquals("1987", ref.getYear());
1656
        assertEquals("Sp. Pl.", ref.getAbbrevTitle());
1657
    }
1658

    
1659

    
1660
    @Test
1661
    public void testNeverEndingParsing(){
1662
        //some full titles result in never ending parsing process https://dev.e-taxonomy.eu/trac/ticket/1556
1663

    
1664
        String irinaExample = "Milichiidae Sharp, 1899, Insects. Part II. Hymenopteracontinued (Tubulifera and Aculeata), Coleoptera, Strepsiptera, Lepidoptera, Diptera, Aphaniptera, Thysanoptera, Hemiptera, Anoplura 6: 504. 1899";
1665
//      irinaExample = "Milichiidae Sharp, 1899, Insects. Part II. Uiuis Iuiui Hymenopteracontinued (Tubulifera and Aculeata), Coleoptera, Strepsiptera, Lepidoptera, Diptera, Aphaniptera, Thysanoptera, Hemiptera, Anoplura 6: 504. 1899";
1666
        INonViralName nvn = this.parser.parseReferencedName(irinaExample, NomenclaturalCode.ICZN, null);
1667
        int parsingProblem = nvn.getParsingProblem();
1668
        Assert.assertEquals("Name should have only rank warning", 1, parsingProblem);
1669
        Assert.assertEquals("Titlecache", "Milichiidae Sharp, 1899", nvn.getTitleCache());
1670
        Assert.assertEquals("If this line reached everything should be ok", "Milichiidae", nvn.getGenusOrUninomial());
1671

    
1672
        String anotherExample = "Scorzonera hispanica var. brevifolia Boiss. & Balansa in Boissier, Diagn. Pl. Orient., ser. 2 6: 119. 1859.";
1673
        nvn = this.parser.parseReferencedName(anotherExample, ICNAFP, null);
1674
        parsingProblem = nvn.getParsingProblem();
1675
        Assert.assertEquals("Problem should be 0", 0, parsingProblem);
1676
        Assert.assertEquals("Titlecache", "Scorzonera hispanica var. brevifolia Boiss. & Balansa", nvn.getTitleCache());
1677
        Assert.assertEquals("If this line reached everything should be ok", "Scorzonera", nvn.getGenusOrUninomial());
1678

    
1679
        String unparsable = "Taraxacum nevskii L., Trudy Bot. Inst. Nauk S.S.S.R., Ser. 1, Fl. Sist. Vyssh. Rast. 4: 293. 1937.";
1680
//      String unparsableA = "Taraxacum nevskii L. in Trudy Bot. Inst. Nauk: 293. 1937.";
1681
        nvn = this.parser.parseReferencedName(unparsable, ICNAFP, null);
1682
        Assert.assertEquals("Titlecache", "Taraxacum nevskii L.", nvn.getTitleCache());
1683
        Assert.assertEquals("If this line reached everything should be ok", "Taraxacum", nvn.getGenusOrUninomial());
1684
        parsingProblem = nvn.getParsingProblem();
1685
        Assert.assertEquals("Name should no warnings or errors", 0, parsingProblem);
1686

    
1687
        String unparsable2 = "Hieracium pxxx Dahlst., Kongl. Svenska Vetensk. Acad. Handl. ser. 2, 26(3): 255. 1894";
1688
//      String unparsable2A = "Hieracium pxxx Dahlst., Kongl Svenska Vetensk Acad Handl, 26: 255. 1894.";
1689
        nvn = this.parser.parseReferencedName(unparsable2, ICNAFP, null);
1690
        Assert.assertEquals("Titlecache", "Hieracium pxxx Dahlst.", nvn.getTitleCache());
1691
        Assert.assertEquals("If this line reached everything should be ok", "Hieracium", nvn.getGenusOrUninomial());
1692
        parsingProblem = nvn.getParsingProblem();
1693
        Assert.assertEquals("Name should no warnings or errors", 0, parsingProblem);
1694

    
1695

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

    
1701
    }
1702

    
1703
    @Test
1704
    public final void testSeriesPart(){
1705
        Pattern seriesPattern = Pattern.compile(NonViralNameParserImplRegExBase.pSeriesPart);
1706
        Matcher matcher = seriesPattern.matcher("ser. 2");
1707
        Assert.assertTrue("", matcher.matches());
1708
    }
1709

    
1710
    /**
1711
     * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#fullTeams(java.lang.String)}.
1712
     */
1713
    @Test
1714
    public final void testFullTeams() {
1715
        logger.warn("Not yet implemented"); // TODO
1716
    }
1717

    
1718
    /**
1719
     * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#AuthorshipAndEx(java.lang.String)}.
1720
     * @throws StringNotParsableException
1721
     */
1722
    @Test
1723
    public final void testParseAuthorsTaxonNameString() throws StringNotParsableException {
1724
        INonViralName nvn = TaxonNameFactory.NewZoologicalInstance(null);
1725
        parser.parseAuthors(nvn, "Eckweiler & ten Hagen, 2003");
1726
        Team team = (Team)nvn.getCombinationAuthorship();
1727
        Assert.assertNotNull("Comb. author must not be null", team);
1728
        Assert.assertEquals("Must be team with 2 members", 2, team.getTeamMembers().size());
1729
        Assert.assertEquals("Second member must be 'ten Hagen'", "ten Hagen", team.getTeamMembers().get(1).getTitleCache());
1730

    
1731
        //Crosson du Cormier, 1964
1732
        IZoologicalName zooName = TaxonNameFactory.NewZoologicalInstance(null);
1733
        parser.parseAuthors(zooName, "Crosson du Cormier, 1964");
1734
        Person person = (Person)zooName.getCombinationAuthorship();
1735
        Assert.assertNotNull("Comb. author must not be null", person);
1736
        Assert.assertEquals("Persons title must be 'Crosson du Cormier'", "Crosson du Cormier", person.getTitleCache());
1737
        Assert.assertEquals("Year must be 1964", Integer.valueOf(1964), zooName.getPublicationYear() );
1738

    
1739
        //(van der Hoeven, 1839)
1740
        zooName = TaxonNameFactory.NewZoologicalInstance(null);
1741
        parser.parseAuthors(zooName, "(van der Hoeven, 1839)");
1742
        Assert.assertNull("Combination author must be null", zooName.getCombinationAuthorship());
1743
        person = (Person)zooName.getBasionymAuthorship();
1744
        Assert.assertNotNull("Basionym author must not be null", person);
1745
        Assert.assertEquals("Persons title must be 'van der Hoeven'", "van der Hoeven", person.getTitleCache());
1746
        Assert.assertEquals("Year must be 1839", Integer.valueOf(1839), zooName.getOriginalPublicationYear() );
1747

    
1748
        //le Doux, 1931
1749
        zooName = TaxonNameFactory.NewZoologicalInstance(null);
1750
        parser.parseAuthors(zooName, "le Doux, 1931");
1751
        person = (Person)zooName.getCombinationAuthorship();
1752
        Assert.assertNotNull("Comb. author must not be null", person);
1753
        Assert.assertEquals("Persons title must be 'le Doux'", "le Doux", person.getTitleCache());
1754
        Assert.assertEquals("Year must be 1931", Integer.valueOf(1931), zooName.getPublicationYear() );
1755

    
1756

    
1757
    }
1758

    
1759
    @Test  //#4764
1760
    public void testParseSection(){
1761
        //this test does not really test problematic cases where sect.idInVoc = "sect." instead of "sect.(bot.)"
1762
        //however, by changing the csv file entry to sect. just for testing it can be used as a functional test
1763
        String sectionNameStr = "Taraxacum sect. Testtaxa M\u00fcller, Incredible Taxa: 12. 2016";
1764
        INonViralName sectionName = parser.parseReferencedName(sectionNameStr, NomenclaturalCode.ICNAFP, null);
1765
        int parsingProblem = sectionName.getParsingProblem();
1766
        Assert.assertEquals("Problem should be 0", 0, parsingProblem);
1767
        Rank rank = sectionName.getRank();
1768
        Assert.assertEquals("", Rank.SECTION_BOTANY(), rank  );
1769
    }
1770

    
1771
    //#6577
1772
    @Test
1773
    public final void testParseSpNov(){
1774
        //Canabio, issue with space
1775
        INonViralName name = parser.parseFullName("Iresine sp. nov. 1");
1776
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1777
        Assert.assertEquals("sp. nov. 1", name.getSpecificEpithet());
1778

    
1779
        name = parser.parseFullName("Gomphichis sp. 22");
1780
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1781
        Assert.assertEquals("sp. 22", name.getSpecificEpithet());
1782

    
1783
        name = parser.parseFullName("Phleum sp. nov.");
1784
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1785
        Assert.assertEquals("sp. nov.", name.getSpecificEpithet());
1786

    
1787
        name = parser.parseFullName("Phleum sp.");
1788
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1789
        Assert.assertEquals("sp.", name.getSpecificEpithet());
1790

    
1791
    }
1792

    
1793

    
1794
    @Test  //#5072
1795
    public final void testLongRunningParsingCapitals(){
1796
        DateTime start = DateTime.now();
1797
        String nameStr = "Nazeris fujianensis JIAYAO HU, LIZHEN LI, MEIJUN ZHAO,2010";  //name from CoL that created problems
1798
        INonViralName name = parser.parseReferencedName(nameStr, NomenclaturalCode.ICZN, null);
1799
        DateTime end = DateTime.now();
1800
        Duration duration = new Duration(start, end);
1801
        long seconds = duration.getStandardSeconds();
1802
        //this is the critical part of the test that must not be changed
1803
        Assert.assertTrue("Parsing of name should take less then 3 seconds but took " + seconds, seconds < 3);
1804

    
1805
    }
1806

    
1807
    @Test  //#5072
1808
    //http://www.regular-expressions.info/catastrophic.html
1809
    public final void testLongRunningParsing(){
1810

    
1811
        //name only
1812
        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";
1813
        DateTime start = DateTime.now();
1814
        INonViralName name = parser.parseReferencedName(nameStr, NomenclaturalCode.ICNAFP, null);
1815
        DateTime end = DateTime.now();
1816
        Duration duration = new Duration(start, end);
1817
        long seconds = duration.getStandardSeconds();
1818
        //this is the critical part of the test that must not be changed
1819
        Assert.assertTrue("Parsing of name should take less then 3 seconds but took " + seconds, seconds < 3);
1820
        //the following may be discussed
1821
        Assert.assertFalse("Name should parse without problems",name.hasProblem());
1822

    
1823

    
1824
        //with reference
1825
        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.";
1826
        start = DateTime.now();
1827
        name = parser.parseReferencedName(nameStr, NomenclaturalCode.ICNAFP, null);
1828
        end = DateTime.now();
1829
        duration = new Duration(start, end);
1830
        seconds = duration.getStandardSeconds();
1831
        //this is the critical part of the test that must not be changed
1832
        Assert.assertTrue("Parsing of name should take less then 3 seconds but took " + seconds, seconds < 3);
1833
        //the following may be discussed
1834
        Assert.assertFalse("Name should parse without problems",name.hasProblem());
1835
    }
1836

    
1837
    @Test  //#5072
1838
    public final void testLongRunningParsingAuthors(){
1839
        //http://www.regular-expressions.info/catastrophic.html
1840
        //
1841
        //Länge des Nachnamens macht keinen Unterschied
1842
        //Anzahl der "AuthorParts scheint entscheidend
1843
        // & am Ende macht es langsamger (16s), als nur ","(6s))
1844

    
1845
        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";
1846
        TeamOrPersonBase[] authorArray = new TeamOrPersonBase[4];
1847
        try {
1848
            DateTime start = DateTime.now();
1849
            parser.fullAuthors(authorStr, authorArray, new Integer[]{1800, null, null, null}, NomenclaturalCode.ICNAFP);
1850
            DateTime end = DateTime.now();
1851
            Duration duration = new Duration(start, end);
1852
            long seconds = duration.getStandardSeconds();
1853
//            System.out.println(seconds);
1854
            //this is the critical part of the test that must not be changed
1855
            Assert.assertTrue("Parsing of name should take less then 3 seconds but took " + seconds, seconds < 3);
1856
        } catch (StringNotParsableException e) {
1857
            e.printStackTrace();
1858
            Assert.fail("Authors should be parsable");
1859
        }
1860

    
1861
    }
1862

    
1863

    
1864
    /**
1865
     * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#AuthorshipAndEx(java.lang.String)}.
1866
     */
1867
    @Test
1868
    public final void testAuthorshipAndEx() {
1869
        logger.warn("Not yet implemented"); // TODO
1870
    }
1871

    
1872
    /**
1873
     * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#Authorship(java.lang.String)}.
1874
     */
1875
    @Test
1876
    public final void testAuthorship() {
1877
        logger.warn("Not yet implemented"); // TODO
1878
    }
1879

    
1880
    /**
1881
     * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#parseCultivar(java.lang.String)}.
1882
     */
1883
    @Test
1884
    public final void testParseCultivar() {
1885
        logger.warn("Not yet implemented"); // TODO
1886
    }
1887

    
1888
    @Test
1889
    public final void testNomenclaturalStatus() {
1890
        IBotanicalName name = TaxonNameFactory.NewBotanicalInstance(Rank.FAMILY(), "Acanthopale", null, null, null, null, null, null, null);
1891
        name.addStatus(NomenclaturalStatus.NewInstance(NomenclaturalStatusType.ALTERNATIVE()));
1892
        IBotanicalName name2 = TaxonNameFactory.NewBotanicalInstance(Rank.FAMILY());
1893
        parser.parseReferencedName(name2, name.getFullTitleCache(), name2.getRank(), true);
1894
        parser.parseReferencedName(name2, name.getFullTitleCache(), name2.getRank(), true);
1895
        Assert.assertEquals("Title cache should be same. No duplication of nom. status should take place", name.getFullTitleCache(), name2.getFullTitleCache());
1896
    }
1897

    
1898
    @Test
1899
    public final void testSpecificAuthors(){
1900
        //McVaugh
1901
        INonViralName name = parser.parseFullName("Psidium longipes var. orbiculare (O.Berg) McVaugh");
1902
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1903
        TeamOrPersonBase<?> combinationAuthor = name.getCombinationAuthorship();
1904
        assertEquals( "McVaugh", combinationAuthor.getNomenclaturalTitle());
1905
        TeamOrPersonBase<?> basionymAuthor = name.getBasionymAuthorship();
1906
        assertEquals( "O.Berg", basionymAuthor.getNomenclaturalTitle());
1907

    
1908
//      Campanula rhodensis A. DC.
1909

    
1910
    }
1911

    
1912
    @Test
1913
    public final void testExistingProblems(){
1914
        //Canabio, issue with space
1915
        INonViralName name = parser.parseReferencedName("Machaonia erythrocarpa var. hondurensis (Standl.) Borhidi"
1916
                + " in Acta Bot. Hung. 46 (1-2): 30. 2004");
1917
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1918
        TeamOrPersonBase<?> combinationAuthor = name.getCombinationAuthorship();
1919
        assertEquals( "Borhidi", combinationAuthor.getNomenclaturalTitle());
1920
        Reference nomRef = name.getNomenclaturalReference();
1921
        assertEquals(ReferenceType.Article, nomRef.getType());
1922
        assertEquals("46 (1-2)", nomRef.getVolume());
1923

    
1924
        //Canabio, detail with fig.
1925
        name = parser.parseReferencedName("Didymaea floribunda Rzed."
1926
                + " in Bol. Soc. Bot. Mex. 44: 72, fig. 1. 1983");
1927
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1928
        combinationAuthor = name.getCombinationAuthorship();
1929
        assertEquals( "Rzed.", combinationAuthor.getNomenclaturalTitle());
1930
        nomRef = name.getNomenclaturalReference();
1931
        assertEquals(ReferenceType.Article, nomRef.getType());
1932
        assertEquals("44", nomRef.getVolume());
1933
        assertEquals("72, fig. 1", name.getNomenclaturalMicroReference());
1934

    
1935
        //fig with a-c and without dot
1936
        name = parser.parseReferencedName("Deppea guerrerensis Dwyer & Lorence"
1937
                + " in Allertonia 4: 428. fig 4a-c. 1988");  //
1938
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1939
        combinationAuthor = name.getCombinationAuthorship();
1940
        assertEquals( "Dwyer & Lorence", combinationAuthor.getNomenclaturalTitle());
1941
        nomRef = name.getNomenclaturalReference();
1942
        assertEquals(ReferenceType.Article, nomRef.getType());
1943
        assertEquals("4", nomRef.getVolume());
1944
        assertEquals("428. fig 4a-c", name.getNomenclaturalMicroReference());
1945

    
1946
        //issue with EN_DASH (3–4)
1947
        name = parser.parseReferencedName("Arachnothryx tacanensis (Lundell) Borhidi"
1948
              + " in Acta Bot. Hung. 33 (3" + UTF8.EN_DASH + "4): 303. 1987");
1949
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1950
        combinationAuthor = name.getCombinationAuthorship();
1951
        assertEquals( "Borhidi", combinationAuthor.getNomenclaturalTitle());
1952
        nomRef = name.getNomenclaturalReference();
1953
        assertEquals(ReferenceType.Article, nomRef.getType());
1954
        assertEquals("33 (3" + UTF8.EN_DASH + "4)", nomRef.getVolume());
1955
        assertEquals("303", name.getNomenclaturalMicroReference());
1956

    
1957
        //fig with f.
1958
        name = parser.parseReferencedName("Stenotis Terrell"
1959
                + " in Sida 19(4): 901" + UTF8.EN_DASH + "911, f. 1" + UTF8.EN_DASH + "2. 2001");
1960
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1961
        combinationAuthor = name.getCombinationAuthorship();
1962
        assertEquals( "Terrell", combinationAuthor.getNomenclaturalTitle());
1963
        nomRef = name.getNomenclaturalReference();
1964
        assertEquals(ReferenceType.Article, nomRef.getType());
1965
        assertEquals("19(4)", nomRef.getVolume());
1966
        assertEquals("901" + UTF8.EN_DASH + "911, f. 1" + UTF8.EN_DASH + "2", name.getNomenclaturalMicroReference());
1967

    
1968
        //detail with figs
1969
        name = parser.parseReferencedName("Randia sonorensis Wiggins"
1970
                + " in Contr. Dudley Herb. 3: 75, figs 4-6. 1940");
1971
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1972
        combinationAuthor = name.getCombinationAuthorship();
1973
        assertEquals( "Wiggins", combinationAuthor.getNomenclaturalTitle());
1974
        nomRef = name.getNomenclaturalReference();
1975
        assertEquals(ReferenceType.Article, nomRef.getType());
1976
        assertEquals("3", nomRef.getVolume());
1977
        assertEquals("75, figs 4-6", name.getNomenclaturalMicroReference());
1978

    
1979
        //detail with pl. and figs
1980
        name = parser.parseReferencedName("Randia sonorensis Wiggins"
1981
                + " in Contr. Dudley Herb. 3: 75, pl. 19, figs 4-6. 1940");
1982
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1983
        combinationAuthor = name.getCombinationAuthorship();
1984
        assertEquals( "Wiggins", combinationAuthor.getNomenclaturalTitle());
1985
        nomRef = name.getNomenclaturalReference();
1986
        assertEquals(ReferenceType.Article, nomRef.getType());
1987
        assertEquals("3", nomRef.getVolume());
1988
        assertEquals("75, pl. 19, figs 4-6", name.getNomenclaturalMicroReference());
1989

    
1990

    
1991
        //pl
1992
        name = parser.parseReferencedName("Carapichea  Aubl."
1993
                + " in Hist. Pl. Guiane 1: 167, pl. 64. 1775");
1994
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1995
        combinationAuthor = name.getCombinationAuthorship();
1996
        assertEquals( "Aubl.", combinationAuthor.getNomenclaturalTitle());
1997
        nomRef = name.getNomenclaturalReference();
1998
        assertEquals(ReferenceType.Article, nomRef.getType());
1999
        assertEquals("1", nomRef.getVolume());
2000
        assertEquals("167, pl. 64", name.getNomenclaturalMicroReference());
2001

    
2002
        //fig with ,
2003
        name = parser.parseReferencedName("Hoffmannia ixtlanensis Lorence"
2004
                + " in Novon 4: 121. fig. 2a, b. 1994");
2005
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2006
        combinationAuthor = name.getCombinationAuthorship();
2007
        assertEquals( "Lorence", combinationAuthor.getNomenclaturalTitle());
2008
        nomRef = name.getNomenclaturalReference();
2009
        assertEquals(ReferenceType.Article, nomRef.getType());
2010
        assertEquals("4", nomRef.getVolume());
2011
        assertEquals("121. fig. 2a, b", name.getNomenclaturalMicroReference());
2012

    
2013
        //detail with , to number
2014
        name = parser.parseReferencedName("Deppea martinez-calderonii Lorence"
2015
                + " in Allertonia 4: 399. figs 1e, 2. 1988");
2016
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2017
        combinationAuthor = name.getCombinationAuthorship();
2018
        assertEquals( "Lorence", combinationAuthor.getNomenclaturalTitle());
2019
        nomRef = name.getNomenclaturalReference();
2020
        assertEquals(ReferenceType.Article, nomRef.getType());
2021
        assertEquals("4", nomRef.getVolume());
2022
        assertEquals("399. figs 1e, 2", name.getNomenclaturalMicroReference());
2023

    
2024
        //(Suppl.)
2025
        name = parser.parseReferencedName("Manettia costaricensis  Wernham"
2026
                + " in J. Bot. 57(Suppl.): 38. 1919");
2027
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2028
        combinationAuthor = name.getCombinationAuthorship();
2029
        assertEquals( "Wernham", combinationAuthor.getNomenclaturalTitle());
2030
        nomRef = name.getNomenclaturalReference();
2031
        assertEquals(ReferenceType.Article, nomRef.getType());
2032
        assertEquals("57(Suppl.)", nomRef.getVolume());
2033
        assertEquals("38", name.getNomenclaturalMicroReference());
2034

    
2035
        //NY.
2036
        name = parser.parseReferencedName("Crusea psyllioides (Kunth) W.R. Anderson"
2037
                + " in Mem. NY. Bot. Gard. 22: 75. 1972");
2038
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2039
        combinationAuthor = name.getCombinationAuthorship();
2040
        assertEquals( "W.R. Anderson", combinationAuthor.getNomenclaturalTitle());
2041
        nomRef = name.getNomenclaturalReference();
2042
        assertEquals(ReferenceType.Article, nomRef.getType());
2043
        assertEquals("22", nomRef.getVolume());
2044
        assertEquals("75", name.getNomenclaturalMicroReference());
2045

    
2046
        //apostroph word in title
2047
        name = parser.parseReferencedName("Sabicea glabrescens Benth."
2048
                + " in Hooker's J. Bot. Kew Gard. Misc. 3: 219. 1841");
2049
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2050
        combinationAuthor = name.getCombinationAuthorship();
2051
        assertEquals( "Benth.", combinationAuthor.getNomenclaturalTitle());
2052
        nomRef = name.getNomenclaturalReference();
2053
        assertEquals(ReferenceType.Article, nomRef.getType());
2054
        assertEquals("3", nomRef.getVolume());
2055
        assertEquals("219", name.getNomenclaturalMicroReference());
2056

    
2057
        // place published e.g. (Hannover)
2058
        name = parser.parseReferencedName("Pittoniotis trichantha Griseb."
2059
                  + " in Bonplandia (Hannover) 6 (1): 8. 1858");
2060
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2061
        combinationAuthor = name.getCombinationAuthorship();
2062
        assertEquals( "Griseb.", combinationAuthor.getNomenclaturalTitle());
2063
        nomRef = name.getNomenclaturalReference();
2064
        assertEquals(ReferenceType.Article, nomRef.getType());
2065
        assertEquals("6 (1)", nomRef.getVolume());
2066
        assertEquals("8", name.getNomenclaturalMicroReference());
2067

    
2068
        //komplex / incorrect year without quotation marks
2069
        name = parser.parseReferencedName("Javorkaea Borhidi & Jarai-Koml."
2070
                + " in Acta Bot. Hung. 29(1\u20134): 16, f. 1\u20132, t. 1-8. 1983 [1984]");
2071
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2072
        combinationAuthor = name.getCombinationAuthorship();
2073
        assertEquals( "Borhidi & Jarai-Koml.", combinationAuthor.getNomenclaturalTitle());
2074
        nomRef = name.getNomenclaturalReference();
2075
        assertEquals(ReferenceType.Article, nomRef.getType());
2076
        assertEquals("29(1\u20134)", nomRef.getVolume());
2077
        assertEquals("16, f. 1\u20132, t. 1-8", name.getNomenclaturalMicroReference());
2078
        assertEquals("1983 [1984]", nomRef.getDatePublishedString());
2079
        assertEquals("1984", nomRef.getYear());
2080

    
2081
        //incorrect year with \u201e \u201f  (s. eu.etaxonomy.cdm.common.UTF8.ENGLISH_QUOT_START
2082
        name = parser.parseReferencedName("Javorkaea Borhidi & Jarai-Koml."
2083
                + " in Acta Bot. Hung. 29(1-4): 16, f. 1-2. \u201e1983\u201f [1984]");
2084
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2085
        combinationAuthor = name.getCombinationAuthorship();
2086
        assertEquals( "Borhidi & Jarai-Koml.", combinationAuthor.getNomenclaturalTitle());
2087
        nomRef = name.getNomenclaturalReference();
2088
        assertEquals(ReferenceType.Article, nomRef.getType());
2089
        assertEquals("29(1-4)", nomRef.getVolume());
2090
        assertEquals("16, f. 1-2", name.getNomenclaturalMicroReference());
2091
        assertEquals("\u201e1983\u201f [1984]", nomRef.getDatePublishedString());
2092
        assertEquals("1984", nomRef.getYear());
2093

    
2094
        //incorrect year with "
2095
        name = parser.parseReferencedName("Javorkaea Borhidi & Jarai-Koml."
2096
                + " in Acta Bot. Hung. 29(1-4): 16, f. 1-2. \"1983\" [1984]");
2097
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2098
        combinationAuthor = name.getCombinationAuthorship();
2099
        assertEquals( "Borhidi & Jarai-Koml.", combinationAuthor.getNomenclaturalTitle());
2100
        nomRef = name.getNomenclaturalReference();
2101
        assertEquals(ReferenceType.Article, nomRef.getType());
2102
        assertEquals("29(1-4)", nomRef.getVolume());
2103
        assertEquals("16, f. 1-2", name.getNomenclaturalMicroReference());
2104
        assertEquals("\"1983\" [1984]", nomRef.getDatePublishedString());
2105
        assertEquals("1984", nomRef.getYear());
2106

    
2107
        //fig. a
2108
        name = parser.parseReferencedName("Psychotria capitata  Ruiz & Pav."
2109
                + " in Fl. Peruv. 2: 59, pl. 206, fig. a. 1799");
2110
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2111
        combinationAuthor = name.getCombinationAuthorship();
2112
        assertEquals( "Ruiz & Pav.", combinationAuthor.getNomenclaturalTitle());
2113
        nomRef = name.getNomenclaturalReference();
2114
        assertEquals(ReferenceType.Article, nomRef.getType());
2115
        assertEquals("2", nomRef.getVolume());
2116
        assertEquals("59, pl. 206, fig. a", name.getNomenclaturalMicroReference());
2117

    
2118
        //442A.
2119
        name = parser.parseReferencedName("Rogiera elegans Planch."
2120
                + " in Fl. Serres Jard. Eur. 5: 442A. 1849");
2121
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2122
        combinationAuthor = name.getCombinationAuthorship();
2123
        assertEquals( "Planch.", combinationAuthor.getNomenclaturalTitle());
2124
        nomRef = name.getNomenclaturalReference();
2125
        assertEquals(ReferenceType.Article, nomRef.getType());
2126
        assertEquals("5", nomRef.getVolume());
2127
        assertEquals("442A", name.getNomenclaturalMicroReference());
2128

    
2129
        //f
2130
        name = parser.parseReferencedName("Coussarea imitans L.O. Williams"
2131
                + " in Phytologia 26 (6): 488-489, f. 1973");
2132
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2133
        combinationAuthor = name.getCombinationAuthorship();
2134
        assertEquals( "L.O. Williams", combinationAuthor.getNomenclaturalTitle());
2135
        nomRef = name.getNomenclaturalReference();
2136
        assertEquals(ReferenceType.Article, nomRef.getType());
2137
        assertEquals("26 (6)", nomRef.getVolume());
2138
        assertEquals("488-489, f", name.getNomenclaturalMicroReference());
2139

    
2140
        //Phys.-Med.
2141
        name = parser.parseReferencedName("Coccocypselum cordifolium Nees & Mart."
2142
                + " in Nova Acta Phys.-Med. Acad. Caes.\u2013Leop. Nat. Cur. 12: 14. 1824");
2143
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2144
        combinationAuthor = name.getCombinationAuthorship();
2145
        assertEquals( "Nees & Mart.", combinationAuthor.getNomenclaturalTitle());
2146
        nomRef = name.getNomenclaturalReference();
2147
        assertEquals(ReferenceType.Article, nomRef.getType());
2148
        assertEquals("Nova Acta Phys.-Med. Acad. Caes.\u2013Leop. Nat. Cur.", nomRef.getInReference().getAbbrevTitle());
2149
        assertEquals("12", nomRef.getVolume());
2150
        assertEquals("14", name.getNomenclaturalMicroReference());
2151
        assertEquals("1824", nomRef.getYear());
2152

    
2153
        //(ed. 10)  wanted?
2154
//        Syst. Nat. (ed. 10) 2: 930. 1759
2155
//        name = parser.parseReferencedName("Erithalis fruticosa L."
2156
//                + ", Syst. Nat. ed. 10, 2: 930. 1759");
2157
//        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2158
//        combinationAuthor = name.getCombinationAuthorship();
2159
//        assertEquals( "L.", combinationAuthor.getNomenclaturalTitle());
2160
//        nomRef = (Reference)name.getNomenclaturalReference();
2161
//        assertEquals(ReferenceType.Book, nomRef.getType());
2162
//        assertEquals("2", nomRef.getVolume());
2163
//        assertEquals("10", nomRef.getEdition());
2164
//        assertEquals("930", name.getNomenclaturalMicroReference());
2165
//        assertEquals("1759", nomRef.getYear());
2166

    
2167
        //issue with letter "(1a)"
2168
        name = parser.parseReferencedName("Arthraerua (Kuntze) Schinz,"
2169
                + " Nat. Pflanzenfam. 3(1a): 109. 1893");
2170
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2171
        combinationAuthor = name.getCombinationAuthorship();
2172
        assertEquals( "Schinz", combinationAuthor.getNomenclaturalTitle());
2173
        nomRef = name.getNomenclaturalReference();
2174
        Assert.assertFalse("Reference should be parsable", nomRef.isProtectedTitleCache());
2175
        assertEquals(ReferenceType.Book, nomRef.getType());
2176
        assertEquals("Nat. Pflanzenfam.", nomRef.getAbbrevTitle());
2177
        assertEquals("3(1a)", nomRef.getVolume());
2178
        assertEquals("109", name.getNomenclaturalMicroReference());
2179
        assertEquals("1893", nomRef.getYear());
2180

    
2181
        //Accent graph in author name #6057
2182
        name = parser.parseReferencedName("Sedum plicatum O`Brian");
2183
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2184
        assertEquals( "O`Brian", name.getCombinationAuthorship().getNomenclaturalTitle());
2185

    
2186
        //-e-  #6060
2187
        name = parser.parseReferencedName("Thamniopsis stenodictyon (Sehnem) Oliveira-e-Silva & O.Yano");
2188
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2189
        Team team = (Team)name.getCombinationAuthorship();
2190
        assertEquals( "Oliveira-e-Silva", team.getTeamMembers().get(0).getNomenclaturalTitle());
2191

    
2192
        //Vorabdr.
2193
        name = parser.parseReferencedName("Ophrys hystera  Kreutz & Ruedi Peter in J. Eur. Orchideen 30(Vorabdr.): 128. 1997");
2194
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2195
        assertEquals( "30(Vorabdr.)", name.getNomenclaturalReference().getVolume());
2196

    
2197
        //#6100  jun.
2198
        String nameStr = "Swida \u00D7 friedlanderi (W.H.Wagner jun.) Holub";
2199
        name = parser.parseFullName(nameStr, botanicCode, null);  //fails with missing botanicCode, see open issues
2200
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2201
        assertEquals( "W.H.Wagner jun.", name.getBasionymAuthorship().getTitleCache());
2202

    
2203
        //#6100 bis /ter
2204
        nameStr = "Schistidium aquaticum (R.Br.ter) Ochyra";
2205
        name = parser.parseFullName(nameStr);
2206
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2207
        assertEquals( "R.Br.ter", name.getBasionymAuthorship().getTitleCache());
2208

    
2209
        nameStr = "Grimmia mitchellii R.Br.bis";
2210
        name = parser.parseFullName(nameStr);
2211
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2212
        assertEquals( "R.Br.bis", name.getCombinationAuthorship().getTitleCache());
2213

    
2214
        //forma #6100
2215
        nameStr = "Xerocomus parasiticus forma piperatoides (J. Blum) R. Mazza";
2216
        name = parser.parseFullName(nameStr);
2217
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2218
        assertEquals( "piperatoides", name.getInfraSpecificEpithet());
2219
        assertEquals( Rank.FORM(), name.getRank());
2220

    
2221
        //subgen. #6100
2222
        nameStr = "Aliciella subgen. Gilmania (H.Mason & A.D.Grant) J.M.Porter";
2223
        name = parser.parseFullName(nameStr);
2224
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2225
        assertEquals( "Gilmania", name.getInfraGenericEpithet());
2226
        assertEquals( Rank.SUBGENUS(), name.getRank());
2227

    
2228
        //subgen. #6100
2229
        nameStr = "Aliciella subgen. Gilmania J.M.Porter";
2230
        name = parser.parseFullName(nameStr);
2231
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2232
        assertEquals( "Gilmania", name.getInfraGenericEpithet());
2233
        assertEquals( Rank.SUBGENUS(), name.getRank());
2234
        assertEquals( "J.M.Porter", name.getCombinationAuthorship().getTitleCache());
2235

    
2236
        //la Croix #6100
2237
        nameStr = "Eulophia ovalis var. bainesii (Rolfe) P.J.Cribb & la Croix";
2238
        name = parser.parseFullName(nameStr);
2239
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2240
        assertEquals( "P.J.Cribb & la Croix", name.getCombinationAuthorship().getTitleCache());
2241

    
2242
        //I = Yi #6100
2243
        nameStr = "Parasenecio hwangshanicus (P.I Mao) C.I Peng";
2244
        name = parser.parseFullName(nameStr);
2245
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2246
        assertEquals("I (=Yi) should be an accepted ending", "C.I Peng", name.getCombinationAuthorship().getTitleCache());
2247
        assertEquals("I (=Yi) should be an accepted ending", "P.I Mao", name.getBasionymAuthorship().getTitleCache());
2248

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

    
2256
        //Man in 't Veld  #6100
2257
        nameStr = "Phytophthora multivesiculata Ilieva, Man in 't Veld, Veenbaas-Rijks & Pieters";
2258
        name = parser.parseFullName(nameStr);
2259
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2260
        assertEquals("Ilieva, Man in 't Veld, Veenbaas-Rijks & al.",
2261
                name.getCombinationAuthorship().getTitleCache());
2262
        assertEquals("Ilieva, Man in 't Veld, Veenbaas-Rijks & Pieters",
2263
                name.getCombinationAuthorship().getNomenclaturalTitle());
2264

    
2265
        nameStr = "Thymus \u00D7 herberoi De la Torre, Vicedo, Alonso & Paya";
2266
        name = parser.parseFullName(nameStr);
2267
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2268
        assertEquals("De la Torre, Vicedo, Alonso & al.",
2269
                name.getCombinationAuthorship().getTitleCache());
2270
        assertEquals("De la Torre, Vicedo, Alonso & Paya",
2271
                name.getCombinationAuthorship().getNomenclaturalTitle());
2272

    
2273
        //Sant'Anna
2274
        nameStr = "Coelosphaerium evidenter-marginatum M.T.P.Azevedo & Sant'Anna";
2275
        name = parser.parseFullName(nameStr);
2276
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2277
        assertEquals("M.T.P.Azevedo & Sant'Anna", name.getCombinationAuthorship().getTitleCache());
2278

    
2279
        //Heft
2280
        nameStr = "Nepenthes deaniana Macfarl. in Engl., Mein Pflanzenr. IV. 111 (Heft 36): 57. 1908.";
2281
        name = parser.parseReferencedName(nameStr);
2282
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2283
        Reference ref = name.getNomenclaturalReference();
2284
        Assert.assertFalse("Reference should be parsable", ref.hasProblem());
2285
        //or even better IV. 111 (Heft 36), but this is currently not implemented
2286
        assertEquals("111 (Heft 36)", ref.getInReference().getVolume());
2287

    
2288
        //journal with commata at pos 4
2289
        nameStr = "Bufonia kotschyana subsp. densa Chrtek & Krisa in Acta Univ.Carol., Biol. 43(2): 105. 1999";
2290
        name = parser.parseReferencedName(nameStr);
2291
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2292
        String author = name.getAuthorshipCache();
2293
        assertEquals("Chrtek & Krisa", author);
2294
        ref = name.getNomenclaturalReference();
2295
        Assert.assertNotNull("Nomenclatural reference should be an article and therefore have an in reference", ref.getInReference());
2296
        Assert.assertEquals(ReferenceType.Journal, ref.getInReference().getType());
2297

    
2298
    }
2299

    
2300
    @Test
2301
    @Ignore
2302
    public final void openIssues(){
2303
        //#6100  jun.
2304
        String nameStr = "Swida \u00D7 friedlanderi (W.H.Wagner jun.) Holub";
2305
        INonViralName name = parser.parseFullName(nameStr, botanicCode, null);
2306
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2307
        assertEquals( "W.H.Wagner jun.", name.getBasionymAuthorship().getTitleCache());
2308
        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
2309
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2310
        assertEquals( "W.H.Wagner jun.", name.getBasionymAuthorship().getTitleCache());
2311

    
2312
        //´t Hart #6100
2313
        nameStr = "Sedum decipiens (Baker) Thiede & \u00B4t Hart";   //still does not work with "´" if compiled by maven, don't know what the difference is
2314
        name = parser.parseFullName(nameStr);
2315
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2316
        assertEquals("All types of quotation marks should be accepted, though better match it to standard ' afterwards",
2317
                "Thiede & \u00B4t Hart", name.getCombinationAuthorship().getTitleCache());
2318
        nameStr = "Sedum decipiens (Baker) Thiede & ´t Hart";   //does not work if compiled with maven
2319
        name = parser.parseFullName(nameStr);
2320
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2321
        assertEquals("All types of quotation marks should be accepted, though better match it to standard ' afterwards",
2322
                "Thiede & ´t Hart", name.getCombinationAuthorship().getTitleCache());
2323

    
2324
    }
2325

    
2326
}
(2-2/4)