PaChSu
PaChSu

Reputation: 307

Pact JVM Junit Consumer Compilation Error

I am writing the Consumer Side Code for Pact using JVm-Junit library. However at the line : MockProviderConfig config = MockProviderConfig.createDefault(); i am getting error "createDefault() is not undefined for the type MockProviderConfig"

What can I do to proceed.

My POM File looks like this : http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 Consumer_0805 Consumer_080517 0.0.1-SNAPSHOT war

<dependencies>
    <dependency>
        <groupId>au.com.dius</groupId>
        <artifactId>pact-jvm-consumer-junit_2.11</artifactId>
        <version>3.2.9</version>
    </dependency>
</dependencies>

Test Code :

package DSLDirectConsumerTest;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.junit.Test;

import au.com.dius.pact.consumer.ConsumerPactBuilder;
import au.com.dius.pact.model.MockProviderConfig;
import au.com.dius.pact.model.MockProviderConfig$;
import au.com.dius.pact.model.PactConfig;
import au.com.dius.pact.model.PactFragment;
import au.com.dius.pact.model.RequestResponsePact;

public class DirectDSLConsumerPactTest {

    @Test
    public void testPact() {
        PactFragment pactFragment = ConsumerPactBuilder.consumer("Some Consumer").hasPactWith("Some Provider")
                .uponReceiving("a request to say Hello").path("/hello").method("POST").body("{\"name\": \"harry\"}")
                .willRespondWith().status(200).body("{\"hello\": \"harry\"}").toFragment();

        MockProviderConfig.createDefault();

    }

}

Upvotes: 0

Views: 602

Answers (1)

Ronald Holshausen
Ronald Holshausen

Reputation: 931

In version 3.3.8, the MockProviderConfig class is a groovy class, so can be accessed normally.

Prior to version 3.3.0, it was both a Scala Singleton Object and Class, so you would need to access it appropriately as per calling Scala classes from Java.

As createDefault() is defined on the companion singleton object, the correct way to refer to it is:

MockProviderConfig$.MODULE$.createDefault();

Upvotes: 1

Related Questions