Search in sources :

Example 1 with ServerConnector

use of com.vaadin.client.communication.ServerConnector in project flow by vaadin.

the class GwtExecuteJavaScriptElementUtilsTest method testReturnChannel_passedToExecJavaScript_messageSentToServer.

public void testReturnChannel_passedToExecJavaScript_messageSentToServer() {
    ApplicationConfiguration applicationConfiguration = new ApplicationConfiguration();
    applicationConfiguration.setApplicationId("test");
    // Pass a number to the channel
    String expression = "$0(2)";
    int expectedNodeId = 10;
    int expectedChannelId = 20;
    int[] runCountHolder = { 0 };
    ExecuteJavaScriptProcessor processor = new ExecuteJavaScriptProcessor(new Registry() {

        {
            set(StateTree.class, new StateTree(this));
            set(ApplicationConfiguration.class, applicationConfiguration);
            set(ServerConnector.class, new ServerConnector(this) {

                @Override
                public void sendReturnChannelMessage(int stateNodeId, int channelId, JsonArray arguments) {
                    assertEquals(expectedNodeId, stateNodeId);
                    assertEquals(expectedChannelId, channelId);
                    assertEquals("Args array should contain the value passed to the channel function", "[2]", arguments.toJson());
                    runCountHolder[0]++;
                }
            });
        }
    });
    JsonArray serializedChannel = Json.createArray();
    serializedChannel.set(0, JsonCodec.RETURN_CHANNEL_TYPE);
    serializedChannel.set(1, expectedNodeId);
    serializedChannel.set(2, expectedChannelId);
    JsonArray invocation = Json.createArray();
    // Assign channel as $0
    invocation.set(0, serializedChannel);
    invocation.set(1, expression);
    JsonArray invocations = Json.createArray();
    invocations.set(0, invocation);
    processor.execute(invocations);
    assertEquals(1, runCountHolder[0]);
}
Also used : ServerConnector(com.vaadin.client.communication.ServerConnector) JsonArray(elemental.json.JsonArray) StateTree(com.vaadin.client.flow.StateTree) ExecuteJavaScriptProcessor(com.vaadin.client.flow.ExecuteJavaScriptProcessor)

Example 2 with ServerConnector

use of com.vaadin.client.communication.ServerConnector in project flow by vaadin.

the class GwtRouterLinkHandlerTest method gwtSetUp.

@Override
protected void gwtSetUp() throws Exception {
    super.gwtSetUp();
    createDummyWindowVaadinFlow();
    invocations = JsCollections.array();
    ServerConnector connector = new ServerConnector(null) {

        @Override
        public void sendNavigationMessage(String location, Object stateObject, boolean routerLinkEvent) {
            invocations.push(location);
        }
    };
    UILifecycle lifecycle = new UILifecycle();
    lifecycle.setState(UIState.RUNNING);
    registry = new Registry() {

        {
            set(UILifecycle.class, lifecycle);
            set(ServerConnector.class, connector);
            set(MessageHandler.class, new MessageHandler(this));
            set(RequestResponseTracker.class, new RequestResponseTracker(this));
            set(ScrollPositionHandler.class, new ScrollPositionHandler(this));
        }
    };
    boundElement = Browser.getDocument().createDivElement();
    Browser.getDocument().getBody().appendChild(boundElement);
    RouterLinkHandler.bind(registry, boundElement);
}
Also used : ServerConnector(com.vaadin.client.communication.ServerConnector) ScrollPositionHandler(com.vaadin.client.ScrollPositionHandler) MessageHandler(com.vaadin.client.communication.MessageHandler) UILifecycle(com.vaadin.client.UILifecycle) Registry(com.vaadin.client.Registry) RequestResponseTracker(com.vaadin.client.communication.RequestResponseTracker)

Aggregations

ServerConnector (com.vaadin.client.communication.ServerConnector)2 Registry (com.vaadin.client.Registry)1 ScrollPositionHandler (com.vaadin.client.ScrollPositionHandler)1 UILifecycle (com.vaadin.client.UILifecycle)1 MessageHandler (com.vaadin.client.communication.MessageHandler)1 RequestResponseTracker (com.vaadin.client.communication.RequestResponseTracker)1 ExecuteJavaScriptProcessor (com.vaadin.client.flow.ExecuteJavaScriptProcessor)1 StateTree (com.vaadin.client.flow.StateTree)1 JsonArray (elemental.json.JsonArray)1