Search in sources :

Example 81 with RowMetadata

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

the class CSVWriterTest method should_write_with_any_escape_character.

/**
 * see https://jira.talendforge.org/browse/TDP-4390
 */
@Test
public void should_write_with_any_escape_character() throws Exception {
    // given
    final ByteArrayOutputStream temp = new ByteArrayOutputStream();
    Map<String, Object> parameters = new HashMap<>();
    parameters.put(ESCAPE_CHARACTER_PARAM_NAME, "#");
    final CSVWriter tabWriter = (CSVWriter) context.getBean("writer#CSV", temp, parameters);
    final ColumnMetadata column1 = column().id(1).name("song").type(Type.STRING).build();
    final ColumnMetadata column2 = column().id(2).name("band").type(Type.STRING).build();
    final List<ColumnMetadata> columns = Arrays.asList(column1, column2);
    final RowMetadata rowMetadata = new RowMetadata(columns);
    Map<String, String> values = new HashMap<>();
    values.put("0001", "last \"nite");
    values.put("0002", "the Strokes");
    final DataSetRow row = new DataSetRow(rowMetadata, values);
    // when
    tabWriter.write(row);
    tabWriter.write(rowMetadata);
    tabWriter.flush();
    // then
    final String expectedCsv = "\"song\";\"band\"\n" + "\"last #\"nite\";\"the Strokes\"\n";
    assertThat(temp.toString(UTF_8.name())).isEqualTo(expectedCsv);
}
Also used : ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test) AbstractTransformerWriterTest(org.talend.dataprep.transformation.api.transformer.AbstractTransformerWriterTest)

Example 82 with RowMetadata

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

the class JsonWriterTest method write_should_write_columns.

@Test
public void write_should_write_columns() throws Exception {
    // given
    final ColumnMetadata column1 = ColumnMetadata.Builder.column().id(1).name("id").type(Type.STRING).build();
    final ColumnMetadata column2 = ColumnMetadata.Builder.column().id(2).name("firstname").type(Type.STRING).build();
    final List<ColumnMetadata> columns = new ArrayList<>(2);
    columns.add(column1);
    columns.add(column2);
    String expectedOutput = IOUtils.toString(JsonWriterTest.class.getResourceAsStream("expected_columns.json"), UTF_8);
    // when
    writer.write(new RowMetadata(columns));
    writer.close();
    // then
    assertThat(new String(outputStream.toByteArray()), sameJSONAs(expectedOutput).allowingExtraUnexpectedFields());
}
Also used : ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) ArrayList(java.util.ArrayList) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) Test(org.junit.Test)

Example 83 with RowMetadata

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

the class XlsWriterTest method should_only_write_values_in_columns_order_TDP_3188.

/**
 * <a href="https://jira.talendforge.org/browse/TDP-3188>TDP-3188</a>
 */
@Test(expected = IllegalStateException.class)
public void should_only_write_values_in_columns_order_TDP_3188() throws Exception {
    final Map<String, String> values = new HashMap<>();
    values.put("key", "value");
    DataSetRow row = new DataSetRow(new RowMetadata(), values);
    writer.write(row);
}
Also used : HashMap(java.util.HashMap) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test)

Example 84 with RowMetadata

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

the class PreparationExportStrategyTest method setUp.

@Before
public void setUp() throws Exception {
    // Given
    mapper.registerModule(new Jdk8Module());
    strategy.setMapper(new ObjectMapper());
    when(formatRegistrationService.getByName(eq("JSON"))).thenReturn(new JsonFormat());
    final DataSetGetMetadata dataSetGetMetadata = mock(DataSetGetMetadata.class);
    when(applicationContext.getBean(eq(DataSetGetMetadata.class), anyVararg())).thenReturn(dataSetGetMetadata);
    DataSetGet dataSetGet = mock(DataSetGet.class);
    final StringWriter dataSetAsString = new StringWriter();
    DataSet dataSet = new DataSet();
    final DataSetMetadata dataSetMetadata = new DataSetMetadata("ds-1234", "", "", 0L, 0L, new RowMetadata(), "");
    final DataSetContent content = new DataSetContent();
    dataSetMetadata.setContent(content);
    dataSet.setMetadata(dataSetMetadata);
    dataSet.setRecords(Stream.empty());
    mapper.writerFor(DataSet.class).writeValue(dataSetAsString, dataSet);
    when(dataSetGet.execute()).thenReturn(new ByteArrayInputStream(dataSetAsString.toString().getBytes()));
    when(applicationContext.getBean(eq(DataSetGet.class), anyVararg())).thenReturn(dataSetGet);
    final PreparationGetActions preparationGetActions = mock(PreparationGetActions.class);
    when(preparationGetActions.execute()).thenReturn(new ByteArrayInputStream("{}".getBytes()));
    when(applicationContext.getBean(eq(PreparationGetActions.class), eq("prep-1234"), anyString())).thenReturn(preparationGetActions);
    final TransformationCacheKey cacheKey = mock(TransformationCacheKey.class);
    when(cacheKey.getKey()).thenReturn("cache-1234");
    when(cacheKeyGenerator.generateContentKey(anyString(), anyString(), anyString(), anyString(), any(), any(), anyString())).thenReturn(cacheKey);
    final ExecutableTransformer executableTransformer = mock(ExecutableTransformer.class);
    reset(transformer);
    when(transformer.buildExecutable(any(), any())).thenReturn(executableTransformer);
    when(factory.get(any())).thenReturn(transformer);
    when(contentCache.put(any(), any())).thenReturn(new NullOutputStream());
}
Also used : DataSetGet(org.talend.dataprep.command.dataset.DataSetGet) DataSet(org.talend.dataprep.api.dataset.DataSet) DataSetGetMetadata(org.talend.dataprep.command.dataset.DataSetGetMetadata) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) TransformationCacheKey(org.talend.dataprep.cache.TransformationCacheKey) Jdk8Module(com.fasterxml.jackson.datatype.jdk8.Jdk8Module) JsonFormat(org.talend.dataprep.transformation.format.JsonFormat) StringWriter(java.io.StringWriter) ByteArrayInputStream(java.io.ByteArrayInputStream) PreparationGetActions(org.talend.dataprep.command.preparation.PreparationGetActions) ExecutableTransformer(org.talend.dataprep.transformation.api.transformer.ExecutableTransformer) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) DataSetContent(org.talend.dataprep.api.dataset.DataSetContent) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) NullOutputStream(org.apache.commons.io.output.NullOutputStream) Before(org.junit.Before)

Example 85 with RowMetadata

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

the class AbstractTransformerWriterTest method should_only_write_values_in_columns_order_TDP_3188.

/**
 * <a href="https://jira.talendforge.org/browse/TDP-3188>TDP-3188</a>
 */
@Test(expected = IllegalStateException.class)
public void should_only_write_values_in_columns_order_TDP_3188() throws Exception {
    final Map<String, String> values = new HashMap<>();
    values.put("key", "value");
    DataSetRow row = new DataSetRow(new RowMetadata(), values);
    writer.write(row);
}
Also used : HashMap(java.util.HashMap) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) BaseFormatTest(org.talend.dataprep.transformation.format.BaseFormatTest) Test(org.junit.Test)

Aggregations

RowMetadata (org.talend.dataprep.api.dataset.RowMetadata)199 Test (org.junit.Test)130 DataSetRow (org.talend.dataprep.api.dataset.row.DataSetRow)112 ColumnMetadata (org.talend.dataprep.api.dataset.ColumnMetadata)87 AbstractMetadataBaseTest (org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)68 HashMap (java.util.HashMap)48 ActionContext (org.talend.dataprep.transformation.api.action.context.ActionContext)21 DataSetMetadata (org.talend.dataprep.api.dataset.DataSetMetadata)20 RunnableAction (org.talend.dataprep.transformation.actions.common.RunnableAction)19 TransformationContext (org.talend.dataprep.transformation.api.action.context.TransformationContext)18 ArrayList (java.util.ArrayList)16 DataSet (org.talend.dataprep.api.dataset.DataSet)11 List (java.util.List)9 Statistics (org.talend.dataprep.api.dataset.statistics.Statistics)9 Before (org.junit.Before)7 SemanticDomain (org.talend.dataprep.api.dataset.statistics.SemanticDomain)6 Preparation (org.talend.dataprep.api.preparation.Preparation)6 Response (com.jayway.restassured.response.Response)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 Logger (org.slf4j.Logger)5