use of org.springframework.web.socket.sockjs.frame.Jackson2SockJsMessageCodec in project spring-framework by spring-projects.
the class RestTemplateXhrTransportTests method connectReceiveAndCloseWithStompFrame.
@Test
public void connectReceiveAndCloseWithStompFrame() throws Exception {
StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.SEND);
accessor.setDestination("/destination");
MessageHeaders headers = accessor.getMessageHeaders();
Message<byte[]> message = MessageBuilder.createMessage("body".getBytes(StandardCharsets.UTF_8), headers);
byte[] bytes = new StompEncoder().encode(message);
TextMessage textMessage = new TextMessage(bytes);
SockJsFrame frame = SockJsFrame.messageFrame(new Jackson2SockJsMessageCodec(), textMessage.getPayload());
String body = "o\n" + frame.getContent() + "\n" + "c[3000,\"Go away!\"]";
ClientHttpResponse response = response(HttpStatus.OK, body);
connect(response);
verify(this.webSocketHandler).afterConnectionEstablished(any());
verify(this.webSocketHandler).handleMessage(any(), eq(textMessage));
verify(this.webSocketHandler).afterConnectionClosed(any(), eq(new CloseStatus(3000, "Go away!")));
verifyNoMoreInteractions(this.webSocketHandler);
}
use of org.springframework.web.socket.sockjs.frame.Jackson2SockJsMessageCodec in project fastjson by alibaba.
the class FastjsonSockJsMessageCodecTest_encode method test_encode.
public void test_encode() throws Exception {
FastjsonSockJsMessageCodec fastjsonCodec = new FastjsonSockJsMessageCodec();
Jackson2SockJsMessageCodec jacksonCodec = new Jackson2SockJsMessageCodec();
String v0 = "a0\"\0", v1 = "a1";
String fastjsonResult = fastjsonCodec.encode(v0, v1);
String jacksonResult = jacksonCodec.encode(v0, v1);
Assert.assertEquals(jacksonResult, fastjsonResult);
}
Aggregations