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.
Below is a code snippet of a consumer pact test written with pact-jvm version 4.2.14
This test is used to verify the json structure of a message published to a kafka topic.
When the pact is verified by the provider, it also compares for the values of the two fields decimalField1 ( default value 100.0) and numberType(default value of 100).
How can I use pact to only verify if decimalField1 is decimal data type and numberField1 is number data type without matching the values?
Consumer Test Class:
@ExtendWith(PactConsumerTestExt.class)
@PactTestFor(
providerName = "example-provider",
providerType = ProviderType.ASYNCH)
class Test {
@Pact(provider = "example-provider", consumer = "example-consumer")
MessagePact createPact(MessagePactBuilder builder) {
DslPart dslPart =
LambdaDsl.newJsonBody(
body ->
body
.decimalType("decimalField1")
.numberType("numberField1"))
.build();
var metadata = new HashMap<String, String>();
metadata.put("Topic", "TestTopic");
metadata.put(CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
return builder
.hasPactWith("testTopic")
.withMetadata(metadata)
.withContent(body)
.toPact();
}
Description of differences
------------------------------------------------
• Expected 100.0 but got 5.99 at $.decimalField1
• Expected 100 but got 83 at $.decimalField1
Below is a code snippet of a consumer pact test written with pact-jvm version 4.2.14 This test is used to verify the json structure of a message published to a kafka topic. When the pact is verified by the provider, it also compares for the values of the two fields decimalField1 ( default value 100.0) and numberType(default value of 100). How can I use pact to only verify if
decimalField1
is decimal data type andnumberField1
is number data type without matching the values?Consumer Test Class:
Generated pact json:
Failure output: