Package org.mockserver.mock.pact
Class PactVerifier
java.lang.Object
org.mockserver.mock.pact.PactVerifier
Verifies that MockServer's currently-active expectations satisfy each interaction
in a Pact v3 consumer contract. This closes the consumer-driven-contract loop:
the consumer can export a contract via
PactExporter, and the provider
(MockServer) can verify that its expectations produce the expected responses.
For each interaction, the verifier:
- Builds an
HttpRequestfrom the interaction'srequestfields (method, path, query, headers, body) — mirroring howPactExportermaps fields, in reverse. - Finds matching active expectations via the matching engine
(
RequestMatchers.retrieveExpectationsMatchingRequest(org.mockserver.model.RequestDefinition)). - Compares the first matched expectation's response to the interaction's expected response (status, headers subset, body).
Only expectations with a static HttpResponse action are verifiable.
Forward, callback, and template actions are flagged as "unverifiable (non-static action)".
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThe result of verifying a single Pact interaction.static classThe overall result of verifying a Pact contract. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionverify(String pactJson, RequestMatchers requestMatchers) Verifies the given Pact v3 contract JSON against the active expectations in the providedRequestMatchers.
-
Constructor Details
-
PactVerifier
public PactVerifier()
-
-
Method Details
-
verify
Verifies the given Pact v3 contract JSON against the active expectations in the providedRequestMatchers.- Parameters:
pactJson- the Pact v3 contract as a JSON stringrequestMatchers- the active request matchers to verify against- Returns:
- a
PactVerifier.PactVerificationResultcontaining per-interaction results - Throws:
IllegalArgumentException- if the Pact JSON is malformed or contains no interactions
-