use of com.vaadin.flow.templatemodel.Bean 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.templatemodel.Bean 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.templatemodel.Bean 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.templatemodel.Bean 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.templatemodel.Bean in project flow by vaadin.
the class TemplateModelTest method getListFromModel.
@Test
public void getListFromModel() {
ListBeanModelTemplate template = new ListBeanModelTemplate();
List<Bean> beans = new ArrayList<>();
beans.add(new Bean(100));
beans.add(new Bean(200));
beans.add(new Bean(300));
template.getModel().setBeans(beans);
assertListContentsEquals(template.getModel().getBeans(), new Bean(100), new Bean(200), new Bean(300));
}
Aggregations