• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Testing Service Calls in Struts 2.0 Action Class

 
Jay Abrahm
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the action test case below I was able to test the loop which did not have the service call using a very useful struts extension (attached) that I had downloaded from another website.

However, I am not sure on how to test the second scenario commented out in the test method. Should I mock the service call or else is there some other pattern that I need to apply



StrutsTestContext.gif
http://glindholm.wordpress.com/2008/06/30/unit-testing-struts-2-actions/
[Thumbnail for StrutsTestContext.gif]
 
Jay Abrahm
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have created a new Mock Service to extend that service and set it in the session assuming that the Dependency Injection would be overridden as mentioned in the mockrunner examples



And I have changed LoggableActionTest second scenario to as follows


But it still goes to the actual LoggableServiceImpl instead of the MockLoggableServiceImpl. What did I mess up or not understand ?
 
Jay Abrahm
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adding

LogabbleService ls = (LogabbleServiceImpl)session.get(LoggableServiceImpl.class.getName());

to the LoggableAction solved the problem, but then I cant do that since it would mess the actual functionality.

Any idea on how I can override the setting of LoggableService with my MockLoggableServiceImpl.
 
Jay Abrahm
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
MMmm ..

http://www.javaworld.com/javaworld/jw-11-2006/jw-1109-test.html?page=1

Got me worried. So is there no way to pass a mock service into my action class.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic