use of org.apache.tapestry5.commons.Location in project tapestry-5 by apache.
the class PropBindingFactoryTest method write_only_property.
@Test
public void write_only_property() {
TargetBean bean = new TargetBean();
ComponentResources resources = newComponentResources(bean);
Location l = mockLocation();
replay();
Binding binding = factory.newBinding("test binding", resources, null, "writeOnly", l);
binding.set("updated");
assertEquals(bean.writeOnly, "updated");
try {
assertEquals(binding.get(), "ReadOnly");
unreachable();
} catch (TapestryException ex) {
assertEquals(ex.getMessage(), "Expression 'writeOnly' for class org.apache.tapestry5.internal.bindings.TargetBean is write-only.");
assertEquals(ex.getLocation(), l);
}
verify();
}
use of org.apache.tapestry5.commons.Location 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.commons.Location 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.commons.Location in project tapestry-5 by apache.
the class MutableComponentModelImplTest method add_embedded.
@Test
public void add_embedded() {
Resource r = mockResource();
Logger logger = mockLogger();
Location l = mockLocation();
replay();
MutableComponentModel model = new MutableComponentModelImpl(CLASS_NAME, logger, r, null, false, null);
assertTrue(model.getEmbeddedComponentIds().isEmpty());
MutableEmbeddedComponentModel fred = model.addEmbeddedComponent("fred", "Fred", COMPONENT_CLASS_NAME, false, l);
assertEquals(fred.getId(), "fred");
assertEquals(fred.getComponentType(), "Fred");
assertFalse(fred.getInheritInformalParameters());
assertSame(fred.getLocation(), l);
MutableEmbeddedComponentModel barney = model.addEmbeddedComponent("barney", "Barney", COMPONENT_CLASS_NAME, false, null);
assertEquals(model.getEmbeddedComponentIds(), Arrays.asList("barney", "fred"));
assertSame(model.getEmbeddedComponentModel("fred"), fred);
assertSame(model.getEmbeddedComponentModel("barney"), barney);
// Access by id is case insensitive
assertSame(model.getEmbeddedComponentModel("FRED"), fred);
assertSame(model.getEmbeddedComponentModel("BARNEY"), barney);
assertEquals(fred.toString(), "EmbeddedComponentModel[id=fred type=Fred class=org.example.components.Fred inheritInformals=false]");
verify();
}
use of org.apache.tapestry5.commons.Location in project tapestry-5 by apache.
the class MutableComponentModelImplTest method add_embedded_with_inherit_informal_parameters.
@Test
public void add_embedded_with_inherit_informal_parameters() {
Resource r = mockResource();
Logger logger = mockLogger();
Location l = mockLocation();
replay();
MutableComponentModel model = new MutableComponentModelImpl(CLASS_NAME, logger, r, null, false, null);
assertTrue(model.getEmbeddedComponentIds().isEmpty());
MutableEmbeddedComponentModel fred = model.addEmbeddedComponent("fred", "Fred", COMPONENT_CLASS_NAME, true, l);
assertTrue(fred.getInheritInformalParameters());
assertEquals(fred.toString(), "EmbeddedComponentModel[id=fred type=Fred class=org.example.components.Fred inheritInformals=true]");
verify();
}
Aggregations