2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.io
.reference
;
12 import static org
.junit
.Assert
.assertNotNull
;
14 import java
.io
.FileNotFoundException
;
16 import java
.util
.List
;
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
;
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
;
44 public class RisReferenceImportTest
extends CdmTransactionalIntegrationTest
{
47 private CdmApplicationAwareDefaultImport
<?
> defaultImport
;
50 private IReferenceService referenceService
;
52 private IImportConfigurator configurator
;
53 private IImportConfigurator configLong
;
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
);
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
);
66 configurator
= RisReferenceImportConfigurator
.NewInstance(url
, null);
67 configLong
= RisReferenceImportConfigurator
.NewInstance(urlLong
, null);
69 } catch (Exception e
) {
73 assertNotNull("Configurator could not be created", configurator
);
74 assertNotNull("Configurator could not be created", configLong
);
75 assertNotNull("nameService should not be null", referenceService
);
78 //***************************** TESTS *************************************//
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
);
89 Assert
.assertEquals(expected
, result
.getNewRecords(Reference
.class));
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",
94 for (Reference ref
: list
){
95 if (ref
.equals(configurator
.getSourceReference())){
98 Assert
.assertTrue(ref
.getType() == ReferenceType
.Article
|| ref
.getType() == ReferenceType
.Journal
);
99 if (ref
.getType() == ReferenceType
.Article
){
101 Assert
.assertEquals("Decorsella arborea, a second species in Decorsella (Violaceae), and Decorsella versus Rinorea",
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());
113 TimePeriod date
= ref
.getDatePublished();
114 Assert
.assertEquals(Integer
.valueOf(2017) ,date
.getStartYear());
116 Assert
.assertEquals("47(1)" ,ref
.getVolume());
117 Assert
.assertEquals("43-47" ,ref
.getPages());
120 Assert
.assertEquals(DOI
.fromString("10.3372/wi.47.47105"),ref
.getDoi());
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());
126 //TODO still missing Y1, Y2, M3, UR
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());
134 Assert
.assertEquals("0511-9618" ,ref
.getIssn());
137 Assert
.fail("Only an article and a journal should exist");
144 public void testLongFile() {
145 ImportResult result
= defaultImport
.invoke(configLong
);
146 String report
= result
.createReport().toString();
147 System
.out
.println(report
);
149 Integer expected
= 118; //did not count yet
150 Assert
.assertEquals(expected
, result
.getNewRecords(Reference
.class));
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){
158 // Assert.assertEquals("Decorsella arborea, a second species in Decorsella (Violaceae), and Decorsella versus Rinorea",
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());
170 // TimePeriod date = ref.getDatePublished();
171 // Assert.assertEquals(Integer.valueOf(2017) ,date.getStartYear());
173 // Assert.assertEquals("47(1)" ,ref.getVolume());
174 // Assert.assertEquals("43-47" ,ref.getPages());
177 // Assert.assertEquals(DOI.fromString("10.3372/wi.47.47105"),ref.getDoi());
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());
183 // //TODO still missing Y1, Y2, M3, UR
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());
191 // Assert.assertEquals("0511-9618" ,ref.getIssn());
194 // Assert.fail("Only an article and a journal should exist");
201 public void createTestDataSet() throws FileNotFoundException
{}