I am going to unit test a Spring MVC controller (or whole site if possible).
I want to pass a URL (as a string), e.g. "/metrics/filter?a1=1&a2=2&a3=abcdefg&wrongParam=WRONG" and check what controller will return.
Is there an easy way to do it?
Example:
@RequestMapping(value = {"/filter"}, method = RequestMethod.GET)
@ResponseBody
public List<MetricType> getMetricTypes(
@RequestParam(value = "subject", required = false) Long subjectId
,@RequestParam(value = "area", required = false) Long areaId
,@RequestParam(value = "onlyImmediateChildren", required = false) Boolean onlyImmediateChildren
,@RequestParam(value = "componentGroup", required = false) Long componentGroupId
,@RequestParam(value = "hasComponentGroups", required = false) Boolean hasComponentGroups
) throws Exception
{
//some code
}
Many thanks
Maxim
UPDATED
- I only use GET, not post
- I do not use model objects (see example above)
- My system is a web service which has a lot of "/someEntity/filter?a1=123&a2=1234&a3=etc" method with various combinations of parameters. I am not sure it is practical to use model objects in this case.