use of org.apache.tapestry5.commons.Location in project tapestry-5 by apache.
the class PropBindingFactory method newBinding.
public Binding newBinding(String description, ComponentResources container, ComponentResources component, String expression, Location location) {
Object target = container.getComponent();
Class targetClass = target.getClass();
PropertyConduit conduit = source.create(targetClass, expression);
String toString = interner.format("PropBinding[%s %s(%s)]", description, container.getCompleteId(), expression);
return new PropBinding(location, target, conduit, expression, toString);
}
use of org.apache.tapestry5.commons.Location 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);
}
}
use of org.apache.tapestry5.commons.Location 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.commons.Location in project tapestry-5 by apache.
the class TemplateParserImplTest method component_with_parameters.
@Test
public void component_with_parameters() {
List<TemplateToken> tokens = tokens("componentWithParameters.tml");
assertEquals(tokens.size(), 9);
TemplateToken templateToken = get(tokens, 2);
Location l = templateToken.getLocation();
AttributeToken t1 = get(tokens, 3);
// TODO: Not sure what order the attributes appear in. Order in the XML? Sorted
// alphabetically? Random 'cause they're hashed?
assertEquals(t1.name, "cherry");
assertEquals(t1.value, "bomb");
assertSame(t1.getLocation(), l);
AttributeToken t2 = get(tokens, 4);
assertEquals(t2.name, "align");
assertEquals(t2.value, "right");
assertSame(t2.getLocation(), l);
TextToken t3 = get(tokens, 5);
assertEquals(t3.text.trim(), "fred's body");
get(tokens, 6);
}
use of org.apache.tapestry5.commons.Location in project tapestry-5 by apache.
the class BlockImplTest method to_string.
@Test
public void to_string() {
Resource r = new ClasspathResource("foo/pages/MyPage.tml");
Location l = new LocationImpl(r, 23);
BlockImpl block = new BlockImpl(l, "test block");
assertEquals(block.toString(), "Block[test block, at classpath:foo/pages/MyPage.tml, line 23]");
}
Aggregations