Search in sources :

Example 36 with ElementPropertyMap

use of com.vaadin.flow.internal.nodefeature.ElementPropertyMap 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());
    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 37 with ElementPropertyMap

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

the class TemplateModelTest method setModelPropertyAndVerifyGetter.

private void setModelPropertyAndVerifyGetter(PolymerTemplate<?> template, Supplier<Object> getter, String beanPath, String property, Serializable expected) {
    ElementPropertyMap feature = getModelMap(template, beanPath);
    feature.setProperty(property, expected);
    Assert.assertEquals(expected, getter.get());
}
Also used : ElementPropertyMap(com.vaadin.flow.internal.nodefeature.ElementPropertyMap)

Example 38 with ElementPropertyMap

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

the class TemplateModelTest method includeExcludeWhenUsingSubclass.

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

Example 39 with ElementPropertyMap

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

the class TemplateModelTest method verifyModel.

private void verifyModel(PolymerTemplate<?> template, String beanPath, String property, Serializable expected) {
    ElementPropertyMap feature = getModelMap(template, beanPath);
    Assert.assertNotNull(feature);
    Assert.assertEquals(expected, feature.getProperty(property));
}
Also used : ElementPropertyMap(com.vaadin.flow.internal.nodefeature.ElementPropertyMap)

Example 40 with ElementPropertyMap

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

the class AbstractTemplate method removeSimpleProperties.

private List<String> removeSimpleProperties() {
    ElementPropertyMap map = getStateNode().getFeature(ElementPropertyMap.class);
    List<String> props = map.getPropertyNames().filter(name -> !(map.getProperty(name) instanceof StateNode)).collect(Collectors.toList());
    props.forEach(map::removeProperty);
    return props;
}
Also used : BeanModelType(com.vaadin.flow.templatemodel.BeanModelType) ListModelType(com.vaadin.flow.templatemodel.ListModelType) GenericTypeReflector(com.googlecode.gentyref.GenericTypeReflector) StateNode(com.vaadin.flow.internal.StateNode) Component(com.vaadin.flow.component.Component) DeprecatedPolymerTemplate(com.vaadin.flow.component.template.internal.DeprecatedPolymerTemplate) TemplateModel(com.vaadin.flow.templatemodel.TemplateModel) TypeVariable(java.lang.reflect.TypeVariable) Json(elemental.json.Json) Set(java.util.Set) JsonArray(elemental.json.JsonArray) ModelDescriptor(com.vaadin.flow.templatemodel.ModelDescriptor) Collectors(java.util.stream.Collectors) TemplateModelProxyHandler(com.vaadin.flow.templatemodel.TemplateModelProxyHandler) HashSet(java.util.HashSet) ElementPropertyMap(com.vaadin.flow.internal.nodefeature.ElementPropertyMap) List(java.util.List) ModelType(com.vaadin.flow.templatemodel.ModelType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) Map(java.util.Map) Entry(java.util.Map.Entry) Collections(java.util.Collections) StateNode(com.vaadin.flow.internal.StateNode) ElementPropertyMap(com.vaadin.flow.internal.nodefeature.ElementPropertyMap)

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