use of com.vaadin.flow.tests.data.bean.Person in project flow by vaadin.
the class BinderConverterValidatorTest method saveIfValid_beanValidationErrors.
@Test
public void saveIfValid_beanValidationErrors() {
Binder<Person> binder = new Binder<>();
binder.forField(nameField).bind(Person::getFirstName, Person::setFirstName);
String msg = "foo";
binder.withValidator(Validator.from(prsn -> prsn.getAddress() != null || prsn.getEmail() != null, msg));
Person person = new Person();
person.setFirstName("foo");
nameField.setValue("");
Assert.assertFalse(binder.writeBeanIfValid(person));
Assert.assertEquals("foo", person.getFirstName());
}
use of com.vaadin.flow.tests.data.bean.Person in project flow by vaadin.
the class BinderConverterValidatorTest method save_beanValidationErrors.
@Test(expected = ValidationException.class)
public void save_beanValidationErrors() throws ValidationException {
Binder<Person> binder = new Binder<>();
binder.forField(nameField).withValidator(new NotEmptyValidator<>("a")).bind(Person::getFirstName, Person::setFirstName);
binder.withValidator(Validator.from(person -> false, "b"));
Person person = new Person();
nameField.setValue("foo");
try {
binder.writeBean(person);
} finally {
// Bean should have been updated for item validation but reverted
assertNull(person.getFirstName());
}
}
use of com.vaadin.flow.tests.data.bean.Person in project flow by vaadin.
the class BinderConverterValidatorTest method saveIfValid_noValidationErrors.
@Test
public void saveIfValid_noValidationErrors() {
String msg = "foo";
binder.forField(nameField).withValidator(new NotEmptyValidator<>(msg)).bind(Person::getFirstName, Person::setFirstName);
Person person = new Person();
person.setFirstName("foo");
nameField.setValue("bar");
Assert.assertTrue(binder.writeBeanIfValid(person));
Assert.assertEquals("bar", person.getFirstName());
}
use of com.vaadin.flow.tests.data.bean.Person in project flow by vaadin.
the class BinderInstanceFieldTest method bindInstanceFields_complexGenericHierarchy.
@Test
public void bindInstanceFields_complexGenericHierarchy() {
BindComplextHierarchyGenericType form = new BindComplextHierarchyGenericType();
Binder<Person> binder = new Binder<>(Person.class);
binder.bindInstanceFields(form);
Person person = new Person();
person.setFirstName("foo");
binder.setBean(person);
Assert.assertEquals(person.getFirstName(), form.firstName.getValue());
form.firstName.setValue("bar");
Assert.assertEquals(form.firstName.getValue(), person.getFirstName());
}
use of com.vaadin.flow.tests.data.bean.Person in project flow by vaadin.
the class BinderInstanceFieldTest method bindInstanceFields_genericField.
@Test
public void bindInstanceFields_genericField() {
BindGenericField form = new BindGenericField();
Binder<Person> binder = new Binder<>(Person.class);
binder.bindInstanceFields(form);
Person person = new Person();
person.setFirstName("foo");
binder.setBean(person);
Assert.assertEquals(person.getFirstName(), form.firstName.getValue());
form.firstName.setValue("bar");
Assert.assertEquals(form.firstName.getValue(), person.getFirstName());
}
Aggregations