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