aspose file tools*
The moose likes Testing and the fly likes Testing Service Calls in Struts 2.0 Action Class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Testing Service Calls in Struts 2.0 Action Class" Watch "Testing Service Calls in Struts 2.0 Action Class" New topic
Author

Testing Service Calls in Struts 2.0 Action Class

Jay Abrahm
Ranch Hand

Joined: May 28, 2008
Posts: 183
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]

Jay Abrahm
Ranch Hand

Joined: May 28, 2008
Posts: 183
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

Joined: May 28, 2008
Posts: 183
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

Joined: May 28, 2008
Posts: 183
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Testing Service Calls in Struts 2.0 Action Class
 
Similar Threads
Linking to servlets using href
Unit Testing
Junit testing for Struts2
Struts2: Test action classes
which design pattern is suitable for my problem