Java JUnit和SpringWebflow

Java JUnit和SpringWebflow,java,spring,junit4,spring-webflow,Java,Spring,Junit4,Spring Webflow,我在用JUnit测试SpringWebFlows时遇到问题 正如文档中所建议的,我编写了一个扩展AbstractXmlFlowExecutionTests的测试类 public class MyFlowTest extends AbstractXmlFlowExecutionTests { MockExternalContext context = new MockExternalContext(); String workingDirectory = null; @

我在用JUnit测试SpringWebFlows时遇到问题

正如文档中所建议的,我编写了一个扩展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
时,名称不正确,因此出现异常,消息
无法找到要从中继承的流“main/parentflow”

当我使用
resourceFactory.createResource(字符串路径,null,“main/parentflow”
时,从未找到定义流的.xml。异常会打印路径并显示FileNotFound,但路径确实存在(将此路径复制并粘贴到编辑器-File-Open works)

我做错了什么

非常感谢


我正在使用spring-webflow-2.3.2和jUnit 4,所以我通过查看AbstractXmlFlowExecutionTests的源代码发现了问题:
FlowDefinitionResourceFactory.createFileResource
的工作方式与
resourceFactory.createResource不同(字符串路径、属性映射属性、字符串流ID)
。第二种方法是使用类加载器而不是简单的文件加载器。因此,解决方案是在类路径中提供XML文件,以便可以找到它。似乎不允许类加载器仅打开本地计算机上的任何文件

我想我会在maven构建中添加一个步骤,将所有流定义复制到target/WEB\u-INF目录,只是为了测试目的

对我来说,这似乎是丑陋的,我不明白为什么createResource使用这种方法


也许有人可以建议一个更好的解决方案?

尽管我已经很老了,但我仍然倾向于回答:最近我创建了一个库(现在取决于spring WebFlow 2.3.3-RELEASE)来简化对web流的单元测试。你可以提供一个文件或URL资源,或者定义你自己的ResourceMapper(对象->FlowDefinitionResource)使用。我肯定我错过了很多选项,但我仍然建议您尝试一下。请通过Jcenter查看