Nav

About the Spy Event Processor

The Spy Processor allows you to spy what happens before and after an event processor is called.
This allows you to validate, for example that a selected Mule Event reaches a specific event processor containing a specific payload or variable.

Setting a spy processor tells MUnit to run a set of instructions (usually assertions or verifications) before and/or after the execution of the spied event processor.

Assume that you have this Mule Application


         
      
1
2
3
4
5
6
7
8
9
10
<http:listener-config name="HTTP_Listener_config">
  <http:listener-connection host="0.0.0.0" port="${http.port}" />
</http:listener-config>

<flow name="testFlow">

  <http:listener config-ref="HTTP_Listener_config" path="/"/>
  <set-payload value="#['Real_Payload']"/>

</flow>

You can configure the spy processor to spy any HTTP Listener and assert that they payload is null before reaching the component, and not null after it’s been processed:


         
      
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<munit:test name="suiteTest" >

  <munit:enable-flow-sources >
    <munit:enable-flow-source value="testFlow" />
  </munit:enable-flow-sources>

  <munit:behavior >

    <munit-tools:spy processor="http:listener">

      <munit-tools:before-call >
        <munit-tools:assert-that expression="#[payload]" is="#[MunitTools::nullValue()]"/>
      </munit-tools:before-call>

      <munit-tools:after-call >
        <munit-tools:assert-that expression="#[payload]" is="#[MunitTools::notNullValue()]"/>
      </munit-tools:after-call>

    </munit-tools:spy>

  </munit:behavior>

</munit:test>

Or even to spy any HTTP Listener, whose path is configured to be "/"


         
      
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<munit:test name="suiteTest" >

  <munit:enable-flow-sources >
    <munit:enable-flow-source value="testFlow" />
  </munit:enable-flow-sources>

  <munit:behavior >

    <munit-tools:spy processor="http:listener">
      <munit-tools:with-attributes >
        <munit-tools:with-attribute attributeName="path" whereValue="/" />
      </munit-tools:with-attributes>

      <munit-tools:before-call >
        <munit-tools:assert-that expression="#[payload]" is="#[MunitTools::nullValue()]"/>
      </munit-tools:before-call>

      <munit-tools:after-call >
        <munit-tools:assert-that expression="#[payload]" is="#[MunitTools::notNullValue()]"/>
      </munit-tools:after-call>

    </munit-tools:spy>

  </munit:behavior>

</munit:test>

As shown above, this processor allows you to define actions for before and after calling the spied processor. However, keep in mind that the spy processor does not modify the original Mule Event.
If you set variables, attributes, or modify the payload inside a Spy, these changes won’t persist outside the processor.
Overall, you should use the Spy processor to verify or assert.

In this topic:

We use cookies to make interactions with our websites and services easy and meaningful, to better understand how they are used and to tailor advertising. You can read more and make your cookie choices here. By continuing to use this site you are giving us your consent to do this.

+