Search in sources :

Example 1 with BeanModel

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

the class AbstractBeanModelSourceImplTest method sortable_annotation.

// https://issues.apache.org/jira/browse/TAP5-2305
@Test
public void sortable_annotation() {
    Messages messages = mockMessages();
    stub_contains(messages, false);
    replay();
    BeanModel<SortableBean> model = source.createDisplayModel(SortableBean.class, messages);
    model.add("nonSortableByDefault");
    model.add("sortable");
    // checking whether non-@Sortable annotated properties still behave in the old ways
    assertTrue(model.get("sortableByDefault").isSortable());
    assertFalse(model.get("nonSortableByDefault").isSortable());
    // checking @Sortable itself
    assertFalse(model.get("nonSortable").isSortable());
    assertTrue(model.get("sortable").isSortable());
    verify();
}
Also used : Messages(org.apache.tapestry5.commons.Messages) Test(org.testng.annotations.Test)

Example 2 with BeanModel

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

the class AbstractBeanModelSourceImplTest method edit_property_label.

@Test
public void edit_property_label() {
    Messages messages = mockMessages();
    stub_contains(messages, false);
    replay();
    BeanModel model = source.create(SimpleBean.class, true, messages).get("age").label("Decrepitude").model();
    assertEquals(model.get("age").getLabel(), "Decrepitude");
    verify();
}
Also used : Messages(org.apache.tapestry5.commons.Messages) BeanModel(org.apache.tapestry5.beanmodel.BeanModel) Test(org.testng.annotations.Test)

Example 3 with BeanModel

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

the class AbstractBeanModelSourceImplTest method composite_bean.

@Test
public void composite_bean() {
    Messages messages = mockMessages();
    stub_contains(messages, false);
    train_contains(messages, "simpleage-label", true);
    train_get(messages, "simpleage-label", "Years of Age");
    replay();
    BeanModel model = source.create(CompositeBean.class, true, messages);
    // No editor for CompositeBean, so this will be empty.
    assertEquals(model.getPropertyNames(), Collections.emptyList());
    // There's not editor for string arrays yet, so it won't show up normally.
    PropertyModel firstName = model.add("simple.firstName");
    assertEquals(firstName.getLabel(), "First Name");
    PropertyModel age = model.add("simple.age");
    assertEquals(age.getLabel(), "Years of Age");
    CompositeBean bean = new CompositeBean();
    firstName.getConduit().set(bean, "Fred");
    age.getConduit().set(bean, "97");
    assertEquals(bean.getSimple().getFirstName(), "Fred");
    assertEquals(bean.getSimple().getAge(), 97);
    bean.getSimple().setAge(24);
    assertEquals(age.getConduit().get(bean), new Integer(24));
    verify();
}
Also used : Messages(org.apache.tapestry5.commons.Messages) BeanModel(org.apache.tapestry5.beanmodel.BeanModel) PropertyModel(org.apache.tapestry5.beanmodel.PropertyModel) Test(org.testng.annotations.Test)

Example 4 with BeanModel

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

the class AbstractBeanModelSourceImplTest method order_via_annotation.

@Test
public void order_via_annotation() {
    Messages messages = mockMessages();
    stub_contains(messages, false);
    replay();
    BeanModel model = source.create(StoogeBean.class, true, messages);
    assertEquals(model.getPropertyNames(), Arrays.asList("larry", "moe", "shemp", "curly"));
    verify();
}
Also used : Messages(org.apache.tapestry5.commons.Messages) BeanModel(org.apache.tapestry5.beanmodel.BeanModel) Test(org.testng.annotations.Test)

Example 5 with BeanModel

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

the class AbstractBeanModelSourceImplTest method exclude_property.

@Test
public void exclude_property() {
    Messages messages = mockMessages();
    stub_contains(messages, false);
    replay();
    BeanModel model = source.create(SimpleBean.class, true, messages);
    assertSame(model.exclude("age"), model);
    assertEquals(model.getPropertyNames(), Arrays.asList("firstName", "lastName"));
    verify();
}
Also used : Messages(org.apache.tapestry5.commons.Messages) BeanModel(org.apache.tapestry5.beanmodel.BeanModel) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)70 Messages (org.apache.tapestry5.commons.Messages)63 BeanModel (org.apache.tapestry5.beanmodel.BeanModel)61 PropertyModel (org.apache.tapestry5.beanmodel.PropertyModel)24 PropertyConduit (org.apache.tapestry5.beanmodel.PropertyConduit)9 UnknownValueException (org.apache.tapestry5.commons.util.UnknownValueException)5 ComponentResources (org.apache.tapestry5.ComponentResources)4 PropertyOverrides (org.apache.tapestry5.PropertyOverrides)4 BeanModelSource (org.apache.tapestry5.beanmodel.services.BeanModelSource)4 Environment (org.apache.tapestry5.services.Environment)4 BeforeClass (org.testng.annotations.BeforeClass)4 RegistrationData (org.apache.tapestry5.integration.app1.data.RegistrationData)3 Annotation (java.lang.annotation.Annotation)2 BeanValidationContext (org.apache.tapestry5.internal.BeanValidationContext)2 BeanEditContext (org.apache.tapestry5.services.BeanEditContext)2 Type (java.lang.reflect.Type)1 NonVisual (org.apache.tapestry5.beaneditor.NonVisual)1 ReorderProperties (org.apache.tapestry5.beaneditor.ReorderProperties)1 BeanModelImpl (org.apache.tapestry5.beanmodel.internal.beanmodel.BeanModelImpl)1 PropertyExpressionException (org.apache.tapestry5.beanmodel.internal.services.PropertyExpressionException)1