title: spring-test MockMvc kotlin DSL lacks async support?
body: <p>spring-test has added support for a MockMvc DSL which can be found documented here: 
  <a href="https://docs.spring.io/spring/docs/5.2.0.M1/spring-framework-reference/languages.html#mockmvc-dsl" rel="nofollow noreferrer">https://docs.spring.io/spring/docs/5.2.0.M1/spring-framework-reference/languages.html#mockmvc-dsl</a></p>
  
  <p>When testing a controller that returns a CompletableFuture (or any other async result type) a test using MockMvc needs to perform an asyncDispatch of the MvcResult before the body can be asserted.
  This can be found on various blogs or stackoverflow questions: </p>
  
  <ul>
  <li><a href="https://sdqali.in/blog/2015/11/24/testing-async-responses-using-mockmvc/" rel="nofollow noreferrer">https://sdqali.in/blog/2015/11/24/testing-async-responses-using-mockmvc/</a></li>
  <li><a href="https://stackoverflow.com/questions/42069226/mockmvc-perform-post-test-to-async-service">MockMVC perform post test to async service</a></li>
  </ul>
  
  <p>The new DSL seems to lack a clean way to do this.</p>
  
  <p>For example the following code is needed to do the asyncDispatch:</p>
  
  <pre><code>@Test
  internal fun call() {
      val mvcResult = mockMvc.get("/execute") {
          accept = APPLICATION_JSON
      }.andExpect {
          request { asyncStarted() }
      }.andReturn()
      mockMvc.perform(asyncDispatch(mvcResult))
          .andExpect(MockMvcResultMatchers.status().isOk)
          .andExpect(MockMvcResultMatchers.jsonPath("$.value", Is.`is`("test")))
  }
  </code></pre>
  
  <p>Am I missing something that would enable this or is this just not nicely supported in the DSL (yet)? </p>
  
  <p><strong>Update:</strong>
  I tried improving this with an extension function on ResultActionsDsl.</p>
  
  <pre><code>fun ResultActionsDsl.asyncDispatch(mockMvc: MockMvc):ResultActionsDsl {
      val mvcResult = andReturn()
      mockMvc.perform(MockMvcRequestBuilders.asyncDispatch(mvcResult))
      return this
  }
  </code></pre>
  
  <p>This makes it possible to write the test as: </p>
  
  <pre><code>@Test
  internal fun call() {
      mockMvc.get("/execute") {
          accept = APPLICATION_JSON
      }.andExpect {
          request {
              asyncStarted()
          }
      }
      .asyncDispatch(mockMvc)
      .andExpect {
          status { isOk }
          jsonPath("$.value") { value("test") }
      }
  }
  </code></pre>
  
  <p>I still feel like this would be supported out of the box by the DSL.</p>