我已经开始将测试用例写入我的Mule项目了。
我已经为我的主要流程编写了功能测试用例如下。
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"));
}
但是我如何测试我的子流程。他们没有任何终点。那么如何将有效载荷传递给它们并进行测试呢。
以下是我的流量配置。
<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>
答案 0 :(得分:5)
使用FunctionalTestCase
它应该简单如下:
MessageProcessor subFlow = muleContext.getRegistry().lookupObject("subflow_1");
MuleEvent result = subFlow.process(getTestEvent("test_data"));
目前,最好的方法是IMO包含一个测试配置,其中包含要测试的子流的流包装器,并在FunctionalTestCase
的主配置中加载此测试配置。
答案 1 :(得分:2)
通过使用最新的Mule版本,我们可以使用以下脚本测试子流程:
SubflowInterceptingChainLifecycleWrapper subFlow = getSubFlow("subflowName");
subFlow.initialise();
MuleEvent event = subFlow.process(getTestEvent(""));
MuleMessage message = event.getMessage();
assertEquals(expect, message.getPayload());
答案 2 :(得分:1)
从测试用例调用子流非常简单,这是一个例子:
@Test
public void invokeSubFlow() throws Exception {
MessageProcessor mp = (MessageProcessor) muleContext.getRegistry()
.lookupObject("subflow_2");
FlowConstruct parentFlow = muleContext.getRegistry().lookupFlowConstruct("main_flow");
((FlowConstructAware) mp).setFlowConstruct(muleContext.getRegistry()
.lookupFlowConstruct("subflow_2"));
Lifecycle lc = (Lifecycle) mp;
lc.initialise();
lc.start();
MuleMessage muleMessage = new DefaultMuleMessage("test", muleContext);
MuleEvent event = new DefaultMuleEvent(muleMessage,
MessageExchangePattern.REQUEST_RESPONSE,
new DefaultMuleSession(parentFlow,muleContext));
mp.process(event);
}