---
schema_version: "1"
id: 2c12c81f36e91b49f0c725dc0cb05f84e779b99712b6b2a0fa056ed14bfb00e1
title: Installing a Database Server
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/munit/3.6/db-util.md
canonical_url: https://docs.mulesoft.com/munit/3.6/db-util
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 102a325e51f64e8d413a10edd14d7bd892d43f042a6102991d5852d77b76451c
description: MuleSoft Documentation Site
release: "3.6"
latest: false
---
---
product: MUnit
version: 3.6
---

# Installing a Database Server

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

![logo acb active](/mulesoft/current/en-us/_/img/icons/anypoint-code-builder.svg "Anypoint Code Builder")Anypoint Code
Builder

![logo studio active](/mulesoft/current/en-us/_/img/icons/studio.svg "Anypoint Studio")Anypoint Studio

To test a piece of code that connects with a database server, install a database server in your
local environment to run the tests. You can also use a dedicated external database server for
testing, but your Maven project can’t be portable. If so, a third party must install the testing
database server to compile your project.

To make it easier for you to test database connections, MUnit allows you to implement a database
server in your local environment.

## Install the MUnit DB Server Module

To install the MUnit DB Server Module:

1.  Look for the **MUnit Utils Database Server** module.

2.  Add the module to your project in the `pom.xml` file:

    ```xml
    <!-- dbserver Dependency -->
    <dependency>
        <groupId>com.mulesoft.munit.utils</groupId>
        <artifactId>munit-dbserver-module</artifactId>
        <version>LATEST_VERSION</version> (1)
        <classifier>mule-plugin</classifier>
        <scope>test</scope>
    </dependency>
    ```

    <table><tbody><tr><td><i data-value="1"></i><b>1</b></td><td>Check the <a href="https://repository.mulesoft.org/nexus/content/repositories/releases/com/mulesoft/munit/utils/munit-dbserver-module/">MuleSoft Nexus repository</a> to get the <strong>LATEST_VERSION</strong>.<div><p>The MUnit DB server artifact in your <code>pom.xml</code> file must have the <code>test</code> scope.</p></div></td></tr></tbody></table>

3.  The `h2` dependency used for the database is a shared library.  
    Add the dependency to your `pom.xml` file and list it as a `sharedLibrary` in
    `mule-maven-plugin`.

    ```xml
    <!--Third party libs-->
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <version>1.3.166</version>
    </dependency>
    ```

    ```xml
    <plugin>
        <groupId>org.mule.tools.maven</groupId>
        <artifactId>mule-maven-plugin</artifactId>
        <version>${mule.maven.plugin.version}</version>
        <extensions>true</extensions>
        <configuration>
        <sharedLibraries>
                ...
                <sharedLibrary>
                    <groupId>com.h2database</groupId>
                    <artifactId>h2</artifactId>
                </sharedLibrary>
            </sharedLibraries>
        </configuration>
    </plugin>
    ```

> [!NOTE] The **MUnit DB Server** module is located at
> [MuleSoft Nexus repository](https://repository.mulesoft.org/nexus/content/repositories/releases/com/mulesoft/munit/utils/munit-dbserver-module/).
> The **MUnit DB Server** module version 3 and later is compatible with Java 17. Previous versions
> of this module available at Anypoint Exchange are deprecated.

## Attributes Reference

<table><colgroup><col> <col></colgroup><thead><tr><th>Attribute Name</th><th>Description</th></tr></thead><tbody><tr><td><p><code>name</code></p></td><td><p>Defines the configuration name of this DB server. This value must be unique.</p></td></tr><tr><td><p><code>database</code></p></td><td><p>Defines the name of the in-memory DB.</p></td></tr><tr><td><p><code>sqlFile</code></p></td><td><p>Specifies the path of the SQL file that defines the DB structure/contents. Use this parameter to create the DB at startup. See the <a href="#db-structure-sql">Defining the DB Structure from an SQL File</a> section for additional information.</p></td></tr><tr><td><p><code>csv</code></p></td><td><p>Specifies the path of the comma-separated file used to define the DB structure/contents. Use this parameter to create the DB at startup. See <a href="#db-structure-csv">Defining the DB Structure from a CSV File</a> section for additional information.</p></td></tr><tr><td><p><code>connectionStringParameters</code></p></td><td><p>Defines the connection string for your database. You can concatenate the parameters with a semicolon.</p></td></tr></tbody></table>

## Define the DB Structure

You can define the structure and content of your database in two different ways:

- SQL

- CSV

The MUnit DB server is based on H2. Complex structures, index and join commands can present issues.

### Defining the DB Structure from an SQL File

To define the DB structure and content from an SQL file, you must provide a valid set of ANSI SQL
DDL (Data Definition Language) instructions in your MUnit suite file. For example,
`my-munit-suite.xml`.

```xml
<dbserver:config name="MUnit_DB_Server_Config" >
    <dbserver:connection sqlFile="FILE_NAME.sql" database="DATABASE_NAME" connectionStringParameters="MODE=MySQL" />
</dbserver:config>
```

### Define the DB Structure From a CSV File

To define your DB structure in your MUnit suite file based on a CSV file:

- The name of the table is the name of the file (in the following example, `customers`).

- The names of the columns are the headers of your CSV file.

```xml
<dbserver:config name="MUnit_DB_Server_Config" >
    <dbserver:connection csv="FILE_NAME.csv" database="DATABASE_NAME" connectionStringParameters="MODE=MySQL" />
</dbserver:config>
```

You can also split your DB structure among several CSV files. In your MUnit suite file, include the
file names in a list, with the names separated by semicolons:

```xml
<dbserver:config name="MUnit_DB_Server_Config" >
    <dbserver:connection csv="FILE_NAME.csv;FILE_NAME_1.csv" database="DATABASE_NAME" connectionStringParameters="MODE=MySQL" />
</dbserver:config>
```

This creates two tables: `FILE_NAME` and `FILE_NAME_1`.

## MUnit DB Server Processors

The DB server utility has two processors to interact with your DB server:

### Validate-That

To validate that the results of a query are as expected, use the `validate-that` operation in your
MUnit suite file. Set the `results` property to CSV with rows separated by a newline character
(`\n`), as follows:

```xml
<dbserver:validate-that config-ref="DB_Server"
query="SELECT * FROM jobtitlelookup WHERE JOBTITLE='Developer';" returns="&quot;JOBTITLE&quot;,&quot;EECSALARYORHOURLY&quot;,&quot;JOBTITLEID&quot;\n&quot;Developer&quot;,&quot;10&quot;,&quot;DEV&quot;" />
```

### Execute

Execute instructions for the in-memory databases to add or remove registries before a test and
verify that your data is correctly stored using MUnit DB Server.

In your MUnit suite file, use a DB Server connector with the `execute` operation to insert the new
values to the table (`Culinary Team Member,10,HIR`). Then use another DB Server connector with an
`execute query` operation to retrieve all values from the table (including the newly added ones).
Finally, check the payload using a logger component to store the payload:

```xml
<!-- Execute a SQL instruction using the execute operation -->
<dbserver:execute config-ref="MUnit_DB_Server_Config" sql="INSERT INTO jobtitlelookup VALUES ('Culinary Team Member','10','HIR');"/>

<!-- Check the update using execute-query operation -->
<dbserver:execute-query config-ref="MUnit_DB_Server_Config" sql="SELECT * FROM jobtitlelookup"/>

<!-- log the resulting payload -->
<logger level="INFO" message="#[payload]"/>
```

The logger in your console reads:

```text
org.mule.runtime.core.internal.processor.LoggerMessageProcessor: [{JOBTITLEID=DEV, EECSALARYORHOURLY=10, JOBTITLE=Developer}, {JOBTITLEID=HIR, EECSALARYORHOURLY=10, JOBTITLE=Culinary Team Member}]
```

## See Also

- [Configuring DB Server Utility in an MUnit Test](https://docs.mulesoft.com/munit/3.6/db-server-cookbook)
