0% found this document useful (0 votes)
170 views5 pages

Munits

Uploaded by

G ravi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
170 views5 pages

Munits

Uploaded by

G ravi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

What is Spy in Munits?

mule-studio mule-esb munit. we are observing a behavior where in the variables set in the
"before-call" and "after-call" blocks of the spy munit processor are not being recognized in
the actual mule flows.

What is a mock message?


Mock SMS messages appear with their envelopes slightly greyed out so that they appear
separate to real SMS messages. Above you can see the difference between a real and
a Mock SMS within an Inbox

What is event processor in Mule?


Explore Mule 4 Message, events, and variables.

A Mule event contains the core information processed by the runtime. ... The event source
produces a Mule event. The Mule event travels sequentially through the components of a
flow.

Assert that ?

Assert That Event Processor

The Assert That event processor allows you to run assertions to validate the state of a Mule
event’s content. You can use the Assert That processor to validate the Mule event after the
production code runs.

The Assert That processor uses a set of DataWeave functions called  MUnit matchers  to define
the assertion conditions for any value in an expression.

For example, to assert that a payload is equal to a certain value, configure the Assert That
processor using the  equalTo()  matcher.

<munit-tools:assert-that
expression="#[payload]"
is="#[MunitTools::equalTo('example')]"
message="The payload should be ‘example’"/>

Assert Equals ?

The Assert Equals processor allows you to run assertions in order to validate the state of a
Mule Event’s content. This processor can be used to validate the Mule Event after the
production code runs.

For example, to assert that a payload is equal to a certain value, you can configure the
Assert-Equals processor the following way:
<munit-tools:assert-equals
actual="#[payload]"
expected="#[2]"
message="The payload should be 2"/>

Mock When Event Processor ?

The Mock When processor allows you to mock an event processor when it matches the defined
name and attributes.

For example, you can use the Mock Event processor to mock a POST request with a mocked
payload:

<munit-tools:mock-when processor="http:request">
<munit-tools:with-attributes>
<munit-tools:with-attribute attributeName="method"
whereValue="#['POST']"/>
</munit-tools:with-attributes>
<munit-tools:then-return>
<munit-tools:payload value="#['mockPayload']"/>
</munit-tools:then-return>
</munit-tools:mock-when>

You can set the  processor  attribute to define the processor to mock and the  with-
attribute  element to define the attribute’s name and value. In the example above you are
defining a POST method.

Verify Event Processor ?

The Verify Event processor allows you to verify if a processor was called.

For example, you can validate if a specific processor has been called with a particular set of
attributes a specific number of times.

When defining a verification, you are telling MUnit to fail a test if the verification is not successful.

You can define verifications over any processor, even if you haven’t created a mock for it.

<munit-tools:verify-call processor="http:request" atLeast="1">


<munit-tools:with-attributes>
<munit-tools:with-attribute attributeName="method"
whereValue="#['GET']" />
</munit-tools:with-attributes>
</munit-tools:verify-call>

Set Event Processor ?

The Set Event Processor allows you to define a Mule Event.


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.

The example below shows how to define a simple payload of a Mule Message:

<munit:set-event cloneOriginalEvent="false">
<munit:payload value="#['payload_value']" mediaType="text/plain"
encoding="UTF-8"/>
</munit:set-event>

The set-event has the cloneOriginalEvent property. If set to true, it clones the event produced by
your code.
By default, the value of this property is false.

The payload element in the Set Event processor has the following attributes:

Attribute Name Description

value Defines the value of the payload’s message.

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

mediaType Defines the mime type of the message. This attribute is optional.

Storage Event Processors ?

The Storage processors allows you to manage temporary storage during your tests.

All storage is cleared as soon as the test ends.

Store operation

Stores the given data associated with the given key. If  value  not set, it defaults to
the  payload .
<munit-tools:store key="myKey">
<munit-tools:value>#[person : { name: 'John', lastName:
'Smith' }]</munit-tools:value>
</munit-tools:store>

Retrieve operation

Retrieves the data associated with the given key

<munit-tools:retrieve key="myKey"/>

Remove operation

Removes and returns the data associated with the given key

<munit-tools:remove key="myKey"/>

Queue Event Processors ?

The Queue event processors allow you to manage temporary queues during your test runs.

All queues are emptied as soon as the test ends.

Queue

Adds the value to the queue. If not specified, the value is taken from the  payload .

<munit-tools:queue>
<munit-tools:value>#[1]</munit-tools:value>
</munit-tools:queue>

You can specify the queue’s name to which the value should be added. If not specified, the
default queue will be used.

<munit-tools:queue queueName="CUSTOM_QUEUE_1">
<munit-tools:value>#[1]</munit-tools:value>
</munit-tools:queue>

Dequeue

Removes the last element of the queue, if the queue is empty, it waits until an element is
queued.

<munit-tools:dequeue/>

You can specify a timeout when waiting for an element to be queued:


<munit-tools:dequeue timeout="1000" timeoutUnit="SECONDS"/>

Like the queue operation, you can specify the queue’s name from which to dequeue. If not
specified, the default queue will be used.

<munit-tools:dequeue queueName="CUSTOM_QUEUE_1"/>

Queue Size

Function that obtains the queue size.

<munit-tools:assert-that expression="#[MunitTools::queueSize()]"
is="#[MunitTools::equalTo(2)]" />

Like the other operations, you can specify the queue from which to the get the size. If not
specified, the default queue will be used.

<munit-tools:assert-that
expression="#[MunitTools::queueSize('CUSTOM_QUEUE_1')]"
is="#[MunitTools::equ

You might also like