use of io.atlasmap.csv.v2.CsvField in project atlasmap by atlasmap.
the class CsvFieldWriterTest method testWithSimpleDocumentWithoutHeader.
@Test
public void testWithSimpleDocumentWithoutHeader() throws Exception {
CsvConfig csvConfig = new CsvConfig();
csvConfig.setSkipHeaderRecord(true);
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);
String csv = writer.toCsv();
assertEquals("Bob\r\nAndrew\r\n", csv);
}
use of io.atlasmap.csv.v2.CsvField in project atlasmap by atlasmap.
the class CsvFieldWriterTest method testWithHeaderAndIgnoreHeaderCase.
@Test
public void testWithHeaderAndIgnoreHeaderCase() throws Exception {
CsvConfig csvConfig = new CsvConfig();
csvConfig.setHeaders("FAMILYNAME,GIVENNAME");
csvConfig.setIgnoreHeaderCase(true);
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);
String csv = writer.toCsv();
assertEquals("FAMILYNAME,GIVENNAME\r\n,Bob\r\n,Andrew\r\n", csv);
}
use of io.atlasmap.csv.v2.CsvField in project atlasmap by atlasmap.
the class CsvServiceTest method testSchemaNoParametersSpecified.
@Test
public void testSchemaNoParametersSpecified() throws Exception {
final String source = "l1r1,l1r2,l1r3\n" + "l2r1,l2r2,l2r3\n" + "l3r1,l3r2,l3r3\n";
InputStream inputStream = new ByteArrayInputStream(source.getBytes());
Response res = csvService.inspect(inputStream, null, null, null, null, null, null, null, null, null, null, null, null, null, null);
Object entity = res.getEntity();
assertEquals(byte[].class, entity.getClass());
CsvInspectionResponse csvInspectionResponse = Json.mapper().readValue((byte[]) entity, CsvInspectionResponse.class);
CsvComplexType complexType = (CsvComplexType) csvInspectionResponse.getCsvDocument().getFields().getField().get(0);
List<CsvField> fields = complexType.getCsvFields().getCsvField();
assertEquals("0", fields.get(0).getName());
assertEquals("1", fields.get(1).getName());
assertEquals("2", fields.get(2).getName());
}
use of io.atlasmap.csv.v2.CsvField in project atlasmap by atlasmap.
the class CsvServiceTest method testSchemaFile.
@Test
public void testSchemaFile() throws Exception {
InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("test.csv");
Response res = csvService.inspect(inputStream, null, ",", true, null, null, null, null, null, null, null, null, null, null, null);
Object entity = res.getEntity();
assertEquals(byte[].class, entity.getClass());
CsvInspectionResponse csvInspectionResponse = Json.mapper().readValue((byte[]) entity, CsvInspectionResponse.class);
CsvComplexType complexType = (CsvComplexType) csvInspectionResponse.getCsvDocument().getFields().getField().get(0);
List<CsvField> fields = complexType.getCsvFields().getCsvField();
assertEquals(5, fields.size());
assertEquals("sourceCsvString", fields.get(0).getName());
assertEquals("sourceCsvNumber", fields.get(1).getName());
assertEquals("sourceCsvDecimal", fields.get(2).getName());
assertEquals("sourceCsvDate", fields.get(3).getName());
assertEquals("sourceCsvBoolean", fields.get(4).getName());
}
use of io.atlasmap.csv.v2.CsvField in project atlasmap by atlasmap.
the class CsvServiceTest method testSchema.
@Test
public void testSchema() throws Exception {
final String source = "header1,header2,header3\n" + "l1r1,l1r2,l1r3\n" + "l2r1,l2r2,l2r3\n" + "l3r1,l3r2,l3r3\n";
InputStream inputStream = new ByteArrayInputStream(source.getBytes());
Response res = csvService.inspect(inputStream, null, ",", true, null, null, null, null, null, null, null, null, null, null, null);
Object entity = res.getEntity();
assertEquals(byte[].class, entity.getClass());
CsvInspectionResponse csvInspectionResponse = Json.mapper().readValue((byte[]) entity, CsvInspectionResponse.class);
CsvComplexType complexType = (CsvComplexType) csvInspectionResponse.getCsvDocument().getFields().getField().get(0);
List<CsvField> fields = complexType.getCsvFields().getCsvField();
assertEquals("header1", fields.get(0).getName());
assertEquals("header2", fields.get(1).getName());
assertEquals("header3", fields.get(2).getName());
}
Aggregations