2

Is it possible to modify parameter values defined in the body during provider verification?

The pact wiki(https://github.com/DiUS/pact-jvm/tree/master/pact-jvm-provider-junit#modifying-the-requests-before-they-are-sent-version-323245) provides a feature to modify the request:

@TargetRequestFilter
public void exampleRequestFilter(HttpRequest request) {
    request.addHeader("Authorization", "OAUTH hdsagasjhgdjashgdah...");
}

but org.apache.http.HttpRequest can only modify the headers and not the body.

This is my relevant pact information:

"request": {
    "method": "POST",
    "path": "/testApi",
    "headers": {
        "Content-Type": "application/json"
    },
    "body": {
        "fileName": {
            "s3ObjectKey": "1649a6d0-4aee-11e9-8646-d663bd873d93"
        }
    },
    "matchingRules": {
        "body": {
            "$['fileName'].s3ObjectKey": {
                "matchers": [
                    {
                        "match": "regex",
                        "regex": "([a-f0-9]{8}(-[a-f0-9]{4}){3}-[a-f0-9]{12})"
                    }
                ]
            }
        }
    }
},

In the above example, I would like to modify the s3ObjectKey to a different UUID.

This answer(https://stackoverflow.com/a/46377050/3714922) says you can modify URL(I think it refers to path in my pact above) but I couldn't figure out how to modify URL or body.

LoL
  • 41
  • 5
  • I'm not too sure I understand what you're trying to do here. Why do you need a different UUID as part of your test? – J_A_X Mar 21 '19 at 23:51
  • @J_A_X I want to use server generated UUID which I get in `@State`. I don't want the random UUID created by pact regex or the fixed UUID in the pact. – LoL Mar 22 '19 at 04:30
  • on the consumer side or the provider side? Because it works differently for both. The consumer side would get the UUID specified in your contract, while the provider side would return any UUID and then the verifier would validate that it matches the regex. – J_A_X Mar 24 '19 at 23:22
  • @J_A_X I was referring to provider side verification. In the `@State` method for a POST request, I get new UUID from server which I want to use in place of UUID predefined in pact as parameter value in body. – LoL Mar 26 '19 at 03:18
  • For the verification, you'll get the UUID specified in the interaction and it should follow the state to use the correct UUID. From what I gather, you want to have multiple different requests with different UUIDs? In Pact terms, those would be a different interaction for each different UUID if you want to test them all on the provider side, but I would postulate that it's not really needed since just a single one should validate that this particular interaction is working. That is, unless I'm not understanding your problem correctly. – J_A_X Mar 27 '19 at 03:57

0 Answers0