Merge branch '2.0.x'
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2021 the original author or authors.
|
||||
* Copyright 2014-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.
|
||||
@@ -21,7 +21,7 @@ import org.springframework.mock.web.MockMultipartFile;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
|
||||
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.fileUpload;
|
||||
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.multipart;
|
||||
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
|
||||
import static org.springframework.restdocs.payload.PayloadDocumentation.requestPartBody;
|
||||
import static org.springframework.restdocs.payload.PayloadDocumentation.requestPartFields;
|
||||
@@ -37,7 +37,7 @@ public class RequestPartPayload {
|
||||
MockMultipartFile metadata = new MockMultipartFile("metadata", "", "application/json",
|
||||
"{ \"version\": \"1.0\"}".getBytes());
|
||||
|
||||
this.mockMvc.perform(fileUpload("/images").file(image).file(metadata).accept(MediaType.APPLICATION_JSON))
|
||||
this.mockMvc.perform(multipart("/images").file(image).file(metadata).accept(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk()).andDo(document("image-upload", requestPartFields("metadata", // <1>
|
||||
fieldWithPath("version").description("The version of the image")))); // <2>
|
||||
// end::fields[]
|
||||
@@ -49,7 +49,7 @@ public class RequestPartPayload {
|
||||
MockMultipartFile metadata = new MockMultipartFile("metadata", "", "application/json",
|
||||
"{ \"version\": \"1.0\"}".getBytes());
|
||||
|
||||
this.mockMvc.perform(fileUpload("/images").file(image).file(metadata).accept(MediaType.APPLICATION_JSON))
|
||||
this.mockMvc.perform(multipart("/images").file(image).file(metadata).accept(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk()).andDo(document("image-upload", requestPartBody("metadata"))); // <1>
|
||||
// end::body[]
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-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.
|
||||
@@ -216,23 +216,49 @@ public abstract class RestDocumentationRequestBuilders {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a {@link MockHttpServletRequestBuilder} for a multipart request. The url
|
||||
* template will be captured and made available for documentation.
|
||||
* Create a {@link MockMultipartHttpServletRequestBuilder} for a multipart request.
|
||||
* The url template will be captured and made available for documentation.
|
||||
* @param urlTemplate a URL template; the resulting URL will be encoded
|
||||
* @param urlVariables zero or more URL variables
|
||||
* @return the builder for the file upload request
|
||||
* @deprecated since 2.0.6 in favor of {@link #multipart(String, Object...)}
|
||||
*/
|
||||
@Deprecated
|
||||
public static MockMultipartHttpServletRequestBuilder fileUpload(String urlTemplate, Object... urlVariables) {
|
||||
return multipart(urlTemplate, urlVariables);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a {@link MockMultipartHttpServletRequestBuilder} for a multipart request.
|
||||
* @param uri the URL
|
||||
* @return the builder for the file upload request
|
||||
* @deprecated since 2.0.6 in favor of {@link #multipart(URI)}
|
||||
*/
|
||||
@Deprecated
|
||||
public static MockMultipartHttpServletRequestBuilder fileUpload(URI uri) {
|
||||
return multipart(uri);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a {@link MockMultipartHttpServletRequestBuilder} for a multipart request.
|
||||
* The URL template will be captured and made available for documentation.
|
||||
* @param urlTemplate a URL template; the resulting URL will be encoded
|
||||
* @param urlVariables zero or more URL variables
|
||||
* @return the builder for the multipart request
|
||||
* @since 2.0.6
|
||||
*/
|
||||
public static MockMultipartHttpServletRequestBuilder multipart(String urlTemplate, Object... urlVariables) {
|
||||
return (MockMultipartHttpServletRequestBuilder) MockMvcRequestBuilders.multipart(urlTemplate, urlVariables)
|
||||
.requestAttr(RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE, urlTemplate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a {@link MockHttpServletRequestBuilder} for a multipart request.
|
||||
* Create a {@link MockMultipartHttpServletRequestBuilder} for a multipart request.
|
||||
* @param uri the URL
|
||||
* @return the builder for the file upload request
|
||||
* @since 2.0.6
|
||||
*/
|
||||
public static MockMultipartHttpServletRequestBuilder fileUpload(URI uri) {
|
||||
public static MockMultipartHttpServletRequestBuilder multipart(URI uri) {
|
||||
return MockMvcRequestBuilders.multipart(uri);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user