Backbase / api-simulator

A service that's capable of registering itself in a service registry and simulate request handling based solely on an API specification and the examples it contains.
4 stars 1 forks source link

API Simulator

Description

A service that's capable of registering itself in a service registry and do the following:

This allows simulating services that have not been implemented yet or will not be implemented by Backbase because they're meant to be implemented by external parties such as integration APIs.

It's also possible to mock external dependencies so that performance tests provide consistent results and don't fail because of external dependency failures.

Requirements

Setup

Build it as a regular maven project with mvn clean install.

Configuration

The following properties are always configured:

One of the following needs to be configured:

Known issues

https://github.com/stoplightio/prism/issues/1578:

Prism uses a non-configurable timeout of 5 seconds to download the OpenAPI specification and fails with the message socket hang up if the download takes longer than that, a workaround is to use a local file instead.

Execution with Prism

Preparation

Download an OpenAPI specification and copy it to config/openapi.yaml. It's also possible to configure a URL so that the service can download it at startup.

Locally

Run it as a Spring Boot application with working directory pointing to the root directory of this project. Use com.backbase.api.simulator.Application as main class, local profile and configure it with config/application-local.yml file.

Docker

Execute the following command to generate a docker image:

mvn clean install jib:dockerBuild -Pdocker-image

Then you can run the service with:

docker run -v $(pwd)/config/openapi.yaml:/config/openapi.yaml --env-file ./config/env.list -p 8080:8080 --rm -it your-image-name

Execution with WireMock

Preparation

Create stub mappings according to WireMock's documentation.

Stub mappings must be in a directory called mappings.

Locally

Run it as a Spring Boot application with working directory pointing to the root directory of this project. Use com.backbase.api.simulator.Application as main class, local profile and configure it with config/application-local.yml file.

Docker

The following docker-compose runs api-simulator with WireMock:

  access-control:
    image: harbor.backbase.eu/internal/api-simulator:${API_SIMULATOR_VERSION}
    environment:
      spring.application.name: access-control
      backbase.api.simulator.mode: PERFORMANCE
      backbase.api.simulator.port: 8080
      server.port: 18080
    volumes:
      - ./performance/access-control:/config

Where the directory ./performance/access-control/mappings contains JSON stub mapping files.

Useful links