Search in sources :

Example 6 with BindingFactory

use of org.apache.tapestry5.services.BindingFactory in project tapestry-5 by apache.

the class BindingFactoryTest method literal_binding.

@Test
public void literal_binding() {
    ComponentResources res = mockInternalComponentResources();
    Location l = mockLocation();
    replay();
    BindingFactory factory = new LiteralBindingFactory();
    Binding b = factory.newBinding("test binding", res, null, "Tapestry5", l);
    assertSame(InternalUtils.locationOf(b), l);
    assertEquals(b.get(), "Tapestry5");
    assertTrue(b.isInvariant());
    assertSame(b.getBindingType(), String.class);
    try {
        b.set(null);
        unreachable();
    } catch (TapestryException ex) {
        assertSame(ex.getLocation(), l);
    }
    verify();
}
Also used : Binding(org.apache.tapestry5.Binding) TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException) ComponentResources(org.apache.tapestry5.ComponentResources) Location(org.apache.tapestry5.commons.Location) BindingFactory(org.apache.tapestry5.services.BindingFactory) Test(org.testng.annotations.Test)

Example 7 with BindingFactory

use of org.apache.tapestry5.services.BindingFactory 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 8 with BindingFactory

use of org.apache.tapestry5.services.BindingFactory 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)

Example 9 with BindingFactory

use of org.apache.tapestry5.services.BindingFactory 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();
}
Also used : FieldValidatorSource(org.apache.tapestry5.services.FieldValidatorSource) FieldComponent(org.apache.tapestry5.root.FieldComponent) Component(org.apache.tapestry5.runtime.Component) TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException) ComponentResources(org.apache.tapestry5.ComponentResources) Location(org.apache.tapestry5.commons.Location) BindingFactory(org.apache.tapestry5.services.BindingFactory) Test(org.testng.annotations.Test)

Example 10 with BindingFactory

use of org.apache.tapestry5.services.BindingFactory in project tapestry-5 by apache.

the class ValidateBindingFactoryTest method success.

@Test
public void success() {
    FieldValidatorSource source = mockFieldValidatorSource();
    ComponentResources container = mockComponentResources();
    ComponentResources component = mockComponentResources();
    FieldComponent instance = mockFieldComponent();
    Location l = mockLocation();
    FieldValidator validator = mockFieldValidator();
    String expression = "required,minLength=5";
    train_getComponent(component, instance);
    expect(source.createValidators(instance, expression)).andReturn(validator);
    replay();
    BindingFactory factory = new ValidateBindingFactory(source, interner);
    Binding binding = factory.newBinding("descrip", container, component, expression, l);
    assertSame(binding.get(), validator);
    verify();
}
Also used : Binding(org.apache.tapestry5.Binding) FieldValidatorSource(org.apache.tapestry5.services.FieldValidatorSource) FieldComponent(org.apache.tapestry5.root.FieldComponent) FieldValidator(org.apache.tapestry5.FieldValidator) ComponentResources(org.apache.tapestry5.ComponentResources) Location(org.apache.tapestry5.commons.Location) BindingFactory(org.apache.tapestry5.services.BindingFactory) Test(org.testng.annotations.Test)

Aggregations

BindingFactory (org.apache.tapestry5.services.BindingFactory)10 ComponentResources (org.apache.tapestry5.ComponentResources)9 Location (org.apache.tapestry5.commons.Location)9 Test (org.testng.annotations.Test)9 Binding (org.apache.tapestry5.Binding)7 TapestryException (org.apache.tapestry5.commons.internal.util.TapestryException)4 BindingSource (org.apache.tapestry5.services.BindingSource)4 FieldComponent (org.apache.tapestry5.root.FieldComponent)2 FieldValidatorSource (org.apache.tapestry5.services.FieldValidatorSource)2 FieldTranslator (org.apache.tapestry5.FieldTranslator)1 FieldValidator (org.apache.tapestry5.FieldValidator)1 StringInternerImpl (org.apache.tapestry5.commons.internal.services.StringInternerImpl)1 BlockBindingFactory (org.apache.tapestry5.internal.bindings.BlockBindingFactory)1 ComponentBindingFactory (org.apache.tapestry5.internal.bindings.ComponentBindingFactory)1 LiteralBindingFactory (org.apache.tapestry5.internal.bindings.LiteralBindingFactory)1 RenderVariableBindingFactory (org.apache.tapestry5.internal.bindings.RenderVariableBindingFactory)1 Component (org.apache.tapestry5.runtime.Component)1 FieldTranslatorSource (org.apache.tapestry5.services.FieldTranslatorSource)1