4

Is there a small and concise jvm consumer Java (consumer or provider) junit project that somebody could share, preferably in a self contained zip file with all files contained, except for the jar imports?

When I follow for example the steps here: https://github.com/DiUS/pact-jvm/tree/master/pact-jvm-consumer-junit and "Using the base ConsumerPactTest" I get various errors, that I have tried to resolve one by one.

However I believe there must exist a simpler "Hello world" type of example to depict this framework.

I have setup other microservice mocking frameworks before, but Pact shows too many errors setting it up, so I think must have misunderstood how this is supposed to be setup, in its simplest form.

The last issues I had with the example aforementioned were these imports that I find no jar files for: import au.com.dius.pact.consumer.exampleclients.ConsumerClient; import au.com.dius.pact.consumer.ConsumerPactTest; import au.com.dius.pact.model.PactFragment;

For this reason for example @Pact keyword cannot be resolved etc.

Thanks in advance!


Update - Is it possible to NOT use the pact provider mock server code, and instead use the "real" api provider , when creating the pact definition(using ./gradlew test )?

For example in the example at 1), would it be possible to just update (for example using a recorded response in postman) the consumer's @Pact section with the "real" api provider response, without the need to created a mocked response in the spring boot localhost mock server?

1) http://the-creative-tester.github.io/Java-Consumer-Driven-Contract-Testing/

Thank you for any answers!

zombieboy
  • 116
  • 1
  • 10
  • I've written these two articles on pact if they can be helpful somehow: https://hmh.engineering/how-to-write-and-validate-pact-contracts-using-junit5-and-restassured-72b578e7dd65 and https://hmh.engineering/pact-with-java-by-example-bb7175f62d58 – Francislainy Campos Feb 04 '21 at 08:48

3 Answers3

3

I followed this example as a starting point- http://the-creative-tester.github.io/Java-Consumer-Driven-Contract-Testing/

ljs
  • 495
  • 1
  • 8
  • 23
  • Although I managed to build and execute the provider part, the consumer is not possible to build in Eclipse. I get these errors: import org.apache.http.client.fluent.Request; - Unused import statement DslPart - Cannot resolve , PactRule & PactFragment - Depricated | Please advice – zombieboy Oct 10 '17 at 13:44
  • 1
    https://github.com/DiUS/pact-jvm/issues/222 - this issue may be similar to yours, please have a look. I tried mine in intellij Idea (community version) – ljs Oct 17 '17 at 21:21
3

went through a few tutorial for pact for java. found out https://github.com/Mikuu/Pact-JVM-Example#pact-jvm-example has the best coverage/explanation. Including the interaction to pack broker, changing state for pact testing and it is very easy to follow. I really appreciate the effort from the originator for such wonderful documents

bLaXjack
  • 780
  • 2
  • 11
  • 23
2

I recently created the PACT-JVM project using Java and Gradle.

https://github.com/contactsai123/PACT-JVM-Example

It has 1 provider / 2 consumers and setup is pretty straight forward to understand.

Sai
  • 309
  • 1
  • 4
  • 15