Search in sources :

Example 6 with BindingSource

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

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();
}
Also used : Binding(org.apache.tapestry5.Binding) BindingSource(org.apache.tapestry5.services.BindingSource) ClassPropertyAdapter(org.apache.tapestry5.commons.services.ClassPropertyAdapter) ClassPropertyAdapter(org.apache.tapestry5.commons.services.ClassPropertyAdapter) PropertyAdapter(org.apache.tapestry5.commons.services.PropertyAdapter) Component(org.apache.tapestry5.runtime.Component) ComponentResources(org.apache.tapestry5.ComponentResources) PropertyAccess(org.apache.tapestry5.commons.services.PropertyAccess) ComponentDefaultProvider(org.apache.tapestry5.services.ComponentDefaultProvider) Test(org.testng.annotations.Test)

Example 8 with BindingSource

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\"/>");
}
Also used : RenderCommand(org.apache.tapestry5.runtime.RenderCommand) BindingSource(org.apache.tapestry5.services.BindingSource) TypeCoercer(org.apache.tapestry5.commons.services.TypeCoercer) RenderQueue(org.apache.tapestry5.runtime.RenderQueue) AttributeToken(org.apache.tapestry5.internal.parser.AttributeToken) MarkupWriter(org.apache.tapestry5.MarkupWriter) Location(org.apache.tapestry5.commons.Location) Test(org.testng.annotations.Test)

Example 9 with BindingSource

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

Example 10 with BindingSource

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

Aggregations

BindingSource (org.apache.tapestry5.services.BindingSource)8 Test (org.testng.annotations.Test)8 ComponentResources (org.apache.tapestry5.ComponentResources)7 Location (org.apache.tapestry5.commons.Location)6 Binding (org.apache.tapestry5.Binding)5 BindingFactory (org.apache.tapestry5.services.BindingFactory)4 TapestryException (org.apache.tapestry5.commons.internal.util.TapestryException)3 ClassPropertyAdapter (org.apache.tapestry5.commons.services.ClassPropertyAdapter)2 PropertyAccess (org.apache.tapestry5.commons.services.PropertyAccess)2 TypeCoercer (org.apache.tapestry5.commons.services.TypeCoercer)2 Mapper (org.apache.tapestry5.func.Mapper)2 AttributeToken (org.apache.tapestry5.internal.parser.AttributeToken)2 Component (org.apache.tapestry5.runtime.Component)2 ComponentDefaultProvider (org.apache.tapestry5.services.ComponentDefaultProvider)2 Matcher (java.util.regex.Matcher)1 MarkupWriter (org.apache.tapestry5.MarkupWriter)1 PropertyAdapter (org.apache.tapestry5.commons.services.PropertyAdapter)1 RenderCommand (org.apache.tapestry5.runtime.RenderCommand)1 RenderQueue (org.apache.tapestry5.runtime.RenderQueue)1 DynamicDelegate (org.apache.tapestry5.services.dynamic.DynamicDelegate)1