What I am trying to achieve is to test some logic that has a web socket communication behind.
I have recently implemented WebSocket client endpoint and I wanted to test it like http integrations with WireMock - declaratively specifying web socket messages that are expected from external WebSocket server.
Expected library/API:
// SomeLibrary is configured properly
SomeLibrary.stubSocketMessage(forSession(idFromString("Some session id.")))
.respondTo("Message sent from service with web socket client endpoint.")
.withText("Response from web socket server stub.")
.withDelay(500);
// calling my logic that uses WS / sends message
// assertions
I couldn't find such a library therefore I have simply implemented embedded websocket server in my test packages. It was sufficient for single session scenario.
To sum up: I have a websocket connection somewhere in my service layer and I would like to write end to end test with i.e. MockMvc. I want some predefined mock behaviour of WS so I need an embedded http/ws server and to specify behaviour of its WS server endpoint.
Is there solution for what I wanted to achieve? Does it make sense to write such a test? If not, why?