Search in sources :

Example 21 with PropertyModel

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

the class AbstractBeanModelSourceImplTest method default_model_for_bean.

/**
 * Tests defaults for property names, labels and conduits.
 */
@Test
public void default_model_for_bean() {
    Messages messages = mockMessages();
    stub_contains(messages, false);
    replay();
    BeanModel model = source.create(SimpleBean.class, true, messages);
    assertSame(model.getBeanType(), SimpleBean.class);
    // Based on order of the getter methods (no longer alphabetical)
    assertEquals(model.getPropertyNames(), Arrays.asList("firstName", "lastName", "age"));
    assertEquals(model.toString(), "BeanModel[org.apache.tapestry5.genericsresolverguava.internal.SimpleBean properties:firstName, lastName, age]");
    PropertyModel age = model.get("age");
    assertEquals(age.getLabel(), "Age");
    assertSame(age.getPropertyType(), int.class);
    assertEquals(age.getDataType(), "number");
    PropertyModel firstName = model.get("firstName");
    assertEquals(firstName.getLabel(), "First Name");
    assertEquals(firstName.getPropertyType(), String.class);
    assertEquals(firstName.getDataType(), "text");
    assertEquals(model.get("lastName").getLabel(), "Last Name");
    PropertyConduit conduit = model.get("lastName").getConduit();
    SimpleBean instance = new SimpleBean();
    instance.setLastName("Lewis Ship");
    assertEquals(conduit.get(instance), "Lewis Ship");
    conduit.set(instance, "TapestryDude");
    assertEquals(instance.getLastName(), "TapestryDude");
    // Now, one with some type coercion.
    age.getConduit().set(instance, "40");
    assertEquals(instance.getAge(), 40);
    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 22 with PropertyModel

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

the class AbstractBeanModelSourceImplTest method get_added_property_by_id.

@Test
public void get_added_property_by_id() {
    Messages messages = mockMessages();
    stub_contains(messages, false);
    replay();
    BeanModel model = source.create(SimpleBean.class, true, messages);
    PropertyModel pm = model.addEmpty("shrub.foo()");
    assertSame(model.getById("ShrubFoo"), pm);
    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 23 with PropertyModel

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

the class AbstractBeanModelSourceImplTest method add_before.

@Test
public void add_before() {
    Messages messages = mockMessages();
    PropertyConduit conduit = mockPropertyConduit();
    Class propertyType = String.class;
    stub_contains(messages, false);
    expect(conduit.getPropertyType()).andReturn(propertyType).atLeastOnce();
    expect(conduit.getAnnotation(EasyMock.isA(Class.class))).andStubReturn(null);
    replay();
    BeanModel model = source.create(SimpleBean.class, true, messages);
    assertEquals(model.getPropertyNames(), Arrays.asList("firstName", "lastName", "age"));
    // Note the use of case insensitivity here.
    PropertyModel property = model.add(RelativePosition.BEFORE, "lastname", "middleInitial", conduit);
    assertEquals(model.getPropertyNames(), Arrays.asList("firstName", "middleInitial", "lastName", "age"));
    assertEquals(property.getPropertyName(), "middleInitial");
    assertSame(property.getConduit(), conduit);
    assertSame(property.getPropertyType(), propertyType);
    verify();
}
Also used : Messages(org.apache.tapestry5.commons.Messages) BeanModel(org.apache.tapestry5.beanmodel.BeanModel) PropertyModel(org.apache.tapestry5.beanmodel.PropertyModel) BeforeClass(org.testng.annotations.BeforeClass) PropertyConduit(org.apache.tapestry5.beanmodel.PropertyConduit) Test(org.testng.annotations.Test)

Example 24 with PropertyModel

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

the class AbstractBeanModelSourceImplTest method add_before_using_default_conduit.

@Test
public void add_before_using_default_conduit() {
    Messages messages = mockMessages();
    stub_contains(messages, false);
    replay();
    BeanModel model = source.create(SimpleBean.class, true, messages);
    model.exclude("firstname");
    assertEquals(model.getPropertyNames(), Arrays.asList("lastName", "age"));
    // Note the use of case insensitivity here.
    PropertyModel property = model.add(RelativePosition.BEFORE, "lastname", "firstName");
    assertEquals(model.getPropertyNames(), Arrays.asList("firstName", "lastName", "age"));
    assertEquals(property.getPropertyName(), "firstName");
    assertSame(property.getPropertyType(), String.class);
    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 25 with PropertyModel

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

the class AbstractBeanModelSourceImplTest method add_after.

@Test
public void add_after() {
    Messages messages = mockMessages();
    PropertyConduit conduit = mockPropertyConduit();
    Class propertyType = String.class;
    stub_contains(messages, false);
    expect(conduit.getPropertyType()).andReturn(propertyType).atLeastOnce();
    expect(conduit.getAnnotation(EasyMock.isA(Class.class))).andStubReturn(null);
    replay();
    BeanModel model = source.create(SimpleBean.class, true, messages);
    assertEquals(model.getPropertyNames(), Arrays.asList("firstName", "lastName", "age"));
    PropertyModel property = model.add(RelativePosition.AFTER, "firstname", "middleInitial", conduit);
    assertEquals(model.getPropertyNames(), Arrays.asList("firstName", "middleInitial", "lastName", "age"));
    assertEquals(property.getPropertyName(), "middleInitial");
    assertSame(property.getConduit(), conduit);
    assertSame(property.getPropertyType(), propertyType);
    verify();
}
Also used : Messages(org.apache.tapestry5.commons.Messages) BeanModel(org.apache.tapestry5.beanmodel.BeanModel) PropertyModel(org.apache.tapestry5.beanmodel.PropertyModel) BeforeClass(org.testng.annotations.BeforeClass) PropertyConduit(org.apache.tapestry5.beanmodel.PropertyConduit) Test(org.testng.annotations.Test)

Aggregations

PropertyModel (org.apache.tapestry5.beanmodel.PropertyModel)29 Test (org.testng.annotations.Test)23 BeanModel (org.apache.tapestry5.beanmodel.BeanModel)21 Messages (org.apache.tapestry5.commons.Messages)19 PropertyConduit (org.apache.tapestry5.beanmodel.PropertyConduit)9 BeforeClass (org.testng.annotations.BeforeClass)4 ComponentResources (org.apache.tapestry5.ComponentResources)2 Location (org.apache.tapestry5.commons.Location)2 TapestryException (org.apache.tapestry5.commons.internal.util.TapestryException)2 Annotation (java.lang.annotation.Annotation)1 PropertyOverrides (org.apache.tapestry5.PropertyOverrides)1 SortConstraint (org.apache.tapestry5.grid.SortConstraint)1 BeanValidationContext (org.apache.tapestry5.internal.BeanValidationContext)1 BeanBlockSource (org.apache.tapestry5.services.BeanBlockSource)1 PropertyEditContext (org.apache.tapestry5.services.PropertyEditContext)1