Search in sources :

Example 21 with CsvField

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);
}
Also used : FieldGroup(io.atlasmap.v2.FieldGroup) CsvField(io.atlasmap.csv.v2.CsvField) Test(org.junit.jupiter.api.Test)

Aggregations

CsvField (io.atlasmap.csv.v2.CsvField)21 FieldGroup (io.atlasmap.v2.FieldGroup)16 Test (org.junit.jupiter.api.Test)16 ByteArrayInputStream (java.io.ByteArrayInputStream)8 AtlasInternalSession (io.atlasmap.spi.AtlasInternalSession)6 Audits (io.atlasmap.v2.Audits)6 AtlasException (io.atlasmap.api.AtlasException)4 CsvComplexType (io.atlasmap.csv.v2.CsvComplexType)4 Field (io.atlasmap.v2.Field)4 CsvInspectionResponse (io.atlasmap.csv.v2.CsvInspectionResponse)3 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 Response (javax.ws.rs.core.Response)3 CSVFormat (org.apache.commons.csv.CSVFormat)3 InputStreamReader (java.io.InputStreamReader)2 CSVParser (org.apache.commons.csv.CSVParser)2 CSVRecord (org.apache.commons.csv.CSVRecord)2 AtlasPath (io.atlasmap.core.AtlasPath)1 CsvFields (io.atlasmap.csv.v2.CsvFields)1