use of org.simpleflatmapper.test.map.SampleFieldKey in project SimpleFlatMapper by arnaudroger.
the class Issue366 method testBreakDetector.
@Test
public void testBreakDetector() throws Exception {
KeySourceGetter<SampleFieldKey, Object> keySourceGetter = mock(KeySourceGetter.class);
Object object = new Object();
SampleFieldKey key = new SampleFieldKey("k", 1);
when(keySourceGetter.getValue(key, object)).thenReturn(new byte[] { 1, 2 }, new byte[] { 1, 2 }, new byte[] { 1, 3 });
KeyDefinition<Object, SampleFieldKey> keyDefinition = new KeyDefinition<Object, SampleFieldKey>(new SampleFieldKey[] { key }, keySourceGetter, 0);
BreakDetector<Object> breakDetector = new BreakDetector<Object>(keyDefinition);
assertTrue(breakDetector.broke(object));
assertFalse(breakDetector.broke(object));
assertTrue(breakDetector.broke(object));
}
use of org.simpleflatmapper.test.map.SampleFieldKey in project SimpleFlatMapper by arnaudroger.
the class AbstractMapperBuilderTest method testConversionCharacterToJodaTime.
@Test
public void testConversionCharacterToJodaTime() {
ClassMeta<List<DateTime>> classMeta = ReflectionService.disableAsm().<List<DateTime>>getClassMeta(new TypeReference<List<DateTime>>() {
}.getType());
DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("yyyyMMdd HH:mm:ss.SSSS Z");
Mapper<Object[], List<DateTime>> mapper = new SampleMapperBuilder<List<DateTime>>(classMeta).addMapping(new SampleFieldKey("0", 0, new Class[0], String.class), dateTimeFormatter).mapper();
DateTime now = DateTime.now();
Object[] objects = new Object[] { dateTimeFormatter.print(now) };
List<DateTime> map = mapper.map(objects);
assertEquals(now, map.get(0));
}
use of org.simpleflatmapper.test.map.SampleFieldKey in project SimpleFlatMapper by arnaudroger.
the class AbstractMapperBuilderTest method testCustomization.
@Test
public void testCustomization() throws Exception {
ClassMeta<DbObject> classMeta = ReflectionService.newInstance().getClassMeta(DbObject.class);
Mapper<Object[], DbObject> mapper = new SampleMapperBuilder<DbObject>(classMeta).addKey("id").addMapper(new FieldMapper<Object[], DbObject>() {
@Override
public void mapTo(Object[] source, DbObject target, MappingContext<? super Object[]> context) throws Exception {
target.setName("fieldMapper");
}
}).addMapping("email", new GetterProperty(new Getter<Object, String>() {
@Override
public String get(Object target) throws Exception {
return "getterEmail";
}
})).mapper();
DbObject dbObject = mapper.map(new Object[] { 1l });
assertEquals(1, dbObject.getId());
assertEquals("fieldMapper", dbObject.getName());
assertEquals("getterEmail", dbObject.getEmail());
mapper = new SampleMapperBuilder<DbObject>(classMeta).addKey("id").addMapping("email", (Object) FieldMapperColumnDefinition.<SampleFieldKey>identity().add(new GetterProperty(new Getter<Object, String>() {
@Override
public String get(Object target) throws Exception {
return "getterEmail";
}
}))).addMapping("name", FieldMapperColumnDefinition.<SampleFieldKey>identity().add(new GetterProperty(new Getter<Object, String>() {
@Override
public String get(Object target) throws Exception {
return "getterName";
}
}))).mapper();
dbObject = mapper.map(new Object[] { 1l });
assertEquals(1, dbObject.getId());
assertEquals("getterEmail", dbObject.getEmail());
assertEquals("getterName", dbObject.getName());
}
use of org.simpleflatmapper.test.map.SampleFieldKey in project SimpleFlatMapper by arnaudroger.
the class AbstractMapperFactoryTest method testDefaultMapperConfig.
@Test
public void testDefaultMapperConfig() {
MapperFactory mapperFactory = new MapperFactory();
MapperConfig<SampleFieldKey, FieldMapperColumnDefinition<SampleFieldKey>> mapperConfig = mapperFactory.mapperConfig();
final ArrayList<Object> properties = new ArrayList<Object>();
mapperConfig.columnDefinitions().forEach(Object.class, new BiConsumer<Predicate<? super SampleFieldKey>, Object>() {
@Override
public void accept(Predicate<? super SampleFieldKey> predicate, Object o) {
properties.add(o);
}
});
assertTrue(properties.isEmpty());
assertFalse(mapperConfig.failOnAsm());
assertEquals(NO_ASM_MAPPER_THRESHOLD, mapperConfig.asmMapperNbFieldsLimit());
assertNull(mapperConfig.fieldMapperErrorHandler());
assertFalse(mapperConfig.hasFieldMapperErrorHandler());
assertTrue(mapperConfig.mapperBuilderErrorHandler() instanceof RethrowMapperBuilderErrorHandler);
assertTrue(mapperConfig.consumerErrorHandler() instanceof RethrowConsumerErrorHandler);
assertEquals(MapperConfig.MAX_METHOD_SIZE, mapperConfig.maxMethodSize());
assertTrue(mapperConfig.propertyNameMatcherFactory() instanceof DefaultPropertyNameMatcherFactory);
assertTrue(mapperFactory.getReflectionService().isAsmActivated());
}
use of org.simpleflatmapper.test.map.SampleFieldKey in project SimpleFlatMapper by arnaudroger.
the class AbstractMapperFactoryTest method testColumnDefinition.
@Test
public void testColumnDefinition() {
MapperFactory mapperFactory = new MapperFactory();
Object prop1 = new Object();
Object prop2 = new Object();
mapperFactory.addColumnDefinition("mykey", FieldMapperColumnDefinition.<SampleFieldKey>identity().add(prop1));
Assert.assertArrayEquals(new Object[] { prop1 }, mapperFactory.columnDefinitions().getColumnDefinition(new SampleFieldKey("mykey", 0)).properties());
mapperFactory.addColumnDefinition(new Predicate<SampleFieldKey>() {
@Override
public boolean test(SampleFieldKey sampleFieldKey) {
return sampleFieldKey.getIndex() < 1;
}
}, FieldMapperColumnDefinition.<SampleFieldKey>identity().add(prop2));
Assert.assertArrayEquals(new Object[] { prop2, prop1 }, mapperFactory.columnDefinitions().getColumnDefinition(new SampleFieldKey("mykey", 0)).properties());
Assert.assertArrayEquals(new Object[] { prop1 }, mapperFactory.columnDefinitions().getColumnDefinition(new SampleFieldKey("mykey", 1)).properties());
}
Aggregations