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();
}
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();
}
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();
}
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();
}
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();
}
Aggregations