You can instruct the provider to switch to a specific state before an interaction by providing a stateChangeUrl. The verifier will send a POST request to this URL containing the providerState description and any parameters.
Configuration Options
stateChangeUrl: The URL to receive the state change request.stateChangeUsesBody: Determines how data is sent.true (default): Data is sent as a JSON body: { "state" : "...", "params": { ... } }.false: Data is passed as query parameters.
stateChangeRequestFilter: A closure to manipulate the state change request itself (e.g., adding auth headers).
Teardown
Set stateChangeTeardown = true on the provider to enable teardown calls. The verifier will call the URL with an action parameter set to setup before the test, and action=teardown after the test.
pact {
serviceProviders {
provider1 {
hasPactWith('consumer1') {
pactFile = file('path/to/provider1-consumer1-pact.json')
stateChangeUrl = url('http://localhost:8001/tasks/pactStateChange')
stateChangeUsesBody = false // defaults to true
stateChangeRequestFilter = { req ->
req.addHeader('Authorization', 'OAUTH ...')
}
}
}
}
}