use of com.vaadin.flow.internal.nodefeature.ModelMap in project flow by vaadin.
the class TemplateModelTest method setBeanIncludeProperties.
@Test
public void setBeanIncludeProperties() {
TemplateWithInclude template = new TemplateWithInclude();
template.getModel().setBean(new Bean(123));
ModelMap modelMap = getModelMap(template, "bean");
Set<String> mapKeys = getKeys(modelMap);
Assert.assertTrue("Model should contain included 'doubleValue'", mapKeys.remove("doubleValue"));
Assert.assertTrue("Model should contain included 'booleanObject'", mapKeys.remove("booleanObject"));
Assert.assertTrue("model should be empty but contains: " + mapKeys, mapKeys.isEmpty());
}
use of com.vaadin.flow.internal.nodefeature.ModelMap 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());
ModelMap bean1Map = getModelMap(template, "beanContainingBeans.bean1");
Set<String> bean1Keys = getKeys(bean1Map);
Assert.assertTrue(bean1Keys.contains("booleanObject"));
Assert.assertEquals(1, bean1Keys.size());
}
use of com.vaadin.flow.internal.nodefeature.ModelMap in project flow by vaadin.
the class TemplateModelTest method testBeanInModel.
@Test
public void testBeanInModel() {
BeanModelTemplate template = new BeanModelTemplate();
BeanModel model = template.getModel();
AtomicInteger beanTriggered = new AtomicInteger();
Bean bean = new BeanImpl(beanTriggered);
bean.setString("foobar");
StateNode stateNode = (StateNode) template.getElement().getNode().getFeature(ModelMap.class).getValue("bean");
Assert.assertNull(stateNode);
Assert.assertEquals(0, beanTriggered.get());
model.setBean(bean);
stateNode = (StateNode) template.getElement().getNode().getFeature(ModelMap.class).getValue("bean");
// enough to verify that TemplateModelBeanUtil.importBeanIntoModel is
// triggered, since TemplatemodelBeanUtilTests covers the bean import
Assert.assertNotNull(stateNode);
Assert.assertEquals(1, beanTriggered.get());
ModelMap modelMap = ModelMap.get(stateNode);
Assert.assertNotNull(modelMap);
Assert.assertEquals("foobar", modelMap.getValue("string"));
}
use of com.vaadin.flow.internal.nodefeature.ModelMap in project flow by vaadin.
the class TemplateModelTest method includeExcludeWhenUsingSubclass.
@Test
public void includeExcludeWhenUsingSubclass() {
TemplateWithExcludeAndIncludeSubclass template = new TemplateWithExcludeAndIncludeSubclass();
template.getModel().setBean(new Bean(123));
ModelMap modelMap = getModelMap(template, "bean");
Assert.assertTrue(modelMap.hasValue("booleanObject"));
Assert.assertEquals(1, modelMap.getKeys().count());
}
use of com.vaadin.flow.internal.nodefeature.ModelMap 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());
}
Aggregations