• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Testing Service Calls in Struts 2.0 Action Class

 
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
[Thumbnail for StrutsTestContext.gif]
http://glindholm.wordpress.com/2008/06/30/unit-testing-struts-2-actions/
 
Jay Abrahm
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic