Groovy on Grails Blog
Specifying request attribute in service integration testsToday I ran into some problems when wanting to add request dependant tests to my integration test suite. The controller tests in grails are already mocked with MockHttpServletRequest, MockHttpServletResponse, and MockHttpSession , but what about services??
In my case I wanted the RequestContextHolder.getRequestAttributes() to contain a 'request' so I could get the servername from that inside my session scoped service.
So what I did was: def request = new MockHttpServletRequest(); request.setServerName("test2.localhost") RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request)) |
||
|




