use of com.vaadin.flow.data.binder.testcomponents.TestTextField in project flow by vaadin.
the class BinderTest method beanvalidation_two_fields_not_equal.
@Test
public void beanvalidation_two_fields_not_equal() {
TestTextField lastNameField = new TestTextField();
setBeanValidationFirstNameNotEqualsLastName(nameField, lastNameField);
item.setLastName("Valid");
binder.setBean(item);
Assert.assertFalse("Should not have changes initially", binder.hasChanges());
Assert.assertTrue("Should be ok initially", binder.validate().isOk());
Assert.assertNotEquals("First name and last name are not same initially", item.getFirstName(), item.getLastName());
nameField.setValue("Invalid");
Assert.assertFalse("First name change not handled", binder.hasChanges());
Assert.assertTrue("Changing first name to something else than last name should be ok", binder.validate().isOk());
lastNameField.setValue("Invalid");
Assert.assertTrue("Last name should not be saved yet", binder.hasChanges());
Assert.assertFalse("Binder validation should fail with pending illegal value", binder.validate().isOk());
Assert.assertNotEquals("Illegal last name should not be stored to bean", item.getFirstName(), item.getLastName());
nameField.setValue("Valid");
Assert.assertFalse("With new first name both changes should be saved", binder.hasChanges());
Assert.assertTrue("Everything should be ok for 'Valid Invalid'", binder.validate().isOk());
Assert.assertNotEquals("First name and last name should never match.", item.getFirstName(), item.getLastName());
}
use of com.vaadin.flow.data.binder.testcomponents.TestTextField in project flow by vaadin.
the class BinderTest method readNullBeanRemovesError.
@Test
public void readNullBeanRemovesError() {
TestTextField textField = new TestTextField();
binder.forField(textField).asRequired("foobar").bind(Person::getFirstName, Person::setFirstName);
Assert.assertTrue(textField.isRequiredIndicatorVisible());
Assert.assertNull(componentErrors.get(textField));
binder.readBean(item);
Assert.assertNull(componentErrors.get(textField));
textField.setValue(textField.getEmptyValue());
Assert.assertTrue(textField.isRequiredIndicatorVisible());
Assert.assertNotNull(componentErrors.get(textField));
binder.readBean(null);
assertTrue(textField.isRequiredIndicatorVisible());
Assert.assertNull(componentErrors.get(textField));
}
use of com.vaadin.flow.data.binder.testcomponents.TestTextField in project flow by vaadin.
the class BinderTest method beanvalidation_isValid_throws_with_readBean.
@Test(expected = IllegalStateException.class)
public void beanvalidation_isValid_throws_with_readBean() {
TestTextField lastNameField = new TestTextField();
setBeanValidationFirstNameNotEqualsLastName(nameField, lastNameField);
binder.readBean(item);
Assert.assertTrue(binder.isValid());
}
use of com.vaadin.flow.data.binder.testcomponents.TestTextField in project flow by vaadin.
the class ValueContextTest method setUp.
@Before
public void setUp() {
setLocale(UI_LOCALE);
UI.setCurrent(this);
textField = new TestTextField();
add(textField);
}
use of com.vaadin.flow.data.binder.testcomponents.TestTextField in project flow by vaadin.
the class BeanBinderTest method lastName_minSizeConstraint_fieldIsRequired.
@Test
public void lastName_minSizeConstraint_fieldIsRequired() {
BeanValidationBinder<RequiredConstraints> binder = new BeanValidationBinder<>(RequiredConstraints.class);
RequiredConstraints bean = new RequiredConstraints();
TestTextField field = new TestTextField();
binder.bind(field, "lastname");
binder.setBean(bean);
Assert.assertTrue(field.isRequiredIndicatorVisible());
testSerialization(binder);
}
Aggregations