I am considering usage of "WireMock" utility in order to create simple simulators of HTTP based APIs for my automatic tests. My problem is that some of the tests require server sent events (SSE), which is (as far as I read in their github comments) not currently supported, at least not out of the box. Does anyone know if I can implement simple SSE simulator with the existing capabilities of WireMock library, or maybe know for some alternative library of the same type, that supports SSE?
As an option, you can construct the event stream manually and mock a response from SSE endpoint like this (I'm using wiremock-jre8-standalone:2.27.1):
...
import static com.github.tomakehurst.wiremock.client.WireMock.get;
import static com.github.tomakehurst.wiremock.client.WireMock.givenThat;
import static com.github.tomakehurst.wiremock.client.WireMock.notFound;
import static com.github.tomakehurst.wiremock.client.WireMock.okForContentType;
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
...
String eventStream =
"id:id1\nevent:event1\ndata:data1\n\n" +
"id:id2\nevent:event2\ndata:data2\n\n" +
"id:id3\nevent:event3\ndata:data3\n\n";
givenThat(get(urlPathEqualTo("/sse"))
.willReturn(okForContentType("text/event-stream", eventStream)));