StrutsSpringTestCase – getActionMapping() – Does it search for actions in struts.xml?


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?

The Code:

ActionMapping mapping = getActionMapping("/custSeach.action");// Intentionally missed 'r'.
assertEquals("custSeach", mapping.getName());

This passes. But there is no custSeach action in my struts.xml mapping.

More details:

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");

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.

The 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

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published