Mimock requires the following to be installed on the system. Follow the setup instructions from below to setup mimock
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 applicationCREATE DATABASE mimock_db OWNER mimock;-- Create new schema for mimockCREATE SCHEMA IF NOT EXISTS mimock_schema AUTHORIZATION mimock;
# Content of setup_databasepsql -h localhost -p 5432 -U <existing_user> -f ./psql_setup.sql# To run the setup./setup_database[.bat]
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
mimock.properties - 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 mimock.properties file are configurable and these need to be validated starting the applicationserver.ssl.key-store=<path to the keystore>.jksserver.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 applicationspring.jpa.properties.hibernate.default_schema=mimock_schemaspring.datasource.hikari.schema=mimock_schemaspring.liquibase.default-schema=mimock_schemaspring.liquibase.liquibase-schema=mimock_schema# URL to access the database# E.g: jdbc:postgresql://localhost:5432/database_namespring.datasource.url=jdbc:postgresql://localhost:5432/mimock_db# User created for accessing the databasespring.datasource.username=mimockspring.liquibase.user=mimock# Password for the user created for accessing the databasespring.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 )app.security.jwt-expiry-duration=1h# Valid HmacSHA256 key generated for the application (32 Characters)app.security.jwt-secret-key=<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 valuesapp.security.cors-config.allowed-origins=http://localhost:3000,http://localhost:4200# Methods that should be allowed from cross origin requestsapp.security.cors-config.allowed-methods=POST,GET,PUT,DELETE,OPTIONS# Request headers that should be allowed from cross origin requestsapp.security.cors-config.allowed-headers=Authorization,Content-Type,X-Requested-With,Accept,X-XSRF-TOKEN# Response headers that are allowed to be exposed for cross origin requestsapp.security.cors-config.exposed-headers=Content-Language,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=./mimock.properties
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 keystorekeytool -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 servicedocker-compose -f docker-compose.yml up -d
The mimock-k8s directory has sample kubernetes manifest to give an idea of how to setup mimock within a k8s cluster.
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
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