Search in sources :

Example 6 with Value

use of org.apache.tapestry5.ioc.annotations.Value in project tapestry-5 by apache.

the class AbstractBeanModelSourceImplTest method array_type_bean.

@Test
public void array_type_bean() {
    Messages messages = mockMessages();
    stub_contains(messages, false);
    replay();
    BeanModel model = source.create(StringArrayBean.class, true, messages);
    // There's not editor for string arrays yet, so it won't show up normally.
    PropertyModel propertyModel = model.add("array");
    assertSame(propertyModel.getPropertyType(), String[].class);
    String[] value = { "foo", "bar" };
    StringArrayBean bean = new StringArrayBean();
    PropertyConduit conduit = propertyModel.getConduit();
    conduit.set(bean, value);
    assertSame(bean.getArray(), value);
    assertSame(conduit.get(bean), value);
    verify();
}
Also used : Messages(org.apache.tapestry5.commons.Messages) BeanModel(org.apache.tapestry5.beanmodel.BeanModel) PropertyModel(org.apache.tapestry5.beanmodel.PropertyModel) PropertyConduit(org.apache.tapestry5.beanmodel.PropertyConduit) Test(org.testng.annotations.Test)

Example 7 with Value

use of org.apache.tapestry5.ioc.annotations.Value in project tapestry-5 by apache.

the class AbstractBeanModelSourceImplTest method filtering_out_read_only_properties.

@Test
public void filtering_out_read_only_properties() {
    Messages messages = mockMessages();
    stub_contains(messages, false);
    replay();
    BeanModel model = source.create(ReadOnlyBean.class, true, messages);
    assertEquals(model.getPropertyNames(), Arrays.asList("value"));
    model = source.create(ReadOnlyBean.class, false, messages);
    assertEquals(model.getPropertyNames(), Arrays.asList("value", "readOnly"));
    verify();
}
Also used : Messages(org.apache.tapestry5.commons.Messages) BeanModel(org.apache.tapestry5.beanmodel.BeanModel) ReadOnlyBean(org.apache.tapestry5.internal.transform.pages.ReadOnlyBean) Test(org.testng.annotations.Test)

Example 8 with Value

use of org.apache.tapestry5.ioc.annotations.Value in project tapestry-5 by apache.

the class ClientPersistentFieldStorageImplTest method store_and_restore_a_change.

@SuppressWarnings("unchecked")
@Test
public void store_and_restore_a_change() {
    Request request = mockRequest(null);
    Link link = mockLink();
    String pageName = "Foo";
    String componentId = "bar.baz";
    String fieldName = "biff";
    Object value = 99;
    final Holder<String> holder = captureLinkModification(link);
    replay();
    ClientPersistentFieldStorage storage1 = new ClientPersistentFieldStorageImpl(request, clientDataEncoder, analyzer);
    storage1.postChange(pageName, componentId, fieldName, value);
    List<PersistentFieldChange> changes1 = newList(storage1.gatherFieldChanges(pageName));
    storage1.updateLink(link);
    verify();
    assertEquals(changes1.size(), 1);
    PersistentFieldChange change1 = changes1.get(0);
    assertEquals(change1.getComponentId(), componentId);
    assertEquals(change1.getFieldName(), fieldName);
    assertEquals(change1.getValue(), value);
    // Now more training ...
    train_getParameter(request, ClientPersistentFieldStorageImpl.PARAMETER_NAME, holder.get());
    replay();
    ClientPersistentFieldStorage storage2 = new ClientPersistentFieldStorageImpl(request, clientDataEncoder, analyzer);
    List<PersistentFieldChange> changes2 = newList(storage2.gatherFieldChanges(pageName));
    verify();
    assertEquals(changes2.size(), 1);
    PersistentFieldChange change2 = changes2.get(0);
    assertEquals(change2.getComponentId(), componentId);
    assertEquals(change2.getFieldName(), fieldName);
    assertEquals(change2.getValue(), value);
    assertNotSame(change1, change2);
}
Also used : Request(org.apache.tapestry5.http.services.Request) PersistentFieldChange(org.apache.tapestry5.services.PersistentFieldChange) Link(org.apache.tapestry5.http.Link) Test(org.testng.annotations.Test)

Example 9 with Value

use of org.apache.tapestry5.ioc.annotations.Value 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 10 with Value

use of org.apache.tapestry5.ioc.annotations.Value 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)

Aggregations

Test (org.testng.annotations.Test)83 ComponentResources (org.apache.tapestry5.ComponentResources)30 ComponentModel (org.apache.tapestry5.model.ComponentModel)16 MarkupWriter (org.apache.tapestry5.MarkupWriter)13 Field (org.apache.tapestry5.Field)12 PropertyConduit (org.apache.tapestry5.beanmodel.PropertyConduit)11 Location (org.apache.tapestry5.commons.Location)11 MessageFormatter (org.apache.tapestry5.commons.MessageFormatter)11 Type (org.apache.tapestry5.internal.plastic.asm.Type)11 MetaDataLocator (org.apache.tapestry5.services.MetaDataLocator)11 Messages (org.apache.tapestry5.commons.Messages)10 JSONObject (org.apache.tapestry5.json.JSONObject)10 Request (org.apache.tapestry5.http.services.Request)9 SymbolSource (org.apache.tapestry5.ioc.services.SymbolSource)9 TypeCoercer (org.apache.tapestry5.commons.services.TypeCoercer)8 Link (org.apache.tapestry5.http.Link)8 Binding (org.apache.tapestry5.Binding)7 ValidationException (org.apache.tapestry5.ValidationException)7 InternalPropertyConduit (org.apache.tapestry5.beanmodel.internal.InternalPropertyConduit)7 TapestryException (org.apache.tapestry5.commons.internal.util.TapestryException)7