MockMvc allows HttpMethod input for multipart request
Closes gh-28545
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -152,7 +152,7 @@ public class MockMvcHttpConnector implements ClientHttpConnector {
|
||||
}
|
||||
|
||||
// Parse the multipart request in order to adapt to Servlet Part's
|
||||
MockMultipartHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.multipart(uri);
|
||||
MockMultipartHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.multipart(httpMethod, uri);
|
||||
|
||||
Assert.notNull(bytes, "No multipart content");
|
||||
ReactiveHttpInputMessage inputMessage = MockServerHttpRequest.post(uri.toString())
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -69,12 +69,8 @@ public class MockMultipartHttpServletRequestBuilder extends MockHttpServletReque
|
||||
}
|
||||
|
||||
/**
|
||||
* Package-private constructor. Use static factory methods in
|
||||
* {@link MockMvcRequestBuilders}.
|
||||
* <p>For other ways to initialize a {@code MockMultipartHttpServletRequest},
|
||||
* see {@link #with(RequestPostProcessor)} and the
|
||||
* {@link RequestPostProcessor} extension point.
|
||||
* @param uri the URL
|
||||
* Variant of {@link #MockMultipartHttpServletRequestBuilder(String, Object...)}
|
||||
* with a {@link URI}.
|
||||
* @since 4.0.3
|
||||
*/
|
||||
MockMultipartHttpServletRequestBuilder(URI uri) {
|
||||
@@ -82,6 +78,16 @@ public class MockMultipartHttpServletRequestBuilder extends MockHttpServletReque
|
||||
super.contentType(MediaType.MULTIPART_FORM_DATA);
|
||||
}
|
||||
|
||||
/**
|
||||
* Variant of {@link #MockMultipartHttpServletRequestBuilder(String, Object...)}
|
||||
* with a {@link URI} and an {@link HttpMethod}.
|
||||
* @since 5.3.21
|
||||
*/
|
||||
MockMultipartHttpServletRequestBuilder(HttpMethod httpMethod, URI uri) {
|
||||
super(httpMethod, uri);
|
||||
super.contentType(MediaType.MULTIPART_FORM_DATA);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new MockMultipartFile with the given content.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -215,7 +215,7 @@ public abstract class MockMvcRequestBuilders {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a {@link MockMultipartHttpServletRequestBuilder} for a multipart request.
|
||||
* Variant of {@link #multipart(String, Object...)} with a {@link URI}.
|
||||
* @param uri the URL
|
||||
* @since 5.0
|
||||
*/
|
||||
@@ -223,6 +223,17 @@ public abstract class MockMvcRequestBuilders {
|
||||
return new MockMultipartHttpServletRequestBuilder(uri);
|
||||
}
|
||||
|
||||
/**
|
||||
* Variant of {@link #multipart(String, Object...)} with a {@link URI} and
|
||||
* an {@link HttpMethod}.
|
||||
* @param httpMethod the HTTP method to use
|
||||
* @param uri the URL
|
||||
* @since 5.3.21
|
||||
*/
|
||||
public static MockMultipartHttpServletRequestBuilder multipart(HttpMethod httpMethod, URI uri) {
|
||||
return new MockMultipartHttpServletRequestBuilder(httpMethod, uri);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a {@link MockMultipartHttpServletRequestBuilder} for a multipart request.
|
||||
* @param urlTemplate a URL template; the resulting URL will be encoded
|
||||
|
||||
Reference in New Issue
Block a user