use of org.springframework.web.socket.TextMessage in project spring-framework by spring-projects.
the class HttpReceivingTransportHandlerTests method handleRequest.
private void handleRequest(AbstractHttpReceivingTransportHandler transportHandler) throws Exception {
WebSocketHandler wsHandler = mock(WebSocketHandler.class);
AbstractSockJsSession session = new TestHttpSockJsSession("1", new StubSockJsServiceConfig(), wsHandler, null);
transportHandler.initialize(new StubSockJsServiceConfig());
transportHandler.handleRequest(this.request, this.response, wsHandler, session);
assertThat(this.response.getHeaders().getContentType().toString()).isEqualTo("text/plain;charset=UTF-8");
verify(wsHandler).handleMessage(session, new TextMessage("x"));
}
use of org.springframework.web.socket.TextMessage in project spring-framework by spring-projects.
the class HttpReceivingTransportHandlerTests method delegateMessageException.
@Test
public void delegateMessageException() throws Exception {
StubSockJsServiceConfig sockJsConfig = new StubSockJsServiceConfig();
this.servletRequest.setContent("[\"x\"]".getBytes("UTF-8"));
WebSocketHandler wsHandler = mock(WebSocketHandler.class);
TestHttpSockJsSession session = new TestHttpSockJsSession("1", sockJsConfig, wsHandler, null);
session.delegateConnectionEstablished();
willThrow(new Exception()).given(wsHandler).handleMessage(session, new TextMessage("x"));
XhrReceivingTransportHandler transportHandler = new XhrReceivingTransportHandler();
transportHandler.initialize(sockJsConfig);
assertThatExceptionOfType(SockJsMessageDeliveryException.class).isThrownBy(() -> transportHandler.handleRequest(this.request, this.response, wsHandler, session));
assertThat(session.getCloseStatus()).isNull();
}
Aggregations