Search in sources :

Example 1 with ElementPropertyMap

use of com.vaadin.flow.internal.nodefeature.ElementPropertyMap in project flow by vaadin.

the class BeanModelTypeTest method applicationToModel.

@Test
public void applicationToModel() {
    BeanModelType<Bean> beanType = new BeanModelType<>(Bean.class, PropertyFilter.ACCEPT_ALL, false);
    Bean bean = new Bean(3);
    StateNode applicationToModel = beanType.applicationToModel(bean, PropertyFilter.ACCEPT_ALL);
    ElementPropertyMap model = ElementPropertyMap.getModel(applicationToModel);
    assertThreeBean(model);
}
Also used : StateNode(com.vaadin.flow.internal.StateNode) ElementPropertyMap(com.vaadin.flow.internal.nodefeature.ElementPropertyMap) Test(org.junit.Test)

Example 2 with ElementPropertyMap

use of com.vaadin.flow.internal.nodefeature.ElementPropertyMap in project flow by vaadin.

the class BeanModelTypeTest method importBean_incompatibleBean.

@Test(expected = IllegalArgumentException.class)
public void importBean_incompatibleBean() {
    BeanModelType<Bean> beanType = new BeanModelType<>(Bean.class, PropertyFilter.ACCEPT_ALL, false);
    ElementPropertyMap model = createEmptyModel();
    DifferentBean bean = new DifferentBean(3);
    beanType.importProperties(model, bean, PropertyFilter.ACCEPT_ALL);
}
Also used : ElementPropertyMap(com.vaadin.flow.internal.nodefeature.ElementPropertyMap) Test(org.junit.Test)

Example 3 with ElementPropertyMap

use of com.vaadin.flow.internal.nodefeature.ElementPropertyMap in project flow by vaadin.

the class BeanModelTypeTest method importBean.

@Test
public void importBean() {
    BeanModelType<Bean> beanType = new BeanModelType<>(Bean.class, PropertyFilter.ACCEPT_ALL, false);
    ElementPropertyMap model = createEmptyModel();
    Bean bean = new Bean(3);
    beanType.importProperties(model, bean, PropertyFilter.ACCEPT_ALL);
    assertThreeBean(model);
}
Also used : ElementPropertyMap(com.vaadin.flow.internal.nodefeature.ElementPropertyMap) Test(org.junit.Test)

Example 4 with ElementPropertyMap

use of com.vaadin.flow.internal.nodefeature.ElementPropertyMap in project flow by vaadin.

the class TemplateModelTest method setListWithSubBeanInclude.

@Test
public void setListWithSubBeanInclude() {
    TemplateWithIncludeOnListSubBean template = new TemplateWithIncludeOnListSubBean();
    List<BeanContainingBeans> beanContainingBeans = new ArrayList<>();
    beanContainingBeans.add(new BeanContainingBeans(new Bean(11), new Bean(12)));
    beanContainingBeans.add(new BeanContainingBeans(null, new Bean(22)));
    template.getModel().setBeanContainingBeans(beanContainingBeans);
    ModelList modelList = getModelList(template, "beanContainingBeans");
    Assert.assertEquals(2, modelList.size());
    ElementPropertyMap container1Map = ElementPropertyMap.getModel(modelList.get(0));
    ElementPropertyMap container2Map = ElementPropertyMap.getModel(modelList.get(1));
    Set<String> bean1bean2 = new HashSet<>();
    bean1bean2.add("bean1");
    bean1bean2.add("bean2");
    Assert.assertEquals(bean1bean2, container1Map.getPropertyNames().collect(Collectors.toSet()));
    Assert.assertEquals(bean1bean2, container2Map.getPropertyNames().collect(Collectors.toSet()));
    Set<String> container1Bean1Properties = getKeys(container1Map.resolveModelMap("bean1"));
    Assert.assertTrue(container1Bean1Properties.remove("intValue"));
    Assert.assertEquals(0, container1Bean1Properties.size());
    Set<String> container1Bean2Properties = getKeys(container1Map.resolveModelMap("bean2"));
    Assert.assertTrue(container1Bean2Properties.remove("booleanValue"));
    Assert.assertEquals(0, container1Bean2Properties.size());
    Set<String> container2Bean1Properties = getKeys(container2Map.resolveModelMap("bean1"));
    // Null value in the initial bean implies not imported or created
    Assert.assertEquals(0, container2Bean1Properties.size());
    Set<String> container2Bean2Properties = getKeys(container2Map.resolveModelMap("bean2"));
    Assert.assertTrue(container2Bean2Properties.remove("booleanValue"));
    Assert.assertEquals(0, container2Bean2Properties.size());
}
Also used : ModelList(com.vaadin.flow.internal.nodefeature.ModelList) ArrayList(java.util.ArrayList) ElementPropertyMap(com.vaadin.flow.internal.nodefeature.ElementPropertyMap) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with ElementPropertyMap

use of com.vaadin.flow.internal.nodefeature.ElementPropertyMap in project flow by vaadin.

the class TemplateModelTest method setBeanIncludeSubBeanProperties.

@Test
public void setBeanIncludeSubBeanProperties() {
    TemplateWithIncludeForSubBean template = new TemplateWithIncludeForSubBean();
    BeanContainingBeans beanContainer = new BeanContainingBeans();
    beanContainer.setBean1(new Bean(1));
    beanContainer.setBean2(new Bean(2));
    template.getModel().setBeanContainingBeans(beanContainer);
    Assert.assertNotNull(template.getModel().getBeanContainingBeans().getBean1());
    ElementPropertyMap bean1Map = getModelMap(template, "beanContainingBeans.bean1");
    Set<String> bean1Keys = getKeys(bean1Map);
    Assert.assertTrue(bean1Keys.contains("booleanObject"));
    Assert.assertEquals(1, bean1Keys.size());
}
Also used : ElementPropertyMap(com.vaadin.flow.internal.nodefeature.ElementPropertyMap) Test(org.junit.Test)

Aggregations

ElementPropertyMap (com.vaadin.flow.internal.nodefeature.ElementPropertyMap)40 Test (org.junit.Test)31 StateNode (com.vaadin.flow.internal.StateNode)17 Element (com.vaadin.flow.dom.Element)7 Collectors (java.util.stream.Collectors)7 ModelList (com.vaadin.flow.internal.nodefeature.ModelList)6 ArrayList (java.util.ArrayList)6 Assert (org.junit.Assert)6 ElementChildrenList (com.vaadin.flow.internal.nodefeature.ElementChildrenList)5 VisibilityData (com.vaadin.flow.internal.nodefeature.VisibilityData)5 JsonObject (elemental.json.JsonObject)5 Serializable (java.io.Serializable)5 Arrays (java.util.Arrays)5 Collections (java.util.Collections)5 Map (java.util.Map)5 UI (com.vaadin.flow.component.UI)4 Date (java.util.Date)4 HashSet (java.util.HashSet)4 TestComponent (com.vaadin.flow.component.ComponentTest.TestComponent)3 NodeChange (com.vaadin.flow.internal.change.NodeChange)3