1
|
/**
|
2
|
* Copyright (C) 2009 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.dwca.in;
|
10
|
|
11
|
|
12
|
import static org.junit.Assert.assertNotNull;
|
13
|
|
14
|
import java.io.IOException;
|
15
|
import java.net.URI;
|
16
|
import java.net.URL;
|
17
|
|
18
|
import org.apache.log4j.Logger;
|
19
|
import org.junit.Assert;
|
20
|
import org.junit.Before;
|
21
|
import org.junit.BeforeClass;
|
22
|
import org.junit.Test;
|
23
|
|
24
|
import eu.etaxonomy.cdm.io.dwca.jaxb.Extension;
|
25
|
import eu.etaxonomy.cdm.io.stream.CsvStream;
|
26
|
import eu.etaxonomy.cdm.io.stream.StreamItem;
|
27
|
|
28
|
|
29
|
/**
|
30
|
* @author a.mueller
|
31
|
\* @since 17.10.2011
|
32
|
*
|
33
|
*/
|
34
|
public class DwcaZipToStreamConverterTest {
|
35
|
@SuppressWarnings("unused")
|
36
|
private static final Logger logger = Logger.getLogger(DwcaZipToStreamConverterTest.class);
|
37
|
|
38
|
private URI uri;
|
39
|
private DwcaZipToStreamConverter<?> converter;
|
40
|
|
41
|
/**
|
42
|
* @throws java.lang.Exception
|
43
|
*/
|
44
|
@BeforeClass
|
45
|
public static void setUpBeforeClass() throws Exception {
|
46
|
}
|
47
|
|
48
|
/**
|
49
|
* @throws java.lang.Exception
|
50
|
*/
|
51
|
@Before
|
52
|
public void setUp() throws Exception {
|
53
|
String inputFile = "/eu/etaxonomy/cdm/io/dwca/in/DwcaZipToStreamConverterTest-input.zip";
|
54
|
URL url = this.getClass().getResource(inputFile);
|
55
|
uri = url.toURI();
|
56
|
assertNotNull("URI for the test file '" + inputFile + "' does not exist", uri);
|
57
|
converter = DwcaZipToStreamConverter.NewInstance(uri);
|
58
|
assertNotNull("Converter must be created",converter);
|
59
|
}
|
60
|
|
61
|
//************* TEST ********************************************
|
62
|
|
63
|
@Test
|
64
|
public void testInitMetadata(){
|
65
|
String coreEncoding = converter.getArchive().getCore().getEncoding();
|
66
|
Assert.assertEquals("Encoding for core must be 'UTF-8'", "UTF-8", coreEncoding);
|
67
|
}
|
68
|
|
69
|
@Test
|
70
|
public void testGetCoreStream(){
|
71
|
try {
|
72
|
CsvStream coreStream = converter.getCoreStream(null);
|
73
|
Assert.assertNotNull("core stream should not be null", coreStream);
|
74
|
StreamItem next = coreStream.read();
|
75
|
Assert.assertNotNull("Entry should exist in core stream", next);
|
76
|
Assert.assertEquals("First entry should be id1", "1", next.get("id"));
|
77
|
Assert.assertEquals("First entries acceptedNameUsage should be ", "1", next.map.get("http://rs.tdwg.org/dwc/terms/acceptedNameUsageID"));
|
78
|
|
79
|
} catch (IOException e) {
|
80
|
Assert.fail();
|
81
|
}
|
82
|
|
83
|
}
|
84
|
|
85
|
|
86
|
@Test
|
87
|
public void testGetVernacularStream(){
|
88
|
try {
|
89
|
CsvStream vernacularStream = converter.getStream(Extension.VERNACULAR_NAME,null);
|
90
|
Assert.assertNotNull("Vernacular stream should not be null", vernacularStream);
|
91
|
StreamItem next = vernacularStream.read();
|
92
|
Assert.assertNotNull("Entry should exist in vernacular name stream", next);
|
93
|
} catch (IOException e) {
|
94
|
Assert.fail();
|
95
|
}
|
96
|
|
97
|
}
|
98
|
|
99
|
/**
|
100
|
* This test tests the correct handling of core/extension attributes like encoding, fieldsTerminatedBy,
|
101
|
* fieldsEnclosdeBy, ignoreHeaderLines, linesTerminatedBy
|
102
|
* TODO encoding + linesTerminatedBy not yet tested
|
103
|
*/
|
104
|
@Test
|
105
|
public void testCoreExtensionAttributes(){
|
106
|
try {
|
107
|
CsvStream vernacularStream = converter.getStream(Extension.VERNACULAR_NAME,null);
|
108
|
StreamItem next = vernacularStream.read();
|
109
|
Assert.assertNotNull("Entry should exist in vernacular name stream", next);
|
110
|
Assert.assertEquals("First entry should be coreid1", "1", next.get("coreId"));
|
111
|
Assert.assertEquals("First entries language should be 'en' ", "en", next.map.get("http://purl.org/dc/terms/language"));
|
112
|
|
113
|
} catch (IOException e) {
|
114
|
Assert.fail();
|
115
|
}
|
116
|
|
117
|
}
|
118
|
|
119
|
|
120
|
}
|