Multiple mappings per .json file.

4,237 views
Skip to first unread message

Zachariah Kendall

unread,
Apr 25, 2016, 2:41:44 PM4/25/16
to wiremock-user
From what I can tell, WireMock doesn't support having multiple mappings per json file. It'd be nice if a json file could have a [ {} , {} ] list of mappings. Is this something that you'd consider?

My use case is that we're mocking multiple services throughout a system for our build-acceptence-tests. So then we pass through various customer identities that each need many mappings. So we have a ballooning of mapping files SuzieService1.json, SuzieService2.json, etc. Most of these are simple mappings and it'd be nice to collapse them into a single file.

Tom Akehurst

unread,
Apr 25, 2016, 2:51:39 PM4/25/16
to wiremock-user
If you wanted to raise a PR for it, I'd happily merge it. I've got a fairly large backlog of stuff to work on myself though, so as a feature request it might take a while to arrive.

Might I humbly suggest though that if your mapping files are ballooning, then that's probably an indicator of bigger problems looming down the line. Putting multiple mappings per file would hide this, and this was the main reason I didn't do this in the first place - I wanted to discourage my team members from generating hundreds of similar stubs that'd present a maintenance nightmare later.

If stubbing on the fly from within your test code is an option, I'd suggest switching to this and writing builders to generate the appropriate test data. I've found through experience that the up-front investment is well worth it in terms of reduced maintenance over the long term.

Out of interest, what kind of setup do you have? Is WireMock running standalone on a server, or embedded into your test code?
Message has been deleted

Zachariah Kendall

unread,
Apr 25, 2016, 3:33:01 PM4/25/16
to wiremock-user
We use both. For project unit and integration tests, we use embedded WireMock.

Then we have an acceptance test development environment with dozens of services running in integration. Some of these make external service calls in production which we can't make in development, so we have a standalone wiremock service. When one of our project artifacts is build in Jenkins it is deployed to this dev-test environment, and a set of build-acceptance-tests are run,. These BATs hit services which hit services which hit wiremock with customer names that trigger specific mappings. So I guess the bottom line is we have a multi-service deployment that is integrated as it would be in prod, except it can't hit some external services that it would in prod.

Tom Akehurst

unread,
Apr 25, 2016, 3:45:37 PM4/25/16
to wiremock-user
OK, this is interesting. Apologies for taking the thread slightly off topic, but would you be willing to have a 30 minute Skype chat about this?

The reason I ask is that I'm researching the possibility of building a complementary (possibly SaaS) product to WireMock aimed at the second use case you described (i.e. multiple deployments in a test environment). One of the key problems I'm interested in attacking is the management of large stub sets. Since you're clearly working at a scale where you're hitting these issues, I'd be very interested to get your insight.

Zachariah Kendall

unread,
May 12, 2016, 4:34:36 PM5/12/16
to wiremock-user
Yep. Most days around 6PST would work for me.

Tom Akehurst

unread,
May 15, 2016, 5:48:48 AM5/15/16
to wiremock-user
Thanks, appreciate you getting back to me.

Unfortunately I'm 8 hours ahead of you so I'll have to try and find an OK moment to pull a late one.

Zachariah Kendall

unread,
May 16, 2016, 5:47:33 PM5/16/16
to wiremock-user
I can do earlier on the weekends.

Tom Akehurst

unread,
May 18, 2016, 11:56:08 AM5/18/16
to wiremock-user
Would this Saturday or Sunday be any good for you? Any time in your morning would probably work for both of us I guess.

Zachariah Kendall

unread,
May 19, 2016, 1:08:17 PM5/19/16
to Tom Akehurst, wiremock-user
This weekend wont work. I'll be out camping.

--
You received this message because you are subscribed to a topic in the Google Groups "wiremock-user" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/wiremock-user/GQCGLoZlWEk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to wiremock-use...@googlegroups.com.
To post to this group, send email to wiremo...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/wiremock-user/d1aad60a-df5a-4f1c-84d2-1860ea5af9e0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tom Akehurst

unread,
May 20, 2016, 8:22:54 AM5/20/16
to wiremock-user
Ok, no worries. Perhaps you ping me next time you've got an hour to spare on a Saturday or Sunday morning?

talisker25

unread,
Sep 22, 2017, 10:53:55 AM9/22/17
to wiremock-user
Hi guys, 

We have a very similar scenario as Zachariah was describing in the original post. It would be handy for us to combine mappings related to a given scenario in a single json file. We would then have as many "scenario" json files as required. 

Was this feature added to the backlog in the end? Is there an issue # I could track?

Many thanks

Tom Akehurst

unread,
Sep 22, 2017, 12:33:59 PM9/22/17
to wiremock-user
There isn't a GH issue for this at present. Happy to mark one as a feature request if you'd like to create it.

Dalton Robertson

unread,
Feb 7, 2018, 10:11:09 AM2/7/18
to wiremock-user
I was wondering if there are any update on this issue?  I am currently working with Wiremock and have some service calls where there are multiple ways to reach a payload and was hoping to not have to duplicate the mappings for each path.

Tom Akehurst

unread,
Feb 7, 2018, 11:14:17 AM2/7/18
to wiremock-user
That sounds like a slightly different problem to me. And when I've encountered that problem in the past, I've used the DSL to configure stubs rather than files. Is that an option in your case?

Dalton Robertson

unread,
Feb 7, 2018, 1:36:09 PM2/7/18
to wiremock-user
We have only been using JSON so far as for mapping these files and haven't done much with DSL yet. Can you provide an example of using DSL with stubbing? 

Thank you for your timely response! 

Tom Akehurst

unread,
Feb 7, 2018, 2:37:48 PM2/7/18
to wiremock-user
All the examples in http://wiremock.org/docs/stubbing/ are given both as JSON and the DSL.
Reply all
Reply to author
Forward
0 new messages