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.08k stars 480 forks source link

Expecting null message body #1637

Open dominikbrandon opened 2 years ago

dominikbrandon commented 2 years ago

Hi, I'm using Pact as a consumer in order to test events being sent by the provider. Tests are written in Groovy. This particular use case looks like this: when an entity gets created, an event is sent to Kafka, having some properties in the body and a particular key corresponding to the entity's id. When an entity gets deleted, an event is sent to Kafka, having the same key, but a null body.

How do I ensure that the provider will send the message with a null body? Is it even possible? I've tried multiple different options with the basic one looking like below, but matchingRules in the resulting JSON are always missing. I may be missing something, but I haven't yet found a way how to make it work.

return new PactMessageBuilder().call {
    ...
    withContent(contentType: "application/json") {
        null
    }
}
rholshausen commented 1 year ago

When you mean message with a null body, is that a body that contains a JSON NULL value, or that there is no body at all?

dominikbrandon commented 1 year ago

I meant no body at all. Sorry for being unclear.