Search in sources :

Example 11 with Messages

use of org.apache.tapestry5.commons.Messages 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 12 with Messages

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

the class AbstractBeanModelSourceImplTest method reoder_from_annotation.

@Test
public void reoder_from_annotation() {
    Messages messages = mockMessages();
    stub_contains(messages, false);
    replay();
    BeanModel model = source.create(PropertyOrderBean.class, true, messages);
    assertEquals(model.getPropertyNames(), Arrays.asList("third", "first", "second"));
    verify();
}
Also used : Messages(org.apache.tapestry5.commons.Messages) BeanModel(org.apache.tapestry5.beanmodel.BeanModel) Test(org.testng.annotations.Test)

Example 13 with Messages

use of org.apache.tapestry5.commons.Messages 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();
}
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 14 with Messages

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

the class AbstractBeanModelSourceImplTest method unknown_property_id.

@Test
public void unknown_property_id() {
    Messages messages = mockMessages();
    stub_contains(messages, false);
    replay();
    BeanModel model = source.create(SimpleBean.class, true, messages);
    model.addEmpty("shrub.foo()");
    try {
        model.getById("frobozz");
        unreachable();
    } catch (UnknownValueException ex) {
        assertEquals(ex.getMessage(), "Bean editor model for org.apache.tapestry5.internal.services.SimpleBean does not contain a property with id \'frobozz\'.");
        assertListsEquals(ex.getAvailableValues().getValues(), "age", "firstName", "lastName", "shrubfoo");
    }
    verify();
}
Also used : Messages(org.apache.tapestry5.commons.Messages) BeanModel(org.apache.tapestry5.beanmodel.BeanModel) UnknownValueException(org.apache.tapestry5.commons.util.UnknownValueException) Test(org.testng.annotations.Test)

Example 15 with Messages

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

Aggregations

Messages (org.apache.tapestry5.commons.Messages)111 Test (org.testng.annotations.Test)102 BeanModel (org.apache.tapestry5.beanmodel.BeanModel)54 ComponentResources (org.apache.tapestry5.ComponentResources)23 PropertyModel (org.apache.tapestry5.beanmodel.PropertyModel)21 FieldValidator (org.apache.tapestry5.FieldValidator)18 MessageFormatter (org.apache.tapestry5.commons.MessageFormatter)15 FormSupport (org.apache.tapestry5.services.FormSupport)15 FieldValidatorSource (org.apache.tapestry5.services.FieldValidatorSource)14 TypeCoercer (org.apache.tapestry5.commons.services.TypeCoercer)13 Validator (org.apache.tapestry5.Validator)12 Locale (java.util.Locale)11 ValidatorMacro (org.apache.tapestry5.validator.ValidatorMacro)11 Field (org.apache.tapestry5.Field)10 PropertyConduit (org.apache.tapestry5.beanmodel.PropertyConduit)9 AnnotationProvider (org.apache.tapestry5.commons.AnnotationProvider)9 PropertyOverrides (org.apache.tapestry5.PropertyOverrides)7 FieldTranslatorSource (org.apache.tapestry5.services.FieldTranslatorSource)7 TranslatorSource (org.apache.tapestry5.services.TranslatorSource)6 Map (java.util.Map)5