GithubHelp home page GithubHelp logo

Comments (16)

tomakehurst avatar tomakehurst commented on July 19, 2024

You're actually the second person to have asked for this.

I've been planning a "scenarios" feature for a while that will not only allow what you're asking for, but also allow you to switch whole scenarios on and off, and support simple (jMock-esque) state.

I'll roll it out incrementally, with this as the first step.

from wiremock.

unscene avatar unscene commented on July 19, 2024

So I can think of a scenario in JSON format for what I am thinking of:

{
  "recordMappings": true,
  "mappingsOutputDir": "somedir/relative/to/defautl/dir"
  "filesOutputDir": "somedir/relative/to/defautl/dir"
}

What would you define a scenario as? Wrapping how the application records certain things, and specifying a definition file
for the application to use?

from wiremock.

tomakehurst avatar tomakehurst commented on July 19, 2024

I was thinking of making the scenario name the root dir and putting mappings, and __files under it, rather than specifying them separately.

e.g.

wiremock
  scenario-1
      mappings
      __files
  scenario-2
      mappings
      __files

So the command line would look something like:

java -jar wiremock-standalone.jar --proxy-all="http://somehost.com" --record-mappings --scenario="successful-login"

from wiremock.

unscene avatar unscene commented on July 19, 2024

Ahh cool, I see what you mean now, I like that approach better.

from wiremock.

tomakehurst avatar tomakehurst commented on July 19, 2024

Hey Ryan,

I'm guessing you're not too bothered about this now that you've moved on, so I'll close it off. Feel free to re-open if you'd still like something like this implemented.

Cheers,
Tom

from wiremock.

handstandsam avatar handstandsam commented on July 19, 2024

Sounds cool :-) Doing this locally now by just creating different subdirectories with __files and mappings in to accomplish the same sorta thing, just have to move the WireMock standalone jar which is a little annoying.

from wiremock.

handstandsam avatar handstandsam commented on July 19, 2024

I jumped the gun, just found --root-dir in the documentation: http://wiremock.org/running-standalone.html

Does this also work for recording, or just playback?

from wiremock.

tomakehurst avatar tomakehurst commented on July 19, 2024

Should be both, if memory serves.

from wiremock.

handstandsam avatar handstandsam commented on July 19, 2024

You're right, they both work! How did I not figure out this until today? Thanks Tom, this will make things a lot easier.

from wiremock.

nareshk-gs avatar nareshk-gs commented on July 19, 2024

Is this feature available now...?

I tried java -jar wiremock-standalone-2.10.1.jar --proxy-all="http://myhost.com" --record-mappings --scenario="successful" and wiremock fails to start with below exception -

Exception in thread "main" joptsimple.UnrecognizedOptionException: scenario is not a recognized option at joptsimple.OptionException.unrecognizedOption(OptionException.java:108) at joptsimple.OptionParser.handleLongOptionToken(OptionParser.java:510) at joptsimple.OptionParserState$2.handleArgument(OptionParserState.java:56) at joptsimple.OptionParser.parse(OptionParser.java:396) at com.github.tomakehurst.wiremock.standalone.CommandLineOptions.<init>(CommandLineOptions.java:135) at com.github.tomakehurst.wiremock.standalone.WireMockServerRunner.run(WireMockServerRunner.java:52) at com.github.tomakehurst.wiremock.standalone.WireMockServerRunner.main(WireMockServerRunner.java:113)

from wiremock.

tomakehurst avatar tomakehurst commented on July 19, 2024

Not really sure what you're trying to do here, but there's never been any plan to add a scenario CLI parameter. I'd also suggest trying the new record feature as you're using the legacy one there which is less flexible.

from wiremock.

nareshk-gs avatar nareshk-gs commented on July 19, 2024

I just started using WireMock and looking to use one mock service for multiple service needs. For the sake of maintainability, I thought of having files and mappings in corresponding sub directories.

I remember reading in some forum that wiremock supports subdirectory structure. Looking for ways to achieve that.

from wiremock.

handstandsam avatar handstandsam commented on July 19, 2024

Use the root-dir command line param to use files and mappings in another directory.

from wiremock.

nareshk-gs avatar nareshk-gs commented on July 19, 2024

That sort of helped. Thanks.
Does WireMock support driving responses based on "x-Correlation-Id" ..?

from wiremock.

handstandsam avatar handstandsam commented on July 19, 2024

If that is a header, you can match headers. Check out the docs: http://wiremock.org/docs/request-matching/

from wiremock.

nareshk-gs avatar nareshk-gs commented on July 19, 2024

This worked great for my need. Thanks a bunch!!! I might sound silly, but one last thing for a dummy like me.
I have mapping for multiple services on same folder and different service returns its own response based on the correlation id. I want to have a separate file for each service, that returns a specific response when the predefined correlation IDs doesn't match. A detailed example below.

map "app1-corId1" returns file "app1-corId1" as response on matching corId1 and url
map "app1-corId2" returns file "app1-corId2" as response on matching corId2 and url
map "app2-corId3" returns file "app2-corId3" as response on matching corId3 and url
map "app2-corId4" returns file "app2-corId4" as response on matching corId4 and url

I want to return file "app1-anyCorId" on matching the url on corId mismatch and no corId cases. I tried by adding priority 10 and removing header matching from request, but it fails to bring up the mock service. Is there a way to achieve this...?

from wiremock.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.