Search in sources :

Example 1 with BufferFactoryImpl

use of io.vertx.core.buffer.impl.BufferFactoryImpl in project nem2-sdk-java by nemtech.

the class ListenerVertxTest method simulateWebSocketStartup.

private void simulateWebSocketStartup() throws InterruptedException, ExecutionException, TimeoutException {
    ArgumentCaptor<Handler> webSocketHandlerCapture = ArgumentCaptor.forClass(Handler.class);
    ArgumentCaptor<Handler> bufferHandlerCapture = ArgumentCaptor.forClass(Handler.class);
    when(httpClientMock.websocket(any(RequestOptions.class), webSocketHandlerCapture.capture())).thenReturn(httpClientMock);
    when(webSocketMock.handler(bufferHandlerCapture.capture())).thenReturn(webSocketMock);
    CompletableFuture<Void> future = listener.open();
    Handler<WebSocket> webSocketHandler = webSocketHandlerCapture.getValue();
    Assertions.assertNotNull(webSocketHandler);
    webSocketHandler.handle(webSocketMock);
    Handler<Buffer> bufferHandler = bufferHandlerCapture.getValue();
    Assertions.assertNotNull(bufferHandler);
    Buffer event = new BufferFactoryImpl().buffer(jsonHelper.print(Collections.singletonMap("uid", wsId)));
    bufferHandler.handle(event);
    future.get(3, TimeUnit.SECONDS);
}
Also used : Buffer(io.vertx.core.buffer.Buffer) RequestOptions(io.vertx.core.http.RequestOptions) Handler(io.vertx.core.Handler) BufferFactoryImpl(io.vertx.core.buffer.impl.BufferFactoryImpl) WebSocket(io.vertx.core.http.WebSocket)

Aggregations

Handler (io.vertx.core.Handler)1 Buffer (io.vertx.core.buffer.Buffer)1 BufferFactoryImpl (io.vertx.core.buffer.impl.BufferFactoryImpl)1 RequestOptions (io.vertx.core.http.RequestOptions)1 WebSocket (io.vertx.core.http.WebSocket)1