Munit with Databases

The MUnit Database server you can mock the actual db with an in-memory db.

Official documentation at site:


If we want to mock a “SELECT * FROM jobtitlelookup”

Step 1

Add the mule munit database

<!-- dbserver Dependency -->
<!-- H2 Dependency -->

Step 2 - Disable Mule's automatic mocking

Global Elements tab, and select your MUnit Configuration element. Click Edit and uncheck both Mock Mule transport connectors and Mock Inbound endpoints.

or in the xml

 <munit:config mock-inbounds="false" mock-connectors="false"/>

Step 3 - Mock our database from CSV

In the global configuration create a DB Server with

  • Name: DB_Server
  • csv.: jobtitlelookup.csv
  • Database: DATABASE_NAME

<dbserver:config  name="DB_Server" database="DATABASE_NAME"  doc:name="DBServerConfig" connectionStringParameters="MODE=MySQL" csv="jobtitlelookup.csv" />

This uses the H2 database underneath that has compatibility mode for

  • IBM DB2, Apache Derby, HSQLDB, MS SQL Server, MySQL, Oracle, and PostgreSQL

Step 4 - Create a database structure

This can be done in two ways

  • SQL - provide an sql file to create the required tables and insert data
  • CSV - provide a file with columns to create the table and sample data. Multiple cvs files are provided semi-colon separated to create multiple tables

Step 5 - Before step - Start the Database

Step 4 - Test our select on the database

Pass the data to our database flow

mule_munit_testing.txt · Last modified: 2019/02/26 04:20 by root
RSS - 200 © CrosswireDigitialMedia Ltd