mockserver
mockserver copied to clipboard
ONLY_MATCHING_FIELDS is failing a request that STRICT is not
Describe the issue Switching the mock request to ONLY_MATCHING_FIELDS makes the mock to fail matching previously working in STRICT. My understanding is that the ONLY_MATCHING_FIELDS is omitting extra JSON field and Array element.
What you are trying to do I am trying to make multiple payload matching a single mock rule. The idea is that all the optional fields are added at the end of the Array list or spread in JSON but not validated unless a payload that has them comes.
MockServer version 5.14.0
To Reproduce Steps to reproduce the issue:
- How you are running MockServer (i.e maven plugin, docker, etc): Kubernetes/Docker
- Code you used to create expectations
{
"id": "s2gm_create_mosaic_mock",
"httpRequest": {
"method": "POST",
"path": "/Batches/Create",
"headers": {
"x-application": "mock_s2gm"
},
"body": {
"type": "JSON",
"json": {
"ParentId": "${json-unit.ignore-element}",
"Name": "TEMPORAL_MOSAIC_MASTER",
"Path": "/bin/bash",
"Parameters": [
"/opt/s2gm/bin/temporal_mosaic_master.sh",
"-on",
"${json-unit.ignore-element}",
"-n",
"${json-unit.ignore-element}",
"-o",
"${json-unit.ignore-element}",
"-l",
"${json-unit.ignore-element}",
"-of",
"${json-unit.regex}geotiff|netcdf|jpeg2000",
"-r",
"${json-unit.regex}\\d{2}",
"-bd",
"${json-unit.regex}8|16",
"-p",
"${json-unit.regex}WGS84|UTM",
"-b",
"${json-unit.regex}B[0-9]{2}",
"-b",
"${json-unit.any-string}",
"-b",
"${json-unit.any-string}",
"-ab",
"${json-unit.regex}aot|cloud_confidence|snow_confidence|scene_classification|validation_source_index|medoid_quality_band|sun_zenith|sun_azimut|view_zenith_mean|view_azimuth_mean|valid_observations",
"-ab",
"${json-unit.regex}aot|cloud_confidence|snow_confidence|scene_classification|validation_source_index|medoid_quality_band|sun_zenith|sun_azimut|view_zenith_mean|view_azimuth_mean|valid_observations",
"-a",
"${json-unit.any-string}",
"-s",
"${json-unit.regex}\\d{4}-\\d{2}-\\d{2}",
"-e",
"${json-unit.regex}\\d{4}-\\d{2}-\\d{2}",
"-c",
"${json-unit.regex}ESA|LX|Union",
]
},
"matchType": "ONLY_MATCHING_FIELDS"
}
},
"httpResponseTemplate": {
"template": "{ statusCode: 200, body: {BatchId: '$!uuid',created: true} }",
"templateType": "VELOCITY"
}
},
- What error you saw missing element at "null", missing element at "null", missing element at "null", missing element at "null", missing element at "null", missing element at "null", missing element at "null", missing element at "null"
Expected behaviour Expect the rule to match a call with a payload:
{"Name":"TEMPORAL_MOSAIC_MASTER","Parameters":["/opt/s2gm/bin/temporal_mosaic_master.sh","-on","testMosaic","-n","df71a899-d8eb-489a-8bb7-35b889f94d28","-o","/mnt/data/output/f887e7c2-bc6b-4d31-a005-3bf3edaa7546/df71a899-d8eb-489a-8bb7-35b889f94d28","-l","df71a899-d8eb-489a-8bb7-35b889f94d28_logs.json","-of","geotiff","-r","10","-bd","16","-p","WGS84","-b","B02","-b","B03","-b","B04","-ab","valid_observations","-ab","validation_source_index","-a","{\"type\":\"Polygon\",\"coordinates\":[[[4.921875,42.58544426],[4.921875,44.37098696],[7.51464844,44.37098696],[7.51464844,42.58544426],[4.921875,42.58544426]]]}","-s","2022-06-11","-e","2022-06-20"],"ParentId":"df71a899-d8eb-489a-8bb7-35b889f94d28","Path":"/bin/bash"}
MockServer Log Log output, as INFO level (or lower)