1

I need a dynamic response with different values using traffic parrot and wiremock.

I have an integration test with patterns in json files to get a response when I call the API's.

I need to call a product service to retrieve a specific product, my request json:

request.json
{
  "request" {
    "urlPathPattern": "/urlResponse/product/1000",
    "method": "GET"
  },
  "response": {
    "status": 200,
    "headers": {
      "Content-Type": "application/json"
    },
    "bodyFileName": "response.json",
    "transformers": [
      "response-template"
    ]
  }
}

And I need something like this:

response.json
{
  "id": {{request.path.[2]}},
  "type": VARIABLE or DYNAMIC CONTENT,
  "other attr"....
}

I Want to pass a variable content depending of the request, for example, I have an Object

public CustomObject {
  private int id = 1000;
  private String type = "product";
}

When I call the API of product with ID 1000, I want a response.json with type set to "product". I see documentation of Traffic parrot example, but I do not know how to apply.

Edit 1: It is possible to define in request.json a map to define the variable type for the response? Something like this:

If I have an ID with 1000
objMap = 1000; type = "product",
objMap = 2000; type = "Balloon",
etc...
abeld89
  • 57
  • 4
  • 11
  • Is it correct that the URL is the source of those two values: type and id? `/urlResponse/product/1000` – A. Kootstra Mar 12 '19 at 16:49
  • I don't understand you, the value of "id": {{request.path.[2]}}, it will be 1000, but I want to set another value in "type" not passed in the URL. I want define this in the request.json something like this: if(request.path-[2] == 1000) type = "value1"; else type = "value2" – abeld89 Mar 15 '19 at 10:43

0 Answers0