这是我的junit代码。无法使用模拟HTTP/HTTPS获取json/xml响应的发布请求
我下面这些文件,以模拟服务器http://www.mock-server.com/
mockServerClient=new MockServerClient("127.0.0.1", 8080)
.when(
request()
.withMethod("POST")
.withPath("/login")
.withQueryStringParameters(
new Parameter("returnUrl", "/account")
)
.withCookies(
new Cookie("sessionId", "2By8LOhBmaW5nZXJwcmludCIlMDAzMW")
)
.withBody(exact("{username: 'foo', password: 'bar'}")),
exactly(1)
)
.respond(
response()
.withStatusCode(401)
.withHeaders(
new Header("Content-Type", "application/json; charset=utf-8"),
new Header("Cache-Control", "public, max-age=86400")
)
.withBody("{ message: 'incorrect username and password combination' }")
.withDelay(new Delay(TimeUnit.SECONDS, 1))
);
问题是请求,响应,准确,精确,头都没有得到编辑器中解决。 一些额外的进口必须要求,但我找不到任何工作示例/替代它。
我需要的仅仅是嘲笑服务器的url请求和响应在Junits中使用。 作为模拟服务器的替代品,我也试过Mockwebserver- https://github.com/square/okhttp/tree/master/mockwebserver
但它也有很多限制,例如我无法使用mockwebserver进行发布。 还检查此处建议的其他选项https://stackoverflow.com/questions/393099/mocking-http-server。 如果有人知道工作解决方案,请帮助我。 在此先感谢
我可以使用[Wiremock](http://wiremock.org/index.html)工作。 – SwANDp