Search in sources :

Example 26 with ElementPropertyMap

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

the class BeanModelTypeTest method applicationToModel_filtered.

@Test
public void applicationToModel_filtered() {
    BeanModelType<Bean> beanType = new BeanModelType<>(Bean.class, new PropertyFilter(name -> !name.equals("intValue")), false);
    Bean bean = new Bean(3);
    StateNode applicationToModel = beanType.applicationToModel(bean, new PropertyFilter(name -> name.equals("string") || name.equals("intValue")));
    ElementPropertyMap model = ElementPropertyMap.getModel(applicationToModel);
    Assert.assertEquals(Arrays.asList("string"), model.getPropertyNames().collect(Collectors.toList()));
    Assert.assertEquals("3", model.getProperty("string"));
}
Also used : HashSet(java.util.HashSet) ElementPropertyMap(com.vaadin.flow.internal.nodefeature.ElementPropertyMap) Arrays(java.util.Arrays) List(java.util.List) StateNode(com.vaadin.flow.internal.StateNode) Date(java.util.Date) Map(java.util.Map) JsonCodec(com.vaadin.flow.internal.JsonCodec) Json(elemental.json.Json) Test(org.junit.Test) Assert(org.junit.Assert) Collectors(java.util.stream.Collectors) StateNode(com.vaadin.flow.internal.StateNode) ElementPropertyMap(com.vaadin.flow.internal.nodefeature.ElementPropertyMap) Test(org.junit.Test)

Example 27 with ElementPropertyMap

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

the class BeanModelTypeTest method importBean_differentBean.

@Test
public void importBean_differentBean() {
    BeanModelType<Bean> beanType = new BeanModelType<>(Bean.class, PropertyFilter.ACCEPT_ALL, false);
    ElementPropertyMap model = createEmptyModel();
    DifferentBean bean = new DifferentBean(3);
    // Ignore intValue which has an incompatible type
    beanType.importProperties(model, bean, new PropertyFilter(name -> !"intValue".equals(name)));
    Assert.assertEquals(1, model.getPropertyNames().count());
    Assert.assertEquals("3", model.getProperty("string"));
    Assert.assertFalse(model.hasProperty("date"));
}
Also used : HashSet(java.util.HashSet) ElementPropertyMap(com.vaadin.flow.internal.nodefeature.ElementPropertyMap) Arrays(java.util.Arrays) List(java.util.List) StateNode(com.vaadin.flow.internal.StateNode) Date(java.util.Date) Map(java.util.Map) JsonCodec(com.vaadin.flow.internal.JsonCodec) Json(elemental.json.Json) Test(org.junit.Test) Assert(org.junit.Assert) Collectors(java.util.stream.Collectors) ElementPropertyMap(com.vaadin.flow.internal.nodefeature.ElementPropertyMap) Test(org.junit.Test)

Example 28 with ElementPropertyMap

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

the class BeanModelTypeTest method importBean_withTypeFilter.

@Test
public void importBean_withTypeFilter() {
    BeanModelType<Bean> beanType = new BeanModelType<>(Bean.class, new PropertyFilter(name -> "intValue".equals(name)), false);
    ElementPropertyMap model = createEmptyModel();
    Bean bean = new Bean(3);
    beanType.importProperties(model, bean, PropertyFilter.ACCEPT_ALL);
    Assert.assertEquals(1, model.getPropertyNames().count());
    Assert.assertEquals(Integer.valueOf(3), model.getProperty("intValue"));
}
Also used : HashSet(java.util.HashSet) ElementPropertyMap(com.vaadin.flow.internal.nodefeature.ElementPropertyMap) Arrays(java.util.Arrays) List(java.util.List) StateNode(com.vaadin.flow.internal.StateNode) Date(java.util.Date) Map(java.util.Map) JsonCodec(com.vaadin.flow.internal.JsonCodec) Json(elemental.json.Json) Test(org.junit.Test) Assert(org.junit.Assert) Collectors(java.util.stream.Collectors) ElementPropertyMap(com.vaadin.flow.internal.nodefeature.ElementPropertyMap) Test(org.junit.Test)

Example 29 with ElementPropertyMap

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

the class PolymerTemplateTest method stateNodeIsInitialised.

@Test
public void stateNodeIsInitialised() {
    TestPolymerTemplate template = new TestPolymerTemplate();
    StateNode stateNode = template.getStateNode();
    Map<String, Object> expectedState = new HashMap<>();
    expectedState.put("message", null);
    expectedState.put("title", null);
    assertTrue(stateNode.hasFeature(ElementPropertyMap.class));
    ElementPropertyMap modelMap = stateNode.getFeature(ElementPropertyMap.class);
    modelMap.getPropertyNames().forEach(key -> {
        assertTrue(expectedState.containsKey(key));
        assertEquals(expectedState.get(key), modelMap.getProperty(key));
    });
}
Also used : HashMap(java.util.HashMap) StateNode(com.vaadin.flow.internal.StateNode) JsonObject(elemental.json.JsonObject) ElementPropertyMap(com.vaadin.flow.internal.nodefeature.ElementPropertyMap) Test(org.junit.Test)

Example 30 with ElementPropertyMap

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

the class PolymerTemplateTest method updateOneOfModelValues.

@Test
public void updateOneOfModelValues() {
    String message = "message";
    TestPolymerTemplate template = new TestPolymerTemplate();
    ModelClass model = template.getModel();
    StateNode stateNode = template.getStateNode();
    model.setMessage(message);
    assertEquals(message, model.getMessage());
    assertNull(model.getTitle());
    Map<String, Object> expectedState = new HashMap<>();
    expectedState.put("message", message);
    expectedState.put("title", null);
    ElementPropertyMap modelMap = stateNode.getFeature(ElementPropertyMap.class);
    modelMap.getPropertyNames().forEach(key -> {
        assertTrue(expectedState.containsKey(key));
        assertEquals(expectedState.get(key), modelMap.getProperty(key));
    });
}
Also used : HashMap(java.util.HashMap) StateNode(com.vaadin.flow.internal.StateNode) JsonObject(elemental.json.JsonObject) 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