Announcement Announcement Module
Collapse
No announcement yet.
spring-test-mvc and @Requestbody/@Responsebody Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • spring-test-mvc and @Requestbody/@Responsebody

    I want to test a controller using the MockMvc class (which i installed from the spring-test-mvc project, as it is not yet included into the latest spring version)

    I basicaly follow the examples in spring-test-mvc
    The method I'm testing is a "put" that accepts an object (of class "Device" ) as RequestBody.

    Code:
    	@RequestMapping( value="/device", method=RequestMethod.PUT )
    	public @ResponseBody String updatePosition( @RequestBody Device d)
    	{         
                              .............
    		return "OK";
    	}
    How can should I create the test?, i guess it should look something like:

    Code:
        Device d = new Device();
        mockMvc.perform(put("/device").body(..????
                   .andExpect(response().body("OK")
    I guess that the requestbuilder should be used somehow to get the object into the request...
    Also, in "production" a client (using RestTemplate) will marshall the object to xml or json. How can this be configured in the test?

  • #2
    Hi,
    I also would be interested in using MockMvc, but is currently not included in Spring 3.1.0.M2
    In which milestone or RC version will be included?

    Thank you.

    Comment

    Working...
    X