pact-jvm
pact-jvm copied to clipboard
Pact JVM defaults to pact version v4 when it says V3 in the Java doc
Subject: au.com.dius.pact.consumer:junit5:4.3.1
I'm migrating to pact-jvm 4.3.1 and noticed problems:
It says that default Pact version is V3 but actually it defaults to v4 here
I went here as I got:
java.lang.UnsupportedOperationException: Method itProvidesStationPact does not conform required method signature 'public au.com.dius.pact.core.model.V4Pact xxx(PactBuilder builder)'
Having pacts defined like:
@Pact(consumer = "my-consumer", provider = "my-provider")
public RequestResponsePact itProvidesStationPact(PactDslWithProvider pactDsl)
- Should I expect that the migration to V4 and
public au.com.dius.pact.core.model.V4Pact xxx(PactBuilder builder)is mandatory? - if yes, maybe I have a guide? As it looks like highly not backward compatible
In general, I'd prefer an easy way to switch into version 4.
Workaround:
Define explicitly version property, it works on the class level as well: @PactTestFor(pactVersion = PactSpecVersion.V3
Simple code example here : https://github.com/McKratt/greetings/blob/master/greetings-stat-service/stat-client/src/test/java/net/bakaar/greetings/stat/rest/client/GreetingsPactConsumerIT.java. Just update the version if it is not already made. I'm working on a branch currently.
If you want to use Pact specification V4, you can do something like this :
@Pact(consumer = "my-consumer", provider = "my-provider")
public V4Pact itProvidesStationPact(PactBuilder builder) {
return builder
.usingLegacyDsl()
.given("your given state")
.uponReceiving("your description")
.method("GET")
[...]
.toPact(V4Pact.class);
}
@mathieu-amblard Thank you, this is a suitable solution. In this issue I see confusion, shall we expect that the latest libraries publish v3 or v4 as default - this is not clear and forces us to do these workarounds
In addition to the existing questions: why is DSL marked as legacy(usingLegacyDsl)? What is the new way of doing this?