Having a basic Spring Contoller i'd like to Unittest the Request Mapping (not the Method itself), if the doCriticalStuff Method is indeed called
package org.foo;
@Controller
public class HelloWorldController implements IHelloWorldController
{
@RequestMapping(value = "/b/c/", method = RequestMethod.GET)
public void doCriticalStuff(HttpServletRequest request, HttpServletResponse response){
//...
}
}
Right now I'm doging this via curl -X GET http://myIP:myPort/b/c/ from commandline in a manual way.
Any Ideas on how to automate it?
I could setup a Jetty instance, send a request and see if i get the expected response but isn't there an easier way provided by Spring?
Related Post: How to test binders/property editors used on spring 2.5 controllers
I'd use a AnnotationMethodHandlerAdapter and call adapter.handle. Just send in mock request and response objects along with your controller and spring should take care of the rest.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With