use of com.vaadin.flow.templatemodel.Bean in project flow by vaadin.
the class TemplateModelTest method setBeanExcludeProperties.
@Test
public void setBeanExcludeProperties() {
TemplateWithExclude template = new TemplateWithExclude();
template.getModel().setBean(new Bean(123));
ModelMap 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)) {
Assert.assertTrue("Model should contain the property '" + propertyName + "'", mapKeys.remove(propertyName));
}
});
Assert.assertTrue("model should be empty but contains: " + mapKeys, mapKeys.isEmpty());
}
use of com.vaadin.flow.templatemodel.Bean in project flow by vaadin.
the class TemplateModelTest method setListWithExclude.
@Test
public void setListWithExclude() {
TemplateWithExcludeOnList template = new TemplateWithExcludeOnList();
List<Bean> beans = new ArrayList<>();
beans.add(new Bean(1));
beans.add(new Bean(2));
template.getModel().setBeans(beans);
ModelList modelList = getModelList(template, "beans");
ModelMap bean1 = ModelMap.get(modelList.get(0));
ModelMap bean2 = ModelMap.get(modelList.get(1));
Set<String> bean1InMap = getKeys(bean1);
Set<String> bean2InMap = getKeys(bean2);
Assert.assertFalse("Bean1 in model should not have an 'intValue' property", bean1InMap.contains("intValue"));
Assert.assertFalse("Bean2 in model should not have an 'intValue' property", bean2InMap.contains("intValue"));
Assert.assertEquals("All other properties should have been included", 6, bean1InMap.size());
Assert.assertEquals("All other properties should have been included", 6, bean2InMap.size());
}
Aggregations