Setup Mockoon application

  1. Download and Install the application from https://mockoon.com/

  2. Launch Mockoon application

  3. Create a new workspace

    1. When you first launch Mockoon, it will ask you to create a new workspace

    2. Enter a name for your workspace and choose a directory where the workspace data will be stored (for example mockoon-paymentsbbvoucher.json stored under ./examples/mock-bb-payments directory)

    3. Click create

  4. Create a new route

    1. Inside the workspace, click on the Add a route button to create a new route

    2. Enter a name for your route

    3. Define the route path (e.g. /vouchers/voucher_activation )

    4. Select the HTTP method ( GET, POST, PUT, DELETE, etc.)

  5. Define route responses

    1. Under the route configuration, click on the Add a response button

    2. Set the status code for the response ( e.g. 200 for a successful response )

    3. Configure the headers and the response body for the response

    4. Set rules that must be met to return given response

    5. You can create multiple responses for different scenarios

      It’s worth to add that the responses are checked sequentially from first to last, the first rule set that matches is returned. If none match, the default will be returned. Default one can be set by clicking on the drop-down list of all responses and clicking on the flag icon of your choice.

  6. Start Dockerized server

    1. Create Dockerfile

      FROM node:14-alpine RUN npm install -g @mockoon/cli@2.2.1 COPY mockoon-paymentsbbvoucher.json ./mockoon-paymentsbbvoucher.json COPY entrypoint.sh ./entrypoint.sh # Do not run as root. RUN adduser --shell /bin/sh --disabled-password --gecos "" mockoon RUN chown -R mockoon ./mockoon-paymentsbbvoucher.json RUN chown -R mockoon ./entrypoint.sh USER mockoon EXPOSE 3003 ENTRYPOINT ["/entrypoint.sh"]

      node:14-alpine - base image
      mockoon-paymentsbbvoucher.json - workspace created in step 3
      3003 - port on which the server listens (must be the same as in the Mockoon app)

    2. Create docker-compose.yml

      version: '3.3' services: test-app: image: payments-bb-voucher-api-image ports: - 3333:3003 networks: - web build: context: . dockerfile: ./Dockerfile volumes: - ./mockoon-paymentsbbvoucher.json:/mockoon-paymentsbbvoucher.json networks: web: driver: bridge

      ports: 3333:3003 maps port of the container to the port on your machine
      test-app name of the service from docker-compose.yml

    3. Create test_entrypoint.sh

      #!/bin/bash chmod u+x entrypoint.sh docker-compose up -d test-app --build

      test-app name of the service from docker-compose.yml

    4. Create entrypoint.sh

      mockoon-paymentsbbvoucher.json from step 3

 

From now on server can be started by typing ./test_entrypoint.sh or simply docker-compose up invoked from the folder where all the aforementioned files were created.

The server can be called: http://localhost:exposed_port/routes_defined_in_the_mockoon_app