Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Testing web application using Spring Mock

 
Saritha Penumudi
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
Alfred
unit testing



 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic