lundi 16 juillet 2018

How to test WebSockets with Spring

I have some implementation of WebSockets in Spring with following configuration.

public class MyWebSocketMessageBrokerConfigurer extends AbstractWebSocketMessageBrokerConfigurer {

    @Override
    public void configureMessageBroker(MessageBrokerRegistry registry) {
        registry.enableSimpleBroker("/queue");
    }

    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint("/endpoint")
                .withSockJS();
    }

    @Override
    public void configureClientInboundChannel(ChannelRegistration registration) {
        registration.interceptors(new ChannelInterceptorAdapter() {
            @Override
            public Message<?> preSend(Message<?> message, MessageChannel channel) {
                final StompHeaderAccessor accessor = StompHeaderAccessor.wrap(message);
                final StompCommand command = accessor.getCommand();
                if (command == StompCommand.CONNECT) {
                    final Map nativeHeaders = accessor.getMessageHeaders().get(StompHeaderAccessor.NATIVE_HEADERS, Map.class);
                    // do something with headers...
                }
            }
        });
    }
}

I need to test this configuration. Any idea, how to test it? Is there something like mockMvc for WebSockets?

Aucun commentaire:

Enregistrer un commentaire