use of org.simpleflatmapper.util.ListCollector in project SimpleFlatMapper by arnaudroger.
the class CsvMapperDateFormatTest method testReadMultipleFormatOverrideDefault.
@Test
public void testReadMultipleFormatOverrideDefault() throws Exception {
String format1 = "dd/MM/yyyy";
String format2 = "MM-dd-yyyy";
CsvMapper<ObjectWithDate> mapper = CsvMapperFactory.newInstance().defaultDateFormat(format1).addColumnProperty(TRUE, new DateFormatProperty(format2)).newMapper(ObjectWithDate.class);
String data1 = "date1\n18/06/2016";
String data2 = "date1\n06-19-2016";
try {
mapper.forEach(new StringReader(data1), new ListCollector<ObjectWithDate>()).getList();
fail();
} catch (Exception e) {
//
}
List<ObjectWithDate> list = mapper.forEach(new StringReader(data2), new ListCollector<ObjectWithDate>()).getList();
assertEquals(1, list.size());
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
assertEquals(sdf.parse("20160619"), list.get(0).date1);
}
use of org.simpleflatmapper.util.ListCollector in project SimpleFlatMapper by arnaudroger.
the class CsvMapperDateFormatTest method testSetCustomDateFormat.
@Test
public void testSetCustomDateFormat() throws ParseException, MappingException, IOException {
String format = "dd/MM/yyyy HH:mm";
CsvMapper<ObjectWithDate> mapper = CsvMapperFactory.newInstance().defaultDateFormat(format).newMapper(ObjectWithDate.class);
SimpleDateFormat sdf = new SimpleDateFormat(format);
String strDate = sdf.format(new Date());
Date date = sdf.parse(strDate);
String data = "date1,date2\n" + strDate + "," + strDate;
List<ObjectWithDate> list = mapper.forEach(new StringReader(data), new ListCollector<ObjectWithDate>()).getList();
assertEquals(1, list.size());
assertEquals(date, list.get(0).date1);
assertEquals(date, list.get(0).date2);
}
use of org.simpleflatmapper.util.ListCollector in project SimpleFlatMapper by arnaudroger.
the class CsvMapperJoinTest method testDynamicProfessorGS.
@Test
public void testDynamicProfessorGS() throws IOException {
final CsvMapperFactory mapperFactory = getCsvMapperFactory();
final List<ProfessorGS> professors = mapperFactory.newMapper(ProfessorGS.class).forEach(new StringReader(HEADER_DATA), new ListCollector<ProfessorGS>()).getList();
JoinTest.validateProfessors(professors);
}
use of org.simpleflatmapper.util.ListCollector in project SimpleFlatMapper by arnaudroger.
the class CsvMapperJoinTest method testDynamicProfessorGSSharding.
@Test
public void testDynamicProfessorGSSharding() throws IOException {
final CsvMapperFactory mapperFactory = getCsvShardingMapperFactory();
final List<ProfessorGS> professors = mapperFactory.newMapper(ProfessorGS.class).forEach(new StringReader(HEADER_DATA), new ListCollector<ProfessorGS>()).getList();
JoinTest.validateProfessors(professors);
}
use of org.simpleflatmapper.util.ListCollector in project SimpleFlatMapper by arnaudroger.
the class CsvMapperJoinTest method testDynamicProfessorCSharding.
@Test
public void testDynamicProfessorCSharding() throws IOException {
final CsvMapperFactory mapperFactory = getCsvShardingMapperFactory();
final List<ProfessorC> professors = mapperFactory.newMapper(ProfessorC.class).forEach(new StringReader(HEADER_DATA), new ListCollector<ProfessorC>()).getList();
JoinTest.validateProfessors(professors);
}
Aggregations