Project

General

Profile

Download (9.86 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

    
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.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.TeamOrPersonBase;
32
import eu.etaxonomy.cdm.model.common.CdmBase;
33
import eu.etaxonomy.cdm.model.common.TimePeriod;
34
import eu.etaxonomy.cdm.model.reference.Reference;
35
import eu.etaxonomy.cdm.model.reference.ReferenceType;
36
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
37
import eu.etaxonomy.cdm.test.unitils.CleanSweepInsertLoadStrategy;
38

    
39
/**
40
 * @author a.mueller
41
 *
42
 */
43
public class RisReferenceImportTest extends CdmTransactionalIntegrationTest {
44

    
45
	@SpringBeanByName
46
	private CdmApplicationAwareDefaultImport<?> defaultImport;
47

    
48
	@SpringBeanByType
49
	private IReferenceService referenceService;
50

    
51

    
52
	private RisReferenceImportConfigurator configurator;
53
    private RisReferenceImportConfigurator configLong;
54

    
55
	@Before
56
	public void setUp() {
57
		String inputFile = "/eu/etaxonomy/cdm/io/reference/RisReferenceImportTest-input.ris";
58

    
59
        try {
60
            URL url = this.getClass().getResource(inputFile);
61
            assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);
62

    
63
            String inputFileLong = "/eu/etaxonomy/cdm/io/reference/Acantholimon.ris";
64
            URL urlLong = this.getClass().getResource(inputFileLong);
65
            assertNotNull("URL for the test file '" + inputFileLong + "' does not exist", urlLong);
66

    
67
			configurator = RisReferenceImportConfigurator.NewInstance(url, null);
68
			configLong = RisReferenceImportConfigurator.NewInstance(urlLong, null);
69

    
70

    
71
		} catch (Exception e) {
72
			e.printStackTrace();
73
			Assert.fail();
74
		}
75
		assertNotNull("Configurator could not be created", configurator);
76
	    assertNotNull("Configurator could not be created", configLong);
77
	    assertNotNull("nameService should not be null", referenceService);
78
	}
79

    
80
//***************************** TESTS *************************************//
81

    
82
	@Test
83
	@DataSet( value="/eu/etaxonomy/cdm/database/BlankDataSet.xml", loadStrategy=CleanSweepInsertLoadStrategy.class)
84
	//@Ignore
85
    public void testShort() {
86

    
87
		ImportResult result = defaultImport.invoke(configurator);
88
		String report = result.createReport().toString();
89
		Assert.assertTrue(report.length() > 0);
90
		System.out.println(report);
91

    
92
		Integer expected = 2;
93
		Assert.assertEquals(expected, result.getNewRecords(Reference.class));
94

    
95
		List<Reference> list = referenceService.list(Reference.class, null, null, null, null);
96
		Assert.assertEquals("There should be 3 references, the article and the journal and the source reference",
97
		        3, list.size());
98
		for (Reference ref : list){
99
		    if (ref.equals(configurator.getSourceReference())){
100
		        continue;
101
		    }
102
		    Assert.assertTrue(ref.getType() == ReferenceType.Article || ref.getType() == ReferenceType.Journal);
103
		    if (ref.getType() == ReferenceType.Article){
104
		        //title
105
		        Assert.assertEquals("Decorsella arborea, a second species in Decorsella (Violaceae), and Decorsella versus Rinorea",
106
		                ref.getTitle());
107
		        //author
108
		        TeamOrPersonBase<?> author = ref.getAuthorship();
109
		        Assert.assertNotNull(author);
110
		        Assert.assertTrue(author.isInstanceOf(Person.class));
111
		        Person person = CdmBase.deproxy(author, Person.class);
112
		        //this may change in future depending on the correct formatting strategy
113
		        Assert.assertEquals("Jongkind, C.C.H." ,person.getTitleCache());
114
		        Assert.assertEquals("Jongkind" ,person.getFamilyName());
115
		        Assert.assertEquals("Carel C. H." ,person.getGivenName());
116
		        //date
117
		        TimePeriod date = ref.getDatePublished();
118
		        Assert.assertEquals(Integer.valueOf(2017) ,date.getStartYear());
119
		        //vol
120
		        Assert.assertEquals("47(1)" ,ref.getVolume());
121
                Assert.assertEquals("43-47" ,ref.getPages());
122

    
123
                //doi
124
                //Assert.assertEquals(DOI.fromString("10.3372/wi.47.47105"),ref.getDoi());
125

    
126
                //Abstract
127
                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.",
128
                        ref.getReferenceAbstract());
129

    
130
                //TODO still missing Y1, Y2, M3, UR
131

    
132
		    }else if (ref.getType() == ReferenceType.Journal){
133
		        Assert.assertEquals("Willdenowia", ref.getTitle());
134
		        //or is this part of article?
135
		        Assert.assertEquals("Botanic Garden and Botanical Museum Berlin (BGBM)", ref.getPublisher());
136

    
137
		        //ISSN
138
                Assert.assertEquals("0511-9618" ,ref.getIssn());
139

    
140
		    }else{
141
		        Assert.fail("Only an article and a journal should exist");
142
		    }
143
		}
144

    
145
	}
146

    
147
	@Test
148
	//@Ignore
149
    public void testLongFile() {
150
        ImportResult result = defaultImport.invoke(configLong);
151
        String report = result.createReport().toString();
152
        System.out.println(report);
153

    
154
        Integer expected = 118;  //did not count yet
155
        Assert.assertEquals(expected, result.getNewRecords(Reference.class));
156

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

    
203
    }
204

    
205
    @Override
206
    public void createTestDataSet() throws FileNotFoundException {}
207
}
(2-2/2)