use of com.vaadin.flow.internal.nodefeature.ModelList in project flow by vaadin.
the class TemplateModelTest method setListWithInclude.
@Test
public void setListWithInclude() {
TemplateWithIncludeOnList template = new TemplateWithIncludeOnList();
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));
Set<String> propertiesInMap = bean1.getKeys().collect(Collectors.toSet());
Assert.assertTrue("Bean in model should have an 'intValue' property", propertiesInMap.remove("intValue"));
Assert.assertEquals("All other properties should have been filtered out", 0, propertiesInMap.size());
}
use of com.vaadin.flow.internal.nodefeature.ModelList 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());
}
use of com.vaadin.flow.internal.nodefeature.ModelList 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());
ElementPropertyMap container1Map = ElementPropertyMap.getModel(modelList.get(0));
ElementPropertyMap container2Map = ElementPropertyMap.getModel(modelList.get(1));
Set<String> bean1bean2 = new HashSet<>();
bean1bean2.add("bean1");
bean1bean2.add("bean2");
Assert.assertEquals(bean1bean2, container1Map.getPropertyNames().collect(Collectors.toSet()));
Assert.assertEquals(bean1bean2, container2Map.getPropertyNames().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());
}
use of com.vaadin.flow.internal.nodefeature.ModelList in project flow by vaadin.
the class ModelMapTest method resolveAndCreateSubSubChildList.
@Test
public void resolveAndCreateSubSubChildList() {
ModelList child = rootMap.resolveModelList("grand.parent.child");
ModelMap parent = getParentMapAndAssertMapping(child, "child");
ModelMap grand = getParentMapAndAssertMapping(parent, "parent");
ModelMap resolvedRoot = getParentMapAndAssertMapping(grand, "grand");
Assert.assertEquals(rootMap, resolvedRoot);
}
use of com.vaadin.flow.internal.nodefeature.ModelList in project flow by vaadin.
the class MapSyncRpcHandlerTest method syncJSON_jsonIsForStateNodeInList_propertySetToStateNodeCopy.
@Test
public void syncJSON_jsonIsForStateNodeInList_propertySetToStateNodeCopy() throws Exception {
// Let's use element's ElementPropertyMap for testing.
TestComponent component = new TestComponent();
Element element = component.getElement();
UI ui = new UI();
ui.add(component);
StateNode node = element.getNode();
// Set model value directly via ElementPropertyMap
ElementPropertyMap propertyMap = node.getFeature(ElementPropertyMap.class);
propertyMap.setUpdateFromClientFilter(name -> true);
ModelList modelList = propertyMap.resolveModelList("foo");
// fake StateNode has been created for the model
StateNode item = new StateNode(ElementPropertyMap.class);
modelList.add(item);
item.getFeature(ElementPropertyMap.class).setProperty("bar", "baz");
// Use the model node id for JSON object which represents a value to
// update
JsonObject json = Json.createObject();
json.put("nodeId", item.getId());
// send sync request
sendSynchronizePropertyEvent(element, ui, TEST_PROPERTY, json);
// Now the model node should be copied and available as the
// TEST_PROPERTY value
Serializable testPropertyValue = propertyMap.getProperty(TEST_PROPERTY);
Assert.assertTrue(testPropertyValue instanceof StateNode);
StateNode newNode = (StateNode) testPropertyValue;
Assert.assertNotEquals(item.getId(), newNode.getId());
Assert.assertEquals("baz", newNode.getFeature(ElementPropertyMap.class).getProperty("bar"));
}
Aggregations