Search in sources :

Example 16 with PropertyModel

use of org.apache.tapestry5.beanmodel.PropertyModel in project tapestry-5 by apache.

the class AbstractBeanModelSourceImplTest method array_type_bean.

@Test
public void array_type_bean() {
    Messages messages = mockMessages();
    stub_contains(messages, false);
    replay();
    BeanModel model = source.create(StringArrayBean.class, true, messages);
    // There's not editor for string arrays yet, so it won't show up normally.
    PropertyModel propertyModel = model.add("array");
    assertSame(propertyModel.getPropertyType(), String[].class);
    String[] value = { "foo", "bar" };
    StringArrayBean bean = new StringArrayBean();
    PropertyConduit conduit = propertyModel.getConduit();
    conduit.set(bean, value);
    assertSame(bean.getArray(), value);
    assertSame(conduit.get(bean), value);
    verify();
}
Also used : Messages(org.apache.tapestry5.commons.Messages) BeanModel(org.apache.tapestry5.beanmodel.BeanModel) PropertyModel(org.apache.tapestry5.beanmodel.PropertyModel) PropertyConduit(org.apache.tapestry5.beanmodel.PropertyConduit) Test(org.testng.annotations.Test)

Example 17 with PropertyModel

use of org.apache.tapestry5.beanmodel.PropertyModel in project tapestry-5 by apache.

the class BeanModelUtilsTest method include_before_add.

/**
 * TAP5-478
 */
@Test
public void include_before_add() {
    BeanModel model = mockBeanModel();
    PropertyModel fred = mockPropertyModel();
    EasyMock.checkOrder(model, true);
    expect(model.addEmpty("fred")).andReturn(fred);
    expect(model.include("sam", "fred")).andReturn(model);
    replay();
    BeanModelUtils.modify(model, "fred", "sam", null, null);
    verify();
}
Also used : BeanModel(org.apache.tapestry5.beanmodel.BeanModel) PropertyModel(org.apache.tapestry5.beanmodel.PropertyModel) Test(org.testng.annotations.Test)

Example 18 with PropertyModel

use of org.apache.tapestry5.beanmodel.PropertyModel in project tapestry-5 by apache.

the class BeanModelUtilsTest method modify_full.

@Test
public void modify_full() {
    BeanModel model = mockBeanModel();
    PropertyModel fred = mockPropertyModel();
    PropertyModel barney = mockPropertyModel();
    expect(model.addEmpty("fred")).andReturn(fred);
    expect(model.addEmpty("barney")).andReturn(barney);
    expect(model.exclude("pebbles", "bambam")).andReturn(model);
    expect(model.reorder("wilma", "betty")).andReturn(model);
    replay();
    BeanModelUtils.modify(model, "fred,barney", null, "pebbles,bambam", "wilma,betty");
    verify();
}
Also used : BeanModel(org.apache.tapestry5.beanmodel.BeanModel) PropertyModel(org.apache.tapestry5.beanmodel.PropertyModel) Test(org.testng.annotations.Test)

Example 19 with PropertyModel

use of org.apache.tapestry5.beanmodel.PropertyModel in project tapestry-5 by apache.

the class PropertyEditor method setupEnvironment.

/**
 * Creates a {@link org.apache.tapestry5.services.PropertyEditContext} and pushes it onto the {@link
 * org.apache.tapestry5.services.Environment} stack.
 */
void setupEnvironment(final String propertyName) {
    propertyModel = model.get(propertyName);
    PropertyEditContext context = new PropertyEditContext() {

        public Messages getContainerMessages() {
            return overrides.getOverrideMessages();
        }

        public String getLabel() {
            return propertyModel.getLabel();
        }

        public String getPropertyId() {
            return propertyModel.getId();
        }

        public Class getPropertyType() {
            return propertyModel.getPropertyType();
        }

        public Object getPropertyValue() {
            return propertyModel.getConduit().get(object);
        }

        public FieldTranslator getTranslator(Field field) {
            return fieldTranslatorSource.createDefaultTranslator(field, propertyName, overrides.getOverrideMessages(), locale, propertyModel.getPropertyType(), propertyModel.getConduit());
        }

        public FieldValidator getValidator(Field field) {
            return fieldValidatorDefaultSource.createDefaultValidator(field, propertyName, overrides.getOverrideMessages(), locale, propertyModel.getPropertyType(), propertyModel.getConduit());
        }

        public void setPropertyValue(Object value) {
            propertyModel.getConduit().set(object, value);
        }

        public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
            return propertyModel.getAnnotation(annotationClass);
        }
    };
    environment.push(PropertyEditContext.class, context);
    BeanValidationContext beanValidationContext = environment.peek(BeanValidationContext.class);
    if (beanValidationContext != null) {
        beanValidationContext.setCurrentProperty(propertyName);
    }
    heartbeat.begin();
}
Also used : PropertyEditContext(org.apache.tapestry5.services.PropertyEditContext) BeanValidationContext(org.apache.tapestry5.internal.BeanValidationContext) Annotation(java.lang.annotation.Annotation)

Example 20 with PropertyModel

use of org.apache.tapestry5.beanmodel.PropertyModel in project tapestry-5 by apache.

the class AbstractPropertyOutputTest method test_null_pointer_exception_message.

@Test
public // Tests TAPESTRY-2182.
void test_null_pointer_exception_message() {
    final PropertyConduit conduit = mockPropertyConduit();
    final PropertyModel model = mockPropertyModel();
    final Object object = new Object();
    ComponentResources resources = mockComponentResources();
    Location location = mockLocation();
    propertyOutputFixture.inject(model, object, resources);
    expect(model.getConduit()).andReturn(conduit);
    expect(conduit.get(object)).andThrow(new NullPointerException());
    expect(model.getPropertyName()).andReturn("wilma.occupation.address");
    expect(resources.getLocation()).andReturn(location);
    replay();
    try {
        propertyOutputFixture.readPropertyForObject();
        fail("Expected a NullPointerException to be thrown.");
    } catch (final TapestryException ex) {
        assertEquals(ex.getMessage(), "Property 'wilma.occupation.address' contains a null value in the path.");
        assertSame(ex.getLocation(), location);
        assertTrue(ex.getCause() instanceof NullPointerException);
    }
    verify();
}
Also used : PropertyModel(org.apache.tapestry5.beanmodel.PropertyModel) PropertyConduit(org.apache.tapestry5.beanmodel.PropertyConduit) TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException) ComponentResources(org.apache.tapestry5.ComponentResources) Location(org.apache.tapestry5.commons.Location) Test(org.testng.annotations.Test)

Aggregations

PropertyModel (org.apache.tapestry5.beanmodel.PropertyModel)29 Test (org.testng.annotations.Test)23 BeanModel (org.apache.tapestry5.beanmodel.BeanModel)21 Messages (org.apache.tapestry5.commons.Messages)19 PropertyConduit (org.apache.tapestry5.beanmodel.PropertyConduit)9 BeforeClass (org.testng.annotations.BeforeClass)4 ComponentResources (org.apache.tapestry5.ComponentResources)2 Location (org.apache.tapestry5.commons.Location)2 TapestryException (org.apache.tapestry5.commons.internal.util.TapestryException)2 Annotation (java.lang.annotation.Annotation)1 PropertyOverrides (org.apache.tapestry5.PropertyOverrides)1 SortConstraint (org.apache.tapestry5.grid.SortConstraint)1 BeanValidationContext (org.apache.tapestry5.internal.BeanValidationContext)1 BeanBlockSource (org.apache.tapestry5.services.BeanBlockSource)1 PropertyEditContext (org.apache.tapestry5.services.PropertyEditContext)1