Search in sources :

Example 11 with ElementPropertyMap

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

the class BeanModelTypeTest method importBean.

@Test
public void importBean() {
    BeanModelType<Bean> beanType = new BeanModelType<>(Bean.class, PropertyFilter.ACCEPT_ALL, false);
    ElementPropertyMap model = createEmptyModel();
    Bean bean = new Bean(3);
    beanType.importProperties(model, bean, PropertyFilter.ACCEPT_ALL);
    assertThreeBean(model);
}
Also used : ElementPropertyMap(com.vaadin.flow.internal.nodefeature.ElementPropertyMap) Test(org.junit.Test)

Example 12 with ElementPropertyMap

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

the class BeanModelTypeTest method applicationToModel.

@Test
public void applicationToModel() {
    BeanModelType<Bean> beanType = new BeanModelType<>(Bean.class, PropertyFilter.ACCEPT_ALL, false);
    Bean bean = new Bean(3);
    StateNode applicationToModel = beanType.applicationToModel(bean, PropertyFilter.ACCEPT_ALL);
    ElementPropertyMap model = ElementPropertyMap.getModel(applicationToModel);
    assertThreeBean(model);
}
Also used : StateNode(com.vaadin.flow.internal.StateNode) ElementPropertyMap(com.vaadin.flow.internal.nodefeature.ElementPropertyMap) Test(org.junit.Test)

Example 13 with ElementPropertyMap

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

the class TemplateModelTest method setBeanExcludeProperties.

@Test
public void setBeanExcludeProperties() {
    TemplateWithExclude template = new TemplateWithExclude();
    template.getModel().setBean(new Bean(123));
    ElementPropertyMap 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)) {
            assertTrue("Model should contain the property '" + propertyName + "'", mapKeys.remove(propertyName));
        }
    });
    assertTrue("model should be empty but contains: " + mapKeys, mapKeys.isEmpty());
}
Also used : CoreMatchers(org.hamcrest.CoreMatchers) TemplateData(com.vaadin.flow.component.polymertemplate.TemplateParser.TemplateData) ModelList(com.vaadin.flow.internal.nodefeature.ModelList) Supplier(java.util.function.Supplier) DeploymentConfiguration(com.vaadin.flow.function.DeploymentConfiguration) NodeList(com.vaadin.flow.internal.nodefeature.NodeList) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Tag(com.vaadin.flow.component.Tag) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExpectedException(org.junit.rules.ExpectedException) StateNode(com.vaadin.flow.internal.StateNode) Assert.assertTrue(org.junit.Assert.assertTrue) 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) PolymerTemplate(com.vaadin.flow.component.polymertemplate.PolymerTemplate) NodeChange(com.vaadin.flow.internal.change.NodeChange) Mockito(org.mockito.Mockito) HasCurrentService(com.vaadin.flow.component.polymertemplate.HasCurrentService) ElementPropertyMap(com.vaadin.flow.internal.nodefeature.ElementPropertyMap) List(java.util.List) Rule(org.junit.Rule) VaadinService(com.vaadin.flow.server.VaadinService) Jsoup(org.jsoup.Jsoup) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) ElementPropertyMap(com.vaadin.flow.internal.nodefeature.ElementPropertyMap) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 14 with ElementPropertyMap

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

the class TemplateModelTest method testSetterSameValue_noUpdates.

@Test
public void testSetterSameValue_noUpdates() {
    BasicTypeModelTemplate template = new BasicTypeModelTemplate();
    BasicTypeModel model = template.getModel();
    // Initial populate properties model changes. Clear them out.
    template.getElement().getNode().clearChanges();
    model.setString("foobar");
    Assert.assertEquals("foobar", model.getString());
    List<NodeChange> changes = new ArrayList<>();
    ElementPropertyMap modelMap = template.getElement().getNode().getFeature(ElementPropertyMap.class);
    modelMap.collectChanges(changes::add);
    Assert.assertEquals(1, changes.size());
    Assert.assertEquals(template.getElement().getNode(), changes.get(0).getNode());
    changes.clear();
    template.getElement().getNode().clearChanges();
    model.setString("foobar");
    Assert.assertEquals("foobar", model.getString());
    modelMap.collectChanges(changes::add);
    Assert.assertEquals(0, changes.size());
}
Also used : NodeChange(com.vaadin.flow.internal.change.NodeChange) ArrayList(java.util.ArrayList) ElementPropertyMap(com.vaadin.flow.internal.nodefeature.ElementPropertyMap) Test(org.junit.Test)

Example 15 with ElementPropertyMap

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

Aggregations

ElementPropertyMap (com.vaadin.flow.internal.nodefeature.ElementPropertyMap)45 Test (org.junit.Test)35 StateNode (com.vaadin.flow.internal.StateNode)21 HashSet (java.util.HashSet)9 Element (com.vaadin.flow.dom.Element)8 List (java.util.List)8 Collectors (java.util.stream.Collectors)8 ModelList (com.vaadin.flow.internal.nodefeature.ModelList)6 Json (elemental.json.Json)6 ArrayList (java.util.ArrayList)6 Map (java.util.Map)6 Assert (org.junit.Assert)6 ElementChildrenList (com.vaadin.flow.internal.nodefeature.ElementChildrenList)5 ElementData (com.vaadin.flow.internal.nodefeature.ElementData)5 JsonObject (elemental.json.JsonObject)5 Serializable (java.io.Serializable)5 Arrays (java.util.Arrays)5 UI (com.vaadin.flow.component.UI)4 JsonCodec (com.vaadin.flow.internal.JsonCodec)4 JsonArray (elemental.json.JsonArray)4