File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Testing and the fly likes Testing web application using Spring Mock Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Testing web application using Spring Mock" Watch "Testing web application using Spring Mock" New topic

Testing web application using Spring Mock

Saritha Penumudi
Ranch Hand

Joined: Aug 18, 2003
Posts: 148
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?
Alfred Peterson

Joined: Aug 17, 2010
Posts: 12
Hello friends,

I had upgraded from 4.0 to 4.1 but there seem some bugs as i find that spring-mock.jar is not in the dependence.and i also created some user libs to map it with my project,what can i do with the spring-test-support libs.Can i install the miceclipse..does it work or not..?

Please provide your suggestions

Thanks and Regards:
unit testing

I agree. Here's the link:
subject: Testing web application using Spring Mock
It's not a secret anymore!