StrutsSpringTestCase-getActionMapping()-是否在struts.xml中搜索动作? [英] StrutsSpringTestCase - getActionMapping() - Does it search for actions in struts.xml?
问题描述
我正在尝试通过扩展StrutsSpringTestCase
编写针对Struts2动作的测试.
参考.
I am trying to write test for Struts2 action by extending StrutsSpringTestCase
. The
reference.
当我调用getActionMapping(<action url>)
时,它是否在struts.xml文件中搜索动作映射?
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());
通过.但是我的struts.xml
映射中没有custSeach
动作.
This passes. But there is no custSeach
action in my struts.xml
mapping.
修改:更多详细信息
struts.xml
在类路径中.我可以打印从类路径加载的所有文件,而struts.xml
是其中之一.
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
确实存在.但这仍然会引发错误
custSearch
does exist. But it's still throwing the error
没有为动作名称
custSearch
映射的动作.
推荐答案
第一个方法将返回映射以尝试,但不能保证将执行此操作.
Th first method returns a mapping to try, it doesn't guarantee that this action will be executed.
在启动时会解析struts.xml
文件以创建运行时配置,因此,此方法实际上使用
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.
这篇关于StrutsSpringTestCase-getActionMapping()-是否在struts.xml中搜索动作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!