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