【发布时间】:2019-07-10 08:38:03
【问题描述】:
我已经使用示例 REST/HTTP 请求模拟实现了一个基本的 WireMock。服务器代码实现如下。
使用此代码,当我从 Postman 发出 GET 请求(即 GET http://127.0.0.1:8089/some/thing)时,我收到以下错误。
无法提供响应,因为此 WireMock 实例中没有存根映射。
我的设置/代码中缺少什么?
import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
public class MockApp {
private WireMockServer wireMockServer;
public MockApp(String testSpec) {
wireMockServer = new WireMockServer(WireMockConfiguration.options().
port(8089).
usingFilesUnderDirectory(testSpec).
disableRequestJournal());
}
public void start() {
wireMockServer.start();
}
public void stop() {
wireMockServer.stop();
}
}
主要功能是:
public class MockMain {
public static void main(String[] args) {
String baseDir = System.getProperty("user.dir");
String testResource = baseDir + "/resources/testconfig/";
MockAMS mockAMS = new MockAMS(testResource);
mockAMS.start();
}
}
在“resources/testconfig”下,有一个名为 mapping.json 的文件,其中包含:
{
"request": {
"method": "GET",
"url": "/some/thing"
},
"response": {
"status": 200,
"body": "Hello world!",
"headers": {
"Content-Type": "text/plain"
}
}
}
【问题讨论】: