Skip to content

Wiremock extension defining helpers for reusing files from the "__files" folder

License

Notifications You must be signed in to change notification settings

pinguet62/wiremock-files-extension

Repository files navigation

WireMock files extension

Helpers

file-content: include file from "__files" folder

Sample: GET /person/42 will return content of file /home/wiremock/__files/person-42.json

{
  "request": {
    "method": "GET",
    "urlPattern": "/person/\\d+"
  },
  "response": {
    "status": 200,
    "headers": {
      "Content-Type": "application/json"
    },
    "body": "{{#assign 'filename'}}person-{{{request.pathSegments.1}}}.json{{/assign}}  {{file-content filename}}"
  }
}

file-exists: tests existence of file in "__files" folder

{
  "response": {
    "body": "{{#assign 'filename'}}person-{{{request.pathSegments.1}}}.json{{/assign}}  {{#if (file-exists filename)}} [...] {{/if}}"
  }
}

Real use case

Build "get multiple" response dynamically from splitted unitary files:

[
    {{#each (parseJson request.body) as |id|}}
        {{#assign 'filename'}}subFolder/{{{id}}}.json{{/assign}}

        {{#if (file-exists filename)}}
            {{file-content filename}}
        {{/if}}

        {{#if @last}}{{else}},{{/if}}
    {{/each}}
]

Installation

The extension is auto-loaded: just add JAR to classpath.

Sample

wget https://.../wiremock-files-extension.jar

Docker compose:

services:
  mocks:
    image: wiremock/wiremock:3x
    volumes:
      - ./wiremock-files-extension.jar:/var/wiremock/extensions/wiremock-files-extension.jar

About

Wiremock extension defining helpers for reusing files from the "__files" folder

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages