Search in sources :

Example 11 with ModelMap

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

the class TemplateModelTest method setBeanIncludeAndExcludeProperties.

@Test
public void setBeanIncludeAndExcludeProperties() {
    TemplateWithExcludeAndInclude template = new TemplateWithExcludeAndInclude();
    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 12 with ModelMap

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

the class TemplateModelTest method setListWithSubBeanInclude.

@Test
public void setListWithSubBeanInclude() {
    TemplateWithIncludeOnListSubBean template = new TemplateWithIncludeOnListSubBean();
    List<BeanContainingBeans> beanContainingBeans = new ArrayList<>();
    beanContainingBeans.add(new BeanContainingBeans(new Bean(11), new Bean(12)));
    beanContainingBeans.add(new BeanContainingBeans(null, new Bean(22)));
    template.getModel().setBeanContainingBeans(beanContainingBeans);
    ModelList modelList = getModelList(template, "beanContainingBeans");
    Assert.assertEquals(2, modelList.size());
    ModelMap container1Map = ModelMap.get(modelList.get(0));
    ModelMap container2Map = ModelMap.get(modelList.get(1));
    Set<String> bean1bean2 = new HashSet<>();
    bean1bean2.add("bean1");
    bean1bean2.add("bean2");
    Assert.assertEquals(bean1bean2, container1Map.getKeys().collect(Collectors.toSet()));
    Assert.assertEquals(bean1bean2, container2Map.getKeys().collect(Collectors.toSet()));
    Set<String> container1Bean1Properties = getKeys(container1Map.resolveModelMap("bean1"));
    Assert.assertTrue(container1Bean1Properties.remove("intValue"));
    Assert.assertEquals(0, container1Bean1Properties.size());
    Set<String> container1Bean2Properties = getKeys(container1Map.resolveModelMap("bean2"));
    Assert.assertTrue(container1Bean2Properties.remove("booleanValue"));
    Assert.assertEquals(0, container1Bean2Properties.size());
    Set<String> container2Bean1Properties = getKeys(container2Map.resolveModelMap("bean1"));
    // Null value in the initial bean implies not imported or created
    Assert.assertEquals(0, container2Bean1Properties.size());
    Set<String> container2Bean2Properties = getKeys(container2Map.resolveModelMap("bean2"));
    Assert.assertTrue(container2Bean2Properties.remove("booleanValue"));
    Assert.assertEquals(0, container2Bean2Properties.size());
}
Also used : BeanContainingBeans(com.vaadin.flow.templatemodel.BeanContainingBeans) ModelList(com.vaadin.flow.internal.nodefeature.ModelList) ModelMap(com.vaadin.flow.internal.nodefeature.ModelMap) ArrayList(java.util.ArrayList) Bean(com.vaadin.flow.templatemodel.Bean) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 13 with ModelMap

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

the class ModelMapTest method resolveAndCreateSubSubChildMap.

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

Example 14 with ModelMap

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

the class ModelMapTest method dotInvalidInKey.

@Test(expected = IllegalArgumentException.class)
public void dotInvalidInKey() {
    ModelMap map = new ModelMap(new StateNode());
    map.setValue("foo.bar", "a");
}
Also used : ModelMap(com.vaadin.flow.internal.nodefeature.ModelMap) StateNode(com.vaadin.flow.internal.StateNode) Test(org.junit.Test)

Example 15 with ModelMap

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

the class ModelMapTest method resolveAndCreateSubChildMap.

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

Aggregations

ModelMap (com.vaadin.flow.internal.nodefeature.ModelMap)41 Test (org.junit.Test)30 StateNode (com.vaadin.flow.internal.StateNode)18 Bean (com.vaadin.flow.templatemodel.Bean)18 ModelList (com.vaadin.flow.internal.nodefeature.ModelList)9 ModelType (com.vaadin.flow.templatemodel.ModelType)5 PropertyFilter (com.vaadin.flow.templatemodel.PropertyFilter)5 ArrayList (java.util.ArrayList)5 Collectors (java.util.stream.Collectors)5 Assert (org.junit.Assert)5 Arrays (java.util.Arrays)4 Date (java.util.Date)4 BeanContainingBeans (com.vaadin.flow.templatemodel.BeanContainingBeans)3 InvalidTemplateModelException (com.vaadin.flow.templatemodel.InvalidTemplateModelException)3 ReflectTools (com.vaadin.flow.internal.ReflectTools)2 NodeChange (com.vaadin.flow.internal.change.NodeChange)2 BasicModelType (com.vaadin.flow.templatemodel.BasicModelType)2 Serializable (java.io.Serializable)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 ClassList (com.vaadin.flow.dom.ClassList)1