Search in sources :

Example 11 with Bean

use of com.vaadin.flow.templatemodel.Bean in project flow by vaadin.

the class TemplateModelTest method setBeanExcludeSubBeanProperties.

@Test
public void setBeanExcludeSubBeanProperties() {
    TemplateWithExcludeForSubBean template = new TemplateWithExcludeForSubBean();
    BeanContainingBeans beanContainer = new BeanContainingBeans();
    beanContainer.setBean1(new Bean(1));
    beanContainer.setBean2(new Bean(2));
    template.getModel().setBeanContainingBeans(beanContainer);
    Assert.assertNotNull(template.getModel().getBeanContainingBeans().getBean1());
    Assert.assertTrue(getModelMap(template, "beanContainingBeans.bean1").hasValue("booleanValue"));
    // bean1.booleanObject is excluded
    Assert.assertFalse(getModelMap(template, "beanContainingBeans.bean1").hasValue("booleanObject"));
}
Also used : BeanContainingBeans(com.vaadin.flow.templatemodel.BeanContainingBeans) Bean(com.vaadin.flow.templatemodel.Bean) Test(org.junit.Test)

Example 12 with Bean

use of com.vaadin.flow.templatemodel.Bean in project flow by vaadin.

the class BeanModelTypeTest method importBean_withTypeFilter.

@Test
public void importBean_withTypeFilter() {
    BeanModelType<Bean> beanType = new BeanModelType<>(Bean.class, new PropertyFilter(name -> "intValue".equals(name)));
    ModelMap model = ModelMap.get(new StateNode(ModelMap.class));
    Bean bean = new Bean(3);
    beanType.importProperties(model, bean, PropertyFilter.ACCEPT_ALL);
    Assert.assertEquals(1, model.getKeys().count());
    Assert.assertEquals(Integer.valueOf(3), model.getValue("intValue"));
}
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 13 with Bean

use of com.vaadin.flow.templatemodel.Bean in project flow by vaadin.

the class BeanModelTypeTest method importBean_differentBean.

@Test
public void importBean_differentBean() {
    BeanModelType<Bean> beanType = new BeanModelType<>(Bean.class, PropertyFilter.ACCEPT_ALL);
    ModelMap model = ModelMap.get(new StateNode(ModelMap.class));
    DifferentBean bean = new DifferentBean(3);
    // Ignore intValue which has an incompatible type
    beanType.importProperties(model, bean, new PropertyFilter(name -> !"intValue".equals(name)));
    Assert.assertEquals(1, model.getKeys().count());
    Assert.assertEquals("3", model.getValue("string"));
    Assert.assertFalse(model.hasValue("date"));
}
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 14 with Bean

use of com.vaadin.flow.templatemodel.Bean in project flow by vaadin.

the class BeanModelTypeTest method applicationToModel.

@Test
public void applicationToModel() {
    BeanModelType<Bean> beanType = new BeanModelType<>(Bean.class, PropertyFilter.ACCEPT_ALL);
    Bean bean = new Bean(3);
    StateNode applicationToModel = beanType.applicationToModel(bean, PropertyFilter.ACCEPT_ALL);
    ModelMap model = ModelMap.get(applicationToModel);
    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 15 with Bean

use of com.vaadin.flow.templatemodel.Bean in project flow by vaadin.

the class TemplateModelTest method setBeanExcludeSubBeanProperties_getterThrows.

@Test(expected = InvalidTemplateModelException.class)
public void setBeanExcludeSubBeanProperties_getterThrows() {
    TemplateWithExcludeForSubBean template = new TemplateWithExcludeForSubBean();
    BeanContainingBeans beanContainer = new BeanContainingBeans();
    beanContainer.setBean2(new Bean(2));
    template.getModel().setBeanContainingBeans(beanContainer);
    template.getModel().getBeanContainingBeans().getBean2();
}
Also used : BeanContainingBeans(com.vaadin.flow.templatemodel.BeanContainingBeans) Bean(com.vaadin.flow.templatemodel.Bean) Test(org.junit.Test)

Aggregations

Bean (com.vaadin.flow.templatemodel.Bean)22 Test (org.junit.Test)22 ModelMap (com.vaadin.flow.internal.nodefeature.ModelMap)18 StateNode (com.vaadin.flow.internal.StateNode)10 BeanContainingBeans (com.vaadin.flow.templatemodel.BeanContainingBeans)6 ArrayList (java.util.ArrayList)5 Collectors (java.util.stream.Collectors)5 Assert (org.junit.Assert)5 ModelList (com.vaadin.flow.internal.nodefeature.ModelList)4 PropertyFilter (com.vaadin.flow.templatemodel.PropertyFilter)4 Arrays (java.util.Arrays)4 Date (java.util.Date)4 HashSet (java.util.HashSet)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 ReflectTools (com.vaadin.flow.internal.ReflectTools)1 NodeChange (com.vaadin.flow.internal.change.NodeChange)1 AngularTemplate (com.vaadin.flow.template.angular.AngularTemplate)1 InlineTemplate (com.vaadin.flow.template.angular.InlineTemplate)1 TemplateModel (com.vaadin.flow.template.angular.model.TemplateModel)1 TemplateModelTypeParser (com.vaadin.flow.template.angular.model.TemplateModelTypeParser)1