Unit testing 在Mule中对流进行单元测试时模拟过滤器
我有一个流,我想测试如下:Unit testing 在Mule中对流进行单元测试时模拟过滤器,unit-testing,testing,mule,esb,Unit Testing,Testing,Mule,Esb,我有一个流,我想测试如下: <flow name="MyFlow" processingStrategy="synchronous"> <all> <processor-chain> <and-filter> <filter ref="Filter1" /> <filter ref="Filter2"
<flow
name="MyFlow"
processingStrategy="synchronous">
<all>
<processor-chain>
<and-filter>
<filter ref="Filter1" />
<filter ref="Filter2" />
<filter ref="Filter3" />
</and-filter>
<!-- bla bla bla. doesnt matter for this question -->
</processor-chain>
<!-- more stuff that doesnt matter -->
</all>
</flow>
但是,这不起作用
有没有一种方法可以仅仅为了这个特定的测试而模拟这个过滤器或其部分代码
这就是我在我的测试方法中如何调用它:
flow = muleContext.getRegistry().lookupObject(
"MyFlow");
String content = "bananas";
MuleEvent result = flow.process(getTestEvent(content));
提前感谢。对于嘲弄,最好的方法是使用弹药- 在这里,您可以模拟过滤器,只返回相同的事件,使其看起来只是通过。类似于:
whenMessageProcessor("expression-filter").withAttributes(...).thenReturnSameEvent();
或者,如果您想使用标准FunctionalTestCase,我建议您使用并排配置,并提供存根配置
看起来您的过滤器已经是全局的了。因此,您可以将过滤器放置在单独的配置“filters.xml”中,例如,并在测试用例中提供“filters stubs.xml”。其中,它们可以是始终返回true的通用筛选器,如下所示:
<expression-filter expression="#[true]" name="Filter1" />
刚才使用了您提供的第二个解决方案,因为我已经并行配置了,但还没有配置munit。非常感谢。
<expression-filter expression="#[true]" name="Filter1" />
@Override
protected String getConfigResources()
{
return "main.xml, filters-stubs.xml";
}