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
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Testing Asynchronous Systems, Part 4: A Technique-by-Level Test Strategy
  • Same Prompt, Different Test: Using AI Agent Workspaces to Make Testing Repeatable
  • Testing Business Programs Without Constructing Domain Objects
  • Why Standard Test Automation Misses the Failures That Matter in AI Agent Systems

Trending

  • AI-Assisted Product Discovery
  • Vibe Coding: Conversational Software Development — Part 2: In Practice
  • Exactly-Once Stream Processing With Apache Flink
  • Surviving One Million Metrics per Second: Architecture Decisions That Actually Matter

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  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
·
Jul. 01, 21 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
24.6K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

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

  • Testing Asynchronous Systems, Part 4: A Technique-by-Level Test Strategy
  • Same Prompt, Different Test: Using AI Agent Workspaces to Make Testing Repeatable
  • Testing Business Programs Without Constructing Domain Objects
  • Why Standard Test Automation Misses the Failures That Matter in AI Agent Systems

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • 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