Search in sources :

Example 51 with Location

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();
}
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) Test(org.testng.annotations.Test)

Example 52 with Location

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

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

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();
}
Also used : Resource(org.apache.tapestry5.commons.Resource) MutableComponentModel(org.apache.tapestry5.model.MutableComponentModel) Logger(org.slf4j.Logger) MutableEmbeddedComponentModel(org.apache.tapestry5.model.MutableEmbeddedComponentModel) Location(org.apache.tapestry5.commons.Location) Test(org.testng.annotations.Test)

Example 55 with Location

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();
}
Also used : Resource(org.apache.tapestry5.commons.Resource) MutableComponentModel(org.apache.tapestry5.model.MutableComponentModel) Logger(org.slf4j.Logger) MutableEmbeddedComponentModel(org.apache.tapestry5.model.MutableEmbeddedComponentModel) Location(org.apache.tapestry5.commons.Location) Test(org.testng.annotations.Test)

Aggregations

Location (org.apache.tapestry5.commons.Location)51 Test (org.testng.annotations.Test)41 ComponentResources (org.apache.tapestry5.ComponentResources)33 Binding (org.apache.tapestry5.Binding)25 TapestryException (org.apache.tapestry5.commons.internal.util.TapestryException)21 BindingFactory (org.apache.tapestry5.services.BindingFactory)10 BindingSource (org.apache.tapestry5.services.BindingSource)6 Resource (org.apache.tapestry5.commons.Resource)4 UnknownValueException (org.apache.tapestry5.commons.util.UnknownValueException)4 Component (org.apache.tapestry5.runtime.Component)4 MutableEmbeddedComponentModel (org.apache.tapestry5.model.MutableEmbeddedComponentModel)3 Environment (org.apache.tapestry5.services.Environment)3 Logger (org.slf4j.Logger)3 Matcher (java.util.regex.Matcher)2 QName (javax.xml.namespace.QName)2 MarkupWriter (org.apache.tapestry5.MarkupWriter)2 PropertyOverrides (org.apache.tapestry5.PropertyOverrides)2 PropertyConduit (org.apache.tapestry5.beanmodel.PropertyConduit)2 PropertyModel (org.apache.tapestry5.beanmodel.PropertyModel)2 Messages (org.apache.tapestry5.commons.Messages)2