|
|
|
|
@@ -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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|