use of org.simpleflatmapper.util.ListCollector in project SimpleFlatMapper by arnaudroger.
the class CsvMapperBuilderSubObjectTest method testMapDbFinalObject.
@Test
public void testMapDbFinalObject() throws Exception {
CsvMapperBuilder<DbFinal1DeepObject> builder = new CsvMapperBuilder<DbFinal1DeepObject>(DbFinal1DeepObject.class);
addDbObjectFields(builder);
CsvMapper<DbFinal1DeepObject> mapper = builder.mapper();
List<DbFinal1DeepObject> list = mapper.forEach(db1deepObjectCsvReader(), new ListCollector<DbFinal1DeepObject>()).getList();
assertEquals(1, list.size());
DbFinal1DeepObject o = list.get(0);
assertEquals(1234, o.getId());
assertEquals("val!", o.getValue());
DbHelper.assertDbObjectMapping(o.getDbObject());
}
use of org.simpleflatmapper.util.ListCollector in project SimpleFlatMapper by arnaudroger.
the class JdbcMapperFactoryTest method testFieldErrorHandling.
@Test
public void testFieldErrorHandling() throws SQLException, Exception, ParseException {
@SuppressWarnings("unchecked") FieldMapperErrorHandler<JdbcColumnKey> fieldMapperErrorHandler = mock(FieldMapperErrorHandler.class);
final Exception exception = new Exception("Error!");
JdbcMapper<DbObject> mapper = JdbcMapperFactoryHelper.asm().fieldMapperErrorHandler(fieldMapperErrorHandler).addCustomFieldMapper("id", new FieldMapper<ResultSet, DbObject>() {
@Override
public void mapTo(ResultSet source, DbObject target, MappingContext<? super ResultSet> mappingContext) throws Exception {
throw exception;
}
}).newBuilder(DbObject.class).addMapping("id").mapper();
List<DbObject> list = mapper.forEach(new MockDbObjectResultSet(1), new ListCollector<DbObject>()).getList();
assertNotNull(list.get(0));
verify(fieldMapperErrorHandler).errorMappingField(eq(new JdbcColumnKey("id", 1)), any(), same(list.get(0)), same(exception));
}
use of org.simpleflatmapper.util.ListCollector in project SimpleFlatMapper by arnaudroger.
the class JdbcMapperListTest method testIssue458.
private void testIssue458(boolean useAsm) throws SQLException {
JdbcMapper<Col> mapper = JdbcMapperFactory.newInstance().useAsm(useAsm).addKeys("id", "photos_name", "videos_name").newBuilder(Col.class).addMapping("id", 1, 4).addMapping("name", 2, 12).addMapping("photos_name", 3, 12).addMapping("videos_name", 4, 12).mapper();
Connection dbConnection = DbHelper.getDbConnection(DbHelper.TargetDB.POSTGRESQL);
if (dbConnection == null) {
return;
}
Statement statement = dbConnection.createStatement();
ResultSet rs = statement.executeQuery("with \n" + "\tcols(id, name, photos, videos) " + "AS (VALUES(2, 'trees', 'some_photo.jpg', 'videos'), " + "(2, 'trees', 'some_photo2.jpg', 'videos'), " + "(4, 'flowers', null, 'some_videos.mpg'))\n" + "select id, name, photos, videos\n" + "from cols\n" + "order by id");
List<Col> list = mapper.forEach(rs, new ListCollector<Col>()).getList();
assertEquals(2, list.size());
assertEquals(2, list.get(0).id);
assertEquals("trees", list.get(0).name);
assertEquals(Arrays.asList("some_photo.jpg", "some_photo2.jpg"), list.get(0).photos);
assertEquals(Arrays.asList("videos"), list.get(0).videos);
assertEquals(4, list.get(1).id);
assertEquals("flowers", list.get(1).name);
assertEquals(Arrays.asList(), list.get(1).photos);
assertEquals(Arrays.asList("some_videos.mpg"), list.get(1).videos);
dbConnection.close();
}
use of org.simpleflatmapper.util.ListCollector in project SimpleFlatMapper by arnaudroger.
the class DiscriminatorMapperTest method testMapStudentProfessor.
@Test
public void testMapStudentProfessor() {
List<Person> list = mapper.forEach(new Object[][] { { "student", "sname", 1 }, { "professor", "pname", 2 } }, new ListCollector<Person>()).getList();
assertEquals(2, list.size());
StudentGS studentGS = (StudentGS) list.get(0);
ProfessorGS professorGS = (ProfessorGS) list.get(1);
assertEquals("sname", studentGS.getName());
assertEquals("pname", professorGS.getName());
}
use of org.simpleflatmapper.util.ListCollector in project SimpleFlatMapper by arnaudroger.
the class JoinJdbcMapperTest method validateMapper.
private <T extends Professor<?>> void validateMapper(JdbcMapper<T> mapper) throws Exception {
List<T> professors = mapper.forEach(setUpResultSetMock(), new ListCollector<T>()).getList();
JoinTest.validateProfessors(professors);
// IFJAVA8_START
JoinTest.validateProfessors(mapper.stream(setUpResultSetMock()).collect(Collectors.<T>toList()));
JoinTest.validateProfessors(mapper.stream(setUpResultSetMock()).limit(3).collect(Collectors.<T>toList()));
// IFJAVA8_END
Iterator<T> iterator = mapper.iterator(setUpResultSetMock());
professors = new ArrayList<T>();
while (iterator.hasNext()) {
professors.add(iterator.next());
}
JoinTest.validateProfessors(professors);
final ResultSet rs = setUpResultSetMock();
rs.next();
MappingContext<? super ResultSet> mappingContext = mapper.newMappingContext(rs);
mappingContext.broke(rs);
final T professor = mapper.map(rs, mappingContext);
JoinTest.validateProfessorMap(professor);
rs.next();
mappingContext.broke(rs);
rs.next();
mappingContext.broke(rs);
mapper.mapTo(rs, professor, mappingContext);
JoinTest.validateProfessorMapTo(professor);
}
Aggregations