Skip to content

Extend MockRestServiceServer to support AsyncRestTemplate [SPR-11822] #16442

@spring-projects-issues

Description

@spring-projects-issues

Mattias Severson opened SPR-11822 and commented

It would be useful if the MockRestServiceServer could be extended to support clients that uses AsyncRestTemplate, e.g.

AsyncRestTemplate asyncRestTemplate = new AsyncRestTemplate();
MockRestServiceServer mockServer = MockRestServiceServer.createServer(asyncRestTemplate);

mockServer.expect(requestTo("/hotels/42")).andExpect(method(HttpMethod.GET))
     .andRespond(withSuccess("{ \"id\" : \"42\", \"name\" : \"Holiday Inn\"}", MediaType.APPLICATION_JSON));

ListenableFuture<ResponseEntity<Hotel>> entity = asyncRestTemplate.getForEntity("/hotels/{id}", Hotel.class, 42);
Hotel hotel = entity.get().getBody();

// Use the hotel instance...

mockServer.verify();

The above example was inspired by the example in the JavaDoc of MockRestServiceServer. Another approach would be to create a separate MockAsyncRestServiceServer.


Affects: 4.0.5

Referenced from: commits 49e960c

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