Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement multi-stub in one json file for the same url using Wiremock?

I am trying to create one mapping.json under the mappings folder with multiple stubs as below. But I am facing the following error

Wiremock: v2.5.1 (standalone)

Mapping.json file looks,

[
{
  "scenarioName": "Savings account Stub",
  "request": {
    "url": "/ws/*****",
    "method": "POST",
    "bodyPatterns" : [{
      "contains" : "AccountRequest"
    }
    ]
  },
  "response": {
    "status": 200,
    "bodyFileName": "******"
  }
},
{
  "scenarioName": "Current account Stub",
  "request": {
    "method": "POST",
    "url": "/ws/*****",
    "bodyPatterns": [
      {
        "contains": "AccountListRequest"
      }
    ]
  },
  "response": {
    "status": 200,
    "bodyFileName": "******"
  }
}]

Error:

Exception in thread "main" wiremock.com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of com.github.tomakehurst.wiremock.stubbing.StubMapping out of START_ARRAY token

Is there any possibility to create multiple stubs for the same URL in single mapping file? Can anyone tell me what is the exact issue?

like image 221
AnuragSanagapalli Avatar asked Sep 02 '25 10:09

AnuragSanagapalli


1 Answers

Looking at the stubbing documentation, I think you want your mappings.json to look like...

{ 
    "mappings": [
        {
            "scenarioName": "foo",
            "request": {},
            "response": {}
        }, {
            "request": {}
        }
    ],
    "importOptions": {
        "duplicatePolicy": "IGNORE",
        "deleteAllNotInImport": true
    }
}

You'd then want to make a POST request to /__admin/mappings/import with your mappings.json as the request body. The reason for this is that I believe multiple mappings in a single file are only supported via the import option.

like image 186
agoff Avatar answered Sep 04 '25 22:09

agoff