use of org.apache.tapestry5.beanmodel.PropertyModel 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();
}
use of org.apache.tapestry5.beanmodel.PropertyModel 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();
}
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();
}
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.internal.services.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();
}
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();
}
Aggregations