Package org.apache.tapestry5.ioc.services

Examples of org.apache.tapestry5.ioc.services.PropertyAdapter


    }

    @Test
    public void get_annotation_will_read_field()
    {
        PropertyAdapter pa = access.getAdapter(Bean.class).getPropertyAdapter("value");

        DataType dt = pa.getAnnotation(DataType.class);

        assertNotNull(dt);
        assertEquals(dt.value(), "fred");
    }
View Full Code Here


     * TAPESTRY-2448
     */
    @Test
    public void get_annotation_will_read_inherited_field()
    {
        PropertyAdapter pa = access.getAdapter(BeanSubclass.class).getPropertyAdapter("value");

        DataType dt = pa.getAnnotation(DataType.class);

        assertNotNull(dt);
        assertEquals(dt.value(), "fred");

    }
View Full Code Here

    }

    @Test
    public void field_annotation_overridden_by_getter_annotation()
    {
        PropertyAdapter pa = access.getAdapter(Bean.class).getPropertyAdapter("value");

        assertEquals(pa.getAnnotation(Validate.class).value(), "getter-value-overrides");
    }
View Full Code Here

    @Test
    public void using_generics()
    {
        ClassPropertyAdapter cpa1 = access.getAdapter(StringLongPair.class);

        PropertyAdapter pa1 = cpa1.getPropertyAdapter("key");
        assertSame(pa1.getType(), String.class);
        assertTrue(pa1.isCastRequired());

        assertSame(pa1.getDeclaringClass(), Pair.class);

        PropertyAdapter pa2 = cpa1.getPropertyAdapter("value");
        assertSame(pa2.getType(), Long.class);
        assertTrue(pa2.isCastRequired());

        // On the base class, which defines the generic parameter type variables,
        // the properties just look like Object.

        ClassPropertyAdapter cpa2 = access.getAdapter(Pair.class);

        pa1 = cpa2.getPropertyAdapter("key");
        assertSame(pa1.getType(), Object.class);
        assertFalse(pa1.isCastRequired());

        pa2 = cpa2.getPropertyAdapter("value");
        assertSame(pa2.getType(), Object.class);
        assertFalse(pa2.isCastRequired());

    }
View Full Code Here

    }

    @Test
    public void get_scala_properties_with_bean_accessors()
    {
        PropertyAdapter pa = access.getAdapter(ScalaBean.class).getPropertyAdapter("value");

        // even thought scala accessors are present the java bean ones should be the ones used by Tapestry
        assertEquals(pa.getReadMethod().getName(), "getValue");
        assertEquals(pa.getWriteMethod().getName(), "setValue");
    }
View Full Code Here

    }

    @Test
    public void get_scala_properties()
    {
        PropertyAdapter pa = access.getAdapter(ScalaClass.class).getPropertyAdapter("value");

        assertEquals(pa.getReadMethod().getName(), "value");
        assertEquals(pa.getWriteMethod().getName(), "value_$eq");
    }
View Full Code Here

    }

    @Test
    public void access_to_public_field()
    {
        PropertyAdapter pa = access.getAdapter(PublicFieldBean.class).getPropertyAdapter("value");

        assertTrue(pa.isField());
        assertTrue(pa.isRead());
        assertTrue(pa.isUpdate());

        PublicFieldBean bean = new PublicFieldBean();

        pa.set(bean, "fred");

        assertEquals(bean.value, "fred");

        bean.value = "barney";

        assertEquals(pa.get(bean), "barney");
    }
View Full Code Here

    }

    @Test
    public void property_is_favored_over_public_field()
    {
        PropertyAdapter pa = access.getAdapter(ShadowedPublicFieldBean.class).getPropertyAdapter("value");

        assertFalse(pa.isField());

        ShadowedPublicFieldBean bean = new ShadowedPublicFieldBean();

        pa.set(bean, "fred");

        assertNull(bean.value);

        bean.value = "barney";
        bean.setValue("wilma");

        assertEquals(pa.get(bean), "wilma");
    }
View Full Code Here

    @Test
    public void access_property_from_unimplemented_interface_in_abstract_base_class()
    {
        AbstractBean bean = new ConcreteBean(33);

        PropertyAdapter valueAdapter = access.getAdapter(AbstractBean.class).getPropertyAdapter("value");

        assertNotNull(valueAdapter);
        assertFalse(valueAdapter.isField());

        valueAdapter.set(bean, "Hello");

        assertSame(valueAdapter.get(bean), "Hello");
        assertSame(bean.getValue(), "Hello");

        PropertyAdapter otherValueAdapter = access.getAdapter(AbstractBean.class).getPropertyAdapter("otherValue");

        assertNotNull(otherValueAdapter);
        assertFalse(otherValueAdapter.isField());

        otherValueAdapter.set(bean, "Other Value");

        assertSame(otherValueAdapter.get(bean), "Other Value");
        assertSame(bean.getOtherValue(), "Other Value");

        PropertyAdapter intValueAdapter = access.getAdapter(AbstractBean.class).getPropertyAdapter("intvalue");
        assertNotNull(intValueAdapter);

        assertEquals(intValueAdapter.get(bean), 33);

        assertTrue(intValueAdapter.isRead());
        assertFalse(intValueAdapter.isUpdate());
    }
View Full Code Here


    @Test
    public void generic_field_is_recognized()
    {
        PropertyAdapter pa = access.getAdapter(GenericStringBean.class).getPropertyAdapter("value");

        assertTrue(pa.isCastRequired());
        assertEquals(pa.getType(), String.class);
        assertSame(pa.getDeclaringClass(), GenericBean.class);
    }
View Full Code Here

TOP

Related Classes of org.apache.tapestry5.ioc.services.PropertyAdapter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.