Search in sources :

Example 6 with BeanBlockSource

use of org.apache.tapestry5.services.BeanBlockSource in project tapestry-5 by apache.

the class PropertyEditorTest method no_editor_block_available.

@Test
public void no_editor_block_available() {
    PropertyModel model = mockPropertyModel();
    PropertyOverrides overrides = mockPropertyOverrides();
    ComponentResources resources = mockComponentResources();
    BeanBlockSource source = newMock(BeanBlockSource.class);
    RuntimeException exception = new RuntimeException("Simulated failure.");
    Messages messages = mockMessages();
    Location l = mockLocation();
    String propertyId = "foo";
    String dataType = "unk";
    String propertyName = "fooProp";
    Object object = "[OBJECT]";
    String formattedMessage = "formatted-message";
    expect(model.getId()).andReturn(propertyId);
    train_getOverrideBlock(overrides, propertyId, null);
    expect(model.getDataType()).andReturn(dataType);
    expect(source.getEditBlock(dataType)).andThrow(exception);
    expect(model.getPropertyName()).andReturn(propertyName);
    train_getLocation(resources, l);
    expect(messages.format("core-block-error", propertyName, dataType, object, exception)).andReturn(formattedMessage);
    replay();
    PropertyEditor pe = new PropertyEditor();
    pe.inject(resources, overrides, model, source, messages, object);
    try {
        pe.beginRender();
        unreachable();
    } catch (TapestryException ex) {
        assertEquals(ex.getMessage(), formattedMessage);
        assertSame(ex.getLocation(), l);
    }
}
Also used : Messages(org.apache.tapestry5.commons.Messages) BeanBlockSource(org.apache.tapestry5.services.BeanBlockSource) PropertyModel(org.apache.tapestry5.beanmodel.PropertyModel) PropertyOverrides(org.apache.tapestry5.PropertyOverrides) TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException) ComponentResources(org.apache.tapestry5.ComponentResources) Location(org.apache.tapestry5.commons.Location) Test(org.testng.annotations.Test)

Example 7 with BeanBlockSource

use of org.apache.tapestry5.services.BeanBlockSource in project tapestry-5 by apache.

the class BeanBlockSourceImplTest method edit_block_not_found.

@Test
public void edit_block_not_found() {
    RequestPageCache cache = mockRequestPageCache();
    Collection<BeanBlockContribution> configuration = newList();
    replay();
    BeanBlockSource source = new BeanBlockSourceImpl(cache, createBeanBlockOverrideSource(cache), configuration);
    try {
        source.getEditBlock("MyData");
        unreachable();
    } catch (RuntimeException ex) {
        assertEquals(ex.getMessage(), "There is no defined way to edit data of type \'MyData\'.  Make a contribution to the BeanBlockSource service for this type.");
    }
    verify();
}
Also used : BeanBlockSource(org.apache.tapestry5.services.BeanBlockSource) BeanBlockContribution(org.apache.tapestry5.services.BeanBlockContribution) Test(org.testng.annotations.Test)

Aggregations

BeanBlockSource (org.apache.tapestry5.services.BeanBlockSource)7 Test (org.testng.annotations.Test)7 Block (org.apache.tapestry5.Block)4 BeanBlockContribution (org.apache.tapestry5.services.BeanBlockContribution)4 Page (org.apache.tapestry5.internal.structure.Page)2 BeanBlockOverrideSource (org.apache.tapestry5.services.BeanBlockOverrideSource)2 ComponentResources (org.apache.tapestry5.ComponentResources)1 PropertyOverrides (org.apache.tapestry5.PropertyOverrides)1 PropertyModel (org.apache.tapestry5.beanmodel.PropertyModel)1 Location (org.apache.tapestry5.commons.Location)1 Messages (org.apache.tapestry5.commons.Messages)1 TapestryException (org.apache.tapestry5.commons.internal.util.TapestryException)1 DisplayBlockContribution (org.apache.tapestry5.services.DisplayBlockContribution)1 EditBlockContribution (org.apache.tapestry5.services.EditBlockContribution)1