12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- package com.vaadin.tests.server.component.fieldgroup;
-
- import static org.junit.Assert.assertTrue;
-
- import org.junit.Test;
-
- import com.vaadin.data.fieldgroup.FieldGroup;
- import com.vaadin.data.util.ObjectProperty;
- import com.vaadin.data.util.PropertysetItem;
- import com.vaadin.ui.FormLayout;
- import com.vaadin.v7.ui.LegacyTextField;
-
- public class CaseInsensitiveBindingTest {
-
- @Test
- public void caseInsensitivityAndUnderscoreRemoval() {
- PropertysetItem item = new PropertysetItem();
- item.addItemProperty("LastName", new ObjectProperty<String>("Sparrow"));
-
- class MyForm extends FormLayout {
- LegacyTextField lastName = new LegacyTextField("Last name");
-
- public MyForm() {
-
- // Should bind to the LastName property
- addComponent(lastName);
- }
- }
-
- MyForm form = new MyForm();
-
- FieldGroup binder = new FieldGroup(item);
- binder.bindMemberFields(form);
-
- assertTrue("Sparrow".equals(form.lastName.getValue()));
- }
-
- @Test
- public void UnderscoreRemoval() {
- PropertysetItem item = new PropertysetItem();
- item.addItemProperty("first_name", new ObjectProperty<String>("Jack"));
-
- class MyForm extends FormLayout {
- LegacyTextField firstName = new LegacyTextField("First name");
-
- public MyForm() {
- // Should bind to the first_name property
- addComponent(firstName);
- }
- }
-
- MyForm form = new MyForm();
-
- FieldGroup binder = new FieldGroup(item);
- binder.bindMemberFields(form);
-
- assertTrue("Jack".equals(form.firstName.getValue()));
- }
-
- @Test
- public void perfectMatchPriority() {
- PropertysetItem item = new PropertysetItem();
- item.addItemProperty("first_name",
- new ObjectProperty<String>("Not this"));
- item.addItemProperty("firstName", new ObjectProperty<String>("This"));
-
- class MyForm extends FormLayout {
- LegacyTextField firstName = new LegacyTextField("First name");
-
- public MyForm() {
- // should bind to the firstName property, not first_name
- // property
- addComponent(firstName);
- }
- }
-
- MyForm form = new MyForm();
-
- FieldGroup binder = new FieldGroup(item);
- binder.bindMemberFields(form);
-
- assertTrue("This".equals(form.firstName.getValue()));
- }
-
- }
|