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