Search in sources :

Example 16 with TestTextField

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());
}
Also used : TestTextField(com.vaadin.flow.data.binder.testcomponents.TestTextField) Test(org.junit.Test)

Example 17 with TestTextField

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));
}
Also used : TestTextField(com.vaadin.flow.data.binder.testcomponents.TestTextField) Person(com.vaadin.flow.tests.data.bean.Person) Test(org.junit.Test)

Example 18 with TestTextField

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());
}
Also used : TestTextField(com.vaadin.flow.data.binder.testcomponents.TestTextField) Test(org.junit.Test)

Example 19 with TestTextField

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);
}
Also used : TestTextField(com.vaadin.flow.data.binder.testcomponents.TestTextField) Before(org.junit.Before)

Example 20 with TestTextField

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);
}
Also used : TestTextField(com.vaadin.flow.data.binder.testcomponents.TestTextField) Test(org.junit.Test)

Aggregations

TestTextField (com.vaadin.flow.data.binder.testcomponents.TestTextField)28 Test (org.junit.Test)26 Person (com.vaadin.flow.tests.data.bean.Person)13 Matchers.isEmptyString (org.hamcrest.Matchers.isEmptyString)7 StringToIntegerConverter (com.vaadin.flow.data.converter.StringToIntegerConverter)6 Before (org.junit.Before)5 HasValue (com.vaadin.flow.component.HasValue)4 SubConstraint (com.vaadin.flow.data.binder.BeanBinderTest.RequiredConstraints.SubConstraint)4 StringLengthValidator (com.vaadin.flow.data.validator.StringLengthValidator)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Assert (org.junit.Assert)4 Label (com.vaadin.flow.component.html.Label)3 SubSubConstraint (com.vaadin.flow.data.binder.BeanBinderTest.RequiredConstraints.SubSubConstraint)3 Binding (com.vaadin.flow.data.binder.Binder.Binding)3 BindingBuilder (com.vaadin.flow.data.binder.Binder.BindingBuilder)3 NotEmptyValidator (com.vaadin.flow.data.validator.NotEmptyValidator)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 Assert.assertEquals (org.junit.Assert.assertEquals)3 Assert.assertFalse (org.junit.Assert.assertFalse)3