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

More test samples and support for passing objects in on pact construction #67

Open
holly-cummins opened this issue Feb 4, 2023 · 1 comment

Comments

@holly-cummins
Copy link
Contributor

At the moment, the consumer test does the following:

    private static final String alpacaBody = " {\n" +
            "      \"colour\": \"black\",\n" +
            "          \"name\": \"floppy\"\n" +
            "        }";

...

        // Here we define our mock, which is also our expectations for the provider

        return builder.given("test GET")
                .uponReceiving("GET REQUEST")
                .path("/alpaca")
                .method("GET")
                .willRespondWith()
                .status(200)
                .headers(headers)
                .body(alpacaBody)
                .toPact(V4Pact.class);

That should always work, but it would be nice to be able to do

    private static final Alpaca alpaca = new Alpaca("black", "floppy");

...

        // Here we define our mock, which is also our expectations for the provider

        return builder.given("test GET")
                .uponReceiving("GET REQUEST")
                .path("/alpaca")
                .method("GET")
                .willRespondWith()
                .status(200)
                .headers(headers)
                .body(alpaca)
                .toPact(V4Pact.class);

That works with Rest Assured. This would probably be a change to feed back to the Pact library, perhaps by allowing it to be initialised with an object mapper and then us auto-magically handing over the object mapper?

Alternatively, we should include some tests which manually inject the object mapper and create the json. There's no extension-specific magic, but it's a useful example to be able to follow.

@holly-cummins
Copy link
Contributor Author

Injected objects aren't available in the @Pact body, which makes this harder. In Quarkus 3, we will need to check if they are.

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

1 participant