【发布时间】:2011-03-08 13:36:35
【问题描述】:
在网上冲浪了几个小时寻找这个问题的答案,最后我决定在这里发布这个问题。
我正在使用 struts 2 junit 插件来测试 struts 2 应用程序的一些操作。主要的 struts 配置文件(struts.xml)是这样的:
<struts>
<package name="default" extends="struts-default">
</package>
<include file="/com/jmc/textil/productcard/action/productcard.xml"/>
<!--More includes...-->
</struts>
productcard.xml 文件:
<struts>
<!--Some other packages...-->
<package name="productClasification" namespace="/productClasification" extends="default">
<!--More actions...-->
<action name="edit" method="edit" class="com.jmc.textil.productcard.action.ProductClasificationAction">
<result>/main/jsp/json_struts2.jsp</result>
</action>
</package>
</struts>
我有一个扩展 StrutsTestCase 的测试类,以及一个用于“/productClasification/edit”操作的测试方法。当进行以下调用时:
ActionProxy proxy = getActionProxy("/productClasification/edit.action");
ProductClasificationAction clasificationAction =
(ProductClasificationAction) proxy.getAction();
由于无法定位操作而引发异常。默认情况下,StrutsTestCase 使用 struts.xml,但其他 struts 配置 xml 文件呢?
提前致谢。
【问题讨论】:
-
我可能会稍后再回来重温,但让我为未来的访问者提供一个大纲。 web.xml 中 FilterDispatcher 的配置 init 参数告诉 web 应用程序要查找哪些 .xml 文件。假设使用 spring-mock api,您将创建一个 MockFilterConfig 选项。您为此 FilterConfig 对象设置初始化参数(config 是带有您的 xml 文件名称的参数),然后使用此 FilterConfig 初始化一个 FilterDispatcher。可能更进一步,但这听起来很接近。