use of io.atlasmap.csv.v2.CsvField in project atlasmap by atlasmap.
the class CsvFieldWriterTest method testWithSimpleDocumentWithHeaderAndDelimiterSpecified.
@Test
public void testWithSimpleDocumentWithHeaderAndDelimiterSpecified() throws Exception {
CsvConfig csvConfig = new CsvConfig();
csvConfig.setDelimiter(';');
csvConfig.setHeaders("familyName;givenName");
CsvFieldWriter writer = new CsvFieldWriter(csvConfig);
FieldGroup sourceField = new FieldGroup();
sourceField.setName("name");
sourceField.setPath("/<>/name");
CsvField sourceSubField0 = new CsvField();
sourceSubField0.setName("name");
sourceSubField0.setPath("/<0>/name");
sourceSubField0.setValue("Bob");
sourceField.getField().add(sourceSubField0);
CsvField sourceSubField1 = new CsvField();
sourceSubField1.setName("name");
sourceSubField1.setPath("/<1>/name");
sourceSubField1.setValue("Andrew");
sourceField.getField().add(sourceSubField1);
CsvField targetField = new CsvField();
targetField.setName("givenName");
targetField.setPath("/<>/givenName");
write(writer, sourceField, targetField);
sourceField = new FieldGroup();
sourceField.setName("family");
sourceField.setPath("/<>/family");
sourceSubField0 = new CsvField();
sourceSubField0.setName("family");
sourceSubField0.setPath("/<0>/family");
sourceSubField0.setValue("Smith");
sourceField.getField().add(sourceSubField0);
sourceSubField1 = new CsvField();
sourceSubField1.setName("family");
sourceSubField1.setPath("/<1>/family");
sourceSubField1.setValue("Johnson");
sourceField.getField().add(sourceSubField1);
targetField = new CsvField();
targetField.setName("familyName");
targetField.setPath("/<>/familyName");
write(writer, sourceField, targetField);
String csv = writer.toCsv();
assertEquals("familyName;givenName\r\nSmith;Bob\r\nJohnson;Andrew\r\n", csv);
}
Aggregations