Search in sources :

Example 6 with StateNode

use of com.vaadin.flow.internal.StateNode in project flow by vaadin.

the class BeanModelTypeTest method applicationToModel_filtered.

@Test
public void applicationToModel_filtered() {
    BeanModelType<Bean> beanType = new BeanModelType<>(Bean.class, new PropertyFilter(name -> !name.equals("intValue")));
    Bean bean = new Bean(3);
    StateNode applicationToModel = beanType.applicationToModel(bean, new PropertyFilter(name -> name.equals("string") || name.equals("intValue")));
    ModelMap model = ModelMap.get(applicationToModel);
    Assert.assertEquals(Arrays.asList("string"), model.getKeys().collect(Collectors.toList()));
    Assert.assertEquals("3", model.getValue("string"));
}
Also used : PropertyFilter(com.vaadin.flow.templatemodel.PropertyFilter) Arrays(java.util.Arrays) StateNode(com.vaadin.flow.internal.StateNode) Date(java.util.Date) Test(org.junit.Test) Bean(com.vaadin.flow.templatemodel.Bean) Assert(org.junit.Assert) Collectors(java.util.stream.Collectors) ModelMap(com.vaadin.flow.internal.nodefeature.ModelMap) ModelMap(com.vaadin.flow.internal.nodefeature.ModelMap) StateNode(com.vaadin.flow.internal.StateNode) PropertyFilter(com.vaadin.flow.templatemodel.PropertyFilter) Bean(com.vaadin.flow.templatemodel.Bean) Test(org.junit.Test)

Example 7 with StateNode

use of com.vaadin.flow.internal.StateNode 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);
    ModelMap model = ModelMap.get(new StateNode(ModelMap.class));
    DifferentBean bean = new DifferentBean(3);
    beanType.importProperties(model, bean, PropertyFilter.ACCEPT_ALL);
}
Also used : ModelMap(com.vaadin.flow.internal.nodefeature.ModelMap) StateNode(com.vaadin.flow.internal.StateNode) Bean(com.vaadin.flow.templatemodel.Bean) Test(org.junit.Test)

Example 8 with StateNode

use of com.vaadin.flow.internal.StateNode in project flow by vaadin.

the class BeanModelTypeTest method importBean_withImportFilter.

@Test
public void importBean_withImportFilter() {
    BeanModelType<Bean> beanType = new BeanModelType<>(Bean.class, PropertyFilter.ACCEPT_ALL);
    ModelMap model = ModelMap.get(new StateNode(ModelMap.class));
    Bean bean = new Bean(3);
    beanType.importProperties(model, bean, new PropertyFilter(name -> "intObject".equals(name)));
    Assert.assertEquals(1, model.getKeys().count());
    Assert.assertEquals(Integer.valueOf(3), model.getValue("intObject"));
}
Also used : PropertyFilter(com.vaadin.flow.templatemodel.PropertyFilter) Arrays(java.util.Arrays) StateNode(com.vaadin.flow.internal.StateNode) Date(java.util.Date) Test(org.junit.Test) Bean(com.vaadin.flow.templatemodel.Bean) Assert(org.junit.Assert) Collectors(java.util.stream.Collectors) ModelMap(com.vaadin.flow.internal.nodefeature.ModelMap) ModelMap(com.vaadin.flow.internal.nodefeature.ModelMap) StateNode(com.vaadin.flow.internal.StateNode) PropertyFilter(com.vaadin.flow.templatemodel.PropertyFilter) Bean(com.vaadin.flow.templatemodel.Bean) Test(org.junit.Test)

Example 9 with StateNode

use of com.vaadin.flow.internal.StateNode in project flow by vaadin.

the class BeanModelTypeTest method importBean.

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

Example 10 with StateNode

use of com.vaadin.flow.internal.StateNode 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)

Aggregations

StateNode (com.vaadin.flow.internal.StateNode)160 Test (org.junit.Test)99 Element (com.vaadin.flow.dom.Element)29 ElementPropertyMap (com.vaadin.flow.internal.nodefeature.ElementPropertyMap)19 JsonObject (elemental.json.JsonObject)19 TemplateNode (com.vaadin.flow.template.angular.TemplateNode)18 ModelMap (com.vaadin.flow.internal.nodefeature.ModelMap)16 ArrayList (java.util.ArrayList)14 StateNodeTest (com.vaadin.flow.internal.StateNodeTest)13 Serializable (java.io.Serializable)13 StateTree (com.vaadin.flow.internal.StateTree)10 ModelList (com.vaadin.flow.internal.nodefeature.ModelList)10 UI (com.vaadin.flow.component.UI)9 TemplateElementStateProviderTest (com.vaadin.flow.dom.TemplateElementStateProviderTest)9 ElementTemplateNode (com.vaadin.flow.template.angular.ElementTemplateNode)9 Bean (com.vaadin.flow.templatemodel.Bean)9 ChildElementConsumer (com.vaadin.flow.dom.ChildElementConsumer)8 AttachExistingElementFeature (com.vaadin.flow.internal.nodefeature.AttachExistingElementFeature)8 ElementData (com.vaadin.flow.internal.nodefeature.ElementData)8 TemplateOverridesMap (com.vaadin.flow.internal.nodefeature.TemplateOverridesMap)6