Search in sources :

Example 11 with DataSetMetadata

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

the class CSVSchemaParserTest method should_accept_csv_update.

@Test
public void should_accept_csv_update() throws Exception {
    final DataSetMetadata metadata = metadataBuilder.metadata().id("toto").formatFamilyId("formatGuess#csv").build();
    assertTrue(csvSchemaParser.accept(metadata));
}
Also used : DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) Test(org.junit.Test)

Example 12 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_default_empty_escape.

// https://jira.talendforge.org/browse/TDP-4602
@Test
public void should_use_custom_import_parameters_default_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(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 13 with DataSetMetadata

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

the class CSVSerializerTest method should_serialize_csv_with_additional_values.

@Test
public void should_serialize_csv_with_additional_values() throws IOException {
    InputStream inputStream = this.getClass().getResourceAsStream("additional_values.csv");
    DataSetMetadata datasetMetadata = getSimpleDataSetMetadata("name", "email");
    InputStream input = serializer.serialize(inputStream, datasetMetadata, -1);
    String actual = IOUtils.toString(input, UTF_8);
    InputStream expected = this.getClass().getResourceAsStream("additional_values.csv_expected.json");
    Assert.assertThat(actual, sameJSONAsFile(expected));
}
Also used : InputStream(java.io.InputStream) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) Test(org.junit.Test)

Example 14 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_backslash_escape.

// https://jira.talendforge.org/browse/TDP-4602
@Test
public void should_use_custom_import_parameters_backslash_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_backslash_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 15 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_double_quote.

// https://jira.talendforge.org/browse/TDP-4579
@Test
public void should_use_custom_import_parameters_double_quote() throws IOException {
    // given (text escape char is |)
    InputStream inputStream = this.getClass().getResourceAsStream("test_4579_doublequote_import.csv");
    DataSetMetadata datasetMetadata = getSimpleDataSetMetadata("City", "code", "Description");
    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("test_4579_doublequote_import.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)

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