Search in sources :

Example 16 with Bean

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

the class TemplateModelTest method setBeanIncludeProperties.

@Test
public void setBeanIncludeProperties() {
    TemplateWithInclude template = new TemplateWithInclude();
    template.getModel().setBean(new Bean(123));
    ModelMap modelMap = getModelMap(template, "bean");
    Set<String> mapKeys = getKeys(modelMap);
    Assert.assertTrue("Model should contain included 'doubleValue'", mapKeys.remove("doubleValue"));
    Assert.assertTrue("Model should contain included 'booleanObject'", mapKeys.remove("booleanObject"));
    Assert.assertTrue("model should be empty but contains: " + mapKeys, mapKeys.isEmpty());
}
Also used : ModelMap(com.vaadin.flow.internal.nodefeature.ModelMap) Bean(com.vaadin.flow.templatemodel.Bean) Test(org.junit.Test)

Example 17 with Bean

use of com.vaadin.flow.templatemodel.Bean 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());
    ModelMap bean1Map = getModelMap(template, "beanContainingBeans.bean1");
    Set<String> bean1Keys = getKeys(bean1Map);
    Assert.assertTrue(bean1Keys.contains("booleanObject"));
    Assert.assertEquals(1, bean1Keys.size());
}
Also used : BeanContainingBeans(com.vaadin.flow.templatemodel.BeanContainingBeans) ModelMap(com.vaadin.flow.internal.nodefeature.ModelMap) Bean(com.vaadin.flow.templatemodel.Bean) Test(org.junit.Test)

Example 18 with Bean

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

the class TemplateModelTest method testBeanInModel.

@Test
public void testBeanInModel() {
    BeanModelTemplate template = new BeanModelTemplate();
    BeanModel model = template.getModel();
    AtomicInteger beanTriggered = new AtomicInteger();
    Bean bean = new BeanImpl(beanTriggered);
    bean.setString("foobar");
    StateNode stateNode = (StateNode) template.getElement().getNode().getFeature(ModelMap.class).getValue("bean");
    Assert.assertNull(stateNode);
    Assert.assertEquals(0, beanTriggered.get());
    model.setBean(bean);
    stateNode = (StateNode) template.getElement().getNode().getFeature(ModelMap.class).getValue("bean");
    // enough to verify that TemplateModelBeanUtil.importBeanIntoModel is
    // triggered, since TemplatemodelBeanUtilTests covers the bean import
    Assert.assertNotNull(stateNode);
    Assert.assertEquals(1, beanTriggered.get());
    ModelMap modelMap = ModelMap.get(stateNode);
    Assert.assertNotNull(modelMap);
    Assert.assertEquals("foobar", modelMap.getValue("string"));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ModelMap(com.vaadin.flow.internal.nodefeature.ModelMap) StateNode(com.vaadin.flow.internal.StateNode) Bean(com.vaadin.flow.templatemodel.Bean) Test(org.junit.Test)

Example 19 with Bean

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

the class TemplateModelTest method includeExcludeWhenUsingSubclass.

@Test
public void includeExcludeWhenUsingSubclass() {
    TemplateWithExcludeAndIncludeSubclass template = new TemplateWithExcludeAndIncludeSubclass();
    template.getModel().setBean(new Bean(123));
    ModelMap modelMap = getModelMap(template, "bean");
    Assert.assertTrue(modelMap.hasValue("booleanObject"));
    Assert.assertEquals(1, modelMap.getKeys().count());
}
Also used : ModelMap(com.vaadin.flow.internal.nodefeature.ModelMap) Bean(com.vaadin.flow.templatemodel.Bean) Test(org.junit.Test)

Example 20 with Bean

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

the class TemplateModelTest method getListFromModel.

@Test
public void getListFromModel() {
    ListBeanModelTemplate template = new ListBeanModelTemplate();
    List<Bean> beans = new ArrayList<>();
    beans.add(new Bean(100));
    beans.add(new Bean(200));
    beans.add(new Bean(300));
    template.getModel().setBeans(beans);
    assertListContentsEquals(template.getModel().getBeans(), new Bean(100), new Bean(200), new Bean(300));
}
Also used : ArrayList(java.util.ArrayList) 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