Search in sources :

Example 21 with Bean

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

the class TemplateModelTest method setBeanExcludeProperties.

@Test
public void setBeanExcludeProperties() {
    TemplateWithExclude template = new TemplateWithExclude();
    template.getModel().setBean(new Bean(123));
    ModelMap modelMap = getModelMap(template, "bean");
    Set<String> mapKeys = getKeys(modelMap);
    Set<String> excluded = new HashSet<>();
    excluded.add("doubleValue");
    excluded.add("booleanObject");
    for (String excludedPropertyName : excluded) {
        Assert.assertFalse("Model should not contain excluded '" + excludedPropertyName + "'", mapKeys.contains(excludedPropertyName));
    }
    ReflectTools.getSetterMethods(Bean.class).map(method -> ReflectTools.getPropertyName(method)).forEach(propertyName -> {
        if (!excluded.contains(propertyName)) {
            Assert.assertTrue("Model should contain the property '" + propertyName + "'", mapKeys.remove(propertyName));
        }
    });
    Assert.assertTrue("model should be empty but contains: " + mapKeys, mapKeys.isEmpty());
}
Also used : Exclude(com.vaadin.flow.templatemodel.Exclude) Bean(com.vaadin.flow.templatemodel.Bean) ModelList(com.vaadin.flow.internal.nodefeature.ModelList) Supplier(java.util.function.Supplier) ModelMap(com.vaadin.flow.internal.nodefeature.ModelMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Include(com.vaadin.flow.templatemodel.Include) StateNode(com.vaadin.flow.internal.StateNode) TemplateModelTypeParser(com.vaadin.flow.template.angular.model.TemplateModelTypeParser) Set(java.util.Set) Matchers(org.hamcrest.Matchers) ReflectTools(com.vaadin.flow.internal.ReflectTools) Test(org.junit.Test) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) InlineTemplate(com.vaadin.flow.template.angular.InlineTemplate) InvalidTemplateModelException(com.vaadin.flow.templatemodel.InvalidTemplateModelException) NodeChange(com.vaadin.flow.internal.change.NodeChange) List(java.util.List) Assert(org.junit.Assert) AngularTemplate(com.vaadin.flow.template.angular.AngularTemplate) TemplateModel(com.vaadin.flow.template.angular.model.TemplateModel) BeanContainingBeans(com.vaadin.flow.templatemodel.BeanContainingBeans) ModelMap(com.vaadin.flow.internal.nodefeature.ModelMap) Bean(com.vaadin.flow.templatemodel.Bean) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 22 with Bean

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

the class TemplateModelTest method setListWithExclude.

@Test
public void setListWithExclude() {
    TemplateWithExcludeOnList template = new TemplateWithExcludeOnList();
    List<Bean> beans = new ArrayList<>();
    beans.add(new Bean(1));
    beans.add(new Bean(2));
    template.getModel().setBeans(beans);
    ModelList modelList = getModelList(template, "beans");
    ModelMap bean1 = ModelMap.get(modelList.get(0));
    ModelMap bean2 = ModelMap.get(modelList.get(1));
    Set<String> bean1InMap = getKeys(bean1);
    Set<String> bean2InMap = getKeys(bean2);
    Assert.assertFalse("Bean1 in model should not have an 'intValue' property", bean1InMap.contains("intValue"));
    Assert.assertFalse("Bean2 in model should not have an 'intValue' property", bean2InMap.contains("intValue"));
    Assert.assertEquals("All other properties should have been included", 6, bean1InMap.size());
    Assert.assertEquals("All other properties should have been included", 6, bean2InMap.size());
}
Also used : ModelList(com.vaadin.flow.internal.nodefeature.ModelList) ModelMap(com.vaadin.flow.internal.nodefeature.ModelMap) 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