use of com.vaadin.flow.internal.StateNode in project flow by vaadin.
the class AttachExistingElementRpcHandler method handleNode.
@Override
protected Optional<Runnable> handleNode(StateNode node, JsonObject invocationJson) {
assert invocationJson.hasKey(JsonConstants.RPC_ATTACH_REQUESTED_ID);
assert invocationJson.hasKey(JsonConstants.RPC_ATTACH_ASSIGNED_ID);
assert invocationJson.hasKey(JsonConstants.RPC_ATTACH_TAG_NAME);
assert invocationJson.hasKey(JsonConstants.RPC_ATTACH_INDEX);
int requestedId = (int) invocationJson.getNumber(JsonConstants.RPC_ATTACH_REQUESTED_ID);
int assignedId = (int) invocationJson.getNumber(JsonConstants.RPC_ATTACH_ASSIGNED_ID);
String tag = invocationJson.getString(JsonConstants.RPC_ATTACH_TAG_NAME);
int index = (int) invocationJson.getNumber(JsonConstants.RPC_ATTACH_INDEX);
AttachExistingElementFeature feature = node.getFeature(AttachExistingElementFeature.class);
StateTree tree = (StateTree) node.getOwner();
StateNode requestedNode = tree.getNodeById(requestedId);
if (assignedId == -1) {
// handle an error
assert index == -1;
ChildElementConsumer callback = feature.getCallback(requestedNode);
assert callback != null;
callback.onError(feature.getParent(requestedNode), tag, feature.getPreviousSibling(requestedNode));
feature.unregister(requestedNode);
} else {
Element element = Element.get(tree.getNodeById(assignedId));
attachElement(feature, element, index, tree.getNodeById(requestedId), requestedId == assignedId);
}
return Optional.empty();
}
use of com.vaadin.flow.internal.StateNode in project flow by vaadin.
the class ReturnChannelHandlerTest method noReturnChannelMap_invocationIgnored.
@Test
public void noReturnChannelMap_invocationIgnored() {
StateNode nodeWithoutMap = new StateNode();
ui.getElement().getNode().getFeature(ElementChildrenList.class).add(0, nodeWithoutMap);
handleMessage(nodeWithoutMap.getId(), 0);
// Nothing to assert, just checking that no exception is thrown
}
use of com.vaadin.flow.internal.StateNode in project flow by vaadin.
the class MapSyncRpcHandlerTest method handleNode_callsElementPropertyMapDeferredUpdateFromClient.
@Test
public void handleNode_callsElementPropertyMapDeferredUpdateFromClient() {
AtomicInteger deferredUpdateInvocations = new AtomicInteger();
AtomicReference<String> deferredKey = new AtomicReference<>();
StateNode node = new StateNode(ElementPropertyMap.class) {
private ElementPropertyMap map = new ElementPropertyMap(this) {
@Override
public Runnable deferredUpdateFromClient(String key, Serializable value) {
deferredUpdateInvocations.incrementAndGet();
deferredKey.set(key);
return () -> {
};
}
};
@Override
public <F extends NodeFeature> F getFeature(Class<F> featureType) {
if (featureType.equals(ElementPropertyMap.class)) {
return featureType.cast(map);
}
return super.getFeature(featureType);
}
};
new MapSyncRpcHandler().handleNode(node, createSyncPropertyInvocation(node, TEST_PROPERTY, NEW_VALUE));
Assert.assertEquals(1, deferredUpdateInvocations.get());
Assert.assertEquals(TEST_PROPERTY, deferredKey.get());
}
use of com.vaadin.flow.internal.StateNode in project flow by vaadin.
the class MapSyncRpcHandlerTest method propertyIsNotExplicitlyAllowed_subproperty_throwsWithComponentInfo.
@Test
public void propertyIsNotExplicitlyAllowed_subproperty_throwsWithComponentInfo() {
exception.expect(IllegalArgumentException.class);
exception.expectMessage(CoreMatchers.allOf(CoreMatchers.containsString("Component " + TestComponent.class.getName()), CoreMatchers.containsString("'" + TEST_PROPERTY + "'")));
TestComponent component = new TestComponent();
Element element = component.getElement();
StateNode node = element.getNode();
ElementPropertyMap propertyMap = node.getFeature(ElementPropertyMap.class).resolveModelMap("foo.bar");
new MapSyncRpcHandler().handleNode(propertyMap.getNode(), createSyncPropertyInvocation(propertyMap.getNode(), TEST_PROPERTY, NEW_VALUE));
}
use of com.vaadin.flow.internal.StateNode in project flow by vaadin.
the class AttachTemplateChildRpcHandlerTest method assertHandleNode.
private void assertHandleNode(int assignedId, JsonValue id) {
AttachTemplateChildRpcHandler handler = new AttachTemplateChildRpcHandler();
int requestedId = 1;
JsonObject object = Json.createObject();
object.put(JsonConstants.RPC_ATTACH_REQUESTED_ID, requestedId);
object.put(JsonConstants.RPC_ATTACH_ASSIGNED_ID, assignedId);
object.put(JsonConstants.RPC_ATTACH_ID, id);
StateNode node = Mockito.mock(StateNode.class);
StateNode parentNode = Mockito.mock(StateNode.class);
StateTree tree = Mockito.mock(StateTree.class);
Mockito.when(node.getOwner()).thenReturn(tree);
Mockito.when(node.getParent()).thenReturn(parentNode);
Mockito.when(tree.getNodeById(requestedId)).thenReturn(node);
Mockito.when(node.getChangeTracker(Mockito.any(), Mockito.any())).thenReturn(new HashMap<>());
ElementData data = new ElementData(node);
data.setTag("foo");
Mockito.when(node.getFeature(ElementData.class)).thenReturn(data);
Mockito.when(parentNode.getId()).thenReturn(3);
handler.handleNode(node, object);
}
Aggregations