1

I wanted to know if there was a way to mock a custom-filter that is within a sub-flow using MUnit.

I'm using Mule 3.4.0 and MUnit 3.4.0.M5.

The sample flow looks like the following.

<sub-flow name="a">
     <choice>
          <when expression="something...">
               <custom-filter doc:name="filter a">...</custom-filter>
          </when>
          <otherwise>
               ...
          </otherwise>
     </choice>
</sub-flow>

I've had to create a wrapper flow around the subflow because I get a NullPointerException whenever I try to hit the sub flow directly using the runFlow syntax. However, in doing so, I am unable to mock the custom-filter using the whenMessageProcessor syntax. Please see my attempt below.

whenMessageProcessor("custom-filter"
.withAttributes(attribute("name").ofNamespace("doc").withValue("filter a"))
.thenReturn(muleMessageWithPayload("some response");

This results in the message not being mocked.

jcb
  • 195
  • 1
  • 4
  • 20

1 Answers1

1

There are to issues here mixed up.

You having to wrap you sub-flow is a MUnit/Mule issue as commented here: How to mock a Java component within Mule Flow using MUnit

The second issue is filter mocking. Short answer is you can not, please check: https://github.com/mulesoft/munit/issues/108

Conceptually a filter is a shorthanded way of doing a choice (or an if in a normal language). One usually does not mock a choice/if it rather changes a value in a variable or in our case in the mule message payload. That's why the filter MP can not be mocked.

HTH

Community
  • 1
  • 1
Dds
  • 712
  • 5
  • 7