我有一个用 Junit5 编写的契约消费者测试。
DslPart mySettingsDsl = PactDslJsonArray.arrayEachLike()
.eachKeyLike("sumne", PactDslJsonRootValue.stringMatcher("sumne|sid", "sumne"))
.stringMatcher("sid", "[a-zA-Z0-9]{1,10}")
.object("sumne", new PactDslJsonBody()
.stringType(FOOTER, "footer")
.stringType(HEADER, "header")
.stringMatcher(MIDDLE, "\\d{7}")
.stringMatcher(END, "\\d{3}")
.asBody()
).close();
return builder
.uponReceiving("Some Description")
.matchPath("/v1/" + UUID_REGEX + "/customization")
.method(GET.name())
.willRespondWith()
.status(200)
.matchHeader(CONTENT_TYPE, APPLICATION_JSON.getMimeType())
.body(new PactDslJsonBody()
.stringType(STATUS, "ok")
.object(DATA, new PactDslJsonBody()
.stringMatcher(CODE, "\\d{14}")
.stringMatcher(APP_NO, "\\d{5}")
.stringType(PROD_NAME, "product1")
.object(MY_SETTINGS, mySettingsDsl)
.asBody())
.asBody())
.toPact();
它会生成一个像这样的协议文件
{
"provider": {
"name": "provider"
},
"consumer": {
"name": "consumer"
},
"interactions": [
{
"description": "Some Description",
"request": {
"method": "GET",
"path": "/v1/C2D0B4D3-0Bdc-5CDa-2ffF-E8fEb0c9fE1B/customization",
"matchingRules": {
"path": {
"matchers": [
{
"match": "regex",
"regex": "/v1/[0-9a-fA-F]{8}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{12}/customization"
}
],
"combine": "AND"
}
}
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/json"
},
"body": {
"data": {
"code": "84502366577143",
"appNo": "76703",
"mySettings": [
{
"sumne": {
"footer": "footer",
"header": "header",
"middle": "8230126",
"end": "916"
},
"sid": "EfL6wZ"
}
],
"prodName": "product1"
},
"status": "ok"
},
"matchingRules": {
"header": {
"Content-Type": {
"matchers": [
{
"match": "regex",
"regex": "application/json"
}
],
"combine": "AND"
}
},
"body": {
"$.status": {
"matchers": [
{
"match": "type"
}
],
"combine": "AND"
},
"$.data.code": {
"matchers": [
{
"match": "regex",
"regex": "\\d{14}"
}
],
"combine": "AND"
},
"$.data.appNo": {
"matchers": [
{
"match": "regex",
"regex": "\\d{5}"
}
],
"combine": "AND"
},
"$.data.prodName": {
"matchers": [
{
"match": "type"
}
],
"combine": "AND"
},
"$.data.mySettings": {
"matchers": [
{
"match": "type",
"min": 0
}
],
"combine": "AND"
},
"$.data.mySettings[*].*": {
"matchers": [
{
"match": "regex",
"regex": "sumne|sid"
}
],
"combine": "AND"
},
"$.data.mySettings[*].sid": {
"matchers": [
{
"match": "regex",
"regex": "[a-zA-Z0-9]{1,10}"
}
],
"combine": "AND"
},
"$.data.mySettings[*].sumne.footer": {
"matchers": [
{
"match": "type"
}
],
"combine": "AND"
},
"$.data.mySettings[*].sumne.header": {
"matchers": [
{
"match": "type"
}
],
"combine": "AND"
},
"$.data.mySettings[*].sumne.middle": {
"matchers": [
{
"match": "regex",
"regex": "\\d{7}"
}
],
"combine": "AND"
},
"$.data.mySettings[*].sumne.end": {
"matchers": [
{
"match": "regex",
"regex": "\\d{3}"
}
],
"combine": "AND"
}
}
},
"generators": {
"body": {
"$.data.code": {
"type": "Regex",
"regex": "\\d{14}"
},
"$.data.appNo": {
"type": "Regex",
"regex": "\\d{5}"
},
"$.data[*].sid": {
"type": "Regex",
"regex": "[a-zA-Z0-9]{1,10}"
},
"$.data[*].sumne.middle": {
"type": "Regex",
"regex": "\\d{7}"
},
"$.data[*].sumne.end": {
"type": "Regex",
"regex": "\\d{3}"
}
}
}
}
}
],
"metadata": {
"pactSpecification": {
"version": "3.0.0"
},
"pact-jvm": {
"version": "4.1.13"
}
}
}
但是当使用我推送到协议代理时,我在协议代理中mvn pact:publish
只看到了其中的一部分。
{
"status": 200,
"headers": {
"Content-Type": "application/json"
},
"body": {
"data": {
"code": "84502366577143",
"appNo": "76703",
"mySettings": [
],
"prodName": "product1"
},
"status": "ok"
}
}
我在 pactbroker 上看到的 pact 文件中的 mySettings 数组完全为空。这里可能是什么问题?