Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request - Support like Matcher with Predefined Java Objects like in Pact-JS #1756

Open
lislon opened this issue Dec 28, 2023 · 1 comment

Comments

@lislon
Copy link

lislon commented Dec 28, 2023

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

@rholshausen
Copy link
Contributor

Have a look at https://github.com/sngular/pact-annotation-processor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants