Search in sources :

Example 31 with TapestryException

use of org.apache.tapestry5.commons.internal.util.TapestryException in project tapestry-5 by apache.

the class PropBindingFactoryTest method write_only_property.

@Test
public void write_only_property() {
    TargetBean bean = new TargetBean();
    ComponentResources resources = newComponentResources(bean);
    Location l = mockLocation();
    replay();
    Binding binding = factory.newBinding("test binding", resources, null, "writeOnly", l);
    binding.set("updated");
    assertEquals(bean.writeOnly, "updated");
    try {
        assertEquals(binding.get(), "ReadOnly");
        unreachable();
    } catch (TapestryException ex) {
        assertEquals(ex.getMessage(), "Expression 'writeOnly' for class org.apache.tapestry5.internal.bindings.TargetBean is write-only.");
        assertEquals(ex.getLocation(), l);
    }
    verify();
}
Also used : Binding(org.apache.tapestry5.Binding) 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 32 with TapestryException

use of org.apache.tapestry5.commons.internal.util.TapestryException in project tapestry-5 by apache.

the class BindingSourceImplTest method factory_throws_exception.

@Test
public void factory_throws_exception() {
    BindingFactory factory = mockBindingFactory();
    ComponentResources container = mockComponentResources();
    ComponentResources component = mockComponentResources();
    Location l = mockLocation();
    Throwable t = new RuntimeException("Simulated failure.");
    String defaultPrefix = "def";
    String description = "descrip";
    String expression = "full expression";
    factory.newBinding(description, container, component, expression, l);
    setThrowable(t);
    replay();
    Map<String, BindingFactory> map = newMap();
    map.put(defaultPrefix, factory);
    BindingSource source = new BindingSourceImpl(map, interner);
    try {
        source.newBinding(description, container, component, defaultPrefix, expression, l);
        unreachable();
    } catch (TapestryException ex) {
        assertTrue(ex.getMessage().contains("Could not convert 'full expression' into a component parameter binding"));
        assertTrue(ex.getMessage().contains(t.getMessage()));
        assertSame(ex.getLocation(), l);
        assertSame(ex.getCause(), t);
    }
    verify();
}
Also used : BindingSource(org.apache.tapestry5.services.BindingSource) TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException) BindingFactory(org.apache.tapestry5.services.BindingFactory) ComponentResources(org.apache.tapestry5.ComponentResources) Location(org.apache.tapestry5.commons.Location) Test(org.testng.annotations.Test)

Example 33 with TapestryException

use of org.apache.tapestry5.commons.internal.util.TapestryException in project tapestry-5 by apache.

the class ValidateBindingFactoryTest method not_a_field.

@Test
public void not_a_field() {
    FieldValidatorSource source = mockFieldValidatorSource();
    ComponentResources container = mockComponentResources();
    ComponentResources component = mockComponentResources();
    Component instance = mockComponent();
    Location l = mockLocation();
    train_getComponent(component, instance);
    train_getCompleteId(component, "foo.Bar:baz");
    replay();
    BindingFactory factory = new ValidateBindingFactory(source, interner);
    try {
        factory.newBinding("descrip", container, component, "zip,zoom", l);
    } catch (TapestryException ex) {
        assertEquals(ex.getMessage(), "Component 'foo.Bar:baz' is not a field (it does not implement the Field interface) and may not be used with the validate: binding prefix.");
        assertSame(ex.getLocation(), l);
    }
    verify();
}
Also used : FieldValidatorSource(org.apache.tapestry5.services.FieldValidatorSource) FieldComponent(org.apache.tapestry5.root.FieldComponent) Component(org.apache.tapestry5.runtime.Component) TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException) ComponentResources(org.apache.tapestry5.ComponentResources) Location(org.apache.tapestry5.commons.Location) BindingFactory(org.apache.tapestry5.services.BindingFactory) Test(org.testng.annotations.Test)

Example 34 with TapestryException

use of org.apache.tapestry5.commons.internal.util.TapestryException in project tapestry-5 by apache.

the class BeanEditorTest method object_can_not_be_instantiated.

@Test
public void object_can_not_be_instantiated() {
    ComponentResources resources = mockComponentResources();
    BeanModelSource source = mockBeanModelSource();
    BeanModel model = mockBeanModel();
    Location l = mockLocation();
    Throwable exception = new RuntimeException("Fall down go boom.");
    PropertyOverrides overrides = mockPropertyOverrides();
    Messages messages = mockMessages();
    Environment env = EasyMock.createNiceMock(Environment.class);
    train_getOverrideMessages(overrides, messages);
    train_getBoundType(resources, "object", Runnable.class);
    train_createEditModel(source, Runnable.class, messages, model);
    expect(model.newInstance()).andThrow(exception);
    train_getCompleteId(resources, "Foo.bar");
    train_getLocation(resources, l);
    expect(model.getBeanType()).andReturn(Runnable.class);
    replay();
    EasyMock.replay(env);
    BeanEditor component = new BeanEditor();
    component.inject(resources, overrides, source, env);
    try {
        component.doPrepare();
        unreachable();
    } catch (TapestryException ex) {
        assertMessageContains(ex, "Exception instantiating instance of java.lang.Runnable (for component \'Foo.bar\'):");
        assertSame(ex.getLocation(), l);
    }
    verify();
}
Also used : BeanModelSource(org.apache.tapestry5.beanmodel.services.BeanModelSource) Messages(org.apache.tapestry5.commons.Messages) BeanModel(org.apache.tapestry5.beanmodel.BeanModel) Environment(org.apache.tapestry5.services.Environment) 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 35 with TapestryException

use of org.apache.tapestry5.commons.internal.util.TapestryException in project tapestry-5 by apache.

the class BindParameterWorker method createConduit.

private FieldConduit<Object> createConduit(final ComponentResources resources, final String fieldTypeName, final String fieldName, final String[] possibleNames) {
    if (!resources.isMixin())
        throw new TapestryException(String.format("@BindParameter was used on field '%s' of component class '%s', but @BindParameter should only be used in mixins.", fieldName, resources.getComponentModel().getComponentClassName()), null);
    InternalComponentResources containerResources = (InternalComponentResources) resources.getContainerResources();
    // Evaluate this early so that we get a fast fail.
    String containerParameterName = identifyParameterName(resources, InternalUtils.stripMemberName(fieldName), possibleNames);
    Class fieldType = componentClassCache.forName(fieldTypeName);
    return new BoundParameterFieldValueConduit(containerParameterName, containerResources, fieldType);
}
Also used : InternalComponentResources(org.apache.tapestry5.internal.InternalComponentResources) TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException)

Aggregations

TapestryException (org.apache.tapestry5.commons.internal.util.TapestryException)37 Location (org.apache.tapestry5.commons.Location)12 Test (org.testng.annotations.Test)12 ComponentResources (org.apache.tapestry5.ComponentResources)11 Binding (org.apache.tapestry5.Binding)7 BindingFactory (org.apache.tapestry5.services.BindingFactory)4 IOException (java.io.IOException)3 InternalComponentResources (org.apache.tapestry5.internal.InternalComponentResources)3 Component (org.apache.tapestry5.runtime.Component)3 PropertyOverrides (org.apache.tapestry5.PropertyOverrides)2 TrackableComponentEventCallback (org.apache.tapestry5.TrackableComponentEventCallback)2 PropertyModel (org.apache.tapestry5.beanmodel.PropertyModel)2 Messages (org.apache.tapestry5.commons.Messages)2 Link (org.apache.tapestry5.http.Link)2 Instantiator (org.apache.tapestry5.internal.services.Instantiator)2 ComponentPageElement (org.apache.tapestry5.internal.structure.ComponentPageElement)2 Page (org.apache.tapestry5.internal.structure.Page)2 OperationException (org.apache.tapestry5.ioc.internal.OperationException)2 JSONObject (org.apache.tapestry5.json.JSONObject)2 BindingSource (org.apache.tapestry5.services.BindingSource)2