Overlapping logic in bodyPatterns for multiple stubbing

436 views
Skip to first unread message

Sandip Mahanta

unread,
Feb 27, 2016, 12:20:48 AM2/27/16
to wiremock-user
Hi,

I have lots of bodyPattern mapping in my wiremock. Now one of my pattern is subset of other pattern; In this case stubbing used is the one for which mapping is created later
In below Example, stubbing 1 condition is subset of stubbing 2. Now, It becomes critical for me to create the mappings in correct order, otherwise stubbing will not work as desired. Is there any better solution for this?

If I create stubbing1 and then stubbing2 then it works as expected. Otherwise not.
This also restricts me to add these mappings directly to mapping folder. It picks in random order while reading from mapping folder

stubbing 1
{
  "request": {
    "url": "/url/goes/here/",
    "method": "POST",
    "bodyPatterns": [
      {
        "contains": "condition1"
      },
      {
        "contains": "condition3"
      }
    ]
  },
  "response": {
    "status": 200,
    "headers": {
      "Content-Type": "application/json"
    },
    "bodyFileName": "Response1.json"
  }
}

Stubbing 2

{
  "request": {
    "url": "/url/goes/here/",
    "method": "POST",
    "bodyPatterns": [
      {
        "contains": "condition1"
      },
      {
        "contains": "condition2"
      },
      {
        "contains": "condition3"
      }
    ]
  },
  "response": {
    "status": 200,
    "headers": {
      "Content-Type": "application/json"
    },
    "bodyFileName": "Response2.json"
  }
}

Tom Akehurst

unread,
Feb 27, 2016, 1:14:21 PM2/27/16
to wiremock-user
I suggest giving a higher priority to the stub you wish to take precedence (lower number = higher priority )

Sandip Mahanta

unread,
Feb 28, 2016, 10:30:03 PM2/28/16
to wiremock-user
Thanks Tom! I think priority will solve my usecase. Let me try it out
Reply all
Reply to author
Forward
0 new messages