Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-16729

WebTestClient does not provide Hamcrest Matcher assertions for JSONPath

    XMLWordPrintable

    Details

    • Last commented by a User:
      true

      Description

      Seems that the reactive WebTestClient is missing some valuable assertions that are available on MockMvc.

      With MockMvc I can do things like

      this.mockMvc.perform(get("/some/url"))
        .andExpect(jsonPath("$.someNestedObject.*", Matchers.hasSize(5)))
        .andExpect(jsonPath("$.someNestedObject.anotherObject").value(Matchers.startsWith("Some String")));
      

      The WebTestClient.jsonPath method doesn't have an overloaded

      jsonPath(String expression, Matcher<T> matcher)
      

      method like its MockMvcResultMatchers counterpart does. Also JsonPathAssertions doesn't have an overloaded

      value(Matcher<T> matcher)
      

      method like its JsonPathResultMatchers counterpart does. Under the covers both JsonPathResultMatchers & JsonPathAssertions utilize the exact same JsonPathExpectationsHelper which exposes the

      public <T> void assertValue(String content, Matcher<T> matcher)
      

      method which is needed.

      Is there a particular reason this is missing or is it an oversight? Also seems that there is 0 support for assertions against XML using WebTestClient. Again, is there a specific reason as to why not?

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              rstoya05-aop Rossen Stoyanchev
              Reporter:
              edeandrea Eric Deandrea
              Last updater:
              Spring Issues Spring Issues
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Days since last comment:
                3 years, 1 week, 4 days ago