Project

General

Profile

Download (87.3 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.IVolumeReference;
52
import eu.etaxonomy.cdm.model.reference.Reference;
53
import eu.etaxonomy.cdm.model.reference.ReferenceType;
54
import eu.etaxonomy.cdm.strategy.exceptions.StringNotParsableException;
55
/**
56
 * @author a.mueller
57
 *
58
 */
59
public class NonViralNameParserImplTest {
60
	private static final NomenclaturalCode ICNAFP = NomenclaturalCode.ICNAFP;
61
	private static final NomenclaturalCode ICZN = NomenclaturalCode.ICZN;
62

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

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

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

    
86
	private NonViralNameParserImpl parser ;
87
	private NomenclaturalCode botanicCode;
88

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

    
98

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

    
108

    
109
/*************** TEST *********************************************/
110

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

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

    
127
	@Test
128
	public final void testTeamSeperation(){
129
		Rank speciesRank = Rank.SPECIES();
130
		NonViralName<?> name;
131

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

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

    
153
	}
154

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

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

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

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

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

    
189
	}
190

    
191
	/**
192
	 * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#parseSubGenericFullName(java.lang.String)}.
193
	 */
194
	@Test
195
	public final void testParseSubGenericFullName() {
196
		logger.warn("Not yet implemented"); // TODO
197
	}
198

    
199
	/**
200
	 * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#parseSubGenericSimpleName(java.lang.String)}.
201
	 */
202
	@Test
203
	public final void testParseSubGenericSimpleName() {
204
		logger.warn("Not yet implemented"); // TODO
205
	}
206

    
207
	/**
208
	 * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#parseFullName(java.lang.String, eu.etaxonomy.cdm.model.name.Rank)}.
209
	 */
210
	@Test
211
	public final void testParseFullNameUnicode() {
212

    
213
		NonViralName<?> nameAuthor = parser.parseFullName(strNameAbiesAuthor1Unicode, null, Rank.SPECIES());
214
		assertEquals("Abies", nameAuthor.getGenusOrUninomial());
215
		assertEquals("alba", nameAuthor.getSpecificEpithet());
216
		assertEquals("M\u00FCller", nameAuthor.getCombinationAuthorship().getNomenclaturalTitle());
217

    
218
		NonViralName<?> nameBasionymAuthor = parser.parseFullName(strNameAbiesBasionymAuthor1Unicode, null, Rank.SPECIES());
219
		assertEquals("Abies", nameBasionymAuthor.getGenusOrUninomial());
220
		assertEquals("alba", nameBasionymAuthor.getSpecificEpithet());
221
		assertEquals("D'M\u00FCller", nameBasionymAuthor.getCombinationAuthorship().getNomenclaturalTitle());
222
		INomenclaturalAuthor basionymTeam = nameBasionymAuthor.getBasionymAuthorship();
223
		assertEquals("Ciardelli", basionymTeam.getNomenclaturalTitle());
224

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

    
235
		BotanicalName nameBasionymExAuthor2 = (BotanicalName)parser.parseFullName("Washingtonia filifera (Linden ex Andre) H.Wendl. ex de Bary", null, Rank.SPECIES());
236
		assertEquals("Washingtonia", nameBasionymExAuthor2.getGenusOrUninomial());
237
		assertEquals("filifera", nameBasionymExAuthor2.getSpecificEpithet());
238
		assertEquals("H.Wendl.", nameBasionymExAuthor2.getExCombinationAuthorship().getNomenclaturalTitle());
239
		assertEquals("de Bary", nameBasionymExAuthor2.getCombinationAuthorship().getNomenclaturalTitle());
240
		INomenclaturalAuthor basionymTeam3 = nameBasionymExAuthor2.getBasionymAuthorship();
241
		assertEquals("Andre", basionymTeam3.getNomenclaturalTitle());
242
		INomenclaturalAuthor exBasionymTeam3 = nameBasionymExAuthor2.getExBasionymAuthorship();
243
		assertEquals("Linden", exBasionymTeam3.getNomenclaturalTitle());
244
		String title = nameBasionymExAuthor2.getTitleCache();
245
		assertEquals("Washingtonia filifera (Linden ex Andre) H.Wendl. ex de Bary", title);
246

    
247
	}
248

    
249

    
250
	/**
251
	 * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#parseFullName(java.lang.String, eu.etaxonomy.cdm.model.name.Rank)}.
252
	 */
253
	@Test
254
	public final void testParseFullName() {
255
		try {
256
			Method parseMethod = parser.getClass().getDeclaredMethod("parseFullName", String.class, NomenclaturalCode.class, Rank.class);
257
			testName_StringNomcodeRank(parseMethod);
258
		} catch (Exception e) {
259
			e.printStackTrace();
260
			assertTrue(false);
261
		}
262

    
263
		//Team
264
		NonViralName<?> nameTeam1 = parser.parseFullName(strNameTeam1);
265
		assertEquals( "Abies", nameTeam1.getGenusOrUninomial());
266
		assertEquals( "alba", nameTeam1.getSpecificEpithet());
267
		assertEquals("Mueller & L.",  nameTeam1.getCombinationAuthorship().getNomenclaturalTitle());
268
		assertTrue(nameTeam1.getCombinationAuthorship() instanceof Team);
269
		Team team = (Team)nameTeam1.getCombinationAuthorship();
270
		assertEquals("Mueller", team.getTeamMembers().get(0).getNomenclaturalTitle());
271
		assertEquals("L.", team.getTeamMembers().get(1).getNomenclaturalTitle());
272

    
273
		//ZooName
274
		ZoologicalName nameZoo1 = (ZoologicalName)parser.parseFullName(strNameZoo1);
275
		assertEquals( "Abies", nameZoo1.getGenusOrUninomial());
276
		assertEquals( "alba", nameZoo1.getSpecificEpithet());
277
		assertEquals("Mueller & L.",  nameZoo1.getCombinationAuthorship().getNomenclaturalTitle());
278
		assertEquals(NomenclaturalCode.ICZN, nameZoo1.getNomenclaturalCode() );
279
		assertEquals(Integer.valueOf(1822), nameZoo1.getPublicationYear());
280
		assertTrue(nameZoo1.getCombinationAuthorship() instanceof Team);
281
		Team teamZoo = (Team)nameZoo1.getCombinationAuthorship();
282
		assertEquals("Mueller", teamZoo.getTeamMembers().get(0).getNomenclaturalTitle());
283
		assertEquals("L.", teamZoo.getTeamMembers().get(1).getNomenclaturalTitle());
284

    
285
		ZoologicalName nameZoo2 = (ZoologicalName)parser.parseFullName(strNameZoo2);
286
		assertEquals(Integer.valueOf(2002), nameZoo2.getPublicationYear());
287
		assertEquals(Integer.valueOf(1822), nameZoo2.getOriginalPublicationYear());
288
		assertEquals("Mueller",  nameZoo2.getBasionymAuthorship().getNomenclaturalTitle());
289
		assertEquals("Ciardelli",  nameZoo2.getCombinationAuthorship().getNomenclaturalTitle());
290

    
291
		//subsp
292
		ZoologicalName nameZoo3 = (ZoologicalName)parser.parseFullName(strNameZoo3);
293
		assertEquals("Ciardelli",  nameZoo3.getCombinationAuthorship().getNomenclaturalTitle());
294
		assertFalse("Subsp. without marker should be parsable", nameZoo3.hasProblem());
295
		assertEquals("Variety should be recognized", Rank.SUBSPECIES(), nameZoo3.getRank());
296

    
297
		ZoologicalName nameZoo4 = (ZoologicalName)parser.parseFullName(strNameZoo4);
298
		assertEquals("Ciardelli",  nameZoo4.getCombinationAuthorship().getNomenclaturalTitle());
299
		assertFalse("Subsp. without marker should be parsable", nameZoo4.hasProblem());
300
		assertEquals("Variety should be recognized", Rank.SUBSPECIES(), nameZoo4.getRank());
301

    
302
		ZoologicalName nameZoo5 = (ZoologicalName)parser.parseFullName(strNameZoo5);
303
		assertEquals("Ciardelli",  nameZoo5.getCombinationAuthorship().getNomenclaturalTitle());
304
		assertFalse("Subsp. without marker should be parsable", nameZoo5.hasProblem());
305
		assertEquals("Variety should be recognized", Rank.VARIETY(), nameZoo5.getRank());
306

    
307

    
308
		//Autonym
309
		BotanicalName autonymName = (BotanicalName)parser.parseFullName("Abies alba Mill. var. alba", ICNAFP, null);
310
		assertFalse("Autonym should be parsable", autonymName.hasProblem());
311

    
312

    
313
		//empty
314
		NonViralName<?> nameEmpty = parser.parseFullName(strNameEmpty);
315
		assertNotNull(nameEmpty);
316
		assertEquals("", nameEmpty.getTitleCache());
317

    
318
		//null
319
		NonViralName<?> nameNull = parser.parseFullName(strNameNull);
320
		assertNull(nameNull);
321

    
322
		//some authors
323
		String fullNameString = "Abies alba (Greuther & L'Hiver & al. ex M\u00FCller & Schmidt)Clark ex Ciardelli";
324
		NonViralName<?> authorname = parser.parseFullName(fullNameString);
325
		assertFalse(authorname.hasProblem());
326
		assertEquals("Basionym author should have 3 authors", 2, ((Team)authorname.getExBasionymAuthorship()).getTeamMembers().size());
327
        Assert.assertTrue("ExbasionymAuthorship must have more members'", ((Team)authorname.getExBasionymAuthorship()).isHasMoreMembers());
328

    
329
        //author with 2 capitals
330
        fullNameString = "Campanula rhodensis A. DC.";
331
        NonViralName<?> name = parser.parseFullName(fullNameString);
332
        assertFalse(name.hasProblem());
333

    
334
        //author with no space  #5618
335
        fullNameString = "Gordonia moaensis (Vict.)H. Keng";
336
        name = parser.parseFullName(fullNameString);
337
        assertFalse(name.hasProblem());
338
        assertNotNull(name.getCombinationAuthorship());
339
        assertEquals("H. Keng", name.getCombinationAuthorship().getNomenclaturalTitle());
340

    
341
        //name without combination  author  , only to check if above fix for #5618 works correctly
342
        fullNameString = "Gordonia moaensis (Vict.)";
343
        name = parser.parseFullName(fullNameString);
344
        assertFalse(name.hasProblem());
345
        assertNull(name.getCombinationAuthorship());
346
        assertNotNull(name.getBasionymAuthorship());
347
        assertEquals("Vict.", name.getBasionymAuthorship().getNomenclaturalTitle());
348

    
349
	}
350

    
351
	@Test
352
    public final void testEtAl() throws StringNotParsableException {
353
        //some authors
354
        String fullNameString = "Abies alba Greuther, Hiver & al.";
355
        NonViralName<?> authorname = parser.parseFullName(fullNameString);
356
        assertFalse(authorname.hasProblem());
357
        assertEquals("Basionym author should have 2 authors", 2, ((Team)authorname.getCombinationAuthorship()).getTeamMembers().size());
358
        assertTrue("Basionym author team should have more authors", ((Team)authorname.getCombinationAuthorship()).isHasMoreMembers()  );
359

    
360
		//et al.
361
		NonViralName<?> nvn = ZoologicalName.NewInstance(null);
362
		parser.parseAuthors(nvn, "Eckweiler, Hand et al., 2003");
363
	    Team team = (Team)nvn.getCombinationAuthorship();
364
	    Assert.assertNotNull("Comb. author must not be null", team);
365
	    Assert.assertEquals("Must be team with 2 members", 2, team.getTeamMembers().size());
366
	    Assert.assertEquals("Second member must be 'Hand'", "Hand", team.getTeamMembers().get(1).getTitleCache());
367
	    Assert.assertTrue("Team must have more members'", team.isHasMoreMembers());
368
	}
369

    
370
	@Test
371
    public final void testMultipleAuthors() {
372
        //multiple authors for inReference
373
        String fullTitleString = "Abies alba L. in Mill., Gregor & Behr., Sp. Pl. 173: 384. 1982.";
374
        NonViralName<?> multipleAuthorRefName = parser.parseReferencedName(fullTitleString, NomenclaturalCode.ICNAFP, Rank.SPECIES());
375
        assertFalse(multipleAuthorRefName.hasProblem());
376
        assertTrue("Combination author should be a person", multipleAuthorRefName.getCombinationAuthorship() instanceof Person);
377
        assertEquals("Combination author should be L.", "L.", ((Person)multipleAuthorRefName.getCombinationAuthorship()).getNomenclaturalTitle());
378
        INomenclaturalReference nomRef = multipleAuthorRefName.getNomenclaturalReference();
379
        Assert.assertNotNull("nomRef must have inRef", ((Reference<?>)nomRef).getInReference());
380
        Reference<?> inRef = ((Reference<?>)nomRef).getInReference();
381
        String title = inRef.getTitle();
382
        assertEquals("InRef title should be Sp. Pl.", "Sp. Pl.", title);
383
        assertTrue(inRef.getAuthorship() instanceof Team);
384
        Team team = (Team)inRef.getAuthorship();
385
        assertEquals(3, team.getTeamMembers().size());
386

    
387
//        multiple authors in Name
388
        fullTitleString = "Abies alba Mill., Aber & Schwedt";
389
        NonViralName<?> multipleAuthorName = parser.parseReferencedName(fullTitleString, NomenclaturalCode.ICNAFP, Rank.SPECIES());
390
        assertFalse(multipleAuthorName.hasProblem());
391
        assertTrue("Combination author should be a team", multipleAuthorName.getCombinationAuthorship() instanceof Team);
392
        team = (Team)multipleAuthorName.getCombinationAuthorship();
393
        assertEquals(3, team.getTeamMembers().size());
394
        assertEquals("Second team member should be Aber", "Aber", team.getTeamMembers().get(1).getTitleCache());
395

    
396
//      multiple authors in Name with reference
397
	    fullTitleString = "Abies alba Mill., Aber & Schwedt in L., Sp. Pl. 173: 384. 1982.";
398
	    multipleAuthorName = parser.parseReferencedName(fullTitleString, NomenclaturalCode.ICNAFP, Rank.SPECIES());
399
	    assertFalse(multipleAuthorName.hasProblem());
400
	    assertTrue("Combination author should be a team", multipleAuthorName.getCombinationAuthorship() instanceof Team);
401
	    team = (Team)multipleAuthorName.getCombinationAuthorship();
402
	    assertEquals(3, team.getTeamMembers().size());
403
	    assertEquals("Second team member should be Aber", "Aber", team.getTeamMembers().get(1).getTitleCache());
404
	    nomRef = multipleAuthorName.getNomenclaturalReference();
405
        Assert.assertNotNull("nomRef must have inRef", ((Reference<?>)nomRef).getInReference());
406
        inRef = ((Reference<?>)nomRef).getInReference();
407
        title = inRef.getTitle();
408
        assertEquals("InRef title should be Sp. Pl.", "Sp. Pl.", title);
409
        assertTrue(inRef.getAuthorship() instanceof Person);
410
        Person person = (Person)inRef.getAuthorship();
411
        assertEquals("Book author should be L.", "L.", person.getNomenclaturalTitle());
412

    
413

    
414
	    fullTitleString = "Abies alba Mill., Aber & Schwedt, Sp. Pl. 173: 384. 1982.";
415
	    multipleAuthorName = parser.parseReferencedName(fullTitleString, NomenclaturalCode.ICNAFP, Rank.SPECIES());
416
	    assertFalse(multipleAuthorName.hasProblem());
417
	    assertTrue("Combination author should be a team", multipleAuthorName.getCombinationAuthorship() instanceof Team);
418
	    team = (Team)multipleAuthorName.getCombinationAuthorship();
419
	    assertEquals(3, team.getTeamMembers().size());
420
	    assertEquals("Second team member should be Aber", "Aber", team.getTeamMembers().get(1).getTitleCache());
421
	    nomRef = multipleAuthorName.getNomenclaturalReference();
422
        Assert.assertNull("nomRef must not have inRef as it is a book itself", ((Reference<?>)nomRef).getInReference());
423
        title = nomRef.getTitle();
424
        assertEquals("InRef title should be Sp. Pl.", "Sp. Pl.", title);
425
        assertTrue(nomRef.getAuthorship() instanceof Team);
426
        team = (Team)nomRef.getAuthorship();
427
        assertEquals(3, team.getTeamMembers().size());
428
        assertEquals("Second team member should be Schwedt", "Schwedt", team.getTeamMembers().get(2).getTitleCache());
429

    
430
		//et al.
431
		NonViralName<?> nvn = ZoologicalName.NewInstance(null);
432
		parser.parseReferencedName (nvn, "Marmota marmota Eckweiler, Hand et al., 2003", Rank.SPECIES(),true);
433
		assertTrue("Combination author should be a team", nvn.getCombinationAuthorship() instanceof Team);
434
        team = (Team)nvn.getCombinationAuthorship();
435
	    Assert.assertNotNull("Comb. author must not be null", team);
436
	    Assert.assertEquals("Must be team with 2 members", 2, team.getTeamMembers().size());
437
	    Assert.assertEquals("Second member must be 'Hand'", "Hand", team.getTeamMembers().get(1).getTitleCache());
438
	    Assert.assertTrue("Team must have more members'", team.isHasMoreMembers());
439

    
440
	}
441

    
442
	/**
443
	 * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#parseFullName(java.lang.String, eu.etaxonomy.cdm.model.name.Rank)}.
444
	 */
445
	@Test
446
	public final void testHybrids() {
447
		NonViralName<?> name1;
448

    
449

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

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

    
465
		//Uninomial hybrid
466
		name1 = parser.parseFullName("x Aegilops Scholz", botanicCode, null);
467
		assertTrue("Name must have monom hybrid bit set", name1.isMonomHybrid());
468
		assertFalse("Name must not have binom hybrid bit set", name1.isBinomHybrid());
469
		assertFalse("Name must not have trinom hybrid bit set", name1.isTrinomHybrid());
470
		assertEquals("Uninomial must be 'Aegilops'", "Aegilops", name1.getGenusOrUninomial());
471

    
472
		//Subspecies hybrid with hybrid sign
473
		//maybe false: see http://dev.e-taxonomy.eu/trac/ticket/3868
474
		name1 = parser.parseFullName("Aegilops insulae subsp. X abies Scholz", botanicCode, null);
475
		assertFalse("Name must not have monom hybrid bit set", name1.isMonomHybrid());
476
		assertFalse("Name must not have binom hybrid bit set", name1.isBinomHybrid());
477
		assertTrue("Name must have trinom hybrid bit set", name1.isTrinomHybrid());
478
		assertEquals("Infraspecific epithet must be 'abies'", "abies", name1.getInfraSpecificEpithet());
479

    
480
        //Subspecies hybrid with notho / n
481
        name1 = parser.parseFullName("Aegilops insulae nothosubsp. abies Scholz", botanicCode, null);
482
        assertFalse("Name must not have monom hybrid bit set", name1.isMonomHybrid());
483
        assertFalse("Name must not have binom hybrid bit set", name1.isBinomHybrid());
484
        assertFalse("Name must not be protected", name1.isProtectedTitleCache());
485
        assertTrue("Name must have trinom hybrid bit set", name1.isTrinomHybrid());
486
        assertEquals("Infraspecific epithet must be 'abies'", "abies", name1.getInfraSpecificEpithet());
487
        name1 = parser.parseFullName("Aegilops insulae nsubsp. abies Scholz", botanicCode, null);
488
        assertFalse("Name must not have monom hybrid bit set", name1.isMonomHybrid());
489
        assertFalse("Name must not have binom hybrid bit set", name1.isBinomHybrid());
490
        assertFalse("Name must not be protected", name1.isProtectedTitleCache());
491
        assertTrue("Name must have trinom hybrid bit set", name1.isTrinomHybrid());
492
        assertEquals("Infraspecific epithet must be 'abies'", "abies", name1.getInfraSpecificEpithet());
493

    
494
	}
495

    
496
	/**
497
	 * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#parseFullName(java.lang.String, eu.etaxonomy.cdm.model.name.Rank)}.
498
	 */
499
	@Test
500
	public final void testUnrankedNames() {
501
		try {
502
			Method parseMethod = parser.getClass().getDeclaredMethod("parseFullName", String.class, NomenclaturalCode.class, Rank.class);
503
			testName_StringNomcodeRank(parseMethod);
504
		} catch (Exception e) {
505
			e.printStackTrace();
506
			assertTrue(false);
507
		}
508

    
509
		//unranked infraspecific
510
		String infraspecificUnranked = "Genus species [unranked] infraspecific";
511
		NonViralName<?> name = parser.parseFullName(infraspecificUnranked);
512
		assertEquals( "Genus", name.getGenusOrUninomial());
513
		assertEquals( "species", name.getSpecificEpithet());
514
		assertEquals( "infraspecific", name.getInfraSpecificEpithet());
515
		assertEquals( "Unranked rank should be parsed", Rank.INFRASPECIFICTAXON(), name.getRank());
516

    
517
		//unranked infrageneric
518
		String infraGenericUnranked = "Genus [unranked] Infragen";
519
		NonViralName<?> name2 = parser.parseFullName(infraGenericUnranked);
520
		assertEquals( "Genus", name2.getGenusOrUninomial());
521
		assertEquals( null, name2.getSpecificEpithet());
522
		assertEquals( "Infragen", name2.getInfraGenericEpithet());
523
		assertEquals( "Unranked rank should be parsed", Rank.INFRAGENERICTAXON(), name2.getRank());
524

    
525
	}
526

    
527

    
528
	/**
529
	 * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#parseFullName(java.lang.String, eu.etaxonomy.cdm.model.name.Rank)}.
530
	 */
531
	@Test
532
	public final void testHybridFormulars() {
533
		try {
534
			Method parseMethod = parser.getClass().getDeclaredMethod("parseFullName", String.class, NomenclaturalCode.class, Rank.class);
535
			testName_StringNomcodeRank(parseMethod);
536
		} catch (Exception e) {
537
			e.printStackTrace();
538
			assertTrue(false);
539
		}
540

    
541
		//Species hybrid
542
		String hybridCache = "Abies alba "+UTF8.HYBRID+" Pinus bus";
543
		NonViralName<?> name1 = parser.parseFullName(hybridCache, botanicCode, null);
544
		assertTrue("Name must have hybrid formula bit set", name1.isHybridFormula());
545
		assertEquals("Name must have 2 hybrid parents", 2, name1.getHybridChildRelations().size());
546
		assertEquals("Title cache must be correct", hybridCache, name1.getTitleCache());
547
		List<HybridRelationship> orderedRels = name1.getOrderedChildRelationships();
548
		assertEquals("Name must have 2 hybrid parents in ordered list", 2, orderedRels.size());
549
		NonViralName<?> firstParent = orderedRels.get(0).getParentName();
550
		assertEquals("Name must have Abies alba as first hybrid parent", "Abies alba", firstParent.getTitleCache());
551
		NonViralName<?> secondParent = orderedRels.get(1).getParentName();
552
		assertEquals("Name must have Pinus bus as second hybrid parent", "Pinus bus", secondParent.getTitleCache());
553
		assertEquals("Hybrid name must have the lowest rank ('species') as rank", Rank.SPECIES(), name1.getRank());
554
		assertNull("Name must not have a genus eptithet", name1.getGenusOrUninomial());
555
		assertNull("Name must not have a specific eptithet", name1.getSpecificEpithet());
556
		assertFalse("Name must not have parsing problems", name1.hasProblem());
557

    
558
		name1 = parser.parseReferencedName(hybridCache, botanicCode, null);
559
		assertFalse("Name must not have parsing problems", name1.hasProblem());
560

    
561
		//x-sign
562
		hybridCache = "Abies alba x Pinus bus";
563
		name1 = parser.parseFullName(hybridCache, botanicCode, null);
564
		assertFalse("Name must be parsable", name1.hasProblem());
565
		assertTrue("Name must have hybrid formula bit set", name1.isHybridFormula());
566
		assertFalse("Name must not have parsing problems", name1.hasProblem());
567

    
568

    
569
		//Subspecies first hybrid
570
		name1 = parser.parseFullName("Abies alba subsp. beta "+UTF8.HYBRID+" Pinus bus", botanicCode, null);
571
		assertTrue("Name must have hybrid formula bit set", name1.isHybridFormula());
572
		assertEquals("Name must have 2 hybrid parents", 2, name1.getHybridChildRelations().size());
573
		assertEquals("Title cache must be correct", "Abies alba subsp. beta "+UTF8.HYBRID+" Pinus bus", name1.getTitleCache());
574
		orderedRels = name1.getOrderedChildRelationships();
575
		assertEquals("Name must have 2 hybrid parents in ordered list", 2, orderedRels.size());
576
		firstParent = orderedRels.get(0).getParentName();
577
		assertEquals("Name must have Abies alba subsp. beta as first hybrid parent", "Abies alba subsp. beta", firstParent.getTitleCache());
578
		secondParent = orderedRels.get(1).getParentName();
579
		assertEquals("Name must have Pinus bus as second hybrid parent", "Pinus bus", secondParent.getTitleCache());
580
		assertEquals("Hybrid name must have the lower rank ('subspecies') as rank", Rank.SUBSPECIES(), name1.getRank());
581

    
582
		//variety second hybrid
583
		name1 = parser.parseFullName("Abies alba \u00D7 Pinus bus  var. beta", botanicCode, null);
584
		assertTrue("Name must have hybrid formula bit set", name1.isHybridFormula());
585
		assertEquals("Name must have 2 hybrid parents", 2, name1.getHybridChildRelations().size());
586
		assertEquals("Title cache must be correct", "Abies alba \u00D7 Pinus bus var. beta", name1.getTitleCache());
587
		assertEquals("Hybrid name must have the lower rank ('variety') as rank", Rank.VARIETY(), name1.getRank());
588

    
589
		//hybrids with authors
590
		name1 = parser.parseFullName("Abies alba L. \u00D7 Pinus bus Mill.", botanicCode, null);
591
		assertTrue("Name must have hybrid formula bit set", name1.isHybridFormula());
592
		assertEquals("Name must have 2 hybrid parents", 2, name1.getHybridChildRelations().size());
593
		assertEquals("Title cache must be correct", "Abies alba L. \u00D7 Pinus bus Mill.", name1.getTitleCache());
594
		orderedRels = name1.getOrderedChildRelationships();
595
		assertEquals("Name must have 2 hybrid parents in ordered list", 2, orderedRels.size());
596
		firstParent = orderedRels.get(0).getParentName();
597
		assertEquals("Name must have Abies alba L. as first hybrid parent", "Abies alba L.", firstParent.getTitleCache());
598
		secondParent = orderedRels.get(1).getParentName();
599
		assertEquals("Name must have Pinus bus Mill. as second hybrid parent", "Pinus bus Mill.", secondParent.getTitleCache());
600
		assertEquals("Hybrid name must have the lower rank ('species') as rank", Rank.SPECIES(), name1.getRank());
601

    
602
	}
603

    
604
	@Test
605
    public final void testHybridsRemoval(){
606
	    //if the parser input already has hybridrelationships they need to be removed
607
	    //Create input
608
        String hybridCache = "Abies alba "+UTF8.HYBRID+" Pinus bus";
609
        NonViralName<?> name1 = parser.parseFullName(hybridCache, botanicCode, null);
610
        assertFalse("Name must not have parsing problems", name1.hasProblem());
611
        assertTrue("", name1.getHybridChildRelations().size() == 2);
612

    
613
        hybridCache = "Abieta albana "+UTF8.HYBRID+" Pinuta custa";
614
        boolean makeEmpty = true;
615
        parser.parseFullName(name1, hybridCache, Rank.SPECIES(), makeEmpty);
616
        assertEquals("After parsing another string there should still be 2 parents, but different ones", 2, name1.getHybridChildRelations().size());
617
        assertFalse("Name must not have parsing problems", name1.hasProblem());
618

    
619

    
620
        hybridCache = "Calendula arvensis Mill.";
621
        makeEmpty = true;
622
        parser.parseFullName(name1, hybridCache, Rank.SPECIES(), makeEmpty);
623
        assertTrue("", name1.getHybridChildRelations().isEmpty());
624
        assertFalse("Name must not have parsing problems", name1.hasProblem());
625

    
626

    
627
        //AND the same for reference parsing
628
        hybridCache = "Abies alba "+UTF8.HYBRID+" Pinus bus";
629
        name1 = parser.parseReferencedName(hybridCache, botanicCode, null);
630
        assertFalse("Name must not have parsing problems", name1.hasProblem());
631
        assertTrue("", name1.getHybridChildRelations().size() == 2);
632

    
633
        hybridCache = "Abieta albana "+UTF8.HYBRID+" Pinuta custa";
634
        makeEmpty = true;
635
        parser.parseReferencedName(name1, hybridCache, Rank.SPECIES(), makeEmpty);
636
        assertEquals("After parsing another string there should still be 2 parents, but different ones", 2, name1.getHybridChildRelations().size());
637
        assertFalse("Name must not have parsing problems", name1.hasProblem());
638

    
639

    
640
        hybridCache = "Calendula arvensis Mill.";
641
        makeEmpty = true;
642
        parser.parseReferencedName(name1, hybridCache, Rank.SPECIES(), makeEmpty);
643
        assertTrue("", name1.getHybridChildRelations().isEmpty());
644
        assertFalse("Name must not have parsing problems", name1.hasProblem());
645
	}
646

    
647
	private void testName_StringNomcodeRank(Method parseMethod)
648
			throws InvocationTargetException, IllegalAccessException  {
649
		NonViralName<?> name1 = (NonViralName<?>)parseMethod.invoke(parser, strNameAbies1, null, Rank.SPECIES());
650
		//parser.parseFullName(strNameAbies1, null, Rank.SPECIES());
651
		assertEquals("Abies", name1.getGenusOrUninomial());
652
		assertEquals("alba", name1.getSpecificEpithet());
653

    
654
		NonViralName<?> nameAuthor = (NonViralName<?>)parseMethod.invoke(parser, strNameAbiesAuthor1, null, Rank.SPECIES());
655
		assertEquals("Abies", nameAuthor.getGenusOrUninomial());
656
		assertEquals("alba", nameAuthor.getSpecificEpithet());
657
		assertEquals("Mueller", nameAuthor.getCombinationAuthorship().getNomenclaturalTitle());
658

    
659
		NonViralName<?> nameBasionymAuthor = (NonViralName<?>)parseMethod.invoke(parser, strNameAbiesBasionymAuthor1, null, Rank.SPECIES());
660
		assertEquals("Abies", nameBasionymAuthor.getGenusOrUninomial());
661
		assertEquals("alba", nameBasionymAuthor.getSpecificEpithet());
662
		assertEquals("D'Mueller", nameBasionymAuthor.getCombinationAuthorship().getNomenclaturalTitle());
663
		assertEquals("Ciardelli", nameBasionymAuthor.getBasionymAuthorship().getNomenclaturalTitle());
664

    
665
		NonViralName<?> nameBasionymExAuthor = (NonViralName<?>)parseMethod.invoke(parser, strNameAbiesBasionymExAuthor1, null, Rank.SPECIES());
666
		assertEquals("Abies", nameBasionymExAuthor.getGenusOrUninomial());
667
		assertEquals("alba", nameBasionymExAuthor.getSpecificEpithet());
668
		assertEquals("D'Mueller", nameBasionymExAuthor.getExCombinationAuthorship().getNomenclaturalTitle());
669
		assertEquals("de Greuther", nameBasionymExAuthor.getCombinationAuthorship().getNomenclaturalTitle());
670
		assertEquals("Ciardelli", nameBasionymExAuthor.getExBasionymAuthorship().getNomenclaturalTitle());
671
		assertEquals("Doering", nameBasionymExAuthor.getBasionymAuthorship().getNomenclaturalTitle());
672

    
673
		NonViralName<?> name2 = (NonViralName<?>)parseMethod.invoke(parser, strNameAbiesSub1, null, Rank.SPECIES());
674
		assertEquals("Abies", name2.getGenusOrUninomial());
675
		assertEquals("alba", name2.getSpecificEpithet());
676
		assertEquals("beta", name2.getInfraSpecificEpithet());
677
		assertEquals(Rank.SUBSPECIES(), name2.getRank());
678

    
679

    
680
		// unparseable *********
681
		String problemString = "sdfjlös wer eer wer";
682
		NonViralName<?> nameProblem = (NonViralName<?>)parseMethod.invoke(parser, problemString, null, Rank.SPECIES());
683
		List<ParserProblem> list = nameProblem.getParsingProblems();
684
		assertTrue(nameProblem.getParsingProblem()!=0);
685
		assertEquals(problemString, nameProblem.getTitleCache());
686
	}
687

    
688

    
689
	/**
690
	 * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#parseReferencedName(NonViralName, java.lang.String, eu.etaxonomy.cdm.model.name.Rank, boolean)(, )}.
691
	 */
692
	@Test
693
	public final void testParseNomStatus() {
694
		//nom. ambig.
695
		String strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. ambig.";
696
		NonViralName<?> nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
697
		assertFullRefStandard(nameTestStatus);
698
		assertTrue(nameTestStatus.getStatus().size()== 1);
699
		assertEquals( NomenclaturalStatusType.AMBIGUOUS(), nameTestStatus.getStatus().iterator().next().getType());
700

    
701
        //nom. inval.
702
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. inval.";
703
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
704
        assertFullRefStandard(nameTestStatus);
705
        assertTrue(nameTestStatus.getStatus().size()== 1);
706
        assertEquals( NomenclaturalStatusType.INVALID(), nameTestStatus.getStatus().iterator().next().getType());
707

    
708
		//nom. dub.
709
		strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. dub.";
710
		nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
711
		assertFullRefStandard(nameTestStatus);
712
		assertTrue(nameTestStatus.getStatus().size()== 1);
713
		assertEquals( NomenclaturalStatusType.DOUBTFUL(), nameTestStatus.getStatus().iterator().next().getType());
714

    
715
		//nom. confus.
716
		strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. confus.";
717
		nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
718
		assertFullRefStandard(nameTestStatus);
719
		assertTrue(nameTestStatus.getStatus().size()== 1);
720
		assertEquals( NomenclaturalStatusType.CONFUSUM(), nameTestStatus.getStatus().iterator().next().getType());
721

    
722
		//nom. illeg.
723
		strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. illeg.";
724
		nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
725
		assertFullRefStandard(nameTestStatus);
726
		assertTrue(nameTestStatus.getStatus().size()== 1);
727
		assertEquals( NomenclaturalStatusType.ILLEGITIMATE(), nameTestStatus.getStatus().iterator().next().getType());
728

    
729
		//nom. superfl.
730
		strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. superfl.";
731
		nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
732
		assertFullRefStandard(nameTestStatus);
733
		assertTrue(nameTestStatus.getStatus().size()== 1);
734
		assertEquals( NomenclaturalStatusType.SUPERFLUOUS(), nameTestStatus.getStatus().iterator().next().getType());
735

    
736
		//nom. rej.
737
		strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. rej.";
738
		nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
739
		assertFullRefStandard(nameTestStatus);
740
		assertTrue(nameTestStatus.getStatus().size()== 1);
741
		assertEquals( NomenclaturalStatusType.REJECTED(), nameTestStatus.getStatus().iterator().next().getType());
742

    
743
		//nom. utique rej.
744
		strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. utique rej.";
745
		nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
746
		assertFullRefStandard(nameTestStatus);
747
		assertTrue(nameTestStatus.getStatus().size()== 1);
748
		assertEquals( NomenclaturalStatusType.UTIQUE_REJECTED(), nameTestStatus.getStatus().iterator().next().getType());
749

    
750
		//nom. cons. prop.
751
		strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. cons. prop.";
752
		nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
753
		assertFullRefStandard(nameTestStatus);
754
		assertTrue(nameTestStatus.getStatus().size()== 1);
755
		assertEquals( NomenclaturalStatusType.CONSERVED_PROP(), nameTestStatus.getStatus().iterator().next().getType());
756

    
757
		//nom. orth. cons. prop.
758
		strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. orth. cons. prop.";
759
		nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
760
		assertFullRefStandard(nameTestStatus);
761
		assertTrue(nameTestStatus.getStatus().size()== 1);
762
		assertEquals( NomenclaturalStatusType.ORTHOGRAPHY_CONSERVED_PROP(), nameTestStatus.getStatus().iterator().next().getType());
763

    
764
	    //nom. cons. prop.
765
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. cons. des.";
766
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
767
        assertFullRefStandard(nameTestStatus);
768
        assertTrue(nameTestStatus.getStatus().size()== 1);
769
        assertEquals( NomenclaturalStatusType.CONSERVED_DESIG(), nameTestStatus.getStatus().iterator().next().getType());
770

    
771
		//nom. legit.
772
		strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. legit.";
773
		nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
774
		assertFullRefStandard(nameTestStatus);
775
		assertTrue(nameTestStatus.getStatus().size()== 1);
776
		assertEquals( NomenclaturalStatusType.LEGITIMATE(), nameTestStatus.getStatus().iterator().next().getType());
777

    
778
		//nom. altern.
779
		strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. altern.";
780
		nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
781
		assertFullRefStandard(nameTestStatus);
782
		assertTrue(nameTestStatus.getStatus().size()== 1);
783
		assertEquals( NomenclaturalStatusType.ALTERNATIVE(), nameTestStatus.getStatus().iterator().next().getType());
784

    
785
		//nom. alternativ.
786
		strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. alternativ.";
787
		nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
788
		assertFullRefStandard(nameTestStatus);
789
		assertTrue(nameTestStatus.getStatus().size()== 1);
790
		assertEquals( NomenclaturalStatusType.ALTERNATIVE(), nameTestStatus.getStatus().iterator().next().getType());
791

    
792
		//nom. nov.
793
		strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, nom. nov.";
794
		nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
795
		assertFullRefStandard(nameTestStatus);
796
		assertTrue(nameTestStatus.getStatus().size()== 1);
797
		assertEquals( NomenclaturalStatusType.NOVUM(), nameTestStatus.getStatus().iterator().next().getType());
798

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

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

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

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

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

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

    
841
		//comb. inval.
842
		strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, comb. inval.";
843
		nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
844
		assertFullRefStandard(nameTestStatus);
845
		assertTrue(nameTestStatus.getStatus().size()== 1);
846
		assertEquals( NomenclaturalStatusType.COMBINATION_INVALID(), nameTestStatus.getStatus().iterator().next().getType());
847

    
848
		//comb. illeg.
849
		strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, comb. illeg.";
850
		nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
851
		assertFullRefStandard(nameTestStatus);
852
		assertTrue(nameTestStatus.getStatus().size()== 1);
853
		assertEquals( NomenclaturalStatusType.COMBINATION_ILLEGITIMATE(), nameTestStatus.getStatus().iterator().next().getType());
854

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

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

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

    
876
		//opus. utique oppr.
877
		strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, opus. utique oppr.";
878
		nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
879
		assertFullRefStandard(nameTestStatus);
880
		assertTrue(nameTestStatus.getStatus().size()== 1);
881
		assertEquals( NomenclaturalStatusType.OPUS_UTIQUE_OPPR(), nameTestStatus.getStatus().iterator().next().getType());
882

    
883
        //comb. nov.
884
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, comb. nov.";
885
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
886
        assertFullRefStandard(nameTestStatus);
887
        assertTrue(nameTestStatus.getStatus().size()== 1);
888
        assertEquals( NomenclaturalStatusType.COMB_NOV(), nameTestStatus.getStatus().iterator().next().getType());
889

    
890
        //orth. rej.
891
        strTestStatus = "Abies alba Mill., Sp. Pl. 4: 455. 1987, orth. rej.";
892
        nameTestStatus = parser.parseReferencedName(strTestStatus, null, Rank.SPECIES());
893
        assertFullRefStandard(nameTestStatus);
894
        assertTrue(nameTestStatus.getStatus().size()== 1);
895
        assertEquals( NomenclaturalStatusType.ORTHOGRAPHY_REJECTED(), nameTestStatus.getStatus().iterator().next().getType());
896

    
897
        //not yet parsed "not avail."
898
	}
899

    
900
	/**
901
	 * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#parseReferencedName(NonViralName, java.lang.String, eu.etaxonomy.cdm.model.name.Rank, boolean)(, )}.
902
	 */
903
	@Test
904
	public final void testParseReferencedName() {
905
		try {
906
			Method parseMethod = parser.getClass().getDeclaredMethod("parseReferencedName", String.class, NomenclaturalCode.class, Rank.class);
907
			testName_StringNomcodeRank(parseMethod);
908
		} catch (Exception e) {
909
			e.printStackTrace();
910
			assertTrue(false);
911
		}
912

    
913

    
914
		//null
915
		String strNull = null;
916
		Rank rankSpecies = Rank.SPECIES();
917
		NonViralName<?> nameNull = parser.parseReferencedName(strNull, null, rankSpecies);
918
		assertNull(nameNull);
919

    
920
		//Empty
921
		String strEmpty = "";
922
		NonViralName<?> nameEmpty = parser.parseReferencedName(strEmpty, null, rankSpecies);
923
		assertFalse(nameEmpty.hasProblem());
924
		assertEquals(strEmpty, nameEmpty.getFullTitleCache());
925
		assertNull(nameEmpty.getNomenclaturalMicroReference());
926

    
927

    
928
		//Whitespaces
929
		String strFullWhiteSpcaceAndDot = "Abies alba Mill.,  Sp.   Pl.  4:  455 .  1987 .";
930
		NonViralName<?> namefullWhiteSpcaceAndDot = parser.parseReferencedName(strFullWhiteSpcaceAndDot, null, rankSpecies);
931
		assertFullRefStandard(namefullWhiteSpcaceAndDot);
932
		assertTrue(((Reference<?>)namefullWhiteSpcaceAndDot.getNomenclaturalReference()).getType().equals(eu.etaxonomy.cdm.model.reference.ReferenceType.Book));
933
		assertEquals( "Abies alba Mill., Sp. Pl. 4: 455. 1987", namefullWhiteSpcaceAndDot.getFullTitleCache());
934

    
935
		//Book
936
		String fullReference = "Abies alba Mill., Sp. Pl. 4: 455. 1987";
937
		NonViralName<?> name1 = parser.parseReferencedName(fullReference, null, rankSpecies);
938
		assertFullRefStandard(name1);
939
		assertTrue(((Reference<?>)name1.getNomenclaturalReference()).getType().equals(eu.etaxonomy.cdm.model.reference.ReferenceType.Book));
940
		assertEquals(fullReference, name1.getFullTitleCache());
941
		assertTrue("Name author and reference author should be the same", name1.getCombinationAuthorship() == ((Reference<?>)name1.getNomenclaturalReference()).getAuthorship());
942

    
943
		//Book Section
944
		fullReference = "Abies alba Mill. in Otto, Sp. Pl. 4(6): 455. 1987";
945
		NonViralName<?> name2 = parser.parseReferencedName(fullReference + ".", null, rankSpecies);
946
		assertFullRefNameStandard(name2);
947
		assertEquals(fullReference, name2.getFullTitleCache());
948
		assertFalse(name2.hasProblem());
949
		INomenclaturalReference ref = name2.getNomenclaturalReference();
950
		assertEquals(eu.etaxonomy.cdm.model.reference.ReferenceType.BookSection, ((Reference<?>)ref).getType());
951
		IBookSection bookSection = (IBookSection) ref;
952
		IBook inBook = bookSection.getInBook();
953
		assertNotNull(inBook);
954
		assertNotNull(inBook.getAuthorship());
955
		assertEquals("Otto", inBook.getAuthorship().getTitleCache());
956
		assertEquals("Otto, Sp. Pl. 4(6)", inBook.getTitleCache());
957
		assertEquals("Sp. Pl.", inBook.getTitle());
958
		assertEquals("4(6)", inBook.getVolume());
959
		assertTrue("Name author and reference author should be the same", name2.getCombinationAuthorship() == ((Reference<?>)name2.getNomenclaturalReference()).getAuthorship());
960

    
961
		//Article
962
		fullReference = "Abies alba Mill. in Sp. Pl. 4(6): 455. 1987";
963
		NonViralName<?> name3 = parser.parseReferencedName(fullReference, null, rankSpecies);
964
		assertFullRefNameStandard(name3);
965
		name3.setTitleCache(null);
966
		assertEquals(fullReference, name3.getFullTitleCache());
967
		assertFalse(name3.hasProblem());
968
		ref = name3.getNomenclaturalReference();
969
		assertEquals(eu.etaxonomy.cdm.model.reference.ReferenceType.Article, ref.getType());
970
		//Article article = (Article)ref;
971
		IJournal journal = ((IArticle)ref).getInJournal();
972
		assertNotNull(journal);
973
		//assertEquals("Sp. Pl. 4(6)", inBook.getTitleCache());
974
		assertEquals("Sp. Pl.",((Reference<?>) journal).getTitleCache());
975
		assertEquals("Sp. Pl.", journal.getTitle());
976
		assertEquals("4(6)",((IArticle)ref).getVolume());
977
		assertTrue("Name author and reference author should be the same", name3.getCombinationAuthorship() == name3.getNomenclaturalReference().getAuthorship());
978

    
979
		//Article with volume range
980
        fullReference = "Abies alba Mill. in Sp. Pl. 4(1-2): 455. 1987";
981
        NonViralName<?> name3a = parser.parseReferencedName(fullReference, null, rankSpecies);
982
        name3a.setTitleCache(null);
983
        assertEquals(fullReference, name3a.getFullTitleCache());
984
        assertFalse(name3a.hasProblem());
985
        ref = name3a.getNomenclaturalReference();
986
        assertEquals(eu.etaxonomy.cdm.model.reference.ReferenceType.Article, ref.getType());
987
        assertEquals("4(1-2)",((IArticle)ref).getVolume());
988

    
989
		//SoftArticle - having "," on position > 4
990
		String journalTitle = "Bull. Soc. Bot.France. Louis., Roi";
991
		String yearPart = " 1987 - 1989";
992
		String parsedYear = "1987-1989";
993
		String fullReferenceWithoutYear = "Abies alba Mill. in " + journalTitle + " 4(6): 455.";
994
		fullReference = fullReferenceWithoutYear + yearPart;
995
		String fullReferenceWithEnd = fullReference + ".";
996
		NonViralName<?> name4 = parser.parseReferencedName(fullReferenceWithEnd, null, rankSpecies);
997
		assertFalse(name4.hasProblem());
998
		assertFullRefNameStandard(name4);
999
		assertEquals(fullReferenceWithoutYear + " " + parsedYear, name4.getFullTitleCache());
1000
		ref = name4.getNomenclaturalReference();
1001
		assertEquals(ReferenceType.Article, ref.getType());
1002
		//article = (Article)ref;
1003
		assertEquals(parsedYear, ref.getYear());
1004
		journal = ((IArticle)ref).getInJournal();
1005
		assertNotNull(journal);
1006
		assertEquals(journalTitle, ((Reference<?>) journal).getTitleCache());
1007
		assertEquals(journalTitle, journal.getTitle());
1008
		assertEquals("4(6)", ((IArticle)ref).getVolume());
1009

    
1010
		//Zoo name
1011
		String strNotParsableZoo = "Abies alba M., 1923, Sp. P. xxwer4352, nom. inval.";
1012
		ZoologicalName nameZooRefNotParsabel = (ZoologicalName)parser.parseReferencedName(strNotParsableZoo, null, null);
1013
		assertTrue(nameZooRefNotParsabel.hasProblem());
1014
		List<ParserProblem> list = nameZooRefNotParsabel.getParsingProblems();
1015
		assertTrue("List must contain detail and year warning ", list.contains(ParserProblem.CheckDetailOrYear));
1016
		assertEquals(21, nameZooRefNotParsabel.getProblemStarts());
1017
		assertEquals(37, nameZooRefNotParsabel.getProblemEnds());
1018
		assertTrue(nameZooRefNotParsabel.getNomenclaturalReference().hasProblem());
1019
		list = nameZooRefNotParsabel.getNomenclaturalReference().getParsingProblems();
1020
		assertTrue("List must contain detail and year warning ", list.contains(ParserProblem.CheckDetailOrYear));
1021

    
1022
		assertEquals(NomenclaturalCode.ICZN, nameZooRefNotParsabel.getNomenclaturalCode());
1023
		assertEquals(Integer.valueOf(1923), nameZooRefNotParsabel.getPublicationYear());
1024
		assertEquals(1, nameZooRefNotParsabel.getStatus().size());
1025

    
1026
		String strZooNameSineYear = "Homo sapiens L., 1758, Sp. An. 3: 345";
1027
		ZoologicalName nameZooNameSineYear = (ZoologicalName)parser.parseReferencedName(strZooNameSineYear);
1028
		assertFalse(nameZooNameSineYear.hasProblem());
1029
		assertEquals("Name without reference year must have year", (Integer)1758, nameZooNameSineYear.getPublicationYear());
1030
		assertEquals("Name without reference year must have year", "1758", nameZooNameSineYear.getNomenclaturalReference().getYear());
1031

    
1032
		String strZooNameNewCombination = "Homo sapiens (L., 1758) Mill., 1830, Sp. An. 3: 345";
1033
		ZoologicalName nameZooNameNewCombination = (ZoologicalName)parser.parseReferencedName(strZooNameNewCombination);
1034
		assertTrue(nameZooNameNewCombination.hasProblem());
1035
		list = nameZooNameNewCombination.getParsingProblems();
1036
		assertTrue("List must contain new combination has publication warning ", list.contains(ParserProblem.NewCombinationHasPublication));
1037
		assertEquals(35, nameZooNameNewCombination.getProblemStarts());
1038
		assertEquals(51, nameZooNameNewCombination.getProblemEnds());
1039

    
1040

    
1041
		//Special MicroRefs
1042
		String strSpecDetail1 = "Abies alba Mill. in Sp. Pl. 4(6): [455]. 1987";
1043
		NonViralName<?> nameSpecDet1 = parser.parseReferencedName(strSpecDetail1 + ".", null, rankSpecies);
1044
		assertFalse(nameSpecDet1.hasProblem());
1045
		assertEquals(strSpecDetail1, nameSpecDet1.getFullTitleCache());
1046
		assertEquals("[455]", nameSpecDet1.getNomenclaturalMicroReference());
1047

    
1048
		//Special MicroRefs
1049
		String strSpecDetail2 = "Abies alba Mill. in Sp. Pl. 4(6): couv. 2. 1987";
1050
		NonViralName<?> nameSpecDet2 = parser.parseReferencedName(strSpecDetail2 + ".", null, rankSpecies);
1051
		assertFalse(nameSpecDet2.hasProblem());
1052
		assertEquals(strSpecDetail2, nameSpecDet2.getFullTitleCache());
1053
		assertEquals("couv. 2", nameSpecDet2.getNomenclaturalMicroReference());
1054

    
1055
		//Special MicroRefs
1056
		String strSpecDetail3 = "Abies alba Mill. in Sp. Pl. 4(6): fig. 455. 1987";
1057
		NonViralName<?> nameSpecDet3 = parser.parseReferencedName(strSpecDetail3 + ".", null, rankSpecies);
1058
		assertFalse(nameSpecDet3.hasProblem());
1059
		assertEquals(strSpecDetail3, nameSpecDet3.getFullTitleCache());
1060
		assertEquals("fig. 455", nameSpecDet3.getNomenclaturalMicroReference());
1061

    
1062
		//Special MicroRefs
1063
		String strSpecDetail4 = "Abies alba Mill. in Sp. Pl. 4(6): fig. 455-567. 1987";
1064
		fullReference = strSpecDetail4 + ".";
1065
		NonViralName<?> nameSpecDet4 = parser.parseReferencedName(fullReference, null, rankSpecies);
1066
		assertFalse(nameSpecDet4.hasProblem());
1067
		assertEquals(strSpecDetail4, nameSpecDet4.getFullTitleCache());
1068
		assertEquals("fig. 455-567", nameSpecDet4.getNomenclaturalMicroReference());
1069

    
1070

    
1071
		//Special MicroRefs
1072
		String strSpecDetail5 = "Abies alba Mill. in Sp. Pl. 4(6): Gard n\u00B0 4. 1987";
1073
		fullReference = strSpecDetail5 + ".";
1074
		NonViralName<?> nameSpecDet5 = parser.parseReferencedName(fullReference, null, rankSpecies);
1075
		assertFalse(nameSpecDet5.hasProblem());
1076
		assertEquals(strSpecDetail5, nameSpecDet5.getFullTitleCache());
1077
		assertEquals("Gard n\u00B0 4", nameSpecDet5.getNomenclaturalMicroReference());
1078

    
1079
		//Special MicroRefs
1080
		String strSpecDetail6 = "Abies alba Mill. in Sp. Pl. 4(6): 455a. 1987";
1081
		fullReference = strSpecDetail6 + ".";
1082
		NonViralName<?> nameSpecDet6 = parser.parseReferencedName(fullReference, null, rankSpecies);
1083
		assertFalse(nameSpecDet6.hasProblem());
1084
		assertEquals(strSpecDetail6, nameSpecDet6.getFullTitleCache());
1085
		assertEquals("455a", nameSpecDet6.getNomenclaturalMicroReference());
1086

    
1087
		//Special MicroRefs
1088
		String strSpecDetail7 = "Abies alba Mill. in Sp. Pl. 4(6): pp.455-457. 1987";
1089
		fullReference = strSpecDetail7 + ".";
1090
		NonViralName<?> nameSpecDet7 = parser.parseReferencedName(fullReference, null, rankSpecies);
1091
		assertFalse(nameSpecDet7.hasProblem());
1092
		assertEquals(strSpecDetail7, nameSpecDet7.getFullTitleCache());
1093
		assertEquals("pp.455-457", nameSpecDet7.getNomenclaturalMicroReference());
1094

    
1095
		//Special MicroRefs
1096
		String strSpecDetail8 = "Abies alba Mill. in Sp. Pl. 4(6): ppp.455-457. 1987";
1097
		NonViralName<?> nameSpecDet8 = parser.parseReferencedName(strSpecDetail8, null, rankSpecies);
1098
		assertTrue(nameSpecDet8.hasProblem());
1099
		assertEquals(20, nameSpecDet8.getProblemStarts()); //TODO better start behind :
1100
		assertEquals(51, nameSpecDet8.getProblemEnds());   //TODO better stop after -457
1101

    
1102

    
1103
		//Special MicroRefs
1104
		String strSpecDetail9 = "Abies alba Mill. in Sp. Pl. 4(6): pp. 455 - 457. 1987";
1105
		NonViralName<?> nameSpecDet9 = parser.parseReferencedName(strSpecDetail9, null, rankSpecies);
1106
		assertFalse(nameSpecDet9.hasProblem());
1107
		assertEquals(strSpecDetail9, nameSpecDet9.getFullTitleCache());
1108
		assertEquals("pp. 455 - 457", nameSpecDet9.getNomenclaturalMicroReference());
1109

    
1110
		//Special MicroRefs
1111
		String strSpecDetail10 = "Abies alba Mill. in Sp. Pl. 4(6): p 455. 1987";
1112
		NonViralName<?> nameSpecDet10 = parser.parseReferencedName(strSpecDetail10, null, rankSpecies);
1113
		assertFalse(nameSpecDet10.hasProblem());
1114
		assertEquals(strSpecDetail10, nameSpecDet10.getFullTitleCache());
1115
		assertEquals("p 455", nameSpecDet10.getNomenclaturalMicroReference());
1116

    
1117
		//Special MicroRefs
1118
		String strSpecDetail11 = "Abies alba Mill. in Sp. Pl. 4(6): p. 455 - 457. 1987";
1119
		NonViralName<?> nameSpecDet11 = parser.parseReferencedName(strSpecDetail11, null, rankSpecies);
1120
		assertTrue(nameSpecDet11.hasProblem());
1121
		list = nameSpecDet11.getParsingProblems();
1122
		assertTrue("Problem is Detail. Must be pp.", list.contains(ParserProblem.CheckDetailOrYear));
1123
		assertEquals(20, nameSpecDet8.getProblemStarts()); //TODO better start behind :
1124
		assertEquals(51, nameSpecDet8.getProblemEnds());   //TODO better stop after - 457
1125

    
1126

    
1127
		//no volume, no edition
1128
		String strNoVolume = "Abies alba Mill., Sp. Pl.: 455. 1987";
1129
		NonViralName<?> nameNoVolume = parser.parseReferencedName(strNoVolume, null, rankSpecies);
1130
		assertFalse(nameNoVolume.hasProblem());
1131
		assertEquals(strNoVolume, nameNoVolume.getFullTitleCache());
1132
		assertEquals(null, ((IVolumeReference)(nameNoVolume.getNomenclaturalReference())).getVolume());
1133
		assertEquals(null, ((IBook)nameNoVolume.getNomenclaturalReference()).getEdition());
1134

    
1135
		//volume, no edition
1136
		strNoVolume = "Abies alba Mill., Sp. Pl. 2: 455. 1987";
1137
		nameNoVolume = parser.parseReferencedName(strNoVolume, null, rankSpecies);
1138
		assertFalse(nameNoVolume.hasProblem());
1139
		assertEquals(strNoVolume, nameNoVolume.getFullTitleCache());
1140
		assertEquals("2", ((IVolumeReference)(nameNoVolume.getNomenclaturalReference())).getVolume());
1141
		assertEquals(null, ((IBook)(nameNoVolume.getNomenclaturalReference())).getEdition());
1142

    
1143
		//no volume, edition
1144
		strNoVolume = "Abies alba Mill., Sp. Pl., ed. 3: 455. 1987";
1145
		nameNoVolume = parser.parseReferencedName(strNoVolume, null, rankSpecies);
1146
		assertFalse(nameNoVolume.hasProblem());
1147
		assertEquals(strNoVolume, nameNoVolume.getFullTitleCache());
1148
		assertEquals(null, ((IVolumeReference)(nameNoVolume.getNomenclaturalReference())).getVolume());
1149
		assertEquals("3", ((IBook)(nameNoVolume.getNomenclaturalReference())).getEdition());
1150

    
1151
		//volume, edition
1152
		strNoVolume = "Abies alba Mill., Sp. Pl. ed. 3, 4(5): 455. 1987";
1153
		nameNoVolume = parser.parseReferencedName(strNoVolume, null, rankSpecies);
1154
		assertFalse(nameNoVolume.hasProblem());
1155
		assertEquals(strNoVolume.replace(" ed.", ", ed."), nameNoVolume.getFullTitleCache());
1156
		assertEquals("4(5)", ((IVolumeReference)(nameNoVolume.getNomenclaturalReference())).getVolume());
1157
		assertEquals("3", ((IBook)(nameNoVolume.getNomenclaturalReference())).getEdition());
1158

    
1159
		String strUnparsableInRef = "Abies alba Mill. in -er46: 455. 1987";
1160
		NonViralName<?> nameUnparsableInRef = parser.parseReferencedName(strUnparsableInRef, null, rankSpecies);
1161
		assertTrue(nameUnparsableInRef.hasProblem());
1162
		list = nameUnparsableInRef.getParsingProblems();
1163
		assertTrue("Unparsable title", list.contains(ParserProblem.UnparsableReferenceTitle));
1164
		assertEquals(strUnparsableInRef, nameUnparsableInRef.getFullTitleCache());
1165
		assertEquals(20, nameUnparsableInRef.getProblemStarts());
1166
		assertEquals(25, nameUnparsableInRef.getProblemEnds());
1167

    
1168

    
1169
		//volume, edition
1170
		String strNoSeparator = "Abies alba Mill. Sp. Pl. ed. 3, 4(5): 455. 1987";
1171
		NonViralName<?> nameNoSeparator = parser.parseReferencedName(strNoSeparator, ICNAFP, rankSpecies);
1172
		assertTrue(nameNoSeparator.hasProblem());
1173
		list = nameNoSeparator.getParsingProblems();
1174
		assertTrue("Problem is missing name-reference separator", list.contains(ParserProblem.NameReferenceSeparation));
1175
		assertEquals(strNoSeparator, nameNoSeparator.getFullTitleCache());
1176
		assertEquals(10, nameNoSeparator.getProblemStarts()); //TODO better start behind Mill. (?)
1177
		assertEquals(47, nameNoSeparator.getProblemEnds());   //TODO better stop before :
1178

    
1179
		String strUnparsableInRef2 = "Hieracium pepsicum L., My Bookkkk 1. 1903";
1180
		NonViralName<?> nameUnparsableInRef2 = parser.parseReferencedName(strUnparsableInRef2, null, rankSpecies);
1181
		assertTrue(nameUnparsableInRef2.hasProblem());
1182
		list = nameUnparsableInRef2.getParsingProblems();
1183
		assertTrue("Problem detail", list.contains(ParserProblem.CheckDetailOrYear));
1184
		assertEquals(strUnparsableInRef2, nameUnparsableInRef2.getFullTitleCache());
1185
		assertEquals(23, nameUnparsableInRef2.getProblemStarts());
1186
		assertEquals(41, nameUnparsableInRef2.getProblemEnds());
1187

    
1188

    
1189
		String strUnparsableInRef3 = "Hieracium pespcim N., My Bookkkk 1. 1902";
1190
		NonViralName<?> nameUnparsableInRef3 = parser.parseReferencedName(strUnparsableInRef3, null, null);
1191
		assertTrue(nameUnparsableInRef3.hasProblem());
1192
		list = nameUnparsableInRef3.getParsingProblems();
1193
		assertTrue("Problem detail", list.contains(ParserProblem.CheckDetailOrYear));
1194
		assertEquals(strUnparsableInRef3, nameUnparsableInRef3.getFullTitleCache());
1195
		assertEquals(22, nameUnparsableInRef3.getProblemStarts());
1196
		assertEquals(40, nameUnparsableInRef3.getProblemEnds());
1197

    
1198
		String strUnparsableInRef4 = "Hieracium pepsicum (Hsllreterto) L., My Bookkkk 1. 1903";
1199
		NonViralName<?> nameUnparsableInRef4 = parser.parseReferencedName(strUnparsableInRef4, null, null);
1200
		assertTrue(nameUnparsableInRef4.hasProblem());
1201
		list = nameUnparsableInRef4.getParsingProblems();
1202
		assertTrue("Problem detail", list.contains(ParserProblem.CheckDetailOrYear));
1203
		assertEquals(strUnparsableInRef4, nameUnparsableInRef4.getFullTitleCache());
1204
		assertEquals(37, nameUnparsableInRef4.getProblemStarts());
1205
		assertEquals(55, nameUnparsableInRef4.getProblemEnds());
1206

    
1207
		String strSameName = "Hieracium pepcum (Hsllreterto) L., My Bokkk 1. 1903";
1208
		NonViralName<?> nameSameName = nameUnparsableInRef4;
1209
		parser.parseReferencedName(nameSameName, strSameName, null, true);
1210
		assertTrue(nameSameName.hasProblem());
1211
		list = nameSameName.getParsingProblems();
1212
		assertTrue("Problem detail", list.contains(ParserProblem.CheckDetailOrYear));
1213
		assertEquals(strSameName, nameSameName.getFullTitleCache());
1214
		assertEquals(35, nameSameName.getProblemStarts());
1215
		assertEquals(51, nameSameName.getProblemEnds());
1216

    
1217
		String strGenusUnparse = "Hieracium L., jlklk";
1218
		NonViralName<?> nameGenusUnparse =
1219
			parser.parseReferencedName(strGenusUnparse, null, null);
1220
		assertTrue(nameGenusUnparse.hasProblem());
1221
		list = nameGenusUnparse.getParsingProblems();
1222
		assertTrue("Problem detail", list.contains(ParserProblem.CheckDetailOrYear));
1223
		assertTrue("Problem uninomial", list.contains(ParserProblem.CheckRank));
1224
		assertEquals(strGenusUnparse, nameGenusUnparse.getFullTitleCache());
1225
		assertEquals(0, nameGenusUnparse.getProblemStarts());
1226
		assertEquals(19, nameGenusUnparse.getProblemEnds());
1227

    
1228
		String strGenusUnparse2 = "Hieracium L., Per Luigi: 44. 1987";
1229
		NonViralName<?> nameGenusUnparse2 =
1230
			parser.parseReferencedName(strGenusUnparse2, null, Rank.FAMILY());
1231
		assertFalse(nameGenusUnparse2.hasProblem());
1232
		assertEquals(strGenusUnparse2, nameGenusUnparse2.getFullTitleCache());
1233
		assertEquals(-1, nameGenusUnparse2.getProblemStarts());
1234
		assertEquals(-1, nameGenusUnparse2.getProblemEnds());
1235

    
1236
		String strBookSection2 = "Hieracium vulgatum subsp. acuminatum (Jord.) Zahn in Schinz & Keller, Fl. Schweiz, ed. 2, 2: 288. 1905-1907";
1237
		String strBookSection2NoComma = "Hieracium vulgatum subsp. acuminatum (Jord.) Zahn in Schinz & Keller, Fl. Schweiz ed. 2, 2: 288. 1905-1907";
1238
		NonViralName<?> nameBookSection2 =
1239
			parser.parseReferencedName(strBookSection2, null, null);
1240
		assertFalse(nameBookSection2.hasProblem());
1241
		nameBookSection2.setFullTitleCache(null, false);
1242
		assertEquals(strBookSection2NoComma.replace(" ed.", ", ed."), nameBookSection2.getFullTitleCache());
1243
		assertEquals(-1, nameBookSection2.getProblemStarts());
1244
		assertEquals(-1, nameBookSection2.getProblemEnds());
1245
		assertNull((nameBookSection2.getNomenclaturalReference()).getDatePublished().getStart());
1246
		assertEquals("1905-1907", ((IBookSection)nameBookSection2.getNomenclaturalReference()).getInBook().getDatePublished().getYear());
1247

    
1248

    
1249
		String strBookSection = "Hieracium vulgatum subsp. acuminatum (Jord.) Zahn in Schinz & Keller, Fl. Schweiz ed. 2, 2: 288. 1905";
1250
		NonViralName<?> nameBookSection =
1251
			parser.parseReferencedName(strBookSection, null, null);
1252
		assertFalse(nameBookSection.hasProblem());
1253
		assertEquals(strBookSection.replace(" ed.", ", ed."), nameBookSection.getFullTitleCache());
1254
		assertEquals(-1, nameBookSection.getProblemStarts());
1255
		assertEquals(-1, nameBookSection.getProblemEnds());
1256
		assertNull(((IBookSection)nameBookSection.getNomenclaturalReference()).getInBook().getDatePublished().getStart());
1257
		assertEquals("1905", ((IBookSection)nameBookSection.getNomenclaturalReference()).getDatePublished().getYear());
1258

    
1259
		String strXXXs = "Abies alba, Soer der 1987";
1260
		NonViralName<?> problemName = parser.parseReferencedName(strXXXs, null, null);
1261
		assertTrue(problemName.hasProblem());
1262
		list = problemName.getParsingProblems();
1263
		assertTrue("Problem must be name-reference separation", list.contains(ParserProblem.NameReferenceSeparation));
1264
		parser.parseReferencedName(problemName, strBookSection, null, true);
1265
		assertFalse(problemName.hasProblem());
1266

    
1267
		problemName = parser.parseFullName(strXXXs, null, null);
1268
		assertTrue(problemName.hasProblem());
1269
		list = problemName.getParsingProblems();
1270
		assertTrue("Name part must be unparsable", list.contains(ParserProblem.UnparsableNamePart));
1271

    
1272

    
1273
		String testParsable = "Pithecellobium macrostachyum Benth.";
1274
		assertTrue(isParsable(testParsable, ICNAFP));
1275

    
1276
		testParsable = "Pithecellobium macrostachyum (Benth.)";
1277
		assertTrue(isParsable(testParsable, ICNAFP));
1278

    
1279
		testParsable = "Pithecellobium macrostachyum (Benth., 1845)";
1280
		assertTrue(isParsable(testParsable, NomenclaturalCode.ICZN));
1281

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

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

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

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

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

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

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

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

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

    
1313
		testParsable = "Hieracium lachenalii, Ill. Fl. (Mitt.) 6: 1285. 1929";
1314
		assertFalse("Author is obligatory if followed by reference", isParsable(testParsable, ICNAFP));
1315
		assertTrue("Problem must be name-reference separation", getProblems(testParsable, ICNAFP).
1316
				contains(ParserProblem.NameReferenceSeparation));
1317

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

    
1323
		testParsable = "Abies alba Mill. var. alba";
1324
		assertTrue("Autonym problem", isParsable(testParsable, ICNAFP));
1325

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

    
1329

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

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

    
1337

    
1338
	}
1339

    
1340

    
1341
	/**
1342
	 * Test author with name parts van, von, de, de la, d', da, del.
1343
	 * See also http://dev.e-taxonomy.eu/trac/ticket/3373
1344
	 */
1345
	@Test
1346
	public final void  testComposedAuthorNames(){
1347

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

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

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

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

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

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

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

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

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

    
1384
	}
1385

    
1386

    
1387

    
1388
	/**
1389
	 * @param testParsable
1390
	 * @param icbn
1391
	 * @return
1392
	 */
1393
	private List<ParserProblem> getProblems(String string, NomenclaturalCode code) {
1394
		List<ParserProblem> result;
1395
		result = parser.parseReferencedName(string, code, null).getParsingProblems();
1396
		return result;
1397
	}
1398

    
1399
	private boolean isParsable(String string, NomenclaturalCode code){
1400
		NonViralName<?> name = parser.parseReferencedName(string, code, null);
1401
		return ! name.hasProblem();
1402
	}
1403

    
1404
	private void assertFullRefNameStandard(NonViralName<?> name){
1405
		assertEquals("Abies", name.getGenusOrUninomial());
1406
		assertEquals("alba", name.getSpecificEpithet());
1407
		assertEquals("Mill.", name.getAuthorshipCache());
1408
		assertEquals("455", name.getNomenclaturalMicroReference());
1409
		assertNotNull(name.getNomenclaturalReference());
1410
	}
1411

    
1412
	private void assertFullRefStandard(NonViralName<?> name){
1413
		assertEquals("Abies", name.getGenusOrUninomial());
1414
		assertEquals("alba", name.getSpecificEpithet());
1415
		assertEquals("Mill.", name.getAuthorshipCache());
1416
		assertEquals("455", name.getNomenclaturalMicroReference());
1417
		assertNotNull(name.getNomenclaturalReference());
1418
		INomenclaturalReference ref = name.getNomenclaturalReference();
1419
		assertEquals("1987", ref.getYear());
1420
		assertEquals("Sp. Pl.", ref.getTitle());
1421
	}
1422

    
1423

    
1424
	@Test
1425
	public void testNeverEndingParsing(){
1426
		//some full titles result in never ending parsing process https://dev.e-taxonomy.eu/trac/ticket/1556
1427

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

    
1436
		String anotherExample = "Scorzonera hispanica var. brevifolia Boiss. & Balansa in Boissier, Diagn. Pl. Orient., ser. 2 6: 119. 1859.";
1437
		nvn = this.parser.parseReferencedName(anotherExample, ICNAFP, null);
1438
		parsingProblem = nvn.getParsingProblem();
1439
		Assert.assertEquals("Problem should be 0", 0, parsingProblem);
1440
		Assert.assertEquals("Titlecache", "Scorzonera hispanica var. brevifolia Boiss. & Balansa", nvn.getTitleCache());
1441
		Assert.assertEquals("If this line reached everything should be ok", "Scorzonera", nvn.getGenusOrUninomial());
1442

    
1443
		String unparsable = "Taraxacum nevskii L., Trudy Bot. Inst. Nauk S.S.S.R., Ser. 1, Fl. Sist. Vyssh. Rast. 4: 293. 1937.";
1444
//		String unparsableA = "Taraxacum nevskii L. in Trudy Bot. Inst. Nauk: 293. 1937.";
1445
		nvn = this.parser.parseReferencedName(unparsable, ICNAFP, null);
1446
		Assert.assertEquals("Titlecache", "Taraxacum nevskii L.", nvn.getTitleCache());
1447
		Assert.assertEquals("If this line reached everything should be ok", "Taraxacum", nvn.getGenusOrUninomial());
1448
		parsingProblem = nvn.getParsingProblem();
1449
		Assert.assertEquals("Name should no warnings or errors", 0, parsingProblem);
1450

    
1451
		String unparsable2 = "Hieracium pxxx Dahlst., Kongl. Svenska Vetensk. Acad. Handl. ser. 2, 26(3): 255. 1894";
1452
//		String unparsable2A = "Hieracium pxxx Dahlst., Kongl Svenska Vetensk Acad Handl, 26: 255. 1894.";
1453
		nvn = this.parser.parseReferencedName(unparsable2, ICNAFP, null);
1454
		Assert.assertEquals("Titlecache", "Hieracium pxxx Dahlst.", nvn.getTitleCache());
1455
		Assert.assertEquals("If this line reached everything should be ok", "Hieracium", nvn.getGenusOrUninomial());
1456
		parsingProblem = nvn.getParsingProblem();
1457
		Assert.assertEquals("Name should no warnings or errors", 0, parsingProblem);
1458

    
1459

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

    
1465
	}
1466

    
1467
	@Test
1468
	public final void testSeriesPart(){
1469
		Pattern seriesPattern = Pattern.compile(NonViralNameParserImplRegExBase.pSeriesPart);
1470
		Matcher matcher = seriesPattern.matcher("ser. 2");
1471
		Assert.assertTrue("", matcher.matches());
1472
	}
1473

    
1474
	/**
1475
	 * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#fullTeams(java.lang.String)}.
1476
	 */
1477
	@Test
1478
	public final void testFullTeams() {
1479
		logger.warn("Not yet implemented"); // TODO
1480
	}
1481

    
1482
	/**
1483
	 * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#AuthorshipAndEx(java.lang.String)}.
1484
	 * @throws StringNotParsableException
1485
	 */
1486
	@Test
1487
	public final void testParseAuthorsTaxonNameString() throws StringNotParsableException {
1488
		NonViralName<?> nvn = ZoologicalName.NewInstance(null);
1489
		parser.parseAuthors(nvn, "Eckweiler & ten Hagen, 2003");
1490
		Team team = (Team)nvn.getCombinationAuthorship();
1491
		Assert.assertNotNull("Comb. author must not be null", team);
1492
		Assert.assertEquals("Must be team with 2 members", 2, team.getTeamMembers().size());
1493
		Assert.assertEquals("Second member must be 'ten Hagen'", "ten Hagen", team.getTeamMembers().get(1).getTitleCache());
1494

    
1495
		//Crosson du Cormier, 1964
1496
		ZoologicalName zooName = ZoologicalName.NewInstance(null);
1497
		parser.parseAuthors(zooName, "Crosson du Cormier, 1964");
1498
		Person person = (Person)zooName.getCombinationAuthorship();
1499
		Assert.assertNotNull("Comb. author must not be null", person);
1500
		Assert.assertEquals("Persons title must be 'Crosson du Cormier'", "Crosson du Cormier", person.getTitleCache());
1501
		Assert.assertEquals("Year must be 1964", Integer.valueOf(1964), zooName.getPublicationYear() );
1502

    
1503
		//(van der Hoeven, 1839)
1504
		zooName = ZoologicalName.NewInstance(null);
1505
		parser.parseAuthors(zooName, "(van der Hoeven, 1839)");
1506
		Assert.assertNull("Combination author must be null", zooName.getCombinationAuthorship());
1507
		person = (Person)zooName.getBasionymAuthorship();
1508
		Assert.assertNotNull("Basionym author must not be null", person);
1509
		Assert.assertEquals("Persons title must be 'van der Hoeven'", "van der Hoeven", person.getTitleCache());
1510
		Assert.assertEquals("Year must be 1839", Integer.valueOf(1839), zooName.getOriginalPublicationYear() );
1511

    
1512
		//le Doux, 1931
1513
		zooName = ZoologicalName.NewInstance(null);
1514
		parser.parseAuthors(zooName, "le Doux, 1931");
1515
		person = (Person)zooName.getCombinationAuthorship();
1516
		Assert.assertNotNull("Comb. author must not be null", person);
1517
		Assert.assertEquals("Persons title must be 'le Doux'", "le Doux", person.getTitleCache());
1518
		Assert.assertEquals("Year must be 1931", Integer.valueOf(1931), zooName.getPublicationYear() );
1519

    
1520

    
1521
	}
1522

    
1523
	@Test  //#4764
1524
	public void testParseSection(){
1525
	    //this test does not really test problematic cases where sect.idInVoc = "sect." instead of "sect.(bot.)"
1526
	    //however, by changing the csv file entry to sect. just for testing it can be used as a functional test
1527
	    String sectionNameStr = "Taraxacum sect. Testtaxa M\u00fcller, Incredible Taxa: 12. 2016";
1528
	    NonViralName<?> sectionName = parser.parseReferencedName(sectionNameStr, NomenclaturalCode.ICNAFP, null);
1529
	    int parsingProblem = sectionName.getParsingProblem();
1530
	    Assert.assertEquals("Problem should be 0", 0, parsingProblem);
1531
	    Rank rank = sectionName.getRank();
1532
	    Assert.assertEquals("", Rank.SECTION_BOTANY(), rank  );
1533

    
1534
	}
1535

    
1536
	@Test  //#5072
1537
	public final void testLongRunningParsingCapitals(){
1538
	    DateTime start = DateTime.now();
1539
	    String nameStr = "Nazeris fujianensis JIAYAO HU, LIZHEN LI, MEIJUN ZHAO,2010";  //name from CoL that created problems
1540
        NonViralName<?> name = parser.parseReferencedName(nameStr, NomenclaturalCode.ICZN, null);
1541
	    DateTime end = DateTime.now();
1542
        Duration duration = new Duration(start, end);
1543
        long seconds = duration.getStandardSeconds();
1544
        //this is the critical part of the test that must not be changed
1545
        Assert.assertTrue("Parsing of name should take less then 3 seconds but took " + seconds, seconds < 3);
1546

    
1547
 	}
1548

    
1549
	@Test  //#5072
1550
	//http://www.regular-expressions.info/catastrophic.html
1551
    public final void testLongRunningParsing(){
1552

    
1553
	    //name only
1554
        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";
1555
        DateTime start = DateTime.now();
1556
        NonViralName<?> name = parser.parseReferencedName(nameStr, NomenclaturalCode.ICNAFP, null);
1557
        DateTime end = DateTime.now();
1558
        Duration duration = new Duration(start, end);
1559
        long seconds = duration.getStandardSeconds();
1560
        //this is the critical part of the test that must not be changed
1561
        Assert.assertTrue("Parsing of name should take less then 3 seconds but took " + seconds, seconds < 3);
1562
        //the following may be discussed
1563
        Assert.assertFalse("Name should parse without problems",name.hasProblem());
1564

    
1565

    
1566
        //with reference
1567
        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.";
1568
        start = DateTime.now();
1569
        name = parser.parseReferencedName(nameStr, NomenclaturalCode.ICNAFP, null);
1570
        end = DateTime.now();
1571
        duration = new Duration(start, end);
1572
        seconds = duration.getStandardSeconds();
1573
        //this is the critical part of the test that must not be changed
1574
        Assert.assertTrue("Parsing of name should take less then 3 seconds but took " + seconds, seconds < 3);
1575
        //the following may be discussed
1576
        Assert.assertFalse("Name should parse without problems",name.hasProblem());
1577
    }
1578

    
1579
    @Test  //#5072
1580
    public final void testLongRunningParsingAuthors(){
1581
        //http://www.regular-expressions.info/catastrophic.html
1582
        //
1583
        //Länge des Nachnamens macht keinen Unterschied
1584
        //Anzahl der "AuthorParts scheint entscheidend
1585
        // & am Ende macht es langsamger (16s), als nur ","(6s))
1586

    
1587
        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";
1588
        TeamOrPersonBase[] authorArray = new TeamOrPersonBase[4];
1589
        try {
1590
            DateTime start = DateTime.now();
1591
            parser.fullAuthors(authorStr, authorArray, new Integer[]{1800, null, null, null}, BotanicalName.class);
1592
            DateTime end = DateTime.now();
1593
            Duration duration = new Duration(start, end);
1594
            long seconds = duration.getStandardSeconds();
1595
//            System.out.println(seconds);
1596
            //this is the critical part of the test that must not be changed
1597
            Assert.assertTrue("Parsing of name should take less then 3 seconds but took " + seconds, seconds < 3);
1598
        } catch (StringNotParsableException e) {
1599
            e.printStackTrace();
1600
            Assert.fail("Authors should be parsable");
1601
        }
1602

    
1603
    }
1604

    
1605

    
1606
	/**
1607
	 * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#AuthorshipAndEx(java.lang.String)}.
1608
	 */
1609
	@Test
1610
	public final void testAuthorshipAndEx() {
1611
		logger.warn("Not yet implemented"); // TODO
1612
	}
1613

    
1614
	/**
1615
	 * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#Authorship(java.lang.String)}.
1616
	 */
1617
	@Test
1618
	public final void testAuthorship() {
1619
		logger.warn("Not yet implemented"); // TODO
1620
	}
1621

    
1622
	/**
1623
	 * Test method for {@link eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl#parseCultivar(java.lang.String)}.
1624
	 */
1625
	@Test
1626
	public final void testParseCultivar() {
1627
		logger.warn("Not yet implemented"); // TODO
1628
	}
1629

    
1630
	@Test
1631
	public final void testNomenclaturalStatus() {
1632
		BotanicalName name = BotanicalName.NewInstance(Rank.FAMILY(), "Acanthopale", null, null, null, null, null, null, null);
1633
		name.addStatus(NomenclaturalStatus.NewInstance(NomenclaturalStatusType.ALTERNATIVE()));
1634
		BotanicalName name2 = BotanicalName.NewInstance(Rank.FAMILY());
1635
		parser.parseReferencedName(name2, name.getFullTitleCache(),	name2.getRank(), true);
1636
		parser.parseReferencedName(name2, name.getFullTitleCache(),	name2.getRank(), true);
1637
		Assert.assertEquals("Title cache should be same. No duplication of nom. status should take place", name.getFullTitleCache(), name2.getFullTitleCache());
1638
	}
1639

    
1640
	@Test
1641
	public final void testSpecificAuthors(){
1642
	    //McVaugh
1643
        NonViralName<?> name = parser.parseFullName("Psidium longipes var. orbiculare (O.Berg) McVaugh");
1644
        Assert.assertFalse("Name should be parsable", name.isProtectedTitleCache());
1645
        TeamOrPersonBase<?> combinationAuthor = name.getCombinationAuthorship();
1646
        assertEquals( "McVaugh", combinationAuthor.getNomenclaturalTitle());
1647
        TeamOrPersonBase<?> basionymAuthor = name.getBasionymAuthorship();
1648
        assertEquals( "O.Berg", basionymAuthor.getNomenclaturalTitle());
1649

    
1650
//      Campanula rhodensis A. DC.
1651

    
1652
	}
1653

    
1654
}
(2-2/4)