use of org.simpleflatmapper.test.beans.DbFinalObject in project SimpleFlatMapper by arnaudroger.
the class AsmFactoryTest method testCreateInstantiatorFinalDbObjectInjectIdAndName.
@Test
public void testCreateInstantiatorFinalDbObjectInjectIdAndName() throws Exception {
ExecutableInstantiatorDefinition instantiatorDefinition = (ExecutableInstantiatorDefinition) AsmInstantiatorDefinitionFactory.extractDefinitions(DbFinalObject.class).get(0);
HashMap<Parameter, Getter<? super Object, ?>> injections = new HashMap<Parameter, Getter<? super Object, ?>>();
injections.put(new Parameter(0, "id", long.class), new ConstantLongGetter<Object>(33l));
injections.put(new Parameter(1, "name", String.class), new ConstantGetter<Object, String>("fdo"));
Instantiator<Object, DbFinalObject> instantiator = asmFactory.createInstantiator(Object.class, instantiatorDefinition, injections, true);
DbFinalObject fdo = instantiator.newInstance(new Object());
assertNotNull(fdo);
assertNull(fdo.getEmail());
assertNull(fdo.getCreationTime());
assertNull(fdo.getTypeName());
assertNull(fdo.getTypeOrdinal());
assertEquals(33l, fdo.getId());
assertEquals("fdo", fdo.getName());
assertSame(instantiator.getClass(), asmFactory.createInstantiator(Object.class, instantiatorDefinition, injections, true).getClass());
}
use of org.simpleflatmapper.test.beans.DbFinalObject in project SimpleFlatMapper by arnaudroger.
the class AsmFactoryTest method testCreateInstantiatorFinalDbObjectNameAndType.
@Test
public void testCreateInstantiatorFinalDbObjectNameAndType() throws Exception {
HashMap<Parameter, Getter<? super Object, ?>> injections = new HashMap<Parameter, Getter<? super Object, ?>>();
ConstantIntGetter<Object> getter = new ConstantIntGetter<Object>(1);
injections.put(new Parameter(4, "typeOrdinal", Type.class), new OrdinalEnumGetter<Object, Type>(getter, Type.class));
injections.put(new Parameter(1, "name", String.class), new ConstantGetter<Object, String>("fdo"));
List<InstantiatorDefinition> instantiatorDefinitions = AsmInstantiatorDefinitionFactory.extractDefinitions(DbFinalObject.class);
Instantiator<Object, DbFinalObject> instantiator = asmFactory.createInstantiator(Object.class, (ExecutableInstantiatorDefinition) instantiatorDefinitions.get(0), injections, true);
DbFinalObject fdo = instantiator.newInstance(new Object());
assertNotNull(fdo);
assertNull(fdo.getEmail());
assertNull(fdo.getCreationTime());
assertNull(fdo.getTypeName());
assertEquals(0, fdo.getId());
assertEquals("fdo", fdo.getName());
assertEquals(Type.type2, fdo.getTypeOrdinal());
}
use of org.simpleflatmapper.test.beans.DbFinalObject in project SimpleFlatMapper by arnaudroger.
the class CsvMapperBuilderTest method testMapDbObjectWrongName.
@Test
public void testMapDbObjectWrongName() throws Exception {
MapperBuilderErrorHandler mapperBuilderErrorHandler = mock(MapperBuilderErrorHandler.class);
CsvMapperBuilder<DbFinalObject> builder = csvMapperFactory.mapperBuilderErrorHandler(mapperBuilderErrorHandler).newBuilder(DbFinalObject.class);
builder.addMapping("id");
builder.addMapping("No_prop");
verify(mapperBuilderErrorHandler).propertyNotFound(DbFinalObject.class, "No_prop");
}
use of org.simpleflatmapper.test.beans.DbFinalObject in project SimpleFlatMapper by arnaudroger.
the class JdbcMapperCustomMappingTest method testCustomReaderOnConstructor.
@Test
public void testCustomReaderOnConstructor() throws SQLException, Exception {
JdbcMapperFactory mapperFactory = JdbcMapperFactoryHelper.asm().addCustomGetter("id", new Getter<ResultSet, Long>() {
@Override
public Long get(ResultSet target) throws Exception {
return 1l;
}
});
final JdbcMapper<DbFinalObject> mapper = mapperFactory.newMapper(DbFinalObject.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,", "33 as id,"));
}
Aggregations