use of org.springframework.web.socket.TextMessage in project spring-framework by spring-projects.
the class WebSocketStompClientTests method handleWebSocketMessageSplitAcrossTwoMessage.
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void handleWebSocketMessageSplitAcrossTwoMessage() throws Exception {
WebSocketHandler webSocketHandler = connect();
String part1 = "SEND\na:alpha\n\nMessage";
webSocketHandler.handleMessage(this.webSocketSession, new TextMessage(part1));
verifyNoMoreInteractions(this.stompSession);
String part2 = " payload\0";
webSocketHandler.handleMessage(this.webSocketSession, new TextMessage(part2));
ArgumentCaptor<Message> captor = ArgumentCaptor.forClass(Message.class);
verify(this.stompSession).handleMessage(captor.capture());
Message<byte[]> message = captor.getValue();
assertNotNull(message);
StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class);
StompHeaders headers = StompHeaders.readOnlyStompHeaders(accessor.toNativeHeaderMap());
assertEquals(StompCommand.SEND, accessor.getCommand());
assertEquals("alpha", headers.getFirst("a"));
assertEquals("Message payload", new String(message.getPayload(), StandardCharsets.UTF_8));
}
use of org.springframework.web.socket.TextMessage in project spring-framework by spring-projects.
the class WebSocketServerSockJsSessionTests method handleMessageBadData.
@Test
public void handleMessageBadData() throws Exception {
TextMessage message = new TextMessage("[\"x]");
this.session.handleMessage(message, this.webSocketSession);
this.session.isClosed();
verify(this.webSocketHandler).handleTransportError(same(this.session), any(IOException.class));
verifyNoMoreInteractions(this.webSocketHandler);
}
use of org.springframework.web.socket.TextMessage in project spring-framework by spring-projects.
the class WebSocketServerSockJsSessionTests method handleMessage.
@Test
public void handleMessage() throws Exception {
TextMessage message = new TextMessage("[\"x\"]");
this.session.handleMessage(message, this.webSocketSession);
verify(this.webSocketHandler).handleMessage(this.session, new TextMessage("x"));
verifyNoMoreInteractions(this.webSocketHandler);
}
use of org.springframework.web.socket.TextMessage in project spring-framework by spring-projects.
the class WebSocketServerSockJsSessionTests method afterSessionInitializedOpenFrameFirst.
@Test
@SuppressWarnings("resource")
public void afterSessionInitializedOpenFrameFirst() throws Exception {
TextWebSocketHandler handler = new TextWebSocketHandler() {
@Override
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
session.sendMessage(new TextMessage("go go"));
}
};
TestWebSocketServerSockJsSession session = new TestWebSocketServerSockJsSession(this.sockJsConfig, handler, null);
session.initializeDelegateSession(this.webSocketSession);
List<TextMessage> expected = Arrays.asList(new TextMessage("o"), new TextMessage("a[\"go go\"]"));
assertEquals(expected, this.webSocketSession.getSentMessages());
}
use of org.springframework.web.socket.TextMessage in project spring-framework by spring-projects.
the class SockJsSessionTests method delegateMessages.
@Test
public void delegateMessages() throws Exception {
String msg1 = "message 1";
String msg2 = "message 2";
this.session.delegateMessages(msg1, msg2);
verify(this.webSocketHandler).handleMessage(this.session, new TextMessage(msg1));
verify(this.webSocketHandler).handleMessage(this.session, new TextMessage(msg2));
verifyNoMoreInteractions(this.webSocketHandler);
}
Aggregations