spring-cloud - Wiremock 错误:请求不匹配,因为没有注册存根
问题描述
@ClassRule
public static WireMockRule wireMockRule = new WireMockRule(9898);
@Test
public void createXmlFile() {
stubFor(get(urlPathEqualTo("/data/racing/"))
.willReturn(aResponse()
.withBody(loadJSONFile("unibet-demo-input.json"))));
}
我不知道这里出了什么问题!
2019-01-16 15:54:05.810 [qtp1929284175-20] INFO ROOT:2341 - RequestHandlerClass from context returned com.github.tomakehurst.wiremock.http.StubRequestHandler. Normalized mapped under returned 'null'
2019-01-16 15:54:05.822 [qtp1929284175-15] INFO __admin:2341 - RequestHandlerClass from context returned com.github.tomakehurst.wiremock.http.AdminRequestHandler. Normalized mapped under returned 'null'
2019-01-16 15:54:05.925 [qtp1929284175-20] ERROR WireMock:40 - Request was not matched as there were no stubs registered:
{
"url" : "/data/racing/",
"absoluteUrl" : "http://localhost:9898/data/racing/",
"method" : "GET",
"clientIp" : "127.0.0.1",
"headers" : {
"User-Agent" : "Jakarta Commons-HttpClient/3.1",
"Host" : "localhost:9898",
"batchID" : "1056178410254123336",
"breadcrumbId" : "ID-SBGML01938-1547654042343-0-1"
},
"cookies" : { },
"browserProxyRequest" : false,
"loggedDate" : 1547654045870,
"bodyAsBase64" : "",
"body" : "",
"scheme" : "http",
"host" : "localhost",
"port" : 9898,
"loggedDateString" : "2019-01-16T15:54:05Z",
"queryParams" : { }
}
单击以查看不同之处在于说明内容相同。
com.github.tomakehurst.wiremock.client.VerificationException: A request was unmatched by any stub mapping. Closest stub mapping was: <Click to see difference>
at com.github.tomakehurst.wiremock.client.VerificationException.forSingleUnmatchedRequest(VerificationException.java:43)
at com.github.tomakehurst.wiremock.client.VerificationException.forUnmatchedNearMisses(VerificationException.java:48)
at com.github.tomakehurst.wiremock.junit.WireMockRule.checkForUnmatchedRequests(WireMockRule.java:92)
at com.github.tomakehurst.wiremock.junit.WireMockRule.access$000(WireMockRule.java:34)
at com.github.tomakehurst.wiremock.junit.WireMockRule$1.evaluate(WireMockRule.java:74)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
解决方案
我必须在 stubFor 上添加 wireMockRule 才能使其工作。
@ClassRule
public static WireMockRule wireMockRule = new WireMockRule(9898);
@Test
public void createXmlFile() {
wireMockRule.stubFor(get(urlPathEqualTo("/data/racing/"))
.willReturn(aResponse()
.withBody(loadJSONFile("unibet-demo-input.json"))));
}
推荐阅读
- python-2.7 - TypeError: urlopen() 在 Xubuntu 14.04.5 上尝试 Selenium 时获得了关键字参数“body”的多个值
- google-apps-script - 从 Google 表格中确定活动的 Google 幻灯片文件
- node.js - NPM 'run start' 命令给出“npm ERR!code ELIFECYCLE”错误
- python - Ping 脚本 - 如果响应
- asp.net-mvc - 无法使用反射访问运行时缓存
- python - 如何求解非线性方程?
- animation - 如何在 Flutter 中创建这样的圆形动画?
- c++ - 如何在 C++ 中将 cin 输入更改为命令行参数输入
- r - R:带有滑块的函数的交互式图形
- c++ - 关于编译器输出的 xor'ing 浮点值和一般转换问题