use of org.apache.tapestry5.services.BindingFactory in project tapestry-5 by apache.
the class BindingSourceImplTest method expression_has_no_prefix.
@Test
public void expression_has_no_prefix() {
BindingFactory factory = mockBindingFactory();
Binding binding = mockBinding();
ComponentResources container = mockComponentResources();
ComponentResources component = mockComponentResources();
Location l = mockLocation();
String defaultPrefix = "def";
String description = "descrip";
String expression = "full expression";
train_newBinding(factory, description, container, component, expression, l, binding);
replay();
Map<String, BindingFactory> map = newMap();
map.put(defaultPrefix, factory);
BindingSource source = new BindingSourceImpl(map, interner);
Binding actual = source.newBinding(description, container, component, defaultPrefix, expression, l);
assertSame(actual, binding);
verify();
}
use of org.apache.tapestry5.services.BindingFactory in project tapestry-5 by apache.
the class BindingSourceImplTest method expression_prefix_not_in_configuration.
@Test
public void expression_prefix_not_in_configuration() {
BindingFactory factory = mockBindingFactory();
Binding binding = mockBinding();
ComponentResources container = mockComponentResources();
ComponentResources component = mockComponentResources();
Location l = mockLocation();
String defaultPrefix = "def";
String description = "descrip";
String expression = "javascript:not-a-known-prefix";
train_newBinding(factory, description, container, component, expression, l, binding);
replay();
Map<String, BindingFactory> map = newMap();
map.put(defaultPrefix, factory);
BindingSource source = new BindingSourceImpl(map, interner);
Binding actual = source.newBinding(description, container, component, defaultPrefix, expression, l);
assertSame(actual, binding);
verify();
}
use of org.apache.tapestry5.services.BindingFactory in project tapestry-5 by apache.
the class BindingFactoryTest method symbol_binding.
@Test
public void symbol_binding() {
ComponentResources res = mockInternalComponentResources();
Location l = mockLocation();
replay();
BindingFactory factory = getService("SymbolBindingFactory", BindingFactory.class);
Binding binding = factory.newBinding("Test binding", res, null, SymbolConstants.START_PAGE_NAME, l);
assertEquals(binding.get(), "start");
verify();
}
use of org.apache.tapestry5.services.BindingFactory in project tapestry-5 by apache.
the class BindingSourceImpl method newBinding.
public Binding newBinding(String description, ComponentResources container, ComponentResources component, String defaultPrefix, String expression, Location location) {
assert InternalUtils.isNonBlank(description);
assert container != null;
assert InternalUtils.isNonBlank(defaultPrefix);
assert component != null;
// TAP5-845: The expression may be the empty string. This is ok, if it's compatible with
// the default prefix (the empty string is not a valid property expression, but is valid
// as a literal string, perhaps as an informal parameter).
// Location might be null
String subexpression = expression;
int colonx = expression.indexOf(':');
BindingFactory factory = null;
if (colonx > 0) {
String prefix = expression.substring(0, colonx);
factory = factories.get(prefix);
if (factory != null)
subexpression = expression.substring(colonx + 1);
}
if (factory == null)
factory = factories.get(defaultPrefix);
try {
return factory.newBinding(interner.intern(description), container, component, subexpression, location);
} catch (Exception ex) {
throw new TapestryException(String.format("Could not convert '%s' into a component parameter binding: %s", expression, ExceptionUtils.toMessage(ex)), location, ex);
}
}
use of org.apache.tapestry5.services.BindingFactory in project tapestry-5 by apache.
the class BindingFactoryTest method translate_binding.
@Test
public void translate_binding() {
FieldTranslator translator = mockFieldTranslator();
FieldTranslatorSource source = newMock(FieldTranslatorSource.class);
ComponentResources resources = mockComponentResources();
Location l = mockLocation();
String description = "foo bar";
String expression = "mock";
expect(source.createTranslator(resources, expression)).andReturn(translator);
replay();
BindingFactory factory = new TranslateBindingFactory(source, new StringInternerImpl());
Binding binding = factory.newBinding(description, resources, resources, expression, l);
assertSame(binding.get(), translator);
assertSame(InternalUtils.locationOf(binding), l);
verify();
}
Aggregations