Mimock requires the following to be installed on the system. Follow the setup instructions from below to setup mimock

Java 8+
PostgreSQL 13+

Run mimock locally

Ensure PostgreSQL is setup with a user and a schema for mimock to automatically complete the required table setup

The downloaded bundle includes the setup_database script to setup the required user, database and schema for mimock. The psql_setup.sql script has the following queries to create a new user, database and schema

If you already have the required Database, schema and user, then this DB setup stage can be skipped

-- Create new user (This can be updated if you want a different username or password)
CREATE USER mimock WITH PASSWORD '<db password>';
-- Create the database for mimock application
CREATE DATABASE mimock_db OWNER mimock;
-- Create new schema for mimock
# Content of setup_database
psql -h localhost -p 5432 -U <existing_user> -f ./psql_setup.sql
# To run the setup

Mimock requires a keystore (_.jks or _.p12) to be configured before running the application. If you already have a signed certificate, then the same can be used to generate a new keystore (reference). If you do not have a signed certificate, you can use the following command to generate a new self-signed keystore

keytool -genkey -v -keystore <.jks|.p12 file path> -keyalg RSA -keysize 2048 -validity <validity in days> -alias <alias name> -storepass <store password> -keypass <key password> -storetype jks - The bundle includes the properties file with the required configuration to start mimock. Check the config file and ensure the custom config items are properly setup

# The following values from file are configurable and these need to be validated starting the application
server.ssl.key-store=<path to the keystore>.jks
server.ssl.key-store-password=<keystore password>
# The schema to use for the database
# This is a required field and if a schema is not created, it needs to be setup before starting the application
# URL to access the database
# E.g: jdbc:postgresql://localhost:5432/database_name
# User created for accessing the database
# Password for the user created for accessing the database
spring.datasource.password=<db password>
spring.liquibase.password=<db password>
# User session timeout duration
# Allowed values
# s - seconds | m - minutes | h - hours | d - days | w - weeks | M - months | y - years
# It accepts only whole numeric values (E.g: 210m => Valid ; 3.5h => Invalid)
# If the token is invalid, then the default timeout value will be used ( 1 Hour )
# Valid HmacSHA256 key generated for the application (32 Characters)<32 character long key>
# Origins to be allowed to access the application
# If an UI application running on a different origin needs to access mimoc then the origins need to be added to the below list
# Accepts comma seperated values,http://localhost:4200
# Methods that should be allowed from cross origin requests,GET,PUT,DELETE,OPTIONS
# Request headers that should be allowed from cross origin requests,Content-Type,X-Requested-With,Accept,X-XSRF-TOKEN
# Response headers that are allowed to be exposed for cross origin requests,Content-Length,Content-Type

Download the bundle for the required platform from the download section and run the following command

java -jar ./lib/mimock.jar --spring.config.location=./

Run mimock docker container

The docker-compose.yml has the required setup to spin up the PostgreSQL and mimock app containers. The environment variables required for the mimock springboot app are available in the local.env file and the same is referred in the docker-compose manifest.

Before running the service, a new keystore must be generated and placed in the root where the docker-compose.yml file is located. If you already have a signed certificate, then the same can be used to generate a new keystore.

# To generate a new keystore
keytool -genkey -v -keystore <.jks file path> -keyalg RSA -keysize 2048 -validity 10000 -alias <alias name> -storepass <store password> -keypass <key password> -storetype jks
# Start the service
docker-compose -f docker-compose.yml up -d

Run mimock within a k8s cluster

The mimock-k8s directory has sample kubernetes manifest to give an idea of how to setup mimock within a k8s cluster.

Run mimock on a CI pipeline

A demo project is available on Github, which simulates a scenario of running a UI automation test by setting up mocks using mimock. The project is a simple web application which relies on two endpoints, one for a JSON response and the other for a webp image. The mocks for the two endpoints are setup within the workflow and the UI automation script captures the results as snapshots, and publishes the same to the workflow summary

Setup metric collection for mimock

The Prometheus metrics for mimock is exposed on /api/mimock/monitoring/prometheus endpoint. The prometheus.yml file includes the required config for setting up your own prometheus scrapping for mimock