Search in sources :

Example 1 with PropertyFilter

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

the class BeanModelTypeTest method applicationToModel_filtered.

@Test
public void applicationToModel_filtered() {
    BeanModelType<Bean> beanType = new BeanModelType<>(Bean.class, new PropertyFilter(name -> !name.equals("intValue")));
    Bean bean = new Bean(3);
    StateNode applicationToModel = beanType.applicationToModel(bean, new PropertyFilter(name -> name.equals("string") || name.equals("intValue")));
    ModelMap model = ModelMap.get(applicationToModel);
    Assert.assertEquals(Arrays.asList("string"), model.getKeys().collect(Collectors.toList()));
    Assert.assertEquals("3", model.getValue("string"));
}
Also used : PropertyFilter(com.vaadin.flow.templatemodel.PropertyFilter) Arrays(java.util.Arrays) StateNode(com.vaadin.flow.internal.StateNode) Date(java.util.Date) Test(org.junit.Test) Bean(com.vaadin.flow.templatemodel.Bean) Assert(org.junit.Assert) Collectors(java.util.stream.Collectors) ModelMap(com.vaadin.flow.internal.nodefeature.ModelMap) ModelMap(com.vaadin.flow.internal.nodefeature.ModelMap) StateNode(com.vaadin.flow.internal.StateNode) PropertyFilter(com.vaadin.flow.templatemodel.PropertyFilter) Bean(com.vaadin.flow.templatemodel.Bean) Test(org.junit.Test)

Example 2 with PropertyFilter

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

the class BeanModelTypeTest method importBean_withImportFilter.

@Test
public void importBean_withImportFilter() {
    BeanModelType<Bean> beanType = new BeanModelType<>(Bean.class, PropertyFilter.ACCEPT_ALL);
    ModelMap model = ModelMap.get(new StateNode(ModelMap.class));
    Bean bean = new Bean(3);
    beanType.importProperties(model, bean, new PropertyFilter(name -> "intObject".equals(name)));
    Assert.assertEquals(1, model.getKeys().count());
    Assert.assertEquals(Integer.valueOf(3), model.getValue("intObject"));
}
Also used : PropertyFilter(com.vaadin.flow.templatemodel.PropertyFilter) Arrays(java.util.Arrays) StateNode(com.vaadin.flow.internal.StateNode) Date(java.util.Date) Test(org.junit.Test) Bean(com.vaadin.flow.templatemodel.Bean) Assert(org.junit.Assert) Collectors(java.util.stream.Collectors) ModelMap(com.vaadin.flow.internal.nodefeature.ModelMap) ModelMap(com.vaadin.flow.internal.nodefeature.ModelMap) StateNode(com.vaadin.flow.internal.StateNode) PropertyFilter(com.vaadin.flow.templatemodel.PropertyFilter) Bean(com.vaadin.flow.templatemodel.Bean) Test(org.junit.Test)

Example 3 with PropertyFilter

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

the class PropertyFilterTest method simpleFilter.

@Test
public void simpleFilter() {
    PropertyFilter filter = new PropertyFilter("accept"::equals);
    Assert.assertTrue(filter.test("accept"));
    Assert.assertFalse(filter.test("reject"));
}
Also used : PropertyFilter(com.vaadin.flow.templatemodel.PropertyFilter) Test(org.junit.Test)

Example 4 with PropertyFilter

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

the class BeanModelTypeTest method importBean_withTypeFilter.

@Test
public void importBean_withTypeFilter() {
    BeanModelType<Bean> beanType = new BeanModelType<>(Bean.class, new PropertyFilter(name -> "intValue".equals(name)));
    ModelMap model = ModelMap.get(new StateNode(ModelMap.class));
    Bean bean = new Bean(3);
    beanType.importProperties(model, bean, PropertyFilter.ACCEPT_ALL);
    Assert.assertEquals(1, model.getKeys().count());
    Assert.assertEquals(Integer.valueOf(3), model.getValue("intValue"));
}
Also used : PropertyFilter(com.vaadin.flow.templatemodel.PropertyFilter) Arrays(java.util.Arrays) StateNode(com.vaadin.flow.internal.StateNode) Date(java.util.Date) Test(org.junit.Test) Bean(com.vaadin.flow.templatemodel.Bean) Assert(org.junit.Assert) Collectors(java.util.stream.Collectors) ModelMap(com.vaadin.flow.internal.nodefeature.ModelMap) ModelMap(com.vaadin.flow.internal.nodefeature.ModelMap) StateNode(com.vaadin.flow.internal.StateNode) PropertyFilter(com.vaadin.flow.templatemodel.PropertyFilter) Bean(com.vaadin.flow.templatemodel.Bean) Test(org.junit.Test)

Example 5 with PropertyFilter

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

the class BeanModelTypeTest method importBean_differentBean.

@Test
public void importBean_differentBean() {
    BeanModelType<Bean> beanType = new BeanModelType<>(Bean.class, PropertyFilter.ACCEPT_ALL);
    ModelMap model = ModelMap.get(new StateNode(ModelMap.class));
    DifferentBean bean = new DifferentBean(3);
    // Ignore intValue which has an incompatible type
    beanType.importProperties(model, bean, new PropertyFilter(name -> !"intValue".equals(name)));
    Assert.assertEquals(1, model.getKeys().count());
    Assert.assertEquals("3", model.getValue("string"));
    Assert.assertFalse(model.hasValue("date"));
}
Also used : PropertyFilter(com.vaadin.flow.templatemodel.PropertyFilter) Arrays(java.util.Arrays) StateNode(com.vaadin.flow.internal.StateNode) Date(java.util.Date) Test(org.junit.Test) Bean(com.vaadin.flow.templatemodel.Bean) Assert(org.junit.Assert) Collectors(java.util.stream.Collectors) ModelMap(com.vaadin.flow.internal.nodefeature.ModelMap) ModelMap(com.vaadin.flow.internal.nodefeature.ModelMap) StateNode(com.vaadin.flow.internal.StateNode) PropertyFilter(com.vaadin.flow.templatemodel.PropertyFilter) Bean(com.vaadin.flow.templatemodel.Bean) Test(org.junit.Test)

Aggregations

PropertyFilter (com.vaadin.flow.templatemodel.PropertyFilter)7 Test (org.junit.Test)6 StateNode (com.vaadin.flow.internal.StateNode)5 ModelMap (com.vaadin.flow.internal.nodefeature.ModelMap)5 Bean (com.vaadin.flow.templatemodel.Bean)4 Arrays (java.util.Arrays)4 Date (java.util.Date)4 Collectors (java.util.stream.Collectors)4 Assert (org.junit.Assert)4 TemplateElementStateProvider (com.vaadin.flow.dom.impl.TemplateElementStateProvider)1 ReflectTools (com.vaadin.flow.internal.ReflectTools)1 BasicModelType (com.vaadin.flow.templatemodel.BasicModelType)1 ComplexModelType (com.vaadin.flow.templatemodel.ComplexModelType)1 InvalidTemplateModelException (com.vaadin.flow.templatemodel.InvalidTemplateModelException)1 ModelType (com.vaadin.flow.templatemodel.ModelType)1 TemplateModelUtil (com.vaadin.flow.templatemodel.TemplateModelUtil)1 Json (elemental.json.Json)1 JsonObject (elemental.json.JsonObject)1 JsonValue (elemental.json.JsonValue)1 Serializable (java.io.Serializable)1