/
ResultActionsDsl.kt
48 lines (42 loc) · 1.23 KB
/
ResultActionsDsl.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package org.springframework.test.web.servlet
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders
/**
* Provide a [ResultActions] Kotlin DSL in order to be able to write idiomatic Kotlin code.
*
* @author Sebastien Deleuze
* @since 5.2
*/
class ResultActionsDsl(private val actions: ResultActions, private val mockMvc: MockMvc) {
/**
* Provide access to [MockMvcResultMatchersDsl] Kotlin DSL.
* @see MockMvcResultMatchersDsl.match
*/
fun andExpect(dsl: MockMvcResultMatchersDsl.() -> Unit): ResultActionsDsl {
MockMvcResultMatchersDsl(actions).dsl()
return this
}
/**
* Provide access to [MockMvcResultHandlersDsl] Kotlin DSL.
* @see MockMvcResultHandlersDsl.handle
*/
fun andDo(dsl: MockMvcResultHandlersDsl.() -> Unit): ResultActionsDsl {
MockMvcResultHandlersDsl(actions).dsl()
return this
}
/**
* Enable asynchronous dispatching.
* @see MockMvcRequestBuilders.asyncDispatch
* @since 5.2.2
*/
fun asyncDispatch(): ResultActionsDsl {
return andExpect {
request { asyncStarted() }
}.andReturn().let {
ResultActionsDsl(mockMvc.perform(MockMvcRequestBuilders.asyncDispatch(it)), mockMvc)
}
}
/**
* @see ResultActions.andReturn
*/
fun andReturn() = actions.andReturn()
}