I’m working on integration tests for my REST controller and need to test timeout scenarios. I’m using MockRestServiceServer to mock my backend services but I can’t figure out how to simulate slow responses that would trigger timeouts in my app.
Here’s how I set up my mock server:
backendMock = MockRestServiceServer.createServer(restTemplate);
And this is how I configure the mock responses:
backendMock.expect(requestTo("http://test-api.example.com/data"))
.andExpected(method(HttpMethod.POST))
.andRespond(withSuccess(responseData, MediaType.APPLICATION_JSON));
Is there a way to introduce artificial delays or latency into MockRestServiceServer responses? I need to test how my application handles backend timeouts. Should I consider switching to a different mocking framework that supports this feature better?