diff options
author | Patrik Lindström <patrik@vaadin.com> | 2013-07-31 16:42:16 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2013-08-07 10:53:59 +0000 |
commit | 11f8811eb0f7a306c403d36ab45f5d8658d7a164 (patch) | |
tree | da08b51e2d9c02ea2ae963792ff5ad432980d4dd /server/tests | |
parent | 8ba41172216a98a45f82319d9a98d04a26efa52a (diff) | |
download | vaadin-framework-11f8811eb0f7a306c403d36ab45f5d8658d7a164.tar.gz vaadin-framework-11f8811eb0f7a306c403d36ab45f5d8658d7a164.zip |
Make sure bean field validators are only added once (#11045)
Change-Id: I67779fa5bfd4c850101c11c22091c988eb65b808
Diffstat (limited to 'server/tests')
-rw-r--r-- | server/tests/src/com/vaadin/tests/server/validation/TestBeanValidation.java | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/server/tests/src/com/vaadin/tests/server/validation/TestBeanValidation.java b/server/tests/src/com/vaadin/tests/server/validation/TestBeanValidation.java index 8f6928fc35..e1d08a989b 100644 --- a/server/tests/src/com/vaadin/tests/server/validation/TestBeanValidation.java +++ b/server/tests/src/com/vaadin/tests/server/validation/TestBeanValidation.java @@ -1,10 +1,14 @@ package com.vaadin.tests.server.validation; +import junit.framework.Assert; + import org.junit.Test; import com.vaadin.data.Validator.InvalidValueException; +import com.vaadin.data.fieldgroup.BeanFieldGroup; import com.vaadin.data.validator.BeanValidator; import com.vaadin.tests.data.bean.BeanToValidate; +import com.vaadin.ui.Field; public class TestBeanValidation { @Test(expected = InvalidValueException.class) @@ -54,4 +58,42 @@ public class TestBeanValidation { validator.validate("123.45"); } + @Test + public void testBeanValidationNotAddedTwice() { + // See ticket #11045 + BeanFieldGroup<BeanToValidate> fieldGroup = new BeanFieldGroup<BeanToValidate>( + BeanToValidate.class); + + BeanToValidate beanToValidate = new BeanToValidate(); + beanToValidate.setFirstname("a"); + fieldGroup.setItemDataSource(beanToValidate); + + Field<?> nameField = fieldGroup.buildAndBind("firstname"); + Assert.assertEquals(1, nameField.getValidators().size()); + + try { + nameField.validate(); + } catch (InvalidValueException e) { + // NOTE: causes are empty if only one validation fails + Assert.assertEquals(0, e.getCauses().length); + } + + // Create new, identical bean to cause duplicate validator unless #11045 + // is fixed + beanToValidate = new BeanToValidate(); + beanToValidate.setFirstname("a"); + fieldGroup.setItemDataSource(beanToValidate); + + Assert.assertEquals(1, nameField.getValidators().size()); + + try { + nameField.validate(); + } catch (InvalidValueException e) { + // NOTE: if more than one validation fails, we get the number of + // failed validations + Assert.assertEquals(0, e.getCauses().length); + } + + } + } |