use of okhttp3.WebSocket in project okhttp by square.
the class WebSocketHttpTest method throwingOnMessageClosesImmediatelyAndFails.
@Test
public void throwingOnMessageClosesImmediatelyAndFails() throws IOException {
webServer.enqueue(new MockResponse().withWebSocketUpgrade(serverListener));
newWebSocket();
clientListener.assertOpen();
WebSocket server = serverListener.assertOpen();
final RuntimeException e = new RuntimeException();
clientListener.setNextEventDelegate(new WebSocketListener() {
@Override
public void onMessage(WebSocket webSocket, String text) {
throw e;
}
});
server.send("Hello, WebSockets!");
clientListener.assertFailure(e);
serverListener.assertExhausted();
}
use of okhttp3.WebSocket in project okhttp by square.
the class WebSocketHttpTest method closeReasonMaximumLength.
@Test
public void closeReasonMaximumLength() throws IOException {
webServer.enqueue(new MockResponse().withWebSocketUpgrade(serverListener));
String clientReason = repeat('C', 123);
String serverReason = repeat('S', 123);
WebSocket webSocket = newWebSocket();
WebSocket server = serverListener.assertOpen();
clientListener.assertOpen();
webSocket.close(1000, clientReason);
serverListener.assertClosing(1000, clientReason);
server.close(1000, serverReason);
clientListener.assertClosing(1000, serverReason);
clientListener.assertClosed(1000, serverReason);
serverListener.assertClosed(1000, clientReason);
}
use of okhttp3.WebSocket in project okhttp by square.
the class WebSocketHttpTest method nullByteStringThrows.
@Test
public void nullByteStringThrows() throws IOException {
webServer.enqueue(new MockResponse().withWebSocketUpgrade(serverListener));
WebSocket webSocket = newWebSocket();
clientListener.assertOpen();
try {
webSocket.send((ByteString) null);
fail();
} catch (NullPointerException e) {
assertEquals("bytes == null", e.getMessage());
}
}
use of okhttp3.WebSocket in project okhttp by square.
the class WebSocketHttpTest method wrongConnectionHeader.
@Test
public void wrongConnectionHeader() throws IOException {
webServer.enqueue(new MockResponse().setResponseCode(101).setHeader("Upgrade", "websocket").setHeader("Connection", "Downgrade").setHeader("Sec-WebSocket-Accept", "ujmZX4KXZqjwy6vi1aQFH5p4Ygk="));
newWebSocket();
clientListener.assertFailure(101, null, ProtocolException.class, "Expected 'Connection' header value 'Upgrade' but was 'Downgrade'");
}
Aggregations