我正在尝试对groovy组件进行单元测试。
<sub-flow name="public_sf_util_munit"
doc:description="Input:Mule Message
Processing:Adds correlationId to MuleMessage
Output:MuleMessage with populated correlationId property">
<scripting:component doc:name="Add correlationId">
<scripting:script engine="Groovy"><![CDATA[String correlationId = message.correlationId;
if(message.correlationId==null){
correlationId = message.getInboundProperty('x-messageid');
if(correlationId == null){
correlationId = message.rootId;
}
}
message.correlationId = correlationId;
return message]]></scripting:script>
</scripting:component>
</sub-flow>
以下行需要一个入站邮件属性,如何将其添加到我的测试Mule消息中?我正在使用MUnit 3.6.1。
correlationId = message.getInboundProperty('x-messageid');
我到目前为止的测试如下,我需要添加入站属性
@Test
public void givenAMuleMessageWithNullCorrelationIdAndXMessageIdHeader_whenCorrelationIdIsSet_itShouldSetCorrelationWithMessageId() throws Exception {
MuleEvent testEvent = testEvent("something");
MuleEvent resultMuleEvent = runFlow("transformToOutbound", testEvent);
assertThat(resultMuleEvent).isNotNull();
assertThat(resultMuleEvent.getMessage().getCorrelationId()).isEqualTo("321");
}
答案 0 :(得分:0)
您可以在从测试事件中检索到的消息上进行设置:
import org.mule.api.transport.PropertyScope;
...
MuleEvent testEvent = testEvent("something");
testEvent.getMessage().setProperty("x-messageid", "somevalue", PropertyScope.INBOUND);