File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed
main/kotlin/org/springframework/test/web/servlet
test/kotlin/org/springframework/test/web/servlet Expand file tree Collapse file tree 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
129129 */
130130 var queryParams: MultiValueMap <String , String >? = null
131131
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+
132144 /* *
133145 * @see [MockHttpServletRequestBuilder.cookie]
134146 */
@@ -215,6 +227,7 @@ open class MockHttpServletRequestDsl(private val builder: AbstractMockHttpServle
215227 contentType?.also { builder.contentType(it) }
216228 params?.also { builder.params(it) }
217229 queryParams?.also { builder.queryParams(it) }
230+ formFields?.also { builder.formFields(it) }
218231 sessionAttrs?.also { builder.sessionAttrs(it) }
219232 flashAttrs?.also { builder.flashAttrs(it) }
220233 session?.also { builder.session(it) }
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ import org.hamcrest.CoreMatchers
2323import org.junit.jupiter.api.Test
2424import org.springframework.http.HttpMethod
2525import org.springframework.http.HttpStatus
26+ import org.springframework.http.MediaType.APPLICATION_FORM_URLENCODED_VALUE
2627import org.springframework.http.MediaType.APPLICATION_ATOM_XML
2728import org.springframework.http.MediaType.APPLICATION_JSON
2829import org.springframework.http.MediaType.APPLICATION_XML
@@ -230,6 +231,15 @@ class MockMvcExtensionsTests {
230231 assertThat(result.request.queryString).isEqualTo(" foo=bar&foo=baz" )
231232 }
232233
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+ }
233243
234244 @RestController
235245 private class PersonController {
You can’t perform that action at this time.
0 commit comments