Using wiremock, can I return a body that is dependent on the post request

后端 未结 6 859
盖世英雄少女心
盖世英雄少女心 2021-02-12 20:10

I am trying to test an openid provider class. The openid consumer class is making an http request. I am mocking the response to this request using wiremock. I am trying to mock

6条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-12 20:51

    Yes it is possible to create a stub with the request matching in wiremock. Following attributes are supported by for Request matching request.

    • URL
    • HTTP Method
    • Query parameters
    • Headers
    • Basic authentication (a special case of header matching)
    • Cookies
    • Request body
    • Multipart/form-data

    In your scenario if you want to apply matching on the values in the request body you can use the below approach for generating stub for it.

    {
      "request": {
        ...
        "bodyPatterns" : [ {
          "equalToJson" : "{ \"total_results\": 4 }"
        } ]
        ...
      },
      ...
    }
    

    Follow the link for more details: http://wiremock.org/docs/request-matching/

提交回复
热议问题