Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-7951

Add first class support for client-side REST tests

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Major
    • Resolution: Complete
    • Affects Version/s: 3.1 M1
    • Fix Version/s: 3.2 RC1
    • Component/s: Test, Web
    • Labels:
    • Last commented by a User:
      false

      Description

      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();
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                rstoya05-aop Rossen Stoyanchev
                Reporter:
                habuma Craig Walls
                Last updater:
                Chris Beams
              • Votes:
                6 Vote for this issue
                Watchers:
                10 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Days since last comment:
                  6 years, 3 weeks, 2 days ago