use of org.simpleflatmapper.reflect.ReflectionService in project SimpleFlatMapper by arnaudroger.
the class AbstractMapperFactoryTest method testAsmSettings.
@Test
public void testAsmSettings() {
ReflectionService reflectionService = new MapperFactory().useAsm(false).getReflectionService();
assertFalse(reflectionService.isAsmActivated());
MapperConfig<SampleFieldKey, FieldMapperColumnDefinition<SampleFieldKey>> mapperConfig = new MapperFactory().asmMapperNbFieldsLimit(33).failOnAsm(true).maxMethodSize(13).mapperConfig();
assertEquals(33, mapperConfig.asmMapperNbFieldsLimit());
assertEquals(13, mapperConfig.maxMethodSize());
assertEquals(true, mapperConfig.failOnAsm());
reflectionService = new ReflectionService(null);
assertSame(reflectionService, new MapperFactory().reflectionService(reflectionService).getReflectionService());
}
use of org.simpleflatmapper.reflect.ReflectionService in project SimpleFlatMapper by arnaudroger.
the class ReflectionServiceTest method testSelfReferringClass.
@Test
public void testSelfReferringClass() {
final ReflectionService reflectionService = ReflectionService.newInstance();
ClassMeta<Node> cm = reflectionService.getClassMeta(Node.class);
final PropertyMeta<Node, Object> propertyMeta = cm.newPropertyFinder(isValidPropertyMeta).findProperty(DefaultPropertyNameMatcher.of("parent_parent_parent"), new Object[0]);
assertNotNull(propertyMeta);
assertNotNull(cm);
}
use of org.simpleflatmapper.reflect.ReflectionService in project SimpleFlatMapper by arnaudroger.
the class ObjectClassMetaTest method testAliasProvider.
@Test
public void testAliasProvider() {
ReflectionService reflectionService = ReflectionService.newInstance().withAliasProvider(new AliasProvider() {
@Override
public String getAliasForMethod(Method method) {
if ("getName".equals(method.getName())) {
return "myname";
}
return null;
}
@Override
public String getAliasForField(Field field) {
if ("id".equals(field.getName())) {
return "myid";
}
return null;
}
@Override
public Table getTable(Class<?> target) {
return null;
}
});
ClassMeta<DbObject> classMeta = reflectionService.getClassMeta(DbObject.class);
PropertyFinder<DbObject> propertyFinder1 = classMeta.newPropertyFinder(propertyFilter);
// force non direct mode
propertyFinder1.findProperty(DefaultPropertyNameMatcher.of("email"), new Object[0]);
assertNotNull(propertyFinder1.findProperty(DefaultPropertyNameMatcher.of("myid"), new Object[0]));
assertNotNull(propertyFinder1.findProperty(DefaultPropertyNameMatcher.of("myname"), new Object[0]));
classMeta = ReflectionService.newInstance().getClassMeta(DbObject.class);
PropertyFinder<DbObject> propertyFinder2 = classMeta.newPropertyFinder(propertyFilter);
// force non direct mode
propertyFinder2.findProperty(DefaultPropertyNameMatcher.of("email"), new Object[0]);
assertNull(propertyFinder2.findProperty(DefaultPropertyNameMatcher.of("myid"), new Object[0]));
assertNull(propertyFinder2.findProperty(DefaultPropertyNameMatcher.of("myname"), new Object[0]));
}
use of org.simpleflatmapper.reflect.ReflectionService in project SimpleFlatMapper by arnaudroger.
the class TupleClassMetaTest method testRespecify.
@Test
public void testRespecify() throws ClassNotFoundException, MalformedURLException {
ClassLoader cl = new URLClassLoader(new URL[] { LibrarySetsClassLoader.findUrl(Tuple2.class, getClass().getClassLoader()) }, null) {
@Override
public InputStream getResourceAsStream(String name) {
return null;
}
};
ReflectionService reflectionService = new ReflectionService(null) {
};
Class<?> tuple2Class = cl.loadClass(Tuple2.class.getName());
TupleClassMeta classMeta = new TupleClassMeta(tuple2Class, reflectionService);
List<InstantiatorDefinition> instantiatorDefinitions = classMeta.getInstantiatorDefinitions();
assertEquals(1, instantiatorDefinitions.size());
assertEquals("element0", instantiatorDefinitions.get(0).getParameters()[0].getName());
}
use of org.simpleflatmapper.reflect.ReflectionService in project SimpleFlatMapper by arnaudroger.
the class DataTypeTest method getSetter.
public static <N> Setter<SettableByIndexData, N> getSetter(Class<N> target, DataType dataType) throws InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException {
MapperConfig<DatastaxColumnKey, FieldMapperColumnDefinition<DatastaxColumnKey>> mapperConfig = MapperConfig.<DatastaxColumnKey>fieldMapperConfig();
ReflectionService reflectionService = ReflectionService.newInstance();
SettableDataSetterFactory factory = new SettableDataSetterFactory(mapperConfig, reflectionService);
DatastaxColumnKey columnKey = new DatastaxColumnKey("col", 1, dataType);
return factory.getSetter(newPM(target, dataType, columnKey));
}
Aggregations