You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CaseInsensitiveBindingTest.java 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package com.vaadin.tests.server.component.fieldgroup;
  2. import static org.junit.Assert.assertTrue;
  3. import org.junit.Test;
  4. import com.vaadin.data.fieldgroup.FieldGroup;
  5. import com.vaadin.data.util.ObjectProperty;
  6. import com.vaadin.data.util.PropertysetItem;
  7. import com.vaadin.ui.FormLayout;
  8. import com.vaadin.v7.ui.LegacyTextField;
  9. public class CaseInsensitiveBindingTest {
  10. @Test
  11. public void caseInsensitivityAndUnderscoreRemoval() {
  12. PropertysetItem item = new PropertysetItem();
  13. item.addItemProperty("LastName", new ObjectProperty<String>("Sparrow"));
  14. class MyForm extends FormLayout {
  15. LegacyTextField lastName = new LegacyTextField("Last name");
  16. public MyForm() {
  17. // Should bind to the LastName property
  18. addComponent(lastName);
  19. }
  20. }
  21. MyForm form = new MyForm();
  22. FieldGroup binder = new FieldGroup(item);
  23. binder.bindMemberFields(form);
  24. assertTrue("Sparrow".equals(form.lastName.getValue()));
  25. }
  26. @Test
  27. public void UnderscoreRemoval() {
  28. PropertysetItem item = new PropertysetItem();
  29. item.addItemProperty("first_name", new ObjectProperty<String>("Jack"));
  30. class MyForm extends FormLayout {
  31. LegacyTextField firstName = new LegacyTextField("First name");
  32. public MyForm() {
  33. // Should bind to the first_name property
  34. addComponent(firstName);
  35. }
  36. }
  37. MyForm form = new MyForm();
  38. FieldGroup binder = new FieldGroup(item);
  39. binder.bindMemberFields(form);
  40. assertTrue("Jack".equals(form.firstName.getValue()));
  41. }
  42. @Test
  43. public void perfectMatchPriority() {
  44. PropertysetItem item = new PropertysetItem();
  45. item.addItemProperty("first_name",
  46. new ObjectProperty<String>("Not this"));
  47. item.addItemProperty("firstName", new ObjectProperty<String>("This"));
  48. class MyForm extends FormLayout {
  49. LegacyTextField firstName = new LegacyTextField("First name");
  50. public MyForm() {
  51. // should bind to the firstName property, not first_name
  52. // property
  53. addComponent(firstName);
  54. }
  55. }
  56. MyForm form = new MyForm();
  57. FieldGroup binder = new FieldGroup(item);
  58. binder.bindMemberFields(form);
  59. assertTrue("This".equals(form.firstName.getValue()));
  60. }
  61. }