pact-jvm
pact-jvm copied to clipboard
Feature Request - Support like Matcher with Predefined Java Objects like in Pact-JS
Firstly, I want to express my admiration for the work you've done with Pact-JVM.
I'm reaching out to inquire about a feature in Pact-JVM that mirrors the functionality available in Pact-JS. Specifically, I'm interested in the ability to use the like matcher in a way that leverages predefined Java objects.
In our project, we extensively use integration tests with predefined data in the form of Java objects. Simple example (in real project we have ~100 fields):
{
"customer": {
"name": "Test user",
"address": [{"street": "Test street"}]
}
}
We are looking for a way to utilize the like matcher in Pact-JVM that can automatically infer and check against types based on the object provided (By using reflection I suppose), similar to how it's done in Pact-JS.
I recently came across a video https://youtu.be/oPuHb9Rl8Zo?si=dmeDGDjvZA0S1blb&t=544 that demonstrates this functionality in Pact-JS. This got me wondering if there's an existing or planned feature in Pact-JVM that can achieve similar behavior. I.e (pseudocode)
@Pact(....)
public RequestResponsePact createFetchCUstomerPact(PactDslWithProvider builder) {
MyCustomerObject expected = new My CustomerObject();
expected.setName("test user");
expected.setAddress(List.of(new Address("Test street")));
return builder.given("has customer")
.uponReceiving("request of customer")
.path("/")
.method("POST")
.willRespondWith()
.status(200)
.body(PactDslJsonRootValue.like(expected) // <-- will do type matching, ignoring value
.toPact();
}
Thank you
Have a look at https://github.com/sngular/pact-annotation-processor