Nav

Set Message Processor

Overview

The Set Message Processor provided by MUnit allows you to define Mule messages.

This message processor is normally used at the beginning of an MUnit test, to define the first message to send to the flow being tested.

Defining Messages

The example below shows how to define a simple Mule message.

set-payload-munit


    
            
         
1
2
<munit:set payload="#[]">
</munit:set>
Attribute Name Description

payload

Defines the value of the payload’s message. It accepts MEL expressions. If left as a literal, it assumes a string value.

encoding

Defines the encoding of the message. This attributes is optional.

mimeType

Defines the mime type of the message. This attributes is optional.

If you wish to set the payload to be a Spring bean, you can make use of the MUnit MEL function getBeanFromMuleContext('bean_name'). See Assertion for details.

Defining Message Attributes

Using the MUnit Set message processor, you can easily specify the message properties of any scope.

The example below shows how to define one of each property scopes:

set-payload-munit-2


    
            
         
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<munit:set payload="#[]">
  <munit:invocation-properties>
    <munit:invocation-property key="key" value="#['value']"/>
  </munit:invocation-properties>

  <munit:inbound-properties>
    <munit:inbound-property key="key" value="#['value']"/>
  </munit:inbound-properties>

  <munit:session-properties>
    <munit:session-property key="key" value="#['value']"/>
  </munit:session-properties>

  <munit:outbound-properties>
    <munit:outbound-property key="key" value="#['value']"/>
  </munit:outbound-properties>
</munit:set>

All the properties have the same set of attributes:

Table 1. Property Message Processor’s Attributes
Attribute Name Description

key

The key of the property being set.

value

The content of the property. It accepts MEL expressions. If left as a literal, it assumes a string value.

encoding

Defines the encoding of the message. This attributes is optional.

mimeType

Defines the mime type of the message. This attributes is optional.

You can define as many properties per each scope as you need for your test.

If you define two properties in the same scope with the same key, be aware that one would end up overwriting the other.

Defining Null Payloads

In Mule a message payload never contains Null. Instead, Mule has a representation called NullPayload.

In some scenarios, your test requires you to send such a payload. For these cases, MUnit provides the null-payload message processor.

set-null-payload-munit


    
            
         
1
<munit:set-null-payload/>