Создать сообщение с входящими свойствами в MUnit

Я пытаюсь провести модульное тестирование заводного компонента.

    <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");
    }

person Sudarshan    schedule 20.08.2015    source источник


Ответы (1)


Вы можете установить его в сообщении, полученном из тестового события:

import org.mule.api.transport.PropertyScope;

...

MuleEvent testEvent = testEvent("something");
testEvent.getMessage().setProperty("x-messageid", "somevalue",  PropertyScope.INBOUND);
person Ryan Carter    schedule 20.08.2015