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.io.referenceris.in;
|
10
|
|
11
|
import static org.junit.Assert.assertNotNull;
|
12
|
|
13
|
import java.io.FileNotFoundException;
|
14
|
import java.io.IOException;
|
15
|
import java.net.URL;
|
16
|
import java.util.List;
|
17
|
|
18
|
import org.junit.Assert;
|
19
|
import org.junit.Before;
|
20
|
import org.junit.Test;
|
21
|
import org.unitils.dbunit.annotation.DataSet;
|
22
|
import org.unitils.spring.annotation.SpringBeanByName;
|
23
|
import org.unitils.spring.annotation.SpringBeanByType;
|
24
|
|
25
|
import eu.etaxonomy.cdm.api.service.IReferenceService;
|
26
|
//import eu.etaxonomy.cdm.common.DOI;
|
27
|
import eu.etaxonomy.cdm.io.common.CdmApplicationAwareDefaultImport;
|
28
|
import eu.etaxonomy.cdm.io.common.ImportResult;
|
29
|
import eu.etaxonomy.cdm.io.reference.ris.in.RisReferenceImportConfigurator;
|
30
|
import eu.etaxonomy.cdm.model.agent.Person;
|
31
|
import eu.etaxonomy.cdm.model.agent.Team;
|
32
|
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
|
33
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
34
|
import eu.etaxonomy.cdm.model.common.VerbatimTimePeriod;
|
35
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
36
|
import eu.etaxonomy.cdm.model.reference.ReferenceType;
|
37
|
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
|
38
|
import eu.etaxonomy.cdm.test.unitils.CleanSweepInsertLoadStrategy;
|
39
|
|
40
|
/**
|
41
|
* @author a.mueller
|
42
|
*/
|
43
|
public class RisReferenceImportTest extends CdmTransactionalIntegrationTest {
|
44
|
|
45
|
@SpringBeanByName
|
46
|
private CdmApplicationAwareDefaultImport<?> defaultImport;
|
47
|
|
48
|
@SpringBeanByType
|
49
|
private IReferenceService referenceService;
|
50
|
|
51
|
private RisReferenceImportConfigurator configurator;
|
52
|
private RisReferenceImportConfigurator configLong;
|
53
|
|
54
|
@Before
|
55
|
public void setUp() {
|
56
|
String inputFile = "/eu/etaxonomy/cdm/io/reference/ris/in/RisReferenceImportTest-input.ris";
|
57
|
|
58
|
try {
|
59
|
URL url = this.getClass().getResource(inputFile);
|
60
|
assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);
|
61
|
|
62
|
String inputFileLong = "/eu/etaxonomy/cdm/io/reference/ris/in/Acantholimon.ris";
|
63
|
URL urlLong = this.getClass().getResource(inputFileLong);
|
64
|
assertNotNull("URL for the test file '" + inputFileLong + "' does not exist", urlLong);
|
65
|
|
66
|
configurator = RisReferenceImportConfigurator.NewInstance(url, null);
|
67
|
configLong = RisReferenceImportConfigurator.NewInstance(urlLong, null);
|
68
|
|
69
|
} catch (Exception e) {
|
70
|
e.printStackTrace();
|
71
|
Assert.fail();
|
72
|
}
|
73
|
assertNotNull("Configurator could not be created", configurator);
|
74
|
assertNotNull("Configurator could not be created", configLong);
|
75
|
assertNotNull("nameService should not be null", referenceService);
|
76
|
}
|
77
|
|
78
|
//***************************** TESTS *************************************//
|
79
|
|
80
|
@Test
|
81
|
@DataSet( value="/eu/etaxonomy/cdm/database/ClearDBDataSet.xml", loadStrategy=CleanSweepInsertLoadStrategy.class)
|
82
|
//@Ignore
|
83
|
public void testShort() {
|
84
|
|
85
|
ImportResult result = defaultImport.invoke(configurator);
|
86
|
String report = result.createReport().toString();
|
87
|
Assert.assertTrue(report.length() > 0);
|
88
|
System.out.println(report);
|
89
|
|
90
|
Integer expected = 2;
|
91
|
Assert.assertEquals(expected, result.getNewRecords(Reference.class));
|
92
|
|
93
|
List<Reference> list = referenceService.list(Reference.class, null, null, null, null);
|
94
|
Assert.assertEquals("There should be 3 references, the article and the journal and the source reference",
|
95
|
3, list.size());
|
96
|
for (Reference ref : list){
|
97
|
if (ref.equals(configurator.getSourceReference())){
|
98
|
continue;
|
99
|
}
|
100
|
Assert.assertTrue(ref.getType() == ReferenceType.Article || ref.getType() == ReferenceType.Journal);
|
101
|
if (ref.getType() == ReferenceType.Article){
|
102
|
//title
|
103
|
Assert.assertEquals("Decorsella arborea, a second species in Decorsella (Violaceae), and Decorsella versus Rinorea",
|
104
|
ref.getTitle());
|
105
|
//author
|
106
|
TeamOrPersonBase<?> author = ref.getAuthorship();
|
107
|
Assert.assertNotNull(author);
|
108
|
Assert.assertTrue(author.isInstanceOf(Person.class));
|
109
|
Person person = CdmBase.deproxy(author, Person.class);
|
110
|
//this may change in future depending on the correct formatting strategy
|
111
|
Assert.assertEquals("Jongkind, C.C.H." ,person.getTitleCache());
|
112
|
Assert.assertEquals("Jongkind" ,person.getFamilyName());
|
113
|
Assert.assertEquals("Carel C. H." ,person.getGivenName());
|
114
|
//date
|
115
|
VerbatimTimePeriod date = ref.getDatePublished();
|
116
|
Assert.assertEquals(Integer.valueOf(2017) ,date.getStartYear());
|
117
|
//vol
|
118
|
Assert.assertEquals("47(1)" ,ref.getVolume());
|
119
|
Assert.assertEquals("43-47" ,ref.getPages());
|
120
|
|
121
|
//doi
|
122
|
//Assert.assertEquals(DOI.fromString("10.3372/wi.47.47105"),ref.getDoi());
|
123
|
|
124
|
//Abstract
|
125
|
Assert.assertEquals("Abstract: A new species of Violaceae, Decorsella arborea Jongkind, is described and illustrated. The new species differs from the only other species in the genus, D. paradoxa A. Chev., by the larger size of the plants, smaller leaves, more slender flowers, and stamen filaments that are free for a much larger part. Both species are from the Guineo-Congolian forest of tropical Africa. The differences between Decorsella and Rinorea are discussed. Confirming recent reports, some species of Rinorea can have zygomorphic flowers and some of these can be almost equal in shape to Decorsella flowers. Citation: Jongkind C. C. H. 2017: Decorsella arborea, a second species in Decorsella (Violaceae), and Decorsella versus Rinorea. ? Willdenowia 47: 43?47. doi: https://doi.org/10.3372/wi.47.47105 Version of record first published online on 13 February 2017 ahead of inclusion in April 2017 issue.",
|
126
|
ref.getReferenceAbstract());
|
127
|
|
128
|
//TODO still missing Y1, Y2, M3, UR
|
129
|
|
130
|
}else if (ref.getType() == ReferenceType.Journal){
|
131
|
Assert.assertEquals("Willdenowia", ref.getTitle());
|
132
|
//or is this part of article?
|
133
|
Assert.assertEquals("Botanic Garden and Botanical Museum Berlin (BGBM)", ref.getPublisher());
|
134
|
|
135
|
//ISSN
|
136
|
Assert.assertEquals("0511-9618" ,ref.getIssn());
|
137
|
|
138
|
}else{
|
139
|
Assert.fail("Only an article and a journal should exist");
|
140
|
}
|
141
|
}
|
142
|
}
|
143
|
|
144
|
@Test
|
145
|
public void testChapter() throws IOException{
|
146
|
String inputFileLong = "/eu/etaxonomy/cdm/io/reference/ris/in/Arias2012.ris";
|
147
|
URL urlLong = this.getClass().getResource(inputFileLong);
|
148
|
configurator = RisReferenceImportConfigurator.NewInstance(urlLong, null);
|
149
|
|
150
|
ImportResult result = defaultImport.invoke(configurator);
|
151
|
String report = result.createReport().toString();
|
152
|
Assert.assertTrue(report.contains("Reference: 2"));
|
153
|
Assert.assertEquals(0, result.getErrors().size() + result.getExceptions().size() + result.getWarnings().size());
|
154
|
|
155
|
Integer expected = 2;
|
156
|
Assert.assertEquals(expected, result.getNewRecords(Reference.class));
|
157
|
|
158
|
List<Reference> list = referenceService.list(Reference.class, null, null, null, null);
|
159
|
Assert.assertEquals("There should be 3 references, the book-section, the book and the source reference",
|
160
|
3, list.size());
|
161
|
|
162
|
//book section
|
163
|
Reference bookSection = list.stream().filter(r->r.getType() == ReferenceType.BookSection).findFirst().get();
|
164
|
//... title
|
165
|
Assert.assertEquals("Cactaceae", bookSection.getTitle());
|
166
|
//... author
|
167
|
TeamOrPersonBase<?> author = bookSection.getAuthorship();
|
168
|
Assert.assertNotNull(author);
|
169
|
Team team = CdmBase.deproxy(author, Team.class);
|
170
|
Assert.assertEquals(4, team.getTeamMembers().size());
|
171
|
Person firstPerson = CdmBase.deproxy(team.getTeamMembers().get(0));
|
172
|
//this may change in future depending on the correct formatting strategy
|
173
|
Assert.assertEquals("Arias, S." , firstPerson.getTitleCache());
|
174
|
Assert.assertEquals("Arias" , firstPerson.getFamilyName());
|
175
|
Assert.assertNull(firstPerson.getGivenName());
|
176
|
Assert.assertEquals("S." , firstPerson.getInitials());
|
177
|
Person secondPerson = CdmBase.deproxy(team.getTeamMembers().get(1));
|
178
|
Assert.assertEquals("Gama-L\u00F3pez, S." , secondPerson.getTitleCache());
|
179
|
VerbatimTimePeriod date = bookSection.getDatePublished();
|
180
|
Assert.assertEquals(Integer.valueOf(2012), date.getStartYear());
|
181
|
//TODO correct?
|
182
|
Assert.assertEquals("1-235", bookSection.getPages());
|
183
|
|
184
|
//book
|
185
|
Reference book = list.stream().filter(r->r.getType() == ReferenceType.Book).findFirst().get();
|
186
|
//... title
|
187
|
Assert.assertEquals("Flora del Valle de Tehuac\u00E1n-Cuicatl\u00E1n", book.getTitle());
|
188
|
Assert.assertEquals("Fasc\u00EDculo 95", book.getVolume());
|
189
|
Assert.assertEquals("M\u00E9xico D. F.", book.getPlacePublished());
|
190
|
Assert.assertEquals("Instituto de Biolog\u00EDa, Universidad Nacional Aut\u00F3noma de M\u00E9xico", book.getPublisher());
|
191
|
|
192
|
//source reference
|
193
|
Reference sourceRef = list.stream().filter(r->r.equals(configurator.getSourceReference())).findFirst().get();
|
194
|
Assert.assertNotNull(sourceRef);
|
195
|
//TODO cont.
|
196
|
|
197
|
}
|
198
|
|
199
|
@Test
|
200
|
//@Ignore
|
201
|
public void testLongFile() {
|
202
|
ImportResult result = defaultImport.invoke(configLong);
|
203
|
String report = result.createReport().toString();
|
204
|
System.out.println(report);
|
205
|
|
206
|
Integer expected = 118; //did not count yet
|
207
|
Assert.assertEquals(expected, result.getNewRecords(Reference.class));
|
208
|
|
209
|
List<Reference> list = referenceService.list(Reference.class, null, null, null, null);
|
210
|
// Assert.assertEquals("There should be 119 references (still need to count them)", 119, list.size());
|
211
|
//TODO deduplication
|
212
|
|
213
|
Reference ref58 = list.stream().filter(r->hasId(r, "58", false)).findFirst().get();
|
214
|
Assert.assertNotNull("", ref58);
|
215
|
Assert.assertEquals((Integer)2003, ref58.getDatePublished().getStartYear());
|
216
|
|
217
|
Reference ref53 = list.stream().filter(r->hasId(r, "53", false)).findFirst().get();
|
218
|
Assert.assertNotNull("", ref53);
|
219
|
Assert.assertEquals(ReferenceType.BookSection, ref53.getType());
|
220
|
Assert.assertNotNull("", ref53.getInReference());
|
221
|
Assert.assertEquals("Tehran", ref53.getInReference().getPlacePublished());
|
222
|
|
223
|
|
224
|
// for (Reference ref : list){
|
225
|
// Assert.assertTrue(ref.getType() == ReferenceType.Article || ref.getType() == ReferenceType.Journal);
|
226
|
// if (ref.getType() == ReferenceType.Article){
|
227
|
// //title
|
228
|
// Assert.assertEquals("Decorsella arborea, a second species in Decorsella (Violaceae), and Decorsella versus Rinorea",
|
229
|
// ref.getTitle());
|
230
|
// //author
|
231
|
// TeamOrPersonBase<?> author = ref.getAuthorship();
|
232
|
// Assert.assertNotNull(author);
|
233
|
// Assert.assertTrue(author.isInstanceOf(Person.class));
|
234
|
// Person person = CdmBase.deproxy(author, Person.class);
|
235
|
// //this may change in future depending on the correct formatting strategy
|
236
|
// Assert.assertEquals("Carel C. H. Jongkind" ,person.getTitleCache());
|
237
|
// Assert.assertEquals("Jongkind" ,person.getFamilyName());
|
238
|
// Assert.assertEquals("Carel C. H." ,person.getGivenName());
|
239
|
// //date
|
240
|
// TimePeriod date = ref.getDatePublished();
|
241
|
// Assert.assertEquals(Integer.valueOf(2017) ,date.getStartYear());
|
242
|
// //vol
|
243
|
// Assert.assertEquals("47(1)" ,ref.getVolume());
|
244
|
// Assert.assertEquals("43-47" ,ref.getPages());
|
245
|
//
|
246
|
// //doi
|
247
|
// Assert.assertEquals(DOI.fromString("10.3372/wi.47.47105"),ref.getDoi());
|
248
|
//
|
249
|
// //Abstract
|
250
|
// Assert.assertEquals("Abstract: A new species of Violaceae, Decorsella arborea Jongkind, is described and illustrated. The new species differs from the only other species in the genus, D. paradoxa A. Chev., by the larger size of the plants, smaller leaves, more slender flowers, and stamen filaments that are free for a much larger part. Both species are from the Guineo-Congolian forest of tropical Africa. The differences between Decorsella and Rinorea are discussed. Confirming recent reports, some species of Rinorea can have zygomorphic flowers and some of these can be almost equal in shape to Decorsella flowers. Citation: Jongkind C. C. H. 2017: Decorsella arborea, a second species in Decorsella (Violaceae), and Decorsella versus Rinorea. ? Willdenowia 47: 43?47. doi: https://doi.org/10.3372/wi.47.47105 Version of record first published online on 13 February 2017 ahead of inclusion in April 2017 issue.",
|
251
|
// ref.getReferenceAbstract());
|
252
|
//
|
253
|
// //TODO still missing Y1, Y2, M3, UR
|
254
|
//
|
255
|
// }else if (ref.getType() == ReferenceType.Journal){
|
256
|
// Assert.assertEquals("Willdenowia", ref.getTitle());
|
257
|
// //or is this part of article?
|
258
|
// Assert.assertEquals("Botanic Garden and Botanical Museum Berlin (BGBM)", ref.getPublisher());
|
259
|
//
|
260
|
// //ISSN
|
261
|
// Assert.assertEquals("0511-9618" ,ref.getIssn());
|
262
|
//
|
263
|
// }else{
|
264
|
// Assert.fail("Only an article and a journal should exist");
|
265
|
// }
|
266
|
// }
|
267
|
|
268
|
}
|
269
|
|
270
|
private boolean hasId(Reference ref, String idStr, boolean getInRef) {
|
271
|
if (ref.getSources().size() != 1){
|
272
|
return false;
|
273
|
}else{
|
274
|
String idInSource = ref.getSources().iterator().next().getIdInSource();
|
275
|
return idStr.equals(idInSource) &&
|
276
|
(getInRef && ref.getInReference()== null
|
277
|
|| !getInRef && ref.getInReference()!= null );
|
278
|
}
|
279
|
}
|
280
|
|
281
|
@Override
|
282
|
public void createTestDataSet() throws FileNotFoundException {}
|
283
|
}
|