use of org.springframework.messaging.simp.stomp.StompHeaders in project spring-framework by spring-projects.
the class WebSocketStompClientTests method handleWebSocketMessageBinary.
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void handleWebSocketMessageBinary() throws Exception {
String text = "SEND\na:alpha\n\nMessage payload\0";
connect().handleMessage(this.webSocketSession, new BinaryMessage(text.getBytes(StandardCharsets.UTF_8)));
ArgumentCaptor<Message> captor = ArgumentCaptor.forClass(Message.class);
verify(this.stompSession).handleMessage(captor.capture());
Message<byte[]> message = captor.getValue();
assertThat(message).isNotNull();
StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class);
StompHeaders headers = StompHeaders.readOnlyStompHeaders(accessor.toNativeHeaderMap());
assertThat(accessor.getCommand()).isEqualTo(StompCommand.SEND);
assertThat(headers.getFirst("a")).isEqualTo("alpha");
assertThat(new String(message.getPayload(), StandardCharsets.UTF_8)).isEqualTo("Message payload");
}
Aggregations