Search in sources :

Example 1 with ListCollector

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

Example 2 with ListCollector

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

Example 3 with ListCollector

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);
}
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)

Example 4 with ListCollector

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

Example 5 with ListCollector

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());
}
Also used : Db1DeepPartialObject(org.simpleflatmapper.test.beans.Db1DeepPartialObject) ListCollector(org.simpleflatmapper.util.ListCollector) CsvMapperBuilder(org.simpleflatmapper.csv.CsvMapperBuilder) Test(org.junit.Test)

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