I have a few noob questions about Pact JVM (Java);
-
If the providers json structure response is already known (for example by querying the api with Postman) ,is it possible to convert Postman json body automatically into a pact contract file without the need to run a (java) Consumer Fragment creation method, or for example convert it into a java PactDslJsonBody() structure?
-
Is the provider (spring-boot) needed to be up and running (even if the json response structure is already known) when the pact file is being created? It would be good maybe to avoid the need to launch the spring-boot server for each and every contract creation, particularly if the contract details is already known? Particularly if creating many pact contracts for many microservices at ones.
-
Is there a more advanced example of a larger returned provider json structure than this very small json body found in the tutorial example;
[1] http://the-creative-tester.github.io/Java-Consumer-Driven-Contract-Testing/
Furthermore it would be good if that additional example could be shared that only verify a subset of the structure to be returned exist since we got a lot in the responses that are random. -
Could somebody share a pact verify java code example of a pact jvm verify towards an online https (as opposed to http) rest service, like for example google, facebook or similar provider? ( or for example this: [2] https://jsonplaceholder.typicode.com/posts )
-
I gotten a lot of java compilation errors with above example[1]. Are there any version level of pact (and spring) that are less likely to get mismatch with java spring framework versions?
Thanks for your time!
2
Answers
Hi Please find response below:
1)Currently there is no such functionality.Consumer Fragment is basically to define the json so skipping this step doesn’t make sense.
2) The pact file creation uses Pact Mock Server. So you dont need real service to be up. The service should be up only during verification phase.
3,4,5) Version plays a critical role since this framework is actively evolving. Regarding handling complex json structures, there are quite a few examples to show usage of Pact DSL. You may use those to come up with the json structure of your service.
https://github.com/DiUS/pact-jvm/tree/master/pact-jvm-consumer-junit#dsl-matching-methods
For 3), See if this link helps you – http://www.briandupreez.net/2017/03/consumer-driven-testing-with-pact.html
And here are examples from the author of pact-jvm – https://github.com/DiUS/pact-jvm/tree/master/pact-jvm-consumer-junit/src/test/java/au/com/dius/pact/consumer/examples.