use of org.springframework.web.socket.sockjs.transport.session.TestHttpSockJsSession in project spring-framework by spring-projects.
the class HttpReceivingTransportHandlerTests method handleRequestAndExpectFailure.
private void handleRequestAndExpectFailure() throws Exception {
resetResponse();
WebSocketHandler wsHandler = mock(WebSocketHandler.class);
AbstractSockJsSession session = new TestHttpSockJsSession("1", new StubSockJsServiceConfig(), wsHandler, null);
new XhrReceivingTransportHandler().handleRequest(this.request, this.response, wsHandler, session);
assertEquals(500, this.servletResponse.getStatus());
verifyNoMoreInteractions(wsHandler);
}
use of org.springframework.web.socket.sockjs.transport.session.TestHttpSockJsSession 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);
assertEquals("text/plain;charset=UTF-8", this.response.getHeaders().getContentType().toString());
verify(wsHandler).handleMessage(session, new TextMessage("x"));
}
use of org.springframework.web.socket.sockjs.transport.session.TestHttpSockJsSession 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"));
try {
XhrReceivingTransportHandler transportHandler = new XhrReceivingTransportHandler();
transportHandler.initialize(sockJsConfig);
transportHandler.handleRequest(this.request, this.response, wsHandler, session);
fail("Expected exception");
} catch (SockJsMessageDeliveryException ex) {
assertNull(session.getCloseStatus());
}
}
Aggregations