use of com.vaadin.flow.internal.nodefeature.ElementPropertyMap in project flow by vaadin.
the class MapSyncRpcHandlerTest method syncJSON_jsonIsNotListItemAndNotPropertyValue_propertySetToJSON.
@Test
public void syncJSON_jsonIsNotListItemAndNotPropertyValue_propertySetToJSON() 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();
TestComponent anotherComonent = new TestComponent();
StateNode anotherNode = anotherComonent.getElement().getNode();
ElementPropertyMap.getModel(node).setUpdateFromClientFilter(name -> true);
// Use the model node id for JSON object which represents a value to
// update
JsonObject json = Json.createObject();
json.put("nodeId", anotherNode.getId());
// send sync request
sendSynchronizePropertyEvent(element, ui, "foo", json);
Serializable testPropertyValue = node.getFeature(ElementPropertyMap.class).getProperty("foo");
Assert.assertNotSame(anotherNode, testPropertyValue);
Assert.assertTrue(testPropertyValue instanceof JsonValue);
}
use of com.vaadin.flow.internal.nodefeature.ElementPropertyMap in project flow by vaadin.
the class PolymerTemplateTest method initModel_onlyExplicitelySetPropertiesAreSet.
@Test
public void initModel_onlyExplicitelySetPropertiesAreSet() {
InitModelTemplate template = new InitModelTemplate();
template.getModel().setMessage("foo");
ElementPropertyMap map = template.getElement().getNode().getFeature(ElementPropertyMap.class);
// message has been explicitly set
Assert.assertTrue(map.hasProperty("message"));
Assert.assertNotNull(map.getProperty("message"));
// "list" is represented by StateNode so it's considered as explicitly
// set
Assert.assertTrue(map.hasProperty("list"));
Assert.assertNotNull(map.getProperty("list"));
// title has not been
Assert.assertFalse(map.hasProperty("title"));
}
use of com.vaadin.flow.internal.nodefeature.ElementPropertyMap in project flow by vaadin.
the class TemplateModelUtil method resolveListAndRun.
/**
* Resolves a list model type and a model list based on a model instance and
* passes those to the provided callback.
*
* @param <R>
* the return type
* @param model
* the model instance for which to resolve a type and a list, not
* <code>null</code>
* @param modelPath
* the model path to resolve, not <code>null</code>
* @param callback
* the callback to run with the resolved list type and model
* list, not <code>null</code>
* @return the value returned by the callback
*/
public static <R> R resolveListAndRun(TemplateModel model, String modelPath, BiFunction<ListModelType<?>, ModelList, R> callback) {
assert model != null;
assert modelPath != null;
assert callback != null;
BeanModelType<?> modelType = TemplateModelProxyHandler.getModelTypeForProxy(model);
ModelType listType = modelType.resolveType(modelPath);
if (listType instanceof ListModelType<?>) {
StateNode stateNode = TemplateModelProxyHandler.getStateNodeForProxy(model);
ElementPropertyMap modelMap = ElementPropertyMap.getModel(stateNode);
ModelList modelList = modelMap.resolveModelList(modelPath);
return callback.apply((ListModelType<?>) listType, modelList);
} else {
throw new IllegalArgumentException(modelPath + " does not resolve to a list");
}
}
use of com.vaadin.flow.internal.nodefeature.ElementPropertyMap in project flow by vaadin.
the class BeanModelTypeTest method importBean_incompatibleBean.
@Test(expected = IllegalArgumentException.class)
public void importBean_incompatibleBean() {
BeanModelType<Bean> beanType = new BeanModelType<>(Bean.class, PropertyFilter.ACCEPT_ALL, false);
ElementPropertyMap model = createEmptyModel();
DifferentBean bean = new DifferentBean(3);
beanType.importProperties(model, bean, PropertyFilter.ACCEPT_ALL);
}
use of com.vaadin.flow.internal.nodefeature.ElementPropertyMap in project flow by vaadin.
the class BeanModelTypeTest method clientValueToApplication.
@Test
public void clientValueToApplication() {
BeanModelType<Bean> beanType = new BeanModelType<>(Bean.class, PropertyFilter.ACCEPT_ALL, false);
ElementPropertyMap model = createEmptyModel();
model.setProperty("doubleValue", JsonCodec.decodeWithoutTypeInfo(Json.create(3)));
model.setProperty("doubleObject", JsonCodec.decodeWithoutTypeInfo(Json.create(3)));
model.setProperty("intValue", JsonCodec.decodeWithoutTypeInfo(Json.create(3)));
model.setProperty("intObject", JsonCodec.decodeWithoutTypeInfo(Json.create(3)));
model.setProperty("booleanValue", JsonCodec.decodeWithoutTypeInfo(Json.create(true)));
model.setProperty("booleanObject", JsonCodec.decodeWithoutTypeInfo(Json.create(true)));
model.setProperty("string", JsonCodec.decodeWithoutTypeInfo(Json.create("3")));
Bean bean = beanType.modelToApplication(model.getNode());
Assert.assertEquals(3.0, bean.getDoubleValue(), 0);
Assert.assertEquals(3.0, bean.getDoubleObject(), 0);
Assert.assertEquals(3, bean.getIntValue());
Assert.assertEquals(3, bean.getIntObject().intValue());
Assert.assertEquals(Boolean.TRUE, bean.getBooleanObject());
Assert.assertTrue(bean.isBooleanValue());
Assert.assertEquals("3", bean.getString());
}
Aggregations