Project

General

Profile

Download (119 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.Test;
31

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

    
64
    private static final Logger logger = Logger.getLogger(NonViralNameParserImplTest.class);
65

    
66
    final private String strNameFamily = "Asteraceae";
67
    final private String strNameGenus = "Abies Mueller";
68
    final private String strNameGenusUnicode = "Abies M\u00FCller";
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
        NonViralName<?> 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
        ZoologicalName milichiidae = (ZoologicalName)parser.parseSimpleName("Milichiidae", NomenclaturalCode.ICZN, null);
164
        assertEquals("Family rank expected", Rank.FAMILY(), milichiidae.getRank());
165
        BotanicalName crepidinae = (BotanicalName)parser.parseSimpleName("Crepidinae", ICNAFP, null);
166
        assertEquals("Family rank expected", Rank.SUBTRIBE(), crepidinae.getRank());
167
        BotanicalName abies = (BotanicalName)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
        BotanicalName rosa = (BotanicalName)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 = (BotanicalName)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
        ZoologicalName zooName = (ZoologicalName)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 = (ZoologicalName)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
        BotanicalName botName = (BotanicalName)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 = (BotanicalName)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 = (BotanicalName)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
        NonViralName<?> 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
        NonViralName<?> 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
        NonViralName<?> 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
        BotanicalName nameBasionymExAuthor2 = (BotanicalName)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
        NonViralName<?> 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
        ZoologicalName nameZoo1 = (ZoologicalName)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
        ZoologicalName nameZoo2 = (ZoologicalName)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
        ZoologicalName nameZoo3 = (ZoologicalName)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
        ZoologicalName nameZoo4 = (ZoologicalName)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
        ZoologicalName nameZoo5 = (ZoologicalName)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
        BotanicalName autonymName = (BotanicalName)parser.parseFullName("Abies alba Mill. var. alba", ICNAFP, null);
344
        assertFalse("Autonym should be parsable", autonymName.hasProblem());
345

    
346

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

    
352
        //null
353
        NonViralName<?> 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
        NonViralName<?> 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
        NonViralName<?> 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
        NonViralName<?> 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
        NonViralName<?> nvn = ZoologicalName.NewInstance(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
        NonViralName<?> 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
        NonViralName<?> 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
        NonViralName<?> nvn = ZoologicalName.NewInstance(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
        NonViralName<?> 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
//      NonViralName 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 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
    }
562

    
563
    /**
564
     * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#parseFullName(java.lang.String, eu.etaxonomy.cdm.model.name.Rank)}.
565
     */
566
    @Test
567
    public final void testUnrankedNames() {
568
        try {
569
            Method parseMethod = parser.getClass().getDeclaredMethod("parseFullName", String.class, NomenclaturalCode.class, Rank.class);
570
            testName_StringNomcodeRank(parseMethod);
571
        } catch (Exception e) {
572
            e.printStackTrace();
573
            assertTrue(false);
574
        }
575

    
576
        //unranked infraspecific
577
        String infraspecificUnranked = "Genus species [unranked] infraspecific";
578
        NonViralName<?> name = parser.parseFullName(infraspecificUnranked);
579
        assertEquals( "Genus", name.getGenusOrUninomial());
580
        assertEquals( "species", name.getSpecificEpithet());
581
        assertEquals( "infraspecific", name.getInfraSpecificEpithet());
582
        assertEquals( "Unranked rank should be parsed", Rank.INFRASPECIFICTAXON(), name.getRank());
583

    
584
        //unranked infrageneric
585
        String infraGenericUnranked = "Genus [unranked] Infragen";
586
        NonViralName<?> name2 = parser.parseFullName(infraGenericUnranked);
587
        assertEquals( "Genus", name2.getGenusOrUninomial());
588
        assertEquals( null, name2.getSpecificEpithet());
589
        assertEquals( "Infragen", name2.getInfraGenericEpithet());
590
        assertEquals( "Unranked rank should be parsed", Rank.INFRAGENERICTAXON(), name2.getRank());
591

    
592
    }
593

    
594

    
595
    /**
596
     * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#parseFullName(java.lang.String, eu.etaxonomy.cdm.model.name.Rank)}.
597
     */
598
    @Test
599
    public final void testHybridFormulars() {
600
        try {
601
            Method parseMethod = parser.getClass().getDeclaredMethod("parseFullName", String.class, NomenclaturalCode.class, Rank.class);
602
            testName_StringNomcodeRank(parseMethod);
603
        } catch (Exception e) {
604
            e.printStackTrace();
605
            assertTrue(false);
606
        }
607

    
608
        //Species hybrid
609
        String hybridCache = "Abies alba "+UTF8.HYBRID+" Pinus bus";
610
        NonViralName<?> name1 = parser.parseFullName(hybridCache, botanicCode, null);
611
        assertTrue("Name must have hybrid formula bit set", name1.isHybridFormula());
612
        assertEquals("Name must have 2 hybrid parents", 2, name1.getHybridChildRelations().size());
613
        assertEquals("Title cache must be correct", hybridCache, name1.getTitleCache());
614
        List<HybridRelationship> orderedRels = name1.getOrderedChildRelationships();
615
        assertEquals("Name must have 2 hybrid parents in ordered list", 2, orderedRels.size());
616
        NonViralName<?> firstParent = orderedRels.get(0).getParentName();
617
        assertEquals("Name must have Abies alba as first hybrid parent", "Abies alba", firstParent.getTitleCache());
618
        NonViralName<?> secondParent = orderedRels.get(1).getParentName();
619
        assertEquals("Name must have Pinus bus as second hybrid parent", "Pinus bus", secondParent.getTitleCache());
620
        assertEquals("Hybrid name must have the lowest rank ('species') as rank", Rank.SPECIES(), name1.getRank());
621
        assertNull("Name must not have a genus eptithet", name1.getGenusOrUninomial());
622
        assertNull("Name must not have a specific eptithet", name1.getSpecificEpithet());
623
        assertFalse("Name must not have parsing problems", name1.hasProblem());
624

    
625
        name1 = parser.parseReferencedName(hybridCache, botanicCode, null);
626
        assertFalse("Name must not have parsing problems", name1.hasProblem());
627

    
628
        //x-sign
629
        hybridCache = "Abies alba x Pinus bus";
630
        name1 = parser.parseFullName(hybridCache, botanicCode, null);
631
        assertFalse("Name must be parsable", name1.hasProblem());
632
        assertTrue("Name must have hybrid formula bit set", name1.isHybridFormula());
633
        assertFalse("Name must not have parsing problems", name1.hasProblem());
634

    
635
        //Genus //#6030
636
        hybridCache = "Orchis "+UTF8.HYBRID+" Platanthera";
637
        name1 = parser.parseFullName(hybridCache, botanicCode, null);
638
        assertFalse("Name must be parsable", name1.hasProblem());
639
        assertTrue("Name must have hybrid formula bit set", name1.isHybridFormula());
640
        assertFalse("Name must not have parsing problems", name1.hasProblem());
641
        assertEquals("Title cache must be correct", hybridCache, name1.getTitleCache());
642
        orderedRels = name1.getOrderedChildRelationships();
643
        assertEquals("Name must have 2 hybrid parents in ordered list", 2, orderedRels.size());
644
        firstParent = orderedRels.get(0).getParentName();
645
        assertEquals("Name must have Orchis as first hybrid parent", "Orchis", firstParent.getTitleCache());
646
        secondParent = orderedRels.get(1).getParentName();
647
        assertEquals("Name must have Platanthera as second hybrid parent", "Platanthera", secondParent.getTitleCache());
648
        assertEquals("Hybrid name must have genus as rank", Rank.GENUS(), name1.getRank());
649

    
650
        name1 = parser.parseReferencedName(hybridCache, botanicCode, null);
651
        assertFalse("Name must not have parsing problems", name1.hasProblem());
652

    
653
        //Subspecies first hybrid
654
        name1 = parser.parseFullName("Abies alba subsp. beta "+UTF8.HYBRID+" Pinus bus", botanicCode, null);
655
        assertTrue("Name must have hybrid formula bit set", name1.isHybridFormula());
656
        assertEquals("Name must have 2 hybrid parents", 2, name1.getHybridChildRelations().size());
657
        assertEquals("Title cache must be correct", "Abies alba subsp. beta "+UTF8.HYBRID+" Pinus bus", name1.getTitleCache());
658
        orderedRels = name1.getOrderedChildRelationships();
659
        assertEquals("Name must have 2 hybrid parents in ordered list", 2, orderedRels.size());
660
        firstParent = orderedRels.get(0).getParentName();
661
        assertEquals("Name must have Abies alba subsp. beta as first hybrid parent", "Abies alba subsp. beta", firstParent.getTitleCache());
662
        secondParent = orderedRels.get(1).getParentName();
663
        assertEquals("Name must have Pinus bus as second hybrid parent", "Pinus bus", secondParent.getTitleCache());
664
        assertEquals("Hybrid name must have the lower rank ('subspecies') as rank", Rank.SUBSPECIES(), name1.getRank());
665

    
666
        //variety second hybrid
667
        name1 = parser.parseFullName("Abies alba \u00D7 Pinus bus  var. beta", botanicCode, null);
668
        assertTrue("Name must have hybrid formula bit set", name1.isHybridFormula());
669
        assertEquals("Name must have 2 hybrid parents", 2, name1.getHybridChildRelations().size());
670
        assertEquals("Title cache must be correct", "Abies alba \u00D7 Pinus bus var. beta", name1.getTitleCache());
671
        assertEquals("Hybrid name must have the lower rank ('variety') as rank", Rank.VARIETY(), name1.getRank());
672

    
673
        //Defined rank for infraspecific taxa #6032
674
        name1 = parser.parseFullName("Berberis wilsoniae aggregata", botanicCode, Rank.VARIETY());
675
        Rank rank = name1.getRank();
676
        System.out.println(name1.getTitleCache());
677
        System.out.println(rank.getTitleCache());
678

    
679
//        name1 = parser.parseFullName("Berberis aggregata aggregata × Berberis wilsoniae aggregata", botanicCode, Rank.VARIETY());
680
//        assertTrue("Name must have hybrid formula bit set", name1.isHybridFormula());
681
//        assertEquals("Name must have 2 hybrid parents", 2, name1.getHybridChildRelations().size());
682
//        assertEquals("Title cache must be correct", name1, name1.getTitleCache());
683
//        assertEquals("Hybrid name must have the defined rank ('variety') as rank", Rank.VARIETY(), name1.getRank());
684

    
685
        //hybrids with authors
686
        name1 = parser.parseFullName("Abies alba L. \u00D7 Pinus bus Mill.", botanicCode, null);
687
        assertTrue("Name must have hybrid formula bit set", name1.isHybridFormula());
688
        assertEquals("Name must have 2 hybrid parents", 2, name1.getHybridChildRelations().size());
689
        assertEquals("Title cache must be correct", "Abies alba L. \u00D7 Pinus bus Mill.", name1.getTitleCache());
690
        orderedRels = name1.getOrderedChildRelationships();
691
        assertEquals("Name must have 2 hybrid parents in ordered list", 2, orderedRels.size());
692
        firstParent = orderedRels.get(0).getParentName();
693
        assertEquals("Name must have Abies alba L. as first hybrid parent", "Abies alba L.", firstParent.getTitleCache());
694
        secondParent = orderedRels.get(1).getParentName();
695
        assertEquals("Name must have Pinus bus Mill. as second hybrid parent", "Pinus bus Mill.", secondParent.getTitleCache());
696
        assertEquals("Hybrid name must have the lower rank ('species') as rank", Rank.SPECIES(), name1.getRank());
697

    
698
    }
699

    
700
    @Test
701
    public final void testHybridsRemoval(){
702
        //if the parser input already has hybridrelationships they need to be removed
703
        //Create input
704
        String hybridCache = "Abies alba "+UTF8.HYBRID+" Pinus bus";
705
        NonViralName<?> name1 = parser.parseFullName(hybridCache, botanicCode, null);
706
        assertFalse("Name must not have parsing problems", name1.hasProblem());
707
        assertTrue("", name1.getHybridChildRelations().size() == 2);
708

    
709
        hybridCache = "Abieta albana "+UTF8.HYBRID+" Pinuta custa";
710
        boolean makeEmpty = true;
711
        parser.parseFullName(name1, hybridCache, Rank.SPECIES(), makeEmpty);
712
        assertEquals("After parsing another string there should still be 2 parents, but different ones", 2, name1.getHybridChildRelations().size());
713
        assertFalse("Name must not have parsing problems", name1.hasProblem());
714

    
715

    
716
        hybridCache = "Calendula arvensis Mill.";
717
        makeEmpty = true;
718
        parser.parseFullName(name1, hybridCache, Rank.SPECIES(), makeEmpty);
719
        assertTrue("", name1.getHybridChildRelations().isEmpty());
720
        assertFalse("Name must not have parsing problems", name1.hasProblem());
721

    
722

    
723
        //AND the same for reference parsing
724
        hybridCache = "Abies alba "+UTF8.HYBRID+" Pinus bus";
725
        name1 = parser.parseReferencedName(hybridCache, botanicCode, null);
726
        assertFalse("Name must not have parsing problems", name1.hasProblem());
727
        assertTrue("", name1.getHybridChildRelations().size() == 2);
728

    
729
        hybridCache = "Abieta albana "+UTF8.HYBRID+" Pinuta custa";
730
        makeEmpty = true;
731
        parser.parseReferencedName(name1, hybridCache, Rank.SPECIES(), makeEmpty);
732
        assertEquals("After parsing another string there should still be 2 parents, but different ones", 2, name1.getHybridChildRelations().size());
733
        assertFalse("Name must not have parsing problems", name1.hasProblem());
734

    
735

    
736
        hybridCache = "Calendula arvensis Mill.";
737
        makeEmpty = true;
738
        parser.parseReferencedName(name1, hybridCache, Rank.SPECIES(), makeEmpty);
739
        assertTrue("", name1.getHybridChildRelations().isEmpty());
740
        assertFalse("Name must not have parsing problems", name1.hasProblem());
741
    }
742

    
743
    private void testName_StringNomcodeRank(Method parseMethod)
744
            throws InvocationTargetException, IllegalAccessException  {
745
        NonViralName<?> name1 = (NonViralName<?>)parseMethod.invoke(parser, strNameAbies1, null, Rank.SPECIES());
746
        //parser.parseFullName(strNameAbies1, null, Rank.SPECIES());
747
        assertEquals("Abies", name1.getGenusOrUninomial());
748
        assertEquals("alba", name1.getSpecificEpithet());
749

    
750
        NonViralName<?> nameAuthor = (NonViralName<?>)parseMethod.invoke(parser, strNameAbiesAuthor1, null, Rank.SPECIES());
751
        assertEquals("Abies", nameAuthor.getGenusOrUninomial());
752
        assertEquals("alba", nameAuthor.getSpecificEpithet());
753
        assertEquals("Mueller", nameAuthor.getCombinationAuthorship().getNomenclaturalTitle());
754

    
755
        NonViralName<?> nameBasionymAuthor = (NonViralName<?>)parseMethod.invoke(parser, strNameAbiesBasionymAuthor1, null, Rank.SPECIES());
756
        assertEquals("Abies", nameBasionymAuthor.getGenusOrUninomial());
757
        assertEquals("alba", nameBasionymAuthor.getSpecificEpithet());
758
        assertEquals("D'Mueller", nameBasionymAuthor.getCombinationAuthorship().getNomenclaturalTitle());
759
        assertEquals("Ciardelli", nameBasionymAuthor.getBasionymAuthorship().getNomenclaturalTitle());
760

    
761
        NonViralName<?> nameBasionymExAuthor = (NonViralName<?>)parseMethod.invoke(parser, strNameAbiesBasionymExAuthor1, null, Rank.SPECIES());
762
        assertEquals("Abies", nameBasionymExAuthor.getGenusOrUninomial());
763
        assertEquals("alba", nameBasionymExAuthor.getSpecificEpithet());
764
        assertEquals("D'Mueller", nameBasionymExAuthor.getExCombinationAuthorship().getNomenclaturalTitle());
765
        assertEquals("de Greuther", nameBasionymExAuthor.getCombinationAuthorship().getNomenclaturalTitle());
766
        assertEquals("Ciardelli", nameBasionymExAuthor.getExBasionymAuthorship().getNomenclaturalTitle());
767
        assertEquals("Doering", nameBasionymExAuthor.getBasionymAuthorship().getNomenclaturalTitle());
768

    
769
        NonViralName<?> name2 = (NonViralName<?>)parseMethod.invoke(parser, strNameAbiesSub1, null, Rank.SPECIES());
770
        assertEquals("Abies", name2.getGenusOrUninomial());
771
        assertEquals("alba", name2.getSpecificEpithet());
772
        assertEquals("beta", name2.getInfraSpecificEpithet());
773
        assertEquals(Rank.SUBSPECIES(), name2.getRank());
774

    
775

    
776
        // unparseable *********
777
        String problemString = "sdfjlös wer eer wer";
778
        NonViralName<?> nameProblem = (NonViralName<?>)parseMethod.invoke(parser, problemString, null, Rank.SPECIES());
779
        List<ParserProblem> list = nameProblem.getParsingProblems();
780
        assertTrue(nameProblem.getParsingProblem()!=0);
781
        assertEquals(problemString, nameProblem.getTitleCache());
782
    }
783

    
784

    
785
    /**
786
     * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#parseReferencedName(NonViralName, java.lang.String, eu.etaxonomy.cdm.model.name.Rank, boolean)(, )}.
787
     */
788
    @Test
789
    public final void testParseNomStatus() {
790
        //nom. ambig.
791
        String strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. ambig.";
792
        NonViralName<?> nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
793
        assertFullRefStandard(nameTestStatus);
794
        assertTrue(nameTestStatus.getStatus().size()== 1);
795
        assertEquals( NomenclaturalStatusType.AMBIGUOUS(), nameTestStatus.getStatus().iterator().next().getType());
796

    
797
        //nom. inval.
798
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. inval.";
799
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
800
        assertFullRefStandard(nameTestStatus);
801
        assertTrue(nameTestStatus.getStatus().size()== 1);
802
        assertEquals( NomenclaturalStatusType.INVALID(), nameTestStatus.getStatus().iterator().next().getType());
803

    
804
        //nom. dub.
805
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. dub.";
806
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
807
        assertFullRefStandard(nameTestStatus);
808
        assertTrue(nameTestStatus.getStatus().size()== 1);
809
        assertEquals( NomenclaturalStatusType.DOUBTFUL(), nameTestStatus.getStatus().iterator().next().getType());
810

    
811
        //nom. confus.
812
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. confus.";
813
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
814
        assertFullRefStandard(nameTestStatus);
815
        assertTrue(nameTestStatus.getStatus().size()== 1);
816
        assertEquals( NomenclaturalStatusType.CONFUSUM(), nameTestStatus.getStatus().iterator().next().getType());
817

    
818
        //nom. illeg.
819
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. illeg.";
820
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
821
        assertFullRefStandard(nameTestStatus);
822
        assertTrue(nameTestStatus.getStatus().size()== 1);
823
        assertEquals( NomenclaturalStatusType.ILLEGITIMATE(), nameTestStatus.getStatus().iterator().next().getType());
824

    
825
        //nom. superfl.
826
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. superfl.";
827
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
828
        assertFullRefStandard(nameTestStatus);
829
        assertTrue(nameTestStatus.getStatus().size()== 1);
830
        assertEquals( NomenclaturalStatusType.SUPERFLUOUS(), nameTestStatus.getStatus().iterator().next().getType());
831

    
832
        //nom. rej.
833
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. rej.";
834
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
835
        assertFullRefStandard(nameTestStatus);
836
        assertTrue(nameTestStatus.getStatus().size()== 1);
837
        assertEquals( NomenclaturalStatusType.REJECTED(), nameTestStatus.getStatus().iterator().next().getType());
838

    
839
        //nom. utique rej.
840
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. utique rej.";
841
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
842
        assertFullRefStandard(nameTestStatus);
843
        assertTrue(nameTestStatus.getStatus().size()== 1);
844
        assertEquals( NomenclaturalStatusType.UTIQUE_REJECTED(), nameTestStatus.getStatus().iterator().next().getType());
845

    
846
        //nom. cons. prop.
847
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. cons. prop.";
848
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
849
        assertFullRefStandard(nameTestStatus);
850
        assertTrue(nameTestStatus.getStatus().size()== 1);
851
        assertEquals( NomenclaturalStatusType.CONSERVED_PROP(), nameTestStatus.getStatus().iterator().next().getType());
852

    
853
        //nom. orth. cons. prop.
854
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. orth. cons. prop.";
855
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
856
        assertFullRefStandard(nameTestStatus);
857
        assertTrue(nameTestStatus.getStatus().size()== 1);
858
        assertEquals( NomenclaturalStatusType.ORTHOGRAPHY_CONSERVED_PROP(), nameTestStatus.getStatus().iterator().next().getType());
859

    
860
        //nom. cons. prop.
861
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. cons. des.";
862
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
863
        assertFullRefStandard(nameTestStatus);
864
        assertTrue(nameTestStatus.getStatus().size()== 1);
865
        assertEquals( NomenclaturalStatusType.CONSERVED_DESIG(), nameTestStatus.getStatus().iterator().next().getType());
866

    
867
        //nom. legit.
868
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. legit.";
869
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
870
        assertFullRefStandard(nameTestStatus);
871
        assertTrue(nameTestStatus.getStatus().size()== 1);
872
        assertEquals( NomenclaturalStatusType.LEGITIMATE(), nameTestStatus.getStatus().iterator().next().getType());
873

    
874
        //nom. altern.
875
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. altern.";
876
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
877
        assertFullRefStandard(nameTestStatus);
878
        assertTrue(nameTestStatus.getStatus().size()== 1);
879
        assertEquals( NomenclaturalStatusType.ALTERNATIVE(), nameTestStatus.getStatus().iterator().next().getType());
880

    
881
        //nom. alternativ.
882
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. alternativ.";
883
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
884
        assertFullRefStandard(nameTestStatus);
885
        assertTrue(nameTestStatus.getStatus().size()== 1);
886
        assertEquals( NomenclaturalStatusType.ALTERNATIVE(), nameTestStatus.getStatus().iterator().next().getType());
887

    
888
        //nom. nov.
889
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. nov.";
890
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
891
        assertFullRefStandard(nameTestStatus);
892
        assertTrue(nameTestStatus.getStatus().size()== 1);
893
        assertEquals( NomenclaturalStatusType.NOVUM(), nameTestStatus.getStatus().iterator().next().getType());
894

    
895
        //nom. utique rej. prop.
896
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. utique rej. prop.";
897
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
898
        assertFullRefStandard(nameTestStatus);
899
        assertTrue(nameTestStatus.getStatus().size()== 1);
900
        assertEquals( NomenclaturalStatusType.UTIQUE_REJECTED_PROP(), nameTestStatus.getStatus().iterator().next().getType());
901

    
902
        //nom. orth. cons.
903
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. orth. cons.";
904
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
905
        assertFullRefStandard(nameTestStatus);
906
        assertTrue(nameTestStatus.getStatus().size()== 1);
907
        assertEquals( NomenclaturalStatusType.ORTHOGRAPHY_CONSERVED(), nameTestStatus.getStatus().iterator().next().getType());
908

    
909
        //nom. rej. prop.
910
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. rej. prop.";
911
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
912
        assertFullRefStandard(nameTestStatus);
913
        assertTrue(nameTestStatus.getStatus().size()== 1);
914
        assertEquals( NomenclaturalStatusType.REJECTED_PROP(), nameTestStatus.getStatus().iterator().next().getType());
915

    
916
        //nom. cons.
917
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. cons.";
918
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
919
        assertFullRefStandard(nameTestStatus);
920
        assertTrue(nameTestStatus.getStatus().size()== 1);
921
        assertEquals( NomenclaturalStatusType.CONSERVED(), nameTestStatus.getStatus().iterator().next().getType());
922

    
923
        //nom. sanct.
924
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. sanct.";
925
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
926
        assertFullRefStandard(nameTestStatus);
927
        assertTrue(nameTestStatus.getStatus().size()== 1);
928
        assertEquals( NomenclaturalStatusType.SANCTIONED(), nameTestStatus.getStatus().iterator().next().getType());
929

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

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

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

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

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

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

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

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

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

    
993
        //ined.
994
        strTestStatus = "Houstonia macvaughii (Terrell), ined.";
995
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
996
        assertEquals("Houstonia", nameTestStatus.getGenusOrUninomial());
997
        assertEquals("macvaughii", nameTestStatus.getSpecificEpithet());
998
        assertEquals("(Terrell)", nameTestStatus.getAuthorshipCache());
999
        assertEquals(1, nameTestStatus.getStatus().size());
1000
        assertEquals( NomenclaturalStatusType.INED(), nameTestStatus.getStatus().iterator().next().getType());
1001

    
1002
        //not yet parsed "not avail."
1003
    }
1004

    
1005
    /**
1006
     * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#parseReferencedName(NonViralName, java.lang.String, eu.etaxonomy.cdm.model.name.Rank, boolean)(, )}.
1007
     */
1008
    @Test
1009
    public final void testParseReferencedName() {
1010
        try {
1011
            Method parseMethod = parser.getClass().getDeclaredMethod("parseReferencedName", String.class, NomenclaturalCode.class, Rank.class);
1012
            testName_StringNomcodeRank(parseMethod);
1013
        } catch (Exception e) {
1014
            e.printStackTrace();
1015
            assertTrue(false);
1016
        }
1017

    
1018

    
1019
        //null
1020
        String strNull = null;
1021
        Rank rankSpecies = Rank.SPECIES();
1022
        NonViralName<?> nameNull = parser.parseReferencedName(strNull, null, rankSpecies);
1023
        assertNull(nameNull);
1024

    
1025
        //Empty
1026
        String strEmpty = "";
1027
        NonViralName<?> nameEmpty = parser.parseReferencedName(strEmpty, null, rankSpecies);
1028
        assertFalse(nameEmpty.hasProblem());
1029
        assertEquals(strEmpty, nameEmpty.getFullTitleCache());
1030
        assertNull(nameEmpty.getNomenclaturalMicroReference());
1031

    
1032

    
1033
        //Whitespaces
1034
        String strFullWhiteSpcaceAndDot = "Abies alba Mill.,  Sp.   Pl.  4:  455 .  1987 .";
1035
        NonViralName<?> namefullWhiteSpcaceAndDot = parser.parseReferencedName(strFullWhiteSpcaceAndDot, null, rankSpecies);
1036
        assertFullRefStandard(namefullWhiteSpcaceAndDot);
1037
        assertTrue(((Reference)namefullWhiteSpcaceAndDot.getNomenclaturalReference()).getType().equals(eu.etaxonomy.cdm.model.reference.ReferenceType.Book));
1038
        assertEquals( "Abies alba Mill., Sp. Pl. 4: 455. 1987", namefullWhiteSpcaceAndDot.getFullTitleCache());
1039

    
1040
        //Book
1041
        String fullReference = "Abies alba Mill., Sp. Pl. 4: 455. 1987";
1042
        NonViralName<?> name1 = parser.parseReferencedName(fullReference, null, rankSpecies);
1043
        assertFullRefStandard(name1);
1044
        assertTrue(((Reference)name1.getNomenclaturalReference()).getType().equals(eu.etaxonomy.cdm.model.reference.ReferenceType.Book));
1045
        assertEquals(fullReference, name1.getFullTitleCache());
1046
        assertTrue("Name author and reference author should be the same", name1.getCombinationAuthorship() == ((Reference)name1.getNomenclaturalReference()).getAuthorship());
1047

    
1048
        //Book Section
1049
        fullReference = "Abies alba Mill. in Otto, Sp. Pl. 4(6): 455. 1987";
1050
        NonViralName<?> name2 = parser.parseReferencedName(fullReference + ".", null, rankSpecies);
1051
        assertFullRefNameStandard(name2);
1052
        assertEquals(fullReference, name2.getFullTitleCache());
1053
        assertFalse(name2.hasProblem());
1054
        INomenclaturalReference ref = name2.getNomenclaturalReference();
1055
        assertEquals(ReferenceType.BookSection, ((Reference)ref).getType());
1056
        IBookSection bookSection = (IBookSection) ref;
1057
        IBook inBook = bookSection.getInBook();
1058
        assertNotNull(inBook);
1059
        assertNotNull(inBook.getAuthorship());
1060
        assertEquals("Otto", inBook.getAuthorship().getTitleCache());
1061
        assertEquals("Otto, Sp. Pl. 4(6)", inBook.getTitleCache());
1062
        assertEquals("Sp. Pl.", inBook.getAbbrevTitle());
1063
        assertEquals("4(6)", inBook.getVolume());
1064
        assertTrue("Name author and reference author should be the same", name2.getCombinationAuthorship() == ((Reference)name2.getNomenclaturalReference()).getAuthorship());
1065

    
1066
        //Article
1067
        fullReference = "Abies alba Mill. in Sp. Pl. 4(6): 455. 1987";
1068
        NonViralName<?> name3 = parser.parseReferencedName(fullReference, null, rankSpecies);
1069
        assertFullRefNameStandard(name3);
1070
        name3.setTitleCache(null);
1071
        assertEquals(fullReference, name3.getFullTitleCache());
1072
        assertFalse(name3.hasProblem());
1073
        ref = name3.getNomenclaturalReference();
1074
        assertEquals(eu.etaxonomy.cdm.model.reference.ReferenceType.Article, ref.getType());
1075
        //Article article = (Article)ref;
1076
        IJournal journal = ((IArticle)ref).getInJournal();
1077
        assertNotNull(journal);
1078
        //assertEquals("Sp. Pl. 4(6)", inBook.getTitleCache());
1079
        assertEquals("Sp. Pl.",((Reference) journal).getTitleCache());
1080
        assertEquals("Sp. Pl.", journal.getAbbrevTitle());
1081
        assertEquals("4(6)",((IArticle)ref).getVolume());
1082
        assertTrue("Name author and reference author should be the same", name3.getCombinationAuthorship() == name3.getNomenclaturalReference().getAuthorship());
1083

    
1084
        //Article with volume range
1085
        fullReference = "Abies alba Mill. in Sp. Pl. 4(1-2): 455. 1987";
1086
        NonViralName<?> name3a = parser.parseReferencedName(fullReference, null, rankSpecies);
1087
        name3a.setTitleCache(null);
1088
        assertEquals(fullReference, name3a.getFullTitleCache());
1089
        assertFalse(name3a.hasProblem());
1090
        ref = name3a.getNomenclaturalReference();
1091
        assertEquals(eu.etaxonomy.cdm.model.reference.ReferenceType.Article, ref.getType());
1092
        assertEquals("4(1-2)",((IArticle)ref).getVolume());
1093

    
1094
        //SoftArticle - having "," on position > 4
1095
        String journalTitle = "Bull. Soc. Bot.France. Louis., Roi";
1096
        String yearPart = " 1987 - 1989";
1097
        String parsedYear = "1987-1989";
1098
        String fullReferenceWithoutYear = "Abies alba Mill. in " + journalTitle + " 4(6): 455.";
1099
        fullReference = fullReferenceWithoutYear + yearPart;
1100
        String fullReferenceWithEnd = fullReference + ".";
1101
        NonViralName<?> name4 = parser.parseReferencedName(fullReferenceWithEnd, null, rankSpecies);
1102
        assertFalse(name4.hasProblem());
1103
        assertFullRefNameStandard(name4);
1104
        assertEquals(fullReferenceWithoutYear + " " + parsedYear, name4.getFullTitleCache());
1105
        ref = name4.getNomenclaturalReference();
1106
        assertEquals(ReferenceType.Article, ref.getType());
1107
        //article = (Article)ref;
1108
        assertEquals(parsedYear, ref.getYear());
1109
        journal = ((IArticle)ref).getInJournal();
1110
        assertNotNull(journal);
1111
        assertEquals(journalTitle, ((Reference) journal).getTitleCache());
1112
        assertEquals(journalTitle, journal.getAbbrevTitle());
1113
        assertEquals("4(6)", ((IArticle)ref).getVolume());
1114

    
1115
        //Zoo name
1116
        String strNotParsableZoo = "Abies alba M., 1923, Sp. P. xxwer4352, nom. inval.";
1117
        ZoologicalName nameZooRefNotParsabel = (ZoologicalName)parser.parseReferencedName(strNotParsableZoo, null, null);
1118
        assertTrue(nameZooRefNotParsabel.hasProblem());
1119
        List<ParserProblem> list = nameZooRefNotParsabel.getParsingProblems();
1120
        assertTrue("List must contain detail and year warning ", list.contains(ParserProblem.CheckDetailOrYear));
1121
        assertEquals(21, nameZooRefNotParsabel.getProblemStarts());
1122
        assertEquals(37, nameZooRefNotParsabel.getProblemEnds());
1123
        assertTrue(nameZooRefNotParsabel.getNomenclaturalReference().hasProblem());
1124
        list = nameZooRefNotParsabel.getNomenclaturalReference().getParsingProblems();
1125
        assertTrue("List must contain detail and year warning ", list.contains(ParserProblem.CheckDetailOrYear));
1126

    
1127
        assertEquals(NomenclaturalCode.ICZN, nameZooRefNotParsabel.getNomenclaturalCode());
1128
        assertEquals(Integer.valueOf(1923), nameZooRefNotParsabel.getPublicationYear());
1129
        assertEquals(1, nameZooRefNotParsabel.getStatus().size());
1130

    
1131
        String strZooNameSineYear = "Homo sapiens L., 1758, Sp. An. 3: 345";
1132
        ZoologicalName nameZooNameSineYear = (ZoologicalName)parser.parseReferencedName(strZooNameSineYear);
1133
        assertFalse(nameZooNameSineYear.hasProblem());
1134
        assertEquals("Name without reference year must have year", (Integer)1758, nameZooNameSineYear.getPublicationYear());
1135
        assertEquals("Name without reference year must have year", "1758", nameZooNameSineYear.getNomenclaturalReference().getYear());
1136

    
1137
        String strZooNameNewCombination = "Homo sapiens (L., 1758) Mill., 1830, Sp. An. 3: 345";
1138
        ZoologicalName nameZooNameNewCombination = (ZoologicalName)parser.parseReferencedName(strZooNameNewCombination);
1139
        assertTrue(nameZooNameNewCombination.hasProblem());
1140
        list = nameZooNameNewCombination.getParsingProblems();
1141
        assertTrue("List must contain new combination has publication warning ", list.contains(ParserProblem.NewCombinationHasPublication));
1142
        assertEquals(35, nameZooNameNewCombination.getProblemStarts());
1143
        assertEquals(51, nameZooNameNewCombination.getProblemEnds());
1144

    
1145

    
1146
        //Special MicroRefs
1147
        String strSpecDetail1 = "Abies alba Mill. in Sp. Pl. 4(6): [455]. 1987";
1148
        NonViralName<?> nameSpecDet1 = parser.parseReferencedName(strSpecDetail1 + ".", null, rankSpecies);
1149
        assertFalse(nameSpecDet1.hasProblem());
1150
        assertEquals(strSpecDetail1, nameSpecDet1.getFullTitleCache());
1151
        assertEquals("[455]", nameSpecDet1.getNomenclaturalMicroReference());
1152

    
1153
        //Special MicroRefs
1154
        String strSpecDetail2 = "Abies alba Mill. in Sp. Pl. 4(6): couv. 2. 1987";
1155
        NonViralName<?> nameSpecDet2 = parser.parseReferencedName(strSpecDetail2 + ".", null, rankSpecies);
1156
        assertFalse(nameSpecDet2.hasProblem());
1157
        assertEquals(strSpecDetail2, nameSpecDet2.getFullTitleCache());
1158
        assertEquals("couv. 2", nameSpecDet2.getNomenclaturalMicroReference());
1159

    
1160
        //Special MicroRefs
1161
        String strSpecDetail3 = "Abies alba Mill. in Sp. Pl. 4(6): fig. 455. 1987";
1162
        NonViralName<?> nameSpecDet3 = parser.parseReferencedName(strSpecDetail3 + ".", null, rankSpecies);
1163
        assertFalse(nameSpecDet3.hasProblem());
1164
        assertEquals(strSpecDetail3, nameSpecDet3.getFullTitleCache());
1165
        assertEquals("fig. 455", nameSpecDet3.getNomenclaturalMicroReference());
1166

    
1167
        //Special MicroRefs
1168
        String strSpecDetail4 = "Abies alba Mill. in Sp. Pl. 4(6): fig. 455-567. 1987";
1169
        fullReference = strSpecDetail4 + ".";
1170
        NonViralName<?> nameSpecDet4 = parser.parseReferencedName(fullReference, null, rankSpecies);
1171
        assertFalse(nameSpecDet4.hasProblem());
1172
        assertEquals(strSpecDetail4, nameSpecDet4.getFullTitleCache());
1173
        assertEquals("fig. 455-567", nameSpecDet4.getNomenclaturalMicroReference());
1174

    
1175

    
1176
        //Special MicroRefs
1177
        String strSpecDetail5 = "Abies alba Mill. in Sp. Pl. 4(6): Gard n\u00B0 4. 1987";
1178
        fullReference = strSpecDetail5 + ".";
1179
        NonViralName<?> nameSpecDet5 = parser.parseReferencedName(fullReference, null, rankSpecies);
1180
        assertFalse(nameSpecDet5.hasProblem());
1181
        assertEquals(strSpecDetail5, nameSpecDet5.getFullTitleCache());
1182
        assertEquals("Gard n\u00B0 4", nameSpecDet5.getNomenclaturalMicroReference());
1183

    
1184
        //Special MicroRefs
1185
        String strSpecDetail6 = "Abies alba Mill. in Sp. Pl. 4(6): 455a. 1987";
1186
        fullReference = strSpecDetail6 + ".";
1187
        NonViralName<?> nameSpecDet6 = parser.parseReferencedName(fullReference, null, rankSpecies);
1188
        assertFalse(nameSpecDet6.hasProblem());
1189
        assertEquals(strSpecDetail6, nameSpecDet6.getFullTitleCache());
1190
        assertEquals("455a", nameSpecDet6.getNomenclaturalMicroReference());
1191

    
1192
        //Special MicroRefs
1193
        String strSpecDetail7 = "Abies alba Mill. in Sp. Pl. 4(6): pp.455-457. 1987";
1194
        fullReference = strSpecDetail7 + ".";
1195
        NonViralName<?> nameSpecDet7 = parser.parseReferencedName(fullReference, null, rankSpecies);
1196
        assertFalse(nameSpecDet7.hasProblem());
1197
        assertEquals(strSpecDetail7, nameSpecDet7.getFullTitleCache());
1198
        assertEquals("pp.455-457", nameSpecDet7.getNomenclaturalMicroReference());
1199

    
1200
        //Special MicroRefs
1201
        String strSpecDetail8 = "Abies alba Mill. in Sp. Pl. 4(6): ppp.455-457. 1987";
1202
        NonViralName<?> nameSpecDet8 = parser.parseReferencedName(strSpecDetail8, null, rankSpecies);
1203
        assertTrue(nameSpecDet8.hasProblem());
1204
        assertEquals(20, nameSpecDet8.getProblemStarts()); //TODO better start behind :
1205
        assertEquals(51, nameSpecDet8.getProblemEnds());   //TODO better stop after -457
1206

    
1207

    
1208
        //Special MicroRefs
1209
        String strSpecDetail9 = "Abies alba Mill. in Sp. Pl. 4(6): pp. 455 - 457. 1987";
1210
        NonViralName<?> nameSpecDet9 = parser.parseReferencedName(strSpecDetail9, null, rankSpecies);
1211
        assertFalse(nameSpecDet9.hasProblem());
1212
        assertEquals(strSpecDetail9, nameSpecDet9.getFullTitleCache());
1213
        assertEquals("pp. 455 - 457", nameSpecDet9.getNomenclaturalMicroReference());
1214

    
1215
        //Special MicroRefs
1216
        String strSpecDetail10 = "Abies alba Mill. in Sp. Pl. 4(6): p 455. 1987";
1217
        NonViralName<?> nameSpecDet10 = parser.parseReferencedName(strSpecDetail10, null, rankSpecies);
1218
        assertFalse(nameSpecDet10.hasProblem());
1219
        assertEquals(strSpecDetail10, nameSpecDet10.getFullTitleCache());
1220
        assertEquals("p 455", nameSpecDet10.getNomenclaturalMicroReference());
1221

    
1222
        //Special MicroRefs
1223
        String strSpecDetail11 = "Abies alba Mill. in Sp. Pl. 4(6): p. 455 - 457. 1987";
1224
        NonViralName<?> nameSpecDet11 = parser.parseReferencedName(strSpecDetail11, null, rankSpecies);
1225
        assertTrue(nameSpecDet11.hasProblem());
1226
        list = nameSpecDet11.getParsingProblems();
1227
        assertTrue("Problem is Detail. Must be pp.", list.contains(ParserProblem.CheckDetailOrYear));
1228
        assertEquals(20, nameSpecDet8.getProblemStarts()); //TODO better start behind :
1229
        assertEquals(51, nameSpecDet8.getProblemEnds());   //TODO better stop after - 457
1230

    
1231

    
1232
        //no volume, no edition
1233
        String strNoVolume = "Abies alba Mill., Sp. Pl.: 455. 1987";
1234
        NonViralName<?> nameNoVolume = parser.parseReferencedName(strNoVolume, null, rankSpecies);
1235
        assertFalse(nameNoVolume.hasProblem());
1236
        assertEquals(strNoVolume, nameNoVolume.getFullTitleCache());
1237
        assertEquals(null, ((IVolumeReference)(nameNoVolume.getNomenclaturalReference())).getVolume());
1238
        assertEquals(null, ((IBook)nameNoVolume.getNomenclaturalReference()).getEdition());
1239

    
1240
        //volume, no edition
1241
        strNoVolume = "Abies alba Mill., Sp. Pl. 2: 455. 1987";
1242
        nameNoVolume = parser.parseReferencedName(strNoVolume, null, rankSpecies);
1243
        assertFalse(nameNoVolume.hasProblem());
1244
        assertEquals(strNoVolume, nameNoVolume.getFullTitleCache());
1245
        assertEquals("2", ((IVolumeReference)(nameNoVolume.getNomenclaturalReference())).getVolume());
1246
        assertEquals(null, ((IBook)(nameNoVolume.getNomenclaturalReference())).getEdition());
1247

    
1248
        //no volume, edition
1249
        strNoVolume = "Abies alba Mill., Sp. Pl., ed. 3: 455. 1987";
1250
        nameNoVolume = parser.parseReferencedName(strNoVolume, null, rankSpecies);
1251
        assertFalse(nameNoVolume.hasProblem());
1252
        assertEquals(strNoVolume, nameNoVolume.getFullTitleCache());
1253
        assertEquals(null, ((IVolumeReference)(nameNoVolume.getNomenclaturalReference())).getVolume());
1254
        assertEquals("3", ((IBook)(nameNoVolume.getNomenclaturalReference())).getEdition());
1255

    
1256
        //volume, edition
1257
        strNoVolume = "Abies alba Mill., Sp. Pl. ed. 3, 4(5): 455. 1987";
1258
        nameNoVolume = parser.parseReferencedName(strNoVolume, null, rankSpecies);
1259
        assertFalse(nameNoVolume.hasProblem());
1260
        assertEquals(strNoVolume.replace(" ed.", ", ed."), nameNoVolume.getFullTitleCache());
1261
        assertEquals("4(5)", ((IVolumeReference)(nameNoVolume.getNomenclaturalReference())).getVolume());
1262
        assertEquals("3", ((IBook)(nameNoVolume.getNomenclaturalReference())).getEdition());
1263

    
1264
        String strUnparsableInRef = "Abies alba Mill. in -er46: 455. 1987";
1265
        NonViralName<?> nameUnparsableInRef = parser.parseReferencedName(strUnparsableInRef, null, rankSpecies);
1266
        assertTrue(nameUnparsableInRef.hasProblem());
1267
        list = nameUnparsableInRef.getParsingProblems();
1268
        assertTrue("Unparsable title", list.contains(ParserProblem.UnparsableReferenceTitle));
1269
        assertEquals(strUnparsableInRef, nameUnparsableInRef.getFullTitleCache());
1270
        assertEquals(20, nameUnparsableInRef.getProblemStarts());
1271
        assertEquals(25, nameUnparsableInRef.getProblemEnds());
1272

    
1273

    
1274
        //volume, edition
1275
        String strNoSeparator = "Abies alba Mill. Sp. Pl. ed. 3, 4(5): 455. 1987";
1276
        NonViralName<?> nameNoSeparator = parser.parseReferencedName(strNoSeparator, ICNAFP, rankSpecies);
1277
        assertTrue(nameNoSeparator.hasProblem());
1278
        list = nameNoSeparator.getParsingProblems();
1279
        assertTrue("Problem is missing name-reference separator", list.contains(ParserProblem.NameReferenceSeparation));
1280
        assertEquals(strNoSeparator, nameNoSeparator.getFullTitleCache());
1281
        assertEquals(10, nameNoSeparator.getProblemStarts()); //TODO better start behind Mill. (?)
1282
        assertEquals(47, nameNoSeparator.getProblemEnds());   //TODO better stop before :
1283

    
1284
        String strUnparsableInRef2 = "Hieracium pepsicum L., My Bookkkk 1. 1903";
1285
        NonViralName<?> nameUnparsableInRef2 = parser.parseReferencedName(strUnparsableInRef2, null, rankSpecies);
1286
        assertTrue(nameUnparsableInRef2.hasProblem());
1287
        list = nameUnparsableInRef2.getParsingProblems();
1288
        assertTrue("Problem detail", list.contains(ParserProblem.CheckDetailOrYear));
1289
        assertEquals(strUnparsableInRef2, nameUnparsableInRef2.getFullTitleCache());
1290
        assertEquals(23, nameUnparsableInRef2.getProblemStarts());
1291
        assertEquals(41, nameUnparsableInRef2.getProblemEnds());
1292

    
1293

    
1294
        String strUnparsableInRef3 = "Hieracium pespcim N., My Bookkkk 1. 1902";
1295
        NonViralName<?> nameUnparsableInRef3 = parser.parseReferencedName(strUnparsableInRef3, null, null);
1296
        assertTrue(nameUnparsableInRef3.hasProblem());
1297
        list = nameUnparsableInRef3.getParsingProblems();
1298
        assertTrue("Problem detail", list.contains(ParserProblem.CheckDetailOrYear));
1299
        assertEquals(strUnparsableInRef3, nameUnparsableInRef3.getFullTitleCache());
1300
        assertEquals(22, nameUnparsableInRef3.getProblemStarts());
1301
        assertEquals(40, nameUnparsableInRef3.getProblemEnds());
1302

    
1303
        String strUnparsableInRef4 = "Hieracium pepsicum (Hsllreterto) L., My Bookkkk 1. 1903";
1304
        NonViralName<?> nameUnparsableInRef4 = parser.parseReferencedName(strUnparsableInRef4, null, null);
1305
        assertTrue(nameUnparsableInRef4.hasProblem());
1306
        list = nameUnparsableInRef4.getParsingProblems();
1307
        assertTrue("Problem detail", list.contains(ParserProblem.CheckDetailOrYear));
1308
        assertEquals(strUnparsableInRef4, nameUnparsableInRef4.getFullTitleCache());
1309
        assertEquals(37, nameUnparsableInRef4.getProblemStarts());
1310
        assertEquals(55, nameUnparsableInRef4.getProblemEnds());
1311

    
1312
        String strSameName = "Hieracium pepcum (Hsllreterto) L., My Bokkk 1. 1903";
1313
        NonViralName<?> nameSameName = nameUnparsableInRef4;
1314
        parser.parseReferencedName(nameSameName, strSameName, null, true);
1315
        assertTrue(nameSameName.hasProblem());
1316
        list = nameSameName.getParsingProblems();
1317
        assertTrue("Problem detail", list.contains(ParserProblem.CheckDetailOrYear));
1318
        assertEquals(strSameName, nameSameName.getFullTitleCache());
1319
        assertEquals(35, nameSameName.getProblemStarts());
1320
        assertEquals(51, nameSameName.getProblemEnds());
1321

    
1322
        String strGenusUnparse = "Hieracium L., jlklk";
1323
        NonViralName<?> nameGenusUnparse =
1324
            parser.parseReferencedName(strGenusUnparse, null, null);
1325
        assertTrue(nameGenusUnparse.hasProblem());
1326
        list = nameGenusUnparse.getParsingProblems();
1327
        assertTrue("Problem detail", list.contains(ParserProblem.CheckDetailOrYear));
1328
        assertTrue("Problem uninomial", list.contains(ParserProblem.CheckRank));
1329
        assertEquals(strGenusUnparse, nameGenusUnparse.getFullTitleCache());
1330
        assertEquals(0, nameGenusUnparse.getProblemStarts());
1331
        assertEquals(19, nameGenusUnparse.getProblemEnds());
1332

    
1333
        String strGenusUnparse2 = "Hieracium L., Per Luigi: 44. 1987";
1334
        NonViralName<?> nameGenusUnparse2 =
1335
            parser.parseReferencedName(strGenusUnparse2, null, Rank.FAMILY());
1336
        assertFalse(nameGenusUnparse2.hasProblem());
1337
        assertEquals(strGenusUnparse2, nameGenusUnparse2.getFullTitleCache());
1338
        assertEquals(-1, nameGenusUnparse2.getProblemStarts());
1339
        assertEquals(-1, nameGenusUnparse2.getProblemEnds());
1340

    
1341
        String strBookSection2 = "Hieracium vulgatum subsp. acuminatum (Jord.) Zahn in Schinz & Keller, Fl. Schweiz, ed. 2, 2: 288. 1905-1907";
1342
        String strBookSection2NoComma = "Hieracium vulgatum subsp. acuminatum (Jord.) Zahn in Schinz & Keller, Fl. Schweiz ed. 2, 2: 288. 1905-1907";
1343
        NonViralName<?> nameBookSection2 =
1344
            parser.parseReferencedName(strBookSection2, null, null);
1345
        assertFalse(nameBookSection2.hasProblem());
1346
        nameBookSection2.setFullTitleCache(null, false);
1347
        assertEquals(strBookSection2NoComma.replace(" ed.", ", ed."), nameBookSection2.getFullTitleCache());
1348
        assertEquals(-1, nameBookSection2.getProblemStarts());
1349
        assertEquals(-1, nameBookSection2.getProblemEnds());
1350
        assertNull((nameBookSection2.getNomenclaturalReference()).getDatePublished().getStart());
1351
        assertEquals("1905-1907", ((IBookSection)nameBookSection2.getNomenclaturalReference()).getInBook().getDatePublished().getYear());
1352

    
1353

    
1354
        String strBookSection = "Hieracium vulgatum subsp. acuminatum (Jord.) Zahn in Schinz & Keller, Fl. Schweiz ed. 2, 2: 288. 1905";
1355
        NonViralName<?> nameBookSection =
1356
            parser.parseReferencedName(strBookSection, null, null);
1357
        assertFalse(nameBookSection.hasProblem());
1358
        assertEquals(strBookSection.replace(" ed.", ", ed."), nameBookSection.getFullTitleCache());
1359
        assertEquals(-1, nameBookSection.getProblemStarts());
1360
        assertEquals(-1, nameBookSection.getProblemEnds());
1361
        assertNull(((IBookSection)nameBookSection.getNomenclaturalReference()).getInBook().getDatePublished().getStart());
1362
        assertEquals("1905", ((IBookSection)nameBookSection.getNomenclaturalReference()).getDatePublished().getYear());
1363

    
1364
        String strXXXs = "Abies alba, Soer der 1987";
1365
        NonViralName<?> problemName = parser.parseReferencedName(strXXXs, null, null);
1366
        assertTrue(problemName.hasProblem());
1367
        list = problemName.getParsingProblems();
1368
        assertTrue("Problem must be name-reference separation", list.contains(ParserProblem.NameReferenceSeparation));
1369
        parser.parseReferencedName(problemName, strBookSection, null, true);
1370
        assertFalse(problemName.hasProblem());
1371

    
1372
        problemName = parser.parseFullName(strXXXs, null, null);
1373
        assertTrue(problemName.hasProblem());
1374
        list = problemName.getParsingProblems();
1375
        assertTrue("Name part must be unparsable", list.contains(ParserProblem.UnparsableNamePart));
1376

    
1377

    
1378
        String testParsable = "Pithecellobium macrostachyum Benth.";
1379
        assertTrue(isParsable(testParsable, ICNAFP));
1380

    
1381
        testParsable = "Pithecellobium macrostachyum (Benth.)";
1382
        assertTrue(isParsable(testParsable, ICNAFP));
1383

    
1384
        testParsable = "Pithecellobium macrostachyum (Benth., 1845)";
1385
        assertTrue(isParsable(testParsable, NomenclaturalCode.ICZN));
1386

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

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

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

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

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

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

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

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

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

    
1418
        testParsable = "Hieracium lachenalii, Ill. Fl. (Mitt.) 6: 1285. 1929";
1419
        assertFalse("Author is obligatory if followed by reference", isParsable(testParsable, ICNAFP));
1420
        assertTrue("Problem must be name-reference separation", getProblems(testParsable, ICNAFP).
1421
                contains(ParserProblem.NameReferenceSeparation));
1422

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

    
1428
        testParsable = "Abies alba Mill. var. alba";
1429
        assertTrue("Autonym problem", isParsable(testParsable, ICNAFP));
1430

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

    
1434

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

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

    
1442

    
1443
    }
1444

    
1445

    
1446
    /**
1447
     * Test author with name parts van, von, de, de la, d', da, del.
1448
     * See also http://dev.e-taxonomy.eu/trac/ticket/3373
1449
     */
1450
    @Test
1451
    public final void  testComposedAuthorNames(){
1452

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

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

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

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

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

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

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

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

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

    
1489
    }
1490

    
1491

    
1492

    
1493
    /**
1494
     * @param testParsable
1495
     * @param icbn
1496
     * @return
1497
     */
1498
    private List<ParserProblem> getProblems(String string, NomenclaturalCode code) {
1499
        List<ParserProblem> result;
1500
        result = parser.parseReferencedName(string, code, null).getParsingProblems();
1501
        return result;
1502
    }
1503

    
1504
    private boolean isParsable(String string, NomenclaturalCode code){
1505
        NonViralName<?> name = parser.parseReferencedName(string, code, null);
1506
        return ! name.hasProblem();
1507
    }
1508

    
1509
    private void assertFullRefNameStandard(NonViralName<?> name){
1510
        assertEquals("Abies", name.getGenusOrUninomial());
1511
        assertEquals("alba", name.getSpecificEpithet());
1512
        assertEquals("Mill.", name.getAuthorshipCache());
1513
        assertEquals("455", name.getNomenclaturalMicroReference());
1514
        assertNotNull(name.getNomenclaturalReference());
1515
    }
1516

    
1517
    private void assertFullRefStandard(NonViralName<?> name){
1518
        assertEquals("Abies", name.getGenusOrUninomial());
1519
        assertEquals("alba", name.getSpecificEpithet());
1520
        assertEquals("Mill.", name.getAuthorshipCache());
1521
        assertEquals("455", name.getNomenclaturalMicroReference());
1522
        assertNotNull(name.getNomenclaturalReference());
1523
        INomenclaturalReference ref = name.getNomenclaturalReference();
1524
        assertEquals("1987", ref.getYear());
1525
        assertEquals("Sp. Pl.", ref.getAbbrevTitle());
1526
    }
1527

    
1528

    
1529
    @Test
1530
    public void testNeverEndingParsing(){
1531
        //some full titles result in never ending parsing process https://dev.e-taxonomy.eu/trac/ticket/1556
1532

    
1533
        String irinaExample = "Milichiidae Sharp, 1899, Insects. Part II. Hymenopteracontinued (Tubulifera and Aculeata), Coleoptera, Strepsiptera, Lepidoptera, Diptera, Aphaniptera, Thysanoptera, Hemiptera, Anoplura 6: 504. 1899";
1534
//      irinaExample = "Milichiidae Sharp, 1899, Insects. Part II. Uiuis Iuiui Hymenopteracontinued (Tubulifera and Aculeata), Coleoptera, Strepsiptera, Lepidoptera, Diptera, Aphaniptera, Thysanoptera, Hemiptera, Anoplura 6: 504. 1899";
1535
        NonViralName<?> nvn = this.parser.parseReferencedName(irinaExample, NomenclaturalCode.ICZN, null);
1536
        int parsingProblem = nvn.getParsingProblem();
1537
        Assert.assertEquals("Name should have only rank warning", 1, parsingProblem);
1538
        Assert.assertEquals("Titlecache", "Milichiidae Sharp, 1899", nvn.getTitleCache());
1539
        Assert.assertEquals("If this line reached everything should be ok", "Milichiidae", nvn.getGenusOrUninomial());
1540

    
1541
        String anotherExample = "Scorzonera hispanica var. brevifolia Boiss. & Balansa in Boissier, Diagn. Pl. Orient., ser. 2 6: 119. 1859.";
1542
        nvn = this.parser.parseReferencedName(anotherExample, ICNAFP, null);
1543
        parsingProblem = nvn.getParsingProblem();
1544
        Assert.assertEquals("Problem should be 0", 0, parsingProblem);
1545
        Assert.assertEquals("Titlecache", "Scorzonera hispanica var. brevifolia Boiss. & Balansa", nvn.getTitleCache());
1546
        Assert.assertEquals("If this line reached everything should be ok", "Scorzonera", nvn.getGenusOrUninomial());
1547

    
1548
        String unparsable = "Taraxacum nevskii L., Trudy Bot. Inst. Nauk S.S.S.R., Ser. 1, Fl. Sist. Vyssh. Rast. 4: 293. 1937.";
1549
//      String unparsableA = "Taraxacum nevskii L. in Trudy Bot. Inst. Nauk: 293. 1937.";
1550
        nvn = this.parser.parseReferencedName(unparsable, ICNAFP, null);
1551
        Assert.assertEquals("Titlecache", "Taraxacum nevskii L.", nvn.getTitleCache());
1552
        Assert.assertEquals("If this line reached everything should be ok", "Taraxacum", nvn.getGenusOrUninomial());
1553
        parsingProblem = nvn.getParsingProblem();
1554
        Assert.assertEquals("Name should no warnings or errors", 0, parsingProblem);
1555

    
1556
        String unparsable2 = "Hieracium pxxx Dahlst., Kongl. Svenska Vetensk. Acad. Handl. ser. 2, 26(3): 255. 1894";
1557
//      String unparsable2A = "Hieracium pxxx Dahlst., Kongl Svenska Vetensk Acad Handl, 26: 255. 1894.";
1558
        nvn = this.parser.parseReferencedName(unparsable2, ICNAFP, null);
1559
        Assert.assertEquals("Titlecache", "Hieracium pxxx Dahlst.", nvn.getTitleCache());
1560
        Assert.assertEquals("If this line reached everything should be ok", "Hieracium", nvn.getGenusOrUninomial());
1561
        parsingProblem = nvn.getParsingProblem();
1562
        Assert.assertEquals("Name should no warnings or errors", 0, parsingProblem);
1563

    
1564

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

    
1570
    }
1571

    
1572
    @Test
1573
    public final void testSeriesPart(){
1574
        Pattern seriesPattern = Pattern.compile(NonViralNameParserImplRegExBase.pSeriesPart);
1575
        Matcher matcher = seriesPattern.matcher("ser. 2");
1576
        Assert.assertTrue("", matcher.matches());
1577
    }
1578

    
1579
    /**
1580
     * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#fullTeams(java.lang.String)}.
1581
     */
1582
    @Test
1583
    public final void testFullTeams() {
1584
        logger.warn("Not yet implemented"); // TODO
1585
    }
1586

    
1587
    /**
1588
     * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#AuthorshipAndEx(java.lang.String)}.
1589
     * @throws StringNotParsableException
1590
     */
1591
    @Test
1592
    public final void testParseAuthorsTaxonNameString() throws StringNotParsableException {
1593
        NonViralName<?> nvn = ZoologicalName.NewInstance(null);
1594
        parser.parseAuthors(nvn, "Eckweiler & ten Hagen, 2003");
1595
        Team team = (Team)nvn.getCombinationAuthorship();
1596
        Assert.assertNotNull("Comb. author must not be null", team);
1597
        Assert.assertEquals("Must be team with 2 members", 2, team.getTeamMembers().size());
1598
        Assert.assertEquals("Second member must be 'ten Hagen'", "ten Hagen", team.getTeamMembers().get(1).getTitleCache());
1599

    
1600
        //Crosson du Cormier, 1964
1601
        ZoologicalName zooName = ZoologicalName.NewInstance(null);
1602
        parser.parseAuthors(zooName, "Crosson du Cormier, 1964");
1603
        Person person = (Person)zooName.getCombinationAuthorship();
1604
        Assert.assertNotNull("Comb. author must not be null", person);
1605
        Assert.assertEquals("Persons title must be 'Crosson du Cormier'", "Crosson du Cormier", person.getTitleCache());
1606
        Assert.assertEquals("Year must be 1964", Integer.valueOf(1964), zooName.getPublicationYear() );
1607

    
1608
        //(van der Hoeven, 1839)
1609
        zooName = ZoologicalName.NewInstance(null);
1610
        parser.parseAuthors(zooName, "(van der Hoeven, 1839)");
1611
        Assert.assertNull("Combination author must be null", zooName.getCombinationAuthorship());
1612
        person = (Person)zooName.getBasionymAuthorship();
1613
        Assert.assertNotNull("Basionym author must not be null", person);
1614
        Assert.assertEquals("Persons title must be 'van der Hoeven'", "van der Hoeven", person.getTitleCache());
1615
        Assert.assertEquals("Year must be 1839", Integer.valueOf(1839), zooName.getOriginalPublicationYear() );
1616

    
1617
        //le Doux, 1931
1618
        zooName = ZoologicalName.NewInstance(null);
1619
        parser.parseAuthors(zooName, "le Doux, 1931");
1620
        person = (Person)zooName.getCombinationAuthorship();
1621
        Assert.assertNotNull("Comb. author must not be null", person);
1622
        Assert.assertEquals("Persons title must be 'le Doux'", "le Doux", person.getTitleCache());
1623
        Assert.assertEquals("Year must be 1931", Integer.valueOf(1931), zooName.getPublicationYear() );
1624

    
1625

    
1626
    }
1627

    
1628
    @Test  //#4764
1629
    public void testParseSection(){
1630
        //this test does not really test problematic cases where sect.idInVoc = "sect." instead of "sect.(bot.)"
1631
        //however, by changing the csv file entry to sect. just for testing it can be used as a functional test
1632
        String sectionNameStr = "Taraxacum sect. Testtaxa M\u00fcller, Incredible Taxa: 12. 2016";
1633
        NonViralName<?> sectionName = parser.parseReferencedName(sectionNameStr, NomenclaturalCode.ICNAFP, null);
1634
        int parsingProblem = sectionName.getParsingProblem();
1635
        Assert.assertEquals("Problem should be 0", 0, parsingProblem);
1636
        Rank rank = sectionName.getRank();
1637
        Assert.assertEquals("", Rank.SECTION_BOTANY(), rank  );
1638

    
1639
    }
1640

    
1641
    @Test  //#5072
1642
    public final void testLongRunningParsingCapitals(){
1643
        DateTime start = DateTime.now();
1644
        String nameStr = "Nazeris fujianensis JIAYAO HU, LIZHEN LI, MEIJUN ZHAO,2010";  //name from CoL that created problems
1645
        NonViralName<?> name = parser.parseReferencedName(nameStr, NomenclaturalCode.ICZN, null);
1646
        DateTime end = DateTime.now();
1647
        Duration duration = new Duration(start, end);
1648
        long seconds = duration.getStandardSeconds();
1649
        //this is the critical part of the test that must not be changed
1650
        Assert.assertTrue("Parsing of name should take less then 3 seconds but took " + seconds, seconds < 3);
1651

    
1652
    }
1653

    
1654
    @Test  //#5072
1655
    //http://www.regular-expressions.info/catastrophic.html
1656
    public final void testLongRunningParsing(){
1657

    
1658
        //name only
1659
        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";
1660
        DateTime start = DateTime.now();
1661
        NonViralName<?> name = parser.parseReferencedName(nameStr, NomenclaturalCode.ICNAFP, null);
1662
        DateTime end = DateTime.now();
1663
        Duration duration = new Duration(start, end);
1664
        long seconds = duration.getStandardSeconds();
1665
        //this is the critical part of the test that must not be changed
1666
        Assert.assertTrue("Parsing of name should take less then 3 seconds but took " + seconds, seconds < 3);
1667
        //the following may be discussed
1668
        Assert.assertFalse("Name should parse without problems",name.hasProblem());
1669

    
1670

    
1671
        //with reference
1672
        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.";
1673
        start = DateTime.now();
1674
        name = parser.parseReferencedName(nameStr, NomenclaturalCode.ICNAFP, null);
1675
        end = DateTime.now();
1676
        duration = new Duration(start, end);
1677
        seconds = duration.getStandardSeconds();
1678
        //this is the critical part of the test that must not be changed
1679
        Assert.assertTrue("Parsing of name should take less then 3 seconds but took " + seconds, seconds < 3);
1680
        //the following may be discussed
1681
        Assert.assertFalse("Name should parse without problems",name.hasProblem());
1682
    }
1683

    
1684
    @Test  //#5072
1685
    public final void testLongRunningParsingAuthors(){
1686
        //http://www.regular-expressions.info/catastrophic.html
1687
        //
1688
        //Länge des Nachnamens macht keinen Unterschied
1689
        //Anzahl der "AuthorParts scheint entscheidend
1690
        // & am Ende macht es langsamger (16s), als nur ","(6s))
1691

    
1692
        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";
1693
        TeamOrPersonBase[] authorArray = new TeamOrPersonBase[4];
1694
        try {
1695
            DateTime start = DateTime.now();
1696
            parser.fullAuthors(authorStr, authorArray, new Integer[]{1800, null, null, null}, BotanicalName.class);
1697
            DateTime end = DateTime.now();
1698
            Duration duration = new Duration(start, end);
1699
            long seconds = duration.getStandardSeconds();
1700
//            System.out.println(seconds);
1701
            //this is the critical part of the test that must not be changed
1702
            Assert.assertTrue("Parsing of name should take less then 3 seconds but took " + seconds, seconds < 3);
1703
        } catch (StringNotParsableException e) {
1704
            e.printStackTrace();
1705
            Assert.fail("Authors should be parsable");
1706
        }
1707

    
1708
    }
1709

    
1710

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

    
1719
    /**
1720
     * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#Authorship(java.lang.String)}.
1721
     */
1722
    @Test
1723
    public final void testAuthorship() {
1724
        logger.warn("Not yet implemented"); // TODO
1725
    }
1726

    
1727
    /**
1728
     * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#parseCultivar(java.lang.String)}.
1729
     */
1730
    @Test
1731
    public final void testParseCultivar() {
1732
        logger.warn("Not yet implemented"); // TODO
1733
    }
1734

    
1735
    @Test
1736
    public final void testNomenclaturalStatus() {
1737
        BotanicalName name = BotanicalName.NewInstance(Rank.FAMILY(), "Acanthopale", null, null, null, null, null, null, null);
1738
        name.addStatus(NomenclaturalStatus.NewInstance(NomenclaturalStatusType.ALTERNATIVE()));
1739
        BotanicalName name2 = BotanicalName.NewInstance(Rank.FAMILY());
1740
        parser.parseReferencedName(name2, name.getFullTitleCache(), name2.getRank(), true);
1741
        parser.parseReferencedName(name2, name.getFullTitleCache(), name2.getRank(), true);
1742
        Assert.assertEquals("Title cache should be same. No duplication of nom. status should take place", name.getFullTitleCache(), name2.getFullTitleCache());
1743
    }
1744

    
1745
    @Test
1746
    public final void testSpecificAuthors(){
1747
        //McVaugh
1748
        NonViralName<?> name = parser.parseFullName("Psidium longipes var. orbiculare (O.Berg) McVaugh");
1749
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1750
        TeamOrPersonBase<?> combinationAuthor = name.getCombinationAuthorship();
1751
        assertEquals( "McVaugh", combinationAuthor.getNomenclaturalTitle());
1752
        TeamOrPersonBase<?> basionymAuthor = name.getBasionymAuthorship();
1753
        assertEquals( "O.Berg", basionymAuthor.getNomenclaturalTitle());
1754

    
1755
//      Campanula rhodensis A. DC.
1756

    
1757
    }
1758

    
1759
    @Test
1760
    public final void testExistingProblems(){
1761
        //Canabio, issue with space
1762
        NonViralName<?> name = parser.parseReferencedName("Machaonia erythrocarpa var. hondurensis (Standl.) Borhidi"
1763
                + " in Acta Bot. Hung. 46 (1-2): 30. 2004");
1764
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1765
        TeamOrPersonBase<?> combinationAuthor = name.getCombinationAuthorship();
1766
        assertEquals( "Borhidi", combinationAuthor.getNomenclaturalTitle());
1767
        Reference nomRef = (Reference)name.getNomenclaturalReference();
1768
        assertEquals(ReferenceType.Article, nomRef.getType());
1769
        assertEquals("46 (1-2)", nomRef.getVolume());
1770

    
1771
        //Canabio, detail with fig.
1772
        name = parser.parseReferencedName("Didymaea floribunda Rzed."
1773
                + " in Bol. Soc. Bot. Mex. 44: 72, fig. 1. 1983");
1774
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1775
        combinationAuthor = name.getCombinationAuthorship();
1776
        assertEquals( "Rzed.", combinationAuthor.getNomenclaturalTitle());
1777
        nomRef = (Reference)name.getNomenclaturalReference();
1778
        assertEquals(ReferenceType.Article, nomRef.getType());
1779
        assertEquals("44", nomRef.getVolume());
1780
        assertEquals("72, fig. 1", name.getNomenclaturalMicroReference());
1781

    
1782
        //fig with a-c and without dot
1783
        name = parser.parseReferencedName("Deppea guerrerensis Dwyer & Lorence"
1784
                + " in Allertonia 4: 428. fig 4a-c. 1988");  //
1785
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1786
        combinationAuthor = name.getCombinationAuthorship();
1787
        assertEquals( "Dwyer & Lorence", combinationAuthor.getNomenclaturalTitle());
1788
        nomRef = (Reference)name.getNomenclaturalReference();
1789
        assertEquals(ReferenceType.Article, nomRef.getType());
1790
        assertEquals("4", nomRef.getVolume());
1791
        assertEquals("428. fig 4a-c", name.getNomenclaturalMicroReference());
1792

    
1793
        //issue with EN_DASH (3–4)
1794
        name = parser.parseReferencedName("Arachnothryx tacanensis (Lundell) Borhidi"
1795
              + " in Acta Bot. Hung. 33 (3" + UTF8.EN_DASH + "4): 303. 1987");
1796
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1797
        combinationAuthor = name.getCombinationAuthorship();
1798
        assertEquals( "Borhidi", combinationAuthor.getNomenclaturalTitle());
1799
        nomRef = (Reference)name.getNomenclaturalReference();
1800
        assertEquals(ReferenceType.Article, nomRef.getType());
1801
        assertEquals("33 (3" + UTF8.EN_DASH + "4)", nomRef.getVolume());
1802
        assertEquals("303", name.getNomenclaturalMicroReference());
1803

    
1804
        //fig with f.
1805
        name = parser.parseReferencedName("Stenotis Terrell"
1806
                + " in Sida 19(4): 901" + UTF8.EN_DASH + "911, f. 1" + UTF8.EN_DASH + "2. 2001");
1807
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1808
        combinationAuthor = name.getCombinationAuthorship();
1809
        assertEquals( "Terrell", combinationAuthor.getNomenclaturalTitle());
1810
        nomRef = (Reference)name.getNomenclaturalReference();
1811
        assertEquals(ReferenceType.Article, nomRef.getType());
1812
        assertEquals("19(4)", nomRef.getVolume());
1813
        assertEquals("901" + UTF8.EN_DASH + "911, f. 1" + UTF8.EN_DASH + "2", name.getNomenclaturalMicroReference());
1814

    
1815
        //detail with figs
1816
        name = parser.parseReferencedName("Randia sonorensis Wiggins"
1817
                + " in Contr. Dudley Herb. 3: 75, figs 4-6. 1940");
1818
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1819
        combinationAuthor = name.getCombinationAuthorship();
1820
        assertEquals( "Wiggins", combinationAuthor.getNomenclaturalTitle());
1821
        nomRef = (Reference)name.getNomenclaturalReference();
1822
        assertEquals(ReferenceType.Article, nomRef.getType());
1823
        assertEquals("3", nomRef.getVolume());
1824
        assertEquals("75, figs 4-6", name.getNomenclaturalMicroReference());
1825

    
1826
        //detail with pl. and figs
1827
        name = parser.parseReferencedName("Randia sonorensis Wiggins"
1828
                + " in Contr. Dudley Herb. 3: 75, pl. 19, figs 4-6. 1940");
1829
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1830
        combinationAuthor = name.getCombinationAuthorship();
1831
        assertEquals( "Wiggins", combinationAuthor.getNomenclaturalTitle());
1832
        nomRef = (Reference)name.getNomenclaturalReference();
1833
        assertEquals(ReferenceType.Article, nomRef.getType());
1834
        assertEquals("3", nomRef.getVolume());
1835
        assertEquals("75, pl. 19, figs 4-6", name.getNomenclaturalMicroReference());
1836

    
1837

    
1838
        //pl
1839
        name = parser.parseReferencedName("Carapichea  Aubl."
1840
                + " in Hist. Pl. Guiane 1: 167, pl. 64. 1775");
1841
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1842
        combinationAuthor = name.getCombinationAuthorship();
1843
        assertEquals( "Aubl.", combinationAuthor.getNomenclaturalTitle());
1844
        nomRef = (Reference)name.getNomenclaturalReference();
1845
        assertEquals(ReferenceType.Article, nomRef.getType());
1846
        assertEquals("1", nomRef.getVolume());
1847
        assertEquals("167, pl. 64", name.getNomenclaturalMicroReference());
1848

    
1849
        //fig with ,
1850
        name = parser.parseReferencedName("Hoffmannia ixtlanensis Lorence"
1851
                + " in Novon 4: 121. fig. 2a, b. 1994");
1852
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1853
        combinationAuthor = name.getCombinationAuthorship();
1854
        assertEquals( "Lorence", combinationAuthor.getNomenclaturalTitle());
1855
        nomRef = (Reference)name.getNomenclaturalReference();
1856
        assertEquals(ReferenceType.Article, nomRef.getType());
1857
        assertEquals("4", nomRef.getVolume());
1858
        assertEquals("121. fig. 2a, b", name.getNomenclaturalMicroReference());
1859

    
1860
        //detail with , to number
1861
        name = parser.parseReferencedName("Deppea martinez-calderonii Lorence"
1862
                + " in Allertonia 4: 399. figs 1e, 2. 1988");
1863
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1864
        combinationAuthor = name.getCombinationAuthorship();
1865
        assertEquals( "Lorence", combinationAuthor.getNomenclaturalTitle());
1866
        nomRef = (Reference)name.getNomenclaturalReference();
1867
        assertEquals(ReferenceType.Article, nomRef.getType());
1868
        assertEquals("4", nomRef.getVolume());
1869
        assertEquals("399. figs 1e, 2", name.getNomenclaturalMicroReference());
1870

    
1871
        //(Suppl.)
1872
        name = parser.parseReferencedName("Manettia costaricensis  Wernham"
1873
                + " in J. Bot. 57(Suppl.): 38. 1919");
1874
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1875
        combinationAuthor = name.getCombinationAuthorship();
1876
        assertEquals( "Wernham", combinationAuthor.getNomenclaturalTitle());
1877
        nomRef = (Reference)name.getNomenclaturalReference();
1878
        assertEquals(ReferenceType.Article, nomRef.getType());
1879
        assertEquals("57(Suppl.)", nomRef.getVolume());
1880
        assertEquals("38", name.getNomenclaturalMicroReference());
1881

    
1882
        //NY.
1883
        name = parser.parseReferencedName("Crusea psyllioides (Kunth) W.R. Anderson"
1884
                + " in Mem. NY. Bot. Gard. 22: 75. 1972");
1885
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1886
        combinationAuthor = name.getCombinationAuthorship();
1887
        assertEquals( "W.R. Anderson", combinationAuthor.getNomenclaturalTitle());
1888
        nomRef = (Reference)name.getNomenclaturalReference();
1889
        assertEquals(ReferenceType.Article, nomRef.getType());
1890
        assertEquals("22", nomRef.getVolume());
1891
        assertEquals("75", name.getNomenclaturalMicroReference());
1892

    
1893
        //apostroph word in title
1894
        name = parser.parseReferencedName("Sabicea glabrescens Benth."
1895
                + " in Hooker's J. Bot. Kew Gard. Misc. 3: 219. 1841");
1896
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1897
        combinationAuthor = name.getCombinationAuthorship();
1898
        assertEquals( "Benth.", combinationAuthor.getNomenclaturalTitle());
1899
        nomRef = (Reference)name.getNomenclaturalReference();
1900
        assertEquals(ReferenceType.Article, nomRef.getType());
1901
        assertEquals("3", nomRef.getVolume());
1902
        assertEquals("219", name.getNomenclaturalMicroReference());
1903

    
1904
        // place published e.g. (Hannover)
1905
        name = parser.parseReferencedName("Pittoniotis trichantha Griseb."
1906
                  + " in Bonplandia (Hannover) 6 (1): 8. 1858");
1907
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1908
        combinationAuthor = name.getCombinationAuthorship();
1909
        assertEquals( "Griseb.", combinationAuthor.getNomenclaturalTitle());
1910
        nomRef = (Reference)name.getNomenclaturalReference();
1911
        assertEquals(ReferenceType.Article, nomRef.getType());
1912
        assertEquals("6 (1)", nomRef.getVolume());
1913
        assertEquals("8", name.getNomenclaturalMicroReference());
1914

    
1915
        //komplex / incorrect year without quotation marks
1916
        name = parser.parseReferencedName("Javorkaea Borhidi & Jarai-Koml."
1917
                + " in Acta Bot. Hung. 29(1\u20134): 16, f. 1\u20132, t. 1-8. 1983 [1984]");
1918
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1919
        combinationAuthor = name.getCombinationAuthorship();
1920
        assertEquals( "Borhidi & Jarai-Koml.", combinationAuthor.getNomenclaturalTitle());
1921
        nomRef = (Reference)name.getNomenclaturalReference();
1922
        assertEquals(ReferenceType.Article, nomRef.getType());
1923
        assertEquals("29(1\u20134)", nomRef.getVolume());
1924
        assertEquals("16, f. 1\u20132, t. 1-8", name.getNomenclaturalMicroReference());
1925
        assertEquals("1983 [1984]", nomRef.getDatePublishedString());
1926
        assertEquals("1984", nomRef.getYear());
1927

    
1928
        //incorrect year with \u201e \u201f  (s. eu.etaxonomy.cdm.common.UTF8.ENGLISH_QUOT_START
1929
        name = parser.parseReferencedName("Javorkaea Borhidi & Jarai-Koml."
1930
                + " in Acta Bot. Hung. 29(1-4): 16, f. 1-2. \u201e1983\u201f [1984]");
1931
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1932
        combinationAuthor = name.getCombinationAuthorship();
1933
        assertEquals( "Borhidi & Jarai-Koml.", combinationAuthor.getNomenclaturalTitle());
1934
        nomRef = (Reference)name.getNomenclaturalReference();
1935
        assertEquals(ReferenceType.Article, nomRef.getType());
1936
        assertEquals("29(1-4)", nomRef.getVolume());
1937
        assertEquals("16, f. 1-2", name.getNomenclaturalMicroReference());
1938
        assertEquals("\u201e1983\u201f [1984]", nomRef.getDatePublishedString());
1939
        assertEquals("1984", nomRef.getYear());
1940

    
1941
        //incorrect year with "
1942
        name = parser.parseReferencedName("Javorkaea Borhidi & Jarai-Koml."
1943
                + " in Acta Bot. Hung. 29(1-4): 16, f. 1-2. \"1983\" [1984]");
1944
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1945
        combinationAuthor = name.getCombinationAuthorship();
1946
        assertEquals( "Borhidi & Jarai-Koml.", combinationAuthor.getNomenclaturalTitle());
1947
        nomRef = (Reference)name.getNomenclaturalReference();
1948
        assertEquals(ReferenceType.Article, nomRef.getType());
1949
        assertEquals("29(1-4)", nomRef.getVolume());
1950
        assertEquals("16, f. 1-2", name.getNomenclaturalMicroReference());
1951
        assertEquals("\"1983\" [1984]", nomRef.getDatePublishedString());
1952
        assertEquals("1984", nomRef.getYear());
1953

    
1954
        //fig. a
1955
        name = parser.parseReferencedName("Psychotria capitata  Ruiz & Pav."
1956
                + " in Fl. Peruv. 2: 59, pl. 206, fig. a. 1799");
1957
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1958
        combinationAuthor = name.getCombinationAuthorship();
1959
        assertEquals( "Ruiz & Pav.", combinationAuthor.getNomenclaturalTitle());
1960
        nomRef = (Reference)name.getNomenclaturalReference();
1961
        assertEquals(ReferenceType.Article, nomRef.getType());
1962
        assertEquals("2", nomRef.getVolume());
1963
        assertEquals("59, pl. 206, fig. a", name.getNomenclaturalMicroReference());
1964

    
1965
        //442A.
1966
        name = parser.parseReferencedName("Rogiera elegans Planch."
1967
                + " in Fl. Serres Jard. Eur. 5: 442A. 1849");
1968
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1969
        combinationAuthor = name.getCombinationAuthorship();
1970
        assertEquals( "Planch.", combinationAuthor.getNomenclaturalTitle());
1971
        nomRef = (Reference)name.getNomenclaturalReference();
1972
        assertEquals(ReferenceType.Article, nomRef.getType());
1973
        assertEquals("5", nomRef.getVolume());
1974
        assertEquals("442A", name.getNomenclaturalMicroReference());
1975

    
1976
        //f
1977
        name = parser.parseReferencedName("Coussarea imitans L.O. Williams"
1978
                + " in Phytologia 26 (6): 488-489, f. 1973");
1979
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1980
        combinationAuthor = name.getCombinationAuthorship();
1981
        assertEquals( "L.O. Williams", combinationAuthor.getNomenclaturalTitle());
1982
        nomRef = (Reference)name.getNomenclaturalReference();
1983
        assertEquals(ReferenceType.Article, nomRef.getType());
1984
        assertEquals("26 (6)", nomRef.getVolume());
1985
        assertEquals("488-489, f", name.getNomenclaturalMicroReference());
1986

    
1987
        //Phys.-Med.
1988
        name = parser.parseReferencedName("Coccocypselum cordifolium Nees & Mart."
1989
                + " in Nova Acta Phys.-Med. Acad. Caes.\u2013Leop. Nat. Cur. 12: 14. 1824");
1990
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1991
        combinationAuthor = name.getCombinationAuthorship();
1992
        assertEquals( "Nees & Mart.", combinationAuthor.getNomenclaturalTitle());
1993
        nomRef = (Reference)name.getNomenclaturalReference();
1994
        assertEquals(ReferenceType.Article, nomRef.getType());
1995
        assertEquals("Nova Acta Phys.-Med. Acad. Caes.\u2013Leop. Nat. Cur.", nomRef.getInReference().getAbbrevTitle());
1996
        assertEquals("12", nomRef.getVolume());
1997
        assertEquals("14", name.getNomenclaturalMicroReference());
1998
        assertEquals("1824", nomRef.getYear());
1999

    
2000
        //(ed. 10)  wanted?
2001
//        Syst. Nat. (ed. 10) 2: 930. 1759
2002
//        name = parser.parseReferencedName("Erithalis fruticosa L."
2003
//                + ", Syst. Nat. ed. 10, 2: 930. 1759");
2004
//        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2005
//        combinationAuthor = name.getCombinationAuthorship();
2006
//        assertEquals( "L.", combinationAuthor.getNomenclaturalTitle());
2007
//        nomRef = (Reference)name.getNomenclaturalReference();
2008
//        assertEquals(ReferenceType.Book, nomRef.getType());
2009
//        assertEquals("2", nomRef.getVolume());
2010
//        assertEquals("10", nomRef.getEdition());
2011
//        assertEquals("930", name.getNomenclaturalMicroReference());
2012
//        assertEquals("1759", nomRef.getYear());
2013

    
2014
        //issue with letter "(1a)"
2015
        name = parser.parseReferencedName("Arthraerua (Kuntze) Schinz,"
2016
                + " Nat. Pflanzenfam. 3(1a): 109. 1893");
2017
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2018
        combinationAuthor = name.getCombinationAuthorship();
2019
        assertEquals( "Schinz", combinationAuthor.getNomenclaturalTitle());
2020
        nomRef = (Reference)name.getNomenclaturalReference();
2021
        Assert.assertFalse("Reference should be parsable", nomRef.isProtectedTitleCache());
2022
        assertEquals(ReferenceType.Book, nomRef.getType());
2023
        assertEquals("Nat. Pflanzenfam.", nomRef.getAbbrevTitle());
2024
        assertEquals("3(1a)", nomRef.getVolume());
2025
        assertEquals("109", name.getNomenclaturalMicroReference());
2026
        assertEquals("1893", nomRef.getYear());
2027

    
2028
        //Accent graph in author name #6057
2029
        name = parser.parseReferencedName("Sedum plicatum O`Brian");
2030
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2031
        assertEquals( "O`Brian", name.getCombinationAuthorship().getNomenclaturalTitle());
2032

    
2033
        //-e-  #6060
2034
        name = parser.parseReferencedName("Thamniopsis stenodictyon (Sehnem) Oliveira-e-Silva & O.Yano");
2035
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
2036
        Team team = (Team)name.getCombinationAuthorship();
2037
        assertEquals( "Oliveira-e-Silva", team.getTeamMembers().get(0).getNomenclaturalTitle());
2038

    
2039
 }
2040

    
2041
}
(2-2/4)