How to check whether a string contains a substring in Mule?

Clem picture Clem · May 12, 2017 · Viewed 7.1k times · Source

I want to use the Assert Equals component to find if a string exists in my payload. I give an example:

Txt|Name=ST CLAUD|Country=SPAIN|Txtld=45

I want to search if the payload contains the string "SPAIN" Is there a mule expression MEL to do that?

Thank you in advance

Answer

Yevgeniy picture Yevgeniy · May 12, 2017

you should use Assert True instead of Assert Equals and use the contains method defined in java.lang.Stirng (assumed payload is of type String!).

example:

<munit:test name="dataweaveTest" description="MUnit Test">
    <munit:set payload="Txt|Name=ST CLAUD|Country=SPAIN|Txtld=45" doc:name="Set Message"/>
    <munit:assert-true doc:name="Assert True"
        condition="#[payload.contains('SPAINA')]" />
</munit:test>

here is what it looks like in AnypointStudio: enter image description here