Search in sources :

Example 1 with StubSockJsServiceConfig

use of org.springframework.web.socket.sockjs.transport.session.StubSockJsServiceConfig in project spring-framework by spring-projects.

the class DefaultSockJsServiceTests method setup.

@Before
public void setup() {
    super.setUp();
    MockitoAnnotations.initMocks(this);
    Map<String, Object> attributes = Collections.emptyMap();
    this.session = new TestSockJsSession(sessionId, new StubSockJsServiceConfig(), this.wsHandler, attributes);
    given(this.xhrHandler.getTransportType()).willReturn(TransportType.XHR);
    given(this.xhrHandler.createSession(sessionId, this.wsHandler, attributes)).willReturn(this.session);
    given(this.xhrSendHandler.getTransportType()).willReturn(TransportType.XHR_SEND);
    given(this.jsonpHandler.getTransportType()).willReturn(TransportType.JSONP);
    given(this.jsonpHandler.createSession(sessionId, this.wsHandler, attributes)).willReturn(this.session);
    given(this.jsonpSendHandler.getTransportType()).willReturn(TransportType.JSONP_SEND);
    given(this.wsTransportHandler.getTransportType()).willReturn(TransportType.WEBSOCKET);
    this.service = new TransportHandlingSockJsService(this.taskScheduler, this.xhrHandler, this.xhrSendHandler);
}
Also used : TestSockJsSession(org.springframework.web.socket.sockjs.transport.session.TestSockJsSession) TransportHandlingSockJsService(org.springframework.web.socket.sockjs.transport.TransportHandlingSockJsService) StubSockJsServiceConfig(org.springframework.web.socket.sockjs.transport.session.StubSockJsServiceConfig) Before(org.junit.Before)

Example 2 with StubSockJsServiceConfig

use of org.springframework.web.socket.sockjs.transport.session.StubSockJsServiceConfig 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);
}
Also used : TestHttpSockJsSession(org.springframework.web.socket.sockjs.transport.session.TestHttpSockJsSession) WebSocketHandler(org.springframework.web.socket.WebSocketHandler) AbstractSockJsSession(org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession) StubSockJsServiceConfig(org.springframework.web.socket.sockjs.transport.session.StubSockJsServiceConfig)

Example 3 with StubSockJsServiceConfig

use of org.springframework.web.socket.sockjs.transport.session.StubSockJsServiceConfig in project spring-framework by spring-projects.

the class HttpSendingTransportHandlerTests method setUp.

@Override
@Before
public void setUp() {
    super.setUp();
    this.webSocketHandler = mock(WebSocketHandler.class);
    this.taskScheduler = mock(TaskScheduler.class);
    this.sockJsConfig = new StubSockJsServiceConfig();
    this.sockJsConfig.setTaskScheduler(this.taskScheduler);
    setRequest("POST", "/");
}
Also used : WebSocketHandler(org.springframework.web.socket.WebSocketHandler) TaskScheduler(org.springframework.scheduling.TaskScheduler) StubSockJsServiceConfig(org.springframework.web.socket.sockjs.transport.session.StubSockJsServiceConfig) Before(org.junit.Before)

Example 4 with StubSockJsServiceConfig

use of org.springframework.web.socket.sockjs.transport.session.StubSockJsServiceConfig 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"));
}
Also used : TestHttpSockJsSession(org.springframework.web.socket.sockjs.transport.session.TestHttpSockJsSession) WebSocketHandler(org.springframework.web.socket.WebSocketHandler) AbstractSockJsSession(org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession) StubSockJsServiceConfig(org.springframework.web.socket.sockjs.transport.session.StubSockJsServiceConfig) TextMessage(org.springframework.web.socket.TextMessage)

Example 5 with StubSockJsServiceConfig

use of org.springframework.web.socket.sockjs.transport.session.StubSockJsServiceConfig 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());
    }
}
Also used : TestHttpSockJsSession(org.springframework.web.socket.sockjs.transport.session.TestHttpSockJsSession) WebSocketHandler(org.springframework.web.socket.WebSocketHandler) SockJsMessageDeliveryException(org.springframework.web.socket.sockjs.SockJsMessageDeliveryException) StubSockJsServiceConfig(org.springframework.web.socket.sockjs.transport.session.StubSockJsServiceConfig) SockJsMessageDeliveryException(org.springframework.web.socket.sockjs.SockJsMessageDeliveryException) TextMessage(org.springframework.web.socket.TextMessage) Test(org.junit.Test)

Aggregations

StubSockJsServiceConfig (org.springframework.web.socket.sockjs.transport.session.StubSockJsServiceConfig)5 WebSocketHandler (org.springframework.web.socket.WebSocketHandler)4 TestHttpSockJsSession (org.springframework.web.socket.sockjs.transport.session.TestHttpSockJsSession)3 Before (org.junit.Before)2 TextMessage (org.springframework.web.socket.TextMessage)2 AbstractSockJsSession (org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession)2 Test (org.junit.Test)1 TaskScheduler (org.springframework.scheduling.TaskScheduler)1 SockJsMessageDeliveryException (org.springframework.web.socket.sockjs.SockJsMessageDeliveryException)1 TransportHandlingSockJsService (org.springframework.web.socket.sockjs.transport.TransportHandlingSockJsService)1 TestSockJsSession (org.springframework.web.socket.sockjs.transport.session.TestSockJsSession)1