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);
}
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());
}
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);
}
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());
}
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);
}
Aggregations