测试Mule中的子流程 [英] Testing sub-flows in Mule
问题描述
我已经开始将测试用例写入我的Mule项目了。
I have started writing test cases to my Mule project.
我已经为我的主要流程编写了功能测试用例,如下所示。
I have written the functional test case for my Main Flows as follows.
public void testMainFlow_1() throws Exception{
MuleClient client = muleContext.getClient();
MuleMessage result = client.send(helloServiceAddress, fileAsString("SamplePayloads/input_Request.xml"), properties);
assertNotNull("Null Result", result);
assertEquals(result.getPayloadAsString(), fileAsString("SampleResponses/sampleResponse.xml"));
}
但我如何测试我的子流程。他们没有任何终点。那么我怎样才能将有效载荷传递给它们并对其进行测试。
But how can I test my sub-flows. They don't have any end-points. So how can I pass payload to them and test it.
以下是我的流量配置。
<flow name="main_flow" >
....
....
<flow-ref name="subflow_1" />
....
....
<flow-ref name="subflow_2" />
....
....
</flow>
<sub-flow name="subflow_1">
....
<some-transformer ... />
<out-bound call to web-service />
<some-transformer ... />
....
</sub-flow>
<sub-flow name="subflow_2">
....
<some-transformer ... />
<out-bound call to web-service />
<some-transformer ... />
....
</sub-flow>
推荐答案
使用 FunctionalTestCase
它应该简单如下:
MessageProcessor subFlow = muleContext.getRegistry().lookupObject("subflow_1");
MuleEvent result = subFlow.process(getTestEvent("test_data"));
但它不起作用。
目前,最好的方法是IMO包含一个包含流的测试配置要测试的子流的包装器,并在 FunctionalTestCase
中将主测试配置与此测试配置一起加载。
For now, the best approach IMO consists in having a test config that contains flow wrappers for the sub-flows you want to test and load this test config alongside your main config in the FunctionalTestCase
.
@ genjosanzo的方法也有效,但它基于将子流与来自测试代码本身的预先存在的主流相关联。我个人认为创建测试流程会更严格。
@genjosanzo's approach works too but it is based on associating the sub-flow with a pre-existing main-flow from test code itself. I personally think it would be stricter to create test flows instead.
这篇关于测试Mule中的子流程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!