Search in sources :

Example 11 with Location

use of org.apache.tapestry5.commons.Location in project tapestry-5 by apache.

the class PropBindingFactoryTest method read_only_property.

@Test
public void read_only_property() {
    TargetBean bean = new TargetBean();
    ComponentResources resources = newComponentResources(bean);
    Location l = mockLocation();
    replay();
    Binding binding = factory.newBinding("test binding", resources, null, "readOnly", l);
    assertEquals(binding.get(), "ReadOnly");
    try {
        binding.set("fail");
        unreachable();
    } catch (TapestryException ex) {
        assertEquals(ex.getMessage(), "Expression 'readOnly' for class org.apache.tapestry5.internal.bindings.TargetBean is read-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 12 with Location

use of org.apache.tapestry5.commons.Location in project tapestry-5 by apache.

the class PropBindingFactoryTest method object_property.

@Test
public void object_property() {
    TargetBean bean = new TargetBean();
    ComponentResources resources = newComponentResources(bean);
    Location l = mockLocation();
    replay();
    Binding binding = factory.newBinding("test binding", resources, null, "objectValue", l);
    assertSame(binding.getBindingType(), String.class);
    bean.setObjectValue("first");
    assertEquals(binding.get(), "first");
    binding.set("second");
    assertEquals(bean.getObjectValue(), "second");
    assertEquals(InternalUtils.locationOf(binding), l);
    assertEquals(binding.toString(), "PropBinding[test binding foo.Bar:baz(objectValue)]");
    verify();
}
Also used : Binding(org.apache.tapestry5.Binding) ComponentResources(org.apache.tapestry5.ComponentResources) Location(org.apache.tapestry5.commons.Location) Test(org.testng.annotations.Test)

Example 13 with Location

use of org.apache.tapestry5.commons.Location in project tapestry-5 by apache.

the class PropBindingFactoryTest method property_path_through_missing_property.

@Test
public void property_path_through_missing_property() {
    TargetBean bean = new TargetBean();
    ComponentResources resources = mockComponentResources();
    Location l = mockLocation();
    train_getComponent(resources, bean);
    replay();
    String propertyPath = "stringHolder.missingProperty.terminalProperty";
    try {
        factory.newBinding("test binding", resources, null, propertyPath, l);
        unreachable();
    } catch (RuntimeException ex) {
        assertMessageContains(ex, "Class org.apache.tapestry5.internal.bindings.StringHolder does not contain a property", "\'missingProperty\'");
    }
    verify();
}
Also used : ComponentResources(org.apache.tapestry5.ComponentResources) Location(org.apache.tapestry5.commons.Location) Test(org.testng.annotations.Test)

Example 14 with Location

use of org.apache.tapestry5.commons.Location in project tapestry-5 by apache.

the class PropBindingFactoryTest method annotation_from_write_only_property.

@Test
public void annotation_from_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);
    assertEquals(binding.getAnnotation(Validate.class).value(), "writeonly");
    verify();
}
Also used : Binding(org.apache.tapestry5.Binding) ComponentResources(org.apache.tapestry5.ComponentResources) Location(org.apache.tapestry5.commons.Location) Test(org.testng.annotations.Test)

Example 15 with Location

use of org.apache.tapestry5.commons.Location in project tapestry-5 by apache.

the class PropBindingFactoryTest method annotation_does_not_exist.

@Test
public void annotation_does_not_exist() {
    TargetBean bean = new TargetBean();
    ComponentResources resources = newComponentResources(bean);
    Location l = mockLocation();
    replay();
    Binding binding = factory.newBinding("test binding", resources, null, "intValue", l);
    assertNull(binding.getAnnotation(Validate.class));
    verify();
}
Also used : Binding(org.apache.tapestry5.Binding) Validate(org.apache.tapestry5.beaneditor.Validate) ComponentResources(org.apache.tapestry5.ComponentResources) 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