MailResource extends BaseConsumer implements Dispatcher, WebsocketResource { private static void sendLetter(Letter letter, WebSocketChannel channel) { try { WebSockets.sendText(serialize(letter), channel, new WebSocketCallback<Void>() { @Override public void complete(WebSocketChannel channel, Void context) { LOG.debug("Successfully sent {}", letter); } @Override public void onError(WebSocketChannel channel, Void context, Throwable t) { LOG.error(String.format("Failed to send %s", letter), t); } }); } catch (IOException e) { LOG.error(String.format("Failed to serialize %s", letter), e); } } @Autowired  MailResource(Config config); @Override Optional<Message> dispatch(Message message); @Override void onOpen(WebSocketChannel channel); @Override void onClose(WebSocketChannel channel);  }
@Test public void testSendLetter() throws Exception { putLetterToQueue(FIRST_LETTER); ClientManager client = ClientManager.createClient(); URI endpoint = new URI(ApiAware.withUrl(server.getBaseUrl()).getWebSocketUrl("mail")); client.connectToServer(this, endpoint); connectionLatch.await(); putLetterToQueue(SECOND_LETTER); receiveLatch.await(); assertThat(exceptions, is(empty())); assertThat(letters, containsInAnyOrder(FIRST_LETTER, SECOND_LETTER)); }