Search in sources :

Example 1 with BeanContainingBeans

use of com.vaadin.flow.templatemodel.BeanContainingBeans in project flow by vaadin.

the class TemplateModelTest method setBeanIncludeSubBeanProperties_getterThrows.

@Test(expected = InvalidTemplateModelException.class)
public void setBeanIncludeSubBeanProperties_getterThrows() {
    TemplateWithIncludeForSubBean template = new TemplateWithIncludeForSubBean();
    BeanContainingBeans beanContainer = new BeanContainingBeans();
    beanContainer.setBean2(new Bean(2));
    template.getModel().setBeanContainingBeans(beanContainer);
    template.getModel().getBeanContainingBeans().getBean2();
}
Also used : BeanContainingBeans(com.vaadin.flow.templatemodel.BeanContainingBeans) Bean(com.vaadin.flow.templatemodel.Bean) Test(org.junit.Test)

Example 2 with BeanContainingBeans

use of com.vaadin.flow.templatemodel.BeanContainingBeans in project flow by vaadin.

the class TemplateModelTest method setListWithSubBeanInclude.

@Test
public void setListWithSubBeanInclude() {
    TemplateWithIncludeOnListSubBean template = new TemplateWithIncludeOnListSubBean();
    List<BeanContainingBeans> beanContainingBeans = new ArrayList<>();
    beanContainingBeans.add(new BeanContainingBeans(new Bean(11), new Bean(12)));
    beanContainingBeans.add(new BeanContainingBeans(null, new Bean(22)));
    template.getModel().setBeanContainingBeans(beanContainingBeans);
    ModelList modelList = getModelList(template, "beanContainingBeans");
    Assert.assertEquals(2, modelList.size());
    ModelMap container1Map = ModelMap.get(modelList.get(0));
    ModelMap container2Map = ModelMap.get(modelList.get(1));
    Set<String> bean1bean2 = new HashSet<>();
    bean1bean2.add("bean1");
    bean1bean2.add("bean2");
    Assert.assertEquals(bean1bean2, container1Map.getKeys().collect(Collectors.toSet()));
    Assert.assertEquals(bean1bean2, container2Map.getKeys().collect(Collectors.toSet()));
    Set<String> container1Bean1Properties = getKeys(container1Map.resolveModelMap("bean1"));
    Assert.assertTrue(container1Bean1Properties.remove("intValue"));
    Assert.assertEquals(0, container1Bean1Properties.size());
    Set<String> container1Bean2Properties = getKeys(container1Map.resolveModelMap("bean2"));
    Assert.assertTrue(container1Bean2Properties.remove("booleanValue"));
    Assert.assertEquals(0, container1Bean2Properties.size());
    Set<String> container2Bean1Properties = getKeys(container2Map.resolveModelMap("bean1"));
    // Null value in the initial bean implies not imported or created
    Assert.assertEquals(0, container2Bean1Properties.size());
    Set<String> container2Bean2Properties = getKeys(container2Map.resolveModelMap("bean2"));
    Assert.assertTrue(container2Bean2Properties.remove("booleanValue"));
    Assert.assertEquals(0, container2Bean2Properties.size());
}
Also used : BeanContainingBeans(com.vaadin.flow.templatemodel.BeanContainingBeans) ModelList(com.vaadin.flow.internal.nodefeature.ModelList) ModelMap(com.vaadin.flow.internal.nodefeature.ModelMap) ArrayList(java.util.ArrayList) Bean(com.vaadin.flow.templatemodel.Bean) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with BeanContainingBeans

use of com.vaadin.flow.templatemodel.BeanContainingBeans in project flow by vaadin.

the class TemplateModelTest method setBeanExcludeSubBeanProperties.

@Test
public void setBeanExcludeSubBeanProperties() {
    TemplateWithExcludeForSubBean template = new TemplateWithExcludeForSubBean();
    BeanContainingBeans beanContainer = new BeanContainingBeans();
    beanContainer.setBean1(new Bean(1));
    beanContainer.setBean2(new Bean(2));
    template.getModel().setBeanContainingBeans(beanContainer);
    Assert.assertNotNull(template.getModel().getBeanContainingBeans().getBean1());
    Assert.assertTrue(getModelMap(template, "beanContainingBeans.bean1").hasValue("booleanValue"));
    // bean1.booleanObject is excluded
    Assert.assertFalse(getModelMap(template, "beanContainingBeans.bean1").hasValue("booleanObject"));
}
Also used : BeanContainingBeans(com.vaadin.flow.templatemodel.BeanContainingBeans) Bean(com.vaadin.flow.templatemodel.Bean) Test(org.junit.Test)

Example 4 with BeanContainingBeans

use of com.vaadin.flow.templatemodel.BeanContainingBeans in project flow by vaadin.

the class TemplateModelTest method setBeanExcludeSubBeanProperties_getterThrows.

@Test(expected = InvalidTemplateModelException.class)
public void setBeanExcludeSubBeanProperties_getterThrows() {
    TemplateWithExcludeForSubBean template = new TemplateWithExcludeForSubBean();
    BeanContainingBeans beanContainer = new BeanContainingBeans();
    beanContainer.setBean2(new Bean(2));
    template.getModel().setBeanContainingBeans(beanContainer);
    template.getModel().getBeanContainingBeans().getBean2();
}
Also used : BeanContainingBeans(com.vaadin.flow.templatemodel.BeanContainingBeans) Bean(com.vaadin.flow.templatemodel.Bean) Test(org.junit.Test)

Example 5 with BeanContainingBeans

use of com.vaadin.flow.templatemodel.BeanContainingBeans 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());
}
Also used : BeanContainingBeans(com.vaadin.flow.templatemodel.BeanContainingBeans) ModelMap(com.vaadin.flow.internal.nodefeature.ModelMap) Bean(com.vaadin.flow.templatemodel.Bean) Test(org.junit.Test)

Aggregations

Bean (com.vaadin.flow.templatemodel.Bean)5 BeanContainingBeans (com.vaadin.flow.templatemodel.BeanContainingBeans)5 Test (org.junit.Test)5 ModelMap (com.vaadin.flow.internal.nodefeature.ModelMap)2 ModelList (com.vaadin.flow.internal.nodefeature.ModelList)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1