You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add first class support for client-side REST tests [SPR-7951] #12606
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.
RestTemplaterestTemplate = newRestTemplate()
MockRestServiceServermockServer = MockRestServiceServer.createServer(restTemplate);
mockServer.expect(requestTo("/hotels/42")).andExpect(method(HttpMethod.GET))
.andRespond(withSuccess("{ \"id\" : \"42\", \"name\" : \"Holiday Inn\"}", MediaType.APPLICATION_JSON));
Hotelhotel = restTemplate.getForObject("/hotels/{id}", Hotel.class, 42);
// use the hotel instance...mockServer.verify();
Craig, the spring-test-mvc project on Github was created to develop client and server-side test support before moving it to Spring trunk. Currently it has server-side support under org.springframework.test.web.server. We can start the client-side support with a copy of your code under org.springframework.test.web.client. I think you have permissions there, feel free to add it.
I also find this very useful and would like to see it added to spring-mvc. Is this still being worked in? I do have one suggestion though I usually wire my beans by interface not implementation I would like to see something more like this:
'public static MockRestServiceServer createServer(RestOperations restOperations)' I had to change that to use it properly in my code I don't put getters for the RestTemplate in my code like was done in spring-social.
Also you might want to run sonar/pmd/findbugs etc as it raised some flags on some random things like failure to close a BufferedReader in the ResponseCreators class.
Activity
spring-projects-issues commentedon Feb 24, 2011
Craig Walls commented
Update: I've moved the mock server framework code out of Spring Social's core module and into spring-social-test.
spring-projects-issues commentedon Jun 3, 2011
Rossen Stoyanchev commented
Craig, the spring-test-mvc project on Github was created to develop client and server-side test support before moving it to Spring trunk. Currently it has server-side support under
org.springframework.test.web.server. We can start the client-side support with a copy of your code underorg.springframework.test.web.client. I think you have permissions there, feel free to add it.spring-projects-issues commentedon Jun 24, 2011
Alessandro Bortolussi commented
Hi, I have found the mock server framework code extremely useful for testing RestTemplate, and I have introduced it in my company's test code.
As Rossen mentioned, I also believe it would make really lots of sense to have it in a more general-purpose module, like spring-test-mvc.
spring-projects-issues commentedon Apr 9, 2012
William Gorder commented
I also find this very useful and would like to see it added to spring-mvc. Is this still being worked in? I do have one suggestion though I usually wire my beans by interface not implementation I would like to see something more like this:
'public static MockRestServiceServer createServer(RestOperations restOperations)' I had to change that to use it properly in my code I don't put getters for the RestTemplate in my code like was done in spring-social.
Also you might want to run sonar/pmd/findbugs etc as it raised some flags on some random things like failure to close a BufferedReader in the ResponseCreators class.
Thanks for your work on this Craig!
spring-projects-issues commentedon Apr 10, 2012
Rossen Stoyanchev commented
The project is currently located at https://github.com/SpringSource/spring-test-mvc. The plan is to move the code to the spring-test module for Spring 3.2.