mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
Changes because HttpMethod changed to class
This commit contains changes made because HttpMethod changed from enum to class. See gh-27697
This commit is contained in:
+1
@@ -78,6 +78,7 @@ public class MockClientHttpRequest extends MockHttpOutputMessage implements Clie
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public String getMethodValue() {
|
||||
return this.httpMethod.name();
|
||||
}
|
||||
|
||||
+14
-15
@@ -55,10 +55,7 @@ import org.springframework.web.util.UriComponentsBuilder;
|
||||
*/
|
||||
public final class MockServerHttpRequest extends AbstractServerHttpRequest {
|
||||
|
||||
/**
|
||||
* String representation of one of {@link HttpMethod} or not empty custom method (e.g. <i>CONNECT</i>).
|
||||
*/
|
||||
private final String httpMethod;
|
||||
private final HttpMethod httpMethod;
|
||||
|
||||
private final MultiValueMap<String, HttpCookie> cookies;
|
||||
|
||||
@@ -73,13 +70,12 @@ public final class MockServerHttpRequest extends AbstractServerHttpRequest {
|
||||
|
||||
private final Flux<DataBuffer> body;
|
||||
|
||||
private MockServerHttpRequest(String httpMethod,
|
||||
private MockServerHttpRequest(HttpMethod httpMethod,
|
||||
URI uri, @Nullable String contextPath, HttpHeaders headers, MultiValueMap<String, HttpCookie> cookies,
|
||||
@Nullable InetSocketAddress localAddress, @Nullable InetSocketAddress remoteAddress,
|
||||
@Nullable SslInfo sslInfo, Publisher<? extends DataBuffer> body) {
|
||||
|
||||
super(uri, contextPath, headers);
|
||||
Assert.isTrue(StringUtils.hasText(httpMethod), "HTTP method is required.");
|
||||
this.httpMethod = httpMethod;
|
||||
this.cookies = cookies;
|
||||
this.localAddress = localAddress;
|
||||
@@ -90,14 +86,14 @@ public final class MockServerHttpRequest extends AbstractServerHttpRequest {
|
||||
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public HttpMethod getMethod() {
|
||||
return HttpMethod.resolve(this.httpMethod);
|
||||
return this.httpMethod;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public String getMethodValue() {
|
||||
return this.httpMethod;
|
||||
return this.httpMethod.name();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -218,7 +214,7 @@ public final class MockServerHttpRequest extends AbstractServerHttpRequest {
|
||||
public static BodyBuilder method(HttpMethod method, URI url) {
|
||||
Assert.notNull(method, "HTTP method is required. " +
|
||||
"For a custom HTTP method, please provide a String HTTP method value.");
|
||||
return new DefaultBodyBuilder(method.name(), url);
|
||||
return new DefaultBodyBuilder(method, url);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -242,9 +238,12 @@ public final class MockServerHttpRequest extends AbstractServerHttpRequest {
|
||||
* @param vars variables to expand into the template
|
||||
* @return the created builder
|
||||
* @since 5.2.7
|
||||
* @deprecated in favor of {@link #method(HttpMethod, String, Object...)}
|
||||
*/
|
||||
@Deprecated
|
||||
public static BodyBuilder method(String httpMethod, String uri, Object... vars) {
|
||||
return new DefaultBodyBuilder(httpMethod, toUri(uri, vars));
|
||||
Assert.isTrue(StringUtils.hasText(httpMethod), "HTTP method is required.");
|
||||
return new DefaultBodyBuilder(HttpMethod.valueOf(httpMethod), toUri(uri, vars));
|
||||
}
|
||||
|
||||
private static URI toUri(String uri, Object[] vars) {
|
||||
@@ -427,7 +426,7 @@ public final class MockServerHttpRequest extends AbstractServerHttpRequest {
|
||||
|
||||
private static class DefaultBodyBuilder implements BodyBuilder {
|
||||
|
||||
private final String methodValue;
|
||||
private final HttpMethod method;
|
||||
|
||||
private final URI url;
|
||||
|
||||
@@ -449,8 +448,8 @@ public final class MockServerHttpRequest extends AbstractServerHttpRequest {
|
||||
@Nullable
|
||||
private SslInfo sslInfo;
|
||||
|
||||
DefaultBodyBuilder(String method, URI url) {
|
||||
this.methodValue = method;
|
||||
DefaultBodyBuilder(HttpMethod method, URI url) {
|
||||
this.method = method;
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
@@ -589,7 +588,7 @@ public final class MockServerHttpRequest extends AbstractServerHttpRequest {
|
||||
@Override
|
||||
public MockServerHttpRequest body(Publisher<? extends DataBuffer> body) {
|
||||
applyCookiesIfNecessary();
|
||||
return new MockServerHttpRequest(this.methodValue, getUrlToUse(), this.contextPath,
|
||||
return new MockServerHttpRequest(this.method, getUrlToUse(), this.contextPath,
|
||||
this.headers, this.cookies, this.localAddress, this.remoteAddress, this.sslInfo, body);
|
||||
}
|
||||
|
||||
|
||||
+5
-7
@@ -23,6 +23,7 @@ import java.util.Enumeration;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import jakarta.servlet.ServletContext;
|
||||
import jakarta.servlet.ServletException;
|
||||
@@ -102,12 +103,7 @@ public class MockMultipartHttpServletRequest extends MockHttpServletRequest impl
|
||||
@Override
|
||||
public List<MultipartFile> getFiles(String name) {
|
||||
List<MultipartFile> multipartFiles = this.multipartFiles.get(name);
|
||||
if (multipartFiles != null) {
|
||||
return multipartFiles;
|
||||
}
|
||||
else {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return Objects.requireNonNullElse(multipartFiles, Collections.emptyList());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -141,7 +137,9 @@ public class MockMultipartHttpServletRequest extends MockHttpServletRequest impl
|
||||
|
||||
@Override
|
||||
public HttpMethod getRequestMethod() {
|
||||
return HttpMethod.resolve(getMethod());
|
||||
String method = getMethod();
|
||||
Assert.state(method != null, "Method must not be null");
|
||||
return HttpMethod.valueOf(method);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
@@ -132,6 +132,7 @@ public final class MockServerRequest implements ServerRequest {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public String methodName() {
|
||||
return this.method.name();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user