【问题标题】:Wiremock - Autoconfigure doesn't load stubsWiremock - 自动配置不加载存根
【发布时间】:2020-11-19 13:10:33
【问题描述】:

我的wiremock 似乎不适用于自动配置。我在类路径中名为 stubs 的文件夹中有 json 文件,我在端口 8080 上运行了独立 jar。

@AutoConfigureWireMock(stubs="classpath:/stubs", port = 0)
public class TestResource {

    @Autowired
    private Service service;

    @Test
    public void contextLoads() throws Exception {
        assertThat(this.service.go()).isEqualTo("Hello World!");
    }

}

json 文件示例

{
  "request" : {
    "url" : "/api/users",
    "method" : "GET",
    "bodyPatterns" : [ {
      "contains" : "some soap body"
    }]
  },
  "response" : {
    "status" : 200,
    "body" : "Hello World",
    "headers" : {
      "X-Application-Context" : "application:-1",
      "Content-Type" : "text/plain"
    }
  }
}

当我使用 GET -> localhost:8080/api/users/ 发起请求时,它与 json 文件不匹配。

提前致谢

【问题讨论】:

  • @AutoConfigureWireMock 的默认端口是 8080,这里尽量不要指定。

标签: java spring spring-boot stub wiremock


【解决方案1】:

我只是在 localhost:8080/__admin/mappings/import 上通过 POST 请求添加了我所有的 json http://wiremock.org/docs/stubbing/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-06-20
    • 2017-12-03
    • 2011-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多