Skip to content

Add first class support for client-side REST tests [SPR-7951] #12606

Closed
@spring-projects-issues

Description

@spring-projects-issues

Craig Walls opened SPR-7951 and commented

This is based on the spring-test-mvc project that has been available on Github, as a separate project, for over a year. The project provides a fluent API for defining expected requests and setting the desired responses, as well as verifying that all expectations were met.

RestTemplate restTemplate = new RestTemplate()
MockRestServiceServer mockServer = MockRestServiceServer.createServer(restTemplate);

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

Hotel hotel = restTemplate.getForObject("/hotels/{id}", Hotel.class, 42);
// use the hotel instance...

mockServer.verify();

Affects: 3.1 M1

Issue Links:

Referenced from: commits 22bcb54, 2638dd5

6 votes, 10 watchers

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