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

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

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

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

    
87
	private NonViralNameParserImpl parser ;
88
	private NomenclaturalCode botanicCode;
89

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

    
99

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

    
109

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

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

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

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

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

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

    
154
	}
155

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

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

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

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

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

    
190
	}
191

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

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

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

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

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

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

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

    
248
	}
249

    
250

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

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

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

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

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

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

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

    
308

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

    
313

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

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

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

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

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

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

    
350
	}
351

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

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

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

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

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

    
414

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

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

    
441
	}
442

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

    
450

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

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

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

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

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

    
495
	}
496

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

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

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

    
526
	}
527

    
528

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

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

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

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

    
569

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

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

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

    
603
	}
604

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

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

    
620

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

    
627

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

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

    
640

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

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

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

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

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

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

    
680

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

    
689

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
914

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

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

    
928

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

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

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

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

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

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

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

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

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

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

    
1041

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

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

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

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

    
1071

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

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

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

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

    
1103

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

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

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

    
1127

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

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

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

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

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

    
1169

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

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

    
1189

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

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

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

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

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

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

    
1249

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

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

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

    
1273

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1330

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

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

    
1338

    
1339
	}
1340

    
1341

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

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

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

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

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

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

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

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

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

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

    
1385
	}
1386

    
1387

    
1388

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

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

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

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

    
1424

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

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

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

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

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

    
1460

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

    
1466
	}
1467

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

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

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

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

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

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

    
1521

    
1522
	}
1523

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

    
1535
	}
1536

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

    
1548
 	}
1549

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

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

    
1566

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

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

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

    
1604
    }
1605

    
1606

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

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

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

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

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

    
1651
//      Campanula rhodensis A. DC.
1652

    
1653
	}
1654

    
1655
}
(2-2/4)