Search in sources :

Example 16 with DataSetMetadata

use of org.talend.dataprep.api.dataset.DataSetMetadata in project data-prep by Talend.

the class CSVSerializerTest method should_use_custom_import_parameters_empty_enclosure.

// https://jira.talendforge.org/browse/TDP-4602
@Test
public void should_use_custom_import_parameters_empty_enclosure() throws IOException {
    // given (text escape char is |)
    InputStream inputStream = this.getClass().getResourceAsStream("tdp-4602_custom_param_csv_import.csv");
    DataSetMetadata datasetMetadata = getSimpleDataSetMetadata("column1", "column2");
    datasetMetadata.getContent().addParameter(SEPARATOR_PARAMETER, ",");
    datasetMetadata.getContent().addParameter(ESCAPE_CHAR, "\"");
    datasetMetadata.getContent().addParameter(TEXT_ENCLOSURE_CHAR, "");
    // when
    InputStream input = serializer.serialize(inputStream, datasetMetadata, -1);
    String actual = IOUtils.toString(input, UTF_8);
    // then
    final String expected = IOUtils.toString(this.getClass().getResourceAsStream("tdp-4602_custom_param_csv_import_empty_enclosure.json"), UTF_8);
    JSONAssert.assertEquals(expected, actual, false);
}
Also used : InputStream(java.io.InputStream) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) Test(org.junit.Test)

Example 17 with DataSetMetadata

use of org.talend.dataprep.api.dataset.DataSetMetadata in project data-prep by Talend.

the class CSVSerializerTest method should_use_custom_import_parameters_empty_escape.

// https://jira.talendforge.org/browse/TDP-4602
@Test
public void should_use_custom_import_parameters_empty_escape() throws IOException {
    // given (text escape char is |)
    InputStream inputStream = this.getClass().getResourceAsStream("tdp-4602_custom_param_csv_import.csv");
    DataSetMetadata datasetMetadata = getSimpleDataSetMetadata("column1", "column2");
    datasetMetadata.getContent().addParameter(SEPARATOR_PARAMETER, ",");
    datasetMetadata.getContent().addParameter(ESCAPE_CHAR, "");
    datasetMetadata.getContent().addParameter(TEXT_ENCLOSURE_CHAR, "+");
    // when
    InputStream input = serializer.serialize(inputStream, datasetMetadata, -1);
    String actual = IOUtils.toString(input, UTF_8);
    // then
    final String expected = IOUtils.toString(this.getClass().getResourceAsStream("tdp-4602_custom_param_csv_import_default_escape.json"), UTF_8);
    JSONAssert.assertEquals(expected, actual, false);
}
Also used : InputStream(java.io.InputStream) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) Test(org.junit.Test)

Example 18 with DataSetMetadata

use of org.talend.dataprep.api.dataset.DataSetMetadata in project data-prep by Talend.

the class CSVSerializerTest method should_serialize_csv_with_backslash.

/**
 * Please have a look at <a href="https://jira.talendforge.org/browse/TDP-1623>TDP-1623</a>
 */
@Test
public void should_serialize_csv_with_backslash() throws IOException {
    InputStream inputStream = this.getClass().getResourceAsStream("tdp-1623_backslash_not_imported.csv");
    DataSetMetadata datasetMetadata = getSimpleDataSetMetadata("City");
    InputStream input = serializer.serialize(inputStream, datasetMetadata, -1);
    String actual = IOUtils.toString(input, UTF_8);
    String expected = "[{\"0000\":\"Carson City\\\\Seine\"}]";
    Assert.assertEquals(expected, actual);
}
Also used : InputStream(java.io.InputStream) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) Test(org.junit.Test)

Example 19 with DataSetMetadata

use of org.talend.dataprep.api.dataset.DataSetMetadata in project data-prep by Talend.

the class CSVSerializerTest method shouldManageSpecificTextEnclosureChar.

/**
 * Please, have a look at <a href="https://jira.talendforge.org/browse/TDP-2366">TDP-2366</a>
 */
@Test
public void shouldManageSpecificTextEnclosureChar() throws IOException {
    // given (text enclosing separator is ¤ so that " in original CSV are ignored)
    InputStream inputStream = this.getClass().getResourceAsStream("with_quote_in_text.csv");
    DataSetMetadata datasetMetadata = getSimpleDataSetMetadata("City", "code", "Description");
    datasetMetadata.getContent().addParameter(SEPARATOR_PARAMETER, ",");
    datasetMetadata.getContent().addParameter(TEXT_ENCLOSURE_CHAR, "¤");
    // when
    InputStream input = serializer.serialize(inputStream, datasetMetadata, -1);
    String actual = IOUtils.toString(input, UTF_8);
    // then
    final String expected = IOUtils.toString(this.getClass().getResourceAsStream("with_quote_in_text.json"), UTF_8);
    JSONAssert.assertEquals(expected, actual, false);
}
Also used : InputStream(java.io.InputStream) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) Test(org.junit.Test)

Example 20 with DataSetMetadata

use of org.talend.dataprep.api.dataset.DataSetMetadata in project data-prep by Talend.

the class HtmlSchemaParserTest method should_not_accept_html_update.

@Test
public void should_not_accept_html_update() throws Exception {
    final DataSetMetadata metadata = metadataBuilder.metadata().id("tata").formatFamilyId("formatGuess#html").build();
    assertFalse(parser.accept(metadata));
}
Also used : DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) Test(org.junit.Test)

Aggregations

DataSetMetadata (org.talend.dataprep.api.dataset.DataSetMetadata)192 Test (org.junit.Test)126 DataSetBaseTest (org.talend.dataprep.dataset.DataSetBaseTest)63 ColumnMetadata (org.talend.dataprep.api.dataset.ColumnMetadata)48 InputStream (java.io.InputStream)45 Matchers.containsString (org.hamcrest.Matchers.containsString)28 Matchers.isEmptyString (org.hamcrest.Matchers.isEmptyString)28 TDPException (org.talend.dataprep.exception.TDPException)26 RowMetadata (org.talend.dataprep.api.dataset.RowMetadata)20 DataSetServiceTest (org.talend.dataprep.dataset.service.DataSetServiceTest)20 ApiOperation (io.swagger.annotations.ApiOperation)18 DataSet (org.talend.dataprep.api.dataset.DataSet)18 Type (org.talend.dataprep.api.type.Type)17 Timed (org.talend.dataprep.metrics.Timed)17 DistributedLock (org.talend.dataprep.lock.DistributedLock)16 Autowired (org.springframework.beans.factory.annotation.Autowired)14 DataSetRow (org.talend.dataprep.api.dataset.row.DataSetRow)14 IOException (java.io.IOException)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)13 ArrayList (java.util.ArrayList)12