Search in sources :

Example 16 with DefaultPropertyNameMatcher

use of org.simpleflatmapper.reflect.meta.DefaultPropertyNameMatcher in project SimpleFlatMapper by arnaudroger.

the class SubPropertyMetaTest method testSubProperty.

@Test
@SuppressWarnings("unchecked")
public void testSubProperty() throws Exception {
    ClassMeta<Db1DeepObject> classMeta = ReflectionService.newInstance().getClassMeta(Db1DeepObject.class);
    PropertyMeta<Db1DeepObject, String> property = classMeta.newPropertyFinder(new Predicate<PropertyMeta<?, ?>>() {

        @Override
        public boolean test(PropertyMeta<?, ?> propertyMeta) {
            return true;
        }
    }).findProperty(new DefaultPropertyNameMatcher("dbObject_name", 0, false, false), new Object[0]);
    assertTrue(property instanceof SubPropertyMeta);
    assertTrue(property.isSubProperty());
    assertTrue(property.toString().startsWith("SubPropertyMeta{" + "ownerProperty=ObjectPropertyMeta{"));
    SubPropertyMeta<Db1DeepObject, DbObject, String> subPropertyMeta = (SubPropertyMeta<Db1DeepObject, DbObject, String>) property;
    assertEquals(String.class, subPropertyMeta.getPropertyType());
    assertEquals("dbObject.name", subPropertyMeta.getPath());
    Db1DeepObject object = new Db1DeepObject();
    object.setDbObject(new DbObject());
    subPropertyMeta.getSetter().set(object, "n1");
    Getter<Db1DeepObject, String> getter = subPropertyMeta.getGetter();
    assertEquals("n1", getter.get(object));
    Db1DeepObject objectNull = new Db1DeepObject();
    assertEquals(null, getter.get(objectNull));
    assertTrue(getter.toString().startsWith("GetterOnGetter{g1="));
    ClassMeta<?> meta = subPropertyMeta.getPropertyClassMeta();
    assertEquals(String.class, meta.getType());
}
Also used : Db1DeepObject(org.simpleflatmapper.test.beans.Db1DeepObject) SubPropertyMeta(org.simpleflatmapper.reflect.meta.SubPropertyMeta) DbObject(org.simpleflatmapper.test.beans.DbObject) DefaultPropertyNameMatcher(org.simpleflatmapper.reflect.meta.DefaultPropertyNameMatcher) SubPropertyMeta(org.simpleflatmapper.reflect.meta.SubPropertyMeta) PropertyMeta(org.simpleflatmapper.reflect.meta.PropertyMeta) Predicate(org.simpleflatmapper.util.Predicate) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)16 DefaultPropertyNameMatcher (org.simpleflatmapper.reflect.meta.DefaultPropertyNameMatcher)16 PropertyMeta (org.simpleflatmapper.reflect.meta.PropertyMeta)4 PropertyNameMatcher (org.simpleflatmapper.reflect.meta.PropertyNameMatcher)4 Predicate (org.simpleflatmapper.util.Predicate)3 TypeReference (org.simpleflatmapper.util.TypeReference)3 FastTuple (com.boundary.tuple.FastTuple)2 List (java.util.List)2 DbObject (org.simpleflatmapper.test.beans.DbObject)2 Tuple3 (org.simpleflatmapper.tuple.Tuple3)2 TupleSchema (com.boundary.tuple.TupleSchema)1 ResultSet (java.sql.ResultSet)1 Tuple3 (org.jooq.lambda.tuple.Tuple3)1 JdbcColumnKey (org.simpleflatmapper.jdbc.JdbcColumnKey)1 LongFieldMapper (org.simpleflatmapper.map.fieldmapper.LongFieldMapper)1 PropertyMapping (org.simpleflatmapper.map.mapper.PropertyMapping)1 FieldMapperColumnDefinition (org.simpleflatmapper.map.property.FieldMapperColumnDefinition)1 IdentityGetter (org.simpleflatmapper.reflect.getter.IdentityGetter)1 ConstructorPropertyMeta (org.simpleflatmapper.reflect.meta.ConstructorPropertyMeta)1 SelfPropertyMeta (org.simpleflatmapper.reflect.meta.SelfPropertyMeta)1