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