我在使用JUnit测试我的Spring webflow时遇到问题。
按照文档中的建议,我编写了一个扩展AbstractXmlFlowExecutionTests的测试类。
public class MyFlowTest extends AbstractXmlFlowExecutionTests {
MockExternalContext context = new MockExternalContext();
String workingDirectory = null;
@Override
protected FlowDefinitionResource getResource(FlowDefinitionResourceFactory resourceFactory) {
return resourceFactory.createFileResource("WebContent/flows/myflow-flow.xml");
}测试中的webflow继承自一个抽象的父webflow,它定义了一些全局转换。所以我尝试重写getModelResources来提供这个父webflow。但这根本不起作用。
@Override
protected FlowDefinitionResource[] getModelResources(FlowDefinitionResourceFactory resourceFactory) {
FlowDefinitionResource[] flowDefResources = new FlowDefinitionResource[1];
see below...
return flowDefResources;
}我的具体问题是:
当我对父流使用resourceFactory.createFileResource时,名称不正确,因此我收到了消息Unable to find flow 'main/parentflow' to inherit from的异常。
当我使用resourceFactory.createResource(String path, null, "main/parentflow"时,永远找不到定义流的.xml。异常打印路径并显示为FileNotFound,但该路径确实存在(将此路径复制并粘贴到编辑器-文件-打开works。
我在这里做错了什么?
在此之前,非常感谢您。
我使用的是spring-webflow-2.3.2和jUnit 4
发布于 2015-11-27 17:24:51
因此,我通过查看AbstractXmlFlowExecutionTests的源代码发现了问题:FlowDefinitionResourceFactory.createFileResource的工作方式与resourceFactory.createResource(String path, AttributeMap attributes, String flowID)不同。第二种是使用类加载器而不是简单的文件加载器。因此,解决方案是在类路径中提供XML-File,以便可以找到它。似乎不允许类加载器打开本地计算机上的任何文件。
我想我应该在maven构建中添加一个步骤,将所有的流定义复制到target/WEB_INF目录中,以便进行测试。
对我来说,这似乎是丑陋的,我不明白为什么createResource要使用这种方法。
也许有人能提出一个更好的解决方案?
https://stackoverflow.com/questions/33943910
复制相似问题