Search in sources :

Example 26 with Location

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);
}
Also used : PropertyConduit(org.apache.tapestry5.beanmodel.PropertyConduit)

Example 27 with Location

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);
    }
}
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 28 with Location

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();
}
Also used : BindingSource(org.apache.tapestry5.services.BindingSource) TypeCoercer(org.apache.tapestry5.commons.services.TypeCoercer) AttributeToken(org.apache.tapestry5.internal.parser.AttributeToken) 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 29 with Location

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);
}
Also used : Location(org.apache.tapestry5.commons.Location) Test(org.testng.annotations.Test)

Example 30 with Location

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]");
}
Also used : ClasspathResource(org.apache.tapestry5.ioc.internal.util.ClasspathResource) Resource(org.apache.tapestry5.commons.Resource) ClasspathResource(org.apache.tapestry5.ioc.internal.util.ClasspathResource) LocationImpl(org.apache.tapestry5.ioc.internal.util.LocationImpl) Location(org.apache.tapestry5.commons.Location) Test(org.testng.annotations.Test)

Aggregations

Location (org.apache.tapestry5.commons.Location)51 Test (org.testng.annotations.Test)41 ComponentResources (org.apache.tapestry5.ComponentResources)33 Binding (org.apache.tapestry5.Binding)25 TapestryException (org.apache.tapestry5.commons.internal.util.TapestryException)21 BindingFactory (org.apache.tapestry5.services.BindingFactory)10 BindingSource (org.apache.tapestry5.services.BindingSource)6 Resource (org.apache.tapestry5.commons.Resource)4 UnknownValueException (org.apache.tapestry5.commons.util.UnknownValueException)4 Component (org.apache.tapestry5.runtime.Component)4 MutableEmbeddedComponentModel (org.apache.tapestry5.model.MutableEmbeddedComponentModel)3 Environment (org.apache.tapestry5.services.Environment)3 Logger (org.slf4j.Logger)3 Matcher (java.util.regex.Matcher)2 QName (javax.xml.namespace.QName)2 MarkupWriter (org.apache.tapestry5.MarkupWriter)2 PropertyOverrides (org.apache.tapestry5.PropertyOverrides)2 PropertyConduit (org.apache.tapestry5.beanmodel.PropertyConduit)2 PropertyModel (org.apache.tapestry5.beanmodel.PropertyModel)2 Messages (org.apache.tapestry5.commons.Messages)2