use of org.simpleflatmapper.test.beans.DbObject in project SimpleFlatMapper by arnaudroger.
the class AbstractConstantTargetMapperBuilderTest method testConstantValue.
@Test
public void testConstantValue() throws Exception {
ClassMeta<DbObject> classMeta = ReflectionService.newInstance().<DbObject>getClassMeta(DbObject.class);
Writerbuilder<DbObject> builder = new Writerbuilder<DbObject>(classMeta);
builder.addColumn("id");
builder.addColumn("blop", new ConstantValueProperty<String>("blop", String.class));
DbObject dbObject = DbObject.newInstance();
List<Object> list = builder.mapper().map(dbObject);
assertEquals(list.get(0), dbObject.getId());
assertEquals("blop", list.get(1));
}
use of org.simpleflatmapper.test.beans.DbObject in project SimpleFlatMapper by arnaudroger.
the class AbstractMapperBuilderTest method testDefaultValue.
@Test
public void testDefaultValue() throws Exception {
ClassMeta<DbObject> classMeta = ReflectionService.newInstance().<DbObject>getClassMeta(DbObject.class);
FieldMapperColumnDefinitionProviderImpl<SampleFieldKey> definitionProvider = new FieldMapperColumnDefinitionProviderImpl<SampleFieldKey>();
definitionProvider.addColumnProperty("type_name", new DefaultValueProperty<DbObject.Type>(DbObject.Type.type4));
MapperConfig<SampleFieldKey, FieldMapperColumnDefinition<SampleFieldKey>> mapperConfig = MapperConfig.<SampleFieldKey>fieldMapperConfig().columnDefinitions(definitionProvider);
Mapper<Object[], DbObject> mapper = new SampleMapperBuilder<DbObject>(classMeta, mapperConfig).addMapping("id").mapper();
Object[] data = new Object[] { 3l };
DbObject dbObject = mapper.map(data);
assertEquals(3l, dbObject.getId());
assertEquals(DbObject.Type.type4, dbObject.getTypeName());
}
use of org.simpleflatmapper.test.beans.DbObject in project SimpleFlatMapper by arnaudroger.
the class AbstractMapperBuilderTest method testSetDbObject.
@Test
public void testSetDbObject() {
ClassMeta<Set<DbObject>> classMeta = ReflectionService.disableAsm().<Set<DbObject>>getClassMeta(new TypeReference<Set<DbObject>>() {
}.getType());
Mapper<Object[], Set<DbObject>> mapper = new SampleMapperBuilder<Set<DbObject>>(classMeta).addMapping("1_id").addMapping("1_name").addMapping("2_id").addMapping("2_name").mapper();
Set<DbObject> map = mapper.map(new Object[] { 1l, "name1", 2l, "name2" });
assertEquals(2, map.size());
Iterator<DbObject> it = map.iterator();
DbObject o = it.next();
if (o.getId() == 1l) {
assertEquals("name1", o.getName());
o = it.next();
assertEquals(2l, o.getId());
assertEquals("name2", o.getName());
} else {
assertEquals("name2", o.getName());
o = it.next();
assertEquals(1l, o.getId());
assertEquals("name1", o.getName());
}
}
use of org.simpleflatmapper.test.beans.DbObject in project SimpleFlatMapper by arnaudroger.
the class PropertyMappingsBuilderTest method testSelfPropertyInvalidation.
@Test
public void testSelfPropertyInvalidation() {
final ClassMeta<DbObject> classMeta = ReflectionService.newInstance().getClassMeta(DbObject.class);
MapperBuilderErrorHandler errorHandler = mock(MapperBuilderErrorHandler.class);
PropertyMappingsBuilder<DbObject, SampleFieldKey, FieldMapperColumnDefinition<SampleFieldKey>> builder = PropertyMappingsBuilder.of(classMeta, MapperConfig.<SampleFieldKey>fieldMapperConfig().mapperBuilderErrorHandler(errorHandler), ConstantPredicate.<PropertyMeta<?, ?>>truePredicate());
builder.addProperty(new SampleFieldKey("self", 0), FieldMapperColumnDefinition.<SampleFieldKey>identity());
verify(errorHandler, never()).customFieldError(any(FieldKey.class), any(String.class));
verify(errorHandler, never()).accessorNotFound(any(String.class));
verify(errorHandler, never()).propertyNotFound(any(Type.class), any(String.class));
builder.addProperty(new SampleFieldKey("id", 1), FieldMapperColumnDefinition.<SampleFieldKey>identity());
verify(errorHandler).propertyNotFound(DbObject.class, "self");
}
use of org.simpleflatmapper.test.beans.DbObject in project SimpleFlatMapper by arnaudroger.
the class SetRowMapperTest method checkSetRowMapperIdNameEmail.
private void checkSetRowMapperIdNameEmail(SetRowMapper<Object[], Object[][], DbObject, RuntimeException> staticSetRowMapper) throws Exception {
checkIdNameEmailResult(staticSetRowMapper.forEach(ID_NAME_EMAIL_DATA, new ListCollector<DbObject>()).getList());
checkIdNameEmailResult(staticSetRowMapper.iterator(ID_NAME_EMAIL_DATA));
// IFJAVA8_START
checkIdNameEmailResult(staticSetRowMapper.stream(ID_NAME_EMAIL_DATA).collect(Collectors.<DbObject>toList()));
// IFJAVA8_END
checkIdNameEmailRow(1l, staticSetRowMapper.map(ID_NAME_EMAIL_DATA[0]));
checkIdNameEmailRow(1l, staticSetRowMapper.map(ID_NAME_EMAIL_DATA[0], null));
DbObject d = new DbObject();
staticSetRowMapper.mapTo(ID_NAME_EMAIL_DATA[0], d, null);
checkIdNameEmailRow(1l, d);
}
Aggregations