Package io.jooby.test

Class MockWebSocket

java.lang.Object
io.jooby.test.MockWebSocket
All Implemented Interfaces:
io.jooby.WebSocket

public class MockWebSocket extends Object implements io.jooby.WebSocket
Mock implementation of WebSocket for unit testing purpose.

App:


 ws("/path", (ctx, initializer) -> {
   initializer.onConnect(ws -> {
     ws.send("OnConnect");
   });
 });
 
Test:

 MockRouter router = new MockRouter(new App());
 router.ws("/path", ws -> {

   ws.onMessage(message -> {
     System.out.println("Got: " + message);
   });

   ws.send("Another message");
 })
 
Since:
2.2.0
Author:
edgar
  • Nested Class Summary

    Nested classes/interfaces inherited from interface io.jooby.WebSocket

    io.jooby.WebSocket.Handler, io.jooby.WebSocket.Initializer, io.jooby.WebSocket.OnClose, io.jooby.WebSocket.OnConnect, io.jooby.WebSocket.OnError, io.jooby.WebSocket.OnMessage, io.jooby.WebSocket.WriteCallback
  • Field Summary

    Fields inherited from interface io.jooby.WebSocket

    MAX_BUFFER_SIZE
  • Method Summary

    Modifier and Type
    Method
    Description
    io.jooby.WebSocket
    close(io.jooby.WebSocketCloseStatus closeStatus)
     
    void
    forEach(io.jooby.SneakyThrows.Consumer<io.jooby.WebSocket> callback)
     
    io.jooby.Context
     
    List<io.jooby.WebSocket>
     
    boolean
     
    io.jooby.WebSocket
    render(Object value, io.jooby.WebSocket.WriteCallback callback)
     
    io.jooby.WebSocket
    renderBinary(Object value, io.jooby.WebSocket.WriteCallback callback)
     
    io.jooby.WebSocket
    send(byte[] message, io.jooby.WebSocket.WriteCallback callback)
     
    io.jooby.WebSocket
    send(io.jooby.output.Output message, io.jooby.WebSocket.WriteCallback callback)
     
    io.jooby.WebSocket
    send(String message, io.jooby.WebSocket.WriteCallback callback)
     
    io.jooby.WebSocket
    send(ByteBuffer message, io.jooby.WebSocket.WriteCallback callback)
     
    io.jooby.WebSocket
    sendBinary(byte[] message, io.jooby.WebSocket.WriteCallback callback)
     
    io.jooby.WebSocket
    sendBinary(io.jooby.output.Output message, io.jooby.WebSocket.WriteCallback callback)
     
    io.jooby.WebSocket
    sendBinary(String message, io.jooby.WebSocket.WriteCallback callback)
     
    io.jooby.WebSocket
    sendBinary(ByteBuffer message, io.jooby.WebSocket.WriteCallback callback)
     
    io.jooby.WebSocket
    sendPing(String message, io.jooby.WebSocket.WriteCallback callback)
     
    io.jooby.WebSocket
    sendPing(ByteBuffer message, io.jooby.WebSocket.WriteCallback callback)
     

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface io.jooby.WebSocket

    attribute, attribute, close, getAttributes, render, renderBinary, send, send, send, send, sendBinary, sendBinary, sendBinary, sendBinary, sendPing, sendPing, sendPing, sendPing
  • Method Details

    • getContext

      public io.jooby.Context getContext()
      Specified by:
      getContext in interface io.jooby.WebSocket
    • getSessions

      public List<io.jooby.WebSocket> getSessions()
      Specified by:
      getSessions in interface io.jooby.WebSocket
    • isOpen

      public boolean isOpen()
      Specified by:
      isOpen in interface io.jooby.WebSocket
    • forEach

      public void forEach(io.jooby.SneakyThrows.Consumer<io.jooby.WebSocket> callback)
      Specified by:
      forEach in interface io.jooby.WebSocket
    • sendPing

      public io.jooby.WebSocket sendPing(String message, io.jooby.WebSocket.WriteCallback callback)
      Specified by:
      sendPing in interface io.jooby.WebSocket
    • sendPing

      public io.jooby.WebSocket sendPing(ByteBuffer message, io.jooby.WebSocket.WriteCallback callback)
      Specified by:
      sendPing in interface io.jooby.WebSocket
    • send

      public io.jooby.WebSocket send(String message, io.jooby.WebSocket.WriteCallback callback)
      Specified by:
      send in interface io.jooby.WebSocket
    • send

      public io.jooby.WebSocket send(byte[] message, io.jooby.WebSocket.WriteCallback callback)
      Specified by:
      send in interface io.jooby.WebSocket
    • send

      public io.jooby.WebSocket send(ByteBuffer message, io.jooby.WebSocket.WriteCallback callback)
      Specified by:
      send in interface io.jooby.WebSocket
    • send

      public io.jooby.WebSocket send(io.jooby.output.Output message, io.jooby.WebSocket.WriteCallback callback)
      Specified by:
      send in interface io.jooby.WebSocket
    • sendBinary

      public io.jooby.WebSocket sendBinary(String message, io.jooby.WebSocket.WriteCallback callback)
      Specified by:
      sendBinary in interface io.jooby.WebSocket
    • sendBinary

      public io.jooby.WebSocket sendBinary(byte[] message, io.jooby.WebSocket.WriteCallback callback)
      Specified by:
      sendBinary in interface io.jooby.WebSocket
    • sendBinary

      public io.jooby.WebSocket sendBinary(ByteBuffer message, io.jooby.WebSocket.WriteCallback callback)
      Specified by:
      sendBinary in interface io.jooby.WebSocket
    • sendBinary

      public io.jooby.WebSocket sendBinary(io.jooby.output.Output message, io.jooby.WebSocket.WriteCallback callback)
      Specified by:
      sendBinary in interface io.jooby.WebSocket
    • render

      public io.jooby.WebSocket render(Object value, io.jooby.WebSocket.WriteCallback callback)
      Specified by:
      render in interface io.jooby.WebSocket
    • renderBinary

      public io.jooby.WebSocket renderBinary(Object value, io.jooby.WebSocket.WriteCallback callback)
      Specified by:
      renderBinary in interface io.jooby.WebSocket
    • close

      public io.jooby.WebSocket close(io.jooby.WebSocketCloseStatus closeStatus)
      Specified by:
      close in interface io.jooby.WebSocket