From e968734dfa87136d7a488156789edf77cac1d7f6 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Thu, 8 Dec 2011 13:04:33 +0000 Subject: #6603 Added IllegalArgumentException to javadoc and added test svn changeset:22320/svn branch:6.7 --- .../com/vaadin/data/util/BeanContainerTest.java | 34 +++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/server-side/com/vaadin/data/util/BeanContainerTest.java b/tests/server-side/com/vaadin/data/util/BeanContainerTest.java index 5a753e19d0..d9fa8d896e 100644 --- a/tests/server-side/com/vaadin/data/util/BeanContainerTest.java +++ b/tests/server-side/com/vaadin/data/util/BeanContainerTest.java @@ -1,7 +1,9 @@ package com.vaadin.data.util; +import java.util.ArrayList; import java.util.Arrays; import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -10,7 +12,6 @@ import junit.framework.Assert; import com.vaadin.data.Container; import com.vaadin.data.Item; import com.vaadin.data.util.AbstractBeanContainer.BeanIdResolver; -import com.vaadin.data.util.BeanContainer; public class BeanContainerTest extends AbstractBeanContainerTest { @@ -324,6 +325,37 @@ public class BeanContainerTest extends AbstractBeanContainerTest { assertEquals(0, container.size()); } + public void testAddAllWithNullItemId() { + BeanContainer container = new BeanContainer( + Person.class); + // resolver that returns null as item id + container + .setBeanIdResolver(new BeanIdResolver() { + + public String getIdForBean(Person bean) { + return bean.getName(); + } + }); + + List persons = new ArrayList(); + persons.add(new Person("John")); + persons.add(new Person("Marc")); + persons.add(new Person(null)); + persons.add(new Person("foo")); + + try { + container.addAll(persons); + fail(); + } catch (IllegalArgumentException e) { + // should get exception + } + + container.removeAllItems(); + persons.remove(2); + container.addAll(persons); + assertEquals(3, container.size()); + } + public void testAddBeanWithNullResolver() { BeanContainer container = new BeanContainer( Person.class); -- cgit v1.2.3 From fc4ff50b2bdc3c7dc5197d15d6696b661838e2cf Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Thu, 8 Dec 2011 15:37:54 +0000 Subject: Test for how validators work with empty fields svn changeset:22329/svn branch:6.7 --- .../ValidationOfRequiredEmptyFields.html | 133 +++++++++++++++++++++ .../ValidationOfRequiredEmptyFields.java | 94 +++++++++++++++ 2 files changed, 227 insertions(+) create mode 100644 tests/testbench/com/vaadin/tests/validation/ValidationOfRequiredEmptyFields.html create mode 100644 tests/testbench/com/vaadin/tests/validation/ValidationOfRequiredEmptyFields.java (limited to 'tests') diff --git a/tests/testbench/com/vaadin/tests/validation/ValidationOfRequiredEmptyFields.html b/tests/testbench/com/vaadin/tests/validation/ValidationOfRequiredEmptyFields.html new file mode 100644 index 0000000000..4b273ca260 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/validation/ValidationOfRequiredEmptyFields.html @@ -0,0 +1,133 @@ + + + + + + +New Test + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
New Test
open/run/com.vaadin.tests.validation.ValidationOfRequiredFields?restartApplication
mouseClickvaadin=runcomvaadintestsvalidationValidationOfRequiredFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VCheckBox[0]/domChild[0]11,8
mouseClickvaadin=runcomvaadintestsvalidationValidationOfRequiredFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VTextField[0]60,11
enterCharactervaadin=runcomvaadintestsvalidationValidationOfRequiredFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VTextField[0]The field is required
showTooltipvaadin=runcomvaadintestsvalidationValidationOfRequiredFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[4]/VTextField[0]0,0
screenCapturerequired-message
mouseClickvaadin=runcomvaadintestsvalidationValidationOfRequiredFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VCheckBox[0]/domChild[0]13,5
mouseClickvaadin=runcomvaadintestsvalidationValidationOfRequiredFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[4]/VTextField[0]28,13
enterCharactervaadin=runcomvaadintestsvalidationValidationOfRequiredFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[4]/VTextField[0]a
mouseClickvaadin=runcomvaadintestsvalidationValidationOfRequiredFields::/VVerticalLayout[0]/domChild[0]/domChild[1]34,186
showTooltipvaadin=runcomvaadintestsvalidationValidationOfRequiredFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[4]/VTextField[0]0,0
screenCaptureerror-must-be-int
showTooltipvaadin=runcomvaadintestsvalidationValidationOfRequiredFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[3]/VCheckBox[0]/domChild[0]
mouseClickvaadin=runcomvaadintestsvalidationValidationOfRequiredFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[3]/VCheckBox[0]/domChild[0]45,9
showTooltipvaadin=runcomvaadintestsvalidationValidationOfRequiredFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[4]/VTextField[0]0,0
screenCaptureerror-must-be-int-and-5-to-10-chars
mouseClickvaadin=runcomvaadintestsvalidationValidationOfRequiredFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[3]/VCheckBox[0]/domChild[0]12,7
mouseClickvaadin=runcomvaadintestsvalidationValidationOfRequiredFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[4]/VTextField[0]124,12
typevaadin=runcomvaadintestsvalidationValidationOfRequiredFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[4]/VTextField[0]
mouseClickvaadin=runcomvaadintestsvalidationValidationOfRequiredFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VCheckBox[0]/domChild[0]8,10
mouseClickvaadin=runcomvaadintestsvalidationValidationOfRequiredFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[3]/VCheckBox[0]/domChild[0]13,7
showTooltipvaadin=runcomvaadintestsvalidationValidationOfRequiredFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[4]/VTextField[0]0,0
screenCaptureempty-invalid-not-required
+ + diff --git a/tests/testbench/com/vaadin/tests/validation/ValidationOfRequiredEmptyFields.java b/tests/testbench/com/vaadin/tests/validation/ValidationOfRequiredEmptyFields.java new file mode 100644 index 0000000000..396b244758 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/validation/ValidationOfRequiredEmptyFields.java @@ -0,0 +1,94 @@ +package com.vaadin.tests.validation; + +import com.vaadin.data.Property.ValueChangeEvent; +import com.vaadin.data.Property.ValueChangeListener; +import com.vaadin.data.Validator; +import com.vaadin.data.validator.IntegerValidator; +import com.vaadin.data.validator.StringLengthValidator; +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.CheckBox; +import com.vaadin.ui.TextField; + +public class ValidationOfRequiredEmptyFields extends TestBase { + + private TextField tf; + private CheckBox requiredInput; + private TextField requiredErrorInput; + + private Validator integerValidator = new IntegerValidator( + "Must be an integer"); + private Validator stringLengthValidator = new StringLengthValidator( + "Must be 5-10 chars", 5, 10, false); + private CheckBox integerValidatorInput; + private CheckBox stringLengthValidatorInput; + + @Override + protected void setup() { + requiredInput = new CheckBox("Field required"); + requiredInput.setImmediate(true); + requiredInput.addListener(new ValueChangeListener() { + public void valueChange(ValueChangeEvent event) { + tf.setRequired((Boolean) requiredInput.getValue()); + } + }); + + requiredErrorInput = new TextField("Required error message"); + requiredErrorInput.setImmediate(true); + requiredErrorInput.addListener(new ValueChangeListener() { + public void valueChange(ValueChangeEvent event) { + tf.setRequiredError((String) requiredErrorInput.getValue()); + } + }); + + integerValidatorInput = new CheckBox("Integer.parseInt validator"); + integerValidatorInput.setImmediate(true); + integerValidatorInput.addListener(new ValueChangeListener() { + + public void valueChange(ValueChangeEvent event) { + if ((Boolean) integerValidatorInput.getValue()) { + tf.addValidator(integerValidator); + } else { + tf.removeValidator(integerValidator); + } + } + }); + stringLengthValidatorInput = new CheckBox( + "stringLength.parseInt validator"); + stringLengthValidatorInput.setImmediate(true); + stringLengthValidatorInput.addListener(new ValueChangeListener() { + + public void valueChange(ValueChangeEvent event) { + if ((Boolean) stringLengthValidatorInput.getValue()) { + tf.addValidator(stringLengthValidator); + } else { + tf.removeValidator(stringLengthValidator); + } + } + }); + + tf = new TextField(); + tf.setImmediate(true); + + requiredInput.setValue(false); + requiredErrorInput.setValue(""); + integerValidatorInput.setValue(false); + stringLengthValidatorInput.setValue(false); + + addComponent(requiredInput); + addComponent(requiredErrorInput); + addComponent(integerValidatorInput); + addComponent(stringLengthValidatorInput); + addComponent(tf); + } + + @Override + protected String getDescription() { + return null; + } + + @Override + protected Integer getTicketNumber() { + return 3851; + } + +} -- cgit v1.2.3