Search in sources :

Example 76 with StateNode

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");
}
Also used : StateNode(com.vaadin.flow.internal.StateNode) Test(org.junit.Test)

Example 77 with StateNode

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"));
}
Also used : StateNode(com.vaadin.flow.internal.StateNode) Test(org.junit.Test)

Example 78 with StateNode

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");
}
Also used : CoreMatchers(org.hamcrest.CoreMatchers) StateNode(com.vaadin.flow.internal.StateNode) BasicElementStateProvider(com.vaadin.flow.dom.impl.BasicElementStateProvider) PropertyChangeListener(com.vaadin.flow.dom.PropertyChangeListener) Registration(com.vaadin.flow.shared.Registration) Set(java.util.Set) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) AtomicReference(java.util.concurrent.atomic.AtomicReference) Serializable(java.io.Serializable) HashSet(java.util.HashSet) MatcherAssert(org.hamcrest.MatcherAssert) Element(com.vaadin.flow.dom.Element) PropertyChangeEvent(com.vaadin.flow.dom.PropertyChangeEvent) Assert(org.junit.Assert) DomListenerRegistration(com.vaadin.flow.dom.DomListenerRegistration) PropertyChangeEvent(com.vaadin.flow.dom.PropertyChangeEvent) PropertyChangeListener(com.vaadin.flow.dom.PropertyChangeListener) StateNode(com.vaadin.flow.internal.StateNode) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Example 79 with StateNode

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));
}
Also used : JsonArray(elemental.json.JsonArray) StateNode(com.vaadin.flow.internal.StateNode) JsonObject(elemental.json.JsonObject) AbstractNodeFeatureTest(com.vaadin.flow.internal.nodefeature.AbstractNodeFeatureTest) Test(org.junit.Test) StateNodeTest(com.vaadin.flow.internal.StateNodeTest)

Example 80 with StateNode

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));
}
Also used : StateNode(com.vaadin.flow.internal.StateNode) Test(org.junit.Test)

Aggregations

StateNode (com.vaadin.flow.internal.StateNode)196 Test (org.junit.Test)122 Element (com.vaadin.flow.dom.Element)32 JsonObject (elemental.json.JsonObject)24 ElementPropertyMap (com.vaadin.flow.internal.nodefeature.ElementPropertyMap)22 UI (com.vaadin.flow.component.UI)19 StateTree (com.vaadin.flow.internal.StateTree)18 TemplateNode (com.vaadin.flow.template.angular.TemplateNode)18 ArrayList (java.util.ArrayList)18 StateNodeTest (com.vaadin.flow.internal.StateNodeTest)17 Serializable (java.io.Serializable)17 ModelMap (com.vaadin.flow.internal.nodefeature.ModelMap)16 ModelList (com.vaadin.flow.internal.nodefeature.ModelList)10 TemplateElementStateProviderTest (com.vaadin.flow.dom.TemplateElementStateProviderTest)9 ElementData (com.vaadin.flow.internal.nodefeature.ElementData)9 VirtualChildrenList (com.vaadin.flow.internal.nodefeature.VirtualChildrenList)9 ElementTemplateNode (com.vaadin.flow.template.angular.ElementTemplateNode)9 Bean (com.vaadin.flow.templatemodel.Bean)9 HashMap (java.util.HashMap)9 Collectors (java.util.stream.Collectors)9