WebSocketMessageConverter implements MessageConverter<org.springframework.web.socket.WebSocketMessage, org.springframework.web.socket.WebSocketMessage, WebSocketEndpointConfiguration> { @Override public Message convertInbound(org.springframework.web.socket.WebSocketMessage externalMessage, WebSocketEndpointConfiguration endpointConfiguration, TestContext context) { return new WebSocketMessage(externalMessage.getPayload()) .last(externalMessage.isLast()); }  @Override org.springframework.web.socket.WebSocketMessage convertOutbound(Message message, WebSocketEndpointConfiguration endpointConfiguration, TestContext context); @Override void convertOutbound(org.springframework.web.socket.WebSocketMessage externalMessage, Message internalMessage, WebSocketEndpointConfiguration endpointConfiguration, TestContext context); @Override Message convertInbound(org.springframework.web.socket.WebSocketMessage externalMessage, WebSocketEndpointConfiguration endpointConfiguration, TestContext context);  }
@Test public void testConvertTextMessageInbound() throws Exception { WebSocketEndpointConfiguration endpointConfiguration = new WebSocketClientEndpointConfiguration(); org.springframework.web.socket.WebSocketMessage externalMessage = new TextMessage("Hello WebSocket!"); Message internal = messageConverter.convertInbound(externalMessage, endpointConfiguration, context); Assert.assertTrue(WebSocketMessage.class.isInstance(internal)); Assert.assertEquals(internal.getPayload(String.class), "Hello WebSocket!"); Assert.assertEquals(((WebSocketMessage) internal).isLast(), true); externalMessage = new TextMessage("Hello WebSocket - stay tuned!", false); internal = messageConverter.convertInbound(externalMessage, endpointConfiguration, context); Assert.assertTrue(WebSocketMessage.class.isInstance(internal)); Assert.assertEquals(internal.getPayload(String.class), "Hello WebSocket - stay tuned!"); Assert.assertEquals(((WebSocketMessage) internal).isLast(), false); }
@Test public void testConvertBinaryMessageInbound() throws Exception { WebSocketEndpointConfiguration endpointConfiguration = new WebSocketClientEndpointConfiguration(); org.springframework.web.socket.WebSocketMessage externalMessage = new BinaryMessage("Hello WebSocket!".getBytes(Charset.forName("UTF-8"))); Message internal = messageConverter.convertInbound(externalMessage, endpointConfiguration, context); Assert.assertTrue(WebSocketMessage.class.isInstance(internal)); Assert.assertEquals(internal.getPayload(ByteBuffer.class).array(), "Hello WebSocket!".getBytes(Charset.forName("UTF-8"))); Assert.assertEquals(((WebSocketMessage) internal).isLast(), true); }