当我尝试使用MockServer模拟外部HTTP API时,mockserver返回java.lang.IllegalArgumentException
这是测试代码:
new MockServerClient("localhost", 1080)
.when(request("/messages")
.withMethod("POST")
.withQueryStringParameters(
param("subject", "integration-test-subject")
)
).respond(response().withStatusCode(200));
这是例外:
java.lang.IllegalArgumentException: Exception while parsing
[
{
"httpRequest":{
"method":"POST",
"path":"/messages",
"queryStringParameters":{
"subject":[
"integration-test-subject"
]
}
},
"httpResponse":{
"statusCode":200
},
"times":{
"remainingTimes":0,
"unlimited":true
},
"timeToLive":{
"unlimited":true
}
}
] for Expectation
这是 jackson 的例外:
com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.lang.String` out of FIELD_NAME token
at
[
Source:(String)" {
"httpRequest":{
"method":"POST",
"path":"/messages",
"queryStringParameters":{
"subject":[
"integration-test-subject"
]
}
},
"httpResponse":{
"statusCode":200
},
"times":{
"remainingTimes":0,
"unlimited":true
},
"timeToLive":{
"unlimited":true
}
}
我正在尝试通过主体发送
application/x-www-form-urlencoded
请求subject:integration-test-subject
如果在测试中不存在
.withQueryStringParameters(param("subject", "integration-test-subject"))
,则它正常。如何解决这个问题?
最佳答案
这是GitHub中的问题,并有解释
https://github.com/jamesdbloom/mockserver/issues/451
您可以更新到5.4.1