MuleSoft and Integration Testing using POSTMAN Tool

This article provides fundamental details about integration of MuleSoft and Salesforce and how the integration can be tested using POSTMAN tool. It introduces MuleSoft--which is an integrated software--and Salesforce CRM. In addition, a brief description about basic MuleSoft terms are also explained. Now, let us explore the MuleSoft-Salesforce integration and testing it using POSTMAN tool.

Introduction:

This article provides fundamental details about integration of MuleSoft and Salesforce and how the integration can be tested using POSTMAN tool.  It introduces MuleSoft–which is an integrated software–and Salesforce CRM. In addition, a brief description about basic MuleSoft terms are also explained. Now, let us explore the MuleSoft-Salesforce integration and testing it using POSTMAN tool.                                                     

What is MuleSoft?

MuleSoft LLC is a software headquartered in San Francisco. It provides integration software for connecting applications, data, and devices.  MuleSoft’s Anypoint Platform is designed to integrate Software as a Service (SaaS). Later in 2018, Salesforce acquired MuleSoft.

MuleSoft’s Anypoint Platform includes various components such as Anypoint Design Centre, Anypoint Exchange and Anypoint Management Center. It also offers Mule runtime engine.

Why do we need MuleSoft?

MuleSoft enables exchange of data between applications. MuleSoft allows to start with small and connect with more applications over time. 

What is Salesforce?

Salesforce is an integrated Customer Relationship Management Solution (CRM) platform. It brings customers and companies together. Salesforce offers various cloud services like Sales cloud, Service cloud, Marketing cloud, Community cloud, Commerce cloud, Analytics cloud, App cloud, IoT cloud, Health cloud, etc. Salesforce also provides machine learning platform with Salesforce Einstein which is cloud based machine learning. 

MuleSoft and Salesforce:

MuleSoft is a data integration platform built to connect variety of data sources, applications and perform analytics and ETL processes (Extract, Transform and Load).

MuleSoft’s Salesforce connector helps to accelerate Salesforce integrations across Sales cloud, Service cloud, Salesforce platform and Force.com.

Salesforce Connector supports all create, read, upsert, and delete operations across Salesforce objects.

Salesforce connector supports Salesforce’s bulk operations that are optimized for working with large sets of data.

Enables you to easily leverage custom fields and custom entities to solve integration needs to your custom Salesforce instance.

 What is MUnit?

MuleSoft has a framework called MUnit that allows us to write automated test cases for APIs and Integrations. It is suitable for continuous integration/ development
environment.

One of the main advantages of MUnit framework is that it can be integrated with Maven and Surefire.

Options to Test the Mule Applications to Make Request to an Endpoint
Some options are:
1.   A browser
2.   A cURL command line utility
3.   A browser extension like POSTMAN (for google chrome)

Mule Flow

Mule applications are made up of one or more flows. Mule application begins by
processing a message received by an inbound endpoint in a flow.  Mule flow can consist of a single flow or multiple flows to create complex applications.

Typical Mule flow has the following components:

Message Source: Accepts a message from an external source. Triggers the flow execution. i.e Endpoints- HTTP, Database, File FTP etc…

Message Processors:  Message processors are

Components– REST, SOAP JavaScript, Java, Python etc.

Filters

Routers– aggregators, splitters, round robin etc…

Scopes– Flows, Sub flows…

Transformers-
The transformers prepare messages to be processed.

Built in Transformers- convert XML, JSON, File, Object, Array, String etc…

Dynamic Transformers- Anypoint Data Mapper dynamically converts between flat(CSV, Excel) and structured (XML, JSON etc…) formats

Connectors

Connectors are reusable extensions to Mule that enables to integrate a Mule App with third party APIs, databases. In other words, a connector is a software that provides a connection between a Mule flow and an external source.

Anypoint Studio  

Anypoint Studio is an Eclipse based integration development environment. It is used for designing and testing Mule applications. Anypoint studio comes with embedded Mule Runtime to test the applications. 

MuleSoft Integration: Testing with POSTMAN Tool

Creating a Mule flow in Anypoint Studio

We can create a Mule flow or Mule application in Anypoint Studio and
check the response using POSTMAN tool.

Muleflow created in Anypoint Studio:

Components used:

  • Listener- HTTP Connector
  • Two Transform message Connectors to send and receive response
  • Salesforce Create Connector

Steps to Follow

  • Select New Mule project and create global HTTP connector to receive request
  • Add the HTTP connector configuration
  • Select the method as POST (GET can also be given based on the need) in advanced HTTP listener option
  • Use the Salesforce connector and the Salesforce configuration
  • Test the Salesforce configuration connection
  • Then, select the Type (Object to be used) Example: Account
  • Use Transform connector between HTTP connector and Salesforce connector
  • Prepare the data in JSON format and define the meta data in Transform message connector
  • Add another Transform message connector and give the output payload
  • Right click on the canvas and run the Mule project
  • In console output, application logs and information can be seen. Status will be “Deployed

Data in JSON format

JSON stands for JavaScript Object Notation. JSON is a text written in JavaScript Object Notation and it is case sensitive. 

Syntax Rules:

Data are name/value pairs

Data are separated by commas

Curly braces hold objects

Square brackets hold array

JSON supports following data types:

A string

A number

An array

A Boolean

Null

As we use Account object as example, we need to pass Account data in JSON format

[ {

“name”  :  “Test Account” ,
“billingAddress” : “Lamington Road”
“billingCity” :  “Phoenix”,
“billingCountry” : “United States of America”,
“billingPostalCode” : “321678“,
“billingState” :  “Arizona”
}
]

Testing with POSTMAN

What is POSTMAN tool?

POSTMAN is an API development tool that helps build, test, and modify APIs.
In other words, it is a simple GUI for sending HTTP requests and view the responses.

POSTMAN tool can be downloaded in the link : https://www.postman.com/downloads/

Steps to follow:

  • Change the HTTP request from GET to POST.
  • Enter the following URL http://localhost:8083/objectname

             Example: http://localhost:8083/accounts

  • In the Body, click raw and select JSON
  • Copy the JSON data (data that is given in Mule flow) in Body of POSTMAN tool
  • Click Send button
  • Status will be displayed as 200 OK in Response window. Also, success response will be received along with record id (Id of the record created in Salesforce)

HTTP Codes in POSTMAN

200 is success

400 is bad request

401 is unauthorized

Copy the JSON data in the Body section of POSTMAN tool

Click Send

Response is received and Status is 200 OK

Checking the record created in Salesforce

  • Log into Salesforce
  • Enter the record id received in the response window of POSTMAN tool
  • Corresponding Account record (example) will be created in Salesforce
  • The details provided in the body of the POSTMAN tool will be mapped in Account record that is created in Salesforce

Account record is created in Salesforce

Conclusion:

Thus, the above-mentioned steps can be followed to for basic integration of MuleSoft with Salesforce and the response can be tested using POSTMAN tool. As, we are creating records in Salesforce, we use Salesforce Create Connector while creating the Mule flow. Other Salesforce connectors can also be used based on the need or requirement.

About MST

At MST Solutions our cornerstone is to adapt, engage and create solutions which guarantee the success of our clients. The talent of our team and experiences in varied business verticals gives us an advantage over other competitors.

Recent Articles

Work with us.

Our people aren’t just employees, they are key to the success of our business. We recognize the strengths of each individual and allow them time and resources to further develop those skills, crafting a culture of leaders who are passionate about where they are going within our organization.