question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Spring boot and @PactBroker is not working as expected with system properties

See original GitHub issue

In Spring Boot you can provide an application.properties/application.yml file that contains system properties and environment properties.

I use some of the system variables in my test

PactVerificationTest.java

@RunWith(SpringRestPactRunner.class)
@Provider("someprovider")
@IgnoreNoPactsToVerify
@PactBroker(
        protocol = "https",
        host = "${pactbroker.host}", port = "${pactbroker.port}",
        authentication =  @PactBrokerAuth(username = "${pactbroker.auth.username}", password = "${pactbroker.auth.password}")
)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public class PactVerificationTest {

    @TestTarget
    public final Target target = new HttpTarget(50519);

    @MockBean
    private EmailController emailController;

    @Before
    public void beforeTests() {
        doNothing().when(emailController).sendEmail(any(Email.class));
    }

    @State({"default", "extra"})
    public void toDefaultState() {
        System.out.println("Now service in default state");
    }
}

And then I name these variables in the configuration file

application.yml

pactbroker:
  host: "my.host.name.org"
  port: "443"
  auth:
    username: "myusername"
    password: "mypassword"

Unfortunately this does not work and I get a RuntimeError java.lang.RuntimeException: Could not resolve property "pactbroker.host" in the system properties or environment variables and no default value is supplied

So it seems as it wont read the variables.

Versions: Spring Boot 2.0.0.M7 au.com.dius:pact-jvm-provider-spring_2.12 3.5.11

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
uglyogcommented, Mar 12, 2018

This has now been implemented. I have a test project https://github.com/uglyog/pact-springboot-test with this working nicely.

0reactions
uglyogcommented, Mar 19, 2018

3.5.14 has now been released

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spring boot and @PactBroker is not working as expected with ...
In Spring Boot you can provide an application.properties/application.yml file that contains system properties and environment properties.
Read more >
Having trouble in verifying the PACT from provider side using ...
Consumer side is working fine. It has generated pact and published too on pact broker URL. Yes it is expecting a status code...
Read more >
Pact junit runner | Pact Docs
The pact broker loader was updated to allow system properties to be used for the hostname, port or protocol. The port was changed...
Read more >
Spring Cloud Contract Reference Documentation
We talk about Provider Contracts when it is the producer of the API that defines the contracts and publishes it for all its...
Read more >
Writing Contract Tests with Pact in Spring Boot
The unit test will do two things: It verifies that our code can handle the expected provider responses and - as a nice...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found