I am trying to write an integration testing for one of the web components.
I am trying to use Spring Mock classes and I am getting below errors.
Caused by: java.lang.IllegalStateException: No thread-bound request found:
Are you referring to request attributes outside of an actual web request,
or processing a request outside of the originally receiving thread?
If you are actually operating within a web request and still receive this message,
your code is probably running outside of DispatcherServlet/DispatcherPortlet:
Am I doing anything wrong. I have spent more than a day to figure out where I am doing wrong and searched through API's. But I did not find any API from where I can get the registered request object. I think I am doing some fundamental mistake which I am not able to figure it out.
Business logic requires a locale object which controller gets by calling LocaleService.getLocale(). LocaleService is a request-scoped bean with a scoped proxy with autowiring enabled so that the HttpServletRequest is injected.
I am thinking above exception is somewhat related to this. different request objects are being used. I tried to mock LocaleService.getHttpServletRequest() method to return mock request object. But it did not work.
Any Suggestions?