DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Effective Engineering Feedback: Software Testing
  • The LLM Selection War Story: Part 2 - The Six LLM Failure Archetypes That Will Wreck Your Production System
  • Agentic Development: My Invisible Dev Team
  • Clean Code in the Age of Copilot: Why Semantics Matter More Than Ever

Trending

  • Top JavaScript/TypeScript Gen AI Frameworks for 2026
  • A System Cannot Protect What It Does Not Understand
  • Ujorm3: A New Lightweight ORM for JavaBeans and Records
  • Multi-Scale Feature Learning in CNN and U-Net Architectures
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Testing, Tools, and Frameworks
  4. Develop Configurable Parameterized MUnits (APIKit) in Mule 4

Develop Configurable Parameterized MUnits (APIKit) in Mule 4

This article will explain the steps to configure and validate the designed API resource in Mule 4.

By 
Sadik Ali user avatar
Sadik Ali
·
Jul. 01, 21 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
24.3K Views

Join the DZone community and get the full member experience.

Join For Free

This article will explain the steps to configure and validate the designed API resource in Mule 4.

APIKit is a critical part of API resource behavior while exposing to an external system hence unit test cases should be executed with maximum error codes supported by HTTP verbs.



Step 1

         Follow MuleSoft API LifeCycle and design API resources in RAML, import it to Anypoint Studio.


Step 2

Develop MUnit test cases along with configured parameterized input file. This parameterized file will produce as input for events triggered from MUnit flow. Flow steps to develop an MUnit test case for the scenario.

    2.1  Configured input parameterized file as below

2.2  Parameterized file will look like the given snippet:

Plain Text
 
BAD_REQUEST:
  errorType: "APIKIT:BAD_REQUEST"
  statusCode: "400"
  httpStatus: "400"
  message: ""
NOT_FOUND:
  errorType: "APIKIT:NOT_FOUND"
  statusCode: "404"
  message: "Not Found Error"
  httpStatus : "404"

METHOD_NOT_ALLOWED:
  errorType: "APIKIT:METHOD_NOT_ALLOWED"
  statusCode: "405"
  message: "Method Not Allowed Error"
  httpStatus : "405"
    
    
NOT_ACCEPTABLE:
  errorType: "APIKIT:NOT_ACCEPTABLE"
  statusCode: "406"
  message: "Not Acceptable Error"
  httpStatus : "406"
    

UNSUPPORTED_MEDIA_TYPE:
  errorType: "APIKIT:UNSUPPORTED_MEDIA_TYPE"
  statusCode: "415"
  message: "Unsupported MediaType Error"
  httpStatus : "415"
    
EXPRESSION:
  errorType: "EXPRESSION"
  statusCode: "500"
  message: "Expression Error"
  httpStatus: "500"

STREAM_MAXIMUM_SIZE_EXCEEDED:
  errorType: "STREAM_MAXIMUM_SIZE_EXCEEDED"
  statusCode: "500"
  message: "Stream Maximum Size Exceeded Error"
  httpStatus: "500"
  
NOT_IMPLEMENTED:
  errorType: "APIKIT:NOT_IMPLEMENTED"
  statusCode: "501"
  message: "Not Implemented"
  httpStatus: "501"

2.3 Steps in MUnits

  • Flow-ref: configure API main flow.
  • Assign message and status code to variable to reuse in assert component.

          variable: munitStatusCode

       variable: munitStatusCode


  • Configure Assert expression, MuleSoft integration flow points exception as below assumed in assert component.
TypeScript
 
import * from dw::test::Asserts 
 ---
payload must equalTo (
	{
        "code": vars.munitStatusCode,
        "message": vars.munitMessage
      }
  )


  • Below will be the final flow of MUnit to evaluate configured input in the parameterized file:

  • Run the MUnit test cases to assess outcomes with scenarios...

Useful link:  Parameterized

unit test

Opinions expressed by DZone contributors are their own.

Related

  • Effective Engineering Feedback: Software Testing
  • The LLM Selection War Story: Part 2 - The Six LLM Failure Archetypes That Will Wreck Your Production System
  • Agentic Development: My Invisible Dev Team
  • Clean Code in the Age of Copilot: Why Semantics Matter More Than Ever

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook