1
@PactBroker(scheme = "https", host = "${pactbroker.host}", authentication = @PactBrokerAuth(token = "${pactbroker.auth.token}"))
@Provider("PriceService")
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
@ExtendWith(SpringExtension.class)

public class PriceServicePactTests {

    @LocalServerPort
    private final int port = 8082;
    ObjectMapper objectMapper = new ObjectMapper();
    @MockBean
    private PriceDAO priceDao;

    @BeforeEach
    public void setupTest(final PactVerificationContext context) {
        // TODO Catch enviroment variable
        System.setProperty("pact.provider.tag", "dev");

        // TODO Get version from project properties
        System.setProperty("pact.provider.version", "1.0.0");

        context.setTarget(new HttpTestTarget("localhost", port, "/"));
    }

    @BeforeClass
    public void enablePublishingPact() {
        System.setProperty("pact.verifier.publishResults", "true");
    }

    @TestTemplate
    @ExtendWith(PactVerificationInvocationContextProvider.class)
    void pactVerificationTestTemplate(final PactVerificationContext context) {
        context.verifyInteraction();
    }

I'm using this dependency on provider:

<!-- https://mvnrepository.com/artifact/au.com.dius/pact-jvm-provider-junit5 -->
<dependency>
    <groupId>au.com.dius</groupId>
         <artifactId>pact-jvm-provider-junit5</artifactId>
         <version>4.0.10</version>
</dependency>

When I run the test I got the error: java.lang.RuntimeException: Could not resolve property "pactbroker.host" in the system properties or environment variables and no default value is supplied

gustavomcastro
  • 155
  • 1
  • 9
  • where do you specify the `pactbroker.host`? Inside your `application.yml`? – rieckpil Jul 30 '20 at 04:41
  • Yes, I did it on application.yml # Pact.io configuration pactbroker: host: ${PACT_HOST:pact_host} auth: token: ${PACT_TOKEN:my_token} – gustavomcastro Aug 04 '20 at 21:02
  • I think that its a known issue with pact dependency github.com/DiUS/pact-jvm/issues/1023 . I openned an issue github.com/DiUS/pact-jvm/issues/1178 – gustavomcastro Aug 04 '20 at 21:09

1 Answers1

0

Have you externalised your configuration correctly as per https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-external-config?

Here is an example you can follow (it uses environment variables but the process is the same): https://github.com/pactflow/example-provider-springboot/blob/master/src/test/java/com/example/springboot/ProductsPactTest.java#L23

Matthew Fellows
  • 3,669
  • 1
  • 15
  • 18