pact-foundation / pact-jvm

JVM version of Pact. Enables consumer driven contract testing, providing a mock service and DSL for the consumer project, and interaction playback and verification for the service provider project.
https://docs.pact.io
Apache License 2.0
1.07k stars 475 forks source link

how to parse the response at pact provider verfication #1285

Closed LinghaoYu closed 3 years ago

LinghaoYu commented 3 years ago

My scenario is that there are two interactions defined by the consumer, interation1 with state1, and interation2 with state2. After running interation1, there will be an id in the JSON response, and this id has to be used as the query parameter of interation2. On the provider side, is there a way to extract that id from the response of interation1? I am using pact provider junit by the way.

uglyog commented 3 years ago

The Pact framework does not support chaining interactions in this way. Each is verified in isolation. Using the provider states is the correct way to test these. You can use values from the provider state callbacks to inject into the request. See https://stackoverflow.com/questions/63955575/how-to-inject-dynamic-id-for-pact-test-from-provider-to-consumer-using-rest-assu and https://pactflow.io/blog/injecting-values-from-provider-states/