use of org.apache.tapestry5.services.BindingSource in project tapestry-5 by apache.
the class PageElementFactoryImplTest method unclosed_attribute_expression.
@Test
public void unclosed_attribute_expression() {
TypeCoercer typeCoercer = mockTypeCoercer();
BindingSource bindingSource = mockBindingSource();
ComponentResources resources = mockComponentResources();
Location location = mockLocation();
AttributeToken token = new AttributeToken(null, "fred", "${flintstone", location);
replay();
PageElementFactory factory = new PageElementFactoryImpl(typeCoercer, bindingSource);
try {
factory.newAttributeElement(resources, token);
unreachable();
} catch (TapestryException ex) {
assertEquals(ex.getMessage(), "Attribute expression \'${flintstone\' is missing a closing brace.");
assertSame(ex.getLocation(), location);
}
verify();
}
use of org.apache.tapestry5.services.BindingSource in project tapestry-5 by apache.
the class ComponentDefaultProviderImplTest method default_property_exists.
@Test
public void default_property_exists() {
String parameterName = "myparam";
String id = "mycomponentid";
ComponentResources resources = mockComponentResources();
Component container = mockComponent();
PropertyAccess access = mockPropertyAccess();
ClassPropertyAdapter classPropertyAdapter = mockClassPropertyAdapter();
PropertyAdapter propertyAdapter = mockPropertyAdapter();
BindingSource bindingSource = mockBindingSource();
Binding binding = mockBinding();
ComponentResources containerResources = mockComponentResources();
train_getId(resources, id);
train_getContainer(resources, container);
train_getAdapter(access, container, classPropertyAdapter);
train_getPropertyAdapter(classPropertyAdapter, id, propertyAdapter);
train_getContainerResources(resources, containerResources);
train_newBinding(bindingSource, "default myparam", containerResources, BindingConstants.PROP, id, binding);
replay();
ComponentDefaultProvider source = new ComponentDefaultProviderImpl(access, bindingSource, null, null, null);
assertSame(source.defaultBinding(parameterName, resources), binding);
verify();
}
use of org.apache.tapestry5.services.BindingSource in project tapestry-5 by apache.
the class PageElementFactoryImplTest method attribute.
@Test
public void attribute() {
TypeCoercer typeCoercer = mockTypeCoercer();
BindingSource bindingSource = mockBindingSource();
MarkupWriter writer = new MarkupWriterImpl(xmlModel);
Location l = mockLocation();
RenderQueue queue = mockRenderQueue();
replay();
PageElementFactory factory = new PageElementFactoryImpl(typeCoercer, bindingSource);
AttributeToken token = new AttributeToken(null, "name", "value", l);
RenderCommand element = factory.newAttributeElement(null, token);
writer.element("root");
element.render(writer, queue);
verify();
assertEquals(writer.toString(), "<?xml version=\"1.0\"?>\n<root name=\"value\"/>");
}
use of org.apache.tapestry5.services.BindingSource in project tapestry-5 by apache.
the class BindingSourceImplTest method known_prefix.
@Test
public void known_prefix() {
BindingFactory factory = mockBindingFactory();
Binding binding = mockBinding();
ComponentResources container = mockComponentResources();
ComponentResources component = mockComponentResources();
Location l = mockLocation();
String defaultPrefix = "literal";
String description = "descrip";
// The "prop:" prefix is stripped off ...
train_newBinding(factory, description, container, component, "myproperty", l, binding);
replay();
Map<String, BindingFactory> map = newMap();
map.put("prop", factory);
BindingSource source = new BindingSourceImpl(map, interner);
Binding actual = source.newBinding(description, container, component, defaultPrefix, "prop:myproperty", l);
assertSame(actual, binding);
verify();
}
use of org.apache.tapestry5.services.BindingSource 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();
}
Aggregations