diff options
author | Jonni Nakari <jonni@vaadin.com> | 2012-12-17 15:03:04 +0200 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2012-12-17 13:44:44 +0000 |
commit | fffd25fc57c862afdac2f4cfc36695c0bd35ec96 (patch) | |
tree | bdaffc6c393842afdfa4f45d47f7dd8bdc162e9a /server/tests/src/com/vaadin | |
parent | 5c8d4c1f5dfa4f6fb2e73728e2c0512d3e5c7446 (diff) | |
download | vaadin-framework-fffd25fc57c862afdac2f4cfc36695c0bd35ec96.tar.gz vaadin-framework-fffd25fc57c862afdac2f4cfc36695c0bd35ec96.zip |
Case-insensitive FieldGroup binding #10426
Modified buildAndBindMemberFields to use a new findPropertyId method
when searching propertyIds.
Change-Id: I97f1c4eb8a3de7350b0333c8b2b2ff913e0263d9
Diffstat (limited to 'server/tests/src/com/vaadin')
-rw-r--r-- | server/tests/src/com/vaadin/tests/server/component/fieldgroup/CaseInsensitiveBinding.java | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/server/tests/src/com/vaadin/tests/server/component/fieldgroup/CaseInsensitiveBinding.java b/server/tests/src/com/vaadin/tests/server/component/fieldgroup/CaseInsensitiveBinding.java new file mode 100644 index 0000000000..9b768ef77f --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/fieldgroup/CaseInsensitiveBinding.java @@ -0,0 +1,84 @@ +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.ui.TextField; + +public class CaseInsensitiveBinding { + + @Test + public void caseInsensitivityAndUnderscoreRemoval() { + PropertysetItem item = new PropertysetItem(); + item.addItemProperty("LastName", new ObjectProperty<String>("Sparrow")); + + class MyForm extends FormLayout { + TextField lastName = new TextField("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 { + TextField firstName = new TextField("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 { + TextField firstName = new TextField("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())); + } + +} |