我正在尝试在提供者方面进行验证,但出现错误 -
验证 DataConsumer 和 DataProvider 之间的协议 [使用文件 pact/DataConsumer-DataProvider.json] 给定某些状态,请求 json 数据请求失败 - 对于输入字符串:“\null”
不知道我在这里错过了什么。
我的宝乔——
@EqualsAndHashCode
@RequiredArgsConstructor
@Builder(toBuilder = true)
@JsonDeserialize(builder = DataModel.DataModelBuilder.class)
public class DataModel {
@JsonProperty("name")
private final String name;
@JsonProperty("price")
private final double price;
}
契约——
{
"provider": {
"name": "DataProvider"
},
"consumer": {
"name": "DataConsumer"
},
"interactions": [
{
"description": "a request for json data",
"request": {
"method": "GET",
"path": "/get/ice/2.0"
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/json; charset\u003dUTF-8"
},
"body": {
"price": 10,
"name": "some name"
},
"matchingRules": {
"header": {
"Content-Type": {
"matchers": [
{
"match": "regex",
"regex": "application/json(;\\s?charset\u003d[\\w\\-]+)?"
}
],
"combine": "AND"
}
}
},
"generators": {
"body": {
"$.name": {
"type": "ProviderState",
"expression": "\\${name}",
"dataType": "STRING"
},
"$.price": {
"type": "ProviderState",
"expression": "\\${price}",
"dataType": "FLOAT"
}
}
}
},
"providerStates": [
{
"name": "some state"
}
]
}
],
"metadata": {
"pactSpecification": {
"version": "3.0.0"
},
"pact-jvm": {
"version": "3.6.15"
}
}
}
测试 -
@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@Provider("DataProvider")
@PactFolder(value = "pact")
public class ContractVerificationTest {
@TestTemplate
@ExtendWith(PactVerificationSpringProvider.class)
void pactVerificationTestTemplate(PactVerificationContext context) {
context.verifyInteraction();
}
@State("some state")
void testPact() {
}
}
代码 -