Search in sources :

Example 1 with LocalWebSocketConnection

use of org.eclipse.jetty.websocket.common.io.LocalWebSocketConnection in project jetty.project by eclipse.

the class WebSocketRemoteEndpointTest method testTextPingText.

@Test
public void testTextPingText() throws IOException {
    LocalWebSocketConnection conn = new LocalWebSocketConnection(testname, bufferPool);
    OutgoingFramesCapture outgoing = new OutgoingFramesCapture();
    WebSocketRemoteEndpoint remote = new WebSocketRemoteEndpoint(conn, outgoing);
    conn.connect();
    conn.open();
    // Start text message
    remote.sendPartialString("Hello ", false);
    // Attempt to send Ping Message
    remote.sendPing(ByteBuffer.wrap(new byte[] { 0 }));
    // End text message
    remote.sendPartialString("World!", true);
}
Also used : LocalWebSocketConnection(org.eclipse.jetty.websocket.common.io.LocalWebSocketConnection) OutgoingFramesCapture(org.eclipse.jetty.websocket.common.test.OutgoingFramesCapture) Test(org.junit.Test)

Example 2 with LocalWebSocketConnection

use of org.eclipse.jetty.websocket.common.io.LocalWebSocketConnection in project jetty.project by eclipse.

the class WebSocketRemoteEndpointTest method testTextBinaryText.

@Test
public void testTextBinaryText() throws IOException {
    LocalWebSocketConnection conn = new LocalWebSocketConnection(testname, bufferPool);
    OutgoingFramesCapture outgoing = new OutgoingFramesCapture();
    WebSocketRemoteEndpoint remote = new WebSocketRemoteEndpoint(conn, outgoing);
    conn.connect();
    conn.open();
    // Start text message
    remote.sendPartialString("Hello ", false);
    try {
        // Attempt to start Binary Message
        ByteBuffer bytes = ByteBuffer.wrap(new byte[] { 0, 1, 2 });
        remote.sendPartialBytes(bytes, false);
        Assert.fail("Expected " + IllegalStateException.class.getName());
    } catch (IllegalStateException e) {
        // Expected path
        Assert.assertThat("Exception", e.getMessage(), containsString("Cannot send"));
    }
    // End text message
    remote.sendPartialString("World!", true);
}
Also used : LocalWebSocketConnection(org.eclipse.jetty.websocket.common.io.LocalWebSocketConnection) ByteBuffer(java.nio.ByteBuffer) OutgoingFramesCapture(org.eclipse.jetty.websocket.common.test.OutgoingFramesCapture) Test(org.junit.Test)

Aggregations

LocalWebSocketConnection (org.eclipse.jetty.websocket.common.io.LocalWebSocketConnection)2 OutgoingFramesCapture (org.eclipse.jetty.websocket.common.test.OutgoingFramesCapture)2 Test (org.junit.Test)2 ByteBuffer (java.nio.ByteBuffer)1