pact-foundation / pact-jvm

JVM version of Pact. Enables consumer driven contract testing, providing a mock service and DSL for the consumer project, and interaction playback and verification for the service provider project.
https://docs.pact.io
Apache License 2.0
1.08k stars 479 forks source link

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

Open artemptushkin opened 2 years ago

artemptushkin commented 2 years ago

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)

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

McKratt commented 2 years ago

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.

mathieu-amblard commented 2 years ago

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);
    }
artemptushkin commented 2 years ago

@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

systemallica commented 2 years ago

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