Munit with Databases

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

Official documentation at site: https://docs.mulesoft.com/munit/v/1.3/munit-database-server

Overview

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

Step 1

Add the mule munit database

<!-- dbserver Dependency -->
<dependency>
	<groupId>com.mulesoft.munit.utils</groupId>
	<artifactId>munit-dbserver-module</artifactId>
	<version>1.1.0</version>
</dependency>
 
 
<!-- H2 Dependency -->
<dependency>
	<groupId>com.h2database</groupId>
	<artifactId>h2</artifactId>
	<version>1.3.5</version>
</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