Project

General

Profile

Download (10.9 KB) Statistics
| Branch: | Tag: | Revision:
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 119 references (still need to count them)", 119, list.size());
155
        //TODO deduplication
156

    
157
        Reference ref58 = list.stream().filter(r->hasId(r, "58", false)).findFirst().get();
158
        Assert.assertNotNull("", ref58);
159
        Assert.assertEquals((Integer)2003, ref58.getDatePublished().getStartYear());
160

    
161
        Reference ref53 = list.stream().filter(r->hasId(r, "53", false)).findFirst().get();
162
        Assert.assertNotNull("", ref53);
163
        Assert.assertEquals(ReferenceType.BookSection, ref53.getType());
164
        Assert.assertNotNull("", ref53.getInReference());
165
        Assert.assertEquals("Tehran", ref53.getInReference().getPlacePublished());
166

    
167

    
168
        //        for (Reference ref : list){
169
//            Assert.assertTrue(ref.getType() == ReferenceType.Article || ref.getType() == ReferenceType.Journal);
170
//            if (ref.getType() == ReferenceType.Article){
171
//                //title
172
//                Assert.assertEquals("Decorsella arborea, a second species in Decorsella (Violaceae), and Decorsella versus Rinorea",
173
//                        ref.getTitle());
174
//                //author
175
//                TeamOrPersonBase<?> author = ref.getAuthorship();
176
//                Assert.assertNotNull(author);
177
//                Assert.assertTrue(author.isInstanceOf(Person.class));
178
//                Person person = CdmBase.deproxy(author, Person.class);
179
//                //this may change in future depending on the correct formatting strategy
180
//                Assert.assertEquals("Carel C. H. Jongkind" ,person.getTitleCache());
181
//                Assert.assertEquals("Jongkind" ,person.getFamilyName());
182
//                Assert.assertEquals("Carel C. H." ,person.getGivenName());
183
//                //date
184
//                TimePeriod date = ref.getDatePublished();
185
//                Assert.assertEquals(Integer.valueOf(2017) ,date.getStartYear());
186
//                //vol
187
//                Assert.assertEquals("47(1)" ,ref.getVolume());
188
//                Assert.assertEquals("43-47" ,ref.getPages());
189
//
190
//                //doi
191
//                Assert.assertEquals(DOI.fromString("10.3372/wi.47.47105"),ref.getDoi());
192
//
193
//                //Abstract
194
//                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.",
195
//                        ref.getReferenceAbstract());
196
//
197
//                //TODO still missing Y1, Y2, M3, UR
198
//
199
//            }else if (ref.getType() == ReferenceType.Journal){
200
//                Assert.assertEquals("Willdenowia", ref.getTitle());
201
//                //or is this part of article?
202
//                Assert.assertEquals("Botanic Garden and Botanical Museum Berlin (BGBM)", ref.getPublisher());
203
//
204
//                //ISSN
205
//                Assert.assertEquals("0511-9618" ,ref.getIssn());
206
//
207
//            }else{
208
//                Assert.fail("Only an article and a journal should exist");
209
//            }
210
//        }
211

    
212
    }
213

    
214
    private boolean hasId(Reference ref, String idStr, boolean getInRef) {
215
        if (ref.getSources().size() != 1){
216
            return false;
217
        }else{
218
            String idInSource = ref.getSources().iterator().next().getIdInSource();
219
            return idStr.equals(idInSource) &&
220
                    (getInRef && ref.getInReference()== null
221
                      || !getInRef && ref.getInReference()!= null );
222
        }
223
    }
224

    
225
    @Override
226
    public void createTestDataSet() throws FileNotFoundException {}
227
}
    (1-1/1)