File tree 2 files changed +23
-0
lines changed
main/kotlin/org/springframework/test/web/servlet
test/kotlin/org/springframework/test/web/servlet
2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -129,6 +129,18 @@ open class MockHttpServletRequestDsl(private val builder: AbstractMockHttpServle
129
129
*/
130
130
var queryParams: MultiValueMap <String , String >? = null
131
131
132
+ /* *
133
+ * @see [MockHttpServletRequestBuilder.formField]
134
+ */
135
+ fun formField (name : String , vararg values : String ) {
136
+ builder.formField(name, * values)
137
+ }
138
+
139
+ /* *
140
+ * @see [MockHttpServletRequestBuilder.formFields]
141
+ */
142
+ var formFields: MultiValueMap <String , String >? = null
143
+
132
144
/* *
133
145
* @see [MockHttpServletRequestBuilder.cookie]
134
146
*/
@@ -215,6 +227,7 @@ open class MockHttpServletRequestDsl(private val builder: AbstractMockHttpServle
215
227
contentType?.also { builder.contentType(it) }
216
228
params?.also { builder.params(it) }
217
229
queryParams?.also { builder.queryParams(it) }
230
+ formFields?.also { builder.formFields(it) }
218
231
sessionAttrs?.also { builder.sessionAttrs(it) }
219
232
flashAttrs?.also { builder.flashAttrs(it) }
220
233
session?.also { builder.session(it) }
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ import org.hamcrest.CoreMatchers
23
23
import org.junit.jupiter.api.Test
24
24
import org.springframework.http.HttpMethod
25
25
import org.springframework.http.HttpStatus
26
+ import org.springframework.http.MediaType.APPLICATION_FORM_URLENCODED_VALUE
26
27
import org.springframework.http.MediaType.APPLICATION_ATOM_XML
27
28
import org.springframework.http.MediaType.APPLICATION_JSON
28
29
import org.springframework.http.MediaType.APPLICATION_XML
@@ -230,6 +231,15 @@ class MockMvcExtensionsTests {
230
231
assertThat(result.request.queryString).isEqualTo(" foo=bar&foo=baz" )
231
232
}
232
233
234
+ @Test
235
+ fun formField () {
236
+ val result = mockMvc.post(" /person" ) {
237
+ formField(" name" , " foo" )
238
+ formField(" someDouble" , " 1.23" )
239
+ }.andReturn()
240
+ assertThat(result.request.contentType).startsWith(APPLICATION_FORM_URLENCODED_VALUE )
241
+ assertThat(result.request.contentAsString).isEqualTo(" name=foo&someDouble=1.23" )
242
+ }
233
243
234
244
@RestController
235
245
private class PersonController {
You can’t perform that action at this time.
0 commit comments