use of org.simpleflatmapper.test.map.SampleFieldKey in project SimpleFlatMapper by arnaudroger.
the class ConstantSourceMapperBuilderTest method testMapInnerObjectWithMapper.
@Test
public void testMapInnerObjectWithMapper() throws Exception {
ConstantSourceMapperBuilder<Object, MyObjectWithInner, SampleFieldKey> constantSourceMapperBuilder = new ConstantSourceMapperBuilder<Object, MyObjectWithInner, SampleFieldKey>(mapperSource, classMeta, MapperConfig.config(new IdentityFieldMapperColumnDefinitionProvider<SampleFieldKey>()), new MappingContextFactoryBuilder<Object, SampleFieldKey>(null), SampleFieldKey.KEY_FACTORY);
constantSourceMapperBuilder.addMapping(new SampleFieldKey("prop_date", 0), FieldMapperColumnDefinition.<SampleFieldKey>identity());
Mapper<Object, MyObjectWithInner> mapper = constantSourceMapperBuilder.mapper();
MyObjectWithInner o = mapper.map(null);
assertEquals(DATE, o.prop.date);
assertNull(o.prop.str);
}
use of org.simpleflatmapper.test.map.SampleFieldKey in project SimpleFlatMapper by arnaudroger.
the class ConstantSourceMapperBuilderTest method testFieldMapperErrorHandler.
@Test
public void testFieldMapperErrorHandler() throws Exception {
ConstantSourceMapperBuilder<Object, MyObjectWithInner, SampleFieldKey> constantSourceMapperBuilder = new ConstantSourceMapperBuilder<Object, MyObjectWithInner, SampleFieldKey>(mapperSource, classMeta, MapperConfig.config(new IdentityFieldMapperColumnDefinitionProvider<SampleFieldKey>()).fieldMapperErrorHandler(new FieldMapperErrorHandler<SampleFieldKey>() {
@Override
public void errorMappingField(SampleFieldKey key, Object source, Object target, Exception error) throws MappingException {
}
}), new MappingContextFactoryBuilder<Object, SampleFieldKey>(null), SampleFieldKey.KEY_FACTORY);
constantSourceMapperBuilder.addMapping(new SampleFieldKey("prop_date", 16), FieldMapperColumnDefinition.<SampleFieldKey>identity());
Mapper<Object, MyObjectWithInner> mapper = constantSourceMapperBuilder.mapper();
MyObjectWithInner o = mapper.map(null);
System.out.println("mapper = " + mapper);
assertNull(o.prop);
}
use of org.simpleflatmapper.test.map.SampleFieldKey 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.map.SampleFieldKey in project SimpleFlatMapper by arnaudroger.
the class AbstractMapperFactoryTest method testAliases.
@Test
public void testAliases() {
MapperFactory mapperFactory = new MapperFactory();
mapperFactory.addAlias("a", "aa");
mapperFactory.addAliases(new HashMap<String, String>() {
{
put("b", "bb");
put("c", "cc");
}
});
Assert.assertArrayEquals(new Object[] { new RenameProperty("aa") }, mapperFactory.columnDefinitions().getColumnDefinition(new SampleFieldKey("a", 0)).properties());
Assert.assertArrayEquals(new Object[] { new RenameProperty("bb") }, mapperFactory.columnDefinitions().getColumnDefinition(new SampleFieldKey("b", 0)).properties());
Assert.assertArrayEquals(new Object[] { new RenameProperty("cc") }, mapperFactory.columnDefinitions().getColumnDefinition(new SampleFieldKey("c", 0)).properties());
Assert.assertArrayEquals(new Object[] {}, mapperFactory.columnDefinitions().getColumnDefinition(new SampleFieldKey("d", 0)).properties());
}
use of org.simpleflatmapper.test.map.SampleFieldKey in project SimpleFlatMapper by arnaudroger.
the class AbstractMapperFactoryTest method testColumnProperty.
@Test
public void testColumnProperty() {
MapperFactory mapperFactory = new MapperFactory();
Object prop1 = new Object();
Object prop2 = new Object();
final Object prop3 = new Object();
mapperFactory.addColumnProperty("mykey", prop1);
mapperFactory.addColumnProperty(new Predicate<SampleFieldKey>() {
@Override
public boolean test(SampleFieldKey sampleFieldKey) {
return sampleFieldKey.getIndex() < 1;
}
}, prop2);
mapperFactory.addColumnProperty(new Predicate<SampleFieldKey>() {
@Override
public boolean test(SampleFieldKey sampleFieldKey) {
return sampleFieldKey.getIndex() < 1;
}
}, new UnaryFactory<SampleFieldKey, Object>() {
@Override
public Object newInstance(SampleFieldKey sampleFieldKey) {
return prop3;
}
});
Assert.assertArrayEquals(new Object[] { prop3, prop2, prop1 }, mapperFactory.columnDefinitions().getColumnDefinition(new SampleFieldKey("mykey", 0)).properties());
Assert.assertArrayEquals(new Object[] { prop1 }, mapperFactory.columnDefinitions().getColumnDefinition(new SampleFieldKey("mykey", 1)).properties());
}
Aggregations