use of org.simpleflatmapper.util.ListCollector in project SimpleFlatMapper by arnaudroger.
the class CsvMapperDateFormatTest method testReadMultipleFormat.
@Test
public void testReadMultipleFormat() throws Exception {
String format1 = "dd/MM/yyyy";
String format2 = "MM-dd-yyyy";
String format3 = "yyyyMMdd";
CsvMapper<ObjectWithDate> mapper = CsvMapperFactory.newInstance().addColumnProperty(TRUE, new DateFormatProperty(format1)).addColumnProperty(TRUE, new DateFormatProperty(format2)).addColumnProperty(TRUE, new DateFormatProperty(format3)).newMapper(ObjectWithDate.class);
String data = "date1\n18/06/2016\n06-19-2016\n20160620";
List<ObjectWithDate> list = mapper.forEach(new StringReader(data), new ListCollector<ObjectWithDate>()).getList();
assertEquals(3, list.size());
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
assertEquals(sdf.parse("20160618"), list.get(0).date1);
assertEquals(sdf.parse("20160619"), list.get(1).date1);
assertEquals(sdf.parse("20160620"), list.get(2).date1);
}
use of org.simpleflatmapper.util.ListCollector in project SimpleFlatMapper by arnaudroger.
the class CsvMapperJoinTest method testDynamicProfessorField.
@Test
public void testDynamicProfessorField() throws IOException {
final CsvMapperFactory mapperFactory = getCsvMapperFactory();
final List<ProfessorField> professors = mapperFactory.newMapper(ProfessorField.class).forEach(new StringReader(HEADER_DATA), new ListCollector<ProfessorField>()).getList();
JoinTest.validateProfessors(professors);
}
use of org.simpleflatmapper.util.ListCollector in project SimpleFlatMapper by arnaudroger.
the class CsvMapperJoinTest method testDynamicProfessorC.
@Test
public void testDynamicProfessorC() throws IOException {
final CsvMapperFactory mapperFactory = getCsvMapperFactory();
final List<ProfessorC> professors = mapperFactory.newMapper(ProfessorC.class).forEach(new StringReader(HEADER_DATA), new ListCollector<ProfessorC>()).getList();
JoinTest.validateProfessors(professors);
}
use of org.simpleflatmapper.util.ListCollector in project SimpleFlatMapper by arnaudroger.
the class CsvParserTest method testYamlCommentParserForEachRowComment.
@Test
public void testYamlCommentParserForEachRowComment() throws IOException {
String data = "test,\" \"\"hello\"\" \"\n# this a comment, not data\none more";
CsvParser.DSLYamlComment dsl = CsvParser.dsl().withYamlComments();
ListCollector<String[]> rowCollector = new ListCollector<String[]>();
ListCollector<String> commentCollector = new ListCollector<String>();
dsl.forEach(data, rowCollector, commentCollector);
checkYamlCommentParserRows(rowCollector.getList());
checkYamlComments(commentCollector.getList());
rowCollector = new ListCollector<String[]>();
commentCollector = new ListCollector<String>();
dsl.forEach(createTempCsv(data), rowCollector, commentCollector);
checkYamlCommentParserRows(rowCollector.getList());
checkYamlComments(commentCollector.getList());
rowCollector = new ListCollector<String[]>();
commentCollector = new ListCollector<String>();
dsl.forEach(new StringReader(data), rowCollector, commentCollector);
checkYamlCommentParserRows(rowCollector.getList());
checkYamlComments(commentCollector.getList());
rowCollector = new ListCollector<String[]>();
commentCollector = new ListCollector<String>();
dsl.forEach(new StringBuilder(data), rowCollector, commentCollector);
checkYamlCommentParserRows(rowCollector.getList());
checkYamlComments(commentCollector.getList());
}
use of org.simpleflatmapper.util.ListCollector in project SimpleFlatMapper by arnaudroger.
the class CsvMapperBuilderSubObjectTest method testMapDbPartialObject.
@Test
public void testMapDbPartialObject() throws UnsupportedEncodingException, Exception {
CsvMapperBuilder<Db1DeepPartialObject> builder = new CsvMapperBuilder<Db1DeepPartialObject>(Db1DeepPartialObject.class);
addDbObjectFields(builder);
CsvMapper<Db1DeepPartialObject> mapper = builder.mapper();
List<Db1DeepPartialObject> list = mapper.forEach(db1deepObjectCsvReader(), new ListCollector<Db1DeepPartialObject>()).getList();
assertEquals(1, list.size());
Db1DeepPartialObject o = list.get(0);
assertEquals(1234, o.getId());
assertEquals("val!", o.getValue());
DbHelper.assertDbObjectMapping(o.getDbObject());
}
Aggregations