SlideShare a Scribd company logo
Ananth.krishnan@whishworks.com
Mock ESB Endpoints using MUnit
 Mock an Mule ESB endpoint without real time need of
an interface (during development time)
 Unit test your flows without & with real time
interfaces
 Automate your unit test by testing with real time or
without provider interfaces using Munit (from
Jenkins)
 It is possible to mock SAP endpoint, JDBC Endpoint,
Salesforce point and so on!
 Let us see an example of how to mock Salesforce 
What is MUnit?
 A Beta-version testing framework from Mulesoft
http://www.mulesoft.org/documentation/display/curre
nt/Introduction+to+Testing+Mule#IntroductiontoTestin
gMule-GoFurther
 This goes the extra mile than Functional Test Case - as
Functional Test case requires real time interfaces for
unit testing your flows
 Can switch to real time interface or use mock data
easily using a flag from your CI tool 
 Runs within Anypoint Studio and from Maven/Jenkins
Pre-requisites
 Anypoint studio 15 Jan 2015 release
 Mule CE or EE 3.5.2 runtime or 3.6.0 runtime
 MUnit 3.5.x runtime libraries/API
 MUnit interceptor API
 Salesforce credentials (having a SFDC account, user
name/password and security token)
 Apache Maven installation
 Patience 
Get MUnit
 Go to https://github.com/mulesoft/munit
 Download MUnit libraries
 Download Munit mule-interceptor-module
 Run pom.xml ($maven –X E clean insall, skip tests) on
both the projects
 Jar files for Munit and mule-interceptor-modules
should be generated by now 
 Add these jar files (exclude sources) to Anypoint
studio build class path
Salesforce Accounts Download
 Let us build a flow which downloads Accounts from
Salesforce
 Triggered using Http endpoint (for example)
 SOQL query executed in Salesforce endpoint is
SELECT ID, NAME, BILLINGCITY FROM ACCOUNT
 Salesforce returns all Accounts as an
ArrayList<HashMap>
 Each HashMap contains SFDC Account information
by having Name, ID or BILLINGCITY as key
Example Salesforce Flow
Identify payload returned using Debugger
So far…
 We identified Salesforce returns ArrayList<HashMap>
which contains Account information
 SOQL used is
SELECT ID, NAME, BILLINGCITY FROM ACCOUNT
 We had built MUnit libraries for unit testing this
Unit testing approach
 Prepare Test Data to be returned by Salesforce
Endpoint (mocked test data)
 Prepare Assertion data which will assert the Test Data
 Assert Test Data and Assertion Data
MUnit – Java based testing Overview
 Extend your Munit test case from
FunctionalMUnitSuite (org.mule.munit.runner.functional.FunctionalMunitSuite)
 Define your flows to be loaded when Mule test case
starts (like below):
protected String getConfigResources() {
return "SalesforceMock2.xml";
}
 Define whether to mock or use realtime interface
// Return TRUE to mock endpoint, otherwise FALSE
public boolean haveToMockMuleConnectors() {
return true;
}
MUnit – Java based testing Overview
Following is XML file for the flow:
<sfdc:config name="Salesforce"
username="ananth.krishnan@whishworks.com"
password=“aaaaaa" securityToken=“aaaaaa"
doc:name="Salesforce">
<sfdc:connection-pooling-profile
initialisationPolicy="INITIALISE_ONE"
exhaustedAction="WHEN_EXHAUSTED_GROW"/>
</sfdc:config>
<flow name="SalesforceMockFlow">
<http:inbound-endpoint exchange-pattern="request-
response" host="localhost" port="8081" doc:name="HTTP"/>
<logger message="***** Before invoking Salesforce for
Accounts *****" level="INFO" doc:name="Logger"/>
<sfdc:query config-ref="Salesforce" query="select id,
billingcity, name from Account" doc:name="Salesforce"/>
<logger message="#[payload] ==> Payload type is:
#[payload.getClass()]" level="INFO" doc:name="Logger"/>
</flow>
Tell your MUnit java to mock
 To mock an endpoint (Salesforce), in your unit test case,
first specify to mock an endpoint with a test mock data
(like below):
whenMessageProcessor("query").
ofNamespace("sfdc").
thenReturn(
muleMessageWithPayload(
accountsMockData )
);
 Here, accountsMockData is the mock data payload
 Salesforce endpoint is <sfdc:query…> in flow XML having
sfdc as namespae and query as processor name
Next steps
 We had told Munit to mock Salesforce endpoint with
accountsMockData. So
 We need to prepare mock data for Accounts
 We need to prepare Assertion data for Accounts to
Assert
 We need to Assert mock data and Assertion data so
that your flow is fully functional for the test case
 Refer to complete test case java code
MUnit – Mock Salesforce Enpoint
public class SalesforceMockTest extends FunctionalMunitSuite {
@Test
public void testSalesforceAccounts() throws Exception {
// Step 1: Prepare Mock data for List of Salesforce Account objects using
SFDCTestAccountPayloadGenerator
SFDCTestAccountPayloadGenerator mockDataGenerator = new SFDCTestAccountPayloadGenerator();
ArrayList<HashMap<String,String>> accountsMockData =
mockDataGenerator.getSalesforceAccountsTestData();
// Step 2: Register Mock data to Salesforce processor which will be returned (when invoked
in the flow)
whenMessageProcessor("query").ofNamespace("sfdc").thenReturn( muleMessageWithPayload(
accountsMockData ));
// Step 3: Invoke the flow (Salesforce endpoint is mocked now! - using a test event)
MuleEvent resultEvent = runFlow( "SalesforceMockFlow", testEvent("Hello world!") );
ArrayList<HashMap<String,String>> flowResult = (ArrayList<HashMap<String,String>>)
resultEvent.getMessage().getPayload();
// Step 4: resultEvent above has the Mocked Salesforce data. Now we need to assert it
SFDCAssertAccountPayloadGenerator assertDataGenerator = new
SFDCAssertAccountPayloadGenerator();
ArrayList<HashMap<String,String>> assertionData =
assertDataGenerator.getAccountAssertionData();
assertEquals( assertionData, flowResult );
}
}
Note: getConfigResources() and haveToMockMuleConnectors() are omitted due to space constraints in this page
Run MUnit Test Case
 Right Click Project in Anypoint Studio
 Select Test Case java file
 Run As  Junit Test Case (see results in Studio )
Thank you!
Ananth.krishnan@whishworks.com
Ad

More Related Content

What's hot (18)

Load balancer in mule
Load balancer in muleLoad balancer in mule
Load balancer in mule
Ramakrishna kapa
 
Send email attachment using smtp in mule esb
Send email attachment using smtp in mule esbSend email attachment using smtp in mule esb
Send email attachment using smtp in mule esb
RaviShankar Mishra
 
Webservice vm in mule
Webservice vm in muleWebservice vm in mule
Webservice vm in mule
Praneethchampion
 
Introduction to testing mule
Introduction to testing muleIntroduction to testing mule
Introduction to testing mule
Ramakrishna kapa
 
Concepts in mule
Concepts in muleConcepts in mule
Concepts in mule
Sindhu VL
 
Mule soa
Mule soaMule soa
Mule soa
Khasim Saheb
 
Creating restful api using mule esb
Creating restful api using mule esbCreating restful api using mule esb
Creating restful api using mule esb
RaviShankar Mishra
 
Junit in mule demo
Junit in mule demoJunit in mule demo
Junit in mule demo
Sudha Ch
 
Filter expression in mule
Filter expression in muleFilter expression in mule
Filter expression in mule
Rajkattamuri
 
Mule rabbitmq
Mule rabbitmqMule rabbitmq
Mule rabbitmq
Praneethchampion
 
Introduction To Mule
Introduction To MuleIntroduction To Mule
Introduction To Mule
Roy Prins
 
Web service vm in mule
Web service vm in muleWeb service vm in mule
Web service vm in mule
Mohammed246
 
Mule dataweave
Mule dataweaveMule dataweave
Mule dataweave
Son Nguyen
 
Enjoy Munit with Mule
Enjoy Munit with MuleEnjoy Munit with Mule
Enjoy Munit with Mule
Bui Kiet
 
Stored procedure in Mule
Stored procedure in MuleStored procedure in Mule
Stored procedure in Mule
Khasim Saheb
 
Vm component in mule demo
Vm component in mule demoVm component in mule demo
Vm component in mule demo
Sudha Ch
 
Create Account in Salesforce using Mule ESB
Create Account in Salesforce using Mule ESBCreate Account in Salesforce using Mule ESB
Create Account in Salesforce using Mule ESB
Sanjeet Pandey
 
Service orchestration by using flows
Service orchestration by using flowsService orchestration by using flows
Service orchestration by using flows
sathishmca143
 
Send email attachment using smtp in mule esb
Send email attachment using smtp in mule esbSend email attachment using smtp in mule esb
Send email attachment using smtp in mule esb
RaviShankar Mishra
 
Introduction to testing mule
Introduction to testing muleIntroduction to testing mule
Introduction to testing mule
Ramakrishna kapa
 
Concepts in mule
Concepts in muleConcepts in mule
Concepts in mule
Sindhu VL
 
Creating restful api using mule esb
Creating restful api using mule esbCreating restful api using mule esb
Creating restful api using mule esb
RaviShankar Mishra
 
Junit in mule demo
Junit in mule demoJunit in mule demo
Junit in mule demo
Sudha Ch
 
Filter expression in mule
Filter expression in muleFilter expression in mule
Filter expression in mule
Rajkattamuri
 
Introduction To Mule
Introduction To MuleIntroduction To Mule
Introduction To Mule
Roy Prins
 
Web service vm in mule
Web service vm in muleWeb service vm in mule
Web service vm in mule
Mohammed246
 
Mule dataweave
Mule dataweaveMule dataweave
Mule dataweave
Son Nguyen
 
Enjoy Munit with Mule
Enjoy Munit with MuleEnjoy Munit with Mule
Enjoy Munit with Mule
Bui Kiet
 
Stored procedure in Mule
Stored procedure in MuleStored procedure in Mule
Stored procedure in Mule
Khasim Saheb
 
Vm component in mule demo
Vm component in mule demoVm component in mule demo
Vm component in mule demo
Sudha Ch
 
Create Account in Salesforce using Mule ESB
Create Account in Salesforce using Mule ESBCreate Account in Salesforce using Mule ESB
Create Account in Salesforce using Mule ESB
Sanjeet Pandey
 
Service orchestration by using flows
Service orchestration by using flowsService orchestration by using flows
Service orchestration by using flows
sathishmca143
 

Similar to Mule ESB - Mock Salesforce Interface (20)

Mocking with salesforce using Munit
Mocking with salesforce using MunitMocking with salesforce using Munit
Mocking with salesforce using Munit
Son Nguyen
 
Munit junit test case
Munit junit test caseMunit junit test case
Munit junit test case
prudhvivreddy
 
ELEVATE Paris
ELEVATE ParisELEVATE Paris
ELEVATE Paris
Peter Chittum
 
Salesforce1 Platform for programmers
Salesforce1 Platform for programmersSalesforce1 Platform for programmers
Salesforce1 Platform for programmers
Salesforce Developers
 
## Introducing a reactive Scala-Akka based system in a Java centric company
## Introducing a reactive Scala-Akka based system in a Java centric company## Introducing a reactive Scala-Akka based system in a Java centric company
## Introducing a reactive Scala-Akka based system in a Java centric company
Milan Aleksić
 
Jsf intro
Jsf introJsf intro
Jsf intro
vantinhkhuc
 
Dive Deep into Apex: Advanced Apex!
Dive Deep into Apex: Advanced Apex! Dive Deep into Apex: Advanced Apex!
Dive Deep into Apex: Advanced Apex!
Salesforce Developers
 
Asynchronous Apex Salesforce World Tour Paris 2015
Asynchronous Apex Salesforce World Tour Paris 2015Asynchronous Apex Salesforce World Tour Paris 2015
Asynchronous Apex Salesforce World Tour Paris 2015
Samuel De Rycke
 
Sql storeprocedure
Sql storeprocedureSql storeprocedure
Sql storeprocedure
ftz 420
 
Advanced Apex Webinar
Advanced Apex WebinarAdvanced Apex Webinar
Advanced Apex Webinar
pbattisson
 
Declarative presentations UIKonf
Declarative presentations UIKonfDeclarative presentations UIKonf
Declarative presentations UIKonf
Nataliya Patsovska
 
Composable and streamable Play apps
Composable and streamable Play appsComposable and streamable Play apps
Composable and streamable Play apps
Yevgeniy Brikman
 
Performance and Scalability Testing with Python and Multi-Mechanize
Performance and Scalability Testing with Python and Multi-MechanizePerformance and Scalability Testing with Python and Multi-Mechanize
Performance and Scalability Testing with Python and Multi-Mechanize
coreygoldberg
 
F# And Silverlight
F# And SilverlightF# And Silverlight
F# And Silverlight
Talbott Crowell
 
Building Continuous Application with Structured Streaming and Real-Time Data ...
Building Continuous Application with Structured Streaming and Real-Time Data ...Building Continuous Application with Structured Streaming and Real-Time Data ...
Building Continuous Application with Structured Streaming and Real-Time Data ...
Databricks
 
CiklumJavaSat_15112011:Alex Kruk VMForce
CiklumJavaSat_15112011:Alex Kruk VMForceCiklumJavaSat_15112011:Alex Kruk VMForce
CiklumJavaSat_15112011:Alex Kruk VMForce
Ciklum Ukraine
 
Working with data using Azure Functions.pdf
Working with data using Azure Functions.pdfWorking with data using Azure Functions.pdf
Working with data using Azure Functions.pdf
Stephanie Locke
 
Sherlock Homepage - A detective story about running large web services - NDC ...
Sherlock Homepage - A detective story about running large web services - NDC ...Sherlock Homepage - A detective story about running large web services - NDC ...
Sherlock Homepage - A detective story about running large web services - NDC ...
Maarten Balliauw
 
Mike Taulty MIX10 Silverlight Frameworks and Patterns
Mike Taulty MIX10 Silverlight Frameworks and PatternsMike Taulty MIX10 Silverlight Frameworks and Patterns
Mike Taulty MIX10 Silverlight Frameworks and Patterns
ukdpe
 
J unit
J unitJ unit
J unit
Durga Prasad Kakarla
 
Mocking with salesforce using Munit
Mocking with salesforce using MunitMocking with salesforce using Munit
Mocking with salesforce using Munit
Son Nguyen
 
Munit junit test case
Munit junit test caseMunit junit test case
Munit junit test case
prudhvivreddy
 
Salesforce1 Platform for programmers
Salesforce1 Platform for programmersSalesforce1 Platform for programmers
Salesforce1 Platform for programmers
Salesforce Developers
 
## Introducing a reactive Scala-Akka based system in a Java centric company
## Introducing a reactive Scala-Akka based system in a Java centric company## Introducing a reactive Scala-Akka based system in a Java centric company
## Introducing a reactive Scala-Akka based system in a Java centric company
Milan Aleksić
 
Dive Deep into Apex: Advanced Apex!
Dive Deep into Apex: Advanced Apex! Dive Deep into Apex: Advanced Apex!
Dive Deep into Apex: Advanced Apex!
Salesforce Developers
 
Asynchronous Apex Salesforce World Tour Paris 2015
Asynchronous Apex Salesforce World Tour Paris 2015Asynchronous Apex Salesforce World Tour Paris 2015
Asynchronous Apex Salesforce World Tour Paris 2015
Samuel De Rycke
 
Sql storeprocedure
Sql storeprocedureSql storeprocedure
Sql storeprocedure
ftz 420
 
Advanced Apex Webinar
Advanced Apex WebinarAdvanced Apex Webinar
Advanced Apex Webinar
pbattisson
 
Declarative presentations UIKonf
Declarative presentations UIKonfDeclarative presentations UIKonf
Declarative presentations UIKonf
Nataliya Patsovska
 
Composable and streamable Play apps
Composable and streamable Play appsComposable and streamable Play apps
Composable and streamable Play apps
Yevgeniy Brikman
 
Performance and Scalability Testing with Python and Multi-Mechanize
Performance and Scalability Testing with Python and Multi-MechanizePerformance and Scalability Testing with Python and Multi-Mechanize
Performance and Scalability Testing with Python and Multi-Mechanize
coreygoldberg
 
Building Continuous Application with Structured Streaming and Real-Time Data ...
Building Continuous Application with Structured Streaming and Real-Time Data ...Building Continuous Application with Structured Streaming and Real-Time Data ...
Building Continuous Application with Structured Streaming and Real-Time Data ...
Databricks
 
CiklumJavaSat_15112011:Alex Kruk VMForce
CiklumJavaSat_15112011:Alex Kruk VMForceCiklumJavaSat_15112011:Alex Kruk VMForce
CiklumJavaSat_15112011:Alex Kruk VMForce
Ciklum Ukraine
 
Working with data using Azure Functions.pdf
Working with data using Azure Functions.pdfWorking with data using Azure Functions.pdf
Working with data using Azure Functions.pdf
Stephanie Locke
 
Sherlock Homepage - A detective story about running large web services - NDC ...
Sherlock Homepage - A detective story about running large web services - NDC ...Sherlock Homepage - A detective story about running large web services - NDC ...
Sherlock Homepage - A detective story about running large web services - NDC ...
Maarten Balliauw
 
Mike Taulty MIX10 Silverlight Frameworks and Patterns
Mike Taulty MIX10 Silverlight Frameworks and PatternsMike Taulty MIX10 Silverlight Frameworks and Patterns
Mike Taulty MIX10 Silverlight Frameworks and Patterns
ukdpe
 
Ad

Recently uploaded (20)

UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Ad

Mule ESB - Mock Salesforce Interface

  • 2. Mock ESB Endpoints using MUnit  Mock an Mule ESB endpoint without real time need of an interface (during development time)  Unit test your flows without & with real time interfaces  Automate your unit test by testing with real time or without provider interfaces using Munit (from Jenkins)  It is possible to mock SAP endpoint, JDBC Endpoint, Salesforce point and so on!  Let us see an example of how to mock Salesforce 
  • 3. What is MUnit?  A Beta-version testing framework from Mulesoft http://www.mulesoft.org/documentation/display/curre nt/Introduction+to+Testing+Mule#IntroductiontoTestin gMule-GoFurther  This goes the extra mile than Functional Test Case - as Functional Test case requires real time interfaces for unit testing your flows  Can switch to real time interface or use mock data easily using a flag from your CI tool   Runs within Anypoint Studio and from Maven/Jenkins
  • 4. Pre-requisites  Anypoint studio 15 Jan 2015 release  Mule CE or EE 3.5.2 runtime or 3.6.0 runtime  MUnit 3.5.x runtime libraries/API  MUnit interceptor API  Salesforce credentials (having a SFDC account, user name/password and security token)  Apache Maven installation  Patience 
  • 5. Get MUnit  Go to https://github.com/mulesoft/munit  Download MUnit libraries  Download Munit mule-interceptor-module  Run pom.xml ($maven –X E clean insall, skip tests) on both the projects  Jar files for Munit and mule-interceptor-modules should be generated by now   Add these jar files (exclude sources) to Anypoint studio build class path
  • 6. Salesforce Accounts Download  Let us build a flow which downloads Accounts from Salesforce  Triggered using Http endpoint (for example)  SOQL query executed in Salesforce endpoint is SELECT ID, NAME, BILLINGCITY FROM ACCOUNT  Salesforce returns all Accounts as an ArrayList<HashMap>  Each HashMap contains SFDC Account information by having Name, ID or BILLINGCITY as key
  • 8. Identify payload returned using Debugger
  • 9. So far…  We identified Salesforce returns ArrayList<HashMap> which contains Account information  SOQL used is SELECT ID, NAME, BILLINGCITY FROM ACCOUNT  We had built MUnit libraries for unit testing this
  • 10. Unit testing approach  Prepare Test Data to be returned by Salesforce Endpoint (mocked test data)  Prepare Assertion data which will assert the Test Data  Assert Test Data and Assertion Data
  • 11. MUnit – Java based testing Overview  Extend your Munit test case from FunctionalMUnitSuite (org.mule.munit.runner.functional.FunctionalMunitSuite)  Define your flows to be loaded when Mule test case starts (like below): protected String getConfigResources() { return "SalesforceMock2.xml"; }  Define whether to mock or use realtime interface // Return TRUE to mock endpoint, otherwise FALSE public boolean haveToMockMuleConnectors() { return true; }
  • 12. MUnit – Java based testing Overview Following is XML file for the flow: <sfdc:config name="Salesforce" username="[email protected]" password=“aaaaaa" securityToken=“aaaaaa" doc:name="Salesforce"> <sfdc:connection-pooling-profile initialisationPolicy="INITIALISE_ONE" exhaustedAction="WHEN_EXHAUSTED_GROW"/> </sfdc:config> <flow name="SalesforceMockFlow"> <http:inbound-endpoint exchange-pattern="request- response" host="localhost" port="8081" doc:name="HTTP"/> <logger message="***** Before invoking Salesforce for Accounts *****" level="INFO" doc:name="Logger"/> <sfdc:query config-ref="Salesforce" query="select id, billingcity, name from Account" doc:name="Salesforce"/> <logger message="#[payload] ==> Payload type is: #[payload.getClass()]" level="INFO" doc:name="Logger"/> </flow>
  • 13. Tell your MUnit java to mock  To mock an endpoint (Salesforce), in your unit test case, first specify to mock an endpoint with a test mock data (like below): whenMessageProcessor("query"). ofNamespace("sfdc"). thenReturn( muleMessageWithPayload( accountsMockData ) );  Here, accountsMockData is the mock data payload  Salesforce endpoint is <sfdc:query…> in flow XML having sfdc as namespae and query as processor name
  • 14. Next steps  We had told Munit to mock Salesforce endpoint with accountsMockData. So  We need to prepare mock data for Accounts  We need to prepare Assertion data for Accounts to Assert  We need to Assert mock data and Assertion data so that your flow is fully functional for the test case  Refer to complete test case java code
  • 15. MUnit – Mock Salesforce Enpoint public class SalesforceMockTest extends FunctionalMunitSuite { @Test public void testSalesforceAccounts() throws Exception { // Step 1: Prepare Mock data for List of Salesforce Account objects using SFDCTestAccountPayloadGenerator SFDCTestAccountPayloadGenerator mockDataGenerator = new SFDCTestAccountPayloadGenerator(); ArrayList<HashMap<String,String>> accountsMockData = mockDataGenerator.getSalesforceAccountsTestData(); // Step 2: Register Mock data to Salesforce processor which will be returned (when invoked in the flow) whenMessageProcessor("query").ofNamespace("sfdc").thenReturn( muleMessageWithPayload( accountsMockData )); // Step 3: Invoke the flow (Salesforce endpoint is mocked now! - using a test event) MuleEvent resultEvent = runFlow( "SalesforceMockFlow", testEvent("Hello world!") ); ArrayList<HashMap<String,String>> flowResult = (ArrayList<HashMap<String,String>>) resultEvent.getMessage().getPayload(); // Step 4: resultEvent above has the Mocked Salesforce data. Now we need to assert it SFDCAssertAccountPayloadGenerator assertDataGenerator = new SFDCAssertAccountPayloadGenerator(); ArrayList<HashMap<String,String>> assertionData = assertDataGenerator.getAccountAssertionData(); assertEquals( assertionData, flowResult ); } } Note: getConfigResources() and haveToMockMuleConnectors() are omitted due to space constraints in this page
  • 16. Run MUnit Test Case  Right Click Project in Anypoint Studio  Select Test Case java file  Run As  Junit Test Case (see results in Studio )