Skip to content

Add overload for MockRestServiceServer.verify with a timeout #22618

@kewne

Description

@kewne

The goal is to verify that the expected interactions occur up to the given timeout.
This is useful for testing asynchronous flows in event-driven services, similar to the testing support in Spring Amqp.

Sample code:

@SpringBootApplication
public class MyApplication {

  @Autowired
  private RestTemplate template;

  @RabbitListener()
  public void callService(String payload) {
    template.put("http://example.com/hello", payload);
  }
}
@SpringBootTest
@RunWith(SpringRunner.class)
public class ApplicationTest {
  @Autowired
  private MockRestServiceServer mockServer;

  @Autowired
  private AmqpTemplate template;

  @Test
  public void callsService() {
    mockServer.expect(method(PUT))
      .andExpect(requestTo("/hello"))
      .andRespond(withNoContent());
    template.convertAndSend("HelloWorld");
    mockServer.verify(5, TimeUnit.SECONDS);
  }
}

Metadata

Metadata

Assignees

Labels

in: testIssues in the test modulein: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions