Search in sources :

Example 6 with CsvComplexType

use of io.atlasmap.csv.v2.CsvComplexType in project atlasmap by atlasmap.

the class CsvFieldReaderTest method testReadSchemaWithFirstRecordAsHeader.

@Test
public void testReadSchemaWithFirstRecordAsHeader() throws Exception {
    CsvConfig csvConfig = new CsvConfig();
    csvConfig.setFirstRecordAsHeader(true);
    CsvFieldReader csvFieldReader = new CsvFieldReader(csvConfig);
    csvFieldReader.setDocument(new ByteArrayInputStream("givenName,familyName\nBob,Smith\nAndrew,Johnson".getBytes()));
    AtlasInternalSession session = mock(AtlasInternalSession.class);
    when(session.head()).thenReturn(mock(AtlasInternalSession.Head.class));
    Document document = csvFieldReader.readSchema();
    CsvComplexType list = (CsvComplexType) document.getFields().getField().get(0);
    assertEquals("givenName", list.getCsvFields().getCsvField().get(0).getName());
    assertEquals("familyName", list.getCsvFields().getCsvField().get(1).getName());
}
Also used : AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) ByteArrayInputStream(java.io.ByteArrayInputStream) CsvComplexType(io.atlasmap.csv.v2.CsvComplexType) Document(io.atlasmap.v2.Document) Test(org.junit.jupiter.api.Test)

Aggregations

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