use of org.simpleflatmapper.reflect.meta.DefaultPropertyNameMatcher in project SimpleFlatMapper by arnaudroger.
the class ConstantSourceMapperBuilderTest method testIssue495Simple.
@Test
public void testIssue495Simple() throws Exception {
TypeReference<List<Tuple3<Foo, Foo, Foo>>> typeReference = new TypeReference<List<Tuple3<Foo, Foo, Foo>>>() {
};
ClassMeta<List<Tuple3<Foo, Foo, Foo>>> classMeta = this.classMeta.getReflectionService().getClassMeta(typeReference.getType());
Predicate<PropertyMeta<?, ?>> propertyFilter = new Predicate<PropertyMeta<?, ?>>() {
@Override
public boolean test(PropertyMeta<?, ?> propertyMeta) {
return true;
}
};
PropertyFinder<?> propertyFinder = classMeta.newPropertyFinder(propertyFilter);
PropertyMeta<?, ?> p1 = propertyFinder.findProperty(new DefaultPropertyNameMatcher("bar", 0, false, false), new Object[0]);
PropertyMeta<?, ?> p2 = propertyFinder.findProperty(new DefaultPropertyNameMatcher("bar", 0, false, false), new Object[0]);
assertEquals("[0].element0.bar", p1.getPath());
assertEquals("[0].element1.bar", p2.getPath());
propertyFinder = classMeta.newPropertyFinder(propertyFilter);
p1 = propertyFinder.findProperty(new DefaultPropertyNameMatcher("elt0_elt0_bar", 0, false, false), new Object[0]);
p2 = propertyFinder.findProperty(new DefaultPropertyNameMatcher("elt1_elt0_bar", 0, false, false), new Object[0]);
assertEquals("[0].element0.bar", p1.getPath());
assertEquals("[1].element0.bar", p2.getPath());
}
use of org.simpleflatmapper.reflect.meta.DefaultPropertyNameMatcher in project SimpleFlatMapper by arnaudroger.
the class ResultSetFieldMapperFactoryTest method testPrimitiveField.
@Test
public void testPrimitiveField() {
ClassMeta<DbObject> classMeta = ReflectionService.newInstance(false).getClassMeta(DbObject.class);
PropertyMeta<DbObject, Long> id = classMeta.newPropertyFinder(ConstantPredicate.<PropertyMeta<?, ?>>truePredicate()).<Long>findProperty(new DefaultPropertyNameMatcher("id", 0, false, false), new Object[0]);
FieldMapperColumnDefinition<JdbcColumnKey> identity = FieldMapperColumnDefinition.identity();
PropertyMapping<DbObject, Long, JdbcColumnKey, FieldMapperColumnDefinition<JdbcColumnKey>> propertyMapping = new PropertyMapping<DbObject, Long, JdbcColumnKey, FieldMapperColumnDefinition<JdbcColumnKey>>(id, new JdbcColumnKey("id", 1), identity);
FieldMapper<ResultSet, DbObject> fieldMapper = factory.newFieldMapper(propertyMapping, null, RethrowMapperBuilderErrorHandler.INSTANCE);
assertTrue(fieldMapper instanceof LongFieldMapper);
PropertyMapping<DbObject, Long, JdbcColumnKey, FieldMapperColumnDefinition<JdbcColumnKey>> propertyMapping1 = new PropertyMapping<DbObject, Long, JdbcColumnKey, FieldMapperColumnDefinition<JdbcColumnKey>>(id, new JdbcColumnKey("id", 0), identity);
fieldMapper = factory.newFieldMapper(propertyMapping1, null, RethrowMapperBuilderErrorHandler.INSTANCE);
assertTrue(fieldMapper instanceof LongFieldMapper);
}
use of org.simpleflatmapper.reflect.meta.DefaultPropertyNameMatcher in project SimpleFlatMapper by arnaudroger.
the class ConstructorPropertyMetaTest method testToString.
@Test
public void testToString() {
PropertyMeta<CObject, Object> property = classMeta.newPropertyFinder(isValidPropertyMeta).findProperty(new DefaultPropertyNameMatcher("p1", 0, false, false), new Object[0]);
assertTrue(property.toString().startsWith("ConstructorPropertyMeta"));
}
use of org.simpleflatmapper.reflect.meta.DefaultPropertyNameMatcher in project SimpleFlatMapper by arnaudroger.
the class ConstructorPropertyMetaTest method testGetValueIfGetterAvailable.
@Test
public void testGetValueIfGetterAvailable() throws Exception {
PropertyMeta<CObject, Object> property = classMeta.newPropertyFinder(isValidPropertyMeta).findProperty(new DefaultPropertyNameMatcher("p1", 0, false, false), new Object[0]);
assertEquals("v1", property.getGetter().get(cObject));
}
use of org.simpleflatmapper.reflect.meta.DefaultPropertyNameMatcher in project SimpleFlatMapper by arnaudroger.
the class DefaultPropertyNameMatcherTest method testStartOf.
@Test
public void testStartOf() {
PropertyNameMatcher matcher = new DefaultPropertyNameMatcher("my_Col_top_bottom", 0, false, false);
assertTrue(matcher.partialMatch("myCol").getLeftOverMatcher().partialMatch("top").getLeftOverMatcher().matches("bottom"));
assertTrue(matcher.partialMatch("my_Col").getLeftOverMatcher().partialMatch("tOp").getLeftOverMatcher().matches("bottom"));
assertTrue(matcher.partialMatch("my Col").getLeftOverMatcher().partialMatch("tOp").getLeftOverMatcher().matches("bottom"));
assertNull(matcher.partialMatch("my__Col"));
assertNull(matcher.partialMatch("myCol2"));
}
Aggregations