pact-jvm icon indicating copy to clipboard operation
pact-jvm copied to clipboard

Pact JVM defaults to pact version v4 when it says V3 in the Java doc

Open artemptushkin opened this issue 3 years ago • 4 comments

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

artemptushkin avatar Dec 06 '21 11:12 artemptushkin

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.

McKratt avatar Dec 16 '21 14:12 McKratt

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 avatar Jan 19 '22 06:01 mathieu-amblard

@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

artemptushkin avatar Jan 19 '22 08:01 artemptushkin

In addition to the existing questions: why is DSL marked as legacy(usingLegacyDsl)? What is the new way of doing this?

systemallica avatar May 05 '22 14:05 systemallica