Search in sources :

Example 6 with IpnbConnection

use of org.jetbrains.plugins.ipnb.protocol.IpnbConnection in project intellij-community by JetBrains.

the class WebSocketConnectionTest method testBasicWebSocket.

public void testBasicWebSocket() throws IOException, URISyntaxException, InterruptedException {
    final Ref<Boolean> evaluated = Ref.create(false);
    final IpnbConnection connection = new IpnbConnection(getTestServerURI(), new IpnbConnectionListenerBase() {

        private String myMessageId;

        @Override
        public void onOpen(@NotNull IpnbConnection connection) {
            myMessageId = connection.execute("2 + 2");
        }

        @Override
        public void onOutput(@NotNull IpnbConnection connection, @NotNull String parentMessageId) {
            if (myMessageId.equals(parentMessageId)) {
                final IpnbOutputCell output = connection.getOutput();
                assertEquals(output.getClass(), IpnbOutOutputCell.class);
                final List<String> text = output.getText();
                assertNotNull(text);
                assertEquals("4", text.get(0));
                evaluated.set(true);
                connection.shutdown();
            }
        }
    }, null, DefaultProjectFactory.getInstance().getDefaultProject(), "");
    connection.close();
    assertTrue(evaluated.get());
}
Also used : IpnbConnection(org.jetbrains.plugins.ipnb.protocol.IpnbConnection) IpnbOutputCell(org.jetbrains.plugins.ipnb.format.cells.output.IpnbOutputCell) List(java.util.List) IpnbOutOutputCell(org.jetbrains.plugins.ipnb.format.cells.output.IpnbOutOutputCell) IpnbConnectionListenerBase(org.jetbrains.plugins.ipnb.protocol.IpnbConnectionListenerBase)

Aggregations

IpnbConnection (org.jetbrains.plugins.ipnb.protocol.IpnbConnection)6 IpnbConnectionListenerBase (org.jetbrains.plugins.ipnb.protocol.IpnbConnectionListenerBase)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 List (java.util.List)2 IpnbOutOutputCell (org.jetbrains.plugins.ipnb.format.cells.output.IpnbOutOutputCell)2 IpnbOutputCell (org.jetbrains.plugins.ipnb.format.cells.output.IpnbOutputCell)2 IOException (java.io.IOException)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1 IpnbFileEditor (org.jetbrains.plugins.ipnb.editor.IpnbFileEditor)1 IpnbCodePanel (org.jetbrains.plugins.ipnb.editor.panels.code.IpnbCodePanel)1