From 28602ad0121f71591272b678ba8110aa76339a4d Mon Sep 17 00:00:00 2001 From: Johnny Lim Date: Wed, 15 Jun 2022 23:08:52 +0900 Subject: [PATCH] Add MockMvc.multipart() Kotlin extensions with HttpMethod See gh-28545 See gh-28631 Closes gh-28634 --- .../test/web/servlet/MockMvcExtensions.kt | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/spring-test/src/main/kotlin/org/springframework/test/web/servlet/MockMvcExtensions.kt b/spring-test/src/main/kotlin/org/springframework/test/web/servlet/MockMvcExtensions.kt index 83894e34092d..222c9e1f3725 100644 --- a/spring-test/src/main/kotlin/org/springframework/test/web/servlet/MockMvcExtensions.kt +++ b/spring-test/src/main/kotlin/org/springframework/test/web/servlet/MockMvcExtensions.kt @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -224,6 +224,18 @@ fun MockMvc.multipart(urlTemplate: String, vararg vars: Any?, dsl: MockMultipart return MockMultipartHttpServletRequestDsl(requestBuilder).apply(dsl).perform(this) } +/** + * [MockMvc] extension providing access to [MockMultipartHttpServletRequestDsl] Kotlin DSL. + * + * @see MockMvcRequestBuilders.multipart + * @author Sebastien Deleuze + * @since 5.3.26 + */ +fun MockMvc.multipart(httpMethod: HttpMethod, urlTemplate: String, vararg vars: Any?, dsl: MockMultipartHttpServletRequestDsl.() -> Unit = {}): ResultActionsDsl { + val requestBuilder = MockMvcRequestBuilders.multipart(httpMethod, urlTemplate, *vars) + return MockMultipartHttpServletRequestDsl(requestBuilder).apply(dsl).perform(this) +} + /** * [MockMvc] extension providing access to [MockMultipartHttpServletRequestDsl] Kotlin DSL. * @@ -235,3 +247,15 @@ fun MockMvc.multipart(uri: URI, dsl: MockMultipartHttpServletRequestDsl.() -> Un val requestBuilder = MockMvcRequestBuilders.multipart(uri) return MockMultipartHttpServletRequestDsl(requestBuilder).apply(dsl).perform(this) } + +/** + * [MockMvc] extension providing access to [MockMultipartHttpServletRequestDsl] Kotlin DSL. + * + * @see MockMvcRequestBuilders.multipart + * @author Sebastien Deleuze + * @since 5.3.26 + */ +fun MockMvc.multipart(httpMethod: HttpMethod, uri: URI, dsl: MockMultipartHttpServletRequestDsl.() -> Unit = {}): ResultActionsDsl { + val requestBuilder = MockMvcRequestBuilders.multipart(httpMethod, uri) + return MockMultipartHttpServletRequestDsl(requestBuilder).apply(dsl).perform(this) +}