Description
Jared Jacobs opened SPR-16263 and commented
When we attempted to migrate our codebase from 4.3.3 to 5.0.2, our controller integration tests all failed, because our ApplicationContext in the test environment couldn't be created, since we have one controller that uses STOMP over a web socket. We actually aren't even testing STOMP messages in our integration tests. We only test simple HTTP requests, but again, those tests won't run because the ApplicationContext can't be created. This looks like a regression from 4.3.3.
I reproduced the issue easily using an entirely different codebase, a sample application written to showcase testing of spring-websocket. See the example test at the Reference URL above (note the fork).
Problems:
WebSocketServerFactory.doStart()
throws an IllegalStateException because it doesn't have a DecoratedObjectFactory. This can be worked around pretty easily by setting theDecoratedObjectFactory.ATTR
attribute on the ServletContext.WebSocketServerFactory
throws a NullPointerException because it doesn't have an Executor and can't get one via a ContextHandler. This is because Spring's MockServletContext doesn't implement Jetty's ContextHandler.Context. I can’t seem to find a workaround because these spring-websocket types seem to form a chain of construction vianew
:
- WebMvcStompWebSocketEndpointRegistration
- DefaultSockJsService
- DefaultHandshakeHandler
- JettyRequestUpgradeStrategy
- WebSocketServerFactory
For the time being, we are working around the issue by omitting the web socket mappings from our integration test environment (no longer using @EnableWebSocketMessageBroker
in our integration tests). Until this issue is fixed, it seems we no longer have the option of adding tests that exercise the web socket.
Affects: 5.0.2