use of org.simpleflatmapper.test.beans.DbObject in project SimpleFlatMapper by arnaudroger.
the class JdbcMapperFactoryTest method testSetCheckedConsumerError.
@Test
public void testSetCheckedConsumerError() throws SQLException {
ConsumerErrorHandler errorHandler = mock(ConsumerErrorHandler.class);
ResultSet rs = mock(ResultSet.class);
when(rs.next()).thenReturn(true, true, false);
when(rs.getLong(1)).thenReturn(1l);
final Exception exception = new SQLException("Error!");
JdbcMapper<DbObject> mapper = JdbcMapperFactoryHelper.asm().consumerErrorHandler(errorHandler).newBuilder(DbObject.class).addMapping("id").mapper();
mapper.forEach(rs, new CheckedConsumer<DbObject>() {
@Override
public void accept(DbObject dbObject) throws Exception {
throw exception;
}
});
verify(errorHandler, times(2)).handlerError(same(exception), any(DbObject.class));
}
use of org.simpleflatmapper.test.beans.DbObject in project SimpleFlatMapper by arnaudroger.
the class JdbcMapperToStringTest method testDynamicJdbcMapperNoAsm.
@Test
public void testDynamicJdbcMapperNoAsm() throws SQLException {
JdbcMapper<DbObject> mapper = JdbcMapperFactoryHelper.noAsm().newMapper(DbObject.class);
ResultSet rs = mock(ResultSet.class);
ResultSetMetaData metaData = mock(ResultSetMetaData.class);
when(rs.getMetaData()).thenReturn(metaData);
when(metaData.getColumnCount()).thenReturn(1);
when(metaData.getColumnLabel(1)).thenReturn("id");
mapper.iterator(rs);
assertNotNull(mapper.toString());
}
use of org.simpleflatmapper.test.beans.DbObject in project SimpleFlatMapper by arnaudroger.
the class JdbcMapperCustomMappingTest method testColumnAlias.
@Test
public void testColumnAlias() throws Exception {
JdbcMapperFactory mapperFactory = JdbcMapperFactoryHelper.asm();
mapperFactory.addAlias("not_id_column", "id");
final JdbcMapper<DbObject> mapper = mapperFactory.newMapper(DbObject.class);
DbHelper.testQuery(new TestRowHandler<PreparedStatement>() {
@Override
public void handle(PreparedStatement t) throws Exception {
ResultSet r = t.executeQuery();
r.next();
DbHelper.assertDbObjectMapping(mapper.map(r));
}
}, DbHelper.TEST_DB_OBJECT_QUERY.replace("id,", "id as not_id_column,"));
}
use of org.simpleflatmapper.test.beans.DbObject in project SimpleFlatMapper by arnaudroger.
the class JdbcMapperErrorTest method testHandleMapperErrorSetterNotFound.
@Test
public void testHandleMapperErrorSetterNotFound() throws NoSuchMethodException, SecurityException, IOException {
MapperBuilderErrorHandler errorHandler = mock(MapperBuilderErrorHandler.class);
JdbcMapperBuilder<DbObject> builder = JdbcMapperFactoryHelper.asm().mapperBuilderErrorHandler(errorHandler).newBuilder(DbObject.class);
builder.addMapping("id", 1);
builder.addMapping("notthere1", 2);
verify(errorHandler).propertyNotFound(DbObject.class, "notthere1");
builder.addMapping("notthere3");
verify(errorHandler).propertyNotFound(DbObject.class, "notthere3");
}
use of org.simpleflatmapper.test.beans.DbObject in project SimpleFlatMapper by arnaudroger.
the class JdbcMapperErrorTest method testInstantiatorError.
@Test
public void testInstantiatorError() {
MapperImpl<ResultSet, DbObject> mapper = new MapperImpl<ResultSet, DbObject>(null, null, new BiInstantiator<ResultSet, MappingContext<? super ResultSet>, DbObject>() {
@Override
public DbObject newInstance(ResultSet s, MappingContext<? super ResultSet> context) throws Exception {
throw new IOException();
}
});
try {
mapper.map(null);
fail("Expected error");
} catch (Exception e) {
assertTrue(e instanceof IOException);
}
}
Aggregations