1

我有一个在 AWS 云上运行的协议代理。我可以在 demo.service.aws.cloud/demo-service/latest 之类的示例 url 上看到一些描述说“app-a-service 和 app-b-service 之间的协议”显示了交互。这是对经纪人:

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"
  }
}

现在我构建了我的 Springboot 休息控制器,它返回文档中定义的那些响应。我现在如何运行测试以确保我的实现满足协议代理的这些要求?

以下是我的 TestPacts,以确保我的实现符合经纪人的合同(不确定这是否正确):

@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();
    }
}

当我运行时,我得到错误:

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)
4

2 回答 2

0

我认为问题可能是您提供了协议文件的完整路径,而不仅仅是传递主机

IE

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

应该

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

此外,端口对我来说似乎是错误的。TLS 安全端点在端口上运行是不寻常的80- 更有可能是443.

于 2020-03-17T09:51:35.577 回答
0

尝试使用:

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

有一个 scheme 属性可以选择 http 或 https。默认情况下,Scheme 等于 http,因为您使用的是 https,所以应该将其更改为 https。

于 2020-03-20T04:50:22.827 回答