Search in sources :

Example 11 with ModelList

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

the class TemplateModelTest method setListWithInclude.

@Test
public void setListWithInclude() {
    TemplateWithIncludeOnList template = new TemplateWithIncludeOnList();
    List<Bean> beans = new ArrayList<>();
    beans.add(new Bean(1));
    beans.add(new Bean(2));
    template.getModel().setBeans(beans);
    ModelList modelList = getModelList(template, "beans");
    ElementPropertyMap bean1 = ElementPropertyMap.getModel(modelList.get(0));
    Set<String> propertiesInMap = bean1.getPropertyNames().collect(Collectors.toSet());
    Assert.assertTrue("Bean in model should have an 'intValue' property", propertiesInMap.remove("intValue"));
    Assert.assertEquals("All other properties should have been filtered out", 0, propertiesInMap.size());
}
Also used : ModelList(com.vaadin.flow.internal.nodefeature.ModelList) ArrayList(java.util.ArrayList) ElementPropertyMap(com.vaadin.flow.internal.nodefeature.ElementPropertyMap) Test(org.junit.Test)

Example 12 with ModelList

use of com.vaadin.flow.internal.nodefeature.ModelList 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");
    ElementPropertyMap bean1 = ElementPropertyMap.getModel(modelList.get(0));
    ElementPropertyMap bean2 = ElementPropertyMap.getModel(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) ArrayList(java.util.ArrayList) ElementPropertyMap(com.vaadin.flow.internal.nodefeature.ElementPropertyMap) Test(org.junit.Test)

Example 13 with ModelList

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

the class ModelMapTest method resolveAndCreateSubChildList.

@Test
public void resolveAndCreateSubChildList() {
    ModelList child = rootMap.resolveModelList("parent.child");
    ModelMap parent = getParentMapAndAssertMapping(child, "child");
    ModelMap resolvedRoot = getParentMapAndAssertMapping(parent, "parent");
    Assert.assertEquals(rootMap, resolvedRoot);
}
Also used : ModelList(com.vaadin.flow.internal.nodefeature.ModelList) ModelMap(com.vaadin.flow.internal.nodefeature.ModelMap) Test(org.junit.Test)

Example 14 with ModelList

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

the class ModelMapTest method resolveAndCreateImmediateChildList.

@Test
public void resolveAndCreateImmediateChildList() {
    ModelList child = rootMap.resolveModelList("child");
    ModelMap parent = getParentMapAndAssertMapping(child, "child");
    Assert.assertEquals(rootMap, parent);
}
Also used : ModelList(com.vaadin.flow.internal.nodefeature.ModelList) ModelMap(com.vaadin.flow.internal.nodefeature.ModelMap) Test(org.junit.Test)

Aggregations

ModelList (com.vaadin.flow.internal.nodefeature.ModelList)14 Test (org.junit.Test)10 ModelMap (com.vaadin.flow.internal.nodefeature.ModelMap)8 ArrayList (java.util.ArrayList)6 StateNode (com.vaadin.flow.internal.StateNode)5 ElementPropertyMap (com.vaadin.flow.internal.nodefeature.ElementPropertyMap)5 Bean (com.vaadin.flow.templatemodel.Bean)3 HashSet (java.util.HashSet)2 TestComponent (com.vaadin.flow.component.ComponentTest.TestComponent)1 UI (com.vaadin.flow.component.UI)1 Element (com.vaadin.flow.dom.Element)1 BeanContainingBeans (com.vaadin.flow.templatemodel.BeanContainingBeans)1 ModelType (com.vaadin.flow.templatemodel.ModelType)1 JsonObject (elemental.json.JsonObject)1 Serializable (java.io.Serializable)1