gpt4 book ai didi

java - WireMock 使用错误的 __files 目录进行多目录映射配置

转载 作者:行者123 更新时间:2023-12-01 20:07:40 25 4
gpt4 key购买 nike

我使用带有 spring-cloud-contract-wiremockcom.github.tomakehurst.wiremock 依赖项的 Spring Boot。我的wiremock 定义存储在json 文件中。像这样:

directoryA/mappings/detail-mapping-123.json:

{
"request" : {
"urlPath" : "/detail/123",
"method" : "GET"
},
"response" : {
"status" : 200,
"bodyFileName" : "detail.json",
"headers" : {
"Content-Type" : "application/json;charset=UTF-8"
}
}
}

目录A/__files/detail.json:

{
"id": "123",
"name": "name-123"
}

directoryB/mappings/search-mapping-123.json:

{
"request" : {
"urlPath" : "/service/usa/search",
"queryParameters" : {
"query": {
"equalTo": "123"
}
},
"method" : "GET"
},
"response" : {
"status" : 200,
"bodyFileName" : "search-123.json",
"headers" : {
"Content-Type" : "application/json;charset=UTF-8"
}
}
}

directoryB/__files/search-123.json:

{
"count": 1,
"units": [
{
"name": "A123"
}
]
}

我有标准的 JUnit 测试类,其注释为:

@AutoConfigureWireMock(stubs = {"classpath:/directoryA/mappings", "classpath:/directoryB/mappings"},
files = {"classpath:/directoryA", "classpath:/directoryB"},
port = 18081)

该文件看起来被wiremock正确识别,并且所有定义都被正确解析,但问题在于为请求分配正确的正文文件:当应用程序尝试执行请求时:

GET http://localhost:18081/service/usa/search?query=123 HTTP/1.1

然后我收到错误:

java.lang.RuntimeException: java.io.FileNotFoundException: /home/my-project-dir/target/test-classes/directoryA/__files/search-123.json (Not found such file or directory) 

所以...问题是wiremock在目录directoryA中搜索映射定义的bodyFileName部分(directoryB/mappings/search-mapping-123.json)中定义的文件,而不是目录B,使用映射文件的位置。如果有的话会用到

/home/my-project-dir/target/test-classes/directoryB/__files/search-123.json

然后一切都应该正常工作......

有人遇到过类似的问题吗?我不确定这是否是我的配置或wiremock 库中的错误。

最佳答案

尝试从注释@AutoConfigureWireMock中排除“stubs”和“files”参数,并将映射/文件放在src/test/resources中,wiremock默认从这些路径获取

关于java - WireMock 使用错误的 __files 目录进行多目录映射配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52376252/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com