2 * Copyright (C) 2009 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.
9 package eu
.etaxonomy
.cdm
.io
.dwca
.in
;
11 import static org
.junit
.Assert
.assertNotNull
;
13 import java
.io
.IOException
;
17 import org
.apache
.log4j
.Logger
;
18 import org
.junit
.Assert
;
19 import org
.junit
.Before
;
20 import org
.junit
.Test
;
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
;
30 public class DwcaZipToStreamConverterTest
{
32 @SuppressWarnings("unused")
33 private static final Logger logger
= Logger
.getLogger(DwcaZipToStreamConverterTest
.class);
36 private DwcaZipToStreamConverter
<?
> converter
;
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
);
43 assertNotNull("URI for the test file '" + inputFile
+ "' does not exist", uri
);
44 converter
= DwcaZipToStreamConverter
.NewInstance(uri
);
45 assertNotNull("Converter must be created",converter
);
48 //************* 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
);
57 public void testGetCoreStream(){
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"));
66 } catch (IOException e
) {
72 public void testGetVernacularStream(){
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
) {
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
89 public void testCoreExtensionAttributes(){
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"));
97 } catch (IOException e
) {