1

I have a pact broker running on AWS cloud. I can see some description saying "A pact between app-a-service and app-b-service" at some example url like demo.service.aws.cloud/demo-service/latest" shows the Interactions. This is the response on the broker:

A pact between express-demo-service and spring-demo-service
Requests from express-demo-service to spring-demo-service

Get test envs given tEST_ENV and SECRET_ENV set
Interactions

Given tEST_ENV and SECRET_ENV set, upon receiving get test envs from express-demo-service, with

{
  "method": "GET",
  "path": "/env",
  "headers": {
    "Authorization": "Bearer "
  }
}
spring-demo-service will respond with:

{
  "status": 200,
  "headers": {
    "Content-Type": "application/json"
  },
  "body": {
    "TEST_ENV": "foo",
    "SECRET_ENV": "bar"
  }
}

Now I build my Springboot rest controller that returns those response as defined in the documentation. How do I now run a test to ensure my implementation meets those requirements from the pact broker?

The following is my TestPacts to ensure my implementations meets the contract from broker (not sure this is correct):

@RunWith(PactRunner.class)
@Provider("test_provider" )
@PactBroker(host = "https://mybroker.aws.com/pacts/provider/spring-demo-service/consumer/express-demo-service/latest", port = "80")
@VerificationReports({"console", "markdown"})
public class TestPacts {
    private static final Logger LOG = LoggerFactory.getLogger(TestPacts.class);

    private static ConfigurableApplicationContext application;

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

    @BeforeClass
    public static void startSpring(){
        LOG.info("starting application");
        application = SpringApplication.run(ProviderServiceApplication.class);
    }

    @State("default")
    public void toDefaultState() {
        LOG.info("Now service in default state");
    }

    @State("extra")
    public void toExtraState() {
        LOG.info("Now service in extra state");
    }

    @AfterClass
    public static void kill(){
        LOG.info("stop application");
        application.stop();
    }
}

When I run that I get error:

org.junit.runners.model.InitializationError
    at au.com.dius.pact.provider.junit.PactRunner.initialize(PactRunner.kt:93)
    at au.com.dius.pact.provider.junit.PactRunner.getChildren(PactRunner.kt:140)
    at org.junit.runners.ParentRunner.getFilteredChildren(ParentRunner.java:426)
    at org.junit.runners.ParentRunner.getDescription(ParentRunner.java:351)
    at com.intellij.junit4.JUnit4IdeaTestRunner.getDescription(JUnit4IdeaTestRunner.java:78)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:50)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
    at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
    at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)
Katlock
  • 1,200
  • 1
  • 17
  • 41

2 Answers2

0

I think the issue could be that you're providing a full path to the pact file, instead of just passing the host

i.e.

@PactBroker(host = "https://mybroker.aws.com/pacts/provider/spring-demo-service/consumer/express-demo-service/latest", port = "80")

should be

@PactBroker(host = "https://mybroker.aws.com", port = "443")

Also, the port seems wrong to me. It's unusual that a TLS secured endpoint would be running on port 80 - it's more likely 443.

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

Try to use:

@PactBroker(host = "mybroker.aws.com", scheme = "https", port = "443")

There is a scheme attribute to select http or https. Scheme is equals to http by default, as you are using https you should change that to https.