次のような契約があるとします。
org.springframework.cloud.contract.spec.Contract.make {
request {
method "GET"
url "/api/profiles"
headers {
header('Accept': 'application/json;charset=UTF-8')
header('Content-Type': 'application/json;charset=UTF-8')
}
}
response {
status 200
headers {
header('Content-Type': 'application/json;charset=UTF-8')
}
body(
value(
stub(
'''\
[
{
"profile": "profile1",
},
{
"profile": "profile2",
}
]
'''
),
test(
[
[
"profile" : regex(nonEmpty()),
]
]
)
)
)
}
のみのテストは、空でない属性を"profile" : regex(nonEmpty())
持つ配列エントリが少なくとも 1 つあることを確認します。profile
すべてのエントリに空でない があることをテストしたいと思いますprofile
。
私はすでにテストマッチャーを使用してこれを試しました:
jsonPath('$.[*].profile', byRegex(nonEmpty()))
これはすべてprofile
のフィールドが空でないことを確認しますが、そのようなフィールドが実際に存在するかどうかは確認しません。
profile
すべての配列エントリにフィールドが存在し、それぞれが空でないことをテストするにはどうすればよいですか?