Search in sources :

Example 11 with ComponentResources

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

the class PropBindingFactoryTest method method_call_as_terminal.

@Test
public void method_call_as_terminal() {
    TargetBean bean = new TargetBean();
    ComponentResources resources = newComponentResources(bean);
    Location l = mockLocation();
    replay();
    Binding binding = factory.newBinding("test binding", resources, null, "stringHolderMethod().stringValue()", l);
    assertSame(binding.getBindingType(), String.class);
    bean.getStringHolder().setValue("first");
    assertEquals(binding.get(), "first");
    try {
        binding.set("read-only");
        unreachable();
    } catch (TapestryException ex) {
        assertEquals(ex.getMessage(), "Expression 'stringHolderMethod().stringValue()' for class org.apache.tapestry5.internal.bindings.TargetBean is read-only.");
        assertSame(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 ComponentResources

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

the class PropBindingFactoryTest method void_method_in_preamble.

@Test
public void void_method_in_preamble() {
    TargetBean bean = new TargetBean();
    ComponentResources resources = mockComponentResources();
    Location l = mockLocation();
    train_getComponent(resources, bean);
    replay();
    try {
        factory.newBinding("test binding", resources, null, "voidMethod().value", l);
        unreachable();
    } catch (RuntimeException ex) {
        assertMessageContains(ex, "Method org.apache.tapestry5.internal.bindings.TargetBean.voidMethod() returns void");
    }
    verify();
}
Also used : ComponentResources(org.apache.tapestry5.ComponentResources) Location(org.apache.tapestry5.commons.Location) Test(org.testng.annotations.Test)

Example 13 with ComponentResources

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

the class PropBindingFactoryTest method primitive_property.

@Test
public void primitive_property() {
    TargetBean bean = new TargetBean();
    ComponentResources resources = newComponentResources(bean);
    Location l = mockLocation();
    replay();
    Binding binding = factory.newBinding("test binding", resources, null, "intValue", l);
    assertSame(binding.getBindingType(), int.class);
    bean.setIntValue(1);
    assertEquals(binding.get(), 1);
    binding.set(2);
    assertEquals(bean.getIntValue(), 2);
    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 14 with ComponentResources

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

the class PropBindingFactoryTest method method_not_found_in_terminal.

@Test
public void method_not_found_in_terminal() {
    TargetBean bean = new TargetBean();
    ComponentResources resources = mockComponentResources();
    Location l = mockLocation();
    train_getComponent(resources, bean);
    replay();
    try {
        factory.newBinding("test binding", resources, null, "stringHolder.isThatRealBlood()", l);
        unreachable();
    } catch (RuntimeException ex) {
        assertMessageContains(ex, "StringHolder", "does not contain a public method", "isThatRealBlood()");
    }
    verify();
}
Also used : ComponentResources(org.apache.tapestry5.ComponentResources) Location(org.apache.tapestry5.commons.Location) Test(org.testng.annotations.Test)

Example 15 with ComponentResources

use of org.apache.tapestry5.ComponentResources 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)

Aggregations

ComponentResources (org.apache.tapestry5.ComponentResources)110 Test (org.testng.annotations.Test)99 Location (org.apache.tapestry5.commons.Location)34 Binding (org.apache.tapestry5.Binding)24 Messages (org.apache.tapestry5.commons.Messages)24 ComponentModel (org.apache.tapestry5.model.ComponentModel)17 FormSupport (org.apache.tapestry5.services.FormSupport)17 TapestryException (org.apache.tapestry5.commons.internal.util.TapestryException)16 Component (org.apache.tapestry5.runtime.Component)15 MarkupWriter (org.apache.tapestry5.MarkupWriter)14 FieldValidator (org.apache.tapestry5.FieldValidator)13 TypeCoercer (org.apache.tapestry5.commons.services.TypeCoercer)13 FieldValidatorSource (org.apache.tapestry5.services.FieldValidatorSource)13 Validator (org.apache.tapestry5.Validator)11 ValidatorMacro (org.apache.tapestry5.validator.ValidatorMacro)11 MessageFormatter (org.apache.tapestry5.commons.MessageFormatter)10 BindingFactory (org.apache.tapestry5.services.BindingFactory)10 PropertyOverrides (org.apache.tapestry5.PropertyOverrides)9 MetaDataLocator (org.apache.tapestry5.services.MetaDataLocator)9 Request (org.apache.tapestry5.http.services.Request)7