use of com.vaadin.flow.internal.StateNode in project flow by vaadin.
the class ElementPropertyMapTest method deferredUpdateFromClient_listItem_noFilter_throws.
@Test(expected = PropertyChangeDeniedException.class)
public void deferredUpdateFromClient_listItem_noFilter_throws() throws PropertyChangeDeniedException {
ElementPropertyMap map = createSimplePropertyMap();
ModelList list = map.resolveModelList("foo");
StateNode child = new StateNode(ElementPropertyMap.class);
list.add(child);
ElementPropertyMap childModel = ElementPropertyMap.getModel(child);
childModel.deferredUpdateFromClient("bar", "a");
}
use of com.vaadin.flow.internal.StateNode in project flow by vaadin.
the class ElementPropertyMapTest method childPropertyUpdateFilter_setFilterAfterChild.
@Test
public void childPropertyUpdateFilter_setFilterAfterChild() {
ElementPropertyMap map = createSimplePropertyMap();
StateNode child = new StateNode(ElementPropertyMap.class);
ElementPropertyMap childModel = ElementPropertyMap.getModel(child);
map.put("foo", child);
map.setUpdateFromClientFilter("foo.bar"::equals);
Assert.assertTrue(childModel.mayUpdateFromClient("bar", "a"));
Assert.assertFalse(childModel.mayUpdateFromClient("baz", "a"));
}
use of com.vaadin.flow.internal.StateNode in project flow by vaadin.
the class ElementPropertyMapTest method listenerIsNotified.
private void listenerIsNotified(boolean clientEvent) {
ElementPropertyMap map = createSimplePropertyMap();
StateNode node = map.getNode();
AtomicReference<PropertyChangeEvent> event = new AtomicReference<>();
PropertyChangeListener listener = ev -> {
Assert.assertNull(event.get());
event.set(ev);
};
map.addPropertyChangeListener("foo", listener);
map.setProperty("foo", "bar", !clientEvent);
Assert.assertNull(event.get().getOldValue());
Assert.assertEquals("bar", event.get().getValue());
Assert.assertEquals("foo", event.get().getPropertyName());
Assert.assertEquals(Element.get(node), event.get().getSource());
Assert.assertEquals(clientEvent, event.get().isUserOriginated());
// listener is not called. Otherwise its assertion fails.
map.setProperty("bar", "foo");
}
use of com.vaadin.flow.internal.StateNode in project flow by vaadin.
the class ListChangeTest method testBasicJson.
@Test
public void testBasicJson() {
StateNode child1 = StateNodeTest.createEmptyNode("child1");
StateNode child2 = StateNodeTest.createEmptyNode("child2");
ListAddChange<StateNode> change = new ListAddChange<>(feature, true, 0, Arrays.asList(child1, child2));
JsonObject json = change.toJson(null);
Assert.assertEquals(change.getNode().getId(), (int) json.getNumber(JsonConstants.CHANGE_NODE));
Assert.assertEquals(NodeFeatureRegistry.getId(feature.getClass()), (int) json.getNumber(JsonConstants.CHANGE_FEATURE));
Assert.assertEquals(JsonConstants.CHANGE_TYPE_SPLICE, json.getString(JsonConstants.CHANGE_TYPE));
Assert.assertEquals(0, (int) json.getNumber(JsonConstants.CHANGE_SPLICE_INDEX));
JsonArray addNodes = json.getArray(JsonConstants.CHANGE_SPLICE_ADD_NODES);
Assert.assertEquals(2, addNodes.length());
Assert.assertEquals(child1.getId(), (int) addNodes.getNumber(0));
Assert.assertEquals(child2.getId(), (int) addNodes.getNumber(1));
}
use of com.vaadin.flow.internal.StateNode in project flow by vaadin.
the class ElementPropertyMapTest method resolveModelList_modelListStateNodeHasReportedFeature.
@Test
public void resolveModelList_modelListStateNodeHasReportedFeature() {
ElementPropertyMap map = createSimplePropertyMap();
map.resolveModelList("foo");
StateNode stateNode = (StateNode) map.get("foo");
Assert.assertTrue(stateNode.isReportedFeature(ModelList.class));
}
Aggregations