use of org.springframework.web.socket.WebSocketHandler in project spring-framework by spring-projects.
the class WebSocketConnectionManagerTests method clientLifecycle.
@Test
public void clientLifecycle() throws Exception {
TestLifecycleWebSocketClient client = new TestLifecycleWebSocketClient(false);
WebSocketHandler handler = new TextWebSocketHandler();
WebSocketConnectionManager manager = new WebSocketConnectionManager(client, handler, "/a");
manager.startInternal();
assertTrue(client.isRunning());
manager.stopInternal();
assertFalse(client.isRunning());
}
use of org.springframework.web.socket.WebSocketHandler in project spring-framework by spring-projects.
the class WebSocketConnectionManagerTests method openConnection.
@Test
public void openConnection() throws Exception {
List<String> subprotocols = Arrays.asList("abc");
TestLifecycleWebSocketClient client = new TestLifecycleWebSocketClient(false);
WebSocketHandler handler = new TextWebSocketHandler();
WebSocketConnectionManager manager = new WebSocketConnectionManager(client, handler, "/path/{id}", "123");
manager.setSubProtocols(subprotocols);
manager.openConnection();
WebSocketHttpHeaders expectedHeaders = new WebSocketHttpHeaders();
expectedHeaders.setSecWebSocketProtocol(subprotocols);
assertEquals(expectedHeaders, client.headers);
assertEquals(new URI("/path/123"), client.uri);
WebSocketHandlerDecorator loggingHandler = (WebSocketHandlerDecorator) client.webSocketHandler;
assertEquals(LoggingWebSocketHandlerDecorator.class, loggingHandler.getClass());
assertSame(handler, loggingHandler.getDelegate());
}
use of org.springframework.web.socket.WebSocketHandler in project spring-framework by spring-projects.
the class HttpReceivingTransportHandlerTests method readMessagesNoSession.
@Test(expected = IllegalArgumentException.class)
public void readMessagesNoSession() throws Exception {
WebSocketHandler webSocketHandler = mock(WebSocketHandler.class);
new XhrReceivingTransportHandler().handleRequest(this.request, this.response, webSocketHandler, null);
}
use of org.springframework.web.socket.WebSocketHandler 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.WebSocketHandler in project spring-framework by spring-projects.
the class SockJsWebSocketHandlerTests method getSubProtocolsNone.
@Test
public void getSubProtocolsNone() throws Exception {
WebSocketHandler handler = new TextWebSocketHandler();
TaskScheduler scheduler = mock(TaskScheduler.class);
DefaultSockJsService service = new DefaultSockJsService(scheduler);
WebSocketServerSockJsSession session = new WebSocketServerSockJsSession("1", service, handler, null);
SockJsWebSocketHandler sockJsHandler = new SockJsWebSocketHandler(service, handler, session);
assertNull(sockJsHandler.getSubProtocols());
}
Aggregations