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.Initializer, io.jooby.WebSocket.OnClose, io.jooby.WebSocket.OnConnect, io.jooby.WebSocket.OnError, io.jooby.WebSocket.OnMessage
  • 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)
     
    io.jooby.Context
     
    List<io.jooby.WebSocket>
     
    boolean
     
    io.jooby.WebSocket
    render(Object value, boolean broadcast)
     
    io.jooby.WebSocket
    send(byte[] message, boolean broadcast)
     
    io.jooby.WebSocket
    send(String message, boolean broadcast)
     

    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, send, send
  • Method Details

    • getContext

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

      @NonNull 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
    • send

      @NonNull public io.jooby.WebSocket send(@NonNull String message, boolean broadcast)
      Specified by:
      send in interface io.jooby.WebSocket
    • send

      @NonNull public io.jooby.WebSocket send(@NonNull byte[] message, boolean broadcast)
      Specified by:
      send in interface io.jooby.WebSocket
    • render

      @NonNull public io.jooby.WebSocket render(@NonNull Object value, boolean broadcast)
      Specified by:
      render in interface io.jooby.WebSocket
    • close

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