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"));
}
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"));
}
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"));
}
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));
});
}
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));
});
}
Aggregations