Issue
I have a service that does some work on an HttpServletRequest object, specifically using the request.getParameterMap and request.getParameter to construct an object.
I was wondering if there is a straightforward way to take a provided url, in the form of a string, say
String url = "http://www.example.com/?param1=value1¶m";
and easily convert it to a HttpServletRequest object so that I can test it with my unit tests? Or at least just so that request.getParameterMap and request.getParameter work correctly?
Solution
Spring has MockHttpServletRequest in its spring-test module.
If you are using maven you may need to add the appropriate dependency to your pom.xml. You can find spring-test at mvnrepository.com.
Answered By - pap
Answer Checked By - Gilberto Lyons (JavaFixing Admin)