ref #6636 handle Books correctly in RIS import
[cdmlib.git] / cdmlib-io / src / test / java / eu / etaxonomy / cdm / io / reference / RisReferenceImportTest.java
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.io.reference;
11
12 import static org.junit.Assert.assertNotNull;
13
14 import java.io.FileNotFoundException;
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.IImportConfigurator;
29 import eu.etaxonomy.cdm.io.common.ImportResult;
30 import eu.etaxonomy.cdm.io.reference.ris.in.RisReferenceImportConfigurator;
31 import eu.etaxonomy.cdm.model.agent.Person;
32 import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
33 import eu.etaxonomy.cdm.model.common.CdmBase;
34 import eu.etaxonomy.cdm.model.common.TimePeriod;
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 andy
42 *
43 */
44 public class RisReferenceImportTest extends CdmTransactionalIntegrationTest {
45
46 @SpringBeanByName
47 private CdmApplicationAwareDefaultImport<?> defaultImport;
48
49 @SpringBeanByType
50 private IReferenceService referenceService;
51
52 private IImportConfigurator configurator;
53 private IImportConfigurator configLong;
54
55 @Before
56 public void setUp() {
57 String inputFile = "/eu/etaxonomy/cdm/io/reference/RisReferenceImportTest-input.ris";
58 URL url = this.getClass().getResource(inputFile);
59 assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);
60
61 String inputFileLong = "/eu/etaxonomy/cdm/io/reference/Acantholimon.ris";
62 URL urlLong = this.getClass().getResource(inputFileLong);
63 assertNotNull("URL for the test file '" + inputFileLong + "' does not exist", urlLong);
64
65 try {
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/BlankDataSet.xml", loadStrategy=CleanSweepInsertLoadStrategy.class)
82 public void testShort() {
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("Carel C. H. Jongkind" ,person.getTitleCache());
110 Assert.assertEquals("Jongkind" ,person.getLastname());
111 Assert.assertEquals("Carel C. H." ,person.getFirstname());
112 //date
113 TimePeriod 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 public void testLongFile() {
145 ImportResult result = defaultImport.invoke(configLong);
146 String report = result.createReport().toString();
147 System.out.println(report);
148
149 Integer expected = 118; //did not count yet
150 Assert.assertEquals(expected, result.getNewRecords(Reference.class));
151
152 // List<Reference> list = referenceService.list(Reference.class, null, null, null, null);
153 // Assert.assertEquals("There should be 2 references, the article and the journal", 2, list.size());
154 // for (Reference ref : list){
155 // Assert.assertTrue(ref.getType() == ReferenceType.Article || ref.getType() == ReferenceType.Journal);
156 // if (ref.getType() == ReferenceType.Article){
157 // //title
158 // Assert.assertEquals("Decorsella arborea, a second species in Decorsella (Violaceae), and Decorsella versus Rinorea",
159 // ref.getTitle());
160 // //author
161 // TeamOrPersonBase<?> author = ref.getAuthorship();
162 // Assert.assertNotNull(author);
163 // Assert.assertTrue(author.isInstanceOf(Person.class));
164 // Person person = CdmBase.deproxy(author, Person.class);
165 // //this may change in future depending on the correct formatting strategy
166 // Assert.assertEquals("Carel C. H. Jongkind" ,person.getTitleCache());
167 // Assert.assertEquals("Jongkind" ,person.getLastname());
168 // Assert.assertEquals("Carel C. H." ,person.getFirstname());
169 // //date
170 // TimePeriod date = ref.getDatePublished();
171 // Assert.assertEquals(Integer.valueOf(2017) ,date.getStartYear());
172 // //vol
173 // Assert.assertEquals("47(1)" ,ref.getVolume());
174 // Assert.assertEquals("43-47" ,ref.getPages());
175 //
176 // //doi
177 // Assert.assertEquals(DOI.fromString("10.3372/wi.47.47105"),ref.getDoi());
178 //
179 // //Abstract
180 // 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.",
181 // ref.getReferenceAbstract());
182 //
183 // //TODO still missing Y1, Y2, M3, UR
184 //
185 // }else if (ref.getType() == ReferenceType.Journal){
186 // Assert.assertEquals("Willdenowia", ref.getTitle());
187 // //or is this part of article?
188 // Assert.assertEquals("Botanic Garden and Botanical Museum Berlin (BGBM)", ref.getPublisher());
189 //
190 // //ISSN
191 // Assert.assertEquals("0511-9618" ,ref.getIssn());
192 //
193 // }else{
194 // Assert.fail("Only an article and a journal should exist");
195 // }
196 // }
197
198 }
199
200 @Override
201 public void createTestDataSet() throws FileNotFoundException {}
202 }