刚开始使用wiremock并遇到一个场景,我想用特定的json响应来存根GET请求.
将json附加到预期响应时;
.withBodyFile("product.json"))
Run Code Online (Sandbox Code Playgroud)
我得到异常java.io.FileNotFoundException:src/test/resources/__ files/product.json(没有这样的文件或目录).
问题是我在这个位置有json文件.
我在wiremock中定义了一个https存根,如下所示:-
public class HttpsMockMain {
public static void main(String[] args) {
WireMockServer mockServer = new WireMockServer(56789, 8443);
addStub(mockServer);
mockServer.start();
}
private static void addStub(WireMockServer mockServer) {
ResponseDefinitionBuilder responseBuilder = aResponse().withStatus(200).withBody(
"{\"message\":null,\"httpStatus\":0,\"status\":{\"httpStatusCode\":200,\"success\":true,\"errors\":[]},\"_metaData\":{\"urlParams\":{}},\"debugData\":null,\"data\":[\"01125851014\",\"01125851014\",\"debraj.manna@jabong.com\",\"03325853088\",\"03325853088\",\"debraj.manna@rediffmail.com\"],\"httpStatusToBeReturned\":200}");
mockServer.stubFor(post(urlPathEqualTo("/oms-api/")).willReturn(responseBuilder));
}
}
Run Code Online (Sandbox Code Playgroud)
每当我向https://localhost:8443/oms-api/发送 POST 请求时,我都会收到以下异常:-
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Run Code Online (Sandbox Code Playgroud)
是否可以告诉 WireMock 接受任何证书?我在wiremock 1.58和java 1.8。
是否有人在记录服务器响应方面有完整的,最新的教程或项目-根据需要获取,发布和标头,以及使用Wiremock和/或模拟Web服务器播放它们?
我已经看了很多
我正在使用 WireMock 来模拟 SOAP 服务。
它工作得很好,但其中一项服务包含附件。有没有办法用 WireMock 来模拟它?
谢谢
我是Wiremock的新手,并且正在使用Wiremock JSON映射来测试项目中的某些方案。
在一种测试场景中,我需要对尝试访问JSON映射URL之一(例如/ retry)的服务器进行两次重试(500)后,给响应200 OK。
我可以通过引用Wiremock 的有状态行为来实现这一点http://wiremock.org/docs/stateful-behaviour/
但是问题在于,它仅在一个服务器或线程正在访问它时才起作用。但是,如果多个服务器/实例/线程将尝试访问同一服务器/实例/线程,则这将导致行为不一致,因为Wiremock在内部更改状态。
因此,查询的方式是如何使此方案具有线程安全性,以便获得一致的结果?
PS:我准备从JSON映射转移到Wiremock的 JAVA使用率,甚至JUnits使用率。但不确定是否能解决我的问题。另外,我不想使用Junit用法,因为我没有在测试模块的现有项目中进行此更改,而是创建了单独的Wiremock服务器来进行独立测试。
我尝试将wiremock设置为在随机端口上运行https:
@Rule
public WireMockRule wireMockServer = new WireMockRule(
WireMockConfiguration.wireMockConfig().dynamicPort().dynamicHttpsPort()
);
Run Code Online (Sandbox Code Playgroud)
但是当我使用这个并打电话时,wireMockServer.httpsPort()我得到了异常:
java.lang.IllegalStateException: Not listening on HTTPS port. Either HTTPS is not enabled or the WireMock server is stopped.
at com.google.common.base.Preconditions.checkState(Preconditions.java:150)
at com.github.tomakehurst.wiremock.WireMockServer.httpsPort(WireMockServer.java:184)
Run Code Online (Sandbox Code Playgroud)
如何设置 WireMock 使用 https?
注意:我使用的是 2.14.0 版本
我有一个Wiremock服务器的独立实例。映射作为json文件存储在mappings文件夹下。我有一个POST请求,需要在响应中返回动态ID(整数)。有没有办法在json文件中配置它?
我在我的项目中使用 docker-compose 并旋转 rodolpheche/wiremock 图像,如下所示
wiremock:
image: rodolpheche/wiremock
ports:
- "xxxx:xxxxx"
volumes:
- ./src/wiremock:/home/wiremock
Run Code Online (Sandbox Code Playgroud)
现在我想向上面的wiremock 图像添加一些随机主体变压器扩展。扩展路径是 = org.m.BodyRandomizer
我已经看到了关于添加扩展的 docker 页面(https://hub.docker.com/r/rodolpheche/wiremock/),但我无法得到太多。
我正在使用WireMock-Net来存根请求。
我要执行以下请求:
请求:
http://localhost:63078/services/query/?q=SELECT Id from User where username='user@gmail.com'
Run Code Online (Sandbox Code Playgroud)
该请求由SOQL查询组成。这是我尝试做的一小段:
stub.Given(Request.Create()
.WithPath("/services/query/")
.WithParam("q", "SELECT Id from User where username='user@gmail.com'")
.UsingGet())
.RespondWith(Response.Create()
.WithStatusCode(200)
.WithHeader("Content-Type", "application/json")
.WithBodyAsJson(new { Id = "5bdf076c-5654-4b3e-842c-7caf1fabf8c9" }));
Run Code Online (Sandbox Code Playgroud)
问题是:wiremock总是以404答复。我也尝试过使用RegexMatcher,如下所示:
.WithPath("/services/query/")
.WithParam("q", new WireMock.Matchers.RegexMatcher("SELECT Id from User where username.*$"))
Run Code Online (Sandbox Code Playgroud)
但我仍然得到404。
我认为问题出在查询参数中,因为它有两个等于“ =”。有人可以帮我解决这个问题吗?
我想知道 WireMock 默认情况下是否支持 keep-alive,或者我需要在某处明确设置它。
我已经设置了一个基本的 WireMock 独立版本,它接受请求并生成 json 有效负载。但是,当我curl -v 服务时,我没有看到生成的 Connection: keep-alive 标头。
另外,当我使用带有 -k 选项的 apache 基准工具调用模拟服务时,我确实看到创建和销毁了很多连接,这意味着默认情况下,wiremock 不支持保持活动状态。
我认为 WireMock 服务器上一定有一些东西告诉它默认支持持久连接?
问候,阿迪