use of com.vaadin.flow.tests.data.bean.Person in project flow by vaadin.
the class BinderConverterValidatorTest method validate_failedBeanValidatorWithoutFieldValidators.
@Test
public void validate_failedBeanValidatorWithoutFieldValidators() {
binder.forField(nameField).bind(Person::getFirstName, Person::setFirstName);
String msg = "foo";
binder.withValidator(Validator.from(bean -> false, msg));
Person person = new Person();
binder.setBean(person);
List<BindingValidationStatus<?>> errors = binder.validate().getFieldValidationErrors();
assertEquals(0, errors.size());
assertValidField(nameField);
}
use of com.vaadin.flow.tests.data.bean.Person in project flow by vaadin.
the class BinderConverterValidatorTest method saveIfValid_fieldValidationErrors.
@Test
public void saveIfValid_fieldValidationErrors() {
String msg = "foo";
binder.forField(nameField).withValidator(new NotEmptyValidator<>(msg)).bind(Person::getFirstName, Person::setFirstName);
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_fieldValidationErrors.
@Test(expected = ValidationException.class)
public void save_fieldValidationErrors() throws ValidationException {
Binder<Person> binder = new Binder<>();
String msg = "foo";
binder.forField(nameField).withValidator(new NotEmptyValidator<>(msg)).bind(Person::getFirstName, Person::setFirstName);
Person person = new Person();
String firstName = "foo";
person.setFirstName(firstName);
nameField.setValue("");
try {
binder.writeBean(person);
} finally {
// Bean should not have been updated
Assert.assertEquals(firstName, person.getFirstName());
}
}
use of com.vaadin.flow.tests.data.bean.Person in project flow by vaadin.
the class BinderConverterValidatorTest method setUp.
@Before
public void setUp() {
CurrentInstance.clearAll();
binder = new Binder<Person>() {
@Override
protected void handleError(HasValue<?, ?> field, ValidationResult result) {
super.handleError(field, result);
componentErrors.put(field, result.getErrorMessage());
}
@Override
protected void clearError(HasValue<?, ?> field) {
super.clearError(field);
componentErrors.remove(field);
}
};
item = new Person();
item.setFirstName("Johannes");
item.setAge(32);
}
use of com.vaadin.flow.tests.data.bean.Person in project flow by vaadin.
the class BinderConverterValidatorTest method save_null_beanIsUpdated.
@Test
public void save_null_beanIsUpdated() throws ValidationException {
Binder<Person> binder = new Binder<>();
binder.forField(nameField).withConverter(fieldValue -> {
if ("null".equals(fieldValue)) {
return null;
} else {
return fieldValue;
}
}, model -> {
return model;
}).bind(Person::getFirstName, Person::setFirstName);
Person person = new Person();
person.setFirstName("foo");
nameField.setValue("null");
binder.writeBean(person);
assertNull(person.getFirstName());
}
Aggregations