Contact Free trial Login

Run Custom Event Processor

The Run Custom event processor allows you to assert the Mule event content against a custom assertion.

Although it’s not necessary to add any extra dependencies to your pom.xml file, you must your custom assertion class to the mule-artifact.json file as an exported resource.

For example, you can define the following assertion in Java:

public class CustomAssertion implements MunitAssertion {

    @Override
    public void execute(TypedValue expression, Object params) throws AssertionError { (1)
        if (!"Hello World".equals(expression.getValue())) { (2)
            throw new AssertionError("Error the payload is incorrect");
        }
     }

}
1 Implement the only method in the interface public void execute(TypedValue expression, Object params) throws AssertionError
2 Run your custom logic, which in this case validates that the message’s payload is Hello World.

And then use the Run Custom Event Processor to run it:

<munit-tools:run-custom
  assertion="com.example.CustomAssertion" (1)
  expression="#[payload]"/>
1 The assertion field needs to have the canonical class name of your custom assertion and the class needs to be exported.

To export it when packaging your application, add the CustomAssertion to your mule-artifact.json

{
    "name": "mule-application",
    "minMuleVersion": "4.2.0",
    "classLoaderModelLoaderDescriptor": {
        "id": "mule",
        "attributes": {
            "exportedResources": [
                "resources/CustomAssertion.java"
            ]
        }
    }
}

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.