我有一个简单的端点线程存根。调用此存根的库需要cookie存在于响应中。有没有一种简单的方法可以在wiremock配置的响应中提供cookie
用于存根端点的示例代码:
stubFor(post(urlPathEqualTo("/endpoint"))
.willReturn(aResponse()
.withStatus(OK.getStatusCode())
//with a cookie;
这可行吗?我使用以下wiremock版本
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock</artifactId>
<version>2.19.0</version>
</dependency>
Cookie只不过是一个带有属性名称的HTTP标头:“Set-Cookie”。下面的示例适用于JSON变体,但应该很容易转换为Java样式:.withHeader("Set-Cookie", "JSESSIONID=dcba")));
{
"metadata": {
"title": "Cookie example",
"description": "Example to return a Cookie",
},
"request": {
"method": "ANY",
"urlPath": "/returnCookie"
},
"response": {
"status": 200,
"headers": {
"Set-Cookie": ["JSESSIONID=ABSCDEDASDSSDSSE.oai007; path=/; Secure; HttpOnly"]
},
"body": "This stores a cookie";
}
}