Wiremock : how to upload file to folder __files with API

限于喜欢 提交于 2019-12-05 10:06:23

Recent Wiremock versions have endpoint to manage stub files (see https://github.com/tomakehurst/wiremock/blob/2.19.0/src/main/java/com/github/tomakehurst/wiremock/admin/AdminRoutes.java#L77)

You can upload a file with a PUT to /__admin/files/{filename}. There are stored under ${pwd}/__files.

A workaround would be to use the "body" parameter, something like this:

{
    {
    "request": {
        "method": "GET",
        "url": "/body-file"
    },
    "response": {
        "status": 200,
        "body": "<example><node Id='1' Action='Insert' /></example>"
    }
}

(Note the single quotes in '1' vs. "1" - you'd need to escape those with \"1\".

See http://wiremock.org/docs/stubbing - Specifying the response body section.

If you need JSON payload, it's even nicer with the "jsonBody" parameter:

{
    {
    "request": {
        "method": "GET",
        "url": "/body-file"
    },
    "response": {
        "status": 200,
        "jsonBody": 
            { 
              "field1": "value1", 
              "field2" : "value2" 
            }
    }
}

Another nice feature is, quoting:

Stub mappings which have been created can be persisted to the mappings directory via a call to WireMock.saveAllMappings in Java or posting a request with an empty body to http://<host>:<port>/__admin/mappings/save.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!