Search in sources :

Example 16 with ListCollector

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);
}
Also used : ListCollector(org.simpleflatmapper.util.ListCollector) StringReader(java.io.StringReader) SimpleDateFormat(java.text.SimpleDateFormat) MappingException(org.simpleflatmapper.map.MappingException) IOException(java.io.IOException) ParseException(java.text.ParseException) DateFormatProperty(org.simpleflatmapper.map.property.DateFormatProperty) Test(org.junit.Test)

Example 17 with ListCollector

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);
}
Also used : ListCollector(org.simpleflatmapper.util.ListCollector) StringReader(java.io.StringReader) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Test(org.junit.Test)

Example 18 with ListCollector

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);
}
Also used : ProfessorGS(org.simpleflatmapper.test.beans.ProfessorGS) ListCollector(org.simpleflatmapper.util.ListCollector) StringReader(java.io.StringReader) CsvMapperFactory(org.simpleflatmapper.csv.CsvMapperFactory) Test(org.junit.Test) JoinTest(org.simpleflatmapper.test.jdbc.JoinTest)

Example 19 with ListCollector

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);
}
Also used : ProfessorGS(org.simpleflatmapper.test.beans.ProfessorGS) ListCollector(org.simpleflatmapper.util.ListCollector) StringReader(java.io.StringReader) CsvMapperFactory(org.simpleflatmapper.csv.CsvMapperFactory) Test(org.junit.Test) JoinTest(org.simpleflatmapper.test.jdbc.JoinTest)

Example 20 with ListCollector

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);
}
Also used : ListCollector(org.simpleflatmapper.util.ListCollector) StringReader(java.io.StringReader) CsvMapperFactory(org.simpleflatmapper.csv.CsvMapperFactory) ProfessorC(org.simpleflatmapper.test.beans.ProfessorC) Test(org.junit.Test) JoinTest(org.simpleflatmapper.test.jdbc.JoinTest)

Aggregations

ListCollector (org.simpleflatmapper.util.ListCollector)26 Test (org.junit.Test)22 StringReader (java.io.StringReader)10 ResultSet (java.sql.ResultSet)6 CsvMapperFactory (org.simpleflatmapper.csv.CsvMapperFactory)5 JoinTest (org.simpleflatmapper.test.jdbc.JoinTest)5 CsvMapperBuilder (org.simpleflatmapper.csv.CsvMapperBuilder)4 JdbcColumnKey (org.simpleflatmapper.jdbc.JdbcColumnKey)4 DbObject (org.simpleflatmapper.test.beans.DbObject)4 ParseException (java.text.ParseException)3 SimpleDateFormat (java.text.SimpleDateFormat)3 ProfessorGS (org.simpleflatmapper.test.beans.ProfessorGS)3 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 Statement (java.sql.Statement)2 DateFormatProperty (org.simpleflatmapper.map.property.DateFormatProperty)2 Db1DeepPartialObject (org.simpleflatmapper.test.beans.Db1DeepPartialObject)2 ProfessorC (org.simpleflatmapper.test.beans.ProfessorC)2 IOException (java.io.IOException)1 Annotation (java.lang.annotation.Annotation)1