Giter Club home page Giter Club logo

Comments (17)

muhrynov avatar muhrynov commented on May 18, 2024 2

Hi!
I slightly don't understand one moment. In example i see sequence of methods: Get -> Post -> Get
I have question: Can I change state without POST method?
I have one method GET, whose state i want to change after check him again.
For example:

  1. First scenario

`{
"scenarioName": "check status event",
"requiredScenarioState": "Started",
"request": {
"method": "GET",
"urlPathPattern": "/cashboxes/[0-9]+/registration/[0-9]+"
},

"response": {
"status": 200,
"jsonBody": {
"status": "status one",
},
"headers": {
"Content-Type": "application/json"
}
}
}`

  1. Second scenario

"scenarioName": "check status event",
"requiredScenarioState": "Started",
"newScenarioState": "status two",
"request": {
"method": "GET",
"urlPathPattern": "/cashboxes/[0-9]+/registration/[0-9]+"
},

"response": {
"status": 200,
"jsonBody": {
"status": "status two",
},
"headers": {
"Content-Type": "application/json"
}
}
}`

  1. Third scenario

"scenarioName": "check status event",
"requiredScenarioState": "status two",
"newScenarioState": "status three",
"request": {
"method": "GET",
"urlPathPattern": "/cashboxes/[0-9]+/registration/[0-9]+"
},

"response": {
"status": 200,
"jsonBody": {
"status": "status three",
},
"headers": {
"Content-Type": "application/json"
}
}
}`

from wiremock.

macscripter avatar macscripter commented on May 18, 2024 1

Hello!

First of all, THANK YOU VERY MUCH FOR THIS AMAZING SOFTWARE!

I have a problem with a stateful execution.

I copied directly from http://wiremock.org/stateful-behaviour.html

this code in the mappings dir:

`{
"scenarioName": "To do list",
"requiredScenarioState": "Started",
"request": {
"method": "GET",
"url": "/todo/items"
},
"response": {
"status": 200,
"body" : "Buy milk"
}
}

{
"scenarioName": "To do list",
"requiredScenarioState": "Started",
"newScenarioState": "Cancel newspaper item added",
"request": {
"method": "POST",
"url": "/todo/items",
"bodyPatterns": [
{ "contains": "Cancel newspaper subscription" }
]
},
"response": {
"status": 201
}
}

{
"scenarioName": "To do list",
"requiredScenarioState": "Cancel newspaper item added",
"request": {
"method": "GET",
"url": "/todo/items"
},
"response": {
"status": 200,
"body" : "Buy milkCancel newspaper subscription"
}
}`

After, I run wiremock server in standalone mode:
java -jar wiremock-1.57-standalone.jar

After I execute the first scenario (GET):

http://localhost:8080/todo/items

I get the

<items> <item>Buy milk</item> </items>

Fine.

After I execute http://localhost:8080/todo/items (POST) with the json object (application/json):

{"value":"Cancel newspaper subscription"}

And I get:

<title>Error 404 NOT_FOUND</title>

And when I try to execute http://localhost:8080/todo/items (GET)
I get the the same as in the first scenario.....

<items> <item>Buy milk</item> </items>

Could someone explain me where am I wrong?

Thank you!!!!

from wiremock.

tomakehurst avatar tomakehurst commented on May 18, 2024

Hi,

Nice to hear someone other than me is using scenarios!

When you say you want to modify the scenario you're in, do you mean move it to a different state?

If so, then the willSetStateTo() method in the Java DSL will do the trick. The "newScenarioState" attribute in the JSON API does the same.

Perhaps I'm missing what you're getting at?

Cheers,
Tom

from wiremock.

adrian-augustyn avatar adrian-augustyn commented on May 18, 2024

Hi, wow - really quick response. Thanks for that.

Let me shed more light on what I am after.

Firstly - I am using JSON to set up my mappings.

I have a facade service that is accepting a request and then calls bunch of other services fetching and updating a lot of entities.
I use wiremock to stub responses from those services.

Let's say one of those calls is defined like that :

{
"request": {
"method": "GET",
"url": "/service/A/entity"
},
"response": {
"status": 200,
"bodyFileName": "entity_success.xml",
"headers": {
"Content-Type": "application/xml"
}
}
}

This works fine. Now I wanted to add error scenarios. One error scenario per service.
I have added one extra mapping to initiate the state machine - to say - my facade will now work in this scenario :

{
"scenarioName" : "error scenario A",
"newScenarioState": "Return 404 on entity request",
"request": {
"method": "POST",
"url": "/scenario/error_404"
},
"response": {
"status": 201
}
}

NOW. the previous mapping (I thought) would change to something like this:

{
"scenarioName" : "normal",
"requiredScenarioState": "Started",
"request": {
"method": "GET",
"url": "/service/A/entity"
},
"response": {
"status": 200,
"bodyFileName": "entity_success.xml",
"headers": {
"Content-Type": "application/xml"
}
}
}

and the error case would be something like this:

{
"scenarioName" : "error scenario A",
"requiredScenarioState": "Return 404 on entity request",
"request": {
"method": "GET",
"url": "/service/A/entity"
},
"response": {
"status": 404
}
}

But that doesn't work. In fact I am now getting 404 everytime I hit the apis...

Does that make things clearer? :)

Thanks
adrian

from wiremock.

tomakehurst avatar tomakehurst commented on May 18, 2024

Let me take a look at that. I have a run of meetings all afternoon unfortunately, but I'll try and take a look after that.

from wiremock.

adrian-augustyn avatar adrian-augustyn commented on May 18, 2024

Thanks, again. Really appreciate it!
What I was thinking ... but wasn't able to find it - was a call similar to __admin/reset to check what the current scenario details are ... as a step to verify if I am setting everything correctly.

But maybe you will be able to spot some incorrect usage of the json configuration, which would be even better ;-)

from wiremock.

tomakehurst avatar tomakehurst commented on May 18, 2024

Ah, I see now. You're right, I've completely forgotten to document this. To reset all the scenarios' state, you need to POST to __admin/scenarios/reset.

from wiremock.

adrian-augustyn avatar adrian-augustyn commented on May 18, 2024

No, no. Sorry I didn't write that clear enough.
You did document this. http://wiremock.org/stateful-behaviour.html#scenarios-reset

I was just saying that I thought that maybe there was something like __admin/scenarios/details to check if I have actually correctly managed to change the status.

As in:
call to __admin/scenarios/details -> all scenarios on "started"
call to my /scenario/error_404 -> scenario updated, provided the configuration is correct
another call to __admin/scenarios/details -> returns all scenarios on 'started', but my "error scenario A" on "Return 404 on entity request"
call to the existing __admin/scenarios/reset and then all is back to 'started'.

from wiremock.

tomakehurst avatar tomakehurst commented on May 18, 2024

Doh, so I did. Should read my own docs a bit more thoroughly...

There isn't currently a way to interrogate a scenario's state directly. Obviously you could do it indirectly by creating stub mappings dependent on specific states and nothing else and check against those, although I admit that's a pretty messy solution.

Another solution in the short term would be to run it with a debugger attached. The InMemoryStubMappings class contains an instance variable called scenarioMap with all the current states contained.

Longer term, I'm happy to support for this to the backlog, or accept a pull request if you fancy creating one.

from wiremock.

adrian-augustyn avatar adrian-augustyn commented on May 18, 2024

That sounds like an interesting proposal - something I might come back to you at some point.

Would it be too much to ask you, for now, to test that basic JSON configuration of mine to work with scenarios and either post fixed version of it here or add to to documentation? If of course there is something wrong with those mappings I posted ...

cheers

from wiremock.

tomakehurst avatar tomakehurst commented on May 18, 2024

Apologies for not having got to this yet. Day job not leaving me with much time at the moment.

from wiremock.

karkaladeepak avatar karkaladeepak commented on May 18, 2024

Hi,

I am using Wiremock to send various success and failure responses for job requests to my application. The responses are in the form of JSONs which I have stored in 'mappings' folder.

Do we have a provision in wiremock so that I can include/exclude the files I want on scenario basis?
In the sense, if in a particular scenario, I am mocking success, I should be able to change the settings file to include the json files with success responses and exclude others. Similarly when I am mocking failure, I should be able to change the settings file.

Currently I am changing the whole folder structure for every scenario that I am running and then I need to restart the server.

Please let me know if we have a solution for this.

Thanks,
Deepak

from wiremock.

tomakehurst avatar tomakehurst commented on May 18, 2024

Unfortunately swapping out whole mappings based on scenario isn't possible.

Could you give me some examples of the problem you're trying to solve? I suspect there'll be a way to make the current features work in the way you need them to.

from wiremock.

MaharanaPratap avatar MaharanaPratap commented on May 18, 2024

Hi,
First of all great thanks for creating this tool, I have just one word for it "awesome".

I started using it 2 weeks back, trying to use stateful behaviour.
In your documentation, you have not changed the state for the POST method, is it because if the method type is same then only state needs to be changed ?
If we use stateful behaviour, do we need to specify states for all the mappings loaded in the environment?

While is record mode, is there a way to capture stateful behaviour ? I read in the documentation that is same URL is called again, it will be ignored.

from wiremock.

jzk avatar jzk commented on May 18, 2024

There are lots of tools like this one, but scenario make this one unique, thanks for creating it.

from wiremock.

 avatar commented on May 18, 2024

Hi

@macscripter,
I checked and for me it turns out you need to put each scenario step into separate valid json file. Presented example for scenarios is not a valid json file and it seems WireMock just reads first "entry" that handles GET /todo/items and "skips" definitions of following two entries.

BTW, I just discovered that inside mappings directory you can have sub-directories and they are also scanned for mapping definitions. That allows managing scenario files easier.

from wiremock.

rbaker-ps avatar rbaker-ps commented on May 18, 2024

Hi tomakehurst,

Thank you so much for all of your hard work, the Wiremock tool is awesome and it's saved us countless hours of testing!

I was wondering if there is a document that shows all of the different variations of the JSON stubs. I was trying to do scenarios and didn't find what I needed until I came across this ticket.

Thanks so much and keep up the awesome work!

Russ Baker

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.