2015-11-26 85 views
0

我有一个问题,用JUnit测试我的Spring webflows。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但路径确实存在肯定(复制和这个路径粘贴到编辑器 - 提前打开作品

我在做什么错在这里

非常感谢 - 文件。?。

我使用弹簧的Webflow-2.3.2和JUnit 4

回答

0

所以我通过在看看AbstractXmlFlowExecutionTests源发现了问题:FlowDefinitionResourceFactory.createFileResource作品不同于resourceFactory.createResource(String path, AttributeMap attributes, String flowID)第二个是使用一个类加载器而不是一个简单的文件加载器。所以解决方案是provi请在类路径中找到XML文件,以便找到它。类加载器似乎不允许只打开本地机器上的任何文件。

我想我会在我的maven构建中添加一个步骤,将所有流定义复制到目标/ WEB_INF目录,仅用于测试目的。

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

也许有人可以提出更好的解决方案?