97008 48403
+91 40-27177600

Blog

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

single-blog

From the technical center of excellence of Massil Technologies, our technology leaders make it easy to understand the complex situations you come across in Mule ESB from the experience of Massil Technologies to have countered them in their experience of working on client projects in real time. This blog talks about how to check whether a string contains a substring in Mule ESB. This blog is a part of series of blogs being authored and published by Massil Technologies for the benefit of the IT community globally.

To check whether a string contains a substring, we will need to install Mule ESB testing framework called Munit. MUnit is a Mule testing framework that lets you easily automate testing Mule applications, using both unit and integration tests. MUnit also provides a set of tools, such as a message processor mocking framework that lets you test units of code in actual isolation.

Installing Munit:

To use MUnit in Studio, you have to install it from the website. To install MUnit, follow these steps:

  • Verify that your version of Studio is 5.2.0 (July 2015 release) or newer.
  • Add the MUnit update site :
  • Go to HelpInstall New Software.
  • Studio displays the Available Software In the Work with: field, paste the     MUnit update site: http://studio.mulesoft.org/r4/munit
  • Check Munit and Munit Tools for Mule, as shown below.
  • Click Next to complete the installation.

  • Step1Drag and drop an HTTP listener from the palette

  • Step2:In the HTTP Listener’s properties, create a new configuration element for it. Let the port stay as the default value 8081 and set the host to localhost.Step3:Drag and drop a set payload from the palette

  • Step4: The Munit FolderUsing MUnit automatically adds a new folder, src/test/munit, to your project.

  • Creating a New MUnit Test in Studio

    MUnit Studio integration is mainly built around XML-based tests. Most of the MUnit-Studio integration tools guide you in the creation of these tests.

    There are two basic ways to create a new MUnit test in Studio:

    • Choose a specific flow by right clicking the flow and selecting MUnit.
    • Use the wizard, which allows you to create a test for any flow or application in the workspace.

    Creating a Test for a Specific Flow

    To create a test for a specific flow, right-click the flow, then select MUnit > Create a new <flow_name> suite.

  • This action:
    • Creates a new test suite named after the XML file where the flow resides, in this case munit2.xml. Studio displays the test suite on a new tab, next to the tab for the original application:

  • Imports the XML file to the test suite
  • Creates a new MUnit test like the one shown below

Step5:

To add an MUnit message processor to the test shown above, drag it from the Palette to the Testarea before and after the flow-ref.set message and assert true

in assert true

Running a Test Suite

To run a test suite, right-click the empty canvas where the suite resides, then select Run MUnit suite.

Studio displays the output from the running suite in the console.

Running a Test

To run a test, right-click the name of the test, then select Run MUnit Test.

To check that the test is actually running, view the output in the console. In order not to overwhelm the user, the default output provides little information, but enough to verify that the test has run.

An alternative way to run a test is to use the MUnit tab (see below).

  1. Select the desired test in the MUnit tab.
  2. Right-click the test, then select Run.

The MUnit tab displays successful tests in green, failed tests in red.

The Coverage button in the image above allows you to see what flow the test covered, and the percentage of message processors in the flow that was covered by the test:

If you run more than one test, the MUnit tab displays a history of run tests. For failed tests, the Errorsbutton displays the stack trace, which you can copy to your clipboard. To copy the stack trace, right-click the name of the failed test, then select Copy Stack Trace.

As you can see in the image above, you can also use the MUnit tab to Running Your Test or debug your test, by selecting the appropriate menu option.

Clicking the debug button or the play button on the top right causes the last run or debug to be rerun. This rerun includes all tests that were run on the previous one. You can also select a single test from the previous run to rerun on its own.

Hence, we have gone through the step by step process to depict the way Massil Technologies team has addressed. Hope this article from Massil Technologies was useful for you. If you have any further queries on this topic, please reach out to info@massil.tech.

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Get in touch with us

Scroll to top