@Override protected TestSockJsSession initSockJsSession() { return new TestSockJsSession("1", this.sockJsConfig, this.webSocketHandler, Collections.<String, Object>emptyMap()); }
@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.wsTransportHandler.getTransportType()).willReturn(TransportType.WEBSOCKET); this.service = new TransportHandlingSockJsService(this.taskScheduler, this.xhrHandler, this.xhrSendHandler); }
@Test public void delegateMessagesWithErrorAndConnectionClosing() throws Exception { WebSocketHandler wsHandler = new ExceptionWebSocketHandlerDecorator(this.webSocketHandler); TestSockJsSession sockJsSession = new TestSockJsSession( "1", this.sockJsConfig, wsHandler, Collections.<String, Object>emptyMap()); String msg1 = "message 1"; String msg2 = "message 2"; String msg3 = "message 3"; willThrow(new IOException()).given(this.webSocketHandler).handleMessage(sockJsSession, new TextMessage(msg2)); sockJsSession.delegateConnectionEstablished(); try { sockJsSession.delegateMessages(msg1, msg2, msg3); fail("expected exception"); } catch (SockJsMessageDeliveryException ex) { assertEquals(Collections.singletonList(msg3), ex.getUndeliveredMessages()); verify(this.webSocketHandler).afterConnectionEstablished(sockJsSession); verify(this.webSocketHandler).handleMessage(sockJsSession, new TextMessage(msg1)); verify(this.webSocketHandler).handleMessage(sockJsSession, new TextMessage(msg2)); verify(this.webSocketHandler).afterConnectionClosed(sockJsSession, CloseStatus.SERVER_ERROR); verifyNoMoreInteractions(this.webSocketHandler); } }