Search in sources :

Example 1 with Address

use of com.vaadin.flow.tests.data.bean.Address in project flow by vaadin.

the class BinderInstanceFieldTest method bindInstanceFields_bindNestedFieldUsingAnnotation.

@Test
public void bindInstanceFields_bindNestedFieldUsingAnnotation() {
    BindNestedFieldsUsingAnnotation form = new BindNestedFieldsUsingAnnotation();
    Binder<Person> binder = new Binder<>(Person.class, true);
    binder.bindInstanceFields(form);
    Person person = new Person();
    Address address = new Address();
    address.setStreetAddress("Foo st.");
    person.setAddress(address);
    binder.setBean(person);
    Assert.assertEquals("Reading nested properties bound using annotation", person.getAddress().getStreetAddress(), form.streetAddressField.getValue());
    form.streetAddressField.setValue("Bar ave.");
    Assert.assertEquals("Changing nested properties bound using annotation", form.streetAddressField.getValue(), person.getAddress().getStreetAddress());
}
Also used : Address(com.vaadin.flow.tests.data.bean.Address) Person(com.vaadin.flow.tests.data.bean.Person) Test(org.junit.Test)

Example 2 with Address

use of com.vaadin.flow.tests.data.bean.Address in project flow by vaadin.

the class BinderInstanceFieldTest method bindInstanceFields_bindDeepNestedFieldsUsingAnnotation.

@Test
public void bindInstanceFields_bindDeepNestedFieldsUsingAnnotation() {
    BindDeepNestedFieldsUsingAnnotation form = new BindDeepNestedFieldsUsingAnnotation();
    Binder<Couple> binder = new Binder<>(Couple.class, true);
    binder.bindInstanceFields(form);
    Person first = new Person();
    Person second = new Person();
    Address firstAddress = new Address();
    firstAddress.setStreetAddress("Foo st.");
    first.setAddress(firstAddress);
    Address secondAddress = new Address();
    second.setAddress(secondAddress);
    secondAddress.setStreetAddress("Bar ave.");
    Couple couple = new Couple();
    couple.setFirst(first);
    couple.setSecond(second);
    binder.setBean(couple);
    Assert.assertEquals("Binding deep nested properties using annotation", couple.first.getAddress().getStreetAddress(), form.firstStreetField.getValue());
    Assert.assertEquals("Binding parallel deep nested properties using annotation", couple.second.getAddress().getStreetAddress(), form.secondStreetField.getValue());
    form.firstStreetField.setValue(second.getAddress().getStreetAddress());
    Assert.assertEquals("Updating value in deep nested properties", form.firstStreetField.getValue(), first.getAddress().getStreetAddress());
}
Also used : Address(com.vaadin.flow.tests.data.bean.Address) Person(com.vaadin.flow.tests.data.bean.Person) Test(org.junit.Test)

Example 3 with Address

use of com.vaadin.flow.tests.data.bean.Address in project flow by vaadin.

the class BeanPropertySetTest method testSerializeDeserialize_nestedPropertyDefinition.

@Test
public void testSerializeDeserialize_nestedPropertyDefinition() throws Exception {
    PropertyDefinition<com.vaadin.flow.tests.data.bean.Person, ?> definition = BeanPropertySet.get(com.vaadin.flow.tests.data.bean.Person.class, true, PropertyFilterDefinition.getDefaultFilter()).getProperty("address.postalCode").orElseThrow(AssertionFailedError::new);
    PropertyDefinition<com.vaadin.flow.tests.data.bean.Person, ?> deserializedDefinition = ClassesSerializableUtils.serializeAndDeserialize(definition);
    ValueProvider<com.vaadin.flow.tests.data.bean.Person, ?> getter = deserializedDefinition.getGetter();
    Address address = new Address("Ruukinkatu 2-4", 20540, "Turku", Country.FINLAND);
    com.vaadin.flow.tests.data.bean.Person person = new com.vaadin.flow.tests.data.bean.Person("Jon", "Doe", "jon.doe@vaadin.com", 32, Sex.MALE, address);
    Integer postalCode = (Integer) getter.apply(person);
    Assert.assertEquals("Deserialized definition should be functional", address.getPostalCode(), postalCode);
}
Also used : Address(com.vaadin.flow.tests.data.bean.Address) AssertionFailedError(junit.framework.AssertionFailedError) Test(org.junit.Test)

Aggregations

Address (com.vaadin.flow.tests.data.bean.Address)3 Test (org.junit.Test)3 Person (com.vaadin.flow.tests.data.bean.Person)2 AssertionFailedError (junit.framework.AssertionFailedError)1