[英]How to use pact scenario state with wiremock-pact-generator library
我們正在嘗試通過以下參考使用 wiremock-pact-generator 創建一個 pact 合同文件:How ever we could not able to find scenario state handled in the library (wiremock-pact-generator)。
由於我們能夠使用 pactdslwithprovider 庫提供 state,因此我們正在嘗試使用 wiremock-pact-generator 庫來實現同樣的事情。 但是我們找不到提供state的方法。
如果我們遺漏了什么,能否請您告訴我們?
向模擬服務器添加了 wiremock-pact-generation 偵聽器。 `
@BeforeAll
public static void setup() {
mockServer =
new WireMockServer(options().port(1080).extensions(new ResponseTemplateTransformer(true)));
mockServer.addMockServiceRequestListener(
WireMockPactGenerator.builder("product-service-consumer", "producte-service-provider").build());
mockServer.start();
}
`
Wiremock存根:
{
"request" : {
"urlPathPattern" : "/products/1001",
"method" : "GET"
},
"response" : {
"status" : 200,
"body" : "{\"productId\":1001,\"name\": \"Dell Laptop\",\"description\": \"Warranty expiring soon\"}",
"headers" : {
"X-Application-Context" : "application:-1",
"Content-Type" : "application/json"
},
"transformers" : [ "response-template" ]
}
}
契約生成的文件:
{
"consumer": {
"name": "product-service-consumer"
},
"provider": {
"name": "product-service-provider"
},
"interactions": [
{
"description": "GET /products/1001 -> 200",
"request": {
"method": "GET",
"path": "/products/1001",
"headers": {
"content-type": "application/json",
"accept-encoding": "gzip",
"accept": "*/*",
"user-agent": "ReactorNetty/1.0.24"
}
},
"response": {
"status": 200,
"headers": {
"content-type": "application/json",
"x-application-context": "application:-1"
},
"body": {
"productId": 1001,
"name": "Dell Laptop",
"description": "Warranty expiring soon"
}
}
}
]
}
如何確保場景 state 應該添加到契約合同生成文件中:在這種情況下:“provider_state”:“Fetch Product for Id 1001”應該在交互中。
{
"consumer": {
"name": "product-service-consumer"
},
"provider": {
"name": "product-service-provider"
},
"interactions": [
{
*"provider_state": "Fetch Product for Id 1001",*
"description": "GET /products/1001 -> 200",
"request": {
"method": "GET",
"path": "/products/1001",
"headers": {
"content-type": "application/json",
"accept-encoding": "gzip",
"accept": "*/*",
"user-agent": "ReactorNetty/1.0.24"
}
},
"response": {
"status": 200,
"headers": {
"content-type": "application/json",
"x-application-context": "application:-1"
},
"body": {
"productId": 1001,
"name": "Dell Laptop",
"description": "Warranty expiring soon"
}
}
}
]
}
Pact Wiremock 庫不支持設置提供者狀態。
你想通過使用它們來實現什么? 它實際上並不打算用於 Pact 驗證,而是用於其他情況(例如 swagger 模擬驗證器或 Pactflow 的雙向合同測試功能,不需要狀態)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.