I am trying to write test for Struts2 action by extending
StrutsSpringTestCase. The reference: Unit Testing.
When I call
getActionMapping(<action url>), does it search
struts.xml file for the action mapping?
ActionMapping mapping = getActionMapping("/custSeach.action");// Intentionally missed 'r'. assertEquals("custSeach", mapping.getName());
This passes. But there is no
custSeach action in my
struts.xml is in the class path. I could print all files loaded from the classpath and
struts.xml is one of them.
also, I tried the following as well:
ActionProxy proxy = getActionProxy("custSearch"); assertNotNull(proxy);
custSearch does exist. But it’s still throwing the error
There is no Action mapped for action name custSearch.
Th first method returns a mapping to try, it doesn’t guarantee that this action will be executed.
struts.xml files is parsed on startup to create a run-time configuration, so it has less meaning to this method which is actually uses
ActionMapper that could have different implementation.
The second method does actually returns the action config (if no exception is thrown), so the action can be executed.
Answered By – Roman C