package org.talend.dataprep.schema.io;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import org.junit.Assert;
import org.junit.Test;
import org.talend.dataprep.api.dataset.ColumnMetadata;
import org.talend.dataprep.api.dataset.DataSetMetadata;
import org.talend.dataprep.schema.SchemaParser;
import org.talend.dataprep.schema.SchemaParserResult;

/**
 * Unit test for the CSVSchemaParser class.
 * 
 * @see CSVSchemaParser
 */
public class CSVSchemaParserTest {

    /** The parser to test. */
    private CSVSchemaParser parser;

    /**
     * Unit test constructor.
     */
    public CSVSchemaParserTest() {
        parser = new CSVSchemaParser();
    }

    @Test
    public void should_parse_csv() throws IOException {
        String fileName = "org/talend/dataprep/schema/simple.csv";
        try (InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName)) {

            DataSetMetadata datasetMetadata = IoTestUtils.getSimpleDataSetMetadata("first name", "last name");

            SchemaParserResult result = parser.parse(new SchemaParser.Request(inputStream, datasetMetadata));
            List<ColumnMetadata> actual = result.getSheetContents().get(0).getColumnMetadatas();

            Assert.assertEquals(datasetMetadata.getRowMetadata().getColumns(), actual);
        }
    }

}

@@ -33,16 +33,53 @@
 ma.io;%0A%0A
+import java.io.ByteArrayInputStream;%0A
 import j
@@ -1402,10 +1402,777 @@
 %0A    %7D%0A%0A
+    /**%0A     * When trying to guess the columns data type an IndexOutOfBoundsException should not be thrown.%0A     * @throws IOException%0A     */%0A    @Test%0A    public void TDP_898() throws IOException %7B%0A        String str = %22c1;c2%22+System.lineSeparator()+%221;2;false%22;%0A        try (InputStream inputStream = new ByteArrayInputStream(str.getBytes())) %7B%0A            DataSetMetadata datasetMetadata = IoTestUtils.getSimpleDataSetMetadata(%22c1%22, %22c2%22);%0A            try %7B%0A                SchemaParserResult result = parser.parse(new SchemaParser.Request(inputStream, datasetMetadata));%0A            %7D%0A            catch(IndexOutOfBoundsException exc)%7B%0A                Assert.fail(%22Should not throw an IndexOutOfBoundsException, when parsing!%22);%0A            %7D%0A%0A%0A        %7D%0A    %7D%0A%0A
 %7D%0A

add a unit test for TDP-898