Version Matrix

wire-mock-stub

Build Status Download

Simple WireMock backed service for mocking API calls.

Stubbing

Refer to WireMock's Stubbing for further information, however a brief introduction follows:

Please be good samaritans and clean up your own stubbed mappings at the end of your tests

Setup

Essentially, in order to configure the following response:

Method Path Response Status Response Body Headers
GET /resource/123A 200 {"id":"123A","account":"Platinum"} Content-Type: application/json

Issue a request to [POST] http://host:9994/__admin/mappings with the body:

 {
   "request": {
     "method": "GET",
     "url": "/resource/123A"
   },
   "response": {
     "status": 200,
     "jsonBody": {"id":"123A","account":"Platinum"},
     "headers": {
       "Content-Type": "application/json"
     }
   }
 }

You should get a response with status 201 and response body similar to:

{
    "id": "ea1eec28-64af-4e7d-ac4a-e6fb9fa4c4a6",
    "request": {
        "url": "/resource/123A",
        "method": "GET"
    },
    "response": {
        "status": 200,
        "body": "{\"id\":\"123A\",\"account\":\"Platinum\"}",
        "headers": {
            "Content-Type": "application/json"
        }
    },
    "uuid": "ea1eec28-64af-4e7d-ac4a-e6fb9fa4c4a6"
}

Make a note of the id being returned.

We strongly suggest that that you delete your stub mappings after running your tests and it's with this id that you would do so.

Tear down

Please clean up your stub mappings by issuing the request [DELETE] http://host:9994/__admin/mappings/{id} where the id is the result of the stub mapping you created. The response should be a 200.

Limits to stubbing

wire-mock-stub simply provides a WireMock instance, concurrent access, overlapping tests or clearing down stubbed responses may lead to inconsistencies. It is up to the consumer to correctly setup and destroy desired stub behaviour.

License

This code is open source software licensed under the Apache 2.0 License.