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.net.URL;
|
15
|
import java.util.List;
|
16
|
|
17
|
import org.junit.Assert;
|
18
|
import org.junit.Before;
|
19
|
import org.junit.Test;
|
20
|
import org.unitils.dbunit.annotation.DataSet;
|
21
|
import org.unitils.spring.annotation.SpringBeanByName;
|
22
|
import org.unitils.spring.annotation.SpringBeanByType;
|
23
|
|
24
|
import eu.etaxonomy.cdm.api.service.IReferenceService;
|
25
|
//import eu.etaxonomy.cdm.common.DOI;
|
26
|
import eu.etaxonomy.cdm.io.common.CdmApplicationAwareDefaultImport;
|
27
|
import eu.etaxonomy.cdm.io.common.ImportResult;
|
28
|
import eu.etaxonomy.cdm.io.reference.ris.in.RisReferenceImportConfigurator;
|
29
|
import eu.etaxonomy.cdm.model.agent.Person;
|
30
|
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
|
31
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
32
|
import eu.etaxonomy.cdm.model.common.VerbatimTimePeriod;
|
33
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
34
|
import eu.etaxonomy.cdm.model.reference.ReferenceType;
|
35
|
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
|
36
|
import eu.etaxonomy.cdm.test.unitils.CleanSweepInsertLoadStrategy;
|
37
|
|
38
|
/**
|
39
|
* @author a.mueller
|
40
|
*/
|
41
|
public class RisReferenceImportTest extends CdmTransactionalIntegrationTest {
|
42
|
|
43
|
@SpringBeanByName
|
44
|
private CdmApplicationAwareDefaultImport<?> defaultImport;
|
45
|
|
46
|
@SpringBeanByType
|
47
|
private IReferenceService referenceService;
|
48
|
|
49
|
private RisReferenceImportConfigurator configurator;
|
50
|
private RisReferenceImportConfigurator configLong;
|
51
|
|
52
|
@Before
|
53
|
public void setUp() {
|
54
|
String inputFile = "/eu/etaxonomy/cdm/io/reference/ris/in/RisReferenceImportTest-input.ris";
|
55
|
|
56
|
try {
|
57
|
URL url = this.getClass().getResource(inputFile);
|
58
|
assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);
|
59
|
|
60
|
String inputFileLong = "/eu/etaxonomy/cdm/io/reference/ris/in/Acantholimon.ris";
|
61
|
URL urlLong = this.getClass().getResource(inputFileLong);
|
62
|
assertNotNull("URL for the test file '" + inputFileLong + "' does not exist", urlLong);
|
63
|
|
64
|
configurator = RisReferenceImportConfigurator.NewInstance(url, null);
|
65
|
configLong = RisReferenceImportConfigurator.NewInstance(urlLong, null);
|
66
|
|
67
|
} catch (Exception e) {
|
68
|
e.printStackTrace();
|
69
|
Assert.fail();
|
70
|
}
|
71
|
assertNotNull("Configurator could not be created", configurator);
|
72
|
assertNotNull("Configurator could not be created", configLong);
|
73
|
assertNotNull("nameService should not be null", referenceService);
|
74
|
}
|
75
|
|
76
|
//***************************** TESTS *************************************//
|
77
|
|
78
|
@Test
|
79
|
@DataSet( value="/eu/etaxonomy/cdm/database/ClearDBDataSet.xml", loadStrategy=CleanSweepInsertLoadStrategy.class)
|
80
|
//@Ignore
|
81
|
public void testShort() {
|
82
|
|
83
|
ImportResult result = defaultImport.invoke(configurator);
|
84
|
String report = result.createReport().toString();
|
85
|
Assert.assertTrue(report.length() > 0);
|
86
|
System.out.println(report);
|
87
|
|
88
|
Integer expected = 2;
|
89
|
Assert.assertEquals(expected, result.getNewRecords(Reference.class));
|
90
|
|
91
|
List<Reference> list = referenceService.list(Reference.class, null, null, null, null);
|
92
|
Assert.assertEquals("There should be 3 references, the article and the journal and the source reference",
|
93
|
3, list.size());
|
94
|
for (Reference ref : list){
|
95
|
if (ref.equals(configurator.getSourceReference())){
|
96
|
continue;
|
97
|
}
|
98
|
Assert.assertTrue(ref.getType() == ReferenceType.Article || ref.getType() == ReferenceType.Journal);
|
99
|
if (ref.getType() == ReferenceType.Article){
|
100
|
//title
|
101
|
Assert.assertEquals("Decorsella arborea, a second species in Decorsella (Violaceae), and Decorsella versus Rinorea",
|
102
|
ref.getTitle());
|
103
|
//author
|
104
|
TeamOrPersonBase<?> author = ref.getAuthorship();
|
105
|
Assert.assertNotNull(author);
|
106
|
Assert.assertTrue(author.isInstanceOf(Person.class));
|
107
|
Person person = CdmBase.deproxy(author, Person.class);
|
108
|
//this may change in future depending on the correct formatting strategy
|
109
|
Assert.assertEquals("Jongkind, C.C.H." ,person.getTitleCache());
|
110
|
Assert.assertEquals("Jongkind" ,person.getFamilyName());
|
111
|
Assert.assertEquals("Carel C. H." ,person.getGivenName());
|
112
|
//date
|
113
|
VerbatimTimePeriod date = ref.getDatePublished();
|
114
|
Assert.assertEquals(Integer.valueOf(2017) ,date.getStartYear());
|
115
|
//vol
|
116
|
Assert.assertEquals("47(1)" ,ref.getVolume());
|
117
|
Assert.assertEquals("43-47" ,ref.getPages());
|
118
|
|
119
|
//doi
|
120
|
//Assert.assertEquals(DOI.fromString("10.3372/wi.47.47105"),ref.getDoi());
|
121
|
|
122
|
//Abstract
|
123
|
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.",
|
124
|
ref.getReferenceAbstract());
|
125
|
|
126
|
//TODO still missing Y1, Y2, M3, UR
|
127
|
|
128
|
}else if (ref.getType() == ReferenceType.Journal){
|
129
|
Assert.assertEquals("Willdenowia", ref.getTitle());
|
130
|
//or is this part of article?
|
131
|
Assert.assertEquals("Botanic Garden and Botanical Museum Berlin (BGBM)", ref.getPublisher());
|
132
|
|
133
|
//ISSN
|
134
|
Assert.assertEquals("0511-9618" ,ref.getIssn());
|
135
|
|
136
|
}else{
|
137
|
Assert.fail("Only an article and a journal should exist");
|
138
|
}
|
139
|
}
|
140
|
|
141
|
}
|
142
|
|
143
|
@Test
|
144
|
//@Ignore
|
145
|
public void testLongFile() {
|
146
|
ImportResult result = defaultImport.invoke(configLong);
|
147
|
String report = result.createReport().toString();
|
148
|
System.out.println(report);
|
149
|
|
150
|
Integer expected = 118; //did not count yet
|
151
|
Assert.assertEquals(expected, result.getNewRecords(Reference.class));
|
152
|
|
153
|
// List<Reference> list = referenceService.list(Reference.class, null, null, null, null);
|
154
|
// Assert.assertEquals("There should be 2 references, the article and the journal", 2, list.size());
|
155
|
// for (Reference ref : list){
|
156
|
// Assert.assertTrue(ref.getType() == ReferenceType.Article || ref.getType() == ReferenceType.Journal);
|
157
|
// if (ref.getType() == ReferenceType.Article){
|
158
|
// //title
|
159
|
// Assert.assertEquals("Decorsella arborea, a second species in Decorsella (Violaceae), and Decorsella versus Rinorea",
|
160
|
// ref.getTitle());
|
161
|
// //author
|
162
|
// TeamOrPersonBase<?> author = ref.getAuthorship();
|
163
|
// Assert.assertNotNull(author);
|
164
|
// Assert.assertTrue(author.isInstanceOf(Person.class));
|
165
|
// Person person = CdmBase.deproxy(author, Person.class);
|
166
|
// //this may change in future depending on the correct formatting strategy
|
167
|
// Assert.assertEquals("Carel C. H. Jongkind" ,person.getTitleCache());
|
168
|
// Assert.assertEquals("Jongkind" ,person.getFamilyName());
|
169
|
// Assert.assertEquals("Carel C. H." ,person.getGivenName());
|
170
|
// //date
|
171
|
// TimePeriod date = ref.getDatePublished();
|
172
|
// Assert.assertEquals(Integer.valueOf(2017) ,date.getStartYear());
|
173
|
// //vol
|
174
|
// Assert.assertEquals("47(1)" ,ref.getVolume());
|
175
|
// Assert.assertEquals("43-47" ,ref.getPages());
|
176
|
//
|
177
|
// //doi
|
178
|
// Assert.assertEquals(DOI.fromString("10.3372/wi.47.47105"),ref.getDoi());
|
179
|
//
|
180
|
// //Abstract
|
181
|
// 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.",
|
182
|
// ref.getReferenceAbstract());
|
183
|
//
|
184
|
// //TODO still missing Y1, Y2, M3, UR
|
185
|
//
|
186
|
// }else if (ref.getType() == ReferenceType.Journal){
|
187
|
// Assert.assertEquals("Willdenowia", ref.getTitle());
|
188
|
// //or is this part of article?
|
189
|
// Assert.assertEquals("Botanic Garden and Botanical Museum Berlin (BGBM)", ref.getPublisher());
|
190
|
//
|
191
|
// //ISSN
|
192
|
// Assert.assertEquals("0511-9618" ,ref.getIssn());
|
193
|
//
|
194
|
// }else{
|
195
|
// Assert.fail("Only an article and a journal should exist");
|
196
|
// }
|
197
|
// }
|
198
|
|
199
|
}
|
200
|
|
201
|
@Override
|
202
|
public void createTestDataSet() throws FileNotFoundException {}
|
203
|
}
|