use of org.simpleflatmapper.test.beans.Db1DeepObject in project SimpleFlatMapper by arnaudroger.
the class CsvMapperBuilderSubObjectTest method testMapDbObject.
@Test
public void testMapDbObject() throws Exception {
CsvMapperBuilder<Db1DeepObject> builder = new CsvMapperBuilder<Db1DeepObject>(Db1DeepObject.class, ReflectionService.newInstance(false));
addDbObjectFields(builder);
CsvMapper<Db1DeepObject> mapper = builder.mapper();
List<Db1DeepObject> list = mapper.forEach(db1deepObjectCsvReader(), new ListCollector<Db1DeepObject>()).getList();
assertEquals(1, list.size());
Db1DeepObject o = list.get(0);
assertEquals(1234, o.getId());
assertEquals("val!", o.getValue());
DbHelper.assertDbObjectMapping(o.getDbObject());
}
use of org.simpleflatmapper.test.beans.Db1DeepObject in project SimpleFlatMapper by arnaudroger.
the class JdbcMapperSubObjectTest method testMapInnerObjectWithColumnDefinition.
@Test
public void testMapInnerObjectWithColumnDefinition() throws Exception {
JdbcMapperBuilder<Db1DeepObject> builder = JdbcMapperFactoryHelper.asm().newBuilder(Db1DeepObject.class);
FieldMapperColumnDefinition<JdbcColumnKey> columnDefinition = FieldMapperColumnDefinition.customGetter(new Getter<ResultSet, String>() {
@Override
public String get(ResultSet target) throws Exception {
return "ov1";
}
});
builder.addMapping("db_object_name", columnDefinition);
final JdbcMapper<Db1DeepObject> mapper = builder.mapper();
ResultSet rs = mock(ResultSet.class);
when(rs.getString(1)).thenReturn("name1");
when(rs.next()).thenReturn(true, false);
Db1DeepObject next = mapper.iterator(rs).next();
assertEquals("ov1", next.getDbObject().getName());
}
use of org.simpleflatmapper.test.beans.Db1DeepObject in project SimpleFlatMapper by arnaudroger.
the class CsvMapperBuilderSubObjectTest method testMapDbObjectWithCustomReader.
@Test
public void testMapDbObjectWithCustomReader() throws Exception {
CsvMapperBuilder<Db1DeepObject> builder = new CsvMapperBuilder<Db1DeepObject>(Db1DeepObject.class, ReflectionService.newInstance(false));
CsvColumnDefinition columnDefinition = CsvColumnDefinition.customReaderDefinition(new CellValueReader<String>() {
@Override
public String read(char[] chars, int offset, int length, ParsingContext parsingContext) {
return "cv1";
}
});
builder.addMapping("db_Object_name", columnDefinition);
CsvMapper<Db1DeepObject> mapper = builder.mapper();
Db1DeepObject v1 = mapper.iterator(new StringReader("v1")).next();
assertEquals("cv1", v1.getDbObject().getName());
}
use of org.simpleflatmapper.test.beans.Db1DeepObject in project SimpleFlatMapper by arnaudroger.
the class SubPropertyMetaTest method testSubProperty.
@Test
@SuppressWarnings("unchecked")
public void testSubProperty() throws Exception {
ClassMeta<Db1DeepObject> classMeta = ReflectionService.newInstance().getClassMeta(Db1DeepObject.class);
PropertyMeta<Db1DeepObject, String> property = classMeta.newPropertyFinder(new Predicate<PropertyMeta<?, ?>>() {
@Override
public boolean test(PropertyMeta<?, ?> propertyMeta) {
return true;
}
}).findProperty(new DefaultPropertyNameMatcher("dbObject_name", 0, false, false), new Object[0]);
assertTrue(property instanceof SubPropertyMeta);
assertTrue(property.isSubProperty());
assertTrue(property.toString().startsWith("SubPropertyMeta{" + "ownerProperty=ObjectPropertyMeta{"));
SubPropertyMeta<Db1DeepObject, DbObject, String> subPropertyMeta = (SubPropertyMeta<Db1DeepObject, DbObject, String>) property;
assertEquals(String.class, subPropertyMeta.getPropertyType());
assertEquals("dbObject.name", subPropertyMeta.getPath());
Db1DeepObject object = new Db1DeepObject();
object.setDbObject(new DbObject());
subPropertyMeta.getSetter().set(object, "n1");
Getter<Db1DeepObject, String> getter = subPropertyMeta.getGetter();
assertEquals("n1", getter.get(object));
Db1DeepObject objectNull = new Db1DeepObject();
assertEquals(null, getter.get(objectNull));
assertTrue(getter.toString().startsWith("GetterOnGetter{g1="));
ClassMeta<?> meta = subPropertyMeta.getPropertyClassMeta();
assertEquals(String.class, meta.getType());
}
Aggregations