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 java.net.URI;
|
12
|
|
13
|
import org.apache.log4j.Logger;
|
14
|
import org.junit.Assert;
|
15
|
import org.junit.Before;
|
16
|
import org.junit.BeforeClass;
|
17
|
import org.junit.Test;
|
18
|
|
19
|
import eu.etaxonomy.cdm.common.DOI;
|
20
|
import eu.etaxonomy.cdm.model.agent.Institution;
|
21
|
import eu.etaxonomy.cdm.model.agent.Person;
|
22
|
import eu.etaxonomy.cdm.model.agent.Team;
|
23
|
import eu.etaxonomy.cdm.model.reference.IArticle;
|
24
|
import eu.etaxonomy.cdm.model.reference.IBook;
|
25
|
import eu.etaxonomy.cdm.model.reference.IBookSection;
|
26
|
import eu.etaxonomy.cdm.model.reference.IJournal;
|
27
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
28
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
29
|
import eu.etaxonomy.cdm.model.term.DefaultTermInitializer;
|
30
|
import eu.etaxonomy.cdm.strategy.parser.TimePeriodParser;
|
31
|
|
32
|
/**
|
33
|
* Test class for {@link MatchStrategyFactory}
|
34
|
*
|
35
|
* @author a.mueller
|
36
|
* @since 03.08.2009
|
37
|
*/
|
38
|
public class MatchStrategyFactoryTest {
|
39
|
|
40
|
@SuppressWarnings("unused")
|
41
|
private static final Logger logger = Logger.getLogger(MatchStrategyFactoryTest.class);
|
42
|
|
43
|
private static boolean FAIL_ALL = true;
|
44
|
|
45
|
private IMatchStrategyEqual matchStrategy;
|
46
|
|
47
|
private Institution institution1;
|
48
|
|
49
|
@BeforeClass
|
50
|
public static void setUpBeforeClass() throws Exception {
|
51
|
DefaultTermInitializer termInitializer = new DefaultTermInitializer();
|
52
|
termInitializer.initialize();
|
53
|
}
|
54
|
|
55
|
@Before
|
56
|
public void setUp() throws Exception {
|
57
|
|
58
|
institution1 = Institution.NewNamedInstance("Institution1");
|
59
|
|
60
|
}
|
61
|
|
62
|
//********************* TEST *********************************************/
|
63
|
|
64
|
@Test
|
65
|
public void testNewInstance() {
|
66
|
matchStrategy = MatchStrategyFactory.NewDefaultInstance(Reference.class);
|
67
|
Assert.assertNotNull(matchStrategy);
|
68
|
// Assert.assertEquals(Reference.class, matchStrategy.getMatchClass());
|
69
|
}
|
70
|
|
71
|
@Test
|
72
|
public void testParsedPerson() throws MatchException {
|
73
|
IParsedMatchStrategy matchStrategy = MatchStrategyFactory.NewParsedPersonInstance();
|
74
|
Assert.assertNotNull(matchStrategy);
|
75
|
Person fullPerson;
|
76
|
Person parsedPerson;
|
77
|
MatchResult result;
|
78
|
|
79
|
fullPerson = getDefaultFullPerson();
|
80
|
|
81
|
//should match
|
82
|
parsedPerson = getDefaultParsedPerson();
|
83
|
result = matchStrategy.invoke(parsedPerson, fullPerson);
|
84
|
System.out.println(result);
|
85
|
Assert.assertTrue("Same nom.title. should match", result.isSuccessful());
|
86
|
|
87
|
//differing nom. title.
|
88
|
parsedPerson.setNomenclaturalTitle("Wrong");
|
89
|
result = matchStrategy.invoke(fullPerson, parsedPerson, FAIL_ALL);
|
90
|
System.out.println(result);
|
91
|
Assert.assertFalse("Differing nom.title. should not match",
|
92
|
matchStrategy.invoke(parsedPerson, fullPerson).isSuccessful());
|
93
|
|
94
|
//differing family
|
95
|
parsedPerson = getDefaultParsedPerson();
|
96
|
parsedPerson.setFamilyName("Wrong");
|
97
|
Assert.assertFalse("Differing family name should not match",
|
98
|
matchStrategy.invoke(parsedPerson, fullPerson).isSuccessful());
|
99
|
fullPerson.setFamilyName(null);
|
100
|
Assert.assertFalse("Only parsed with family name should not match. Wrong direction.",
|
101
|
matchStrategy.invoke(parsedPerson, fullPerson).isSuccessful());
|
102
|
|
103
|
//
|
104
|
parsedPerson = getDefaultParsedPerson();
|
105
|
parsedPerson.setInitials("D.");
|
106
|
Assert.assertFalse("Differing nom. title should not match",
|
107
|
matchStrategy.invoke(fullPerson, parsedPerson).isSuccessful());
|
108
|
|
109
|
//nom. title. (2)
|
110
|
fullPerson = getDefaultFullPerson();
|
111
|
parsedPerson = getDefaultParsedPerson();
|
112
|
fullPerson.setNomenclaturalTitle("Wro.");
|
113
|
Assert.assertFalse("Differing nom. title should not match",
|
114
|
matchStrategy.invoke(fullPerson, parsedPerson).isSuccessful());
|
115
|
|
116
|
//fullPerson protected
|
117
|
fullPerson = getDefaultFullPerson();
|
118
|
parsedPerson = getDefaultParsedPerson();
|
119
|
fullPerson.setTitleCache(fullPerson.getTitleCache(), true);
|
120
|
Assert.assertFalse("Differing protected title should not match",
|
121
|
matchStrategy.invoke(fullPerson, parsedPerson).isSuccessful());
|
122
|
|
123
|
//parsedPerson protected
|
124
|
fullPerson = getDefaultFullPerson();
|
125
|
parsedPerson = getDefaultParsedPerson();
|
126
|
parsedPerson.setTitleCache(parsedPerson.getTitleCache(), true);
|
127
|
// System.out.println(fullPerson.getTitleCache());
|
128
|
// System.out.println(parsedPerson.getTitleCache());
|
129
|
Assert.assertFalse("Differing nom. title should not match",
|
130
|
matchStrategy.invoke(fullPerson, parsedPerson).isSuccessful());
|
131
|
}
|
132
|
|
133
|
protected Person getDefaultFullPerson() {
|
134
|
Person fullPerson = Person.NewInstance();
|
135
|
fullPerson.setInitials("F.G.");
|
136
|
fullPerson.setFamilyName("Name");
|
137
|
fullPerson.setNomenclaturalTitle("Nam.");
|
138
|
fullPerson.setGivenName("Full Given");
|
139
|
fullPerson.setPrefix("Dr.");
|
140
|
fullPerson.setSuffix("jr.");
|
141
|
// fullPerson.setCollectorTitle();
|
142
|
fullPerson.setLifespan(TimePeriodParser.parseString("1972-2015"));
|
143
|
fullPerson.addInstitutionalMembership(institution1, TimePeriodParser.parseString("2002-2004"), "Dept. X", "Developer");
|
144
|
return fullPerson;
|
145
|
}
|
146
|
|
147
|
protected Person getDefaultParsedPerson() {
|
148
|
Person parsedPerson = Person.NewInstance();
|
149
|
parsedPerson.setNomenclaturalTitle("Nam.");
|
150
|
return parsedPerson;
|
151
|
}
|
152
|
|
153
|
@Test
|
154
|
public void testParsedTeam() throws MatchException {
|
155
|
IParsedMatchStrategy matchStrategy = MatchStrategyFactory.NewParsedTeamInstance();
|
156
|
Assert.assertNotNull(matchStrategy);
|
157
|
Team fullTeam;
|
158
|
Team parsedTeam;
|
159
|
MatchResult matchResult;
|
160
|
|
161
|
fullTeam = getDefaultFullTeam();
|
162
|
parsedTeam = getDefaultParsedTeam();
|
163
|
|
164
|
//should match
|
165
|
Assert.assertTrue("Same nom.title. should match",
|
166
|
matchStrategy.invoke(parsedTeam, fullTeam).isSuccessful());
|
167
|
|
168
|
//differing nom. title.
|
169
|
parsedTeam.setNomenclaturalTitle("Wrong");
|
170
|
Assert.assertFalse("Differing nom.title. should not match",
|
171
|
matchStrategy.invoke(parsedTeam, fullTeam).isSuccessful());
|
172
|
|
173
|
//differing family
|
174
|
parsedTeam = getDefaultParsedTeam();
|
175
|
parsedTeam.getTeamMembers().get(0).setFamilyName("Wrong");
|
176
|
matchResult = matchStrategy.invoke(parsedTeam, fullTeam, true);
|
177
|
Assert.assertFalse("Differing family name should not match", matchResult.isSuccessful());
|
178
|
parsedTeam.getTeamMembers().get(0).setNomenclaturalTitle("Wrong.");
|
179
|
matchResult = matchStrategy.invoke(parsedTeam, fullTeam, true);
|
180
|
System.out.println(matchResult);
|
181
|
Assert.assertFalse("Differing family name should not match", matchResult.isSuccessful());
|
182
|
|
183
|
//
|
184
|
parsedTeam = getDefaultParsedTeam();
|
185
|
parsedTeam.getTeamMembers().get(0).setInitials("D.");
|
186
|
Assert.assertFalse("Differing nom. title should not match",
|
187
|
matchStrategy.invoke(parsedTeam, fullTeam).isSuccessful());
|
188
|
|
189
|
//nom. title. (2)
|
190
|
fullTeam = getDefaultFullTeam();
|
191
|
parsedTeam = getDefaultParsedTeam();
|
192
|
fullTeam.setNomenclaturalTitle("Wro.");
|
193
|
Assert.assertFalse("Differing nom. title should not match",
|
194
|
matchStrategy.invoke(parsedTeam, fullTeam).isSuccessful());
|
195
|
|
196
|
//fullPerson protected
|
197
|
fullTeam = getDefaultFullTeam();
|
198
|
parsedTeam = getDefaultParsedTeam();
|
199
|
fullTeam.setTitleCache(fullTeam.getTitleCache(), true);
|
200
|
Assert.assertFalse("Differing protected title should not match",
|
201
|
matchStrategy.invoke(parsedTeam, fullTeam).isSuccessful());
|
202
|
|
203
|
//parsedPerson protected
|
204
|
fullTeam = getDefaultFullTeam();
|
205
|
parsedTeam = getDefaultParsedTeam();
|
206
|
parsedTeam.setTitleCache(parsedTeam.getTitleCache(), true);
|
207
|
Assert.assertFalse("Differing nom. title should not match",
|
208
|
matchStrategy.invoke(parsedTeam, fullTeam).isSuccessful());
|
209
|
|
210
|
fullTeam = getDefaultFullTeam();
|
211
|
parsedTeam = getDefaultParsedTeam();
|
212
|
fullTeam.setHasMoreMembers(true);
|
213
|
Assert.assertFalse("Differing nom. title should not match",
|
214
|
matchStrategy.invoke(parsedTeam, fullTeam).isSuccessful());
|
215
|
}
|
216
|
|
217
|
private Team getDefaultFullTeam() {
|
218
|
Team team = Team.NewInstance();
|
219
|
team.addTeamMember(getDefaultFullPerson());
|
220
|
team.addTeamMember(getFullPerson2());
|
221
|
team.getNomenclaturalTitle();
|
222
|
return team;
|
223
|
}
|
224
|
|
225
|
|
226
|
protected Person getFullPerson2() {
|
227
|
Person fullPerson = Person.NewInstance();
|
228
|
fullPerson.setInitials("A.B.");
|
229
|
fullPerson.setFamilyName("Nice");
|
230
|
fullPerson.setNomenclaturalTitle("Nice");
|
231
|
fullPerson.setGivenName("John");
|
232
|
return fullPerson;
|
233
|
}
|
234
|
|
235
|
private Team getDefaultParsedTeam() {
|
236
|
Team team = Team.NewInstance();
|
237
|
team.addTeamMember(getDefaultParsedPerson());
|
238
|
team.addTeamMember(getFullPerson2());
|
239
|
//TODO should be done in cache strategy
|
240
|
team.getNomenclaturalTitle();
|
241
|
return team;
|
242
|
}
|
243
|
|
244
|
protected Person getParsedPerson2() {
|
245
|
Person parsedPerson = Person.NewInstance();
|
246
|
parsedPerson.setNomenclaturalTitle("Nice");
|
247
|
return parsedPerson;
|
248
|
}
|
249
|
|
250
|
@Test
|
251
|
public void testParsedBook() throws MatchException {
|
252
|
IParsedMatchStrategy matchStrategy = MatchStrategyFactory.NewParsedBookInstance();
|
253
|
Assert.assertNotNull(matchStrategy);
|
254
|
IBook fullBook;
|
255
|
IBook parsedBook;
|
256
|
|
257
|
fullBook = getDefaultFullBook();
|
258
|
parsedBook = getDefaultParsedBook();
|
259
|
|
260
|
//should match
|
261
|
parsedBook = getDefaultParsedBook();
|
262
|
Assert.assertTrue("Same abbrev. title should match",
|
263
|
matchStrategy.invoke(parsedBook, fullBook).isSuccessful());
|
264
|
fullBook.setDoi(DOI.fromString("10.1234/abc"));
|
265
|
Assert.assertTrue("DOI only with full book should match as abbrev title identifies the book",
|
266
|
matchStrategy.invoke(parsedBook, fullBook).isSuccessful());
|
267
|
|
268
|
//differing nom. title.
|
269
|
parsedBook.setAbbrevTitle("Wrong");
|
270
|
Assert.assertFalse("Differing abbrev. title. should not match",
|
271
|
matchStrategy.invoke(parsedBook, fullBook).isSuccessful());
|
272
|
|
273
|
//differing family
|
274
|
parsedBook = getDefaultParsedBook();
|
275
|
parsedBook.setTitle("Wrong title");
|
276
|
Assert.assertFalse("Differing title should not match",
|
277
|
matchStrategy.invoke(parsedBook, fullBook).isSuccessful());
|
278
|
fullBook.setTitle(null);
|
279
|
Assert.assertFalse("Title only for parsed book should not match. Wrong direction.",
|
280
|
matchStrategy.invoke(parsedBook, fullBook).isSuccessful());
|
281
|
|
282
|
//change author
|
283
|
fullBook = getDefaultFullBook();
|
284
|
parsedBook = getDefaultParsedBook();
|
285
|
((Team)fullBook.getAuthorship()).getTeamMembers().get(0).setNomenclaturalTitle("Wrong");
|
286
|
Assert.assertFalse("Differing author in nomencl. title should not match",
|
287
|
matchStrategy.invoke(parsedBook, fullBook).isSuccessful());
|
288
|
|
289
|
//change author
|
290
|
fullBook = getDefaultFullBook();
|
291
|
parsedBook = getDefaultParsedBook();
|
292
|
((Team)fullBook.getAuthorship()).getTeamMembers().get(0).setFamilyName("Changed");
|
293
|
Assert.assertTrue("Full book family name author changed should still match",
|
294
|
matchStrategy.invoke(parsedBook, fullBook).isSuccessful());
|
295
|
}
|
296
|
|
297
|
@Test
|
298
|
public void testParsedBookSection() throws MatchException {
|
299
|
IParsedMatchStrategy matchStrategy = MatchStrategyFactory.NewParsedBookSectionInstance();
|
300
|
Assert.assertNotNull(matchStrategy);
|
301
|
IBookSection fullBookSection;
|
302
|
IBookSection parsedBookSection;
|
303
|
|
304
|
fullBookSection = getMatchingFullBookSection();
|
305
|
parsedBookSection = getDefaultParsedBookSection();
|
306
|
Assert.assertTrue("Only author, book and date published should match",
|
307
|
matchStrategy.invoke(parsedBookSection, fullBookSection).isSuccessful() );
|
308
|
fullBookSection.setDoi(DOI.fromString("10.1234/abc"));
|
309
|
Assert.assertFalse("Full book section having additional parameters should not match if parsed article has no identifying parameter like (abbrev)title or page",
|
310
|
matchStrategy.invoke(parsedBookSection, fullBookSection).isSuccessful());
|
311
|
fullBookSection.setDoi(null);
|
312
|
fullBookSection.setReferenceAbstract("My abstract");
|
313
|
Assert.assertFalse("Full book section having additional parameters should not match if parsed article has no identifying parameter like (abbrev)title or page",
|
314
|
matchStrategy.invoke(parsedBookSection, fullBookSection).isSuccessful());
|
315
|
|
316
|
//should match
|
317
|
fullBookSection = getDefaultFullBookSection();
|
318
|
Assert.assertFalse("Abbrev. title must be equal or null",
|
319
|
matchStrategy.invoke(fullBookSection, parsedBookSection).isSuccessful());
|
320
|
parsedBookSection.setAbbrevTitle(fullBookSection.getAbbrevTitle());
|
321
|
Assert.assertFalse("Still not match because pages are not equal (parsed is null)",
|
322
|
matchStrategy.invoke(parsedBookSection, fullBookSection).isSuccessful());
|
323
|
parsedBookSection.setPages(fullBookSection.getPages());
|
324
|
Assert.assertFalse("Now they should match",
|
325
|
matchStrategy.invoke(parsedBookSection, fullBookSection).isSuccessful());
|
326
|
|
327
|
//differing nom. title.
|
328
|
parsedBookSection.setAbbrevTitle("Wrong");
|
329
|
Assert.assertFalse("Differing abbrev. title. should not match",
|
330
|
matchStrategy.invoke(parsedBookSection, fullBookSection).isSuccessful());
|
331
|
|
332
|
//differing family
|
333
|
parsedBookSection = getDefaultParsedBookSection();
|
334
|
parsedBookSection.setTitle("Wrong title");
|
335
|
Assert.assertFalse("Differing title should not match",
|
336
|
matchStrategy.invoke(parsedBookSection, fullBookSection).isSuccessful());
|
337
|
fullBookSection.setTitle(null);
|
338
|
Assert.assertFalse("Title only for parsed book should not match. Wrong direction.",
|
339
|
matchStrategy.invoke(parsedBookSection, fullBookSection).isSuccessful());
|
340
|
|
341
|
//change author
|
342
|
fullBookSection = getMatchingFullBookSection();
|
343
|
parsedBookSection = getDefaultParsedBookSection();
|
344
|
fullBookSection.getAuthorship().setNomenclaturalTitle("Wrong");
|
345
|
Assert.assertFalse("Differing author in nomencl. title should not match",
|
346
|
matchStrategy.invoke(parsedBookSection, fullBookSection).isSuccessful());
|
347
|
|
348
|
//change author
|
349
|
fullBookSection = getMatchingFullBookSection();
|
350
|
parsedBookSection = getDefaultParsedBookSection();
|
351
|
((Person)fullBookSection.getAuthorship()).setFamilyName("Changed");
|
352
|
Assert.assertTrue("Full book family name author changed should still match",
|
353
|
matchStrategy.invoke(parsedBookSection, fullBookSection).isSuccessful());
|
354
|
}
|
355
|
|
356
|
private IBook getDefaultFullBook() {
|
357
|
IBook book = getDefaultParsedBook();
|
358
|
book.setAuthorship(getDefaultFullTeam());
|
359
|
book.setTitle("Flora Hellenica");
|
360
|
book.setUri(URI.create("https://www.flora.hellenica.gr"));
|
361
|
book.setIsbn("1234-222-222-333"); //format not yet correct
|
362
|
book.setPublisher("Greek publisher", "Athens");
|
363
|
book.getTitleCache();
|
364
|
return book;
|
365
|
}
|
366
|
|
367
|
private IBook getDefaultParsedBook() {
|
368
|
IBook book = ReferenceFactory.newBook();
|
369
|
book.setAbbrevTitle("Fl. Hell.");
|
370
|
book.setVolume("2");
|
371
|
book.setEdition("ed. 3");
|
372
|
book.setEditor("editor");
|
373
|
book.setAuthorship(getDefaultParsedTeam());
|
374
|
book.setDatePublished(TimePeriodParser.parseStringVerbatim("1982-10-06"));
|
375
|
book.getAbbrevTitleCache();
|
376
|
return book;
|
377
|
}
|
378
|
|
379
|
private IBookSection getDefaultFullBookSection() {
|
380
|
IBookSection bookSection = getMatchingFullBookSection();
|
381
|
bookSection.setTitle("Book section title");
|
382
|
bookSection.setAbbrevTitle("Bk. sct. tit.");
|
383
|
bookSection.setPages("22-33");
|
384
|
return bookSection;
|
385
|
}
|
386
|
|
387
|
private IBookSection getMatchingFullBookSection() {
|
388
|
IBookSection bookSection = ReferenceFactory.newBookSection();
|
389
|
bookSection.setAuthorship(getDefaultFullPerson());
|
390
|
bookSection.setInBook(getDefaultFullBook());
|
391
|
bookSection.setDatePublished(TimePeriodParser.parseStringVerbatim("1892"));
|
392
|
return bookSection;
|
393
|
}
|
394
|
|
395
|
private IBookSection getDefaultParsedBookSection() {
|
396
|
IBookSection bookSection = ReferenceFactory.newBookSection();
|
397
|
bookSection.setAuthorship(getDefaultParsedPerson());
|
398
|
bookSection.setInBook(getDefaultParsedBook());
|
399
|
bookSection.setDatePublished(TimePeriodParser.parseStringVerbatim("1892"));
|
400
|
return bookSection;
|
401
|
}
|
402
|
|
403
|
@Test
|
404
|
public void testParsedArticle() throws MatchException {
|
405
|
|
406
|
IParsedMatchStrategy matchStrategy = MatchStrategyFactory.NewParsedArticleInstance();
|
407
|
Assert.assertNotNull(matchStrategy);
|
408
|
IArticle fullArticle;
|
409
|
IArticle parsedArticle;
|
410
|
|
411
|
fullArticle = getMatchingFullArticle();
|
412
|
parsedArticle = getDefaultParsedArticle();
|
413
|
Assert.assertTrue("Having only paramters both have in common like author, book and date published "
|
414
|
+ "should match", matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
|
415
|
fullArticle.setDoi(DOI.fromString("10.1234/abc"));
|
416
|
Assert.assertFalse("Full article having additional parameters should not match if parsed article has no identifying parameter like (abbrev)title or page",
|
417
|
matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
|
418
|
|
419
|
//no match due to missing abbrev title match
|
420
|
fullArticle = getDefaultFullArticle();
|
421
|
Assert.assertFalse("Abbrev. title must be equal or null", matchStrategy.invoke(parsedArticle,
|
422
|
fullArticle).isSuccessful());
|
423
|
parsedArticle.setAbbrevTitle(fullArticle.getAbbrevTitle());
|
424
|
Assert.assertFalse("Still not match because pages are not equal (parsed is null)",
|
425
|
matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
|
426
|
//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
|
427
|
parsedArticle.setPages(fullArticle.getPages());
|
428
|
Assert.assertFalse("Now they should match",
|
429
|
matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
|
430
|
|
431
|
//differing nom. title.
|
432
|
parsedArticle.setAbbrevTitle("Wrong");
|
433
|
Assert.assertFalse("Differing abbrev. title. should not match",
|
434
|
matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
|
435
|
|
436
|
//differing family
|
437
|
parsedArticle = getDefaultParsedArticle();
|
438
|
parsedArticle.setTitle("Wrong title");
|
439
|
Assert.assertFalse("Differing title should not match",
|
440
|
matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
|
441
|
fullArticle.setTitle(null);
|
442
|
Assert.assertFalse("Title only for parsed book should not match. Wrong direction.",
|
443
|
matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
|
444
|
|
445
|
//change author
|
446
|
fullArticle = getMatchingFullArticle();
|
447
|
parsedArticle = getDefaultParsedArticle();
|
448
|
fullArticle.getAuthorship().setNomenclaturalTitle("Wrong");
|
449
|
Assert.assertFalse("Differing author in nomencl. title should not match",
|
450
|
matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
|
451
|
|
452
|
//change author
|
453
|
fullArticle = getMatchingFullArticle();
|
454
|
parsedArticle = getDefaultParsedArticle();
|
455
|
((Team)fullArticle.getAuthorship()).getTeamMembers().get(0).setFamilyName("Changed");
|
456
|
Assert.assertTrue("Full book family name author changed should still match",
|
457
|
matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
|
458
|
}
|
459
|
|
460
|
/**
|
461
|
* Like {@link #getMatchingFullArticle() matching full article} with additional
|
462
|
* title, abbrevTitle and pages
|
463
|
*/
|
464
|
private IArticle getDefaultFullArticle() {
|
465
|
IArticle article = getMatchingFullArticle();
|
466
|
article.setTitle("Article title");
|
467
|
article.setAbbrevTitle("Art. tit.");
|
468
|
article.setPages("22-33");
|
469
|
return article;
|
470
|
}
|
471
|
|
472
|
/**
|
473
|
* Article with {@link #getDefaultFullTeam() full team},
|
474
|
* {@link #getDefaultFullJournal() full journal} and date published
|
475
|
*/
|
476
|
private IArticle getMatchingFullArticle() {
|
477
|
IArticle article = ReferenceFactory.newArticle();
|
478
|
article.setAuthorship(getDefaultFullTeam());
|
479
|
article.setInJournal(getDefaultFullJournal());
|
480
|
article.setDatePublished(TimePeriodParser.parseStringVerbatim("1950"));
|
481
|
return article;
|
482
|
}
|
483
|
|
484
|
/**
|
485
|
* Article with {@link #getDefaultParsedTeam() parsed authorship},
|
486
|
* {@link #getDefaultParsedJournal() parsed journal} and date published.
|
487
|
*/
|
488
|
private IArticle getDefaultParsedArticle() {
|
489
|
IArticle article = ReferenceFactory.newArticle();
|
490
|
article.setAuthorship(getDefaultParsedTeam());
|
491
|
article.setInJournal(getDefaultParsedJournal());
|
492
|
article.setDatePublished(TimePeriodParser.parseStringVerbatim("1950"));
|
493
|
return article;
|
494
|
}
|
495
|
|
496
|
private IJournal getDefaultFullJournal() {
|
497
|
IJournal journal = getDefaultParsedJournal();
|
498
|
// journal.setAuthorship(getDefaultFullTeam()); //journals should not have authors
|
499
|
journal.setTitle("J. Flow. Pl.");
|
500
|
journal.setUri(URI.create("https://www.journal-flowering-plants.gr"));
|
501
|
journal.setIssn("1234-222-222-333"); //format not yet correct
|
502
|
journal.setPublisher("Botanical publisher", "Paris");
|
503
|
journal.getTitleCache();
|
504
|
return journal;
|
505
|
}
|
506
|
|
507
|
private IJournal getDefaultParsedJournal() {
|
508
|
IJournal journal = ReferenceFactory.newJournal();
|
509
|
journal.setAbbrevTitle("Fl. Hell.");
|
510
|
// journal.setAuthorship(getDefaultParsedTeam()); //journals should not have authors
|
511
|
// ((Reference)journal).setDatePublished(TimePeriodParser.parseStringVerbatim("1992-04-03")); //journals should not have date published
|
512
|
journal.getTitleCache(); //not sure if enough
|
513
|
return journal;
|
514
|
}
|
515
|
|
516
|
@Test
|
517
|
public void testParsedReference() throws MatchException {
|
518
|
IParsedMatchStrategy matchStrategy = MatchStrategyFactory.NewParsedReferenceInstance();
|
519
|
Assert.assertNotNull(matchStrategy);
|
520
|
IArticle fullArticle;
|
521
|
IArticle parsedArticle;
|
522
|
|
523
|
fullArticle = getMatchingFullArticle();
|
524
|
parsedArticle = getDefaultParsedArticle();
|
525
|
Assert.assertTrue("Only author, book and date published should match", matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful() );
|
526
|
|
527
|
//should match
|
528
|
fullArticle = getDefaultFullArticle();
|
529
|
Assert.assertFalse("Abbrev. title must be equal or null", matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
|
530
|
parsedArticle.setAbbrevTitle(fullArticle.getAbbrevTitle());
|
531
|
Assert.assertFalse("Still not match because pages are not equal (parsed is null)", matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
|
532
|
parsedArticle.setPages(fullArticle.getPages());
|
533
|
Assert.assertFalse("Now they should match", matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
|
534
|
|
535
|
//differing nom. title.
|
536
|
parsedArticle.setAbbrevTitle("Wrong");
|
537
|
Assert.assertFalse("Differing abbrev. title. should not match", matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
|
538
|
|
539
|
//differing family
|
540
|
parsedArticle = getDefaultParsedArticle();
|
541
|
parsedArticle.setTitle("Wrong title");
|
542
|
Assert.assertFalse("Differing title should not match", matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
|
543
|
fullArticle.setTitle(null);
|
544
|
Assert.assertFalse("Title only for parsed book should not match. Wrong direction.", matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
|
545
|
|
546
|
//change author
|
547
|
fullArticle = getMatchingFullArticle();
|
548
|
parsedArticle = getDefaultParsedArticle();
|
549
|
fullArticle.getAuthorship().setNomenclaturalTitle("Wrong");
|
550
|
Assert.assertFalse("Differing author in nomencl. title should not match", matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
|
551
|
|
552
|
//change author
|
553
|
fullArticle = getMatchingFullArticle();
|
554
|
parsedArticle = getDefaultParsedArticle();
|
555
|
((Team)fullArticle.getAuthorship()).getTeamMembers().get(0).setFamilyName("Changed");
|
556
|
Assert.assertTrue("Full book family name author changed should still match", matchStrategy.invoke(parsedArticle, fullArticle).isSuccessful());
|
557
|
}
|
558
|
}
|