Project

General

Profile

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

    
11
import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;
12
import org.junit.Assert;
13
import org.junit.Before;
14
import org.junit.Test;
15

    
16
import eu.etaxonomy.cdm.common.DOI;
17
import eu.etaxonomy.cdm.common.URI;
18
import eu.etaxonomy.cdm.model.agent.Institution;
19
import eu.etaxonomy.cdm.model.agent.Person;
20
import eu.etaxonomy.cdm.model.agent.Team;
21
import eu.etaxonomy.cdm.model.description.Distribution;
22
import eu.etaxonomy.cdm.model.description.TaxonNameDescription;
23
import eu.etaxonomy.cdm.model.name.Rank;
24
import eu.etaxonomy.cdm.model.name.TaxonName;
25
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
26
import eu.etaxonomy.cdm.model.reference.IArticle;
27
import eu.etaxonomy.cdm.model.reference.IBook;
28
import eu.etaxonomy.cdm.model.reference.IBookSection;
29
import eu.etaxonomy.cdm.model.reference.IJournal;
30
import eu.etaxonomy.cdm.model.reference.Reference;
31
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
32
import eu.etaxonomy.cdm.strategy.parser.TimePeriodParser;
33
import eu.etaxonomy.cdm.test.TermTestBase;
34

    
35
/**
36
 * Test class for {@link MatchStrategyFactory}
37
 *
38
 * @author a.mueller
39
 * @since 03.08.2009
40
 */
41
public class MatchStrategyFactoryTest extends TermTestBase {
42

    
43
	@SuppressWarnings("unused")
44
	private static final Logger logger = LogManager.getLogger(MatchStrategyFactoryTest.class);
45

    
46
	private static boolean FAIL_ALL = true;
47

    
48
	private IMatchStrategyEqual matchStrategy;
49

    
50
	private Institution institution1;
51

    
52
	@Before
53
	public void setUp() throws Exception {
54
		institution1 = Institution.NewNamedInstance("Institution1");
55
	}
56

    
57
//********************* TEST *********************************************/
58

    
59
	@Test
60
	public void testNewInstance() {
61
		matchStrategy = MatchStrategyFactory.NewDefaultInstance(Reference.class);
62
		Assert.assertNotNull(matchStrategy);
63
//		Assert.assertEquals(Reference.class, matchStrategy.getMatchClass());
64
	}
65

    
66
    @Test
67
    public void testParsedPerson() throws MatchException {
68

    
69
        IParsedMatchStrategy matchStrategy = MatchStrategyFactory.NewParsedPersonInstance();
70
        Assert.assertNotNull(matchStrategy);
71
        Person fullPerson;
72
        Person parsedPerson;
73
        MatchResult result;
74

    
75
        fullPerson = getDefaultFullPerson();
76
        //should match
77
        parsedPerson = getDefaultParsedPerson();
78

    
79
        result = matchStrategy.invoke(parsedPerson, fullPerson);
80
//        System.out.println(result);
81
        Assert.assertTrue("Same nom.title. should match", result.isSuccessful());
82

    
83
        //differing nom. title.
84
        parsedPerson.setNomenclaturalTitle("Wrong");
85
        result = matchStrategy.invoke(fullPerson, parsedPerson, FAIL_ALL);
86
//        System.out.println(result);
87
        Assert.assertFalse("Differing nom.title should not match",
88
                matchStrategy.invoke(parsedPerson, fullPerson).isSuccessful());
89

    
90
        //differing family
91
        parsedPerson = getDefaultParsedPerson();
92
        parsedPerson.setFamilyName("Wrong");
93
        Assert.assertFalse("Differing family name should not match",
94
                matchStrategy.invoke(parsedPerson, fullPerson).isSuccessful());
95
        fullPerson.setFamilyName(null);
96
        Assert.assertFalse("Only parsed with family name should not match. Wrong direction.",
97
                matchStrategy.invoke(parsedPerson, fullPerson).isSuccessful());
98

    
99
        //
100
        parsedPerson = getDefaultParsedPerson();
101
        parsedPerson.setInitials("D.");
102
        Assert.assertFalse("Differing nom. title should not match",
103
                matchStrategy.invoke(fullPerson, parsedPerson).isSuccessful());
104

    
105
        //nom. title. (2)
106
        fullPerson = getDefaultFullPerson();
107
        parsedPerson = getDefaultParsedPerson();
108
        fullPerson.setNomenclaturalTitle("Wro.");
109
        Assert.assertFalse("Differing nom. title should not match",
110
                matchStrategy.invoke(fullPerson, parsedPerson).isSuccessful());
111

    
112
        //collector Title
113
        fullPerson = getDefaultFullPerson();
114
        parsedPerson = getDefaultParsedPerson();
115
        parsedPerson.setCollectorTitle("Collector");
116
        result = matchStrategy.invoke(fullPerson, parsedPerson, FAIL_ALL);
117
//        System.out.println(result);
118
        Assert.assertFalse("Differing collectorTitle should not match",
119
                matchStrategy.invoke(parsedPerson, fullPerson).isSuccessful());
120

    
121
        //fullPerson protected
122
        fullPerson = getDefaultFullPerson();
123
        parsedPerson = getDefaultParsedPerson();
124
        fullPerson.setTitleCache(fullPerson.getTitleCache(), true);
125
        Assert.assertFalse("Differing protected title should not match",
126
                matchStrategy.invoke(fullPerson, parsedPerson).isSuccessful());
127

    
128
        //parsedPerson protected
129
        fullPerson = getDefaultFullPerson();
130
        parsedPerson = getDefaultParsedPerson();
131
        parsedPerson.setTitleCache(parsedPerson.getTitleCache(), true);
132
//        System.out.println(fullPerson.getTitleCache());
133
//        System.out.println(parsedPerson.getTitleCache());
134
        Assert.assertFalse("Differing nom. title should not match",
135
                matchStrategy.invoke(fullPerson, parsedPerson).isSuccessful());
136
    }
137

    
138
    protected Person getDefaultFullPerson() {
139
        Person fullPerson = Person.NewInstance();
140
        fullPerson.setInitials("F.G.");
141
        fullPerson.setFamilyName("Name");
142
        fullPerson.setNomenclaturalTitle("Nam.");
143
        fullPerson.setGivenName("Full Given");
144
        fullPerson.setPrefix("Dr.");
145
        fullPerson.setSuffix("jr.");
146
        fullPerson.setCollectorTitle("Coll.");
147
        fullPerson.setLifespan(TimePeriodParser.parseString("1972-2015"));
148
        fullPerson.addInstitutionalMembership(institution1, TimePeriodParser.parseString("2002-2004"), "Dept. X", "Developer");
149
        fullPerson.updateCaches();
150
        return fullPerson;
151
    }
152

    
153
    protected Person getDefaultParsedPerson() {
154
        Person parsedPerson = Person.NewInstance();
155
        parsedPerson.setNomenclaturalTitle("Nam.");
156
        parsedPerson.updateCaches();
157
        return parsedPerson;
158
    }
159

    
160
    @Test
161
    public void testParsedTeam() throws MatchException {
162

    
163
        IParsedMatchStrategy matchStrategy = MatchStrategyFactory.NewParsedTeamInstance();
164
        Assert.assertNotNull(matchStrategy);
165
        Team fullTeam;
166
        Team parsedTeam;
167
        MatchResult matchResult;
168

    
169
        fullTeam = getDefaultFullTeam();
170
        parsedTeam = getDefaultParsedTeam();
171

    
172
        //should match
173
        Assert.assertTrue("Same nom.title. should match",
174
                matchStrategy.invoke(parsedTeam, fullTeam).isSuccessful());
175

    
176
        //differing nom. title.
177
        parsedTeam.setNomenclaturalTitleCache("Wrong", true);
178
        Assert.assertFalse("Differing nom.title. should not match",
179
                matchStrategy.invoke(parsedTeam, fullTeam).isSuccessful());
180

    
181
        //differing family
182
        parsedTeam = getDefaultParsedTeam();
183
        parsedTeam.getTeamMembers().get(0).setFamilyName("Wrong");
184
        matchResult = matchStrategy.invoke(parsedTeam, fullTeam, true);
185
        Assert.assertFalse("Differing family name should not match", matchResult.isSuccessful());
186
        parsedTeam.getTeamMembers().get(0).setNomenclaturalTitle("Wrong.");
187
        matchResult = matchStrategy.invoke(parsedTeam, fullTeam, true);
188
        System.out.println(matchResult);
189
        Assert.assertFalse("Differing family name should not match", matchResult.isSuccessful());
190

    
191
        //
192
        parsedTeam = getDefaultParsedTeam();
193
        parsedTeam.getTeamMembers().get(0).setInitials("D.");
194
        Assert.assertFalse("Differing nom. title should not match",
195
                matchStrategy.invoke(parsedTeam, fullTeam).isSuccessful());
196

    
197
        //nom. title. (2)
198
        fullTeam = getDefaultFullTeam();
199
        parsedTeam = getDefaultParsedTeam();
200
        fullTeam.setNomenclaturalTitleCache("Wro.", true);
201
        Assert.assertFalse("Differing nom. title should not match",
202
                matchStrategy.invoke(parsedTeam, fullTeam).isSuccessful());
203

    
204
        //fullPerson protected
205
        fullTeam = getDefaultFullTeam();
206
        parsedTeam = getDefaultParsedTeam();
207
        fullTeam.setTitleCache(fullTeam.getTitleCache(), true);
208
        Assert.assertFalse("Differing protected title should not match",
209
                matchStrategy.invoke(parsedTeam, fullTeam).isSuccessful());
210

    
211
        //parsedPerson protected
212
        fullTeam = getDefaultFullTeam();
213
        parsedTeam = getDefaultParsedTeam();
214
        parsedTeam.setTitleCache(parsedTeam.getTitleCache(), true);
215
        Assert.assertFalse("Differing nom. title should not match",
216
                matchStrategy.invoke(parsedTeam, fullTeam).isSuccessful());
217

    
218
        fullTeam = getDefaultFullTeam();
219
        parsedTeam = getDefaultParsedTeam();
220
        fullTeam.setHasMoreMembers(true);
221
        Assert.assertFalse("Differing nom. title should not match",
222
                matchStrategy.invoke(parsedTeam, fullTeam).isSuccessful());
223
    }
224

    
225
    private Team getDefaultFullTeam() {
226
        Team team = Team.NewInstance();
227
        team.addTeamMember(getDefaultFullPerson());
228
        team.addTeamMember(getFullPerson2());
229
        team.updateCaches();
230
        return team;
231
    }
232

    
233

    
234
    protected Person getFullPerson2() {
235
        Person fullPerson = Person.NewInstance();
236
        fullPerson.setInitials("A.B.");
237
        fullPerson.setFamilyName("Nice");
238
        fullPerson.setNomenclaturalTitle("Nice");
239
        fullPerson.setGivenName("John");
240
        fullPerson.updateCaches();
241
        return fullPerson;
242
    }
243

    
244
    private Team getDefaultParsedTeam() {
245
        Team team = Team.NewInstance();
246
        team.addTeamMember(getDefaultParsedPerson());
247
        team.addTeamMember(getFullPerson2());
248
        team.updateCaches();
249
        return team;
250
    }
251

    
252
    protected Person getParsedPerson2() {
253
        Person parsedPerson = Person.NewInstance();
254
        parsedPerson.setNomenclaturalTitle("Nice");
255
        parsedPerson.updateCaches();
256
        return parsedPerson;
257
    }
258

    
259
    @Test
260
    public void testParsedBook() throws MatchException {
261
        IParsedMatchStrategy matchStrategy = MatchStrategyFactory.NewParsedBookInstance();
262
        Assert.assertNotNull(matchStrategy);
263
        IBook fullBook;
264
        IBook parsedBook;
265

    
266
        fullBook = getDefaultFullBook();
267
        parsedBook = getDefaultParsedBook();
268

    
269
        //should match
270
        parsedBook = getDefaultParsedBook();
271
        Assert.assertTrue("Same abbrev. title should match",
272
                matchStrategy.invoke(parsedBook, fullBook).isSuccessful());
273
        fullBook.setDoi(DOI.fromString("10.1234/abc"));
274
        Assert.assertTrue("DOI only with full book should match as abbrev title identifies the book",
275
                matchStrategy.invoke(parsedBook, fullBook).isSuccessful());
276

    
277
        //differing nom. title.
278
        parsedBook.setAbbrevTitle("Wrong");
279
        Assert.assertFalse("Differing abbrev. title. should not match",
280
                matchStrategy.invoke(parsedBook, fullBook).isSuccessful());
281

    
282
        //differing family
283
        parsedBook = getDefaultParsedBook();
284
        parsedBook.setTitle("Wrong title");
285
        Assert.assertFalse("Differing title should not match",
286
                matchStrategy.invoke(parsedBook, fullBook).isSuccessful());
287
        fullBook.setTitle(null);
288
        Assert.assertFalse("Title only for parsed book should not match. Wrong direction.",
289
                matchStrategy.invoke(parsedBook, fullBook).isSuccessful());
290

    
291
        //change author
292
        fullBook = getDefaultFullBook();
293
        parsedBook = getDefaultParsedBook();
294
        ((Team)fullBook.getAuthorship()).getTeamMembers().get(0).setNomenclaturalTitle("Wrong");
295
        Assert.assertFalse("Differing author in nomencl. title should not match",
296
                matchStrategy.invoke(parsedBook, fullBook).isSuccessful());
297

    
298
        //change author
299
        fullBook = getDefaultFullBook();
300
        parsedBook = getDefaultParsedBook();
301
        ((Team)fullBook.getAuthorship()).getTeamMembers().get(0).setFamilyName("Changed");
302
        Assert.assertTrue("Full book family name author changed should still match",
303
                matchStrategy.invoke(parsedBook, fullBook).isSuccessful());
304
    }
305

    
306
    @Test
307
    public void testParsedBookSection() throws MatchException {
308
        IParsedMatchStrategy matchStrategy = MatchStrategyFactory.NewParsedBookSectionInstance();
309
        Assert.assertNotNull(matchStrategy);
310
        IBookSection fullBookSection;
311
        IBookSection parsedBookSection;
312

    
313
        fullBookSection = getMatchingFullBookSection();
314
        parsedBookSection = getDefaultParsedBookSection();
315
        Assert.assertTrue("Only author, book and date published should match",
316
                matchStrategy.invoke(parsedBookSection, fullBookSection).isSuccessful() );
317
        fullBookSection.setDoi(DOI.fromString("10.1234/abc"));
318
        Assert.assertFalse("Full book section having additional parameters should not match if parsed article has no identifying parameter like (abbrev)title or page",
319
                matchStrategy.invoke(parsedBookSection, fullBookSection).isSuccessful());
320
        fullBookSection.setDoi(null);
321
        fullBookSection.setReferenceAbstract("My abstract");
322
        Assert.assertFalse("Full book section having additional parameters should not match if parsed article has no identifying parameter like (abbrev)title or page",
323
                matchStrategy.invoke(parsedBookSection, fullBookSection).isSuccessful());
324

    
325
        //should match
326
        fullBookSection = getDefaultFullBookSection();
327
        Assert.assertFalse("Abbrev. title must be equal or null",
328
                matchStrategy.invoke(fullBookSection, parsedBookSection).isSuccessful());
329
        parsedBookSection.setAbbrevTitle(fullBookSection.getAbbrevTitle());
330
        Assert.assertFalse("Still not match because pages are not equal (parsed is null)",
331
                matchStrategy.invoke(parsedBookSection, fullBookSection).isSuccessful());
332
        parsedBookSection.setPages(fullBookSection.getPages());
333
        Assert.assertFalse("Now they should match",
334
                matchStrategy.invoke(parsedBookSection, fullBookSection).isSuccessful());
335

    
336
        //differing nom. title.
337
        parsedBookSection.setAbbrevTitle("Wrong");
338
        Assert.assertFalse("Differing abbrev. title. should not match",
339
                matchStrategy.invoke(parsedBookSection, fullBookSection).isSuccessful());
340

    
341
        //differing family
342
        parsedBookSection = getDefaultParsedBookSection();
343
        parsedBookSection.setTitle("Wrong title");
344
        Assert.assertFalse("Differing title should not match",
345
                matchStrategy.invoke(parsedBookSection, fullBookSection).isSuccessful());
346
        fullBookSection.setTitle(null);
347
        Assert.assertFalse("Title only for parsed book should not match. Wrong direction.",
348
                matchStrategy.invoke(parsedBookSection, fullBookSection).isSuccessful());
349

    
350
        //change author
351
        fullBookSection = getMatchingFullBookSection();
352
        parsedBookSection = getDefaultParsedBookSection();
353
        fullBookSection.getAuthorship().setNomenclaturalTitleCache("Wrong", true);
354
        Assert.assertFalse("Differing author in nomencl. title should not match",
355
                matchStrategy.invoke(parsedBookSection, fullBookSection).isSuccessful());
356

    
357
        //change author
358
        fullBookSection = getMatchingFullBookSection();
359
        parsedBookSection = getDefaultParsedBookSection();
360
        ((Person)fullBookSection.getAuthorship()).setFamilyName("Changed");
361
        Assert.assertTrue("Full book family name author changed should still match",
362
                matchStrategy.invoke(parsedBookSection, fullBookSection).isSuccessful());
363
    }
364

    
365
    private IBook getDefaultFullBook() {
366
        IBook book = getDefaultParsedBook();
367
        book.setAuthorship(getDefaultFullTeam());
368
        book.setTitle("Flora Hellenica");
369
        book.setUri(URI.create("https://www.flora.hellenica.gr"));
370
        book.setIsbn("1234-222-222-333");  //format not yet correct
371
        book.setPublisher("Greek publisher", "Athens");
372
        ((Reference)book).updateCaches();
373
        return book;
374
    }
375

    
376
    private IBook getDefaultParsedBook() {
377
        IBook book = ReferenceFactory.newBook();
378
        book.setAbbrevTitle("Fl. Hell.");
379
        book.setVolume("2");
380
        book.setEdition("ed. 3");
381
        book.setEditor("editor");
382
        book.setAuthorship(getDefaultParsedTeam());
383
        book.setDatePublished(TimePeriodParser.parseStringVerbatim("1982-10-06"));
384
        ((Reference)book).updateCaches();
385
        return book;
386
    }
387

    
388
    private IBookSection getDefaultFullBookSection() {
389
        IBookSection bookSection = getMatchingFullBookSection();
390
        bookSection.setTitle("Book section title");
391
        bookSection.setAbbrevTitle("Bk. sct. tit.");
392
        bookSection.setPages("22-33");
393
        ((Reference)bookSection).updateCaches();
394
        return bookSection;
395
    }
396

    
397
    private IBookSection getMatchingFullBookSection() {
398
        IBookSection bookSection = ReferenceFactory.newBookSection();
399
        bookSection.setAuthorship(getDefaultFullPerson());
400
        bookSection.setInBook(getDefaultFullBook());
401
        bookSection.setDatePublished(TimePeriodParser.parseStringVerbatim("1892"));
402
        ((Reference)bookSection).updateCaches();
403
        return bookSection;
404
    }
405

    
406
    private IBookSection getDefaultParsedBookSection() {
407
        IBookSection bookSection = ReferenceFactory.newBookSection();
408
        bookSection.setAuthorship(getDefaultParsedPerson());
409
        bookSection.setInBook(getDefaultParsedBook());
410
        bookSection.setDatePublished(TimePeriodParser.parseStringVerbatim("1892"));
411
        ((Reference)bookSection).updateCaches();
412
        return bookSection;
413
    }
414

    
415
    @Test
416
    public void testParsedArticle() throws MatchException {
417

    
418
        IParsedMatchStrategy matchStrategy = MatchStrategyFactory.NewParsedArticleInstance();
419
        Assert.assertNotNull(matchStrategy);
420
        IArticle fullArticle;
421
        IArticle parsedArticle;
422

    
423
        fullArticle = getMatchingFullArticle();
424
        parsedArticle = getDefaultParsedArticle();
425
        Assert.assertTrue("Having only paramters both have in common like author, book and date published "
426
                + "should match", matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
427
        fullArticle.setDoi(DOI.fromString("10.1234/abc"));
428
        Assert.assertFalse("Full article having additional parameters should not match if parsed article has no identifying parameter like (abbrev)title or page",
429
                matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
430

    
431
        //no match due to missing abbrev title match
432
        fullArticle = getDefaultFullArticle();
433
        Assert.assertFalse("Abbrev. title must be equal or null", matchStrategy.invoke(parsedArticle,
434
                fullArticle).isSuccessful());
435
        parsedArticle.setAbbrevTitle(fullArticle.getAbbrevTitle());
436
        Assert.assertFalse("Still not match because pages are not equal (parsed is null)",
437
                matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
438
        //FIXME in future this should not fail, but parsed articles never have really pages, they only have page or a page span in the parsed detail which is not the same as the pages of the article
439
        parsedArticle.setPages(fullArticle.getPages());
440
        Assert.assertFalse("Now they should match",
441
                matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
442

    
443
        //differing nom. title.
444
        parsedArticle.setAbbrevTitle("Wrong");
445
        Assert.assertFalse("Differing abbrev. title. should not match",
446
                matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
447

    
448
        //differing family
449
        parsedArticle = getDefaultParsedArticle();
450
        parsedArticle.setTitle("Wrong title");
451
        Assert.assertFalse("Differing title should not match",
452
                matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
453
        fullArticle.setTitle(null);
454
        Assert.assertFalse("Title only for parsed book should not match. Wrong direction.",
455
                matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
456

    
457
        //change author
458
        fullArticle = getMatchingFullArticle();
459
        parsedArticle = getDefaultParsedArticle();
460
        fullArticle.getAuthorship().setNomenclaturalTitleCache("Wrong", true);
461
        Assert.assertFalse("Differing author in nomencl. title should not match",
462
                matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
463

    
464
        //change author
465
        fullArticle = getMatchingFullArticle();
466
        parsedArticle = getDefaultParsedArticle();
467
        ((Team)fullArticle.getAuthorship()).getTeamMembers().get(0).setFamilyName("Changed");
468
        Assert.assertTrue("Full book family name author changed should still match",
469
                matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
470
    }
471

    
472
    /**
473
     * Like {@link #getMatchingFullArticle() matching full article} with additional
474
     * title, abbrevTitle and pages
475
     */
476
    private IArticle getDefaultFullArticle() {
477
        IArticle article = getMatchingFullArticle();
478
        article.setTitle("Article title");
479
        article.setAbbrevTitle("Art. tit.");
480
        article.setPages("22-33");
481
        ((Reference)article).updateCaches();
482
        return article;
483
    }
484

    
485
    /**
486
     * Article with {@link #getDefaultFullTeam() full team},
487
     * {@link #getDefaultFullJournal() full journal} and date published
488
     */
489
    private IArticle getMatchingFullArticle() {
490
        IArticle article = ReferenceFactory.newArticle();
491
        article.setAuthorship(getDefaultFullTeam());
492
        article.setInJournal(getDefaultFullJournal());
493
        article.setDatePublished(TimePeriodParser.parseStringVerbatim("1950"));
494
        ((Reference)article).updateCaches();
495
        return article;
496
    }
497

    
498
    /**
499
     * Article with {@link #getDefaultParsedTeam() parsed authorship},
500
     * {@link #getDefaultParsedJournal() parsed journal} and date published.
501
     */
502
    private IArticle getDefaultParsedArticle() {
503
        IArticle article = ReferenceFactory.newArticle();
504
        article.setAuthorship(getDefaultParsedTeam());
505
        article.setInJournal(getDefaultParsedJournal());
506
        article.setDatePublished(TimePeriodParser.parseStringVerbatim("1950"));
507
        ((Reference)article).updateCaches();
508
        return article;
509
    }
510

    
511
    private IJournal getDefaultFullJournal() {
512
        IJournal journal = getDefaultParsedJournal();
513
//        journal.setAuthorship(getDefaultFullTeam()); //journals should not have authors
514
        journal.setTitle("J. Flow. Pl.");
515
        journal.setUri(URI.create("https://www.journal-flowering-plants.gr"));
516
        journal.setIssn("1234-222-222-333");  //format not yet correct
517
        journal.setPublisher("Botanical publisher", "Paris");
518
        ((Reference)journal).updateCaches();
519
        return journal;
520
    }
521

    
522
    private IJournal getDefaultParsedJournal() {
523
        IJournal journal = ReferenceFactory.newJournal();
524
        journal.setAbbrevTitle("Fl. Hell.");
525
//        journal.setAuthorship(getDefaultParsedTeam());  //journals should not have authors
526
//        ((Reference)journal).setDatePublished(TimePeriodParser.parseStringVerbatim("1992-04-03")); //journals should not have date published
527
        ((Reference)journal).updateCaches();
528
        return journal;
529
    }
530

    
531
    @Test
532
    public void testParsedReference() throws MatchException {
533
        IParsedMatchStrategy matchStrategy = MatchStrategyFactory.NewParsedReferenceInstance();
534
        Assert.assertNotNull(matchStrategy);
535
        IArticle fullArticle;
536
        IArticle parsedArticle;
537

    
538
        fullArticle = getMatchingFullArticle();
539
        parsedArticle = getDefaultParsedArticle();
540
        Assert.assertTrue("Only author, book and date published should match", matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful() );
541

    
542
        //should match
543
        fullArticle = getDefaultFullArticle();
544
        Assert.assertFalse("Abbrev. title must be equal or null", matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
545
        parsedArticle.setAbbrevTitle(fullArticle.getAbbrevTitle());
546
        Assert.assertFalse("Still not match because pages are not equal (parsed is null)", matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
547
        parsedArticle.setPages(fullArticle.getPages());
548
        Assert.assertFalse("Now they should match", matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
549

    
550
        //differing nom. title.
551
        parsedArticle.setAbbrevTitle("Wrong");
552
        Assert.assertFalse("Differing abbrev. title. should not match", matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
553

    
554
        //differing family
555
        parsedArticle = getDefaultParsedArticle();
556
        parsedArticle.setTitle("Wrong title");
557
        Assert.assertFalse("Differing title should not match", matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
558
        fullArticle.setTitle(null);
559
        Assert.assertFalse("Title only for parsed book should not match. Wrong direction.", matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
560

    
561
        //change author
562
        fullArticle = getMatchingFullArticle();
563
        parsedArticle = getDefaultParsedArticle();
564
        fullArticle.getAuthorship().setNomenclaturalTitleCache("Wrong", true);
565
        Assert.assertFalse("Differing author in nomencl. title should not match", matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
566

    
567
        //change author
568
        fullArticle = getMatchingFullArticle();
569
        parsedArticle = getDefaultParsedArticle();
570
        ((Team)fullArticle.getAuthorship()).getTeamMembers().get(0).setFamilyName("Changed");
571
        Assert.assertTrue("Full book family name author changed should still match", matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
572
    }
573

    
574
    /**
575
     * Article with {@link #getDefaultFullTeam() full team},
576
     * {@link #getDefaultFullJournal() full journal} and date published
577
     */
578
    private TaxonName getDefaultFullName() {
579
        TaxonName name = getDefaultParsedName();
580
        name.setNameApprobation("approbation");
581
        TaxonNameDescription description = TaxonNameDescription.NewInstance(name);
582
        description.addElement(Distribution.NewInstance());
583
        //TODO continue
584
        name.updateCaches();
585
        return name;
586
    }
587

    
588
    private TaxonName getDefaultParsedName() {
589
        TaxonName name = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
590
        name.setBasionymAuthorship(getDefaultFullTeam());
591
        name.setGenusOrUninomial("Abies");
592
        name.setSpecificEpithet("alba");
593
        name.updateCaches();
594
        return name;
595
    }
596

    
597
    @Test
598
    public void testParsedOriginalSpelling() throws MatchException {
599
        IParsedMatchStrategy matchStrategy = MatchStrategyFactory.NewParsedOriginalSpellingInstance();
600
        Assert.assertNotNull(matchStrategy);
601

    
602
        TaxonName fullName = getDefaultFullName();
603
        TaxonName parsedName = getDefaultParsedName();
604
        Assert.assertTrue("Only ... should match", matchStrategy.invoke(parsedName, fullName).isSuccessful() );
605

    
606
        //TODO
607
    }
608
}
(2-2/2)