Mock controller with object parameter

I'm trying to test a method with this signature:

@RequestMapping(value="/Employee/{id}", method=RequestMethod.PUT, consumes="application/json") 
@Transactional
public @ResponseBody Map update(@PathVariable Integer id, 
    @RequestBody HashMap<String, Object> information) {

}

      

The problem is that the param MockMvc attributes only take String parameters, is there a way to pass an HashMap

instance class object or object to the RequestBody parameter as a parameter?

When I try to pass HashMap

as a string, I get a MismatchException.

+3


source to share


1 answer


For this you need to use Jackson. The idea is to deserialize your objects (it doesn't matter if it's a HashMap) into a JSON string and pass it to MockMvc.



Here's a tutorial on how to do it . Just search for TestClass and see how it is used. Skip unit testing the GET requests.

+3


source







All Articles