Search in sources :

Example 1 with TestTextField

use of com.vaadin.flow.data.binder.testcomponents.TestTextField in project flow by vaadin.

the class BeanBinderTest method subfield_name_fieldIsRequired.

@Test
public void subfield_name_fieldIsRequired() {
    BeanValidationBinder<RequiredConstraints> binder = new BeanValidationBinder<>(RequiredConstraints.class);
    RequiredConstraints bean = new RequiredConstraints();
    bean.setSubfield(new RequiredConstraints.SubConstraint());
    TestTextField field = new TestTextField();
    binder.bind(field, "subfield.name");
    binder.setBean(bean);
    Assert.assertTrue(field.isRequiredIndicatorVisible());
    testSerialization(binder);
}
Also used : SubConstraint(com.vaadin.flow.data.binder.BeanBinderTest.RequiredConstraints.SubConstraint) TestTextField(com.vaadin.flow.data.binder.testcomponents.TestTextField) Test(org.junit.Test)

Example 2 with TestTextField

use of com.vaadin.flow.data.binder.testcomponents.TestTextField in project flow by vaadin.

the class BeanBinderTest method subSubfield_name_valueCanBeValidated.

@Test
public void subSubfield_name_valueCanBeValidated() {
    BeanValidationBinder<RequiredConstraints> binder = new BeanValidationBinder<>(RequiredConstraints.class);
    TestTextField field = new TestTextField();
    binder.bind(field, "subfield.subsub.value");
    RequiredConstraints bean = new RequiredConstraints();
    SubConstraint subfield = new SubConstraint();
    bean.setSubfield(subfield);
    subfield.setSubsub(new SubSubConstraint());
    binder.setBean(bean);
    Assert.assertFalse(binder.validate().isOk());
    field.setValue("overtencharacters");
    Assert.assertTrue(binder.validate().isOk());
}
Also used : TestTextField(com.vaadin.flow.data.binder.testcomponents.TestTextField) SubSubConstraint(com.vaadin.flow.data.binder.BeanBinderTest.RequiredConstraints.SubSubConstraint) SubSubConstraint(com.vaadin.flow.data.binder.BeanBinderTest.RequiredConstraints.SubSubConstraint) SubConstraint(com.vaadin.flow.data.binder.BeanBinderTest.RequiredConstraints.SubConstraint) Test(org.junit.Test)

Example 3 with TestTextField

use of com.vaadin.flow.data.binder.testcomponents.TestTextField in project flow by vaadin.

the class BeanBinderTest method subfield_name_valueCanBeValidated.

@Test
public void subfield_name_valueCanBeValidated() {
    BeanValidationBinder<RequiredConstraints> binder = new BeanValidationBinder<>(RequiredConstraints.class);
    TestTextField field = new TestTextField();
    binder.bind(field, "subfield.name");
    RequiredConstraints bean = new RequiredConstraints();
    bean.setSubfield(new SubConstraint());
    binder.setBean(bean);
    Assert.assertFalse(binder.validate().isOk());
    field.setValue("overfive");
    Assert.assertTrue(binder.validate().isOk());
}
Also used : TestTextField(com.vaadin.flow.data.binder.testcomponents.TestTextField) SubSubConstraint(com.vaadin.flow.data.binder.BeanBinderTest.RequiredConstraints.SubSubConstraint) SubConstraint(com.vaadin.flow.data.binder.BeanBinderTest.RequiredConstraints.SubConstraint) Test(org.junit.Test)

Example 4 with TestTextField

use of com.vaadin.flow.data.binder.testcomponents.TestTextField in project flow by vaadin.

the class BeanBinderTest method firstName_isNotNullConstraint_fieldIsRequired.

@Test
public void firstName_isNotNullConstraint_fieldIsRequired() {
    BeanValidationBinder<RequiredConstraints> binder = new BeanValidationBinder<>(RequiredConstraints.class);
    RequiredConstraints bean = new RequiredConstraints();
    TestTextField field = new TestTextField();
    binder.bind(field, "firstname");
    binder.setBean(bean);
    Assert.assertTrue(field.isRequiredIndicatorVisible());
    testSerialization(binder);
}
Also used : TestTextField(com.vaadin.flow.data.binder.testcomponents.TestTextField) Test(org.junit.Test)

Example 5 with TestTextField

use of com.vaadin.flow.data.binder.testcomponents.TestTextField in project flow by vaadin.

the class BeanBinderTest method age_minSizeConstraint_fieldIsRequired.

@Test
public void age_minSizeConstraint_fieldIsRequired() {
    BeanValidationBinder<RequiredConstraints> binder = new BeanValidationBinder<>(RequiredConstraints.class);
    RequiredConstraints bean = new RequiredConstraints();
    TestTextField field = new TestTextField();
    binder.bind(field, "age");
    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