【问题标题】:Build message with inbound properties in MUnit在 MUnit 中使用入站属性构建消息
【发布时间】:2015-08-20 18:28:52
【问题描述】:

我正在尝试对一个 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");
    }

【问题讨论】:

    标签: mule munit


    【解决方案1】:

    您可以在从测试事件中检索到的消息上设置它:

    import org.mule.api.transport.PropertyScope;
    
    ...
    
    MuleEvent testEvent = testEvent("something");
    testEvent.getMessage().setProperty("x-messageid", "somevalue",  PropertyScope.INBOUND);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-15
      • 1970-01-01
      • 2016-11-08
      • 1970-01-01
      • 2016-08-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多