Hi team, just curious to know about- I just need t...
# wiremock-java
d
Hi team, just curious to know about- I just need to queue later api calls' response on the basis of condition placed in first request. I'm having my wiremock set up in JSON way I play API 1 with condition 1, resp1 is returned. Afterwards if API2 is called, response will be resp2 I play API 1 with condition A, resp1 is returned. Afterwards if API2 is called, response will be respB I hope I'm clear, please let me know if it needs further clarity needs.
r
sounds like scenarios are what you're looking for. here's the docs https://wiremock.org/docs/stateful-behaviour/
d
I'd an eye on it, let me dig down if it fits
@Rafe Arnold I checked it, I am using 2 different URLs in scenarios. PFB
Copy code
{
  "mappings": [
    {
      "scenarioName": "To do list",
      "requiredScenarioState": "Started",
      "request": {
        "method": "POST",
        "urlPathPattern": "/wiremock/any/resource",
        "bodyPatterns": [
          {
            "matchesXPath": "//resource/Id/1[contains(text(),'12341234')]"
          }
        ]
      },
      "response": {
        "status": 202
      },
      "serveEventListeners": [
        {
          "name": "recordState",
          "parameters": {
            "context": "co",
            "state": {
              "resourceId": "{{xPath request.body '//resource/text()'}}"
            }
          }
        }
      ]
    },
    {
      "scenarioName": "To do list",
      "requiredScenarioState": "Cancel newspaper item added",
      "request": {
        "method": "GET",
        "urlPathPattern": "/wiremock/resource/add"
      },
      "response": {
        "status": 200,
        "bodyFileName": "resourceSumResponse.xml"
      }
    }
  ]
}
Copy code
the endpoint - "/wiremock/resource/add"
checking thru postman, gives- Request was not matched
it would be helpful if anyone can give input if prior idea he/she has
l
Hi, sorry, but I don't think I fully understand what you are trying to achieve. You are using the state extension in the example you posted above so are you trying to get different endpoints to return that state? Could you expand on what it is you are trying to achieve?
d
the issue is resolved now. The problem was, I was using requiredScenarioState in first one instead of newScenarioState. Thanks @Lee Turner and to @Rafe Arnold specially
👍 1
l
Excellent. Glad it is sorted
👍 1