MockRestServiceServer simulate backend timeout in integration test

前端 未结 5 1912
太阳男子
太阳男子 2021-02-12 20:02

I am writing some kind of integration test on my REST controller using MockRestServiceServer to mock backend behaviour. What I am trying to achieve now is to simulate very slow

5条回答
  •  心在旅途
    2021-02-12 20:45

    Approach that you can go for: Specifying the responsebody either with Class Path resource or normal string content. More detailed version of what Skeeve suggested above

    .andRespond(request -> {
                try {
                    Thread.sleep(TimeUnit.SECONDS.toMillis(5)); // Delay
                } catch (InterruptedException ignored) {}
                return withStatus(OK).body(responseBody).contentType(MediaType.APPLICATION_JSON).createResponse(request);
            });
    

提交回复
热议问题