Correct package for MockServerWebExchange
Discovered late, but not too late. MockServerWebExchange is now in the proper package matching to the location of ServerWebExchange.
This commit is contained in:
parent
223e27d53d
commit
48c41049b1
|
@ -23,6 +23,7 @@ import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.reactivestreams.Publisher;
|
import org.reactivestreams.Publisher;
|
||||||
|
@ -45,10 +46,7 @@ import org.springframework.web.util.UriComponentsBuilder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mock extension of {@link AbstractServerHttpRequest} for use in tests without
|
* Mock extension of {@link AbstractServerHttpRequest} for use in tests without
|
||||||
* an actual server.
|
* an actual server. Use the static methods to obtain a builder.
|
||||||
*
|
|
||||||
* <p>Use the static builder methods in this class to create an instance possibly
|
|
||||||
* further creating a {@link MockServerWebExchange} via {@link #toExchange()}.
|
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @since 5.0
|
* @since 5.0
|
||||||
|
@ -108,13 +106,6 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
|
||||||
throw new IllegalStateException("This is a mock. No running server, no native request.");
|
throw new IllegalStateException("This is a mock. No running server, no native request.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Shortcut to wrap the request with a {@code MockServerWebExchange}.
|
|
||||||
*/
|
|
||||||
public MockServerWebExchange toExchange() {
|
|
||||||
return new MockServerWebExchange(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Static builder methods
|
// Static builder methods
|
||||||
|
|
||||||
|
@ -266,6 +257,13 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
|
||||||
*/
|
*/
|
||||||
B acceptCharset(Charset... acceptableCharsets);
|
B acceptCharset(Charset... acceptableCharsets);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the list of acceptable {@linkplain Locale locales}, as specified
|
||||||
|
* by the {@code Accept-Languages} header.
|
||||||
|
* @param acceptableLocales the acceptable locales
|
||||||
|
*/
|
||||||
|
B acceptLanguageAsLocales(Locale... acceptableLocales);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the value of the {@code If-Modified-Since} header.
|
* Set the value of the {@code If-Modified-Since} header.
|
||||||
* <p>The date should be specified as the number of milliseconds since
|
* <p>The date should be specified as the number of milliseconds since
|
||||||
|
@ -304,11 +302,6 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
|
||||||
*/
|
*/
|
||||||
MockServerHttpRequest build();
|
MockServerHttpRequest build();
|
||||||
|
|
||||||
/**
|
|
||||||
* Shortcut for:<br>
|
|
||||||
* {@code build().toExchange()}
|
|
||||||
*/
|
|
||||||
MockServerWebExchange toExchange();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -357,6 +350,7 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
|
||||||
|
|
||||||
private static final DataBufferFactory BUFFER_FACTORY = new DefaultDataBufferFactory();
|
private static final DataBufferFactory BUFFER_FACTORY = new DefaultDataBufferFactory();
|
||||||
|
|
||||||
|
|
||||||
private final HttpMethod method;
|
private final HttpMethod method;
|
||||||
|
|
||||||
private final URI url;
|
private final URI url;
|
||||||
|
@ -371,6 +365,7 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
|
||||||
@Nullable
|
@Nullable
|
||||||
private InetSocketAddress remoteAddress;
|
private InetSocketAddress remoteAddress;
|
||||||
|
|
||||||
|
|
||||||
public DefaultBodyBuilder(HttpMethod method, URI url) {
|
public DefaultBodyBuilder(HttpMethod method, URI url) {
|
||||||
this.method = method;
|
this.method = method;
|
||||||
this.url = url;
|
this.url = url;
|
||||||
|
@ -426,6 +421,12 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BodyBuilder acceptLanguageAsLocales(Locale... acceptableLocales) {
|
||||||
|
this.headers.setAcceptLanguageAsLocales(Arrays.asList(acceptableLocales));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BodyBuilder contentLength(long contentLength) {
|
public BodyBuilder contentLength(long contentLength) {
|
||||||
this.headers.setContentLength(contentLength);
|
this.headers.setContentLength(contentLength);
|
||||||
|
@ -467,11 +468,6 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
|
||||||
return body(Flux.empty());
|
return body(Flux.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public MockServerWebExchange toExchange() {
|
|
||||||
return build().toExchange();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MockServerHttpRequest body(String body) {
|
public MockServerHttpRequest body(String body) {
|
||||||
return body(Flux.just(BUFFER_FACTORY.wrap(body.getBytes(getCharset()))));
|
return body(Flux.just(BUFFER_FACTORY.wrap(body.getBytes(getCharset()))));
|
||||||
|
|
|
@ -13,32 +13,30 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.springframework.mock.http.server.reactive;
|
package org.springframework.mock.web.server;
|
||||||
|
|
||||||
import org.springframework.http.codec.ServerCodecConfigurer;
|
import org.springframework.http.codec.ServerCodecConfigurer;
|
||||||
import org.springframework.web.server.ServerWebExchangeDecorator;
|
import org.springframework.mock.http.server.reactive.MockServerHttpRequest;
|
||||||
|
import org.springframework.mock.http.server.reactive.MockServerHttpResponse;
|
||||||
import org.springframework.web.server.adapter.DefaultServerWebExchange;
|
import org.springframework.web.server.adapter.DefaultServerWebExchange;
|
||||||
import org.springframework.web.server.i18n.AcceptHeaderLocaleContextResolver;
|
import org.springframework.web.server.i18n.AcceptHeaderLocaleContextResolver;
|
||||||
import org.springframework.web.server.session.DefaultWebSessionManager;
|
import org.springframework.web.server.session.DefaultWebSessionManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@code ServerWebExchange} for use in tests.
|
* Variant of {@link DefaultServerWebExchange} for use in tests with
|
||||||
|
* {@link MockServerHttpRequest} and {@link MockServerHttpResponse}.
|
||||||
*
|
*
|
||||||
* <p>Effectively a wrapper around {@link DefaultServerWebExchange} plugged in
|
* <p>See static factory methods to create an instance.
|
||||||
* with {@link MockServerHttpRequest} and {@link MockServerHttpResponse}.
|
|
||||||
*
|
|
||||||
* <p>Typically used via {@link MockServerHttpRequest#toExchange()}.
|
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @since 5.0
|
* @since 5.0
|
||||||
*/
|
*/
|
||||||
public class MockServerWebExchange extends ServerWebExchangeDecorator {
|
public final class MockServerWebExchange extends DefaultServerWebExchange {
|
||||||
|
|
||||||
|
|
||||||
public MockServerWebExchange(MockServerHttpRequest request) {
|
private MockServerWebExchange(MockServerHttpRequest request) {
|
||||||
super(new DefaultServerWebExchange(
|
super(request, new MockServerHttpResponse(), new DefaultWebSessionManager(),
|
||||||
request, new MockServerHttpResponse(), new DefaultWebSessionManager(),
|
ServerCodecConfigurer.create(), new AcceptHeaderLocaleContextResolver());
|
||||||
ServerCodecConfigurer.create(), new AcceptHeaderLocaleContextResolver()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -47,4 +45,14 @@ public class MockServerWebExchange extends ServerWebExchangeDecorator {
|
||||||
return (MockServerHttpResponse) super.getResponse();
|
return (MockServerHttpResponse) super.getResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a {@link MockServerWebExchange} from the given request.
|
||||||
|
* @param request the request to use.
|
||||||
|
* @return the exchange
|
||||||
|
*/
|
||||||
|
public static MockServerWebExchange from(MockServerHttpRequest request) {
|
||||||
|
return new MockServerWebExchange(request);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
/**
|
||||||
|
* Mock implementations of Spring's reactive server web API abtsractions.
|
||||||
|
*/
|
||||||
|
@NonNullApi
|
||||||
|
@NonNullFields
|
||||||
|
package org.springframework.mock.web.server;
|
||||||
|
|
||||||
|
import org.springframework.lang.NonNullApi;
|
||||||
|
import org.springframework.lang.NonNullFields;
|
|
@ -96,7 +96,8 @@ public class DefaultServerWebExchange implements ServerWebExchange {
|
||||||
|
|
||||||
|
|
||||||
public DefaultServerWebExchange(ServerHttpRequest request, ServerHttpResponse response,
|
public DefaultServerWebExchange(ServerHttpRequest request, ServerHttpResponse response,
|
||||||
WebSessionManager sessionManager, ServerCodecConfigurer codecConfigurer, LocaleContextResolver localeContextResolver) {
|
WebSessionManager sessionManager, ServerCodecConfigurer codecConfigurer,
|
||||||
|
LocaleContextResolver localeContextResolver) {
|
||||||
|
|
||||||
Assert.notNull(request, "'request' is required");
|
Assert.notNull(request, "'request' is required");
|
||||||
Assert.notNull(response, "'response' is required");
|
Assert.notNull(response, "'response' is required");
|
||||||
|
|
|
@ -38,6 +38,7 @@ import org.springframework.http.HttpMethod;
|
||||||
import org.springframework.http.HttpRange;
|
import org.springframework.http.HttpRange;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.http.server.reactive.AbstractServerHttpRequest;
|
import org.springframework.http.server.reactive.AbstractServerHttpRequest;
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.LinkedMultiValueMap;
|
import org.springframework.util.LinkedMultiValueMap;
|
||||||
import org.springframework.util.MimeType;
|
import org.springframework.util.MimeType;
|
||||||
import org.springframework.util.MultiValueMap;
|
import org.springframework.util.MultiValueMap;
|
||||||
|
@ -45,10 +46,7 @@ import org.springframework.web.util.UriComponentsBuilder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mock extension of {@link AbstractServerHttpRequest} for use in tests without
|
* Mock extension of {@link AbstractServerHttpRequest} for use in tests without
|
||||||
* an actual server.
|
* an actual server. Use the static methods to obtain a builder.
|
||||||
*
|
|
||||||
* <p>Use the static builder methods in this class to create an instance possibly
|
|
||||||
* further creating a {@link MockServerWebExchange} via {@link #toExchange()}.
|
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @since 5.0
|
* @since 5.0
|
||||||
|
@ -59,15 +57,15 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
|
||||||
|
|
||||||
private final MultiValueMap<String, HttpCookie> cookies;
|
private final MultiValueMap<String, HttpCookie> cookies;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private final InetSocketAddress remoteAddress;
|
private final InetSocketAddress remoteAddress;
|
||||||
|
|
||||||
private final Flux<DataBuffer> body;
|
private final Flux<DataBuffer> body;
|
||||||
|
|
||||||
|
|
||||||
private MockServerHttpRequest(HttpMethod httpMethod, URI uri, String contextPath,
|
private MockServerHttpRequest(HttpMethod httpMethod, URI uri, @Nullable String contextPath,
|
||||||
HttpHeaders headers, MultiValueMap<String, HttpCookie> cookies,
|
HttpHeaders headers, MultiValueMap<String, HttpCookie> cookies,
|
||||||
InetSocketAddress remoteAddress,
|
@Nullable InetSocketAddress remoteAddress, Publisher<? extends DataBuffer> body) {
|
||||||
Publisher<? extends DataBuffer> body) {
|
|
||||||
|
|
||||||
super(uri, contextPath, headers);
|
super(uri, contextPath, headers);
|
||||||
this.httpMethod = httpMethod;
|
this.httpMethod = httpMethod;
|
||||||
|
@ -88,6 +86,7 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
public InetSocketAddress getRemoteAddress() {
|
public InetSocketAddress getRemoteAddress() {
|
||||||
return this.remoteAddress;
|
return this.remoteAddress;
|
||||||
}
|
}
|
||||||
|
@ -108,14 +107,6 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Shortcut to wrap the request with a {@code MockServerWebExchange}.
|
|
||||||
*/
|
|
||||||
public MockServerWebExchange toExchange() {
|
|
||||||
return new MockServerWebExchange(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Static builder methods
|
// Static builder methods
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -311,11 +302,6 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
|
||||||
*/
|
*/
|
||||||
MockServerHttpRequest build();
|
MockServerHttpRequest build();
|
||||||
|
|
||||||
/**
|
|
||||||
* Shortcut for:<br>
|
|
||||||
* {@code build().toExchange()}
|
|
||||||
*/
|
|
||||||
MockServerWebExchange toExchange();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -369,12 +355,14 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
|
||||||
|
|
||||||
private final URI url;
|
private final URI url;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private String contextPath;
|
private String contextPath;
|
||||||
|
|
||||||
private final HttpHeaders headers = new HttpHeaders();
|
private final HttpHeaders headers = new HttpHeaders();
|
||||||
|
|
||||||
private final MultiValueMap<String, HttpCookie> cookies = new LinkedMultiValueMap<>();
|
private final MultiValueMap<String, HttpCookie> cookies = new LinkedMultiValueMap<>();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private InetSocketAddress remoteAddress;
|
private InetSocketAddress remoteAddress;
|
||||||
|
|
||||||
|
|
||||||
|
@ -480,11 +468,6 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
|
||||||
return body(Flux.empty());
|
return body(Flux.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public MockServerWebExchange toExchange() {
|
|
||||||
return build().toExchange();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MockServerHttpRequest body(String body) {
|
public MockServerHttpRequest body(String body) {
|
||||||
return body(Flux.just(BUFFER_FACTORY.wrap(body.getBytes(getCharset()))));
|
return body(Flux.just(BUFFER_FACTORY.wrap(body.getBytes(getCharset()))));
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
|
||||||
|
// For @NonNull annotations on implementation classes
|
||||||
|
|
||||||
|
@NonNullApi
|
||||||
|
@NonNullFields
|
||||||
|
package org.springframework.mock.http.server.reactive.test;
|
||||||
|
|
||||||
|
import org.springframework.lang.NonNullApi;
|
||||||
|
import org.springframework.lang.NonNullFields;
|
|
@ -13,32 +13,30 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.springframework.mock.http.server.reactive.test;
|
package org.springframework.mock.web.test.server;
|
||||||
|
|
||||||
import org.springframework.http.codec.ServerCodecConfigurer;
|
import org.springframework.http.codec.ServerCodecConfigurer;
|
||||||
import org.springframework.web.server.ServerWebExchangeDecorator;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse;
|
||||||
import org.springframework.web.server.adapter.DefaultServerWebExchange;
|
import org.springframework.web.server.adapter.DefaultServerWebExchange;
|
||||||
import org.springframework.web.server.i18n.AcceptHeaderLocaleContextResolver;
|
import org.springframework.web.server.i18n.AcceptHeaderLocaleContextResolver;
|
||||||
import org.springframework.web.server.session.DefaultWebSessionManager;
|
import org.springframework.web.server.session.DefaultWebSessionManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@code ServerWebExchange} for use in tests.
|
* Variant of {@link DefaultServerWebExchange} for use in tests with
|
||||||
|
* {@link MockServerHttpRequest} and {@link MockServerHttpResponse}.
|
||||||
*
|
*
|
||||||
* <p>Effectively a wrapper around {@link DefaultServerWebExchange} plugged in
|
* <p>See static factory methods to create an instance.
|
||||||
* with {@link MockServerHttpRequest} and {@link MockServerHttpResponse}.
|
|
||||||
*
|
|
||||||
* <p>Typically used via {@link MockServerHttpRequest#toExchange()}.
|
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @since 5.0
|
* @since 5.0
|
||||||
*/
|
*/
|
||||||
public class MockServerWebExchange extends ServerWebExchangeDecorator {
|
public final class MockServerWebExchange extends DefaultServerWebExchange {
|
||||||
|
|
||||||
|
|
||||||
public MockServerWebExchange(MockServerHttpRequest request) {
|
private MockServerWebExchange(MockServerHttpRequest request) {
|
||||||
super(new DefaultServerWebExchange(
|
super(request, new MockServerHttpResponse(), new DefaultWebSessionManager(),
|
||||||
request, new MockServerHttpResponse(), new DefaultWebSessionManager(),
|
ServerCodecConfigurer.create(), new AcceptHeaderLocaleContextResolver());
|
||||||
ServerCodecConfigurer.create(), new AcceptHeaderLocaleContextResolver()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -47,4 +45,14 @@ public class MockServerWebExchange extends ServerWebExchangeDecorator {
|
||||||
return (MockServerHttpResponse) super.getResponse();
|
return (MockServerHttpResponse) super.getResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a {@link MockServerWebExchange} from the given request.
|
||||||
|
* @param request the request to use.
|
||||||
|
* @return the exchange
|
||||||
|
*/
|
||||||
|
public static MockServerWebExchange from(MockServerHttpRequest request) {
|
||||||
|
return new MockServerWebExchange(request);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
|
||||||
|
// For @NonNull annotations on implementation classes
|
||||||
|
|
||||||
|
@NonNullApi
|
||||||
|
@NonNullFields
|
||||||
|
package org.springframework.mock.web.test.server;
|
||||||
|
|
||||||
|
import org.springframework.lang.NonNullApi;
|
||||||
|
import org.springframework.lang.NonNullFields;
|
|
@ -34,6 +34,7 @@ import org.springframework.http.codec.multipart.FilePart;
|
||||||
import org.springframework.http.codec.multipart.MultipartHttpMessageWriter;
|
import org.springframework.http.codec.multipart.MultipartHttpMessageWriter;
|
||||||
import org.springframework.mock.http.client.reactive.test.MockClientHttpRequest;
|
import org.springframework.mock.http.client.reactive.test.MockClientHttpRequest;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.tests.sample.beans.ITestBean;
|
import org.springframework.tests.sample.beans.ITestBean;
|
||||||
import org.springframework.tests.sample.beans.TestBean;
|
import org.springframework.tests.sample.beans.TestBean;
|
||||||
import org.springframework.util.LinkedMultiValueMap;
|
import org.springframework.util.LinkedMultiValueMap;
|
||||||
|
@ -181,7 +182,7 @@ public class WebExchangeDataBinderTests {
|
||||||
public void testBindingWithQueryParams() throws Exception {
|
public void testBindingWithQueryParams() throws Exception {
|
||||||
String url = "/path?spouse=someValue&spouse.name=test";
|
String url = "/path?spouse=someValue&spouse.name=test";
|
||||||
MockServerHttpRequest request = MockServerHttpRequest.post(url).build();
|
MockServerHttpRequest request = MockServerHttpRequest.post(url).build();
|
||||||
this.binder.bind(request.toExchange()).block(Duration.ofSeconds(5));
|
this.binder.bind(MockServerWebExchange.from(request)).block(Duration.ofSeconds(5));
|
||||||
|
|
||||||
assertNotNull(this.testBean.getSpouse());
|
assertNotNull(this.testBean.getSpouse());
|
||||||
assertEquals("test", this.testBean.getSpouse().getName());
|
assertEquals("test", this.testBean.getSpouse().getName());
|
||||||
|
@ -223,11 +224,11 @@ public class WebExchangeDataBinderTests {
|
||||||
forClassWithGenerics(MultiValueMap.class, String.class, String.class),
|
forClassWithGenerics(MultiValueMap.class, String.class, String.class),
|
||||||
MediaType.APPLICATION_FORM_URLENCODED, request, Collections.emptyMap()).block();
|
MediaType.APPLICATION_FORM_URLENCODED, request, Collections.emptyMap()).block();
|
||||||
|
|
||||||
return MockServerHttpRequest
|
return MockServerWebExchange.from(
|
||||||
|
MockServerHttpRequest
|
||||||
.post("/")
|
.post("/")
|
||||||
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
|
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
|
||||||
.body(request.getBody())
|
.body(request.getBody()));
|
||||||
.toExchange();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ServerWebExchange exchangeMultipart(MultiValueMap<String, ?> multipartData) {
|
private ServerWebExchange exchangeMultipart(MultiValueMap<String, ?> multipartData) {
|
||||||
|
@ -237,11 +238,10 @@ public class WebExchangeDataBinderTests {
|
||||||
new MultipartHttpMessageWriter().write(Mono.just(multipartData), forClass(MultiValueMap.class),
|
new MultipartHttpMessageWriter().write(Mono.just(multipartData), forClass(MultiValueMap.class),
|
||||||
MediaType.MULTIPART_FORM_DATA, request, Collections.emptyMap()).block();
|
MediaType.MULTIPART_FORM_DATA, request, Collections.emptyMap()).block();
|
||||||
|
|
||||||
return MockServerHttpRequest
|
return MockServerWebExchange.from(MockServerHttpRequest
|
||||||
.post("/")
|
.post("/")
|
||||||
.contentType(request.getHeaders().getContentType())
|
.contentType(request.getHeaders().getContentType())
|
||||||
.body(request.getBody())
|
.body(request.getBody()));
|
||||||
.toExchange();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,24 +1,46 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2002-2017 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.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
package org.springframework.web.cors.reactive;
|
package org.springframework.web.cors.reactive;
|
||||||
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.HttpMethod;
|
import org.springframework.http.HttpMethod;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerWebExchange;
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.web.cors.CorsConfiguration;
|
import org.springframework.web.cors.CorsConfiguration;
|
||||||
import org.springframework.web.server.WebFilterChain;
|
import org.springframework.web.server.WebFilterChain;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.springframework.http.HttpHeaders.*;
|
import static org.springframework.http.HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS;
|
||||||
|
import static org.springframework.http.HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN;
|
||||||
|
import static org.springframework.http.HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS;
|
||||||
|
import static org.springframework.http.HttpHeaders.ACCESS_CONTROL_MAX_AGE;
|
||||||
|
import static org.springframework.http.HttpHeaders.ACCESS_CONTROL_REQUEST_HEADERS;
|
||||||
|
import static org.springframework.http.HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD;
|
||||||
|
import static org.springframework.http.HttpHeaders.HOST;
|
||||||
|
import static org.springframework.http.HttpHeaders.ORIGIN;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for {@link CorsWebFilter}.
|
* Unit tests for {@link CorsWebFilter}.
|
||||||
|
@ -50,19 +72,19 @@ public class CorsWebFilterTests {
|
||||||
.header(ORIGIN, "http://domain2.com")
|
.header(ORIGIN, "http://domain2.com")
|
||||||
.header("header2", "foo")
|
.header("header2", "foo")
|
||||||
.build();
|
.build();
|
||||||
MockServerWebExchange exchange = new MockServerWebExchange(request);
|
|
||||||
|
|
||||||
WebFilterChain filterChain = (filterExchange) -> {
|
WebFilterChain filterChain = (filterExchange) -> {
|
||||||
try {
|
try {
|
||||||
assertEquals("http://domain2.com", filterExchange.getResponse().getHeaders().getFirst(ACCESS_CONTROL_ALLOW_ORIGIN));
|
HttpHeaders headers = filterExchange.getResponse().getHeaders();
|
||||||
assertEquals("header3, header4", filterExchange.getResponse().getHeaders().getFirst(ACCESS_CONTROL_EXPOSE_HEADERS));
|
assertEquals("http://domain2.com", headers.getFirst(ACCESS_CONTROL_ALLOW_ORIGIN));
|
||||||
|
assertEquals("header3, header4", headers.getFirst(ACCESS_CONTROL_EXPOSE_HEADERS));
|
||||||
} catch (AssertionError ex) {
|
} catch (AssertionError ex) {
|
||||||
return Mono.error(ex);
|
return Mono.error(ex);
|
||||||
}
|
}
|
||||||
return Mono.empty();
|
return Mono.empty();
|
||||||
|
|
||||||
};
|
};
|
||||||
filter.filter(exchange, filterChain);
|
filter.filter(MockServerWebExchange.from(request), filterChain);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -74,9 +96,10 @@ public class CorsWebFilterTests {
|
||||||
.header(ORIGIN, "http://domain2.com")
|
.header(ORIGIN, "http://domain2.com")
|
||||||
.header("header2", "foo")
|
.header("header2", "foo")
|
||||||
.build();
|
.build();
|
||||||
MockServerWebExchange exchange = new MockServerWebExchange(request);
|
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
|
|
||||||
WebFilterChain filterChain = (filterExchange) -> Mono.error(new AssertionError("Invalid requests must not be forwarded to the filter chain"));
|
WebFilterChain filterChain = (filterExchange) -> Mono.error(
|
||||||
|
new AssertionError("Invalid requests must not be forwarded to the filter chain"));
|
||||||
filter.filter(exchange, filterChain);
|
filter.filter(exchange, filterChain);
|
||||||
|
|
||||||
assertNull(exchange.getResponse().getHeaders().getFirst(ACCESS_CONTROL_ALLOW_ORIGIN));
|
assertNull(exchange.getResponse().getHeaders().getFirst(ACCESS_CONTROL_ALLOW_ORIGIN));
|
||||||
|
@ -92,15 +115,17 @@ public class CorsWebFilterTests {
|
||||||
.header(ACCESS_CONTROL_REQUEST_METHOD, HttpMethod.GET.name())
|
.header(ACCESS_CONTROL_REQUEST_METHOD, HttpMethod.GET.name())
|
||||||
.header(ACCESS_CONTROL_REQUEST_HEADERS, "header1, header2")
|
.header(ACCESS_CONTROL_REQUEST_HEADERS, "header1, header2")
|
||||||
.build();
|
.build();
|
||||||
MockServerWebExchange exchange = new MockServerWebExchange(request);
|
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
|
|
||||||
WebFilterChain filterChain = (filterExchange) -> Mono.error(new AssertionError("Preflight requests must not be forwarded to the filter chain"));
|
WebFilterChain filterChain = (filterExchange) -> Mono.error(
|
||||||
|
new AssertionError("Preflight requests must not be forwarded to the filter chain"));
|
||||||
filter.filter(exchange, filterChain);
|
filter.filter(exchange, filterChain);
|
||||||
|
|
||||||
assertEquals("http://domain2.com", exchange.getResponse().getHeaders().getFirst(ACCESS_CONTROL_ALLOW_ORIGIN));
|
HttpHeaders headers = exchange.getResponse().getHeaders();
|
||||||
assertEquals("header1, header2", exchange.getResponse().getHeaders().getFirst(ACCESS_CONTROL_ALLOW_HEADERS));
|
assertEquals("http://domain2.com", headers.getFirst(ACCESS_CONTROL_ALLOW_ORIGIN));
|
||||||
assertEquals("header3, header4", exchange.getResponse().getHeaders().getFirst(ACCESS_CONTROL_EXPOSE_HEADERS));
|
assertEquals("header1, header2", headers.getFirst(ACCESS_CONTROL_ALLOW_HEADERS));
|
||||||
assertEquals(123L, Long.parseLong(exchange.getResponse().getHeaders().getFirst(ACCESS_CONTROL_MAX_AGE)));
|
assertEquals("header3, header4", headers.getFirst(ACCESS_CONTROL_EXPOSE_HEADERS));
|
||||||
|
assertEquals(123L, Long.parseLong(headers.getFirst(ACCESS_CONTROL_MAX_AGE)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -113,9 +138,11 @@ public class CorsWebFilterTests {
|
||||||
.header(ACCESS_CONTROL_REQUEST_METHOD, HttpMethod.DELETE.name())
|
.header(ACCESS_CONTROL_REQUEST_METHOD, HttpMethod.DELETE.name())
|
||||||
.header(ACCESS_CONTROL_REQUEST_HEADERS, "header1, header2")
|
.header(ACCESS_CONTROL_REQUEST_HEADERS, "header1, header2")
|
||||||
.build();
|
.build();
|
||||||
MockServerWebExchange exchange = new MockServerWebExchange(request);
|
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
|
|
||||||
|
WebFilterChain filterChain = (filterExchange) -> Mono.error(
|
||||||
|
new AssertionError("Preflight requests must not be forwarded to the filter chain"));
|
||||||
|
|
||||||
WebFilterChain filterChain = (filterExchange) -> Mono.error(new AssertionError("Preflight requests must not be forwarded to the filter chain"));
|
|
||||||
filter.filter(exchange, filterChain);
|
filter.filter(exchange, filterChain);
|
||||||
|
|
||||||
assertNull(exchange.getResponse().getHeaders().getFirst(ACCESS_CONTROL_ALLOW_ORIGIN));
|
assertNull(exchange.getResponse().getHeaders().getFirst(ACCESS_CONTROL_ALLOW_ORIGIN));
|
||||||
|
|
|
@ -24,6 +24,7 @@ import org.springframework.http.HttpMethod;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.server.reactive.ServerHttpResponse;
|
import org.springframework.http.server.reactive.ServerHttpResponse;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.web.cors.CorsConfiguration;
|
import org.springframework.web.cors.CorsConfiguration;
|
||||||
import org.springframework.web.server.ServerWebExchange;
|
import org.springframework.web.server.ServerWebExchange;
|
||||||
|
|
||||||
|
@ -151,7 +152,8 @@ public class DefaultCorsProcessorTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void preflightRequestAllOriginsAllowed() throws Exception {
|
public void preflightRequestAllOriginsAllowed() throws Exception {
|
||||||
ServerWebExchange exchange = preFlightRequest().header(ACCESS_CONTROL_REQUEST_METHOD, "GET").toExchange();
|
MockServerHttpRequest request = preFlightRequest().header(ACCESS_CONTROL_REQUEST_METHOD, "GET").build();
|
||||||
|
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
this.conf.addAllowedOrigin("*");
|
this.conf.addAllowedOrigin("*");
|
||||||
this.processor.process(this.conf, exchange);
|
this.processor.process(this.conf, exchange);
|
||||||
|
|
||||||
|
@ -161,7 +163,8 @@ public class DefaultCorsProcessorTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void preflightRequestWrongAllowedMethod() throws Exception {
|
public void preflightRequestWrongAllowedMethod() throws Exception {
|
||||||
ServerWebExchange exchange = preFlightRequest().header(ACCESS_CONTROL_REQUEST_METHOD, "DELETE").toExchange();
|
MockServerHttpRequest request = preFlightRequest().header(ACCESS_CONTROL_REQUEST_METHOD, "DELETE").build();
|
||||||
|
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
this.conf.addAllowedOrigin("*");
|
this.conf.addAllowedOrigin("*");
|
||||||
this.processor.process(this.conf, exchange);
|
this.processor.process(this.conf, exchange);
|
||||||
|
|
||||||
|
@ -170,7 +173,8 @@ public class DefaultCorsProcessorTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void preflightRequestMatchedAllowedMethod() throws Exception {
|
public void preflightRequestMatchedAllowedMethod() throws Exception {
|
||||||
ServerWebExchange exchange = preFlightRequest().header(ACCESS_CONTROL_REQUEST_METHOD, "GET").toExchange();
|
MockServerHttpRequest request = preFlightRequest().header(ACCESS_CONTROL_REQUEST_METHOD, "GET").build();
|
||||||
|
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
this.conf.addAllowedOrigin("*");
|
this.conf.addAllowedOrigin("*");
|
||||||
this.processor.process(this.conf, exchange);
|
this.processor.process(this.conf, exchange);
|
||||||
|
|
||||||
|
@ -181,7 +185,7 @@ public class DefaultCorsProcessorTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void preflightRequestTestWithOriginButWithoutOtherHeaders() throws Exception {
|
public void preflightRequestTestWithOriginButWithoutOtherHeaders() throws Exception {
|
||||||
ServerWebExchange exchange = preFlightRequest().toExchange();
|
ServerWebExchange exchange = MockServerWebExchange.from(preFlightRequest().build());
|
||||||
this.processor.process(this.conf, exchange);
|
this.processor.process(this.conf, exchange);
|
||||||
|
|
||||||
ServerHttpResponse response = exchange.getResponse();
|
ServerHttpResponse response = exchange.getResponse();
|
||||||
|
@ -191,7 +195,8 @@ public class DefaultCorsProcessorTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void preflightRequestWithoutRequestMethod() throws Exception {
|
public void preflightRequestWithoutRequestMethod() throws Exception {
|
||||||
ServerWebExchange exchange = preFlightRequest().header(ACCESS_CONTROL_REQUEST_HEADERS, "Header1").toExchange();
|
MockServerHttpRequest request = preFlightRequest().header(ACCESS_CONTROL_REQUEST_HEADERS, "Header1").build();
|
||||||
|
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
this.processor.process(this.conf, exchange);
|
this.processor.process(this.conf, exchange);
|
||||||
|
|
||||||
ServerHttpResponse response = exchange.getResponse();
|
ServerHttpResponse response = exchange.getResponse();
|
||||||
|
@ -201,10 +206,10 @@ public class DefaultCorsProcessorTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void preflightRequestWithRequestAndMethodHeaderButNoConfig() throws Exception {
|
public void preflightRequestWithRequestAndMethodHeaderButNoConfig() throws Exception {
|
||||||
ServerWebExchange exchange = preFlightRequest()
|
ServerWebExchange exchange = MockServerWebExchange.from(preFlightRequest()
|
||||||
.header(ACCESS_CONTROL_REQUEST_METHOD, "GET")
|
.header(ACCESS_CONTROL_REQUEST_METHOD, "GET")
|
||||||
.header(ACCESS_CONTROL_REQUEST_HEADERS, "Header1")
|
.header(ACCESS_CONTROL_REQUEST_HEADERS, "Header1")
|
||||||
.toExchange();
|
.build());
|
||||||
|
|
||||||
this.processor.process(this.conf, exchange);
|
this.processor.process(this.conf, exchange);
|
||||||
|
|
||||||
|
@ -215,10 +220,10 @@ public class DefaultCorsProcessorTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void preflightRequestValidRequestAndConfig() throws Exception {
|
public void preflightRequestValidRequestAndConfig() throws Exception {
|
||||||
ServerWebExchange exchange = preFlightRequest()
|
ServerWebExchange exchange = MockServerWebExchange.from(preFlightRequest()
|
||||||
.header(ACCESS_CONTROL_REQUEST_METHOD, "GET")
|
.header(ACCESS_CONTROL_REQUEST_METHOD, "GET")
|
||||||
.header(ACCESS_CONTROL_REQUEST_HEADERS, "Header1")
|
.header(ACCESS_CONTROL_REQUEST_HEADERS, "Header1")
|
||||||
.toExchange();
|
.build());
|
||||||
|
|
||||||
this.conf.addAllowedOrigin("*");
|
this.conf.addAllowedOrigin("*");
|
||||||
this.conf.addAllowedMethod("GET");
|
this.conf.addAllowedMethod("GET");
|
||||||
|
@ -239,10 +244,10 @@ public class DefaultCorsProcessorTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void preflightRequestCredentials() throws Exception {
|
public void preflightRequestCredentials() throws Exception {
|
||||||
ServerWebExchange exchange = preFlightRequest()
|
ServerWebExchange exchange = MockServerWebExchange.from(preFlightRequest()
|
||||||
.header(ACCESS_CONTROL_REQUEST_METHOD, "GET")
|
.header(ACCESS_CONTROL_REQUEST_METHOD, "GET")
|
||||||
.header(ACCESS_CONTROL_REQUEST_HEADERS, "Header1")
|
.header(ACCESS_CONTROL_REQUEST_HEADERS, "Header1")
|
||||||
.toExchange();
|
.build());
|
||||||
|
|
||||||
this.conf.addAllowedOrigin("http://domain1.com");
|
this.conf.addAllowedOrigin("http://domain1.com");
|
||||||
this.conf.addAllowedOrigin("http://domain2.com");
|
this.conf.addAllowedOrigin("http://domain2.com");
|
||||||
|
@ -262,10 +267,10 @@ public class DefaultCorsProcessorTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void preflightRequestCredentialsWithOriginWildcard() throws Exception {
|
public void preflightRequestCredentialsWithOriginWildcard() throws Exception {
|
||||||
ServerWebExchange exchange = preFlightRequest()
|
ServerWebExchange exchange = MockServerWebExchange.from(preFlightRequest()
|
||||||
.header(ACCESS_CONTROL_REQUEST_METHOD, "GET")
|
.header(ACCESS_CONTROL_REQUEST_METHOD, "GET")
|
||||||
.header(ACCESS_CONTROL_REQUEST_HEADERS, "Header1")
|
.header(ACCESS_CONTROL_REQUEST_HEADERS, "Header1")
|
||||||
.toExchange();
|
.build());
|
||||||
|
|
||||||
this.conf.addAllowedOrigin("http://domain1.com");
|
this.conf.addAllowedOrigin("http://domain1.com");
|
||||||
this.conf.addAllowedOrigin("*");
|
this.conf.addAllowedOrigin("*");
|
||||||
|
@ -283,10 +288,10 @@ public class DefaultCorsProcessorTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void preflightRequestAllowedHeaders() throws Exception {
|
public void preflightRequestAllowedHeaders() throws Exception {
|
||||||
ServerWebExchange exchange = preFlightRequest()
|
ServerWebExchange exchange = MockServerWebExchange.from(preFlightRequest()
|
||||||
.header(ACCESS_CONTROL_REQUEST_METHOD, "GET")
|
.header(ACCESS_CONTROL_REQUEST_METHOD, "GET")
|
||||||
.header(ACCESS_CONTROL_REQUEST_HEADERS, "Header1, Header2")
|
.header(ACCESS_CONTROL_REQUEST_HEADERS, "Header1, Header2")
|
||||||
.toExchange();
|
.build());
|
||||||
|
|
||||||
this.conf.addAllowedHeader("Header1");
|
this.conf.addAllowedHeader("Header1");
|
||||||
this.conf.addAllowedHeader("Header2");
|
this.conf.addAllowedHeader("Header2");
|
||||||
|
@ -306,10 +311,10 @@ public class DefaultCorsProcessorTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void preflightRequestAllowsAllHeaders() throws Exception {
|
public void preflightRequestAllowsAllHeaders() throws Exception {
|
||||||
ServerWebExchange exchange = preFlightRequest()
|
ServerWebExchange exchange = MockServerWebExchange.from(preFlightRequest()
|
||||||
.header(ACCESS_CONTROL_REQUEST_METHOD, "GET")
|
.header(ACCESS_CONTROL_REQUEST_METHOD, "GET")
|
||||||
.header(ACCESS_CONTROL_REQUEST_HEADERS, "Header1, Header2")
|
.header(ACCESS_CONTROL_REQUEST_HEADERS, "Header1, Header2")
|
||||||
.toExchange();
|
.build());
|
||||||
|
|
||||||
this.conf.addAllowedHeader("*");
|
this.conf.addAllowedHeader("*");
|
||||||
this.conf.addAllowedOrigin("http://domain2.com");
|
this.conf.addAllowedOrigin("http://domain2.com");
|
||||||
|
@ -327,10 +332,10 @@ public class DefaultCorsProcessorTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void preflightRequestWithEmptyHeaders() throws Exception {
|
public void preflightRequestWithEmptyHeaders() throws Exception {
|
||||||
ServerWebExchange exchange = preFlightRequest()
|
ServerWebExchange exchange = MockServerWebExchange.from(preFlightRequest()
|
||||||
.header(ACCESS_CONTROL_REQUEST_METHOD, "GET")
|
.header(ACCESS_CONTROL_REQUEST_METHOD, "GET")
|
||||||
.header(ACCESS_CONTROL_REQUEST_HEADERS, "")
|
.header(ACCESS_CONTROL_REQUEST_HEADERS, "")
|
||||||
.toExchange();
|
.build());
|
||||||
|
|
||||||
this.conf.addAllowedHeader("*");
|
this.conf.addAllowedHeader("*");
|
||||||
this.conf.addAllowedOrigin("http://domain2.com");
|
this.conf.addAllowedOrigin("http://domain2.com");
|
||||||
|
@ -345,7 +350,8 @@ public class DefaultCorsProcessorTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void preflightRequestWithNullConfig() throws Exception {
|
public void preflightRequestWithNullConfig() throws Exception {
|
||||||
ServerWebExchange exchange = preFlightRequest().header(ACCESS_CONTROL_REQUEST_METHOD, "GET").toExchange();
|
MockServerHttpRequest request = preFlightRequest().header(ACCESS_CONTROL_REQUEST_METHOD, "GET").build();
|
||||||
|
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
this.conf.addAllowedOrigin("*");
|
this.conf.addAllowedOrigin("*");
|
||||||
this.processor.process(null, exchange);
|
this.processor.process(null, exchange);
|
||||||
|
|
||||||
|
@ -356,7 +362,7 @@ public class DefaultCorsProcessorTests {
|
||||||
|
|
||||||
|
|
||||||
private ServerWebExchange actualRequest() {
|
private ServerWebExchange actualRequest() {
|
||||||
return corsRequest(HttpMethod.GET).toExchange();
|
return MockServerWebExchange.from(corsRequest(HttpMethod.GET).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
private MockServerHttpRequest.BaseBuilder<?> preFlightRequest() {
|
private MockServerHttpRequest.BaseBuilder<?> preFlightRequest() {
|
||||||
|
|
|
@ -19,8 +19,8 @@ package org.springframework.web.cors.reactive;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.web.cors.CorsConfiguration;
|
import org.springframework.web.cors.CorsConfiguration;
|
||||||
import org.springframework.web.server.ServerWebExchange;
|
|
||||||
import org.springframework.web.util.pattern.PathPatternParser;
|
import org.springframework.web.util.pattern.PathPatternParser;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
@ -40,7 +40,7 @@ public class UrlBasedCorsConfigurationSourceTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void empty() {
|
public void empty() {
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/bar/test.html").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/bar/test.html").build());
|
||||||
assertNull(this.configSource.getCorsConfiguration(exchange));
|
assertNull(this.configSource.getCorsConfiguration(exchange));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,10 +49,10 @@ public class UrlBasedCorsConfigurationSourceTests {
|
||||||
CorsConfiguration config = new CorsConfiguration();
|
CorsConfiguration config = new CorsConfiguration();
|
||||||
this.configSource.registerCorsConfiguration("/bar/**", config);
|
this.configSource.registerCorsConfiguration("/bar/**", config);
|
||||||
|
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/foo/test.html").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/foo/test.html").build());
|
||||||
assertNull(this.configSource.getCorsConfiguration(exchange));
|
assertNull(this.configSource.getCorsConfiguration(exchange));
|
||||||
|
|
||||||
exchange = MockServerHttpRequest.get("/bar/test.html").toExchange();
|
exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/bar/test.html").build());
|
||||||
assertEquals(config, this.configSource.getCorsConfiguration(exchange));
|
assertEquals(config, this.configSource.getCorsConfiguration(exchange));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ import reactor.core.publisher.Mono;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerWebExchange;
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.web.server.ServerWebExchange;
|
import org.springframework.web.server.ServerWebExchange;
|
||||||
import org.springframework.web.server.WebFilterChain;
|
import org.springframework.web.server.WebFilterChain;
|
||||||
|
|
||||||
|
@ -43,13 +43,13 @@ public class ForwardedHeaderFilterTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void removeOnly() {
|
public void removeOnly() {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("/")
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/")
|
||||||
.header("Forwarded", "for=192.0.2.60;proto=http;by=203.0.113.43")
|
.header("Forwarded", "for=192.0.2.60;proto=http;by=203.0.113.43")
|
||||||
.header("X-Forwarded-Host", "example.com")
|
.header("X-Forwarded-Host", "example.com")
|
||||||
.header("X-Forwarded-Port", "8080")
|
.header("X-Forwarded-Port", "8080")
|
||||||
.header("X-Forwarded-Proto", "http")
|
.header("X-Forwarded-Proto", "http")
|
||||||
.header("X-Forwarded-Prefix", "prefix")
|
.header("X-Forwarded-Prefix", "prefix")
|
||||||
.toExchange();
|
.build());
|
||||||
|
|
||||||
this.filter.setRemoveOnly(true);
|
this.filter.setRemoveOnly(true);
|
||||||
this.filter.filter(exchange, this.filterChain).block(Duration.ZERO);
|
this.filter.filter(exchange, this.filterChain).block(Duration.ZERO);
|
||||||
|
@ -65,11 +65,11 @@ public class ForwardedHeaderFilterTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void xForwardedRequest() throws Exception {
|
public void xForwardedRequest() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("http://example.com/path")
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("http://example.com/path")
|
||||||
.header("X-Forwarded-Host", "84.198.58.199")
|
.header("X-Forwarded-Host", "84.198.58.199")
|
||||||
.header("X-Forwarded-Port", "443")
|
.header("X-Forwarded-Port", "443")
|
||||||
.header("X-Forwarded-Proto", "https")
|
.header("X-Forwarded-Proto", "https")
|
||||||
.toExchange();
|
.build());
|
||||||
|
|
||||||
this.filter.filter(exchange, this.filterChain).block(Duration.ZERO);
|
this.filter.filter(exchange, this.filterChain).block(Duration.ZERO);
|
||||||
|
|
||||||
|
@ -79,10 +79,10 @@ public class ForwardedHeaderFilterTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void forwardedRequest() throws Exception {
|
public void forwardedRequest() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("http://example.com/path")
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("http://example.com/path")
|
||||||
.header("Forwarded", "host=84.198.58.199;proto=https")
|
.header("Forwarded", "host=84.198.58.199;proto=https")
|
||||||
|
|
||||||
.toExchange();
|
.build());
|
||||||
|
|
||||||
this.filter.filter(exchange, this.filterChain).block(Duration.ZERO);
|
this.filter.filter(exchange, this.filterChain).block(Duration.ZERO);
|
||||||
|
|
||||||
|
@ -92,9 +92,9 @@ public class ForwardedHeaderFilterTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void requestUriWithForwardedPrefix() throws Exception {
|
public void requestUriWithForwardedPrefix() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("http://example.com/path")
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("http://example.com/path")
|
||||||
.header("X-Forwarded-Prefix", "/prefix")
|
.header("X-Forwarded-Prefix", "/prefix")
|
||||||
.toExchange();
|
.build());
|
||||||
|
|
||||||
this.filter.filter(exchange, this.filterChain).block(Duration.ZERO);
|
this.filter.filter(exchange, this.filterChain).block(Duration.ZERO);
|
||||||
|
|
||||||
|
@ -104,9 +104,9 @@ public class ForwardedHeaderFilterTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void requestUriWithForwardedPrefixTrailingSlash() throws Exception {
|
public void requestUriWithForwardedPrefixTrailingSlash() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("http://example.com/path")
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("http://example.com/path")
|
||||||
.header("X-Forwarded-Prefix", "/prefix/")
|
.header("X-Forwarded-Prefix", "/prefix/")
|
||||||
.toExchange();
|
.build());
|
||||||
|
|
||||||
this.filter.filter(exchange, this.filterChain).block(Duration.ZERO);
|
this.filter.filter(exchange, this.filterChain).block(Duration.ZERO);
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.HttpMethod;
|
import org.springframework.http.HttpMethod;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerWebExchange;
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.web.server.ServerWebExchange;
|
import org.springframework.web.server.ServerWebExchange;
|
||||||
import org.springframework.web.server.WebFilterChain;
|
import org.springframework.web.server.WebFilterChain;
|
||||||
|
|
||||||
|
@ -84,10 +84,10 @@ public class HiddenHttpMethodFilterTests {
|
||||||
@Test
|
@Test
|
||||||
public void filterWithHttpPut() {
|
public void filterWithHttpPut() {
|
||||||
|
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.put("/")
|
ServerWebExchange exchange = MockServerWebExchange.from(
|
||||||
|
MockServerHttpRequest.put("/")
|
||||||
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
||||||
.body("_method=DELETE")
|
.body("_method=DELETE"));
|
||||||
.toExchange();
|
|
||||||
|
|
||||||
this.filter.filter(exchange, this.filterChain).block(Duration.ZERO);
|
this.filter.filter(exchange, this.filterChain).block(Duration.ZERO);
|
||||||
assertEquals(HttpMethod.PUT, this.filterChain.getHttpMethod());
|
assertEquals(HttpMethod.PUT, this.filterChain.getHttpMethod());
|
||||||
|
@ -96,10 +96,10 @@ public class HiddenHttpMethodFilterTests {
|
||||||
|
|
||||||
private Mono<Void> postForm(String body) {
|
private Mono<Void> postForm(String body) {
|
||||||
|
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.post("/")
|
MockServerWebExchange exchange = MockServerWebExchange.from(
|
||||||
|
MockServerHttpRequest.post("/")
|
||||||
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
||||||
.body(body)
|
.body(body));
|
||||||
.toExchange();
|
|
||||||
|
|
||||||
return this.filter.filter(exchange, this.filterChain);
|
return this.filter.filter(exchange, this.filterChain);
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ import org.junit.runners.Parameterized.Parameters;
|
||||||
import org.springframework.http.HttpMethod;
|
import org.springframework.http.HttpMethod;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerWebExchange;
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
|
@ -79,7 +79,8 @@ public class DefaultServerWebExchangeCheckNotModifiedTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void checkNotModifiedNon2xxStatus() {
|
public void checkNotModifiedNon2xxStatus() {
|
||||||
MockServerWebExchange exchange = get("/").ifModifiedSince(this.currentDate.toEpochMilli()).toExchange();
|
MockServerHttpRequest request = get("/").ifModifiedSince(this.currentDate.toEpochMilli()).build();
|
||||||
|
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
exchange.getResponse().setStatusCode(HttpStatus.NOT_MODIFIED);
|
exchange.getResponse().setStatusCode(HttpStatus.NOT_MODIFIED);
|
||||||
|
|
||||||
assertFalse(exchange.checkNotModified(this.currentDate));
|
assertFalse(exchange.checkNotModified(this.currentDate));
|
||||||
|
@ -90,7 +91,7 @@ public class DefaultServerWebExchangeCheckNotModifiedTests {
|
||||||
@Test // SPR-14559
|
@Test // SPR-14559
|
||||||
public void checkNotModifiedInvalidIfNoneMatchHeader() {
|
public void checkNotModifiedInvalidIfNoneMatchHeader() {
|
||||||
String eTag = "\"etagvalue\"";
|
String eTag = "\"etagvalue\"";
|
||||||
MockServerWebExchange exchange = get("/").ifNoneMatch("missingquotes").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").ifNoneMatch("missingquotes").build());
|
||||||
assertFalse(exchange.checkNotModified(eTag));
|
assertFalse(exchange.checkNotModified(eTag));
|
||||||
assertNull(exchange.getResponse().getStatusCode());
|
assertNull(exchange.getResponse().getStatusCode());
|
||||||
assertEquals(eTag, exchange.getResponse().getHeaders().getETag());
|
assertEquals(eTag, exchange.getResponse().getHeaders().getETag());
|
||||||
|
@ -98,7 +99,8 @@ public class DefaultServerWebExchangeCheckNotModifiedTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void checkNotModifiedHeaderAlreadySet() {
|
public void checkNotModifiedHeaderAlreadySet() {
|
||||||
MockServerWebExchange exchange = get("/").ifModifiedSince(currentDate.toEpochMilli()).toExchange();
|
MockServerHttpRequest request = get("/").ifModifiedSince(currentDate.toEpochMilli()).build();
|
||||||
|
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
exchange.getResponse().getHeaders().add("Last-Modified", CURRENT_TIME);
|
exchange.getResponse().getHeaders().add("Last-Modified", CURRENT_TIME);
|
||||||
|
|
||||||
assertTrue(exchange.checkNotModified(currentDate));
|
assertTrue(exchange.checkNotModified(currentDate));
|
||||||
|
@ -109,7 +111,8 @@ public class DefaultServerWebExchangeCheckNotModifiedTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void checkNotModifiedTimestamp() throws Exception {
|
public void checkNotModifiedTimestamp() throws Exception {
|
||||||
MockServerWebExchange exchange = get("/").ifModifiedSince(currentDate.toEpochMilli()).toExchange();
|
MockServerHttpRequest request = get("/").ifModifiedSince(currentDate.toEpochMilli()).build();
|
||||||
|
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
|
|
||||||
assertTrue(exchange.checkNotModified(currentDate));
|
assertTrue(exchange.checkNotModified(currentDate));
|
||||||
|
|
||||||
|
@ -120,7 +123,8 @@ public class DefaultServerWebExchangeCheckNotModifiedTests {
|
||||||
@Test
|
@Test
|
||||||
public void checkModifiedTimestamp() {
|
public void checkModifiedTimestamp() {
|
||||||
Instant oneMinuteAgo = currentDate.minusSeconds(60);
|
Instant oneMinuteAgo = currentDate.minusSeconds(60);
|
||||||
MockServerWebExchange exchange = get("/").ifModifiedSince(oneMinuteAgo.toEpochMilli()).toExchange();
|
MockServerHttpRequest request = get("/").ifModifiedSince(oneMinuteAgo.toEpochMilli()).build();
|
||||||
|
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
|
|
||||||
assertFalse(exchange.checkNotModified(currentDate));
|
assertFalse(exchange.checkNotModified(currentDate));
|
||||||
|
|
||||||
|
@ -131,7 +135,7 @@ public class DefaultServerWebExchangeCheckNotModifiedTests {
|
||||||
@Test
|
@Test
|
||||||
public void checkNotModifiedETag() {
|
public void checkNotModifiedETag() {
|
||||||
String eTag = "\"Foo\"";
|
String eTag = "\"Foo\"";
|
||||||
MockServerWebExchange exchange = get("/").ifNoneMatch(eTag).toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").ifNoneMatch(eTag).build());
|
||||||
|
|
||||||
assertTrue(exchange.checkNotModified(eTag));
|
assertTrue(exchange.checkNotModified(eTag));
|
||||||
|
|
||||||
|
@ -142,7 +146,7 @@ public class DefaultServerWebExchangeCheckNotModifiedTests {
|
||||||
@Test
|
@Test
|
||||||
public void checkNotModifiedETagWithSeparatorChars() {
|
public void checkNotModifiedETagWithSeparatorChars() {
|
||||||
String eTag = "\"Foo, Bar\"";
|
String eTag = "\"Foo, Bar\"";
|
||||||
MockServerWebExchange exchange = get("/").ifNoneMatch(eTag).toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").ifNoneMatch(eTag).build());
|
||||||
|
|
||||||
assertTrue(exchange.checkNotModified(eTag));
|
assertTrue(exchange.checkNotModified(eTag));
|
||||||
|
|
||||||
|
@ -155,7 +159,7 @@ public class DefaultServerWebExchangeCheckNotModifiedTests {
|
||||||
public void checkModifiedETag() {
|
public void checkModifiedETag() {
|
||||||
String currentETag = "\"Foo\"";
|
String currentETag = "\"Foo\"";
|
||||||
String oldEtag = "Bar";
|
String oldEtag = "Bar";
|
||||||
MockServerWebExchange exchange = get("/").ifNoneMatch(oldEtag).toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").ifNoneMatch(oldEtag).build());
|
||||||
|
|
||||||
assertFalse(exchange.checkNotModified(currentETag));
|
assertFalse(exchange.checkNotModified(currentETag));
|
||||||
|
|
||||||
|
@ -167,7 +171,7 @@ public class DefaultServerWebExchangeCheckNotModifiedTests {
|
||||||
public void checkNotModifiedUnpaddedETag() {
|
public void checkNotModifiedUnpaddedETag() {
|
||||||
String eTag = "Foo";
|
String eTag = "Foo";
|
||||||
String paddedEtag = String.format("\"%s\"", eTag);
|
String paddedEtag = String.format("\"%s\"", eTag);
|
||||||
MockServerWebExchange exchange = get("/").ifNoneMatch(paddedEtag).toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").ifNoneMatch(paddedEtag).build());
|
||||||
|
|
||||||
assertTrue(exchange.checkNotModified(eTag));
|
assertTrue(exchange.checkNotModified(eTag));
|
||||||
|
|
||||||
|
@ -179,7 +183,7 @@ public class DefaultServerWebExchangeCheckNotModifiedTests {
|
||||||
public void checkModifiedUnpaddedETag() {
|
public void checkModifiedUnpaddedETag() {
|
||||||
String currentETag = "Foo";
|
String currentETag = "Foo";
|
||||||
String oldEtag = "Bar";
|
String oldEtag = "Bar";
|
||||||
MockServerWebExchange exchange = get("/").ifNoneMatch(oldEtag).toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").ifNoneMatch(oldEtag).build());
|
||||||
|
|
||||||
assertFalse(exchange.checkNotModified(currentETag));
|
assertFalse(exchange.checkNotModified(currentETag));
|
||||||
|
|
||||||
|
@ -190,7 +194,7 @@ public class DefaultServerWebExchangeCheckNotModifiedTests {
|
||||||
@Test
|
@Test
|
||||||
public void checkNotModifiedWildcardIsIgnored() {
|
public void checkNotModifiedWildcardIsIgnored() {
|
||||||
String eTag = "\"Foo\"";
|
String eTag = "\"Foo\"";
|
||||||
MockServerWebExchange exchange = get("/").ifNoneMatch("*").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").ifNoneMatch("*").build());
|
||||||
assertFalse(exchange.checkNotModified(eTag));
|
assertFalse(exchange.checkNotModified(eTag));
|
||||||
|
|
||||||
assertNull(exchange.getResponse().getStatusCode());
|
assertNull(exchange.getResponse().getStatusCode());
|
||||||
|
@ -201,7 +205,8 @@ public class DefaultServerWebExchangeCheckNotModifiedTests {
|
||||||
public void checkNotModifiedETagAndTimestamp() {
|
public void checkNotModifiedETagAndTimestamp() {
|
||||||
String eTag = "\"Foo\"";
|
String eTag = "\"Foo\"";
|
||||||
long time = currentDate.toEpochMilli();
|
long time = currentDate.toEpochMilli();
|
||||||
MockServerWebExchange exchange = get("/").ifNoneMatch(eTag).ifModifiedSince(time).toExchange();
|
MockServerHttpRequest request = get("/").ifNoneMatch(eTag).ifModifiedSince(time).build();
|
||||||
|
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
|
|
||||||
assertTrue(exchange.checkNotModified(eTag, currentDate));
|
assertTrue(exchange.checkNotModified(eTag, currentDate));
|
||||||
|
|
||||||
|
@ -215,10 +220,10 @@ public class DefaultServerWebExchangeCheckNotModifiedTests {
|
||||||
public void checkNotModifiedETagAndModifiedTimestamp() {
|
public void checkNotModifiedETagAndModifiedTimestamp() {
|
||||||
String eTag = "\"Foo\"";
|
String eTag = "\"Foo\"";
|
||||||
Instant oneMinuteAgo = currentDate.minusSeconds(60);
|
Instant oneMinuteAgo = currentDate.minusSeconds(60);
|
||||||
MockServerWebExchange exchange = get("/")
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/")
|
||||||
.ifNoneMatch(eTag)
|
.ifNoneMatch(eTag)
|
||||||
.ifModifiedSince(oneMinuteAgo.toEpochMilli())
|
.ifModifiedSince(oneMinuteAgo.toEpochMilli())
|
||||||
.toExchange();
|
.build());
|
||||||
|
|
||||||
assertTrue(exchange.checkNotModified(eTag, currentDate));
|
assertTrue(exchange.checkNotModified(eTag, currentDate));
|
||||||
|
|
||||||
|
@ -232,7 +237,8 @@ public class DefaultServerWebExchangeCheckNotModifiedTests {
|
||||||
String currentETag = "\"Foo\"";
|
String currentETag = "\"Foo\"";
|
||||||
String oldEtag = "\"Bar\"";
|
String oldEtag = "\"Bar\"";
|
||||||
long time = currentDate.toEpochMilli();
|
long time = currentDate.toEpochMilli();
|
||||||
MockServerWebExchange exchange = get("/").ifNoneMatch(oldEtag).ifModifiedSince(time).toExchange();
|
MockServerHttpRequest request = get("/").ifNoneMatch(oldEtag).ifModifiedSince(time).build();
|
||||||
|
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
|
|
||||||
assertFalse(exchange.checkNotModified(currentETag, currentDate));
|
assertFalse(exchange.checkNotModified(currentETag, currentDate));
|
||||||
|
|
||||||
|
@ -245,7 +251,7 @@ public class DefaultServerWebExchangeCheckNotModifiedTests {
|
||||||
public void checkNotModifiedETagWeakStrong() {
|
public void checkNotModifiedETagWeakStrong() {
|
||||||
String eTag = "\"Foo\"";
|
String eTag = "\"Foo\"";
|
||||||
String weakEtag = String.format("W/%s", eTag);
|
String weakEtag = String.format("W/%s", eTag);
|
||||||
MockServerWebExchange exchange = get("/").ifNoneMatch(eTag).toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").ifNoneMatch(eTag).build());
|
||||||
|
|
||||||
assertTrue(exchange.checkNotModified(weakEtag));
|
assertTrue(exchange.checkNotModified(weakEtag));
|
||||||
|
|
||||||
|
@ -256,7 +262,8 @@ public class DefaultServerWebExchangeCheckNotModifiedTests {
|
||||||
@Test
|
@Test
|
||||||
public void checkNotModifiedETagStrongWeak() {
|
public void checkNotModifiedETagStrongWeak() {
|
||||||
String eTag = "\"Foo\"";
|
String eTag = "\"Foo\"";
|
||||||
MockServerWebExchange exchange = get("/").ifNoneMatch(String.format("W/%s", eTag)).toExchange();
|
MockServerHttpRequest request = get("/").ifNoneMatch(String.format("W/%s", eTag)).build();
|
||||||
|
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
|
|
||||||
assertTrue(exchange.checkNotModified(eTag));
|
assertTrue(exchange.checkNotModified(eTag));
|
||||||
|
|
||||||
|
@ -268,7 +275,7 @@ public class DefaultServerWebExchangeCheckNotModifiedTests {
|
||||||
public void checkNotModifiedMultipleETags() {
|
public void checkNotModifiedMultipleETags() {
|
||||||
String eTag = "\"Bar\"";
|
String eTag = "\"Bar\"";
|
||||||
String multipleETags = String.format("\"Foo\", %s", eTag);
|
String multipleETags = String.format("\"Foo\", %s", eTag);
|
||||||
MockServerWebExchange exchange = get("/").ifNoneMatch(multipleETags).toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").ifNoneMatch(multipleETags).build());
|
||||||
|
|
||||||
assertTrue(exchange.checkNotModified(eTag));
|
assertTrue(exchange.checkNotModified(eTag));
|
||||||
|
|
||||||
|
@ -280,7 +287,8 @@ public class DefaultServerWebExchangeCheckNotModifiedTests {
|
||||||
public void checkNotModifiedTimestampWithLengthPart() throws Exception {
|
public void checkNotModifiedTimestampWithLengthPart() throws Exception {
|
||||||
long epochTime = dateFormat.parse(CURRENT_TIME).getTime();
|
long epochTime = dateFormat.parse(CURRENT_TIME).getTime();
|
||||||
String header = "Wed, 09 Apr 2014 09:57:42 GMT; length=13774";
|
String header = "Wed, 09 Apr 2014 09:57:42 GMT; length=13774";
|
||||||
MockServerWebExchange exchange = get("/").header("If-Modified-Since", header).toExchange();
|
MockServerHttpRequest request = get("/").header("If-Modified-Since", header).build();
|
||||||
|
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
|
|
||||||
assertTrue(exchange.checkNotModified(Instant.ofEpochMilli(epochTime)));
|
assertTrue(exchange.checkNotModified(Instant.ofEpochMilli(epochTime)));
|
||||||
|
|
||||||
|
@ -292,7 +300,8 @@ public class DefaultServerWebExchangeCheckNotModifiedTests {
|
||||||
public void checkModifiedTimestampWithLengthPart() throws Exception {
|
public void checkModifiedTimestampWithLengthPart() throws Exception {
|
||||||
long epochTime = dateFormat.parse(CURRENT_TIME).getTime();
|
long epochTime = dateFormat.parse(CURRENT_TIME).getTime();
|
||||||
String header = "Tue, 08 Apr 2014 09:57:42 GMT; length=13774";
|
String header = "Tue, 08 Apr 2014 09:57:42 GMT; length=13774";
|
||||||
MockServerWebExchange exchange = get("/").header("If-Modified-Since", header).toExchange();
|
MockServerHttpRequest request = get("/").header("If-Modified-Since", header).build();
|
||||||
|
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
|
|
||||||
assertFalse(exchange.checkNotModified(Instant.ofEpochMilli(epochTime)));
|
assertFalse(exchange.checkNotModified(Instant.ofEpochMilli(epochTime)));
|
||||||
|
|
||||||
|
@ -304,7 +313,8 @@ public class DefaultServerWebExchangeCheckNotModifiedTests {
|
||||||
public void checkNotModifiedTimestampConditionalPut() throws Exception {
|
public void checkNotModifiedTimestampConditionalPut() throws Exception {
|
||||||
Instant oneMinuteAgo = currentDate.minusSeconds(60);
|
Instant oneMinuteAgo = currentDate.minusSeconds(60);
|
||||||
long millis = currentDate.toEpochMilli();
|
long millis = currentDate.toEpochMilli();
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.put("/").ifUnmodifiedSince(millis).toExchange();
|
MockServerHttpRequest request = MockServerHttpRequest.put("/").ifUnmodifiedSince(millis).build();
|
||||||
|
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
|
|
||||||
assertFalse(exchange.checkNotModified(oneMinuteAgo));
|
assertFalse(exchange.checkNotModified(oneMinuteAgo));
|
||||||
assertNull(exchange.getResponse().getStatusCode());
|
assertNull(exchange.getResponse().getStatusCode());
|
||||||
|
@ -315,7 +325,8 @@ public class DefaultServerWebExchangeCheckNotModifiedTests {
|
||||||
public void checkNotModifiedTimestampConditionalPutConflict() throws Exception {
|
public void checkNotModifiedTimestampConditionalPutConflict() throws Exception {
|
||||||
Instant oneMinuteAgo = currentDate.minusSeconds(60);
|
Instant oneMinuteAgo = currentDate.minusSeconds(60);
|
||||||
long millis = oneMinuteAgo.toEpochMilli();
|
long millis = oneMinuteAgo.toEpochMilli();
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.put("/").ifUnmodifiedSince(millis).toExchange();
|
MockServerHttpRequest request = MockServerHttpRequest.put("/").ifUnmodifiedSince(millis).build();
|
||||||
|
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
|
|
||||||
assertTrue(exchange.checkNotModified(currentDate));
|
assertTrue(exchange.checkNotModified(currentDate));
|
||||||
assertEquals(412, exchange.getResponse().getStatusCode().value());
|
assertEquals(412, exchange.getResponse().getStatusCode().value());
|
||||||
|
|
|
@ -20,7 +20,7 @@ import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerWebExchange;
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.web.server.ServerWebExchange;
|
import org.springframework.web.server.ServerWebExchange;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
@ -32,10 +32,11 @@ public class ServerWebExchangeTests {
|
||||||
|
|
||||||
private ServerWebExchange exchange;
|
private ServerWebExchange exchange;
|
||||||
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void createExchange() {
|
public void createExchange() {
|
||||||
MockServerHttpRequest request = MockServerHttpRequest.get("http://example.com").build();
|
MockServerHttpRequest request = MockServerHttpRequest.get("http://example.com").build();
|
||||||
this.exchange = new MockServerWebExchange(request);
|
this.exchange = MockServerWebExchange.from(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -24,6 +24,7 @@ import reactor.test.StepVerifier;
|
||||||
|
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.web.server.ServerWebExchange;
|
import org.springframework.web.server.ServerWebExchange;
|
||||||
import org.springframework.web.server.WebExceptionHandler;
|
import org.springframework.web.server.WebExceptionHandler;
|
||||||
import org.springframework.web.server.WebHandler;
|
import org.springframework.web.server.WebHandler;
|
||||||
|
@ -38,10 +39,11 @@ import static org.junit.Assert.assertNull;
|
||||||
*/
|
*/
|
||||||
public class ExceptionHandlingWebHandlerTests {
|
public class ExceptionHandlingWebHandlerTests {
|
||||||
|
|
||||||
private final ServerWebExchange exchange = MockServerHttpRequest.get("http://localhost:8080").toExchange();
|
|
||||||
|
|
||||||
private final WebHandler targetHandler = new StubWebHandler(new IllegalStateException("boo"));
|
private final WebHandler targetHandler = new StubWebHandler(new IllegalStateException("boo"));
|
||||||
|
|
||||||
|
private final ServerWebExchange exchange = MockServerWebExchange.from(
|
||||||
|
MockServerHttpRequest.get("http://localhost:8080").build());
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void handleErrorSignal() throws Exception {
|
public void handleErrorSignal() throws Exception {
|
||||||
|
|
|
@ -28,6 +28,7 @@ import reactor.core.publisher.Mono;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse;
|
||||||
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.web.server.ServerWebExchange;
|
import org.springframework.web.server.ServerWebExchange;
|
||||||
import org.springframework.web.server.WebExceptionHandler;
|
import org.springframework.web.server.WebExceptionHandler;
|
||||||
import org.springframework.web.server.WebFilter;
|
import org.springframework.web.server.WebFilter;
|
||||||
|
@ -57,7 +58,7 @@ public class FilteringWebHandlerTests {
|
||||||
StubWebHandler targetHandler = new StubWebHandler();
|
StubWebHandler targetHandler = new StubWebHandler();
|
||||||
|
|
||||||
new FilteringWebHandler(targetHandler, Arrays.asList(filter1, filter2, filter3))
|
new FilteringWebHandler(targetHandler, Arrays.asList(filter1, filter2, filter3))
|
||||||
.handle(MockServerHttpRequest.get("/").toExchange())
|
.handle(MockServerWebExchange.from(MockServerHttpRequest.get("/").build()))
|
||||||
.block(Duration.ZERO);
|
.block(Duration.ZERO);
|
||||||
|
|
||||||
assertTrue(filter1.invoked());
|
assertTrue(filter1.invoked());
|
||||||
|
@ -72,7 +73,7 @@ public class FilteringWebHandlerTests {
|
||||||
StubWebHandler targetHandler = new StubWebHandler();
|
StubWebHandler targetHandler = new StubWebHandler();
|
||||||
|
|
||||||
new FilteringWebHandler(targetHandler, Collections.emptyList())
|
new FilteringWebHandler(targetHandler, Collections.emptyList())
|
||||||
.handle(MockServerHttpRequest.get("/").toExchange())
|
.handle(MockServerWebExchange.from(MockServerHttpRequest.get("/").build()))
|
||||||
.block(Duration.ZERO);
|
.block(Duration.ZERO);
|
||||||
|
|
||||||
assertTrue(targetHandler.invoked());
|
assertTrue(targetHandler.invoked());
|
||||||
|
@ -87,7 +88,7 @@ public class FilteringWebHandlerTests {
|
||||||
StubWebHandler targetHandler = new StubWebHandler();
|
StubWebHandler targetHandler = new StubWebHandler();
|
||||||
|
|
||||||
new FilteringWebHandler(targetHandler, Arrays.asList(filter1, filter2, filter3))
|
new FilteringWebHandler(targetHandler, Arrays.asList(filter1, filter2, filter3))
|
||||||
.handle(MockServerHttpRequest.get("/").toExchange())
|
.handle(MockServerWebExchange.from(MockServerHttpRequest.get("/").build()))
|
||||||
.block(Duration.ZERO);
|
.block(Duration.ZERO);
|
||||||
|
|
||||||
assertTrue(filter1.invoked());
|
assertTrue(filter1.invoked());
|
||||||
|
@ -103,7 +104,7 @@ public class FilteringWebHandlerTests {
|
||||||
StubWebHandler targetHandler = new StubWebHandler();
|
StubWebHandler targetHandler = new StubWebHandler();
|
||||||
|
|
||||||
new FilteringWebHandler(targetHandler, Collections.singletonList(filter))
|
new FilteringWebHandler(targetHandler, Collections.singletonList(filter))
|
||||||
.handle(MockServerHttpRequest.get("/").toExchange())
|
.handle(MockServerWebExchange.from(MockServerHttpRequest.get("/").build()))
|
||||||
.block(Duration.ofSeconds(5));
|
.block(Duration.ofSeconds(5));
|
||||||
|
|
||||||
assertTrue(filter.invoked());
|
assertTrue(filter.invoked());
|
||||||
|
|
|
@ -24,7 +24,7 @@ import reactor.test.StepVerifier;
|
||||||
|
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerWebExchange;
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.web.server.ResponseStatusException;
|
import org.springframework.web.server.ResponseStatusException;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
@ -39,7 +39,8 @@ public class ResponseStatusExceptionHandlerTests {
|
||||||
|
|
||||||
private final ResponseStatusExceptionHandler handler = new ResponseStatusExceptionHandler();
|
private final ResponseStatusExceptionHandler handler = new ResponseStatusExceptionHandler();
|
||||||
|
|
||||||
private final MockServerWebExchange exchange = MockServerHttpRequest.get("/").toExchange();
|
private final MockServerWebExchange exchange = MockServerWebExchange.from(
|
||||||
|
MockServerHttpRequest.get("/").build());
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -23,7 +23,7 @@ import java.util.Locale;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerWebExchange;
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.web.server.ServerWebExchange;
|
import org.springframework.web.server.ServerWebExchange;
|
||||||
|
|
||||||
import static java.util.Locale.*;
|
import static java.util.Locale.*;
|
||||||
|
@ -62,34 +62,27 @@ public class AcceptHeaderLocaleContextResolverTests {
|
||||||
this.resolver.setSupportedLocales(Arrays.asList(US, JAPAN));
|
this.resolver.setSupportedLocales(Arrays.asList(US, JAPAN));
|
||||||
this.resolver.setDefaultLocale(JAPAN);
|
this.resolver.setDefaultLocale(JAPAN);
|
||||||
|
|
||||||
MockServerWebExchange exchange = new MockServerWebExchange(MockServerHttpRequest
|
MockServerHttpRequest request = MockServerHttpRequest.get("/").acceptLanguageAsLocales(KOREA).build();
|
||||||
.get("/")
|
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
.acceptLanguageAsLocales(KOREA)
|
|
||||||
.build());
|
|
||||||
assertEquals(JAPAN, this.resolver.resolveLocaleContext(exchange).getLocale());
|
assertEquals(JAPAN, this.resolver.resolveLocaleContext(exchange).getLocale());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void defaultLocale() throws Exception {
|
public void defaultLocale() throws Exception {
|
||||||
this.resolver.setDefaultLocale(JAPANESE);
|
this.resolver.setDefaultLocale(JAPANESE);
|
||||||
MockServerWebExchange exchange = new MockServerWebExchange(MockServerHttpRequest
|
MockServerHttpRequest request = MockServerHttpRequest.get("/").build();
|
||||||
.get("/")
|
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
.build());
|
|
||||||
assertEquals(JAPANESE, this.resolver.resolveLocaleContext(exchange).getLocale());
|
assertEquals(JAPANESE, this.resolver.resolveLocaleContext(exchange).getLocale());
|
||||||
|
|
||||||
exchange = new MockServerWebExchange(MockServerHttpRequest
|
request = MockServerHttpRequest.get("/").acceptLanguageAsLocales(US).build();
|
||||||
.get("/")
|
exchange = MockServerWebExchange.from(request);
|
||||||
.acceptLanguageAsLocales(US)
|
|
||||||
.build());
|
|
||||||
assertEquals(US, this.resolver.resolveLocaleContext(exchange).getLocale());
|
assertEquals(US, this.resolver.resolveLocaleContext(exchange).getLocale());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private ServerWebExchange exchange(Locale... locales) {
|
private ServerWebExchange exchange(Locale... locales) {
|
||||||
return new MockServerWebExchange(MockServerHttpRequest
|
MockServerHttpRequest request = MockServerHttpRequest.get("").acceptLanguageAsLocales(locales).build();
|
||||||
.get("")
|
return MockServerWebExchange.from(request);
|
||||||
.acceptLanguageAsLocales(locales)
|
|
||||||
.build());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.context.i18n.TimeZoneAwareLocaleContext;
|
import org.springframework.context.i18n.TimeZoneAwareLocaleContext;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerWebExchange;
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.web.server.ServerWebExchange;
|
import org.springframework.web.server.ServerWebExchange;
|
||||||
|
|
||||||
import static java.util.Locale.CANADA;
|
import static java.util.Locale.CANADA;
|
||||||
|
@ -55,10 +55,8 @@ public class FixedLocaleContextResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
private ServerWebExchange exchange(Locale... locales) {
|
private ServerWebExchange exchange(Locale... locales) {
|
||||||
return new MockServerWebExchange(MockServerHttpRequest
|
MockServerHttpRequest request = MockServerHttpRequest.get("").acceptLanguageAsLocales(locales).build();
|
||||||
.get("")
|
return MockServerWebExchange.from(request);
|
||||||
.acceptLanguageAsLocales(locales)
|
|
||||||
.build());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ package org.springframework.web.server.session;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.web.server.ServerWebExchange;
|
import org.springframework.web.server.ServerWebExchange;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -40,7 +41,7 @@ public class HeaderWebSessionIdResolverTests {
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
this.idResolver = new HeaderWebSessionIdResolver();
|
this.idResolver = new HeaderWebSessionIdResolver();
|
||||||
this.exchange = MockServerHttpRequest.get("/path").toExchange();
|
this.exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path").build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -121,9 +122,9 @@ public class HeaderWebSessionIdResolverTests {
|
||||||
@Test
|
@Test
|
||||||
public void resolveSessionIdsWhenIdThenIdFound() {
|
public void resolveSessionIdsWhenIdThenIdFound() {
|
||||||
String id = "123";
|
String id = "123";
|
||||||
this.exchange = MockServerHttpRequest.get("/path")
|
this.exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path")
|
||||||
.header(HeaderWebSessionIdResolver.DEFAULT_HEADER_NAME, id)
|
.header(HeaderWebSessionIdResolver.DEFAULT_HEADER_NAME, id)
|
||||||
.toExchange();
|
.build());
|
||||||
|
|
||||||
List<String> ids = this.idResolver.resolveSessionIds(this.exchange);
|
List<String> ids = this.idResolver.resolveSessionIds(this.exchange);
|
||||||
|
|
||||||
|
@ -134,9 +135,10 @@ public class HeaderWebSessionIdResolverTests {
|
||||||
public void resolveSessionIdsWhenMultipleIdsThenIdsFound() {
|
public void resolveSessionIdsWhenMultipleIdsThenIdsFound() {
|
||||||
String id1 = "123";
|
String id1 = "123";
|
||||||
String id2 = "abc";
|
String id2 = "abc";
|
||||||
this.exchange = MockServerHttpRequest.get("/path")
|
this.exchange = MockServerWebExchange.from(
|
||||||
|
MockServerHttpRequest.get("/path")
|
||||||
.header(HeaderWebSessionIdResolver.DEFAULT_HEADER_NAME, id1, id2)
|
.header(HeaderWebSessionIdResolver.DEFAULT_HEADER_NAME, id1, id2)
|
||||||
.toExchange();
|
.build());
|
||||||
|
|
||||||
List<String> ids = this.idResolver.resolveSessionIds(this.exchange);
|
List<String> ids = this.idResolver.resolveSessionIds(this.exchange);
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@ import org.springframework.core.codec.CharSequenceEncoder;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.codec.EncoderHttpMessageWriter;
|
import org.springframework.http.codec.EncoderHttpMessageWriter;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
@ -51,8 +52,10 @@ import org.springframework.web.server.handler.ExceptionHandlingWebHandler;
|
||||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||||
import static org.hamcrest.CoreMatchers.startsWith;
|
import static org.hamcrest.CoreMatchers.startsWith;
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.Matchers.is;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.springframework.http.MediaType.*;
|
import static org.junit.Assert.assertSame;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
import static org.springframework.http.MediaType.APPLICATION_JSON;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test the effect of exceptions at different stages of request processing by
|
* Test the effect of exceptions at different stages of request processing by
|
||||||
|
@ -79,7 +82,8 @@ public class DispatcherHandlerErrorTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void noHandler() throws Exception {
|
public void noHandler() throws Exception {
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/does-not-exist").toExchange();
|
MockServerHttpRequest request = MockServerHttpRequest.get("/does-not-exist").build();
|
||||||
|
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
Mono<Void> publisher = this.dispatcherHandler.handle(exchange);
|
Mono<Void> publisher = this.dispatcherHandler.handle(exchange);
|
||||||
|
|
||||||
StepVerifier.create(publisher)
|
StepVerifier.create(publisher)
|
||||||
|
@ -92,7 +96,8 @@ public class DispatcherHandlerErrorTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void controllerReturnsMonoError() throws Exception {
|
public void controllerReturnsMonoError() throws Exception {
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/error-signal").toExchange();
|
MockServerHttpRequest request = MockServerHttpRequest.get("/error-signal").build();
|
||||||
|
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
Mono<Void> publisher = this.dispatcherHandler.handle(exchange);
|
Mono<Void> publisher = this.dispatcherHandler.handle(exchange);
|
||||||
|
|
||||||
StepVerifier.create(publisher)
|
StepVerifier.create(publisher)
|
||||||
|
@ -102,7 +107,8 @@ public class DispatcherHandlerErrorTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void controllerThrowsException() throws Exception {
|
public void controllerThrowsException() throws Exception {
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/raise-exception").toExchange();
|
MockServerHttpRequest request = MockServerHttpRequest.get("/raise-exception").build();
|
||||||
|
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
Mono<Void> publisher = this.dispatcherHandler.handle(exchange);
|
Mono<Void> publisher = this.dispatcherHandler.handle(exchange);
|
||||||
|
|
||||||
StepVerifier.create(publisher)
|
StepVerifier.create(publisher)
|
||||||
|
@ -112,7 +118,8 @@ public class DispatcherHandlerErrorTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void unknownReturnType() throws Exception {
|
public void unknownReturnType() throws Exception {
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/unknown-return-type").toExchange();
|
MockServerHttpRequest request = MockServerHttpRequest.get("/unknown-return-type").build();
|
||||||
|
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
Mono<Void> publisher = this.dispatcherHandler.handle(exchange);
|
Mono<Void> publisher = this.dispatcherHandler.handle(exchange);
|
||||||
|
|
||||||
StepVerifier.create(publisher)
|
StepVerifier.create(publisher)
|
||||||
|
@ -125,9 +132,8 @@ public class DispatcherHandlerErrorTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void responseBodyMessageConversionError() throws Exception {
|
public void responseBodyMessageConversionError() throws Exception {
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.post("/request-body")
|
ServerWebExchange exchange = MockServerWebExchange.from(
|
||||||
.accept(APPLICATION_JSON).body("body")
|
MockServerHttpRequest.post("/request-body").accept(APPLICATION_JSON).body("body"));
|
||||||
.toExchange();
|
|
||||||
|
|
||||||
Mono<Void> publisher = this.dispatcherHandler.handle(exchange);
|
Mono<Void> publisher = this.dispatcherHandler.handle(exchange);
|
||||||
|
|
||||||
|
@ -138,9 +144,8 @@ public class DispatcherHandlerErrorTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void requestBodyError() throws Exception {
|
public void requestBodyError() throws Exception {
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.post("/request-body")
|
ServerWebExchange exchange = MockServerWebExchange.from(
|
||||||
.body(Mono.error(EXCEPTION))
|
MockServerHttpRequest.post("/request-body").body(Mono.error(EXCEPTION)));
|
||||||
.toExchange();
|
|
||||||
|
|
||||||
Mono<Void> publisher = this.dispatcherHandler.handle(exchange);
|
Mono<Void> publisher = this.dispatcherHandler.handle(exchange);
|
||||||
|
|
||||||
|
@ -151,7 +156,8 @@ public class DispatcherHandlerErrorTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void webExceptionHandler() throws Exception {
|
public void webExceptionHandler() throws Exception {
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/unknown-argument-type").toExchange();
|
ServerWebExchange exchange = MockServerWebExchange.from(
|
||||||
|
MockServerHttpRequest.get("/unknown-argument-type").build());
|
||||||
|
|
||||||
List<WebExceptionHandler> handlers = Collections.singletonList(new ServerError500ExceptionHandler());
|
List<WebExceptionHandler> handlers = Collections.singletonList(new ServerError500ExceptionHandler());
|
||||||
WebHandler webHandler = new ExceptionHandlingWebHandler(this.dispatcherHandler, handlers);
|
WebHandler webHandler = new ExceptionHandlingWebHandler(this.dispatcherHandler, handlers);
|
||||||
|
|
|
@ -28,7 +28,7 @@ import org.springframework.core.Ordered;
|
||||||
import org.springframework.core.io.buffer.DataBuffer;
|
import org.springframework.core.io.buffer.DataBuffer;
|
||||||
import org.springframework.core.io.buffer.DefaultDataBufferFactory;
|
import org.springframework.core.io.buffer.DefaultDataBufferFactory;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerWebExchange;
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.web.method.ResolvableMethod;
|
import org.springframework.web.method.ResolvableMethod;
|
||||||
import org.springframework.web.server.ServerWebExchange;
|
import org.springframework.web.server.ServerWebExchange;
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ public class DispatcherHandlerTests {
|
||||||
|
|
||||||
DispatcherHandler dispatcherHandler = new DispatcherHandler(context);
|
DispatcherHandler dispatcherHandler = new DispatcherHandler(context);
|
||||||
|
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("/").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||||
dispatcherHandler.handle(exchange).block(Duration.ofSeconds(0));
|
dispatcherHandler.handle(exchange).block(Duration.ofSeconds(0));
|
||||||
assertEquals("1", exchange.getResponse().getBodyAsString().block(Duration.ofSeconds(5)));
|
assertEquals("1", exchange.getResponse().getBodyAsString().block(Duration.ofSeconds(5)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.web.server.NotAcceptableStatusException;
|
import org.springframework.web.server.NotAcceptableStatusException;
|
||||||
import org.springframework.web.server.ServerWebExchange;
|
import org.springframework.web.server.ServerWebExchange;
|
||||||
|
|
||||||
|
@ -46,8 +47,8 @@ public class HeaderContentTypeResolverTests {
|
||||||
@Test
|
@Test
|
||||||
public void resolveMediaTypes() throws Exception {
|
public void resolveMediaTypes() throws Exception {
|
||||||
String header = "text/plain; q=0.5, text/html, text/x-dvi; q=0.8, text/x-c";
|
String header = "text/plain; q=0.5, text/html, text/x-dvi; q=0.8, text/x-c";
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/").header("accept", header).toExchange();
|
MockServerHttpRequest request = MockServerHttpRequest.get("/").header("accept", header).build();
|
||||||
List<MediaType> mediaTypes = this.resolver.resolveMediaTypes(exchange);
|
List<MediaType> mediaTypes = this.resolver.resolveMediaTypes(MockServerWebExchange.from(request));
|
||||||
|
|
||||||
assertEquals(4, mediaTypes.size());
|
assertEquals(4, mediaTypes.size());
|
||||||
assertEquals("text/html", mediaTypes.get(0).toString());
|
assertEquals("text/html", mediaTypes.get(0).toString());
|
||||||
|
@ -59,8 +60,8 @@ public class HeaderContentTypeResolverTests {
|
||||||
@Test(expected = NotAcceptableStatusException.class)
|
@Test(expected = NotAcceptableStatusException.class)
|
||||||
public void resolveMediaTypesParseError() throws Exception {
|
public void resolveMediaTypesParseError() throws Exception {
|
||||||
String header = "textplain; q=0.5";
|
String header = "textplain; q=0.5";
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/").header("accept", header).toExchange();
|
MockServerHttpRequest request = MockServerHttpRequest.get("/").header("accept", header).build();
|
||||||
this.resolver.resolveMediaTypes(exchange);
|
this.resolver.resolveMediaTypes(MockServerWebExchange.from(request));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerWebExchange;
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.web.server.NotAcceptableStatusException;
|
import org.springframework.web.server.NotAcceptableStatusException;
|
||||||
import org.springframework.web.server.ServerWebExchange;
|
import org.springframework.web.server.ServerWebExchange;
|
||||||
|
|
||||||
|
@ -38,7 +38,8 @@ public class ParameterContentTypeResolverTests {
|
||||||
@Test
|
@Test
|
||||||
public void noKey() throws Exception {
|
public void noKey() throws Exception {
|
||||||
ParameterContentTypeResolver resolver = new ParameterContentTypeResolver(Collections.emptyMap());
|
ParameterContentTypeResolver resolver = new ParameterContentTypeResolver(Collections.emptyMap());
|
||||||
List<MediaType> mediaTypes = resolver.resolveMediaTypes(MockServerHttpRequest.get("/").toExchange());
|
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||||
|
List<MediaType> mediaTypes = resolver.resolveMediaTypes(exchange);
|
||||||
|
|
||||||
assertEquals(0, mediaTypes.size());
|
assertEquals(0, mediaTypes.size());
|
||||||
}
|
}
|
||||||
|
@ -86,7 +87,7 @@ public class ParameterContentTypeResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
private MockServerWebExchange createExchange(String format) {
|
private MockServerWebExchange createExchange(String format) {
|
||||||
return MockServerHttpRequest.get("/path?format=" + format).toExchange();
|
return MockServerWebExchange.from(MockServerHttpRequest.get("/path?format=" + format).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
import org.springframework.web.server.ServerWebExchange;
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
@ -36,7 +36,8 @@ public class RequestedContentTypeResolverBuilderTests {
|
||||||
public void defaultSettings() throws Exception {
|
public void defaultSettings() throws Exception {
|
||||||
|
|
||||||
RequestedContentTypeResolver resolver = new RequestedContentTypeResolverBuilder().build();
|
RequestedContentTypeResolver resolver = new RequestedContentTypeResolverBuilder().build();
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/flower").accept(MediaType.IMAGE_GIF).toExchange();
|
MockServerHttpRequest request = MockServerHttpRequest.get("/flower").accept(MediaType.IMAGE_GIF).build();
|
||||||
|
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
List<MediaType> mediaTypes = resolver.resolveMediaTypes(exchange);
|
List<MediaType> mediaTypes = resolver.resolveMediaTypes(exchange);
|
||||||
|
|
||||||
assertEquals(Collections.singletonList(MediaType.IMAGE_GIF), mediaTypes);
|
assertEquals(Collections.singletonList(MediaType.IMAGE_GIF), mediaTypes);
|
||||||
|
@ -49,7 +50,8 @@ public class RequestedContentTypeResolverBuilderTests {
|
||||||
builder.parameterResolver().mediaType("json", MediaType.APPLICATION_JSON);
|
builder.parameterResolver().mediaType("json", MediaType.APPLICATION_JSON);
|
||||||
RequestedContentTypeResolver resolver = builder.build();
|
RequestedContentTypeResolver resolver = builder.build();
|
||||||
|
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/flower?format=json").toExchange();
|
MockServerHttpRequest request = MockServerHttpRequest.get("/flower?format=json").build();
|
||||||
|
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
List<MediaType> mediaTypes = resolver.resolveMediaTypes(exchange);
|
List<MediaType> mediaTypes = resolver.resolveMediaTypes(exchange);
|
||||||
|
|
||||||
assertEquals(Collections.singletonList(MediaType.APPLICATION_JSON), mediaTypes);
|
assertEquals(Collections.singletonList(MediaType.APPLICATION_JSON), mediaTypes);
|
||||||
|
@ -62,8 +64,8 @@ public class RequestedContentTypeResolverBuilderTests {
|
||||||
builder.parameterResolver().mediaType("json", MediaType.APPLICATION_JSON).parameterName("s");
|
builder.parameterResolver().mediaType("json", MediaType.APPLICATION_JSON).parameterName("s");
|
||||||
RequestedContentTypeResolver resolver = builder.build();
|
RequestedContentTypeResolver resolver = builder.build();
|
||||||
|
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/flower?s=json").toExchange();
|
MockServerHttpRequest request = MockServerHttpRequest.get("/flower?s=json").build();
|
||||||
List<MediaType> mediaTypes = resolver.resolveMediaTypes(exchange);
|
List<MediaType> mediaTypes = resolver.resolveMediaTypes(MockServerWebExchange.from(request));
|
||||||
|
|
||||||
assertEquals(Collections.singletonList(MediaType.APPLICATION_JSON), mediaTypes);
|
assertEquals(Collections.singletonList(MediaType.APPLICATION_JSON), mediaTypes);
|
||||||
}
|
}
|
||||||
|
@ -75,8 +77,8 @@ public class RequestedContentTypeResolverBuilderTests {
|
||||||
builder.fixedResolver(MediaType.APPLICATION_JSON);
|
builder.fixedResolver(MediaType.APPLICATION_JSON);
|
||||||
RequestedContentTypeResolver resolver = builder.build();
|
RequestedContentTypeResolver resolver = builder.build();
|
||||||
|
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/").accept(MediaType.ALL).toExchange();
|
MockServerHttpRequest request = MockServerHttpRequest.get("/").accept(MediaType.ALL).build();
|
||||||
List<MediaType> mediaTypes = resolver.resolveMediaTypes(exchange);
|
List<MediaType> mediaTypes = resolver.resolveMediaTypes(MockServerWebExchange.from(request));
|
||||||
|
|
||||||
assertEquals(Collections.singletonList(MediaType.APPLICATION_JSON), mediaTypes);
|
assertEquals(Collections.singletonList(MediaType.APPLICATION_JSON), mediaTypes);
|
||||||
}
|
}
|
||||||
|
@ -88,11 +90,11 @@ public class RequestedContentTypeResolverBuilderTests {
|
||||||
builder.resolver(new FixedContentTypeResolver(MediaType.APPLICATION_JSON));
|
builder.resolver(new FixedContentTypeResolver(MediaType.APPLICATION_JSON));
|
||||||
RequestedContentTypeResolver resolver = builder.build();
|
RequestedContentTypeResolver resolver = builder.build();
|
||||||
|
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||||
List<MediaType> mediaTypes = resolver.resolveMediaTypes(exchange);
|
List<MediaType> mediaTypes = resolver.resolveMediaTypes(exchange);
|
||||||
assertEquals(Collections.singletonList(MediaType.APPLICATION_JSON), mediaTypes);
|
assertEquals(Collections.singletonList(MediaType.APPLICATION_JSON), mediaTypes);
|
||||||
|
|
||||||
exchange = MockServerHttpRequest.get("/").accept(MediaType.ALL).toExchange();
|
exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").accept(MediaType.ALL).build());
|
||||||
mediaTypes = resolver.resolveMediaTypes(exchange);
|
mediaTypes = resolver.resolveMediaTypes(exchange);
|
||||||
assertEquals(Collections.singletonList(MediaType.APPLICATION_JSON), mediaTypes);
|
assertEquals(Collections.singletonList(MediaType.APPLICATION_JSON), mediaTypes);
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ import org.springframework.core.io.buffer.support.DataBufferTestUtils;
|
||||||
import org.springframework.http.CacheControl;
|
import org.springframework.http.CacheControl;
|
||||||
import org.springframework.http.server.PathContainer;
|
import org.springframework.http.server.PathContainer;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerWebExchange;
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.web.reactive.HandlerMapping;
|
import org.springframework.web.reactive.HandlerMapping;
|
||||||
import org.springframework.web.reactive.handler.SimpleUrlHandlerMapping;
|
import org.springframework.web.reactive.handler.SimpleUrlHandlerMapping;
|
||||||
import org.springframework.web.reactive.resource.AppCacheManifestTransformer;
|
import org.springframework.web.reactive.resource.AppCacheManifestTransformer;
|
||||||
|
@ -81,7 +81,7 @@ public class ResourceHandlerRegistryTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void mapPathToLocation() throws Exception {
|
public void mapPathToLocation() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("").build());
|
||||||
exchange.getAttributes().put(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE,
|
exchange.getAttributes().put(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE,
|
||||||
PathContainer.parsePath("/testStylesheet.css"));
|
PathContainer.parsePath("/testStylesheet.css"));
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,7 @@ import org.springframework.http.codec.ServerCodecConfigurer;
|
||||||
import org.springframework.http.codec.json.Jackson2JsonEncoder;
|
import org.springframework.http.codec.json.Jackson2JsonEncoder;
|
||||||
import org.springframework.http.codec.xml.Jaxb2XmlDecoder;
|
import org.springframework.http.codec.xml.Jaxb2XmlDecoder;
|
||||||
import org.springframework.http.codec.xml.Jaxb2XmlEncoder;
|
import org.springframework.http.codec.xml.Jaxb2XmlEncoder;
|
||||||
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.util.MimeType;
|
import org.springframework.util.MimeType;
|
||||||
import org.springframework.util.MimeTypeUtils;
|
import org.springframework.util.MimeTypeUtils;
|
||||||
import org.springframework.util.MultiValueMap;
|
import org.springframework.util.MultiValueMap;
|
||||||
|
@ -104,7 +105,7 @@ public class WebFluxConfigurationSupportTests {
|
||||||
RequestedContentTypeResolver resolver = context.getBean(name, RequestedContentTypeResolver.class);
|
RequestedContentTypeResolver resolver = context.getBean(name, RequestedContentTypeResolver.class);
|
||||||
assertSame(resolver, mapping.getContentTypeResolver());
|
assertSame(resolver, mapping.getContentTypeResolver());
|
||||||
|
|
||||||
ServerWebExchange exchange = get("/path").accept(MediaType.APPLICATION_JSON).toExchange();
|
ServerWebExchange exchange = MockServerWebExchange.from(get("/path").accept(MediaType.APPLICATION_JSON).build());
|
||||||
assertEquals(Collections.singletonList(MediaType.APPLICATION_JSON), resolver.resolveMediaTypes(exchange));
|
assertEquals(Collections.singletonList(MediaType.APPLICATION_JSON), resolver.resolveMediaTypes(exchange));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ import org.springframework.http.codec.EncoderHttpMessageWriter;
|
||||||
import org.springframework.http.codec.HttpMessageWriter;
|
import org.springframework.http.codec.HttpMessageWriter;
|
||||||
import org.springframework.http.server.reactive.ServerHttpResponse;
|
import org.springframework.http.server.reactive.ServerHttpResponse;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerWebExchange;
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.web.reactive.function.BodyInserter;
|
import org.springframework.web.reactive.function.BodyInserter;
|
||||||
import org.springframework.web.reactive.result.view.ViewResolver;
|
import org.springframework.web.reactive.result.view.ViewResolver;
|
||||||
|
|
||||||
|
@ -191,17 +191,18 @@ public class DefaultEntityResponseBuilderTests {
|
||||||
|
|
||||||
Mono<EntityResponse<Publisher<String>>> result = EntityResponse.fromPublisher(publisher, String.class).build();
|
Mono<EntityResponse<Publisher<String>>> result = EntityResponse.fromPublisher(publisher, String.class).build();
|
||||||
|
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("http://localhost").toExchange();
|
MockServerHttpRequest request = MockServerHttpRequest.get("http://localhost").build();
|
||||||
|
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
|
|
||||||
ServerResponse.Context context = new ServerResponse.Context() {
|
ServerResponse.Context context = new ServerResponse.Context() {
|
||||||
@Override
|
@Override
|
||||||
public List<HttpMessageWriter<?>> messageWriters() {
|
public List<HttpMessageWriter<?>> messageWriters() {
|
||||||
return Collections.<HttpMessageWriter<?>>singletonList(new EncoderHttpMessageWriter<>(CharSequenceEncoder.allMimeTypes()));
|
return Collections.singletonList(new EncoderHttpMessageWriter<>(CharSequenceEncoder.allMimeTypes()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ViewResolver> viewResolvers() {
|
public List<ViewResolver> viewResolvers() {
|
||||||
return Collections.<ViewResolver>emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
StepVerifier.create(result)
|
StepVerifier.create(result)
|
||||||
|
|
|
@ -29,7 +29,7 @@ import reactor.test.StepVerifier;
|
||||||
|
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerWebExchange;
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.web.reactive.result.view.View;
|
import org.springframework.web.reactive.result.view.View;
|
||||||
import org.springframework.web.reactive.result.view.ViewResolver;
|
import org.springframework.web.reactive.result.view.ViewResolver;
|
||||||
|
|
||||||
|
@ -108,7 +108,8 @@ public class DefaultRenderingResponseTests {
|
||||||
Map<String, Object> model = Collections.singletonMap("foo", "bar");
|
Map<String, Object> model = Collections.singletonMap("foo", "bar");
|
||||||
Mono<RenderingResponse> result = RenderingResponse.create("view").modelAttributes(model).build();
|
Mono<RenderingResponse> result = RenderingResponse.create("view").modelAttributes(model).build();
|
||||||
|
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("http://localhost").toExchange();
|
MockServerHttpRequest build = MockServerHttpRequest.get("http://localhost").build();
|
||||||
|
MockServerWebExchange exchange = MockServerWebExchange.from(build);
|
||||||
ViewResolver viewResolver = mock(ViewResolver.class);
|
ViewResolver viewResolver = mock(ViewResolver.class);
|
||||||
View view = mock(View.class);
|
View view = mock(View.class);
|
||||||
when(viewResolver.resolveViewName("view", Locale.ENGLISH)).thenReturn(Mono.just(view));
|
when(viewResolver.resolveViewName("view", Locale.ENGLISH)).thenReturn(Mono.just(view));
|
||||||
|
|
|
@ -46,12 +46,12 @@ import org.springframework.http.MediaType;
|
||||||
import org.springframework.http.codec.DecoderHttpMessageReader;
|
import org.springframework.http.codec.DecoderHttpMessageReader;
|
||||||
import org.springframework.http.codec.HttpMessageReader;
|
import org.springframework.http.codec.HttpMessageReader;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerWebExchange;
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.util.LinkedMultiValueMap;
|
import org.springframework.util.LinkedMultiValueMap;
|
||||||
import org.springframework.util.MultiValueMap;
|
import org.springframework.util.MultiValueMap;
|
||||||
import org.springframework.web.server.UnsupportedMediaTypeStatusException;
|
import org.springframework.web.server.UnsupportedMediaTypeStatusException;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.springframework.web.reactive.function.BodyExtractors.toMono;
|
import static org.springframework.web.reactive.function.BodyExtractors.toMono;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -72,7 +72,7 @@ public class DefaultServerRequestTests {
|
||||||
public void method() throws Exception {
|
public void method() throws Exception {
|
||||||
HttpMethod method = HttpMethod.HEAD;
|
HttpMethod method = HttpMethod.HEAD;
|
||||||
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(method, "http://example.com").build();
|
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(method, "http://example.com").build();
|
||||||
DefaultServerRequest request = new DefaultServerRequest(mockRequest.toExchange(), messageReaders);
|
DefaultServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), messageReaders);
|
||||||
|
|
||||||
assertEquals(method, request.method());
|
assertEquals(method, request.method());
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ public class DefaultServerRequestTests {
|
||||||
URI uri = URI.create("https://example.com");
|
URI uri = URI.create("https://example.com");
|
||||||
|
|
||||||
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.GET, uri).build();
|
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.GET, uri).build();
|
||||||
DefaultServerRequest request = new DefaultServerRequest(mockRequest.toExchange(), messageReaders);
|
DefaultServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), messageReaders);
|
||||||
|
|
||||||
assertEquals(uri, request.uri());
|
assertEquals(uri, request.uri());
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,7 @@ public class DefaultServerRequestTests {
|
||||||
public void uriBuilder() throws Exception {
|
public void uriBuilder() throws Exception {
|
||||||
URI uri = new URI("http", "localhost", "/path", "a=1", null);
|
URI uri = new URI("http", "localhost", "/path", "a=1", null);
|
||||||
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.GET, uri).build();
|
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.GET, uri).build();
|
||||||
DefaultServerRequest request = new DefaultServerRequest(mockRequest.toExchange(), messageReaders);
|
DefaultServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), messageReaders);
|
||||||
|
|
||||||
|
|
||||||
URI result = request.uriBuilder().build();
|
URI result = request.uriBuilder().build();
|
||||||
|
@ -105,7 +105,7 @@ public class DefaultServerRequestTests {
|
||||||
@Test
|
@Test
|
||||||
public void attribute() throws Exception {
|
public void attribute() throws Exception {
|
||||||
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.GET, "http://example.com").build();
|
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.GET, "http://example.com").build();
|
||||||
MockServerWebExchange exchange = new MockServerWebExchange(mockRequest);
|
MockServerWebExchange exchange = MockServerWebExchange.from(mockRequest);
|
||||||
exchange.getAttributes().put("foo", "bar");
|
exchange.getAttributes().put("foo", "bar");
|
||||||
|
|
||||||
DefaultServerRequest request = new DefaultServerRequest(exchange, messageReaders);
|
DefaultServerRequest request = new DefaultServerRequest(exchange, messageReaders);
|
||||||
|
@ -116,7 +116,7 @@ public class DefaultServerRequestTests {
|
||||||
@Test
|
@Test
|
||||||
public void queryParams() throws Exception {
|
public void queryParams() throws Exception {
|
||||||
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.GET, "http://example.com?foo=bar").build();
|
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.GET, "http://example.com?foo=bar").build();
|
||||||
DefaultServerRequest request = new DefaultServerRequest(mockRequest.toExchange(), messageReaders);
|
DefaultServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), messageReaders);
|
||||||
|
|
||||||
assertEquals(Optional.of("bar"), request.queryParam("foo"));
|
assertEquals(Optional.of("bar"), request.queryParam("foo"));
|
||||||
}
|
}
|
||||||
|
@ -124,7 +124,7 @@ public class DefaultServerRequestTests {
|
||||||
@Test
|
@Test
|
||||||
public void emptyQueryParam() throws Exception {
|
public void emptyQueryParam() throws Exception {
|
||||||
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.GET, "http://example.com?foo").build();
|
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.GET, "http://example.com?foo").build();
|
||||||
DefaultServerRequest request = new DefaultServerRequest(mockRequest.toExchange(), messageReaders);
|
DefaultServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), messageReaders);
|
||||||
|
|
||||||
assertEquals(Optional.of(""), request.queryParam("foo"));
|
assertEquals(Optional.of(""), request.queryParam("foo"));
|
||||||
}
|
}
|
||||||
|
@ -132,7 +132,7 @@ public class DefaultServerRequestTests {
|
||||||
@Test
|
@Test
|
||||||
public void absentQueryParam() throws Exception {
|
public void absentQueryParam() throws Exception {
|
||||||
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.GET, "http://example.com?foo").build();
|
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.GET, "http://example.com?foo").build();
|
||||||
DefaultServerRequest request = new DefaultServerRequest(mockRequest.toExchange(), messageReaders);
|
DefaultServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), messageReaders);
|
||||||
|
|
||||||
assertEquals(Optional.empty(), request.queryParam("bar"));
|
assertEquals(Optional.empty(), request.queryParam("bar"));
|
||||||
}
|
}
|
||||||
|
@ -140,7 +140,7 @@ public class DefaultServerRequestTests {
|
||||||
@Test
|
@Test
|
||||||
public void pathVariable() throws Exception {
|
public void pathVariable() throws Exception {
|
||||||
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.GET, "http://example.com").build();
|
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.GET, "http://example.com").build();
|
||||||
MockServerWebExchange exchange = new MockServerWebExchange(mockRequest);
|
MockServerWebExchange exchange = MockServerWebExchange.from(mockRequest);
|
||||||
Map<String, String> pathVariables = Collections.singletonMap("foo", "bar");
|
Map<String, String> pathVariables = Collections.singletonMap("foo", "bar");
|
||||||
exchange.getAttributes().put(RouterFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE, pathVariables);
|
exchange.getAttributes().put(RouterFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE, pathVariables);
|
||||||
|
|
||||||
|
@ -153,7 +153,7 @@ public class DefaultServerRequestTests {
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void pathVariableNotFound() throws Exception {
|
public void pathVariableNotFound() throws Exception {
|
||||||
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.GET, "http://example.com").build();
|
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.GET, "http://example.com").build();
|
||||||
MockServerWebExchange exchange = new MockServerWebExchange(mockRequest);
|
MockServerWebExchange exchange = MockServerWebExchange.from(mockRequest);
|
||||||
Map<String, String> pathVariables = Collections.singletonMap("foo", "bar");
|
Map<String, String> pathVariables = Collections.singletonMap("foo", "bar");
|
||||||
exchange.getAttributes().put(RouterFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE, pathVariables);
|
exchange.getAttributes().put(RouterFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE, pathVariables);
|
||||||
|
|
||||||
|
@ -165,7 +165,7 @@ public class DefaultServerRequestTests {
|
||||||
@Test
|
@Test
|
||||||
public void pathVariables() throws Exception {
|
public void pathVariables() throws Exception {
|
||||||
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.GET, "http://example.com").build();
|
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.GET, "http://example.com").build();
|
||||||
MockServerWebExchange exchange = new MockServerWebExchange(mockRequest);
|
MockServerWebExchange exchange = MockServerWebExchange.from(mockRequest);
|
||||||
Map<String, String> pathVariables = Collections.singletonMap("foo", "bar");
|
Map<String, String> pathVariables = Collections.singletonMap("foo", "bar");
|
||||||
exchange.getAttributes().put(RouterFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE, pathVariables);
|
exchange.getAttributes().put(RouterFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE, pathVariables);
|
||||||
|
|
||||||
|
@ -193,7 +193,7 @@ public class DefaultServerRequestTests {
|
||||||
|
|
||||||
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.GET, "http://example.com?foo=bar").
|
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.GET, "http://example.com?foo=bar").
|
||||||
headers(httpHeaders).build();
|
headers(httpHeaders).build();
|
||||||
DefaultServerRequest request = new DefaultServerRequest(mockRequest.toExchange(), messageReaders);
|
DefaultServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), messageReaders);
|
||||||
|
|
||||||
ServerRequest.Headers headers = request.headers();
|
ServerRequest.Headers headers = request.headers();
|
||||||
assertEquals(accept, headers.accept());
|
assertEquals(accept, headers.accept());
|
||||||
|
@ -208,7 +208,7 @@ public class DefaultServerRequestTests {
|
||||||
HttpCookie cookie = new HttpCookie("foo", "bar");
|
HttpCookie cookie = new HttpCookie("foo", "bar");
|
||||||
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.GET, "http://example.com").
|
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.GET, "http://example.com").
|
||||||
cookie(cookie).build();
|
cookie(cookie).build();
|
||||||
MockServerWebExchange exchange = new MockServerWebExchange(mockRequest);
|
MockServerWebExchange exchange = MockServerWebExchange.from(mockRequest);
|
||||||
|
|
||||||
DefaultServerRequest request = new DefaultServerRequest(exchange, messageReaders);
|
DefaultServerRequest request = new DefaultServerRequest(exchange, messageReaders);
|
||||||
|
|
||||||
|
@ -231,7 +231,7 @@ public class DefaultServerRequestTests {
|
||||||
|
|
||||||
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.GET, "http://example.com?foo=bar").
|
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.GET, "http://example.com?foo=bar").
|
||||||
headers(httpHeaders).body(body);
|
headers(httpHeaders).body(body);
|
||||||
DefaultServerRequest request = new DefaultServerRequest(mockRequest.toExchange(), messageReaders);
|
DefaultServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), messageReaders);
|
||||||
|
|
||||||
Mono<String> resultMono = request.body(toMono(String.class));
|
Mono<String> resultMono = request.body(toMono(String.class));
|
||||||
assertEquals("foo", resultMono.block());
|
assertEquals("foo", resultMono.block());
|
||||||
|
@ -248,7 +248,7 @@ public class DefaultServerRequestTests {
|
||||||
httpHeaders.setContentType(MediaType.TEXT_PLAIN);
|
httpHeaders.setContentType(MediaType.TEXT_PLAIN);
|
||||||
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.GET, "http://example.com?foo=bar").
|
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.GET, "http://example.com?foo=bar").
|
||||||
headers(httpHeaders).body(body);
|
headers(httpHeaders).body(body);
|
||||||
DefaultServerRequest request = new DefaultServerRequest(mockRequest.toExchange(), messageReaders);
|
DefaultServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), messageReaders);
|
||||||
|
|
||||||
Mono<String> resultMono = request.bodyToMono(String.class);
|
Mono<String> resultMono = request.bodyToMono(String.class);
|
||||||
assertEquals("foo", resultMono.block());
|
assertEquals("foo", resultMono.block());
|
||||||
|
@ -265,7 +265,7 @@ public class DefaultServerRequestTests {
|
||||||
httpHeaders.setContentType(MediaType.TEXT_PLAIN);
|
httpHeaders.setContentType(MediaType.TEXT_PLAIN);
|
||||||
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.GET, "http://example.com?foo=bar").
|
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.GET, "http://example.com?foo=bar").
|
||||||
headers(httpHeaders).body(body);
|
headers(httpHeaders).body(body);
|
||||||
DefaultServerRequest request = new DefaultServerRequest(mockRequest.toExchange(), messageReaders);
|
DefaultServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), messageReaders);
|
||||||
|
|
||||||
ParameterizedTypeReference<String> typeReference = new ParameterizedTypeReference<String>() {};
|
ParameterizedTypeReference<String> typeReference = new ParameterizedTypeReference<String>() {};
|
||||||
Mono<String> resultMono = request.bodyToMono(typeReference);
|
Mono<String> resultMono = request.bodyToMono(typeReference);
|
||||||
|
@ -283,7 +283,7 @@ public class DefaultServerRequestTests {
|
||||||
httpHeaders.setContentType(MediaType.TEXT_PLAIN);
|
httpHeaders.setContentType(MediaType.TEXT_PLAIN);
|
||||||
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.GET, "http://example.com?foo=bar").
|
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.GET, "http://example.com?foo=bar").
|
||||||
headers(httpHeaders).body(body);
|
headers(httpHeaders).body(body);
|
||||||
DefaultServerRequest request = new DefaultServerRequest(mockRequest.toExchange(), messageReaders);
|
DefaultServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), messageReaders);
|
||||||
|
|
||||||
Flux<String> resultFlux = request.bodyToFlux(String.class);
|
Flux<String> resultFlux = request.bodyToFlux(String.class);
|
||||||
assertEquals(Collections.singletonList("foo"), resultFlux.collectList().block());
|
assertEquals(Collections.singletonList("foo"), resultFlux.collectList().block());
|
||||||
|
@ -300,7 +300,7 @@ public class DefaultServerRequestTests {
|
||||||
httpHeaders.setContentType(MediaType.TEXT_PLAIN);
|
httpHeaders.setContentType(MediaType.TEXT_PLAIN);
|
||||||
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.GET, "http://example.com?foo=bar").
|
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.GET, "http://example.com?foo=bar").
|
||||||
headers(httpHeaders).body(body);
|
headers(httpHeaders).body(body);
|
||||||
DefaultServerRequest request = new DefaultServerRequest(mockRequest.toExchange(), messageReaders);
|
DefaultServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), messageReaders);
|
||||||
|
|
||||||
ParameterizedTypeReference<String> typeReference = new ParameterizedTypeReference<String>() {};
|
ParameterizedTypeReference<String> typeReference = new ParameterizedTypeReference<String>() {};
|
||||||
Flux<String> resultFlux = request.bodyToFlux(typeReference);
|
Flux<String> resultFlux = request.bodyToFlux(typeReference);
|
||||||
|
@ -319,7 +319,7 @@ public class DefaultServerRequestTests {
|
||||||
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.GET, "http://example.com?foo=bar").
|
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.GET, "http://example.com?foo=bar").
|
||||||
headers(httpHeaders).body(body);
|
headers(httpHeaders).body(body);
|
||||||
this.messageReaders = Collections.emptyList();
|
this.messageReaders = Collections.emptyList();
|
||||||
DefaultServerRequest request = new DefaultServerRequest(mockRequest.toExchange(), messageReaders);
|
DefaultServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), messageReaders);
|
||||||
|
|
||||||
Flux<String> resultFlux = request.bodyToFlux(String.class);
|
Flux<String> resultFlux = request.bodyToFlux(String.class);
|
||||||
StepVerifier.create(resultFlux)
|
StepVerifier.create(resultFlux)
|
||||||
|
|
|
@ -34,10 +34,12 @@ import org.springframework.http.MediaType;
|
||||||
import org.springframework.http.codec.HttpMessageWriter;
|
import org.springframework.http.codec.HttpMessageWriter;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerWebExchange;
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.web.reactive.result.view.ViewResolver;
|
import org.springframework.web.reactive.result.view.ViewResolver;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
|
@ -71,7 +73,7 @@ public class ResourceHandlerFunctionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void get() throws IOException {
|
public void get() throws IOException {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("http://localhost").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("http://localhost").build());
|
||||||
MockServerHttpResponse mockResponse = exchange.getResponse();
|
MockServerHttpResponse mockResponse = exchange.getResponse();
|
||||||
|
|
||||||
ServerRequest request = new DefaultServerRequest(exchange, HandlerStrategies.withDefaults().messageReaders());
|
ServerRequest request = new DefaultServerRequest(exchange, HandlerStrategies.withDefaults().messageReaders());
|
||||||
|
@ -107,7 +109,7 @@ public class ResourceHandlerFunctionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void head() throws IOException {
|
public void head() throws IOException {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.head("http://localhost").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.head("http://localhost").build());
|
||||||
MockServerHttpResponse mockResponse = exchange.getResponse();
|
MockServerHttpResponse mockResponse = exchange.getResponse();
|
||||||
|
|
||||||
ServerRequest request = new DefaultServerRequest(exchange, HandlerStrategies.withDefaults().messageReaders());
|
ServerRequest request = new DefaultServerRequest(exchange, HandlerStrategies.withDefaults().messageReaders());
|
||||||
|
@ -132,7 +134,7 @@ public class ResourceHandlerFunctionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void options() {
|
public void options() {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.options("http://localhost").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.options("http://localhost").build());
|
||||||
MockServerHttpResponse mockResponse = exchange.getResponse();
|
MockServerHttpResponse mockResponse = exchange.getResponse();
|
||||||
|
|
||||||
ServerRequest request = new DefaultServerRequest(exchange, HandlerStrategies.withDefaults().messageReaders());
|
ServerRequest request = new DefaultServerRequest(exchange, HandlerStrategies.withDefaults().messageReaders());
|
||||||
|
|
|
@ -30,7 +30,7 @@ import org.springframework.http.codec.DecoderHttpMessageReader;
|
||||||
import org.springframework.http.codec.HttpMessageReader;
|
import org.springframework.http.codec.HttpMessageReader;
|
||||||
import org.springframework.http.codec.ServerCodecConfigurer;
|
import org.springframework.http.codec.ServerCodecConfigurer;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerWebExchange;
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.web.reactive.config.EnableWebFlux;
|
import org.springframework.web.reactive.config.EnableWebFlux;
|
||||||
import org.springframework.web.reactive.function.server.HandlerFunction;
|
import org.springframework.web.reactive.function.server.HandlerFunction;
|
||||||
import org.springframework.web.reactive.function.server.RequestPredicates;
|
import org.springframework.web.reactive.function.server.RequestPredicates;
|
||||||
|
@ -53,9 +53,8 @@ public class RouterFunctionMappingTests {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
this.messageReaders =
|
this.messageReaders = Collections.singletonList(new DecoderHttpMessageReader<>(new ByteBufferDecoder()));
|
||||||
Collections.singletonList(new DecoderHttpMessageReader<>(new ByteBufferDecoder()));
|
this.exchange = MockServerWebExchange.from(MockServerHttpRequest.get("http://example.com/match").build());
|
||||||
this.exchange = new MockServerWebExchange(MockServerHttpRequest.get("http://example.com/match").build());
|
|
||||||
codecConfigurer = ServerCodecConfigurer.create();
|
codecConfigurer = ServerCodecConfigurer.create();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ import org.junit.Test;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.HttpMethod;
|
import org.springframework.http.HttpMethod;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.web.cors.CorsConfiguration;
|
import org.springframework.web.cors.CorsConfiguration;
|
||||||
import org.springframework.web.cors.reactive.CorsConfigurationSource;
|
import org.springframework.web.cors.reactive.CorsConfigurationSource;
|
||||||
import org.springframework.web.server.ServerWebExchange;
|
import org.springframework.web.server.ServerWebExchange;
|
||||||
|
@ -132,11 +133,11 @@ public class CorsUrlHandlerMappingTests {
|
||||||
|
|
||||||
private ServerWebExchange createExchange(HttpMethod method, String path, String origin) {
|
private ServerWebExchange createExchange(HttpMethod method, String path, String origin) {
|
||||||
|
|
||||||
return MockServerHttpRequest
|
return MockServerWebExchange.from(MockServerHttpRequest
|
||||||
.method(method, "http://localhost" + path)
|
.method(method, "http://localhost" + path)
|
||||||
.header("Origin", origin)
|
.header("Origin", origin)
|
||||||
.header(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET")
|
.header(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET")
|
||||||
.toExchange();
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
import org.springframework.http.HttpMethod;
|
import org.springframework.http.HttpMethod;
|
||||||
import org.springframework.http.server.PathContainer;
|
import org.springframework.http.server.PathContainer;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.web.reactive.HandlerMapping;
|
import org.springframework.web.reactive.HandlerMapping;
|
||||||
import org.springframework.web.server.ServerWebExchange;
|
import org.springframework.web.server.ServerWebExchange;
|
||||||
|
|
||||||
|
@ -98,7 +99,8 @@ public class SimpleUrlHandlerMappingTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void testUrl(String url, Object bean, HandlerMapping handlerMapping, String pathWithinMapping) {
|
private void testUrl(String url, Object bean, HandlerMapping handlerMapping, String pathWithinMapping) {
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.method(HttpMethod.GET, URI.create(url)).toExchange();
|
MockServerHttpRequest request = MockServerHttpRequest.method(HttpMethod.GET, URI.create(url)).build();
|
||||||
|
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
Object actual = handlerMapping.getHandler(exchange).block();
|
Object actual = handlerMapping.getHandler(exchange).block();
|
||||||
if (bean != null) {
|
if (bean != null) {
|
||||||
assertNotNull(actual);
|
assertNotNull(actual);
|
||||||
|
|
|
@ -30,8 +30,8 @@ import reactor.core.publisher.Mono;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.ClassPathResource;
|
||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.util.FileCopyUtils;
|
import org.springframework.util.FileCopyUtils;
|
||||||
import org.springframework.web.server.ServerWebExchange;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.Assert.assertThat;
|
||||||
|
@ -79,7 +79,8 @@ public class AppCacheManifestTransformerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void noTransformIfExtensionNoMatch() throws Exception {
|
public void noTransformIfExtensionNoMatch() throws Exception {
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/static/foobar.file").toExchange();
|
MockServerHttpRequest request = MockServerHttpRequest.get("/static/foobar.file").build();
|
||||||
|
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
this.chain = mock(ResourceTransformerChain.class);
|
this.chain = mock(ResourceTransformerChain.class);
|
||||||
Resource resource = mock(Resource.class);
|
Resource resource = mock(Resource.class);
|
||||||
given(resource.getFilename()).willReturn("foobar.file");
|
given(resource.getFilename()).willReturn("foobar.file");
|
||||||
|
@ -91,7 +92,8 @@ public class AppCacheManifestTransformerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void syntaxErrorInManifest() throws Exception {
|
public void syntaxErrorInManifest() throws Exception {
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/static/error.appcache").toExchange();
|
MockServerHttpRequest request = MockServerHttpRequest.get("/static/error.appcache").build();
|
||||||
|
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
this.chain = mock(ResourceTransformerChain.class);
|
this.chain = mock(ResourceTransformerChain.class);
|
||||||
Resource resource = new ClassPathResource("test/error.appcache", getClass());
|
Resource resource = new ClassPathResource("test/error.appcache", getClass());
|
||||||
given(this.chain.transform(exchange, resource)).willReturn(Mono.just(resource));
|
given(this.chain.transform(exchange, resource)).willReturn(Mono.just(resource));
|
||||||
|
@ -102,7 +104,8 @@ public class AppCacheManifestTransformerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void transformManifest() throws Exception {
|
public void transformManifest() throws Exception {
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/static/test.appcache").toExchange();
|
MockServerHttpRequest request = MockServerHttpRequest.get("/static/test.appcache").build();
|
||||||
|
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
VersionResourceResolver versionResolver = new VersionResourceResolver();
|
VersionResourceResolver versionResolver = new VersionResourceResolver();
|
||||||
versionResolver.setStrategyMap(Collections.singletonMap("/**", new ContentVersionStrategy()));
|
versionResolver.setStrategyMap(Collections.singletonMap("/**", new ContentVersionStrategy()));
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ import org.springframework.cache.concurrent.ConcurrentMapCache;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.ClassPathResource;
|
||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerWebExchange;
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
|
@ -71,7 +71,7 @@ public class CachingResourceResolverTests {
|
||||||
public void resolveResourceInternal() {
|
public void resolveResourceInternal() {
|
||||||
String file = "bar.css";
|
String file = "bar.css";
|
||||||
Resource expected = new ClassPathResource("test/" + file, getClass());
|
Resource expected = new ClassPathResource("test/" + file, getClass());
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("").build());
|
||||||
Resource actual = this.chain.resolveResource(exchange, file, this.locations).block(TIMEOUT);
|
Resource actual = this.chain.resolveResource(exchange, file, this.locations).block(TIMEOUT);
|
||||||
|
|
||||||
assertEquals(expected, actual);
|
assertEquals(expected, actual);
|
||||||
|
@ -84,7 +84,7 @@ public class CachingResourceResolverTests {
|
||||||
this.cache.put(CachingResourceResolver.RESOLVED_RESOURCE_CACHE_KEY_PREFIX + "bar.css", expected);
|
this.cache.put(CachingResourceResolver.RESOLVED_RESOURCE_CACHE_KEY_PREFIX + "bar.css", expected);
|
||||||
|
|
||||||
String file = "bar.css";
|
String file = "bar.css";
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("").build());
|
||||||
Resource actual = this.chain.resolveResource(exchange, file, this.locations).block(TIMEOUT);
|
Resource actual = this.chain.resolveResource(exchange, file, this.locations).block(TIMEOUT);
|
||||||
|
|
||||||
assertSame(expected, actual);
|
assertSame(expected, actual);
|
||||||
|
@ -92,7 +92,7 @@ public class CachingResourceResolverTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveResourceInternalNoMatch() {
|
public void resolveResourceInternalNoMatch() {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("").build());
|
||||||
assertNull(this.chain.resolveResource(exchange, "invalid.css", this.locations).block(TIMEOUT));
|
assertNull(this.chain.resolveResource(exchange, "invalid.css", this.locations).block(TIMEOUT));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,8 +121,8 @@ public class CachingResourceResolverTests {
|
||||||
@Test
|
@Test
|
||||||
public void resolveResourceAcceptEncodingInCacheKey() {
|
public void resolveResourceAcceptEncodingInCacheKey() {
|
||||||
String file = "bar.css";
|
String file = "bar.css";
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get(file)
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get(file)
|
||||||
.header("Accept-Encoding", "gzip").toExchange();
|
.header("Accept-Encoding", "gzip").build());
|
||||||
|
|
||||||
Resource expected = this.chain.resolveResource(exchange, file, this.locations).block(TIMEOUT);
|
Resource expected = this.chain.resolveResource(exchange, file, this.locations).block(TIMEOUT);
|
||||||
String cacheKey = CachingResourceResolver.RESOLVED_RESOURCE_CACHE_KEY_PREFIX + file + "+encoding=gzip";
|
String cacheKey = CachingResourceResolver.RESOLVED_RESOURCE_CACHE_KEY_PREFIX + file + "+encoding=gzip";
|
||||||
|
@ -133,7 +133,7 @@ public class CachingResourceResolverTests {
|
||||||
@Test
|
@Test
|
||||||
public void resolveResourceNoAcceptEncodingInCacheKey() {
|
public void resolveResourceNoAcceptEncodingInCacheKey() {
|
||||||
String file = "bar.css";
|
String file = "bar.css";
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get(file).toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get(file).build());
|
||||||
|
|
||||||
Resource expected = this.chain.resolveResource(exchange, file, this.locations).block(TIMEOUT);
|
Resource expected = this.chain.resolveResource(exchange, file, this.locations).block(TIMEOUT);
|
||||||
String cacheKey = CachingResourceResolver.RESOLVED_RESOURCE_CACHE_KEY_PREFIX + file;
|
String cacheKey = CachingResourceResolver.RESOLVED_RESOURCE_CACHE_KEY_PREFIX + file;
|
||||||
|
@ -149,10 +149,11 @@ public class CachingResourceResolverTests {
|
||||||
this.cache.put(CachingResourceResolver.RESOLVED_RESOURCE_CACHE_KEY_PREFIX + "bar.css+encoding=gzip", gzResource);
|
this.cache.put(CachingResourceResolver.RESOLVED_RESOURCE_CACHE_KEY_PREFIX + "bar.css+encoding=gzip", gzResource);
|
||||||
|
|
||||||
String file = "bar.css";
|
String file = "bar.css";
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get(file).toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get(file).build());
|
||||||
assertSame(resource, this.chain.resolveResource(exchange, file, this.locations).block(TIMEOUT));
|
assertSame(resource, this.chain.resolveResource(exchange, file, this.locations).block(TIMEOUT));
|
||||||
|
|
||||||
exchange = MockServerHttpRequest.get(file).header("Accept-Encoding", "gzip").toExchange();
|
MockServerHttpRequest request = MockServerHttpRequest.get(file).header("Accept-Encoding", "gzip").build();
|
||||||
|
exchange = MockServerWebExchange.from(request);
|
||||||
assertSame(gzResource, this.chain.resolveResource(exchange, file, this.locations).block(TIMEOUT));
|
assertSame(gzResource, this.chain.resolveResource(exchange, file, this.locations).block(TIMEOUT));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ import reactor.test.StepVerifier;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.ClassPathResource;
|
||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerWebExchange;
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
@ -76,7 +76,8 @@ public class CssLinkResourceTransformerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void transform() throws Exception {
|
public void transform() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("/static/main.css").toExchange();
|
MockServerHttpRequest request = MockServerHttpRequest.get("/static/main.css").build();
|
||||||
|
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
Resource css = new ClassPathResource("test/main.css", getClass());
|
Resource css = new ClassPathResource("test/main.css", getClass());
|
||||||
|
|
||||||
String expected = "\n" +
|
String expected = "\n" +
|
||||||
|
@ -98,7 +99,7 @@ public class CssLinkResourceTransformerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void transformNoLinks() throws Exception {
|
public void transformNoLinks() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("/static/foo.css").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/static/foo.css").build());
|
||||||
Resource expected = new ClassPathResource("test/foo.css", getClass());
|
Resource expected = new ClassPathResource("test/foo.css", getClass());
|
||||||
StepVerifier.create(this.transformerChain.transform(exchange, expected))
|
StepVerifier.create(this.transformerChain.transform(exchange, expected))
|
||||||
.consumeNextWith(resource -> assertSame(expected, resource))
|
.consumeNextWith(resource -> assertSame(expected, resource))
|
||||||
|
@ -107,7 +108,7 @@ public class CssLinkResourceTransformerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void transformExtLinksNotAllowed() throws Exception {
|
public void transformExtLinksNotAllowed() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("/static/external.css").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/static/external.css").build());
|
||||||
ResourceResolverChain resolverChain = Mockito.mock(DefaultResourceResolverChain.class);
|
ResourceResolverChain resolverChain = Mockito.mock(DefaultResourceResolverChain.class);
|
||||||
ResourceTransformerChain transformerChain = new DefaultResourceTransformerChain(resolverChain,
|
ResourceTransformerChain transformerChain = new DefaultResourceTransformerChain(resolverChain,
|
||||||
Collections.singletonList(new CssLinkResourceTransformer()));
|
Collections.singletonList(new CssLinkResourceTransformer()));
|
||||||
|
@ -133,7 +134,7 @@ public class CssLinkResourceTransformerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void transformWithNonCssResource() throws Exception {
|
public void transformWithNonCssResource() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("/static/images/image.png").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/static/images/image.png").build());
|
||||||
Resource expected = new ClassPathResource("test/images/image.png", getClass());
|
Resource expected = new ClassPathResource("test/images/image.png", getClass());
|
||||||
StepVerifier.create(this.transformerChain.transform(exchange, expected))
|
StepVerifier.create(this.transformerChain.transform(exchange, expected))
|
||||||
.expectNext(expected)
|
.expectNext(expected)
|
||||||
|
@ -142,7 +143,7 @@ public class CssLinkResourceTransformerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void transformWithGzippedResource() throws Exception {
|
public void transformWithGzippedResource() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("/static/main.css").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/static/main.css").build());
|
||||||
Resource original = new ClassPathResource("test/main.css", getClass());
|
Resource original = new ClassPathResource("test/main.css", getClass());
|
||||||
createTempCopy("main.css", "main.css.gz");
|
createTempCopy("main.css", "main.css.gz");
|
||||||
GzipResourceResolver.GzippedResource expected = new GzipResourceResolver.GzippedResource(original);
|
GzipResourceResolver.GzippedResource expected = new GzipResourceResolver.GzippedResource(original);
|
||||||
|
|
|
@ -39,7 +39,7 @@ import org.springframework.core.io.ClassPathResource;
|
||||||
import org.springframework.core.io.FileSystemResource;
|
import org.springframework.core.io.FileSystemResource;
|
||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerWebExchange;
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.util.FileCopyUtils;
|
import org.springframework.util.FileCopyUtils;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
@ -104,8 +104,8 @@ public class GzipResourceResolverTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveGzippedFile() throws IOException {
|
public void resolveGzippedFile() throws IOException {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("")
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("")
|
||||||
.header("Accept-Encoding", "gzip").toExchange();
|
.header("Accept-Encoding", "gzip").build());
|
||||||
|
|
||||||
String file = "js/foo.js";
|
String file = "js/foo.js";
|
||||||
Resource resolved = this.resolver.resolveResource(exchange, file, this.locations).block(TIMEOUT);
|
Resource resolved = this.resolver.resolveResource(exchange, file, this.locations).block(TIMEOUT);
|
||||||
|
@ -120,8 +120,8 @@ public class GzipResourceResolverTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveFingerprintedGzippedFile() throws IOException {
|
public void resolveFingerprintedGzippedFile() throws IOException {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("")
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("")
|
||||||
.header("Accept-Encoding", "gzip").toExchange();
|
.header("Accept-Encoding", "gzip").build());
|
||||||
|
|
||||||
String file = "foo-e36d2e05253c6c7085a91522ce43a0b4.css";
|
String file = "foo-e36d2e05253c6c7085a91522ce43a0b4.css";
|
||||||
Resource resolved = this.resolver.resolveResource(exchange, file, this.locations).block(TIMEOUT);
|
Resource resolved = this.resolver.resolveResource(exchange, file, this.locations).block(TIMEOUT);
|
||||||
|
@ -136,8 +136,8 @@ public class GzipResourceResolverTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveFromCacheWithEncodingVariants() throws IOException {
|
public void resolveFromCacheWithEncodingVariants() throws IOException {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("")
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("")
|
||||||
.header("Accept-Encoding", "gzip").toExchange();
|
.header("Accept-Encoding", "gzip").build());
|
||||||
|
|
||||||
String file = "js/foo.js";
|
String file = "js/foo.js";
|
||||||
Resource resolved = this.resolver.resolveResource(exchange, file, this.locations).block(TIMEOUT);
|
Resource resolved = this.resolver.resolveResource(exchange, file, this.locations).block(TIMEOUT);
|
||||||
|
@ -151,7 +151,7 @@ public class GzipResourceResolverTests {
|
||||||
|
|
||||||
// resolved resource is now cached in CachingResourceResolver
|
// resolved resource is now cached in CachingResourceResolver
|
||||||
|
|
||||||
exchange = MockServerHttpRequest.get("/js/foo.js").toExchange();
|
exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/js/foo.js").build());
|
||||||
resolved = this.resolver.resolveResource(exchange, file, this.locations).block(TIMEOUT);
|
resolved = this.resolver.resolveResource(exchange, file, this.locations).block(TIMEOUT);
|
||||||
|
|
||||||
Resource resource = new ClassPathResource("test/"+file, getClass());
|
Resource resource = new ClassPathResource("test/"+file, getClass());
|
||||||
|
|
|
@ -28,7 +28,7 @@ import reactor.core.publisher.Mono;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.ClassPathResource;
|
||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerWebExchange;
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.web.server.ServerWebExchange;
|
import org.springframework.web.server.ServerWebExchange;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
@ -71,7 +71,8 @@ public class ResourceTransformerSupportTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveUrlPath() throws Exception {
|
public void resolveUrlPath() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("/resources/main.css").toExchange();
|
MockServerHttpRequest request = MockServerHttpRequest.get("/resources/main.css").build();
|
||||||
|
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
String resourcePath = "/resources/bar.css";
|
String resourcePath = "/resources/bar.css";
|
||||||
Resource css = new ClassPathResource("test/main.css", getClass());
|
Resource css = new ClassPathResource("test/main.css", getClass());
|
||||||
String actual = this.transformer.resolveUrlPath(
|
String actual = this.transformer.resolveUrlPath(
|
||||||
|
@ -84,7 +85,7 @@ public class ResourceTransformerSupportTests {
|
||||||
@Test
|
@Test
|
||||||
public void resolveUrlPathWithRelativePath() throws Exception {
|
public void resolveUrlPathWithRelativePath() throws Exception {
|
||||||
Resource css = new ClassPathResource("test/main.css", getClass());
|
Resource css = new ClassPathResource("test/main.css", getClass());
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("").build());
|
||||||
String actual = this.transformer.resolveUrlPath(
|
String actual = this.transformer.resolveUrlPath(
|
||||||
"bar.css", exchange, css, this.transformerChain).block(Duration.ofSeconds(5));
|
"bar.css", exchange, css, this.transformerChain).block(Duration.ofSeconds(5));
|
||||||
|
|
||||||
|
@ -94,7 +95,7 @@ public class ResourceTransformerSupportTests {
|
||||||
@Test
|
@Test
|
||||||
public void resolveUrlPathWithRelativePathInParentDirectory() throws Exception {
|
public void resolveUrlPathWithRelativePathInParentDirectory() throws Exception {
|
||||||
Resource imagePng = new ClassPathResource("test/images/image.png", getClass());
|
Resource imagePng = new ClassPathResource("test/images/image.png", getClass());
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("").build());
|
||||||
String actual = this.transformer.resolveUrlPath(
|
String actual = this.transformer.resolveUrlPath(
|
||||||
"../bar.css", exchange, imagePng, this.transformerChain).block(Duration.ofSeconds(5));
|
"../bar.css", exchange, imagePng, this.transformerChain).block(Duration.ofSeconds(5));
|
||||||
|
|
||||||
|
|
|
@ -34,9 +34,9 @@ import org.springframework.core.io.ClassPathResource;
|
||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
import org.springframework.mock.web.test.MockServletContext;
|
import org.springframework.mock.web.test.MockServletContext;
|
||||||
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
||||||
import org.springframework.web.reactive.handler.SimpleUrlHandlerMapping;
|
import org.springframework.web.reactive.handler.SimpleUrlHandlerMapping;
|
||||||
import org.springframework.web.server.ServerWebExchange;
|
|
||||||
import org.springframework.web.util.pattern.PathPattern;
|
import org.springframework.web.util.pattern.PathPattern;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
@ -72,7 +72,7 @@ public class ResourceUrlProviderTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getStaticResourceUrl() {
|
public void getStaticResourceUrl() {
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||||
String uriString = "/resources/foo.css";
|
String uriString = "/resources/foo.css";
|
||||||
String actual = this.urlProvider.getForUriString(uriString, exchange).block(Duration.ofSeconds(5));
|
String actual = this.urlProvider.getForUriString(uriString, exchange).block(Duration.ofSeconds(5));
|
||||||
assertEquals(uriString, actual);
|
assertEquals(uriString, actual);
|
||||||
|
@ -80,7 +80,7 @@ public class ResourceUrlProviderTests {
|
||||||
|
|
||||||
@Test // SPR-13374
|
@Test // SPR-13374
|
||||||
public void getStaticResourceUrlRequestWithQueryOrHash() {
|
public void getStaticResourceUrlRequestWithQueryOrHash() {
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||||
|
|
||||||
String url = "/resources/foo.css?foo=bar&url=http://example.org";
|
String url = "/resources/foo.css?foo=bar&url=http://example.org";
|
||||||
String resolvedUrl = this.urlProvider.getForUriString(url, exchange).block(Duration.ofSeconds(5));
|
String resolvedUrl = this.urlProvider.getForUriString(url, exchange).block(Duration.ofSeconds(5));
|
||||||
|
@ -103,7 +103,7 @@ public class ResourceUrlProviderTests {
|
||||||
resolvers.add(new PathResourceResolver());
|
resolvers.add(new PathResourceResolver());
|
||||||
this.handler.setResourceResolvers(resolvers);
|
this.handler.setResourceResolvers(resolvers);
|
||||||
|
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||||
String path = "/resources/foo.css";
|
String path = "/resources/foo.css";
|
||||||
String url = this.urlProvider.getForUriString(path, exchange).block(Duration.ofSeconds(5));
|
String url = this.urlProvider.getForUriString(path, exchange).block(Duration.ofSeconds(5));
|
||||||
assertEquals("/resources/foo-e36d2e05253c6c7085a91522ce43a0b4.css", url);
|
assertEquals("/resources/foo-e36d2e05253c6c7085a91522ce43a0b4.css", url);
|
||||||
|
@ -126,7 +126,7 @@ public class ResourceUrlProviderTests {
|
||||||
this.handlerMap.put("/resources/*.css", otherHandler);
|
this.handlerMap.put("/resources/*.css", otherHandler);
|
||||||
this.urlProvider.registerHandlers(this.handlerMap);
|
this.urlProvider.registerHandlers(this.handlerMap);
|
||||||
|
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||||
String path = "/resources/foo.css";
|
String path = "/resources/foo.css";
|
||||||
String url = this.urlProvider.getForUriString(path, exchange).block(Duration.ofSeconds(5));
|
String url = this.urlProvider.getForUriString(path, exchange).block(Duration.ofSeconds(5));
|
||||||
assertEquals("/resources/foo-e36d2e05253c6c7085a91522ce43a0b4.css", url);
|
assertEquals("/resources/foo-e36d2e05253c6c7085a91522ce43a0b4.css", url);
|
||||||
|
|
|
@ -47,7 +47,7 @@ import org.springframework.http.MediaType;
|
||||||
import org.springframework.http.server.PathContainer;
|
import org.springframework.http.server.PathContainer;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerWebExchange;
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
import org.springframework.web.reactive.HandlerMapping;
|
import org.springframework.web.reactive.HandlerMapping;
|
||||||
import org.springframework.web.server.MethodNotAllowedException;
|
import org.springframework.web.server.MethodNotAllowedException;
|
||||||
|
@ -90,7 +90,7 @@ public class ResourceWebHandlerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getResource() throws Exception {
|
public void getResource() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("").build());
|
||||||
setPathWithinHandlerMapping(exchange, "foo.css");
|
setPathWithinHandlerMapping(exchange, "foo.css");
|
||||||
this.handler.handle(exchange).block(TIMEOUT);
|
this.handler.handle(exchange).block(TIMEOUT);
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ public class ResourceWebHandlerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getResourceHttpHeader() throws Exception {
|
public void getResourceHttpHeader() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.head("").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.head("").build());
|
||||||
setPathWithinHandlerMapping(exchange, "foo.css");
|
setPathWithinHandlerMapping(exchange, "foo.css");
|
||||||
this.handler.handle(exchange).block(TIMEOUT);
|
this.handler.handle(exchange).block(TIMEOUT);
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ public class ResourceWebHandlerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getResourceHttpOptions() throws Exception {
|
public void getResourceHttpOptions() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.options("").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.options("").build());
|
||||||
setPathWithinHandlerMapping(exchange, "foo.css");
|
setPathWithinHandlerMapping(exchange, "foo.css");
|
||||||
this.handler.handle(exchange).block(TIMEOUT);
|
this.handler.handle(exchange).block(TIMEOUT);
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ public class ResourceWebHandlerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getResourceNoCache() throws Exception {
|
public void getResourceNoCache() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("").build());
|
||||||
setPathWithinHandlerMapping(exchange, "foo.css");
|
setPathWithinHandlerMapping(exchange, "foo.css");
|
||||||
this.handler.setCacheControl(CacheControl.noStore());
|
this.handler.setCacheControl(CacheControl.noStore());
|
||||||
this.handler.handle(exchange).block(TIMEOUT);
|
this.handler.handle(exchange).block(TIMEOUT);
|
||||||
|
@ -158,7 +158,7 @@ public class ResourceWebHandlerTests {
|
||||||
this.handler.setResourceResolvers(Arrays.asList(versionResolver, new PathResourceResolver()));
|
this.handler.setResourceResolvers(Arrays.asList(versionResolver, new PathResourceResolver()));
|
||||||
this.handler.afterPropertiesSet();
|
this.handler.afterPropertiesSet();
|
||||||
|
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("").build());
|
||||||
setPathWithinHandlerMapping(exchange, "versionString/foo.css");
|
setPathWithinHandlerMapping(exchange, "versionString/foo.css");
|
||||||
this.handler.handle(exchange).block(TIMEOUT);
|
this.handler.handle(exchange).block(TIMEOUT);
|
||||||
|
|
||||||
|
@ -169,7 +169,7 @@ public class ResourceWebHandlerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getResourceWithHtmlMediaType() throws Exception {
|
public void getResourceWithHtmlMediaType() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("").build());
|
||||||
setPathWithinHandlerMapping(exchange, "foo.html");
|
setPathWithinHandlerMapping(exchange, "foo.html");
|
||||||
this.handler.handle(exchange).block(TIMEOUT);
|
this.handler.handle(exchange).block(TIMEOUT);
|
||||||
|
|
||||||
|
@ -184,7 +184,7 @@ public class ResourceWebHandlerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getResourceFromAlternatePath() throws Exception {
|
public void getResourceFromAlternatePath() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("").build());
|
||||||
setPathWithinHandlerMapping(exchange, "baz.css");
|
setPathWithinHandlerMapping(exchange, "baz.css");
|
||||||
this.handler.handle(exchange).block(TIMEOUT);
|
this.handler.handle(exchange).block(TIMEOUT);
|
||||||
|
|
||||||
|
@ -201,21 +201,23 @@ public class ResourceWebHandlerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getResourceFromSubDirectory() throws Exception {
|
public void getResourceFromSubDirectory() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("").build());
|
||||||
setPathWithinHandlerMapping(exchange, "js/foo.js");
|
setPathWithinHandlerMapping(exchange, "js/foo.js");
|
||||||
this.handler.handle(exchange).block(TIMEOUT);
|
this.handler.handle(exchange).block(TIMEOUT);
|
||||||
|
|
||||||
assertEquals(MediaType.parseMediaType("application/javascript"), exchange.getResponse().getHeaders().getContentType());
|
assertEquals(MediaType.parseMediaType("application/javascript"),
|
||||||
|
exchange.getResponse().getHeaders().getContentType());
|
||||||
assertResponseBody(exchange, "function foo() { console.log(\"hello world\"); }");
|
assertResponseBody(exchange, "function foo() { console.log(\"hello world\"); }");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getResourceFromSubDirectoryOfAlternatePath() throws Exception {
|
public void getResourceFromSubDirectoryOfAlternatePath() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("").build());
|
||||||
setPathWithinHandlerMapping(exchange, "js/baz.js");
|
setPathWithinHandlerMapping(exchange, "js/baz.js");
|
||||||
this.handler.handle(exchange).block(TIMEOUT);
|
this.handler.handle(exchange).block(TIMEOUT);
|
||||||
|
|
||||||
assertEquals(MediaType.parseMediaType("application/javascript"), exchange.getResponse().getHeaders().getContentType());
|
HttpHeaders headers = exchange.getResponse().getHeaders();
|
||||||
|
assertEquals(MediaType.parseMediaType("application/javascript"), headers.getContentType());
|
||||||
assertResponseBody(exchange, "function foo() { console.log(\"hello world\"); }");
|
assertResponseBody(exchange, "function foo() { console.log(\"hello world\"); }");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,8 +228,8 @@ public class ResourceWebHandlerTests {
|
||||||
handler.setLocations(paths);
|
handler.setLocations(paths);
|
||||||
handler.afterPropertiesSet();
|
handler.afterPropertiesSet();
|
||||||
|
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("")
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("")
|
||||||
.header("Accept", "application/json,text/plain,*/*").toExchange();
|
.header("Accept", "application/json,text/plain,*/*").build());
|
||||||
setPathWithinHandlerMapping(exchange, "foo.html");
|
setPathWithinHandlerMapping(exchange, "foo.html");
|
||||||
handler.handle(exchange).block(TIMEOUT);
|
handler.handle(exchange).block(TIMEOUT);
|
||||||
|
|
||||||
|
@ -268,7 +270,8 @@ public class ResourceWebHandlerTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void testInvalidPath(HttpMethod httpMethod, String requestPath, Resource location) throws Exception {
|
private void testInvalidPath(HttpMethod httpMethod, String requestPath, Resource location) throws Exception {
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.method(httpMethod, "").toExchange();
|
MockServerHttpRequest request = MockServerHttpRequest.method(httpMethod, "").build();
|
||||||
|
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
setPathWithinHandlerMapping(exchange, requestPath);
|
setPathWithinHandlerMapping(exchange, requestPath);
|
||||||
this.handler.handle(exchange).block(TIMEOUT);
|
this.handler.handle(exchange).block(TIMEOUT);
|
||||||
if (!location.createRelative(requestPath).exists() && !requestPath.contains(":")) {
|
if (!location.createRelative(requestPath).exists() && !requestPath.contains(":")) {
|
||||||
|
@ -337,8 +340,8 @@ public class ResourceWebHandlerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void notModified() throws Exception {
|
public void notModified() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("")
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("")
|
||||||
.ifModifiedSince(resourceLastModified("test/foo.css")).toExchange();
|
.ifModifiedSince(resourceLastModified("test/foo.css")).build());
|
||||||
setPathWithinHandlerMapping(exchange, "foo.css");
|
setPathWithinHandlerMapping(exchange, "foo.css");
|
||||||
this.handler.handle(exchange).block(TIMEOUT);
|
this.handler.handle(exchange).block(TIMEOUT);
|
||||||
assertEquals(HttpStatus.NOT_MODIFIED, exchange.getResponse().getStatusCode());
|
assertEquals(HttpStatus.NOT_MODIFIED, exchange.getResponse().getStatusCode());
|
||||||
|
@ -347,7 +350,8 @@ public class ResourceWebHandlerTests {
|
||||||
@Test
|
@Test
|
||||||
public void modified() throws Exception {
|
public void modified() throws Exception {
|
||||||
long timestamp = resourceLastModified("test/foo.css") / 1000 * 1000 - 1;
|
long timestamp = resourceLastModified("test/foo.css") / 1000 * 1000 - 1;
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("").ifModifiedSince(timestamp).toExchange();
|
MockServerHttpRequest request = MockServerHttpRequest.get("").ifModifiedSince(timestamp).build();
|
||||||
|
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
setPathWithinHandlerMapping(exchange, "foo.css");
|
setPathWithinHandlerMapping(exchange, "foo.css");
|
||||||
this.handler.handle(exchange).block(TIMEOUT);
|
this.handler.handle(exchange).block(TIMEOUT);
|
||||||
|
|
||||||
|
@ -357,7 +361,7 @@ public class ResourceWebHandlerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void directory() throws Exception {
|
public void directory() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("").build());
|
||||||
setPathWithinHandlerMapping(exchange, "js/");
|
setPathWithinHandlerMapping(exchange, "js/");
|
||||||
this.handler.handle(exchange).block(TIMEOUT);
|
this.handler.handle(exchange).block(TIMEOUT);
|
||||||
assertEquals(HttpStatus.NOT_FOUND, exchange.getResponse().getStatusCode());
|
assertEquals(HttpStatus.NOT_FOUND, exchange.getResponse().getStatusCode());
|
||||||
|
@ -365,7 +369,7 @@ public class ResourceWebHandlerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void directoryInJarFile() throws Exception {
|
public void directoryInJarFile() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("").build());
|
||||||
setPathWithinHandlerMapping(exchange, "underscorejs/");
|
setPathWithinHandlerMapping(exchange, "underscorejs/");
|
||||||
this.handler.handle(exchange).block(TIMEOUT);
|
this.handler.handle(exchange).block(TIMEOUT);
|
||||||
|
|
||||||
|
@ -375,7 +379,7 @@ public class ResourceWebHandlerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void missingResourcePath() throws Exception {
|
public void missingResourcePath() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("").build());
|
||||||
setPathWithinHandlerMapping(exchange, "");
|
setPathWithinHandlerMapping(exchange, "");
|
||||||
this.handler.handle(exchange).block(TIMEOUT);
|
this.handler.handle(exchange).block(TIMEOUT);
|
||||||
assertEquals(HttpStatus.NOT_FOUND, exchange.getResponse().getStatusCode());
|
assertEquals(HttpStatus.NOT_FOUND, exchange.getResponse().getStatusCode());
|
||||||
|
@ -383,13 +387,13 @@ public class ResourceWebHandlerTests {
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void noPathWithinHandlerMappingAttribute() throws Exception {
|
public void noPathWithinHandlerMappingAttribute() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("").build());
|
||||||
this.handler.handle(exchange).block(TIMEOUT);
|
this.handler.handle(exchange).block(TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = MethodNotAllowedException.class)
|
@Test(expected = MethodNotAllowedException.class)
|
||||||
public void unsupportedHttpMethod() throws Exception {
|
public void unsupportedHttpMethod() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.post("").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.post("").build());
|
||||||
setPathWithinHandlerMapping(exchange, "foo.css");
|
setPathWithinHandlerMapping(exchange, "foo.css");
|
||||||
this.handler.handle(exchange).block(TIMEOUT);
|
this.handler.handle(exchange).block(TIMEOUT);
|
||||||
}
|
}
|
||||||
|
@ -402,7 +406,8 @@ public class ResourceWebHandlerTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resourceNotFound(HttpMethod httpMethod) throws Exception {
|
private void resourceNotFound(HttpMethod httpMethod) throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.method(httpMethod, "").toExchange();
|
MockServerHttpRequest request = MockServerHttpRequest.method(httpMethod, "").build();
|
||||||
|
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
setPathWithinHandlerMapping(exchange, "not-there.css");
|
setPathWithinHandlerMapping(exchange, "not-there.css");
|
||||||
this.handler.handle(exchange).block(TIMEOUT);
|
this.handler.handle(exchange).block(TIMEOUT);
|
||||||
assertEquals(HttpStatus.NOT_FOUND, exchange.getResponse().getStatusCode());
|
assertEquals(HttpStatus.NOT_FOUND, exchange.getResponse().getStatusCode());
|
||||||
|
@ -410,7 +415,8 @@ public class ResourceWebHandlerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void partialContentByteRange() throws Exception {
|
public void partialContentByteRange() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("").header("Range", "bytes=0-1").toExchange();
|
MockServerHttpRequest request = MockServerHttpRequest.get("").header("Range", "bytes=0-1").build();
|
||||||
|
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
setPathWithinHandlerMapping(exchange, "foo.txt");
|
setPathWithinHandlerMapping(exchange, "foo.txt");
|
||||||
this.handler.handle(exchange).block(TIMEOUT);
|
this.handler.handle(exchange).block(TIMEOUT);
|
||||||
|
|
||||||
|
@ -425,7 +431,8 @@ public class ResourceWebHandlerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void partialContentByteRangeNoEnd() throws Exception {
|
public void partialContentByteRangeNoEnd() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("").header("range", "bytes=9-").toExchange();
|
MockServerHttpRequest request = MockServerHttpRequest.get("").header("range", "bytes=9-").build();
|
||||||
|
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
setPathWithinHandlerMapping(exchange, "foo.txt");
|
setPathWithinHandlerMapping(exchange, "foo.txt");
|
||||||
this.handler.handle(exchange).block(TIMEOUT);
|
this.handler.handle(exchange).block(TIMEOUT);
|
||||||
|
|
||||||
|
@ -440,7 +447,8 @@ public class ResourceWebHandlerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void partialContentByteRangeLargeEnd() throws Exception {
|
public void partialContentByteRangeLargeEnd() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("").header("range", "bytes=9-10000").toExchange();
|
MockServerHttpRequest request = MockServerHttpRequest.get("").header("range", "bytes=9-10000").build();
|
||||||
|
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
setPathWithinHandlerMapping(exchange, "foo.txt");
|
setPathWithinHandlerMapping(exchange, "foo.txt");
|
||||||
this.handler.handle(exchange).block(TIMEOUT);
|
this.handler.handle(exchange).block(TIMEOUT);
|
||||||
|
|
||||||
|
@ -455,7 +463,8 @@ public class ResourceWebHandlerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void partialContentSuffixRange() throws Exception {
|
public void partialContentSuffixRange() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("").header("range", "bytes=-1").toExchange();
|
MockServerHttpRequest request = MockServerHttpRequest.get("").header("range", "bytes=-1").build();
|
||||||
|
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
setPathWithinHandlerMapping(exchange, "foo.txt");
|
setPathWithinHandlerMapping(exchange, "foo.txt");
|
||||||
this.handler.handle(exchange).block(TIMEOUT);
|
this.handler.handle(exchange).block(TIMEOUT);
|
||||||
|
|
||||||
|
@ -470,7 +479,8 @@ public class ResourceWebHandlerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void partialContentSuffixRangeLargeSuffix() throws Exception {
|
public void partialContentSuffixRangeLargeSuffix() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("").header("range", "bytes=-11").toExchange();
|
MockServerHttpRequest request = MockServerHttpRequest.get("").header("range", "bytes=-11").build();
|
||||||
|
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
setPathWithinHandlerMapping(exchange, "foo.txt");
|
setPathWithinHandlerMapping(exchange, "foo.txt");
|
||||||
this.handler.handle(exchange).block(TIMEOUT);
|
this.handler.handle(exchange).block(TIMEOUT);
|
||||||
|
|
||||||
|
@ -485,7 +495,8 @@ public class ResourceWebHandlerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void partialContentInvalidRangeHeader() throws Exception {
|
public void partialContentInvalidRangeHeader() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("").header("range", "bytes=foo bar").toExchange();
|
MockServerHttpRequest request = MockServerHttpRequest.get("").header("range", "bytes=foo bar").build();
|
||||||
|
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
setPathWithinHandlerMapping(exchange, "foo.txt");
|
setPathWithinHandlerMapping(exchange, "foo.txt");
|
||||||
|
|
||||||
StepVerifier.create(this.handler.handle(exchange))
|
StepVerifier.create(this.handler.handle(exchange))
|
||||||
|
@ -499,7 +510,8 @@ public class ResourceWebHandlerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void partialContentMultipleByteRanges() throws Exception {
|
public void partialContentMultipleByteRanges() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("").header("Range", "bytes=0-1, 4-5, 8-9").toExchange();
|
MockServerHttpRequest request = MockServerHttpRequest.get("").header("Range", "bytes=0-1, 4-5, 8-9").build();
|
||||||
|
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
setPathWithinHandlerMapping(exchange, "foo.txt");
|
setPathWithinHandlerMapping(exchange, "foo.txt");
|
||||||
this.handler.handle(exchange).block(TIMEOUT);
|
this.handler.handle(exchange).block(TIMEOUT);
|
||||||
|
|
||||||
|
@ -542,7 +554,7 @@ public class ResourceWebHandlerTests {
|
||||||
|
|
||||||
@Test // SPR-14005
|
@Test // SPR-14005
|
||||||
public void doOverwriteExistingCacheControlHeaders() throws Exception {
|
public void doOverwriteExistingCacheControlHeaders() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("").build());
|
||||||
exchange.getResponse().getHeaders().setCacheControl(CacheControl.noStore().getHeaderValue());
|
exchange.getResponse().getHeaders().setCacheControl(CacheControl.noStore().getHeaderValue());
|
||||||
setPathWithinHandlerMapping(exchange, "foo.css");
|
setPathWithinHandlerMapping(exchange, "foo.css");
|
||||||
this.handler.handle(exchange).block(TIMEOUT);
|
this.handler.handle(exchange).block(TIMEOUT);
|
||||||
|
|
|
@ -30,6 +30,7 @@ import reactor.core.publisher.Mono;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.ClassPathResource;
|
||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.web.server.ServerWebExchange;
|
import org.springframework.web.server.ServerWebExchange;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.instanceOf;
|
import static org.hamcrest.Matchers.instanceOf;
|
||||||
|
@ -162,7 +163,8 @@ public class VersionResourceResolverTests {
|
||||||
String version = "version";
|
String version = "version";
|
||||||
String file = "bar.css";
|
String file = "bar.css";
|
||||||
Resource expected = new ClassPathResource("test/" + file, getClass());
|
Resource expected = new ClassPathResource("test/" + file, getClass());
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/resources/bar-version.css").toExchange();
|
MockServerHttpRequest request = MockServerHttpRequest.get("/resources/bar-version.css").build();
|
||||||
|
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
given(this.chain.resolveResource(exchange, versionFile, this.locations)).willReturn(Mono.empty());
|
given(this.chain.resolveResource(exchange, versionFile, this.locations)).willReturn(Mono.empty());
|
||||||
given(this.chain.resolveResource(exchange, file, this.locations)).willReturn(Mono.just(expected));
|
given(this.chain.resolveResource(exchange, file, this.locations)).willReturn(Mono.just(expected));
|
||||||
given(this.versionStrategy.extractVersion(versionFile)).willReturn(version);
|
given(this.versionStrategy.extractVersion(versionFile)).willReturn(version);
|
||||||
|
|
|
@ -26,6 +26,7 @@ import reactor.core.publisher.Mono;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.ClassPathResource;
|
||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.web.server.ServerWebExchange;
|
import org.springframework.web.server.ServerWebExchange;
|
||||||
|
|
||||||
import static java.util.Collections.singletonList;
|
import static java.util.Collections.singletonList;
|
||||||
|
@ -63,7 +64,7 @@ public class WebJarsResourceResolverTests {
|
||||||
this.locations = singletonList(new ClassPathResource("/META-INF/resources/webjars"));
|
this.locations = singletonList(new ClassPathResource("/META-INF/resources/webjars"));
|
||||||
this.resolver = new WebJarsResourceResolver();
|
this.resolver = new WebJarsResourceResolver();
|
||||||
this.chain = mock(ResourceResolverChain.class);
|
this.chain = mock(ResourceResolverChain.class);
|
||||||
this.exchange = MockServerHttpRequest.get("").toExchange();
|
this.exchange = MockServerWebExchange.from(MockServerHttpRequest.get("").build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -25,14 +25,20 @@ import org.junit.Test;
|
||||||
import org.springframework.core.ReactiveAdapterRegistry;
|
import org.springframework.core.ReactiveAdapterRegistry;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerWebExchange;
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.web.reactive.HandlerMapping;
|
import org.springframework.web.reactive.HandlerMapping;
|
||||||
import org.springframework.web.reactive.accept.FixedContentTypeResolver;
|
import org.springframework.web.reactive.accept.FixedContentTypeResolver;
|
||||||
import org.springframework.web.reactive.accept.HeaderContentTypeResolver;
|
import org.springframework.web.reactive.accept.HeaderContentTypeResolver;
|
||||||
import org.springframework.web.reactive.accept.RequestedContentTypeResolver;
|
import org.springframework.web.reactive.accept.RequestedContentTypeResolver;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.springframework.http.MediaType.*;
|
import static org.springframework.http.MediaType.ALL;
|
||||||
|
import static org.springframework.http.MediaType.APPLICATION_JSON_UTF8;
|
||||||
|
import static org.springframework.http.MediaType.APPLICATION_OCTET_STREAM;
|
||||||
|
import static org.springframework.http.MediaType.IMAGE_GIF;
|
||||||
|
import static org.springframework.http.MediaType.IMAGE_JPEG;
|
||||||
|
import static org.springframework.http.MediaType.IMAGE_PNG;
|
||||||
|
import static org.springframework.http.MediaType.TEXT_PLAIN;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for {@link HandlerResultHandlerSupport}.
|
* Unit tests for {@link HandlerResultHandlerSupport}.
|
||||||
|
@ -48,7 +54,7 @@ public class HandlerResultHandlerTests {
|
||||||
public void usesContentTypeResolver() throws Exception {
|
public void usesContentTypeResolver() throws Exception {
|
||||||
TestResultHandler resultHandler = new TestResultHandler(new FixedContentTypeResolver(IMAGE_GIF));
|
TestResultHandler resultHandler = new TestResultHandler(new FixedContentTypeResolver(IMAGE_GIF));
|
||||||
List<MediaType> mediaTypes = Arrays.asList(IMAGE_JPEG, IMAGE_GIF, IMAGE_PNG);
|
List<MediaType> mediaTypes = Arrays.asList(IMAGE_JPEG, IMAGE_GIF, IMAGE_PNG);
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("/path").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path").build());
|
||||||
MediaType actual = resultHandler.selectMediaType(exchange, () -> mediaTypes);
|
MediaType actual = resultHandler.selectMediaType(exchange, () -> mediaTypes);
|
||||||
|
|
||||||
assertEquals(IMAGE_GIF, actual);
|
assertEquals(IMAGE_GIF, actual);
|
||||||
|
@ -56,7 +62,7 @@ public class HandlerResultHandlerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void producibleMediaTypesRequestAttribute() throws Exception {
|
public void producibleMediaTypesRequestAttribute() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("/path").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path").build());
|
||||||
exchange.getAttributes().put(HandlerMapping.PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE, Collections.singleton(IMAGE_GIF));
|
exchange.getAttributes().put(HandlerMapping.PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE, Collections.singleton(IMAGE_GIF));
|
||||||
|
|
||||||
List<MediaType> mediaTypes = Arrays.asList(IMAGE_JPEG, IMAGE_GIF, IMAGE_PNG);
|
List<MediaType> mediaTypes = Arrays.asList(IMAGE_JPEG, IMAGE_GIF, IMAGE_PNG);
|
||||||
|
@ -67,9 +73,9 @@ public class HandlerResultHandlerTests {
|
||||||
|
|
||||||
@Test // SPR-9160
|
@Test // SPR-9160
|
||||||
public void sortsByQuality() throws Exception {
|
public void sortsByQuality() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("/path")
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path")
|
||||||
.header("Accept", "text/plain; q=0.5, application/json")
|
.header("Accept", "text/plain; q=0.5, application/json")
|
||||||
.toExchange();
|
.build());
|
||||||
|
|
||||||
List<MediaType> mediaTypes = Arrays.asList(TEXT_PLAIN, APPLICATION_JSON_UTF8);
|
List<MediaType> mediaTypes = Arrays.asList(TEXT_PLAIN, APPLICATION_JSON_UTF8);
|
||||||
MediaType actual = this.resultHandler.selectMediaType(exchange, () -> mediaTypes);
|
MediaType actual = this.resultHandler.selectMediaType(exchange, () -> mediaTypes);
|
||||||
|
@ -81,7 +87,7 @@ public class HandlerResultHandlerTests {
|
||||||
public void charsetFromAcceptHeader() throws Exception {
|
public void charsetFromAcceptHeader() throws Exception {
|
||||||
MediaType text8859 = MediaType.parseMediaType("text/plain;charset=ISO-8859-1");
|
MediaType text8859 = MediaType.parseMediaType("text/plain;charset=ISO-8859-1");
|
||||||
MediaType textUtf8 = MediaType.parseMediaType("text/plain;charset=UTF-8");
|
MediaType textUtf8 = MediaType.parseMediaType("text/plain;charset=UTF-8");
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("/path").accept(text8859).toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path").accept(text8859).build());
|
||||||
MediaType actual = this.resultHandler.selectMediaType(exchange, () -> Collections.singletonList(textUtf8));
|
MediaType actual = this.resultHandler.selectMediaType(exchange, () -> Collections.singletonList(textUtf8));
|
||||||
|
|
||||||
assertEquals(text8859, actual);
|
assertEquals(text8859, actual);
|
||||||
|
@ -90,7 +96,7 @@ public class HandlerResultHandlerTests {
|
||||||
@Test // SPR-12894
|
@Test // SPR-12894
|
||||||
public void noConcreteMediaType() throws Exception {
|
public void noConcreteMediaType() throws Exception {
|
||||||
List<MediaType> producible = Collections.singletonList(ALL);
|
List<MediaType> producible = Collections.singletonList(ALL);
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("/path").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path").build());
|
||||||
MediaType actual = this.resultHandler.selectMediaType(exchange, () -> producible);
|
MediaType actual = this.resultHandler.selectMediaType(exchange, () -> producible);
|
||||||
|
|
||||||
assertEquals(APPLICATION_OCTET_STREAM, actual);
|
assertEquals(APPLICATION_OCTET_STREAM, actual);
|
||||||
|
|
|
@ -20,7 +20,7 @@ import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerWebExchange;
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
@ -83,7 +83,8 @@ public class CompositeRequestConditionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void match() {
|
public void match() {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("/path?param1=paramValue1").toExchange();
|
MockServerHttpRequest request = MockServerHttpRequest.get("/path?param1=paramValue1").build();
|
||||||
|
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
|
|
||||||
RequestCondition<?> condition1 = new RequestMethodsRequestCondition(RequestMethod.GET, RequestMethod.POST);
|
RequestCondition<?> condition1 = new RequestMethodsRequestCondition(RequestMethod.GET, RequestMethod.POST);
|
||||||
RequestCondition<?> condition2 = new RequestMethodsRequestCondition(RequestMethod.GET);
|
RequestCondition<?> condition2 = new RequestMethodsRequestCondition(RequestMethod.GET);
|
||||||
|
@ -97,20 +98,20 @@ public class CompositeRequestConditionTests {
|
||||||
@Test
|
@Test
|
||||||
public void noMatch() {
|
public void noMatch() {
|
||||||
CompositeRequestCondition cond = new CompositeRequestCondition(this.param1);
|
CompositeRequestCondition cond = new CompositeRequestCondition(this.param1);
|
||||||
assertNull(cond.getMatchingCondition(MockServerHttpRequest.get("/").toExchange()));
|
assertNull(cond.getMatchingCondition(MockServerWebExchange.from(MockServerHttpRequest.get("/").build())));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void matchEmpty() {
|
public void matchEmpty() {
|
||||||
CompositeRequestCondition empty = new CompositeRequestCondition();
|
CompositeRequestCondition empty = new CompositeRequestCondition();
|
||||||
assertSame(empty, empty.getMatchingCondition(MockServerHttpRequest.get("/").toExchange()));
|
assertSame(empty, empty.getMatchingCondition(MockServerWebExchange.from(MockServerHttpRequest.get("/").build())));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void compare() {
|
public void compare() {
|
||||||
CompositeRequestCondition cond1 = new CompositeRequestCondition(this.param1);
|
CompositeRequestCondition cond1 = new CompositeRequestCondition(this.param1);
|
||||||
CompositeRequestCondition cond3 = new CompositeRequestCondition(this.param3);
|
CompositeRequestCondition cond3 = new CompositeRequestCondition(this.param3);
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("/").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||||
|
|
||||||
assertEquals(1, cond1.compareTo(cond3, exchange));
|
assertEquals(1, cond1.compareTo(cond3, exchange));
|
||||||
assertEquals(-1, cond3.compareTo(cond1, exchange));
|
assertEquals(-1, cond3.compareTo(cond1, exchange));
|
||||||
|
@ -120,7 +121,7 @@ public class CompositeRequestConditionTests {
|
||||||
public void compareEmpty() {
|
public void compareEmpty() {
|
||||||
CompositeRequestCondition empty = new CompositeRequestCondition();
|
CompositeRequestCondition empty = new CompositeRequestCondition();
|
||||||
CompositeRequestCondition notEmpty = new CompositeRequestCondition(this.param1);
|
CompositeRequestCondition notEmpty = new CompositeRequestCondition(this.param1);
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("/").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||||
|
|
||||||
assertEquals(0, empty.compareTo(empty, exchange));
|
assertEquals(0, empty.compareTo(empty, exchange));
|
||||||
assertEquals(-1, notEmpty.compareTo(empty, exchange));
|
assertEquals(-1, notEmpty.compareTo(empty, exchange));
|
||||||
|
@ -131,7 +132,7 @@ public class CompositeRequestConditionTests {
|
||||||
public void compareDifferentLength() {
|
public void compareDifferentLength() {
|
||||||
CompositeRequestCondition cond1 = new CompositeRequestCondition(this.param1);
|
CompositeRequestCondition cond1 = new CompositeRequestCondition(this.param1);
|
||||||
CompositeRequestCondition cond2 = new CompositeRequestCondition(this.param1, this.header1);
|
CompositeRequestCondition cond2 = new CompositeRequestCondition(this.param1, this.header1);
|
||||||
cond1.compareTo(cond2, MockServerHttpRequest.get("/").toExchange());
|
cond1.compareTo(cond2, MockServerWebExchange.from(MockServerHttpRequest.get("/").build()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerWebExchange;
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.web.reactive.result.condition.ConsumesRequestCondition.ConsumeMediaTypeExpression;
|
import org.springframework.web.reactive.result.condition.ConsumesRequestCondition.ConsumeMediaTypeExpression;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
@ -101,7 +101,7 @@ public class ConsumesRequestConditionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void compareToSingle() throws Exception {
|
public void compareToSingle() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("/").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||||
|
|
||||||
ConsumesRequestCondition condition1 = new ConsumesRequestCondition("text/plain");
|
ConsumesRequestCondition condition1 = new ConsumesRequestCondition("text/plain");
|
||||||
ConsumesRequestCondition condition2 = new ConsumesRequestCondition("text/*");
|
ConsumesRequestCondition condition2 = new ConsumesRequestCondition("text/*");
|
||||||
|
@ -115,7 +115,7 @@ public class ConsumesRequestConditionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void compareToMultiple() throws Exception {
|
public void compareToMultiple() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("/").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||||
|
|
||||||
ConsumesRequestCondition condition1 = new ConsumesRequestCondition("*/*", "text/plain");
|
ConsumesRequestCondition condition1 = new ConsumesRequestCondition("*/*", "text/plain");
|
||||||
ConsumesRequestCondition condition2 = new ConsumesRequestCondition("text/*", "text/plain;q=0.7");
|
ConsumesRequestCondition condition2 = new ConsumesRequestCondition("text/*", "text/plain;q=0.7");
|
||||||
|
@ -188,7 +188,8 @@ public class ConsumesRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
private MockServerWebExchange postExchange(String contentType) {
|
private MockServerWebExchange postExchange(String contentType) {
|
||||||
return MockServerHttpRequest.post("/").header(HttpHeaders.CONTENT_TYPE, contentType).toExchange();
|
return MockServerWebExchange.from(
|
||||||
|
MockServerHttpRequest.post("/").header(HttpHeaders.CONTENT_TYPE, contentType).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ import java.util.Collection;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerWebExchange;
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
|
@ -47,7 +47,7 @@ public class HeadersRequestConditionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void headerPresent() throws Exception {
|
public void headerPresent() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("/").header("Accept", "").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("Accept", "").build());
|
||||||
HeadersRequestCondition condition = new HeadersRequestCondition("accept");
|
HeadersRequestCondition condition = new HeadersRequestCondition("accept");
|
||||||
|
|
||||||
assertNotNull(condition.getMatchingCondition(exchange));
|
assertNotNull(condition.getMatchingCondition(exchange));
|
||||||
|
@ -55,7 +55,7 @@ public class HeadersRequestConditionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void headerPresentNoMatch() throws Exception {
|
public void headerPresentNoMatch() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("/").header("bar", "").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("bar", "").build());
|
||||||
HeadersRequestCondition condition = new HeadersRequestCondition("foo");
|
HeadersRequestCondition condition = new HeadersRequestCondition("foo");
|
||||||
|
|
||||||
assertNull(condition.getMatchingCondition(exchange));
|
assertNull(condition.getMatchingCondition(exchange));
|
||||||
|
@ -63,7 +63,7 @@ public class HeadersRequestConditionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void headerNotPresent() throws Exception {
|
public void headerNotPresent() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("/").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||||
HeadersRequestCondition condition = new HeadersRequestCondition("!accept");
|
HeadersRequestCondition condition = new HeadersRequestCondition("!accept");
|
||||||
|
|
||||||
assertNotNull(condition.getMatchingCondition(exchange));
|
assertNotNull(condition.getMatchingCondition(exchange));
|
||||||
|
@ -71,7 +71,7 @@ public class HeadersRequestConditionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void headerValueMatch() throws Exception {
|
public void headerValueMatch() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("/").header("foo", "bar").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("foo", "bar").build());
|
||||||
HeadersRequestCondition condition = new HeadersRequestCondition("foo=bar");
|
HeadersRequestCondition condition = new HeadersRequestCondition("foo=bar");
|
||||||
|
|
||||||
assertNotNull(condition.getMatchingCondition(exchange));
|
assertNotNull(condition.getMatchingCondition(exchange));
|
||||||
|
@ -79,7 +79,7 @@ public class HeadersRequestConditionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void headerValueNoMatch() throws Exception {
|
public void headerValueNoMatch() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("/").header("foo", "bazz").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("foo", "bazz").build());
|
||||||
HeadersRequestCondition condition = new HeadersRequestCondition("foo=bar");
|
HeadersRequestCondition condition = new HeadersRequestCondition("foo=bar");
|
||||||
|
|
||||||
assertNull(condition.getMatchingCondition(exchange));
|
assertNull(condition.getMatchingCondition(exchange));
|
||||||
|
@ -87,7 +87,7 @@ public class HeadersRequestConditionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void headerCaseSensitiveValueMatch() throws Exception {
|
public void headerCaseSensitiveValueMatch() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("/").header("foo", "bar").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("foo", "bar").build());
|
||||||
HeadersRequestCondition condition = new HeadersRequestCondition("foo=Bar");
|
HeadersRequestCondition condition = new HeadersRequestCondition("foo=Bar");
|
||||||
|
|
||||||
assertNull(condition.getMatchingCondition(exchange));
|
assertNull(condition.getMatchingCondition(exchange));
|
||||||
|
@ -95,7 +95,7 @@ public class HeadersRequestConditionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void headerValueMatchNegated() throws Exception {
|
public void headerValueMatchNegated() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("/").header("foo", "baz").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("foo", "baz").build());
|
||||||
HeadersRequestCondition condition = new HeadersRequestCondition("foo!=bar");
|
HeadersRequestCondition condition = new HeadersRequestCondition("foo!=bar");
|
||||||
|
|
||||||
assertNotNull(condition.getMatchingCondition(exchange));
|
assertNotNull(condition.getMatchingCondition(exchange));
|
||||||
|
@ -103,7 +103,7 @@ public class HeadersRequestConditionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void headerValueNoMatchNegated() throws Exception {
|
public void headerValueNoMatchNegated() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("/").header("foo", "bar").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("foo", "bar").build());
|
||||||
HeadersRequestCondition condition = new HeadersRequestCondition("foo!=bar");
|
HeadersRequestCondition condition = new HeadersRequestCondition("foo!=bar");
|
||||||
|
|
||||||
assertNull(condition.getMatchingCondition(exchange));
|
assertNull(condition.getMatchingCondition(exchange));
|
||||||
|
@ -111,7 +111,7 @@ public class HeadersRequestConditionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void compareTo() throws Exception {
|
public void compareTo() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("/").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||||
|
|
||||||
HeadersRequestCondition condition1 = new HeadersRequestCondition("foo", "bar", "baz");
|
HeadersRequestCondition condition1 = new HeadersRequestCondition("foo", "bar", "baz");
|
||||||
HeadersRequestCondition condition2 = new HeadersRequestCondition("foo", "bar");
|
HeadersRequestCondition condition2 = new HeadersRequestCondition("foo", "bar");
|
||||||
|
@ -136,7 +136,7 @@ public class HeadersRequestConditionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getMatchingCondition() throws Exception {
|
public void getMatchingCondition() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("/").header("foo", "bar").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("foo", "bar").build());
|
||||||
HeadersRequestCondition condition = new HeadersRequestCondition("foo");
|
HeadersRequestCondition condition = new HeadersRequestCondition("foo");
|
||||||
|
|
||||||
HeadersRequestCondition result = condition.getMatchingCondition(exchange);
|
HeadersRequestCondition result = condition.getMatchingCondition(exchange);
|
||||||
|
|
|
@ -20,7 +20,7 @@ import java.util.Collection;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerWebExchange;
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.web.server.ServerWebExchange;
|
import org.springframework.web.server.ServerWebExchange;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
@ -48,42 +48,42 @@ public class ParamsRequestConditionTests {
|
||||||
@Test
|
@Test
|
||||||
public void paramPresent() throws Exception {
|
public void paramPresent() throws Exception {
|
||||||
ParamsRequestCondition condition = new ParamsRequestCondition("foo");
|
ParamsRequestCondition condition = new ParamsRequestCondition("foo");
|
||||||
assertNotNull(condition.getMatchingCondition(get("/path?foo=").toExchange()));
|
assertNotNull(condition.getMatchingCondition(MockServerWebExchange.from(get("/path?foo=").build())));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // SPR-15831
|
@Test // SPR-15831
|
||||||
public void paramPresentNullValue() throws Exception {
|
public void paramPresentNullValue() throws Exception {
|
||||||
ParamsRequestCondition condition = new ParamsRequestCondition("foo");
|
ParamsRequestCondition condition = new ParamsRequestCondition("foo");
|
||||||
assertNotNull(condition.getMatchingCondition(get("/path?foo").toExchange()));
|
assertNotNull(condition.getMatchingCondition(MockServerWebExchange.from(get("/path?foo").build())));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void paramPresentNoMatch() throws Exception {
|
public void paramPresentNoMatch() throws Exception {
|
||||||
ParamsRequestCondition condition = new ParamsRequestCondition("foo");
|
ParamsRequestCondition condition = new ParamsRequestCondition("foo");
|
||||||
assertNull(condition.getMatchingCondition(get("/path?bar=").toExchange()));
|
assertNull(condition.getMatchingCondition(MockServerWebExchange.from(get("/path?bar=").build())));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void paramNotPresent() throws Exception {
|
public void paramNotPresent() throws Exception {
|
||||||
MockServerWebExchange exchange = get("/").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").build());
|
||||||
assertNotNull(new ParamsRequestCondition("!foo").getMatchingCondition(exchange));
|
assertNotNull(new ParamsRequestCondition("!foo").getMatchingCondition(exchange));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void paramValueMatch() throws Exception {
|
public void paramValueMatch() throws Exception {
|
||||||
ParamsRequestCondition condition = new ParamsRequestCondition("foo=bar");
|
ParamsRequestCondition condition = new ParamsRequestCondition("foo=bar");
|
||||||
assertNotNull(condition.getMatchingCondition(get("/path?foo=bar").toExchange()));
|
assertNotNull(condition.getMatchingCondition(MockServerWebExchange.from(get("/path?foo=bar").build())));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void paramValueNoMatch() throws Exception {
|
public void paramValueNoMatch() throws Exception {
|
||||||
ParamsRequestCondition condition = new ParamsRequestCondition("foo=bar");
|
ParamsRequestCondition condition = new ParamsRequestCondition("foo=bar");
|
||||||
assertNull(condition.getMatchingCondition(get("/path?foo=bazz").toExchange()));
|
assertNull(condition.getMatchingCondition(MockServerWebExchange.from(get("/path?foo=bazz").build())));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void compareTo() throws Exception {
|
public void compareTo() throws Exception {
|
||||||
ServerWebExchange exchange = get("/").toExchange();
|
ServerWebExchange exchange = MockServerWebExchange.from(get("/").build());
|
||||||
|
|
||||||
ParamsRequestCondition condition1 = new ParamsRequestCondition("foo", "bar", "baz");
|
ParamsRequestCondition condition1 = new ParamsRequestCondition("foo", "bar", "baz");
|
||||||
ParamsRequestCondition condition2 = new ParamsRequestCondition("foo", "bar");
|
ParamsRequestCondition condition2 = new ParamsRequestCondition("foo", "bar");
|
||||||
|
|
|
@ -22,7 +22,7 @@ import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerWebExchange;
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.web.server.ServerWebExchange;
|
import org.springframework.web.server.ServerWebExchange;
|
||||||
import org.springframework.web.util.pattern.PathPattern;
|
import org.springframework.web.util.pattern.PathPattern;
|
||||||
import org.springframework.web.util.pattern.PathPatternParser;
|
import org.springframework.web.util.pattern.PathPatternParser;
|
||||||
|
@ -80,7 +80,8 @@ public class PatternsRequestConditionTests {
|
||||||
@Test
|
@Test
|
||||||
public void matchDirectPath() throws Exception {
|
public void matchDirectPath() throws Exception {
|
||||||
PatternsRequestCondition condition = createPatternsCondition("/foo");
|
PatternsRequestCondition condition = createPatternsCondition("/foo");
|
||||||
PatternsRequestCondition match = condition.getMatchingCondition(get("/foo").toExchange());
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/foo").build());
|
||||||
|
PatternsRequestCondition match = condition.getMatchingCondition(exchange);
|
||||||
|
|
||||||
assertNotNull(match);
|
assertNotNull(match);
|
||||||
}
|
}
|
||||||
|
@ -88,7 +89,8 @@ public class PatternsRequestConditionTests {
|
||||||
@Test
|
@Test
|
||||||
public void matchPattern() throws Exception {
|
public void matchPattern() throws Exception {
|
||||||
PatternsRequestCondition condition = createPatternsCondition("/foo/*");
|
PatternsRequestCondition condition = createPatternsCondition("/foo/*");
|
||||||
PatternsRequestCondition match = condition.getMatchingCondition(get("/foo/bar").toExchange());
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/foo/bar").build());
|
||||||
|
PatternsRequestCondition match = condition.getMatchingCondition(exchange);
|
||||||
|
|
||||||
assertNotNull(match);
|
assertNotNull(match);
|
||||||
}
|
}
|
||||||
|
@ -96,7 +98,8 @@ public class PatternsRequestConditionTests {
|
||||||
@Test
|
@Test
|
||||||
public void matchSortPatterns() throws Exception {
|
public void matchSortPatterns() throws Exception {
|
||||||
PatternsRequestCondition condition = createPatternsCondition("/*/*", "/foo/bar", "/foo/*");
|
PatternsRequestCondition condition = createPatternsCondition("/*/*", "/foo/bar", "/foo/*");
|
||||||
PatternsRequestCondition match = condition.getMatchingCondition(get("/foo/bar").toExchange());
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/foo/bar").build());
|
||||||
|
PatternsRequestCondition match = condition.getMatchingCondition(exchange);
|
||||||
PatternsRequestCondition expected = createPatternsCondition("/foo/bar", "/foo/*", "/*/*");
|
PatternsRequestCondition expected = createPatternsCondition("/foo/bar", "/foo/*", "/*/*");
|
||||||
|
|
||||||
assertEquals(expected, match);
|
assertEquals(expected, match);
|
||||||
|
@ -104,7 +107,7 @@ public class PatternsRequestConditionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void matchTrailingSlash() throws Exception {
|
public void matchTrailingSlash() throws Exception {
|
||||||
MockServerWebExchange exchange = get("/foo/").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/foo/").build());
|
||||||
|
|
||||||
PatternsRequestCondition condition = createPatternsCondition("/foo");
|
PatternsRequestCondition condition = createPatternsCondition("/foo");
|
||||||
PatternsRequestCondition match = condition.getMatchingCondition(exchange);
|
PatternsRequestCondition match = condition.getMatchingCondition(exchange);
|
||||||
|
@ -123,7 +126,7 @@ public class PatternsRequestConditionTests {
|
||||||
PathPatternParser parser = new PathPatternParser();
|
PathPatternParser parser = new PathPatternParser();
|
||||||
parser.setMatchOptionalTrailingSeparator(false);
|
parser.setMatchOptionalTrailingSeparator(false);
|
||||||
condition = new PatternsRequestCondition(parser.parse("/foo"));
|
condition = new PatternsRequestCondition(parser.parse("/foo"));
|
||||||
match = condition.getMatchingCondition(get("/foo/").toExchange());
|
match = condition.getMatchingCondition(MockServerWebExchange.from(get("/foo/").build()));
|
||||||
|
|
||||||
assertNull(match);
|
assertNull(match);
|
||||||
}
|
}
|
||||||
|
@ -131,7 +134,8 @@ public class PatternsRequestConditionTests {
|
||||||
@Test
|
@Test
|
||||||
public void matchPatternContainsExtension() throws Exception {
|
public void matchPatternContainsExtension() throws Exception {
|
||||||
PatternsRequestCondition condition = createPatternsCondition("/foo.jpg");
|
PatternsRequestCondition condition = createPatternsCondition("/foo.jpg");
|
||||||
PatternsRequestCondition match = condition.getMatchingCondition(get("/foo.html").toExchange());
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/foo.html").build());
|
||||||
|
PatternsRequestCondition match = condition.getMatchingCondition(exchange);
|
||||||
|
|
||||||
assertNull(match);
|
assertNull(match);
|
||||||
}
|
}
|
||||||
|
@ -141,7 +145,7 @@ public class PatternsRequestConditionTests {
|
||||||
PatternsRequestCondition c1 = createPatternsCondition("/foo*");
|
PatternsRequestCondition c1 = createPatternsCondition("/foo*");
|
||||||
PatternsRequestCondition c2 = createPatternsCondition("/foo*");
|
PatternsRequestCondition c2 = createPatternsCondition("/foo*");
|
||||||
|
|
||||||
assertEquals(0, c1.compareTo(c2, get("/foo").toExchange()));
|
assertEquals(0, c1.compareTo(c2, MockServerWebExchange.from(get("/foo").build())));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -155,7 +159,7 @@ public class PatternsRequestConditionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void comparePatternSpecificity() throws Exception {
|
public void comparePatternSpecificity() throws Exception {
|
||||||
ServerWebExchange exchange = get("/foo").toExchange();
|
ServerWebExchange exchange = MockServerWebExchange.from(get("/foo").build());
|
||||||
|
|
||||||
PatternsRequestCondition c1 = createPatternsCondition("/fo*");
|
PatternsRequestCondition c1 = createPatternsCondition("/fo*");
|
||||||
PatternsRequestCondition c2 = createPatternsCondition("/foo");
|
PatternsRequestCondition c2 = createPatternsCondition("/foo");
|
||||||
|
@ -170,7 +174,7 @@ public class PatternsRequestConditionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void compareNumberOfMatchingPatterns() throws Exception {
|
public void compareNumberOfMatchingPatterns() throws Exception {
|
||||||
ServerWebExchange exchange = get("/foo.html").toExchange();
|
ServerWebExchange exchange = MockServerWebExchange.from(get("/foo.html").build());
|
||||||
|
|
||||||
PatternsRequestCondition c1 = createPatternsCondition("/foo.*", "/foo.jpeg");
|
PatternsRequestCondition c1 = createPatternsCondition("/foo.*", "/foo.jpeg");
|
||||||
PatternsRequestCondition c2 = createPatternsCondition("/foo.*", "/foo.html");
|
PatternsRequestCondition c2 = createPatternsCondition("/foo.*", "/foo.html");
|
||||||
|
|
|
@ -22,7 +22,7 @@ import java.util.Collections;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerWebExchange;
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.web.server.ServerWebExchange;
|
import org.springframework.web.server.ServerWebExchange;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
@ -41,7 +41,7 @@ public class ProducesRequestConditionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void match() throws Exception {
|
public void match() throws Exception {
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/").header("Accept", "text/plain").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("Accept", "text/plain").build());
|
||||||
ProducesRequestCondition condition = new ProducesRequestCondition("text/plain");
|
ProducesRequestCondition condition = new ProducesRequestCondition("text/plain");
|
||||||
|
|
||||||
assertNotNull(condition.getMatchingCondition(exchange));
|
assertNotNull(condition.getMatchingCondition(exchange));
|
||||||
|
@ -49,7 +49,7 @@ public class ProducesRequestConditionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void matchNegated() throws Exception {
|
public void matchNegated() throws Exception {
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/").header("Accept", "text/plain").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("Accept", "text/plain").build());
|
||||||
ProducesRequestCondition condition = new ProducesRequestCondition("!text/plain");
|
ProducesRequestCondition condition = new ProducesRequestCondition("!text/plain");
|
||||||
|
|
||||||
assertNull(condition.getMatchingCondition(exchange));
|
assertNull(condition.getMatchingCondition(exchange));
|
||||||
|
@ -63,7 +63,7 @@ public class ProducesRequestConditionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void matchWildcard() throws Exception {
|
public void matchWildcard() throws Exception {
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/").header("Accept", "text/plain").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("Accept", "text/plain").build());
|
||||||
ProducesRequestCondition condition = new ProducesRequestCondition("text/*");
|
ProducesRequestCondition condition = new ProducesRequestCondition("text/*");
|
||||||
|
|
||||||
assertNotNull(condition.getMatchingCondition(exchange));
|
assertNotNull(condition.getMatchingCondition(exchange));
|
||||||
|
@ -71,7 +71,7 @@ public class ProducesRequestConditionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void matchMultiple() throws Exception {
|
public void matchMultiple() throws Exception {
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/").header("Accept", "text/plain").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("Accept", "text/plain").build());
|
||||||
ProducesRequestCondition condition = new ProducesRequestCondition("text/plain", "application/xml");
|
ProducesRequestCondition condition = new ProducesRequestCondition("text/plain", "application/xml");
|
||||||
|
|
||||||
assertNotNull(condition.getMatchingCondition(exchange));
|
assertNotNull(condition.getMatchingCondition(exchange));
|
||||||
|
@ -79,7 +79,7 @@ public class ProducesRequestConditionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void matchSingle() throws Exception {
|
public void matchSingle() throws Exception {
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/").header("Accept", "application/xml").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("Accept", "application/xml").build());
|
||||||
ProducesRequestCondition condition = new ProducesRequestCondition("text/plain");
|
ProducesRequestCondition condition = new ProducesRequestCondition("text/plain");
|
||||||
|
|
||||||
assertNull(condition.getMatchingCondition(exchange));
|
assertNull(condition.getMatchingCondition(exchange));
|
||||||
|
@ -87,7 +87,7 @@ public class ProducesRequestConditionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void matchParseError() throws Exception {
|
public void matchParseError() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("/").header("Accept", "bogus").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("Accept", "bogus").build());
|
||||||
ProducesRequestCondition condition = new ProducesRequestCondition("text/plain");
|
ProducesRequestCondition condition = new ProducesRequestCondition("text/plain");
|
||||||
|
|
||||||
assertNull(condition.getMatchingCondition(exchange));
|
assertNull(condition.getMatchingCondition(exchange));
|
||||||
|
@ -95,7 +95,7 @@ public class ProducesRequestConditionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void matchParseErrorWithNegation() throws Exception {
|
public void matchParseErrorWithNegation() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("/").header("Accept", "bogus").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("Accept", "bogus").build());
|
||||||
ProducesRequestCondition condition = new ProducesRequestCondition("!text/plain");
|
ProducesRequestCondition condition = new ProducesRequestCondition("!text/plain");
|
||||||
|
|
||||||
assertNull(condition.getMatchingCondition(exchange));
|
assertNull(condition.getMatchingCondition(exchange));
|
||||||
|
@ -107,7 +107,7 @@ public class ProducesRequestConditionTests {
|
||||||
ProducesRequestCondition xml = new ProducesRequestCondition("application/xml");
|
ProducesRequestCondition xml = new ProducesRequestCondition("application/xml");
|
||||||
ProducesRequestCondition none = new ProducesRequestCondition();
|
ProducesRequestCondition none = new ProducesRequestCondition();
|
||||||
|
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/").header("Accept", "application/xml, text/html").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("Accept", "application/xml, text/html").build());
|
||||||
|
|
||||||
assertTrue(html.compareTo(xml, exchange) > 0);
|
assertTrue(html.compareTo(xml, exchange) > 0);
|
||||||
assertTrue(xml.compareTo(html, exchange) < 0);
|
assertTrue(xml.compareTo(html, exchange) < 0);
|
||||||
|
@ -116,18 +116,21 @@ public class ProducesRequestConditionTests {
|
||||||
assertTrue(html.compareTo(none, exchange) < 0);
|
assertTrue(html.compareTo(none, exchange) < 0);
|
||||||
assertTrue(none.compareTo(html, exchange) > 0);
|
assertTrue(none.compareTo(html, exchange) > 0);
|
||||||
|
|
||||||
exchange = MockServerHttpRequest.get("/").header("Accept", "application/xml, text/*").toExchange();
|
exchange = MockServerWebExchange.from(
|
||||||
|
MockServerHttpRequest.get("/").header("Accept", "application/xml, text/*").build());
|
||||||
|
|
||||||
assertTrue(html.compareTo(xml, exchange) > 0);
|
assertTrue(html.compareTo(xml, exchange) > 0);
|
||||||
assertTrue(xml.compareTo(html, exchange) < 0);
|
assertTrue(xml.compareTo(html, exchange) < 0);
|
||||||
|
|
||||||
exchange = MockServerHttpRequest.get("/").header("Accept", "application/pdf").toExchange();
|
exchange = MockServerWebExchange.from(
|
||||||
|
MockServerHttpRequest.get("/").header("Accept", "application/pdf").build());
|
||||||
|
|
||||||
assertTrue(html.compareTo(xml, exchange) == 0);
|
assertTrue(html.compareTo(xml, exchange) == 0);
|
||||||
assertTrue(xml.compareTo(html, exchange) == 0);
|
assertTrue(xml.compareTo(html, exchange) == 0);
|
||||||
|
|
||||||
// See SPR-7000
|
// See SPR-7000
|
||||||
exchange = MockServerHttpRequest.get("/").header("Accept", "text/html;q=0.9,application/xml").toExchange();
|
exchange = MockServerWebExchange.from(
|
||||||
|
MockServerHttpRequest.get("/").header("Accept", "text/html;q=0.9,application/xml").build());
|
||||||
|
|
||||||
assertTrue(html.compareTo(xml, exchange) > 0);
|
assertTrue(html.compareTo(xml, exchange) > 0);
|
||||||
assertTrue(xml.compareTo(html, exchange) < 0);
|
assertTrue(xml.compareTo(html, exchange) < 0);
|
||||||
|
@ -135,7 +138,7 @@ public class ProducesRequestConditionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void compareToWithSingleExpression() throws Exception {
|
public void compareToWithSingleExpression() throws Exception {
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/").header("Accept", "text/plain").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("Accept", "text/plain").build());
|
||||||
|
|
||||||
ProducesRequestCondition condition1 = new ProducesRequestCondition("text/plain");
|
ProducesRequestCondition condition1 = new ProducesRequestCondition("text/plain");
|
||||||
ProducesRequestCondition condition2 = new ProducesRequestCondition("text/*");
|
ProducesRequestCondition condition2 = new ProducesRequestCondition("text/*");
|
||||||
|
@ -152,7 +155,7 @@ public class ProducesRequestConditionTests {
|
||||||
ProducesRequestCondition condition1 = new ProducesRequestCondition("*/*", "text/plain");
|
ProducesRequestCondition condition1 = new ProducesRequestCondition("*/*", "text/plain");
|
||||||
ProducesRequestCondition condition2 = new ProducesRequestCondition("text/*", "text/plain;q=0.7");
|
ProducesRequestCondition condition2 = new ProducesRequestCondition("text/*", "text/plain;q=0.7");
|
||||||
|
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/").header("Accept", "text/plain").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("Accept", "text/plain").build());
|
||||||
|
|
||||||
int result = condition1.compareTo(condition2, exchange);
|
int result = condition1.compareTo(condition2, exchange);
|
||||||
assertTrue("Invalid comparison result: " + result, result < 0);
|
assertTrue("Invalid comparison result: " + result, result < 0);
|
||||||
|
@ -166,7 +169,8 @@ public class ProducesRequestConditionTests {
|
||||||
ProducesRequestCondition condition1 = new ProducesRequestCondition("text/*", "text/plain");
|
ProducesRequestCondition condition1 = new ProducesRequestCondition("text/*", "text/plain");
|
||||||
ProducesRequestCondition condition2 = new ProducesRequestCondition("application/*", "application/xml");
|
ProducesRequestCondition condition2 = new ProducesRequestCondition("application/*", "application/xml");
|
||||||
|
|
||||||
ServerWebExchange exchange = get("/").header("Accept", "text/plain", "application/xml").toExchange();
|
ServerWebExchange exchange = MockServerWebExchange.from(
|
||||||
|
get("/").header("Accept", "text/plain", "application/xml").build());
|
||||||
|
|
||||||
int result = condition1.compareTo(condition2, exchange);
|
int result = condition1.compareTo(condition2, exchange);
|
||||||
assertTrue("Invalid comparison result: " + result, result < 0);
|
assertTrue("Invalid comparison result: " + result, result < 0);
|
||||||
|
@ -174,7 +178,8 @@ public class ProducesRequestConditionTests {
|
||||||
result = condition2.compareTo(condition1, exchange);
|
result = condition2.compareTo(condition1, exchange);
|
||||||
assertTrue("Invalid comparison result: " + result, result > 0);
|
assertTrue("Invalid comparison result: " + result, result > 0);
|
||||||
|
|
||||||
exchange = MockServerHttpRequest.get("/").header("Accept", "application/xml", "text/plain").toExchange();
|
exchange = MockServerWebExchange.from(
|
||||||
|
MockServerHttpRequest.get("/").header("Accept", "application/xml", "text/plain").build());
|
||||||
|
|
||||||
result = condition1.compareTo(condition2, exchange);
|
result = condition1.compareTo(condition2, exchange);
|
||||||
assertTrue("Invalid comparison result: " + result, result > 0);
|
assertTrue("Invalid comparison result: " + result, result > 0);
|
||||||
|
@ -187,7 +192,7 @@ public class ProducesRequestConditionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void compareToMediaTypeAll() throws Exception {
|
public void compareToMediaTypeAll() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("/").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||||
|
|
||||||
ProducesRequestCondition condition1 = new ProducesRequestCondition();
|
ProducesRequestCondition condition1 = new ProducesRequestCondition();
|
||||||
ProducesRequestCondition condition2 = new ProducesRequestCondition("application/json");
|
ProducesRequestCondition condition2 = new ProducesRequestCondition("application/json");
|
||||||
|
@ -203,7 +208,8 @@ public class ProducesRequestConditionTests {
|
||||||
assertTrue(condition1.compareTo(condition2, exchange) < 0);
|
assertTrue(condition1.compareTo(condition2, exchange) < 0);
|
||||||
assertTrue(condition2.compareTo(condition1, exchange) > 0);
|
assertTrue(condition2.compareTo(condition1, exchange) > 0);
|
||||||
|
|
||||||
exchange = MockServerHttpRequest.get("/").header("Accept", "*/*").toExchange();
|
exchange = MockServerWebExchange.from(
|
||||||
|
MockServerHttpRequest.get("/").header("Accept", "*/*").build());
|
||||||
|
|
||||||
condition1 = new ProducesRequestCondition();
|
condition1 = new ProducesRequestCondition();
|
||||||
condition2 = new ProducesRequestCondition("application/json");
|
condition2 = new ProducesRequestCondition("application/json");
|
||||||
|
@ -222,7 +228,7 @@ public class ProducesRequestConditionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void compareToMediaTypeAllWithParameter() throws Exception {
|
public void compareToMediaTypeAllWithParameter() throws Exception {
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/").header("Accept", "*/*;q=0.9").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("Accept", "*/*;q=0.9").build());
|
||||||
|
|
||||||
ProducesRequestCondition condition1 = new ProducesRequestCondition();
|
ProducesRequestCondition condition1 = new ProducesRequestCondition();
|
||||||
ProducesRequestCondition condition2 = new ProducesRequestCondition("application/json");
|
ProducesRequestCondition condition2 = new ProducesRequestCondition("application/json");
|
||||||
|
@ -233,7 +239,7 @@ public class ProducesRequestConditionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void compareToEqualMatch() throws Exception {
|
public void compareToEqualMatch() throws Exception {
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/").header("Accept", "text/*").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("Accept", "text/*").build());
|
||||||
|
|
||||||
ProducesRequestCondition condition1 = new ProducesRequestCondition("text/plain");
|
ProducesRequestCondition condition1 = new ProducesRequestCondition("text/plain");
|
||||||
ProducesRequestCondition condition2 = new ProducesRequestCondition("text/xhtml");
|
ProducesRequestCondition condition2 = new ProducesRequestCondition("text/xhtml");
|
||||||
|
@ -274,7 +280,7 @@ public class ProducesRequestConditionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getMatchingCondition() throws Exception {
|
public void getMatchingCondition() throws Exception {
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/").header("Accept", "text/plain").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("Accept", "text/plain").build());
|
||||||
|
|
||||||
ProducesRequestCondition condition = new ProducesRequestCondition("text/plain", "application/xml");
|
ProducesRequestCondition condition = new ProducesRequestCondition("text/plain", "application/xml");
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ package org.springframework.web.reactive.result.condition;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerWebExchange;
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
@ -34,7 +34,7 @@ import static org.junit.Assert.assertSame;
|
||||||
*/
|
*/
|
||||||
public class RequestConditionHolderTests {
|
public class RequestConditionHolderTests {
|
||||||
|
|
||||||
private final MockServerWebExchange exchange = MockServerHttpRequest.get("/").toExchange();
|
private final MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -29,7 +29,7 @@ import org.junit.rules.ExpectedException;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerWebExchange;
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
import org.springframework.web.reactive.result.method.RequestMappingInfo;
|
import org.springframework.web.reactive.result.method.RequestMappingInfo;
|
||||||
import org.springframework.web.server.ServerWebExchange;
|
import org.springframework.web.server.ServerWebExchange;
|
||||||
|
@ -87,7 +87,7 @@ public class RequestMappingInfoTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void matchPatternsCondition() {
|
public void matchPatternsCondition() {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("/foo").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/foo").build());
|
||||||
|
|
||||||
RequestMappingInfo info = paths("/foo*", "/bar").build();
|
RequestMappingInfo info = paths("/foo*", "/bar").build();
|
||||||
RequestMappingInfo expected = paths("/foo*").build();
|
RequestMappingInfo expected = paths("/foo*").build();
|
||||||
|
@ -102,7 +102,8 @@ public class RequestMappingInfoTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void matchParamsCondition() {
|
public void matchParamsCondition() {
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/foo?foo=bar").toExchange();
|
MockServerHttpRequest request = MockServerHttpRequest.get("/foo?foo=bar").build();
|
||||||
|
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
|
|
||||||
RequestMappingInfo info = paths("/foo").params("foo=bar").build();
|
RequestMappingInfo info = paths("/foo").params("foo=bar").build();
|
||||||
RequestMappingInfo match = info.getMatchingCondition(exchange);
|
RequestMappingInfo match = info.getMatchingCondition(exchange);
|
||||||
|
@ -117,7 +118,8 @@ public class RequestMappingInfoTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void matchHeadersCondition() {
|
public void matchHeadersCondition() {
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/foo").header("foo", "bar").toExchange();
|
MockServerHttpRequest request = MockServerHttpRequest.get("/foo").header("foo", "bar").build();
|
||||||
|
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
|
|
||||||
RequestMappingInfo info = paths("/foo").headers("foo=bar").build();
|
RequestMappingInfo info = paths("/foo").headers("foo=bar").build();
|
||||||
RequestMappingInfo match = info.getMatchingCondition(exchange);
|
RequestMappingInfo match = info.getMatchingCondition(exchange);
|
||||||
|
@ -132,7 +134,8 @@ public class RequestMappingInfoTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void matchConsumesCondition() {
|
public void matchConsumesCondition() {
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.post("/foo").contentType(MediaType.TEXT_PLAIN).toExchange();
|
MockServerHttpRequest request = MockServerHttpRequest.post("/foo").contentType(MediaType.TEXT_PLAIN).build();
|
||||||
|
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
|
|
||||||
RequestMappingInfo info = paths("/foo").consumes("text/plain").build();
|
RequestMappingInfo info = paths("/foo").consumes("text/plain").build();
|
||||||
RequestMappingInfo match = info.getMatchingCondition(exchange);
|
RequestMappingInfo match = info.getMatchingCondition(exchange);
|
||||||
|
@ -147,7 +150,8 @@ public class RequestMappingInfoTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void matchProducesCondition() {
|
public void matchProducesCondition() {
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/foo").accept(MediaType.TEXT_PLAIN).toExchange();
|
MockServerHttpRequest request = MockServerHttpRequest.get("/foo").accept(MediaType.TEXT_PLAIN).build();
|
||||||
|
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
|
|
||||||
RequestMappingInfo info = paths("/foo").produces("text/plain").build();
|
RequestMappingInfo info = paths("/foo").produces("text/plain").build();
|
||||||
RequestMappingInfo match = info.getMatchingCondition(exchange);
|
RequestMappingInfo match = info.getMatchingCondition(exchange);
|
||||||
|
@ -162,7 +166,8 @@ public class RequestMappingInfoTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void matchCustomCondition() {
|
public void matchCustomCondition() {
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/foo?foo=bar").toExchange();
|
MockServerHttpRequest request = MockServerHttpRequest.get("/foo?foo=bar").build();
|
||||||
|
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
|
|
||||||
RequestMappingInfo info = paths("/foo").params("foo=bar").build();
|
RequestMappingInfo info = paths("/foo").params("foo=bar").build();
|
||||||
RequestMappingInfo match = info.getMatchingCondition(exchange);
|
RequestMappingInfo match = info.getMatchingCondition(exchange);
|
||||||
|
@ -183,7 +188,7 @@ public class RequestMappingInfoTests {
|
||||||
RequestMappingInfo oneMethod = paths().methods(RequestMethod.GET).build();
|
RequestMappingInfo oneMethod = paths().methods(RequestMethod.GET).build();
|
||||||
RequestMappingInfo oneMethodOneParam = paths().methods(RequestMethod.GET).params("foo").build();
|
RequestMappingInfo oneMethodOneParam = paths().methods(RequestMethod.GET).params("foo").build();
|
||||||
|
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/foo").toExchange();
|
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/foo").build());
|
||||||
Comparator<RequestMappingInfo> comparator = (info, otherInfo) -> info.compareTo(otherInfo, exchange);
|
Comparator<RequestMappingInfo> comparator = (info, otherInfo) -> info.compareTo(otherInfo, exchange);
|
||||||
|
|
||||||
List<RequestMappingInfo> list = asList(none, oneMethod, oneMethodOneParam);
|
List<RequestMappingInfo> list = asList(none, oneMethod, oneMethodOneParam);
|
||||||
|
@ -279,10 +284,10 @@ public class RequestMappingInfoTests {
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Ignore
|
||||||
public void preFlightRequest() throws Exception {
|
public void preFlightRequest() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.options("/foo")
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.options("/foo")
|
||||||
.header("Origin", "http://domain.com")
|
.header("Origin", "http://domain.com")
|
||||||
.header(HttpHeaders.ACCESS_CONTROL_REQUEST_HEADERS, "POST")
|
.header(HttpHeaders.ACCESS_CONTROL_REQUEST_HEADERS, "POST")
|
||||||
.toExchange();
|
.build());
|
||||||
|
|
||||||
RequestMappingInfo info = paths("/foo").methods(RequestMethod.POST).build();
|
RequestMappingInfo info = paths("/foo").methods(RequestMethod.POST).build();
|
||||||
RequestMappingInfo match = info.getMatchingCondition(exchange);
|
RequestMappingInfo match = info.getMatchingCondition(exchange);
|
||||||
|
|
|
@ -25,6 +25,7 @@ import org.junit.Test;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.HttpMethod;
|
import org.springframework.http.HttpMethod;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
import org.springframework.web.server.ServerWebExchange;
|
import org.springframework.web.server.ServerWebExchange;
|
||||||
|
|
||||||
|
@ -138,7 +139,7 @@ public class RequestMethodsRequestConditionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
private ServerWebExchange getExchange(String method) throws URISyntaxException {
|
private ServerWebExchange getExchange(String method) throws URISyntaxException {
|
||||||
return MockServerHttpRequest.method(HttpMethod.valueOf(method), "/").toExchange();
|
return MockServerWebExchange.from(MockServerHttpRequest.method(HttpMethod.valueOf(method), "/").build());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ import reactor.test.StepVerifier;
|
||||||
|
|
||||||
import org.springframework.http.server.PathContainer;
|
import org.springframework.http.server.PathContainer;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.method.HandlerMethod;
|
import org.springframework.web.method.HandlerMethod;
|
||||||
|
@ -74,7 +75,8 @@ public class HandlerMethodMappingTests {
|
||||||
public void directMatch() throws Exception {
|
public void directMatch() throws Exception {
|
||||||
String key = "foo";
|
String key = "foo";
|
||||||
this.mapping.registerMapping(key, this.handler, this.method1);
|
this.mapping.registerMapping(key, this.handler, this.method1);
|
||||||
Mono<Object> result = this.mapping.getHandler(MockServerHttpRequest.get(key).toExchange());
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get(key).build());
|
||||||
|
Mono<Object> result = this.mapping.getHandler(exchange);
|
||||||
|
|
||||||
assertEquals(this.method1, ((HandlerMethod) result.block()).getMethod());
|
assertEquals(this.method1, ((HandlerMethod) result.block()).getMethod());
|
||||||
}
|
}
|
||||||
|
@ -84,7 +86,8 @@ public class HandlerMethodMappingTests {
|
||||||
this.mapping.registerMapping("/fo*", this.handler, this.method1);
|
this.mapping.registerMapping("/fo*", this.handler, this.method1);
|
||||||
this.mapping.registerMapping("/f*", this.handler, this.method2);
|
this.mapping.registerMapping("/f*", this.handler, this.method2);
|
||||||
|
|
||||||
Mono<Object> result = this.mapping.getHandler(MockServerHttpRequest.get("/foo").toExchange());
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/foo").build());
|
||||||
|
Mono<Object> result = this.mapping.getHandler(exchange);
|
||||||
assertEquals(this.method1, ((HandlerMethod) result.block()).getMethod());
|
assertEquals(this.method1, ((HandlerMethod) result.block()).getMethod());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,7 +95,8 @@ public class HandlerMethodMappingTests {
|
||||||
public void ambiguousMatch() throws Exception {
|
public void ambiguousMatch() throws Exception {
|
||||||
this.mapping.registerMapping("/f?o", this.handler, this.method1);
|
this.mapping.registerMapping("/f?o", this.handler, this.method1);
|
||||||
this.mapping.registerMapping("/fo?", this.handler, this.method2);
|
this.mapping.registerMapping("/fo?", this.handler, this.method2);
|
||||||
Mono<Object> result = this.mapping.getHandler(MockServerHttpRequest.get("/foo").toExchange());
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/foo").build());
|
||||||
|
Mono<Object> result = this.mapping.getHandler(exchange);
|
||||||
|
|
||||||
StepVerifier.create(result).expectError(IllegalStateException.class).verify();
|
StepVerifier.create(result).expectError(IllegalStateException.class).verify();
|
||||||
}
|
}
|
||||||
|
@ -124,12 +128,12 @@ public class HandlerMethodMappingTests {
|
||||||
public void unregisterMapping() throws Exception {
|
public void unregisterMapping() throws Exception {
|
||||||
String key = "foo";
|
String key = "foo";
|
||||||
this.mapping.registerMapping(key, this.handler, this.method1);
|
this.mapping.registerMapping(key, this.handler, this.method1);
|
||||||
Mono<Object> result = this.mapping.getHandler(MockServerHttpRequest.get(key).toExchange());
|
Mono<Object> result = this.mapping.getHandler(MockServerWebExchange.from(MockServerHttpRequest.get(key).build()));
|
||||||
|
|
||||||
assertNotNull(result.block());
|
assertNotNull(result.block());
|
||||||
|
|
||||||
this.mapping.unregisterMapping(key);
|
this.mapping.unregisterMapping(key);
|
||||||
result = this.mapping.getHandler(MockServerHttpRequest.get(key).toExchange());
|
result = this.mapping.getHandler(MockServerWebExchange.from(MockServerHttpRequest.get(key).build()));
|
||||||
|
|
||||||
assertNull(result.block());
|
assertNull(result.block());
|
||||||
assertThat(this.mapping.getMappingRegistry().getMappings().keySet(), Matchers.not(Matchers.contains(key)));
|
assertThat(this.mapping.getMappingRegistry().getMappings().keySet(), Matchers.not(Matchers.contains(key)));
|
||||||
|
|
|
@ -25,7 +25,7 @@ import reactor.test.StepVerifier;
|
||||||
|
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerWebExchange;
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||||
import org.springframework.web.reactive.BindingContext;
|
import org.springframework.web.reactive.BindingContext;
|
||||||
import org.springframework.web.reactive.HandlerResult;
|
import org.springframework.web.reactive.HandlerResult;
|
||||||
|
@ -46,7 +46,7 @@ import static org.springframework.web.method.ResolvableMethod.*;
|
||||||
public class InvocableHandlerMethodTests {
|
public class InvocableHandlerMethodTests {
|
||||||
|
|
||||||
private final MockServerWebExchange exchange =
|
private final MockServerWebExchange exchange =
|
||||||
MockServerHttpRequest.get("http://localhost:8080/path").toExchange();
|
MockServerWebExchange.from(MockServerHttpRequest.get("http://localhost:8080/path").build());
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -36,6 +36,7 @@ import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.HttpMethod;
|
import org.springframework.http.HttpMethod;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.util.ClassUtils;
|
import org.springframework.util.ClassUtils;
|
||||||
import org.springframework.util.MultiValueMap;
|
import org.springframework.util.MultiValueMap;
|
||||||
|
@ -63,6 +64,8 @@ import static org.junit.Assert.assertSame;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.Assert.assertThat;
|
||||||
import static org.springframework.mock.http.server.reactive.test.MockServerHttpRequest.get;
|
import static org.springframework.mock.http.server.reactive.test.MockServerHttpRequest.get;
|
||||||
import static org.springframework.mock.http.server.reactive.test.MockServerHttpRequest.method;
|
import static org.springframework.mock.http.server.reactive.test.MockServerHttpRequest.method;
|
||||||
|
import static org.springframework.mock.http.server.reactive.test.MockServerHttpRequest.post;
|
||||||
|
import static org.springframework.mock.http.server.reactive.test.MockServerHttpRequest.put;
|
||||||
import static org.springframework.web.bind.annotation.RequestMethod.GET;
|
import static org.springframework.web.bind.annotation.RequestMethod.GET;
|
||||||
import static org.springframework.web.bind.annotation.RequestMethod.HEAD;
|
import static org.springframework.web.bind.annotation.RequestMethod.HEAD;
|
||||||
import static org.springframework.web.bind.annotation.RequestMethod.OPTIONS;
|
import static org.springframework.web.bind.annotation.RequestMethod.OPTIONS;
|
||||||
|
@ -95,7 +98,7 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||||
@Test
|
@Test
|
||||||
public void getHandlerDirectMatch() throws Exception {
|
public void getHandlerDirectMatch() throws Exception {
|
||||||
Method expected = on(TestController.class).annot(getMapping("/foo").params()).resolveMethod();
|
Method expected = on(TestController.class).annot(getMapping("/foo").params()).resolveMethod();
|
||||||
ServerWebExchange exchange = get("/foo").toExchange();
|
ServerWebExchange exchange = MockServerWebExchange.from(get("/foo").build());
|
||||||
HandlerMethod hm = (HandlerMethod) this.handlerMapping.getHandler(exchange).block();
|
HandlerMethod hm = (HandlerMethod) this.handlerMapping.getHandler(exchange).block();
|
||||||
|
|
||||||
assertEquals(expected, hm.getMethod());
|
assertEquals(expected, hm.getMethod());
|
||||||
|
@ -104,7 +107,7 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||||
@Test
|
@Test
|
||||||
public void getHandlerGlobMatch() throws Exception {
|
public void getHandlerGlobMatch() throws Exception {
|
||||||
Method expected = on(TestController.class).annot(requestMapping("/ba*").method(GET, HEAD)).resolveMethod();
|
Method expected = on(TestController.class).annot(requestMapping("/ba*").method(GET, HEAD)).resolveMethod();
|
||||||
ServerWebExchange exchange = get("/bar").toExchange();
|
ServerWebExchange exchange = MockServerWebExchange.from(get("/bar").build());
|
||||||
HandlerMethod hm = (HandlerMethod) this.handlerMapping.getHandler(exchange).block();
|
HandlerMethod hm = (HandlerMethod) this.handlerMapping.getHandler(exchange).block();
|
||||||
|
|
||||||
assertEquals(expected, hm.getMethod());
|
assertEquals(expected, hm.getMethod());
|
||||||
|
@ -113,11 +116,11 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||||
@Test
|
@Test
|
||||||
public void getHandlerEmptyPathMatch() throws Exception {
|
public void getHandlerEmptyPathMatch() throws Exception {
|
||||||
Method expected = on(TestController.class).annot(requestMapping("")).resolveMethod();
|
Method expected = on(TestController.class).annot(requestMapping("")).resolveMethod();
|
||||||
ServerWebExchange exchange = get("").toExchange();
|
ServerWebExchange exchange = MockServerWebExchange.from(get("").build());
|
||||||
HandlerMethod hm = (HandlerMethod) this.handlerMapping.getHandler(exchange).block();
|
HandlerMethod hm = (HandlerMethod) this.handlerMapping.getHandler(exchange).block();
|
||||||
assertEquals(expected, hm.getMethod());
|
assertEquals(expected, hm.getMethod());
|
||||||
|
|
||||||
exchange = get("/").toExchange();
|
exchange = MockServerWebExchange.from(get("/").build());
|
||||||
hm = (HandlerMethod) this.handlerMapping.getHandler(exchange).block();
|
hm = (HandlerMethod) this.handlerMapping.getHandler(exchange).block();
|
||||||
assertEquals(expected, hm.getMethod());
|
assertEquals(expected, hm.getMethod());
|
||||||
}
|
}
|
||||||
|
@ -125,7 +128,7 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||||
@Test
|
@Test
|
||||||
public void getHandlerBestMatch() throws Exception {
|
public void getHandlerBestMatch() throws Exception {
|
||||||
Method expected = on(TestController.class).annot(getMapping("/foo").params("p")).resolveMethod();
|
Method expected = on(TestController.class).annot(getMapping("/foo").params("p")).resolveMethod();
|
||||||
ServerWebExchange exchange = get("/foo?p=anything").toExchange();
|
ServerWebExchange exchange = MockServerWebExchange.from(get("/foo?p=anything").build());
|
||||||
HandlerMethod hm = (HandlerMethod) this.handlerMapping.getHandler(exchange).block();
|
HandlerMethod hm = (HandlerMethod) this.handlerMapping.getHandler(exchange).block();
|
||||||
|
|
||||||
assertEquals(expected, hm.getMethod());
|
assertEquals(expected, hm.getMethod());
|
||||||
|
@ -133,7 +136,7 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getHandlerRequestMethodNotAllowed() throws Exception {
|
public void getHandlerRequestMethodNotAllowed() throws Exception {
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.post("/bar").toExchange();
|
ServerWebExchange exchange = MockServerWebExchange.from(post("/bar").build());
|
||||||
Mono<Object> mono = this.handlerMapping.getHandler(exchange);
|
Mono<Object> mono = this.handlerMapping.getHandler(exchange);
|
||||||
|
|
||||||
assertError(mono, MethodNotAllowedException.class,
|
assertError(mono, MethodNotAllowedException.class,
|
||||||
|
@ -142,7 +145,7 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||||
|
|
||||||
@Test // SPR-9603
|
@Test // SPR-9603
|
||||||
public void getHandlerRequestMethodMatchFalsePositive() throws Exception {
|
public void getHandlerRequestMethodMatchFalsePositive() throws Exception {
|
||||||
ServerWebExchange exchange = get("/users").accept(MediaType.APPLICATION_XML).toExchange();
|
ServerWebExchange exchange = MockServerWebExchange.from(get("/users").accept(MediaType.APPLICATION_XML).build());
|
||||||
this.handlerMapping.registerHandler(new UserController());
|
this.handlerMapping.registerHandler(new UserController());
|
||||||
Mono<Object> mono = this.handlerMapping.getHandler(exchange);
|
Mono<Object> mono = this.handlerMapping.getHandler(exchange);
|
||||||
|
|
||||||
|
@ -160,7 +163,8 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getHandlerTestInvalidContentType() throws Exception {
|
public void getHandlerTestInvalidContentType() throws Exception {
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.put("/person/1").header("content-type", "bogus").toExchange();
|
MockServerHttpRequest request = put("/person/1").header("content-type", "bogus").build();
|
||||||
|
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
Mono<Object> mono = this.handlerMapping.getHandler(exchange);
|
Mono<Object> mono = this.handlerMapping.getHandler(exchange);
|
||||||
|
|
||||||
assertError(mono, UnsupportedMediaTypeStatusException.class,
|
assertError(mono, UnsupportedMediaTypeStatusException.class,
|
||||||
|
@ -176,7 +180,7 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||||
|
|
||||||
@Test // SPR-12854
|
@Test // SPR-12854
|
||||||
public void getHandlerTestRequestParamMismatch() throws Exception {
|
public void getHandlerTestRequestParamMismatch() throws Exception {
|
||||||
ServerWebExchange exchange = get("/params").toExchange();
|
ServerWebExchange exchange = MockServerWebExchange.from(get("/params").build());
|
||||||
Mono<Object> mono = this.handlerMapping.getHandler(exchange);
|
Mono<Object> mono = this.handlerMapping.getHandler(exchange);
|
||||||
assertError(mono, ServerWebInputException.class, ex -> {
|
assertError(mono, ServerWebInputException.class, ex -> {
|
||||||
assertThat(ex.getReason(), containsString("[foo=bar]"));
|
assertThat(ex.getReason(), containsString("[foo=bar]"));
|
||||||
|
@ -194,13 +198,13 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getHandlerProducibleMediaTypesAttribute() throws Exception {
|
public void getHandlerProducibleMediaTypesAttribute() throws Exception {
|
||||||
ServerWebExchange exchange = get("/content").accept(MediaType.APPLICATION_XML).toExchange();
|
ServerWebExchange exchange = MockServerWebExchange.from(get("/content").accept(MediaType.APPLICATION_XML).build());
|
||||||
this.handlerMapping.getHandler(exchange).block();
|
this.handlerMapping.getHandler(exchange).block();
|
||||||
|
|
||||||
String name = HandlerMapping.PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE;
|
String name = HandlerMapping.PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE;
|
||||||
assertEquals(Collections.singleton(MediaType.APPLICATION_XML), exchange.getAttributes().get(name));
|
assertEquals(Collections.singleton(MediaType.APPLICATION_XML), exchange.getAttributes().get(name));
|
||||||
|
|
||||||
exchange = get("/content").accept(MediaType.APPLICATION_JSON).toExchange();
|
exchange = MockServerWebExchange.from(get("/content").accept(MediaType.APPLICATION_JSON).build());
|
||||||
this.handlerMapping.getHandler(exchange).block();
|
this.handlerMapping.getHandler(exchange).block();
|
||||||
|
|
||||||
assertNull("Negated expression shouldn't be listed as producible type",
|
assertNull("Negated expression shouldn't be listed as producible type",
|
||||||
|
@ -210,7 +214,7 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void handleMatchUriTemplateVariables() throws Exception {
|
public void handleMatchUriTemplateVariables() throws Exception {
|
||||||
ServerWebExchange exchange = get("/1/2").toExchange();
|
ServerWebExchange exchange = MockServerWebExchange.from(get("/1/2").build());
|
||||||
|
|
||||||
RequestMappingInfo key = paths("/{path1}/{path2}").build();
|
RequestMappingInfo key = paths("/{path1}/{path2}").build();
|
||||||
this.handlerMapping.handleMatch(key, handlerMethod, exchange);
|
this.handlerMapping.handleMatch(key, handlerMethod, exchange);
|
||||||
|
@ -227,7 +231,7 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||||
public void handleMatchUriTemplateVariablesDecode() throws Exception {
|
public void handleMatchUriTemplateVariablesDecode() throws Exception {
|
||||||
RequestMappingInfo key = paths("/{group}/{identifier}").build();
|
RequestMappingInfo key = paths("/{group}/{identifier}").build();
|
||||||
URI url = URI.create("/group/a%2Fb");
|
URI url = URI.create("/group/a%2Fb");
|
||||||
ServerWebExchange exchange = method(HttpMethod.GET, url).toExchange();
|
ServerWebExchange exchange = MockServerWebExchange.from(method(HttpMethod.GET, url).build());
|
||||||
|
|
||||||
this.handlerMapping.handleMatch(key, handlerMethod, exchange);
|
this.handlerMapping.handleMatch(key, handlerMethod, exchange);
|
||||||
|
|
||||||
|
@ -243,7 +247,7 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||||
@Test
|
@Test
|
||||||
public void handleMatchBestMatchingPatternAttribute() throws Exception {
|
public void handleMatchBestMatchingPatternAttribute() throws Exception {
|
||||||
RequestMappingInfo key = paths("/{path1}/2", "/**").build();
|
RequestMappingInfo key = paths("/{path1}/2", "/**").build();
|
||||||
ServerWebExchange exchange = get("/1/2").toExchange();
|
ServerWebExchange exchange = MockServerWebExchange.from(get("/1/2").build());
|
||||||
this.handlerMapping.handleMatch(key, handlerMethod, exchange);
|
this.handlerMapping.handleMatch(key, handlerMethod, exchange);
|
||||||
|
|
||||||
PathPattern bestMatch = (PathPattern) exchange.getAttributes().get(BEST_MATCHING_PATTERN_ATTRIBUTE);
|
PathPattern bestMatch = (PathPattern) exchange.getAttributes().get(BEST_MATCHING_PATTERN_ATTRIBUTE);
|
||||||
|
@ -256,7 +260,7 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||||
@Test
|
@Test
|
||||||
public void handleMatchBestMatchingPatternAttributeNoPatternsDefined() throws Exception {
|
public void handleMatchBestMatchingPatternAttributeNoPatternsDefined() throws Exception {
|
||||||
RequestMappingInfo key = paths().build();
|
RequestMappingInfo key = paths().build();
|
||||||
ServerWebExchange exchange = get("/1/2").toExchange();
|
ServerWebExchange exchange = MockServerWebExchange.from(get("/1/2").build());
|
||||||
this.handlerMapping.handleMatch(key, handlerMethod, exchange);
|
this.handlerMapping.handleMatch(key, handlerMethod, exchange);
|
||||||
|
|
||||||
PathPattern bestMatch = (PathPattern) exchange.getAttributes().get(BEST_MATCHING_PATTERN_ATTRIBUTE);
|
PathPattern bestMatch = (PathPattern) exchange.getAttributes().get(BEST_MATCHING_PATTERN_ATTRIBUTE);
|
||||||
|
@ -268,7 +272,7 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||||
MultiValueMap<String, String> matrixVariables;
|
MultiValueMap<String, String> matrixVariables;
|
||||||
Map<String, String> uriVariables;
|
Map<String, String> uriVariables;
|
||||||
|
|
||||||
ServerWebExchange exchange = get("/cars;colors=red,blue,green;year=2012").toExchange();
|
ServerWebExchange exchange = MockServerWebExchange.from(get("/cars;colors=red,blue,green;year=2012").build());
|
||||||
handleMatch(exchange, "/{cars}");
|
handleMatch(exchange, "/{cars}");
|
||||||
|
|
||||||
matrixVariables = getMatrixVariables(exchange, "cars");
|
matrixVariables = getMatrixVariables(exchange, "cars");
|
||||||
|
@ -282,7 +286,8 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void handleMatchMatrixVariablesDecoding() throws Exception {
|
public void handleMatchMatrixVariablesDecoding() throws Exception {
|
||||||
ServerWebExchange exchange = method(HttpMethod.GET, URI.create("/path;mvar=a%2fb")).toExchange();
|
MockServerHttpRequest request = method(HttpMethod.GET, URI.create("/path;mvar=a%2fb")).build();
|
||||||
|
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
handleMatch(exchange, "/{filter}");
|
handleMatch(exchange, "/{filter}");
|
||||||
|
|
||||||
MultiValueMap<String, String> matrixVariables = getMatrixVariables(exchange, "filter");
|
MultiValueMap<String, String> matrixVariables = getMatrixVariables(exchange, "filter");
|
||||||
|
@ -305,7 +310,8 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void testHttpMediaTypeNotSupportedException(String url) throws Exception {
|
private void testHttpMediaTypeNotSupportedException(String url) throws Exception {
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.put(url).contentType(MediaType.APPLICATION_JSON).toExchange();
|
MockServerHttpRequest request = put(url).contentType(MediaType.APPLICATION_JSON).build();
|
||||||
|
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
Mono<Object> mono = this.handlerMapping.getHandler(exchange);
|
Mono<Object> mono = this.handlerMapping.getHandler(exchange);
|
||||||
|
|
||||||
assertError(mono, UnsupportedMediaTypeStatusException.class, ex ->
|
assertError(mono, UnsupportedMediaTypeStatusException.class, ex ->
|
||||||
|
@ -315,7 +321,7 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void testHttpOptions(String requestURI, Set<HttpMethod> allowedMethods) throws Exception {
|
private void testHttpOptions(String requestURI, Set<HttpMethod> allowedMethods) throws Exception {
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.options(requestURI).toExchange();
|
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.options(requestURI).build());
|
||||||
HandlerMethod handlerMethod = (HandlerMethod) this.handlerMapping.getHandler(exchange).block();
|
HandlerMethod handlerMethod = (HandlerMethod) this.handlerMapping.getHandler(exchange).block();
|
||||||
|
|
||||||
BindingContext bindingContext = new BindingContext();
|
BindingContext bindingContext = new BindingContext();
|
||||||
|
@ -332,7 +338,7 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void testMediaTypeNotAcceptable(String url) throws Exception {
|
private void testMediaTypeNotAcceptable(String url) throws Exception {
|
||||||
ServerWebExchange exchange = get(url).accept(MediaType.APPLICATION_JSON).toExchange();
|
ServerWebExchange exchange = MockServerWebExchange.from(get(url).accept(MediaType.APPLICATION_JSON).build());
|
||||||
Mono<Object> mono = this.handlerMapping.getHandler(exchange);
|
Mono<Object> mono = this.handlerMapping.getHandler(exchange);
|
||||||
|
|
||||||
assertError(mono, NotAcceptableStatusException.class, ex ->
|
assertError(mono, NotAcceptableStatusException.class, ex ->
|
||||||
|
|
|
@ -28,7 +28,7 @@ import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.core.annotation.Order;
|
import org.springframework.core.annotation.Order;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerWebExchange;
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.util.ClassUtils;
|
import org.springframework.util.ClassUtils;
|
||||||
|
@ -53,7 +53,8 @@ import static org.mockito.Mockito.mock;
|
||||||
*/
|
*/
|
||||||
public class ControllerAdviceTests {
|
public class ControllerAdviceTests {
|
||||||
|
|
||||||
private final MockServerWebExchange exchange = MockServerHttpRequest.get("/").toExchange();
|
private final MockServerWebExchange exchange =
|
||||||
|
MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -29,11 +29,10 @@ import org.springframework.core.ReactiveAdapterRegistry;
|
||||||
import org.springframework.core.annotation.SynthesizingMethodParameter;
|
import org.springframework.core.annotation.SynthesizingMethodParameter;
|
||||||
import org.springframework.http.HttpCookie;
|
import org.springframework.http.HttpCookie;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerWebExchange;
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.util.ReflectionUtils;
|
import org.springframework.util.ReflectionUtils;
|
||||||
import org.springframework.web.bind.annotation.CookieValue;
|
import org.springframework.web.bind.annotation.CookieValue;
|
||||||
import org.springframework.web.reactive.BindingContext;
|
import org.springframework.web.reactive.BindingContext;
|
||||||
import org.springframework.web.server.ServerWebExchange;
|
|
||||||
import org.springframework.web.server.ServerWebInputException;
|
import org.springframework.web.server.ServerWebInputException;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
@ -98,7 +97,7 @@ public class CookieValueMethodArgumentResolverTests {
|
||||||
@Test
|
@Test
|
||||||
public void resolveCookieArgument() {
|
public void resolveCookieArgument() {
|
||||||
HttpCookie expected = new HttpCookie("name", "foo");
|
HttpCookie expected = new HttpCookie("name", "foo");
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/").cookie(expected).toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").cookie(expected).build());
|
||||||
|
|
||||||
Mono<Object> mono = this.resolver.resolveArgument(
|
Mono<Object> mono = this.resolver.resolveArgument(
|
||||||
this.cookieParameter, this.bindingContext, exchange);
|
this.cookieParameter, this.bindingContext, exchange);
|
||||||
|
@ -109,7 +108,7 @@ public class CookieValueMethodArgumentResolverTests {
|
||||||
@Test
|
@Test
|
||||||
public void resolveCookieStringArgument() {
|
public void resolveCookieStringArgument() {
|
||||||
HttpCookie cookie = new HttpCookie("name", "foo");
|
HttpCookie cookie = new HttpCookie("name", "foo");
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/").cookie(cookie).toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").cookie(cookie).build());
|
||||||
|
|
||||||
Mono<Object> mono = this.resolver.resolveArgument(
|
Mono<Object> mono = this.resolver.resolveArgument(
|
||||||
this.cookieStringParameter, this.bindingContext, exchange);
|
this.cookieStringParameter, this.bindingContext, exchange);
|
||||||
|
@ -119,7 +118,7 @@ public class CookieValueMethodArgumentResolverTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveCookieDefaultValue() {
|
public void resolveCookieDefaultValue() {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("/").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||||
Object result = this.resolver.resolveArgument(this.cookieStringParameter, this.bindingContext, exchange).block();
|
Object result = this.resolver.resolveArgument(this.cookieStringParameter, this.bindingContext, exchange).block();
|
||||||
|
|
||||||
assertTrue(result instanceof String);
|
assertTrue(result instanceof String);
|
||||||
|
@ -128,7 +127,7 @@ public class CookieValueMethodArgumentResolverTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void notFound() {
|
public void notFound() {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("/").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||||
Mono<Object> mono = resolver.resolveArgument(this.cookieParameter, this.bindingContext, exchange);
|
Mono<Object> mono = resolver.resolveArgument(this.cookieParameter, this.bindingContext, exchange);
|
||||||
StepVerifier.create(mono)
|
StepVerifier.create(mono)
|
||||||
.expectNextCount(0)
|
.expectNextCount(0)
|
||||||
|
|
|
@ -27,7 +27,7 @@ import org.springframework.core.MethodParameter;
|
||||||
import org.springframework.core.ReactiveAdapterRegistry;
|
import org.springframework.core.ReactiveAdapterRegistry;
|
||||||
import org.springframework.core.ResolvableType;
|
import org.springframework.core.ResolvableType;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerWebExchange;
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.validation.BindingResult;
|
import org.springframework.validation.BindingResult;
|
||||||
import org.springframework.validation.Errors;
|
import org.springframework.validation.Errors;
|
||||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||||
|
@ -53,7 +53,7 @@ public class ErrorsArgumentResolverTests {
|
||||||
|
|
||||||
private BindingResult bindingResult;
|
private BindingResult bindingResult;
|
||||||
|
|
||||||
private MockServerWebExchange exchange = MockServerHttpRequest.post("/path").toExchange();
|
private MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.post("/path").build());
|
||||||
|
|
||||||
private final ResolvableMethod testMethod = ResolvableMethod.on(getClass()).named("handle").build();
|
private final ResolvableMethod testMethod = ResolvableMethod.on(getClass()).named("handle").build();
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
|
||||||
import org.springframework.core.MethodParameter;
|
import org.springframework.core.MethodParameter;
|
||||||
import org.springframework.core.ReactiveAdapterRegistry;
|
import org.springframework.core.ReactiveAdapterRegistry;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerWebExchange;
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.util.ReflectionUtils;
|
import org.springframework.util.ReflectionUtils;
|
||||||
import org.springframework.web.reactive.BindingContext;
|
import org.springframework.web.reactive.BindingContext;
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ public class ExpressionValueMethodArgumentResolverTests {
|
||||||
|
|
||||||
private ExpressionValueMethodArgumentResolver resolver;
|
private ExpressionValueMethodArgumentResolver resolver;
|
||||||
|
|
||||||
private final MockServerWebExchange exchange = MockServerHttpRequest.get("/").toExchange();
|
private final MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||||
|
|
||||||
private MethodParameter paramSystemProperty;
|
private MethodParameter paramSystemProperty;
|
||||||
private MethodParameter paramNotSupported;
|
private MethodParameter paramNotSupported;
|
||||||
|
|
|
@ -40,7 +40,7 @@ import org.springframework.http.HttpEntity;
|
||||||
import org.springframework.http.RequestEntity;
|
import org.springframework.http.RequestEntity;
|
||||||
import org.springframework.http.codec.DecoderHttpMessageReader;
|
import org.springframework.http.codec.DecoderHttpMessageReader;
|
||||||
import org.springframework.http.codec.HttpMessageReader;
|
import org.springframework.http.codec.HttpMessageReader;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerWebExchange;
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
import org.springframework.web.method.ResolvableMethod;
|
import org.springframework.web.method.ResolvableMethod;
|
||||||
import org.springframework.web.reactive.BindingContext;
|
import org.springframework.web.reactive.BindingContext;
|
||||||
|
@ -303,7 +303,7 @@ public class HttpEntityArgumentResolverTests {
|
||||||
|
|
||||||
|
|
||||||
private MockServerWebExchange postExchange(String body) {
|
private MockServerWebExchange postExchange(String body) {
|
||||||
return post("/path").header("foo", "bar").contentType(TEXT_PLAIN).body(body).toExchange();
|
return MockServerWebExchange.from(post("/path").header("foo", "bar").contentType(TEXT_PLAIN).body(body));
|
||||||
}
|
}
|
||||||
|
|
||||||
private ResolvableType httpEntityType(Class<?> bodyType, Class<?>... generics) {
|
private ResolvableType httpEntityType(Class<?> bodyType, Class<?>... generics) {
|
||||||
|
@ -328,7 +328,7 @@ public class HttpEntityArgumentResolverTests {
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private <T> HttpEntity<T> resolveValueWithEmptyBody(ResolvableType type) {
|
private <T> HttpEntity<T> resolveValueWithEmptyBody(ResolvableType type) {
|
||||||
ServerWebExchange exchange = post("/path").toExchange();
|
ServerWebExchange exchange = MockServerWebExchange.from(post("/path").build());
|
||||||
MethodParameter param = this.testMethod.arg(type);
|
MethodParameter param = this.testMethod.arg(type);
|
||||||
Mono<Object> result = this.resolver.resolveArgument(param, new BindingContext(), exchange);
|
Mono<Object> result = this.resolver.resolveArgument(param, new BindingContext(), exchange);
|
||||||
HttpEntity<String> httpEntity = (HttpEntity<String>) result.block(Duration.ofSeconds(5));
|
HttpEntity<String> httpEntity = (HttpEntity<String>) result.block(Duration.ofSeconds(5));
|
||||||
|
|
|
@ -28,6 +28,7 @@ import org.springframework.core.ReactiveAdapterRegistry;
|
||||||
import org.springframework.core.convert.ConversionService;
|
import org.springframework.core.convert.ConversionService;
|
||||||
import org.springframework.format.support.DefaultFormattingConversionService;
|
import org.springframework.format.support.DefaultFormattingConversionService;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.web.bind.WebDataBinder;
|
import org.springframework.web.bind.WebDataBinder;
|
||||||
import org.springframework.web.bind.annotation.InitBinder;
|
import org.springframework.web.bind.annotation.InitBinder;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
@ -35,7 +36,6 @@ import org.springframework.web.bind.support.ConfigurableWebBindingInitializer;
|
||||||
import org.springframework.web.reactive.BindingContext;
|
import org.springframework.web.reactive.BindingContext;
|
||||||
import org.springframework.web.reactive.result.method.SyncHandlerMethodArgumentResolver;
|
import org.springframework.web.reactive.result.method.SyncHandlerMethodArgumentResolver;
|
||||||
import org.springframework.web.reactive.result.method.SyncInvocableHandlerMethod;
|
import org.springframework.web.reactive.result.method.SyncInvocableHandlerMethod;
|
||||||
import org.springframework.web.server.ServerWebExchange;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
@ -55,7 +55,7 @@ public class InitBinderBindingContextTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createBinder() throws Exception {
|
public void createBinder() throws Exception {
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||||
BindingContext context = createBindingContext("initBinder", WebDataBinder.class);
|
BindingContext context = createBindingContext("initBinder", WebDataBinder.class);
|
||||||
WebDataBinder dataBinder = context.createDataBinder(exchange, null, null);
|
WebDataBinder dataBinder = context.createDataBinder(exchange, null, null);
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ public class InitBinderBindingContextTests {
|
||||||
ConversionService conversionService = new DefaultFormattingConversionService();
|
ConversionService conversionService = new DefaultFormattingConversionService();
|
||||||
bindingInitializer.setConversionService(conversionService);
|
bindingInitializer.setConversionService(conversionService);
|
||||||
|
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||||
BindingContext context = createBindingContext("initBinder", WebDataBinder.class);
|
BindingContext context = createBindingContext("initBinder", WebDataBinder.class);
|
||||||
WebDataBinder dataBinder = context.createDataBinder(exchange, null, null);
|
WebDataBinder dataBinder = context.createDataBinder(exchange, null, null);
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ public class InitBinderBindingContextTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createBinderWithAttrName() throws Exception {
|
public void createBinderWithAttrName() throws Exception {
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||||
BindingContext context = createBindingContext("initBinderWithAttributeName", WebDataBinder.class);
|
BindingContext context = createBindingContext("initBinderWithAttributeName", WebDataBinder.class);
|
||||||
WebDataBinder dataBinder = context.createDataBinder(exchange, null, "foo");
|
WebDataBinder dataBinder = context.createDataBinder(exchange, null, "foo");
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ public class InitBinderBindingContextTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createBinderWithAttrNameNoMatch() throws Exception {
|
public void createBinderWithAttrNameNoMatch() throws Exception {
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||||
BindingContext context = createBindingContext("initBinderWithAttributeName", WebDataBinder.class);
|
BindingContext context = createBindingContext("initBinderWithAttributeName", WebDataBinder.class);
|
||||||
WebDataBinder dataBinder = context.createDataBinder(exchange, null, "invalidName");
|
WebDataBinder dataBinder = context.createDataBinder(exchange, null, "invalidName");
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ public class InitBinderBindingContextTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createBinderNullAttrName() throws Exception {
|
public void createBinderNullAttrName() throws Exception {
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||||
BindingContext context = createBindingContext("initBinderWithAttributeName", WebDataBinder.class);
|
BindingContext context = createBindingContext("initBinderWithAttributeName", WebDataBinder.class);
|
||||||
WebDataBinder dataBinder = context.createDataBinder(exchange, null, null);
|
WebDataBinder dataBinder = context.createDataBinder(exchange, null, null);
|
||||||
|
|
||||||
|
@ -105,14 +105,15 @@ public class InitBinderBindingContextTests {
|
||||||
|
|
||||||
@Test(expected = IllegalStateException.class)
|
@Test(expected = IllegalStateException.class)
|
||||||
public void returnValueNotExpected() throws Exception {
|
public void returnValueNotExpected() throws Exception {
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||||
BindingContext context = createBindingContext("initBinderReturnValue", WebDataBinder.class);
|
BindingContext context = createBindingContext("initBinderReturnValue", WebDataBinder.class);
|
||||||
context.createDataBinder(exchange, null, "invalidName");
|
context.createDataBinder(exchange, null, "invalidName");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createBinderTypeConversion() throws Exception {
|
public void createBinderTypeConversion() throws Exception {
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/path?requestParam=22").toExchange();
|
MockServerHttpRequest request = MockServerHttpRequest.get("/path?requestParam=22").build();
|
||||||
|
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
ReactiveAdapterRegistry adapterRegistry = new ReactiveAdapterRegistry();
|
ReactiveAdapterRegistry adapterRegistry = new ReactiveAdapterRegistry();
|
||||||
this.argumentResolvers.add(new RequestParamMethodArgumentResolver(null, adapterRegistry, false));
|
this.argumentResolvers.add(new RequestParamMethodArgumentResolver(null, adapterRegistry, false));
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,8 @@ import org.springframework.http.codec.DecoderHttpMessageReader;
|
||||||
import org.springframework.http.codec.HttpMessageReader;
|
import org.springframework.http.codec.HttpMessageReader;
|
||||||
import org.springframework.http.codec.json.Jackson2JsonDecoder;
|
import org.springframework.http.codec.json.Jackson2JsonDecoder;
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.validation.Errors;
|
import org.springframework.validation.Errors;
|
||||||
import org.springframework.validation.Validator;
|
import org.springframework.validation.Validator;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
@ -57,9 +59,12 @@ import org.springframework.web.server.ServerWebExchange;
|
||||||
import org.springframework.web.server.ServerWebInputException;
|
import org.springframework.web.server.ServerWebInputException;
|
||||||
import org.springframework.web.server.UnsupportedMediaTypeStatusException;
|
import org.springframework.web.server.UnsupportedMediaTypeStatusException;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
import static org.springframework.core.ResolvableType.*;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.springframework.mock.http.server.reactive.test.MockServerHttpRequest.*;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.springframework.core.ResolvableType.forClassWithGenerics;
|
||||||
|
import static org.springframework.mock.http.server.reactive.test.MockServerHttpRequest.post;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for {@link AbstractMessageReaderArgumentResolver}.
|
* Unit tests for {@link AbstractMessageReaderArgumentResolver}.
|
||||||
|
@ -86,7 +91,8 @@ public class MessageReaderArgumentResolverTests {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Test
|
@Test
|
||||||
public void missingContentType() throws Exception {
|
public void missingContentType() throws Exception {
|
||||||
ServerWebExchange exchange = post("/path").body("{\"bar\":\"BARBAR\",\"foo\":\"FOOFOO\"}").toExchange();
|
MockServerHttpRequest request = post("/path").body("{\"bar\":\"BARBAR\",\"foo\":\"FOOFOO\"}");
|
||||||
|
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
ResolvableType type = forClassWithGenerics(Mono.class, TestBean.class);
|
ResolvableType type = forClassWithGenerics(Mono.class, TestBean.class);
|
||||||
MethodParameter param = this.testMethod.arg(type);
|
MethodParameter param = this.testMethod.arg(type);
|
||||||
Mono<Object> result = this.resolver.readBody(param, true, this.bindingContext, exchange);
|
Mono<Object> result = this.resolver.readBody(param, true, this.bindingContext, exchange);
|
||||||
|
@ -99,7 +105,8 @@ public class MessageReaderArgumentResolverTests {
|
||||||
|
|
||||||
@Test @SuppressWarnings("unchecked") // SPR-9942
|
@Test @SuppressWarnings("unchecked") // SPR-9942
|
||||||
public void emptyBody() throws Exception {
|
public void emptyBody() throws Exception {
|
||||||
ServerWebExchange exchange = post("/path").contentType(MediaType.APPLICATION_JSON).toExchange();
|
MockServerHttpRequest request = post("/path").contentType(MediaType.APPLICATION_JSON).build();
|
||||||
|
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
ResolvableType type = forClassWithGenerics(Mono.class, TestBean.class);
|
ResolvableType type = forClassWithGenerics(Mono.class, TestBean.class);
|
||||||
MethodParameter param = this.testMethod.arg(type);
|
MethodParameter param = this.testMethod.arg(type);
|
||||||
Mono<TestBean> result = (Mono<TestBean>) this.resolver.readBody(
|
Mono<TestBean> result = (Mono<TestBean>) this.resolver.readBody(
|
||||||
|
@ -292,7 +299,8 @@ public class MessageReaderArgumentResolverTests {
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private <T> T resolveValue(MethodParameter param, String body) {
|
private <T> T resolveValue(MethodParameter param, String body) {
|
||||||
ServerWebExchange exchange = post("/path").contentType(MediaType.APPLICATION_JSON).body(body).toExchange();
|
MockServerHttpRequest request = post("/path").contentType(MediaType.APPLICATION_JSON).body(body);
|
||||||
|
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
Mono<Object> result = this.resolver.readBody(param, true, this.bindingContext, exchange);
|
Mono<Object> result = this.resolver.readBody(param, true, this.bindingContext, exchange);
|
||||||
Object value = result.block(Duration.ofSeconds(5));
|
Object value = result.block(Duration.ofSeconds(5));
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@ import org.springframework.http.codec.ResourceHttpMessageWriter;
|
||||||
import org.springframework.http.codec.json.Jackson2JsonEncoder;
|
import org.springframework.http.codec.json.Jackson2JsonEncoder;
|
||||||
import org.springframework.http.codec.xml.Jaxb2XmlEncoder;
|
import org.springframework.http.codec.xml.Jaxb2XmlEncoder;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerWebExchange;
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
import org.springframework.web.reactive.accept.RequestedContentTypeResolver;
|
import org.springframework.web.reactive.accept.RequestedContentTypeResolver;
|
||||||
import org.springframework.web.reactive.accept.RequestedContentTypeResolverBuilder;
|
import org.springframework.web.reactive.accept.RequestedContentTypeResolverBuilder;
|
||||||
|
@ -69,7 +69,8 @@ public class MessageWriterResultHandlerTests {
|
||||||
|
|
||||||
private final AbstractMessageWriterResultHandler resultHandler = initResultHandler();
|
private final AbstractMessageWriterResultHandler resultHandler = initResultHandler();
|
||||||
|
|
||||||
private final MockServerWebExchange exchange = MockServerHttpRequest.get("/path").toExchange();
|
private final MockServerWebExchange exchange = MockServerWebExchange.from(
|
||||||
|
MockServerHttpRequest.get("/path").build());
|
||||||
|
|
||||||
|
|
||||||
private AbstractMessageWriterResultHandler initResultHandler(HttpMessageWriter<?>... writers) {
|
private AbstractMessageWriterResultHandler initResultHandler(HttpMessageWriter<?>... writers) {
|
||||||
|
|
|
@ -32,6 +32,7 @@ import org.springframework.core.MethodParameter;
|
||||||
import org.springframework.core.ReactiveAdapterRegistry;
|
import org.springframework.core.ReactiveAdapterRegistry;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.validation.BindingResult;
|
import org.springframework.validation.BindingResult;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
|
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
|
||||||
|
@ -309,10 +310,9 @@ public class ModelAttributeMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
private ServerWebExchange postForm(String formData) throws URISyntaxException {
|
private ServerWebExchange postForm(String formData) throws URISyntaxException {
|
||||||
return MockServerHttpRequest.post("/")
|
return MockServerWebExchange.from(MockServerHttpRequest.post("/")
|
||||||
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
|
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
|
||||||
.body(formData)
|
.body(formData));
|
||||||
.toExchange();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,7 @@ import org.springframework.core.ReactiveAdapterRegistry;
|
||||||
import org.springframework.core.annotation.AnnotationUtils;
|
import org.springframework.core.annotation.AnnotationUtils;
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.util.ReflectionUtils;
|
import org.springframework.util.ReflectionUtils;
|
||||||
import org.springframework.validation.Validator;
|
import org.springframework.validation.Validator;
|
||||||
|
@ -66,7 +67,8 @@ public class ModelInitializerTests {
|
||||||
|
|
||||||
private ModelInitializer modelInitializer;
|
private ModelInitializer modelInitializer;
|
||||||
|
|
||||||
private final ServerWebExchange exchange = MockServerHttpRequest.get("/path").toExchange();
|
private final ServerWebExchange exchange = MockServerWebExchange.from(
|
||||||
|
MockServerHttpRequest.get("/path").build());
|
||||||
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
|
|
|
@ -28,7 +28,7 @@ import reactor.core.publisher.Mono;
|
||||||
import org.springframework.core.MethodParameter;
|
import org.springframework.core.MethodParameter;
|
||||||
import org.springframework.core.ReactiveAdapterRegistry;
|
import org.springframework.core.ReactiveAdapterRegistry;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerWebExchange;
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.util.ReflectionUtils;
|
import org.springframework.util.ReflectionUtils;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.reactive.BindingContext;
|
import org.springframework.web.reactive.BindingContext;
|
||||||
|
@ -48,7 +48,8 @@ public class PathVariableMapMethodArgumentResolverTests {
|
||||||
|
|
||||||
private PathVariableMapMethodArgumentResolver resolver;
|
private PathVariableMapMethodArgumentResolver resolver;
|
||||||
|
|
||||||
private final MockServerWebExchange exchange= MockServerHttpRequest.get("/").toExchange();
|
private final MockServerWebExchange exchange= MockServerWebExchange.from(
|
||||||
|
MockServerHttpRequest.get("/").build());
|
||||||
|
|
||||||
private MethodParameter paramMap;
|
private MethodParameter paramMap;
|
||||||
private MethodParameter paramNamedMap;
|
private MethodParameter paramNamedMap;
|
||||||
|
|
|
@ -31,7 +31,7 @@ import org.springframework.core.ReactiveAdapterRegistry;
|
||||||
import org.springframework.core.annotation.SynthesizingMethodParameter;
|
import org.springframework.core.annotation.SynthesizingMethodParameter;
|
||||||
import org.springframework.format.support.DefaultFormattingConversionService;
|
import org.springframework.format.support.DefaultFormattingConversionService;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerWebExchange;
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.util.ReflectionUtils;
|
import org.springframework.util.ReflectionUtils;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.support.ConfigurableWebBindingInitializer;
|
import org.springframework.web.bind.support.ConfigurableWebBindingInitializer;
|
||||||
|
@ -54,7 +54,8 @@ public class PathVariableMethodArgumentResolverTests {
|
||||||
|
|
||||||
private PathVariableMethodArgumentResolver resolver;
|
private PathVariableMethodArgumentResolver resolver;
|
||||||
|
|
||||||
private final MockServerWebExchange exchange= MockServerHttpRequest.get("/").toExchange();
|
private final MockServerWebExchange exchange= MockServerWebExchange.from(
|
||||||
|
MockServerHttpRequest.get("/").build());
|
||||||
|
|
||||||
private MethodParameter paramNamedString;
|
private MethodParameter paramNamedString;
|
||||||
private MethodParameter paramString;
|
private MethodParameter paramString;
|
||||||
|
|
|
@ -24,6 +24,7 @@ import reactor.core.publisher.Mono;
|
||||||
import org.springframework.core.MethodParameter;
|
import org.springframework.core.MethodParameter;
|
||||||
import org.springframework.core.ReactiveAdapterRegistry;
|
import org.springframework.core.ReactiveAdapterRegistry;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.web.method.ResolvableMethod;
|
import org.springframework.web.method.ResolvableMethod;
|
||||||
import org.springframework.web.reactive.BindingContext;
|
import org.springframework.web.reactive.BindingContext;
|
||||||
import org.springframework.web.server.ServerWebExchange;
|
import org.springframework.web.server.ServerWebExchange;
|
||||||
|
@ -56,7 +57,7 @@ public class PrincipalArgumentResolverTests {
|
||||||
|
|
||||||
BindingContext context = new BindingContext();
|
BindingContext context = new BindingContext();
|
||||||
Principal user = () -> "Joe";
|
Principal user = () -> "Joe";
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/").build().toExchange()
|
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build())
|
||||||
.mutate().principal(Mono.just(user)).build();
|
.mutate().principal(Mono.just(user)).build();
|
||||||
|
|
||||||
MethodParameter param = this.testMethod.arg(Principal.class);
|
MethodParameter param = this.testMethod.arg(Principal.class);
|
||||||
|
|
|
@ -32,7 +32,7 @@ import org.springframework.core.ReactiveAdapterRegistry;
|
||||||
import org.springframework.core.annotation.SynthesizingMethodParameter;
|
import org.springframework.core.annotation.SynthesizingMethodParameter;
|
||||||
import org.springframework.format.support.DefaultFormattingConversionService;
|
import org.springframework.format.support.DefaultFormattingConversionService;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerWebExchange;
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.util.ReflectionUtils;
|
import org.springframework.util.ReflectionUtils;
|
||||||
import org.springframework.web.bind.annotation.RequestAttribute;
|
import org.springframework.web.bind.annotation.RequestAttribute;
|
||||||
import org.springframework.web.bind.support.ConfigurableWebBindingInitializer;
|
import org.springframework.web.bind.support.ConfigurableWebBindingInitializer;
|
||||||
|
@ -56,7 +56,8 @@ public class RequestAttributeMethodArgumentResolverTests {
|
||||||
|
|
||||||
private RequestAttributeMethodArgumentResolver resolver;
|
private RequestAttributeMethodArgumentResolver resolver;
|
||||||
|
|
||||||
private final MockServerWebExchange exchange= MockServerHttpRequest.get("/").toExchange();
|
private final MockServerWebExchange exchange = MockServerWebExchange.from(
|
||||||
|
MockServerHttpRequest.get("/").build());
|
||||||
|
|
||||||
private Method handleMethod;
|
private Method handleMethod;
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,7 @@ import org.springframework.core.codec.StringDecoder;
|
||||||
import org.springframework.http.codec.DecoderHttpMessageReader;
|
import org.springframework.http.codec.DecoderHttpMessageReader;
|
||||||
import org.springframework.http.codec.HttpMessageReader;
|
import org.springframework.http.codec.HttpMessageReader;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.method.ResolvableMethod;
|
import org.springframework.web.method.ResolvableMethod;
|
||||||
import org.springframework.web.reactive.BindingContext;
|
import org.springframework.web.reactive.BindingContext;
|
||||||
|
@ -223,7 +224,7 @@ public class RequestBodyArgumentResolverTests {
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private <T> T resolveValue(MethodParameter param, String body) {
|
private <T> T resolveValue(MethodParameter param, String body) {
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.post("/path").body(body).toExchange();
|
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.post("/path").body(body));
|
||||||
Mono<Object> result = this.resolver.readBody(param, true, new BindingContext(), exchange);
|
Mono<Object> result = this.resolver.readBody(param, true, new BindingContext(), exchange);
|
||||||
Object value = result.block(Duration.ofSeconds(5));
|
Object value = result.block(Duration.ofSeconds(5));
|
||||||
|
|
||||||
|
@ -237,7 +238,7 @@ public class RequestBodyArgumentResolverTests {
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private <T> T resolveValueWithEmptyBody(MethodParameter param) {
|
private <T> T resolveValueWithEmptyBody(MethodParameter param) {
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.post("/path").build().toExchange();
|
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.post("/path").build());
|
||||||
Mono<Object> result = this.resolver.resolveArgument(param, new BindingContext(), exchange);
|
Mono<Object> result = this.resolver.resolveArgument(param, new BindingContext(), exchange);
|
||||||
Object value = result.block(Duration.ofSeconds(5));
|
Object value = result.block(Duration.ofSeconds(5));
|
||||||
|
|
||||||
|
|
|
@ -29,11 +29,11 @@ import org.springframework.core.ReactiveAdapterRegistry;
|
||||||
import org.springframework.core.annotation.SynthesizingMethodParameter;
|
import org.springframework.core.annotation.SynthesizingMethodParameter;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.util.LinkedMultiValueMap;
|
import org.springframework.util.LinkedMultiValueMap;
|
||||||
import org.springframework.util.MultiValueMap;
|
import org.springframework.util.MultiValueMap;
|
||||||
import org.springframework.util.ReflectionUtils;
|
import org.springframework.util.ReflectionUtils;
|
||||||
import org.springframework.web.bind.annotation.RequestHeader;
|
import org.springframework.web.bind.annotation.RequestHeader;
|
||||||
import org.springframework.web.server.ServerWebExchange;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
|
@ -92,7 +92,8 @@ public class RequestHeaderMapMethodArgumentResolverTests {
|
||||||
String name = "foo";
|
String name = "foo";
|
||||||
String value = "bar";
|
String value = "bar";
|
||||||
Map<String, String> expected = Collections.singletonMap(name, value);
|
Map<String, String> expected = Collections.singletonMap(name, value);
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/").header(name, value).toExchange();
|
MockServerHttpRequest request = MockServerHttpRequest.get("/").header(name, value).build();
|
||||||
|
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
|
|
||||||
Mono<Object> mono = resolver.resolveArgument(paramMap, null, exchange);
|
Mono<Object> mono = resolver.resolveArgument(paramMap, null, exchange);
|
||||||
Object result = mono.block();
|
Object result = mono.block();
|
||||||
|
@ -106,7 +107,8 @@ public class RequestHeaderMapMethodArgumentResolverTests {
|
||||||
String name = "foo";
|
String name = "foo";
|
||||||
String value1 = "bar";
|
String value1 = "bar";
|
||||||
String value2 = "baz";
|
String value2 = "baz";
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/").header(name, value1, value2).toExchange();
|
MockServerHttpRequest request = MockServerHttpRequest.get("/").header(name, value1, value2).build();
|
||||||
|
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
|
|
||||||
MultiValueMap<String, String> expected = new LinkedMultiValueMap<>(1);
|
MultiValueMap<String, String> expected = new LinkedMultiValueMap<>(1);
|
||||||
expected.add(name, value1);
|
expected.add(name, value1);
|
||||||
|
@ -124,7 +126,8 @@ public class RequestHeaderMapMethodArgumentResolverTests {
|
||||||
String name = "foo";
|
String name = "foo";
|
||||||
String value1 = "bar";
|
String value1 = "bar";
|
||||||
String value2 = "baz";
|
String value2 = "baz";
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/").header(name, value1, value2).toExchange();
|
MockServerHttpRequest request = MockServerHttpRequest.get("/").header(name, value1, value2).build();
|
||||||
|
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
|
|
||||||
HttpHeaders expected = new HttpHeaders();
|
HttpHeaders expected = new HttpHeaders();
|
||||||
expected.add(name, value1);
|
expected.add(name, value1);
|
||||||
|
|
|
@ -33,7 +33,7 @@ import org.springframework.core.ReactiveAdapterRegistry;
|
||||||
import org.springframework.core.annotation.SynthesizingMethodParameter;
|
import org.springframework.core.annotation.SynthesizingMethodParameter;
|
||||||
import org.springframework.format.support.DefaultFormattingConversionService;
|
import org.springframework.format.support.DefaultFormattingConversionService;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerWebExchange;
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.util.ReflectionUtils;
|
import org.springframework.util.ReflectionUtils;
|
||||||
import org.springframework.web.bind.annotation.RequestHeader;
|
import org.springframework.web.bind.annotation.RequestHeader;
|
||||||
import org.springframework.web.bind.support.ConfigurableWebBindingInitializer;
|
import org.springframework.web.bind.support.ConfigurableWebBindingInitializer;
|
||||||
|
@ -41,7 +41,11 @@ import org.springframework.web.reactive.BindingContext;
|
||||||
import org.springframework.web.server.ServerWebExchange;
|
import org.springframework.web.server.ServerWebExchange;
|
||||||
import org.springframework.web.server.ServerWebInputException;
|
import org.springframework.web.server.ServerWebInputException;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for {@link RequestHeaderMethodArgumentResolver}.
|
* Unit tests for {@link RequestHeaderMethodArgumentResolver}.
|
||||||
|
@ -108,7 +112,7 @@ public class RequestHeaderMethodArgumentResolverTests {
|
||||||
@Test
|
@Test
|
||||||
public void resolveStringArgument() throws Exception {
|
public void resolveStringArgument() throws Exception {
|
||||||
String expected = "foo";
|
String expected = "foo";
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/").header("name", expected).toExchange();
|
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("name", expected).build());
|
||||||
|
|
||||||
Mono<Object> mono = this.resolver.resolveArgument(
|
Mono<Object> mono = this.resolver.resolveArgument(
|
||||||
this.paramNamedDefaultValueStringHeader, this.bindingContext, exchange);
|
this.paramNamedDefaultValueStringHeader, this.bindingContext, exchange);
|
||||||
|
@ -120,7 +124,8 @@ public class RequestHeaderMethodArgumentResolverTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveStringArrayArgument() throws Exception {
|
public void resolveStringArrayArgument() throws Exception {
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/").header("name", "foo", "bar").toExchange();
|
MockServerHttpRequest request = MockServerHttpRequest.get("/").header("name", "foo", "bar").build();
|
||||||
|
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
|
|
||||||
Mono<Object> mono = this.resolver.resolveArgument(
|
Mono<Object> mono = this.resolver.resolveArgument(
|
||||||
this.paramNamedValueStringArray, this.bindingContext, exchange);
|
this.paramNamedValueStringArray, this.bindingContext, exchange);
|
||||||
|
@ -132,7 +137,7 @@ public class RequestHeaderMethodArgumentResolverTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveDefaultValue() throws Exception {
|
public void resolveDefaultValue() throws Exception {
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("/").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||||
Mono<Object> mono = this.resolver.resolveArgument(
|
Mono<Object> mono = this.resolver.resolveArgument(
|
||||||
this.paramNamedDefaultValueStringHeader, this.bindingContext, exchange);
|
this.paramNamedDefaultValueStringHeader, this.bindingContext, exchange);
|
||||||
|
|
||||||
|
@ -147,7 +152,7 @@ public class RequestHeaderMethodArgumentResolverTests {
|
||||||
try {
|
try {
|
||||||
Mono<Object> mono = this.resolver.resolveArgument(
|
Mono<Object> mono = this.resolver.resolveArgument(
|
||||||
this.paramSystemProperty, this.bindingContext,
|
this.paramSystemProperty, this.bindingContext,
|
||||||
MockServerHttpRequest.get("/").toExchange());
|
MockServerWebExchange.from(MockServerHttpRequest.get("/").build()));
|
||||||
|
|
||||||
Object result = mono.block();
|
Object result = mono.block();
|
||||||
assertTrue(result instanceof String);
|
assertTrue(result instanceof String);
|
||||||
|
@ -161,7 +166,8 @@ public class RequestHeaderMethodArgumentResolverTests {
|
||||||
@Test
|
@Test
|
||||||
public void resolveNameFromSystemPropertyThroughExpression() throws Exception {
|
public void resolveNameFromSystemPropertyThroughExpression() throws Exception {
|
||||||
String expected = "foo";
|
String expected = "foo";
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/").header("bar", expected).toExchange();
|
MockServerHttpRequest request = MockServerHttpRequest.get("/").header("bar", expected).build();
|
||||||
|
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
|
|
||||||
System.setProperty("systemProperty", "bar");
|
System.setProperty("systemProperty", "bar");
|
||||||
try {
|
try {
|
||||||
|
@ -180,7 +186,8 @@ public class RequestHeaderMethodArgumentResolverTests {
|
||||||
@Test
|
@Test
|
||||||
public void resolveNameFromSystemPropertyThroughPlaceholder() throws Exception {
|
public void resolveNameFromSystemPropertyThroughPlaceholder() throws Exception {
|
||||||
String expected = "foo";
|
String expected = "foo";
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/").header("bar", expected).toExchange();
|
MockServerHttpRequest request = MockServerHttpRequest.get("/").header("bar", expected).build();
|
||||||
|
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
|
|
||||||
System.setProperty("systemProperty", "bar");
|
System.setProperty("systemProperty", "bar");
|
||||||
try {
|
try {
|
||||||
|
@ -200,7 +207,7 @@ public class RequestHeaderMethodArgumentResolverTests {
|
||||||
public void notFound() throws Exception {
|
public void notFound() throws Exception {
|
||||||
Mono<Object> mono = resolver.resolveArgument(
|
Mono<Object> mono = resolver.resolveArgument(
|
||||||
this.paramNamedValueStringArray, this.bindingContext,
|
this.paramNamedValueStringArray, this.bindingContext,
|
||||||
MockServerHttpRequest.get("/").toExchange());
|
MockServerWebExchange.from(MockServerHttpRequest.get("/").build()));
|
||||||
|
|
||||||
StepVerifier.create(mono)
|
StepVerifier.create(mono)
|
||||||
.expectNextCount(0)
|
.expectNextCount(0)
|
||||||
|
@ -212,7 +219,8 @@ public class RequestHeaderMethodArgumentResolverTests {
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public void dateConversion() throws Exception {
|
public void dateConversion() throws Exception {
|
||||||
String rfc1123val = "Thu, 21 Apr 2016 17:11:08 +0100";
|
String rfc1123val = "Thu, 21 Apr 2016 17:11:08 +0100";
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/").header("name", rfc1123val).toExchange();
|
MockServerHttpRequest request = MockServerHttpRequest.get("/").header("name", rfc1123val).build();
|
||||||
|
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
|
|
||||||
Mono<Object> mono = this.resolver.resolveArgument(this.paramDate, this.bindingContext, exchange);
|
Mono<Object> mono = this.resolver.resolveArgument(this.paramDate, this.bindingContext, exchange);
|
||||||
Object result = mono.block();
|
Object result = mono.block();
|
||||||
|
@ -224,7 +232,8 @@ public class RequestHeaderMethodArgumentResolverTests {
|
||||||
@Test
|
@Test
|
||||||
public void instantConversion() throws Exception {
|
public void instantConversion() throws Exception {
|
||||||
String rfc1123val = "Thu, 21 Apr 2016 17:11:08 +0100";
|
String rfc1123val = "Thu, 21 Apr 2016 17:11:08 +0100";
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/").header("name", rfc1123val).toExchange();
|
MockServerHttpRequest request = MockServerHttpRequest.get("/").header("name", rfc1123val).build();
|
||||||
|
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
|
|
||||||
Mono<Object> mono = this.resolver.resolveArgument(this.paramInstant, this.bindingContext, exchange);
|
Mono<Object> mono = this.resolver.resolveArgument(this.paramInstant, this.bindingContext, exchange);
|
||||||
Object result = mono.block();
|
Object result = mono.block();
|
||||||
|
@ -234,6 +243,7 @@ public class RequestHeaderMethodArgumentResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public void params(
|
public void params(
|
||||||
@RequestHeader(name = "name", defaultValue = "bar") String param1,
|
@RequestHeader(name = "name", defaultValue = "bar") String param1,
|
||||||
@RequestHeader("name") String[] param2,
|
@RequestHeader("name") String[] param2,
|
||||||
|
|
|
@ -27,6 +27,7 @@ import reactor.core.publisher.Mono;
|
||||||
import org.springframework.core.MethodParameter;
|
import org.springframework.core.MethodParameter;
|
||||||
import org.springframework.core.ReactiveAdapterRegistry;
|
import org.springframework.core.ReactiveAdapterRegistry;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.util.MultiValueMap;
|
import org.springframework.util.MultiValueMap;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.method.ResolvableMethod;
|
import org.springframework.web.method.ResolvableMethod;
|
||||||
|
@ -79,7 +80,8 @@ public class RequestParamMapMethodArgumentResolverTests {
|
||||||
@Test
|
@Test
|
||||||
public void resolveMapArgumentWithQueryString() throws Exception {
|
public void resolveMapArgumentWithQueryString() throws Exception {
|
||||||
MethodParameter param = this.testMethod.annot(requestParam().name("")).arg(Map.class);
|
MethodParameter param = this.testMethod.annot(requestParam().name("")).arg(Map.class);
|
||||||
Object result= resolve(param, MockServerHttpRequest.get("/path?foo=bar").toExchange());
|
MockServerHttpRequest request = MockServerHttpRequest.get("/path?foo=bar").build();
|
||||||
|
Object result= resolve(param, MockServerWebExchange.from(request));
|
||||||
assertTrue(result instanceof Map);
|
assertTrue(result instanceof Map);
|
||||||
assertEquals(Collections.singletonMap("foo", "bar"), result);
|
assertEquals(Collections.singletonMap("foo", "bar"), result);
|
||||||
}
|
}
|
||||||
|
@ -87,7 +89,8 @@ public class RequestParamMapMethodArgumentResolverTests {
|
||||||
@Test
|
@Test
|
||||||
public void resolveMultiValueMapArgument() throws Exception {
|
public void resolveMultiValueMapArgument() throws Exception {
|
||||||
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(MultiValueMap.class);
|
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(MultiValueMap.class);
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/path?foo=bar&foo=baz").toExchange();
|
MockServerHttpRequest request = MockServerHttpRequest.get("/path?foo=bar&foo=baz").build();
|
||||||
|
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
Object result= resolve(param, exchange);
|
Object result= resolve(param, exchange);
|
||||||
|
|
||||||
assertTrue(result instanceof MultiValueMap);
|
assertTrue(result instanceof MultiValueMap);
|
||||||
|
|
|
@ -29,7 +29,7 @@ import org.springframework.core.MethodParameter;
|
||||||
import org.springframework.core.ReactiveAdapterRegistry;
|
import org.springframework.core.ReactiveAdapterRegistry;
|
||||||
import org.springframework.format.support.DefaultFormattingConversionService;
|
import org.springframework.format.support.DefaultFormattingConversionService;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerWebExchange;
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.support.ConfigurableWebBindingInitializer;
|
import org.springframework.web.bind.support.ConfigurableWebBindingInitializer;
|
||||||
import org.springframework.web.method.ResolvableMethod;
|
import org.springframework.web.method.ResolvableMethod;
|
||||||
|
@ -135,13 +135,15 @@ public class RequestParamMethodArgumentResolverTests {
|
||||||
@Test
|
@Test
|
||||||
public void resolveWithQueryString() throws Exception {
|
public void resolveWithQueryString() throws Exception {
|
||||||
MethodParameter param = this.testMethod.annot(requestParam().notRequired("bar")).arg(String.class);
|
MethodParameter param = this.testMethod.annot(requestParam().notRequired("bar")).arg(String.class);
|
||||||
assertEquals("foo", resolve(param, MockServerHttpRequest.get("/path?name=foo").toExchange()));
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path?name=foo").build());
|
||||||
|
assertEquals("foo", resolve(param, exchange));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveStringArray() throws Exception {
|
public void resolveStringArray() throws Exception {
|
||||||
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(String[].class);
|
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(String[].class);
|
||||||
Object result = resolve(param, MockServerHttpRequest.get("/path?name=foo&name=bar").toExchange());
|
MockServerHttpRequest request = MockServerHttpRequest.get("/path?name=foo&name=bar").build();
|
||||||
|
Object result = resolve(param, MockServerWebExchange.from(request));
|
||||||
assertTrue(result instanceof String[]);
|
assertTrue(result instanceof String[]);
|
||||||
assertArrayEquals(new String[] {"foo", "bar"}, (String[]) result);
|
assertArrayEquals(new String[] {"foo", "bar"}, (String[]) result);
|
||||||
}
|
}
|
||||||
|
@ -149,13 +151,13 @@ public class RequestParamMethodArgumentResolverTests {
|
||||||
@Test
|
@Test
|
||||||
public void resolveDefaultValue() throws Exception {
|
public void resolveDefaultValue() throws Exception {
|
||||||
MethodParameter param = this.testMethod.annot(requestParam().notRequired("bar")).arg(String.class);
|
MethodParameter param = this.testMethod.annot(requestParam().notRequired("bar")).arg(String.class);
|
||||||
assertEquals("bar", resolve(param, MockServerHttpRequest.get("/").toExchange()));
|
assertEquals("bar", resolve(param, MockServerWebExchange.from(MockServerHttpRequest.get("/").build())));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void missingRequestParam() throws Exception {
|
public void missingRequestParam() throws Exception {
|
||||||
|
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("/").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||||
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(String[].class);
|
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(String[].class);
|
||||||
Mono<Object> mono = this.resolver.resolveArgument(param, this.bindContext, exchange);
|
Mono<Object> mono = this.resolver.resolveArgument(param, this.bindContext, exchange);
|
||||||
|
|
||||||
|
@ -167,7 +169,8 @@ public class RequestParamMethodArgumentResolverTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveSimpleTypeParam() throws Exception {
|
public void resolveSimpleTypeParam() throws Exception {
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/path?stringNotAnnot=plainValue").toExchange();
|
MockServerHttpRequest request = MockServerHttpRequest.get("/path?stringNotAnnot=plainValue").build();
|
||||||
|
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
MethodParameter param = this.testMethod.annotNotPresent(RequestParam.class).arg(String.class);
|
MethodParameter param = this.testMethod.annotNotPresent(RequestParam.class).arg(String.class);
|
||||||
Object result = resolve(param, exchange);
|
Object result = resolve(param, exchange);
|
||||||
assertEquals("plainValue", result);
|
assertEquals("plainValue", result);
|
||||||
|
@ -176,12 +179,12 @@ public class RequestParamMethodArgumentResolverTests {
|
||||||
@Test // SPR-8561
|
@Test // SPR-8561
|
||||||
public void resolveSimpleTypeParamToNull() throws Exception {
|
public void resolveSimpleTypeParamToNull() throws Exception {
|
||||||
MethodParameter param = this.testMethod.annotNotPresent(RequestParam.class).arg(String.class);
|
MethodParameter param = this.testMethod.annotNotPresent(RequestParam.class).arg(String.class);
|
||||||
assertNull(resolve(param, MockServerHttpRequest.get("/").toExchange()));
|
assertNull(resolve(param, MockServerWebExchange.from(MockServerHttpRequest.get("/").build())));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // SPR-10180
|
@Test // SPR-10180
|
||||||
public void resolveEmptyValueToDefault() throws Exception {
|
public void resolveEmptyValueToDefault() throws Exception {
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/path?name=").toExchange();
|
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path?name=").build());
|
||||||
MethodParameter param = this.testMethod.annot(requestParam().notRequired("bar")).arg(String.class);
|
MethodParameter param = this.testMethod.annot(requestParam().notRequired("bar")).arg(String.class);
|
||||||
Object result = resolve(param, exchange);
|
Object result = resolve(param, exchange);
|
||||||
assertEquals("bar", result);
|
assertEquals("bar", result);
|
||||||
|
@ -190,23 +193,25 @@ public class RequestParamMethodArgumentResolverTests {
|
||||||
@Test
|
@Test
|
||||||
public void resolveEmptyValueWithoutDefault() throws Exception {
|
public void resolveEmptyValueWithoutDefault() throws Exception {
|
||||||
MethodParameter param = this.testMethod.annotNotPresent(RequestParam.class).arg(String.class);
|
MethodParameter param = this.testMethod.annotNotPresent(RequestParam.class).arg(String.class);
|
||||||
assertEquals("", resolve(param, MockServerHttpRequest.get("/path?stringNotAnnot=").toExchange()));
|
MockServerHttpRequest request = MockServerHttpRequest.get("/path?stringNotAnnot=").build();
|
||||||
|
assertEquals("", resolve(param, MockServerWebExchange.from(request)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveEmptyValueRequiredWithoutDefault() throws Exception {
|
public void resolveEmptyValueRequiredWithoutDefault() throws Exception {
|
||||||
MethodParameter param = this.testMethod.annot(requestParam()).arg(String.class);
|
MethodParameter param = this.testMethod.annot(requestParam()).arg(String.class);
|
||||||
assertEquals("", resolve(param, MockServerHttpRequest.get("/path?name=").toExchange()));
|
MockServerHttpRequest request = MockServerHttpRequest.get("/path?name=").build();
|
||||||
|
assertEquals("", resolve(param, MockServerWebExchange.from(request)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveOptionalParamValue() throws Exception {
|
public void resolveOptionalParamValue() throws Exception {
|
||||||
ServerWebExchange exchange = MockServerHttpRequest.get("/").toExchange();
|
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||||
MethodParameter param = this.testMethod.arg(forClassWithGenerics(Optional.class, Integer.class));
|
MethodParameter param = this.testMethod.arg(forClassWithGenerics(Optional.class, Integer.class));
|
||||||
Object result = resolve(param, exchange);
|
Object result = resolve(param, exchange);
|
||||||
assertEquals(Optional.empty(), result);
|
assertEquals(Optional.empty(), result);
|
||||||
|
|
||||||
exchange = MockServerHttpRequest.get("/path?name=123").toExchange();
|
exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path?name=123").build());
|
||||||
result = resolve(param, exchange);
|
result = resolve(param, exchange);
|
||||||
|
|
||||||
assertEquals(Optional.class, result.getClass());
|
assertEquals(Optional.class, result.getClass());
|
||||||
|
|
|
@ -50,7 +50,7 @@ import org.springframework.http.codec.HttpMessageWriter;
|
||||||
import org.springframework.http.codec.ResourceHttpMessageWriter;
|
import org.springframework.http.codec.ResourceHttpMessageWriter;
|
||||||
import org.springframework.http.codec.json.Jackson2JsonEncoder;
|
import org.springframework.http.codec.json.Jackson2JsonEncoder;
|
||||||
import org.springframework.http.codec.xml.Jaxb2XmlEncoder;
|
import org.springframework.http.codec.xml.Jaxb2XmlEncoder;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerWebExchange;
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
import org.springframework.web.reactive.HandlerResult;
|
import org.springframework.web.reactive.HandlerResult;
|
||||||
import org.springframework.web.reactive.accept.RequestedContentTypeResolver;
|
import org.springframework.web.reactive.accept.RequestedContentTypeResolver;
|
||||||
|
@ -159,7 +159,7 @@ public class ResponseEntityResultHandlerTests {
|
||||||
ResponseEntity<Void> value = ResponseEntity.noContent().build();
|
ResponseEntity<Void> value = ResponseEntity.noContent().build();
|
||||||
MethodParameter returnType = on(TestController.class).resolveReturnType(entity(Void.class));
|
MethodParameter returnType = on(TestController.class).resolveReturnType(entity(Void.class));
|
||||||
HandlerResult result = handlerResult(value, returnType);
|
HandlerResult result = handlerResult(value, returnType);
|
||||||
MockServerWebExchange exchange = get("/path").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/path").build());
|
||||||
this.resultHandler.handleResult(exchange, result).block(Duration.ofSeconds(5));
|
this.resultHandler.handleResult(exchange, result).block(Duration.ofSeconds(5));
|
||||||
|
|
||||||
assertEquals(HttpStatus.NO_CONTENT, exchange.getResponse().getStatusCode());
|
assertEquals(HttpStatus.NO_CONTENT, exchange.getResponse().getStatusCode());
|
||||||
|
@ -173,7 +173,7 @@ public class ResponseEntityResultHandlerTests {
|
||||||
headers.setAllow(new LinkedHashSet<>(Arrays.asList(HttpMethod.GET, HttpMethod.POST, HttpMethod.OPTIONS)));
|
headers.setAllow(new LinkedHashSet<>(Arrays.asList(HttpMethod.GET, HttpMethod.POST, HttpMethod.OPTIONS)));
|
||||||
MethodParameter returnType = on(TestController.class).resolveReturnType(entity(Void.class));
|
MethodParameter returnType = on(TestController.class).resolveReturnType(entity(Void.class));
|
||||||
HandlerResult result = handlerResult(headers, returnType);
|
HandlerResult result = handlerResult(headers, returnType);
|
||||||
MockServerWebExchange exchange = get("/path").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/path").build());
|
||||||
this.resultHandler.handleResult(exchange, result).block(Duration.ofSeconds(5));
|
this.resultHandler.handleResult(exchange, result).block(Duration.ofSeconds(5));
|
||||||
|
|
||||||
assertEquals(HttpStatus.OK, exchange.getResponse().getStatusCode());
|
assertEquals(HttpStatus.OK, exchange.getResponse().getStatusCode());
|
||||||
|
@ -188,7 +188,7 @@ public class ResponseEntityResultHandlerTests {
|
||||||
ResponseEntity<Void> value = ResponseEntity.created(location).build();
|
ResponseEntity<Void> value = ResponseEntity.created(location).build();
|
||||||
MethodParameter returnType = on(TestController.class).resolveReturnType(entity(Void.class));
|
MethodParameter returnType = on(TestController.class).resolveReturnType(entity(Void.class));
|
||||||
HandlerResult result = handlerResult(value, returnType);
|
HandlerResult result = handlerResult(value, returnType);
|
||||||
MockServerWebExchange exchange = get("/path").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/path").build());
|
||||||
this.resultHandler.handleResult(exchange, result).block(Duration.ofSeconds(5));
|
this.resultHandler.handleResult(exchange, result).block(Duration.ofSeconds(5));
|
||||||
|
|
||||||
assertEquals(HttpStatus.CREATED, exchange.getResponse().getStatusCode());
|
assertEquals(HttpStatus.CREATED, exchange.getResponse().getStatusCode());
|
||||||
|
@ -202,7 +202,7 @@ public class ResponseEntityResultHandlerTests {
|
||||||
Object returnValue = Mono.just(notFound().build());
|
Object returnValue = Mono.just(notFound().build());
|
||||||
MethodParameter type = on(TestController.class).resolveReturnType(Mono.class, entity(String.class));
|
MethodParameter type = on(TestController.class).resolveReturnType(Mono.class, entity(String.class));
|
||||||
HandlerResult result = handlerResult(returnValue, type);
|
HandlerResult result = handlerResult(returnValue, type);
|
||||||
MockServerWebExchange exchange = get("/path").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/path").build());
|
||||||
this.resultHandler.handleResult(exchange, result).block(Duration.ofSeconds(5));
|
this.resultHandler.handleResult(exchange, result).block(Duration.ofSeconds(5));
|
||||||
|
|
||||||
assertEquals(HttpStatus.NOT_FOUND, exchange.getResponse().getStatusCode());
|
assertEquals(HttpStatus.NOT_FOUND, exchange.getResponse().getStatusCode());
|
||||||
|
@ -235,7 +235,7 @@ public class ResponseEntityResultHandlerTests {
|
||||||
public void handleReturnValueLastModified() throws Exception {
|
public void handleReturnValueLastModified() throws Exception {
|
||||||
Instant currentTime = Instant.now().truncatedTo(ChronoUnit.SECONDS);
|
Instant currentTime = Instant.now().truncatedTo(ChronoUnit.SECONDS);
|
||||||
Instant oneMinAgo = currentTime.minusSeconds(60);
|
Instant oneMinAgo = currentTime.minusSeconds(60);
|
||||||
MockServerWebExchange exchange = get("/path").ifModifiedSince(currentTime.toEpochMilli()).toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/path").ifModifiedSince(currentTime.toEpochMilli()).build());
|
||||||
|
|
||||||
ResponseEntity<String> entity = ok().lastModified(oneMinAgo.toEpochMilli()).body("body");
|
ResponseEntity<String> entity = ok().lastModified(oneMinAgo.toEpochMilli()).body("body");
|
||||||
MethodParameter returnType = on(TestController.class).resolveReturnType(entity(String.class));
|
MethodParameter returnType = on(TestController.class).resolveReturnType(entity(String.class));
|
||||||
|
@ -248,7 +248,7 @@ public class ResponseEntityResultHandlerTests {
|
||||||
@Test
|
@Test
|
||||||
public void handleReturnValueEtag() throws Exception {
|
public void handleReturnValueEtag() throws Exception {
|
||||||
String etagValue = "\"deadb33f8badf00d\"";
|
String etagValue = "\"deadb33f8badf00d\"";
|
||||||
MockServerWebExchange exchange = get("/path").ifNoneMatch(etagValue).toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/path").ifNoneMatch(etagValue).build());
|
||||||
|
|
||||||
ResponseEntity<String> entity = ok().eTag(etagValue).body("body");
|
ResponseEntity<String> entity = ok().eTag(etagValue).body("body");
|
||||||
MethodParameter returnType = on(TestController.class).resolveReturnType(entity(String.class));
|
MethodParameter returnType = on(TestController.class).resolveReturnType(entity(String.class));
|
||||||
|
@ -260,7 +260,7 @@ public class ResponseEntityResultHandlerTests {
|
||||||
|
|
||||||
@Test // SPR-14559
|
@Test // SPR-14559
|
||||||
public void handleReturnValueEtagInvalidIfNoneMatch() throws Exception {
|
public void handleReturnValueEtagInvalidIfNoneMatch() throws Exception {
|
||||||
MockServerWebExchange exchange = get("/path").ifNoneMatch("unquoted").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/path").ifNoneMatch("unquoted").build());
|
||||||
|
|
||||||
ResponseEntity<String> entity = ok().eTag("\"deadb33f8badf00d\"").body("body");
|
ResponseEntity<String> entity = ok().eTag("\"deadb33f8badf00d\"").body("body");
|
||||||
MethodParameter returnType = on(TestController.class).resolveReturnType(entity(String.class));
|
MethodParameter returnType = on(TestController.class).resolveReturnType(entity(String.class));
|
||||||
|
@ -278,10 +278,10 @@ public class ResponseEntityResultHandlerTests {
|
||||||
Instant currentTime = Instant.now().truncatedTo(ChronoUnit.SECONDS);
|
Instant currentTime = Instant.now().truncatedTo(ChronoUnit.SECONDS);
|
||||||
Instant oneMinAgo = currentTime.minusSeconds(60);
|
Instant oneMinAgo = currentTime.minusSeconds(60);
|
||||||
|
|
||||||
MockServerWebExchange exchange = get("/path")
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/path")
|
||||||
.ifNoneMatch(eTag)
|
.ifNoneMatch(eTag)
|
||||||
.ifModifiedSince(currentTime.toEpochMilli())
|
.ifModifiedSince(currentTime.toEpochMilli())
|
||||||
.toExchange();
|
.build());
|
||||||
|
|
||||||
ResponseEntity<String> entity = ok().eTag(eTag).lastModified(oneMinAgo.toEpochMilli()).body("body");
|
ResponseEntity<String> entity = ok().eTag(eTag).lastModified(oneMinAgo.toEpochMilli()).body("body");
|
||||||
MethodParameter returnType = on(TestController.class).resolveReturnType(entity(String.class));
|
MethodParameter returnType = on(TestController.class).resolveReturnType(entity(String.class));
|
||||||
|
@ -299,10 +299,10 @@ public class ResponseEntityResultHandlerTests {
|
||||||
Instant currentTime = Instant.now().truncatedTo(ChronoUnit.SECONDS);
|
Instant currentTime = Instant.now().truncatedTo(ChronoUnit.SECONDS);
|
||||||
Instant oneMinAgo = currentTime.minusSeconds(60);
|
Instant oneMinAgo = currentTime.minusSeconds(60);
|
||||||
|
|
||||||
MockServerWebExchange exchange = get("/path")
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/path")
|
||||||
.ifNoneMatch(etag)
|
.ifNoneMatch(etag)
|
||||||
.ifModifiedSince(currentTime.toEpochMilli())
|
.ifModifiedSince(currentTime.toEpochMilli())
|
||||||
.toExchange();
|
.build());
|
||||||
|
|
||||||
ResponseEntity<String> entity = ok().eTag(newEtag).lastModified(oneMinAgo.toEpochMilli()).body("body");
|
ResponseEntity<String> entity = ok().eTag(newEtag).lastModified(oneMinAgo.toEpochMilli()).body("body");
|
||||||
MethodParameter returnType = on(TestController.class).resolveReturnType(entity(String.class));
|
MethodParameter returnType = on(TestController.class).resolveReturnType(entity(String.class));
|
||||||
|
@ -315,7 +315,7 @@ public class ResponseEntityResultHandlerTests {
|
||||||
@Test // SPR-14877
|
@Test // SPR-14877
|
||||||
public void handleMonoWithWildcardBodyType() throws Exception {
|
public void handleMonoWithWildcardBodyType() throws Exception {
|
||||||
|
|
||||||
MockServerWebExchange exchange = get("/path").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/path").build());
|
||||||
exchange.getAttributes().put(PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE, Collections.singleton(APPLICATION_JSON));
|
exchange.getAttributes().put(PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE, Collections.singleton(APPLICATION_JSON));
|
||||||
|
|
||||||
MethodParameter type = on(TestController.class).resolveReturnType(Mono.class, ResponseEntity.class);
|
MethodParameter type = on(TestController.class).resolveReturnType(Mono.class, ResponseEntity.class);
|
||||||
|
@ -330,7 +330,7 @@ public class ResponseEntityResultHandlerTests {
|
||||||
@Test // SPR-14877
|
@Test // SPR-14877
|
||||||
public void handleMonoWithWildcardBodyTypeAndNullBody() throws Exception {
|
public void handleMonoWithWildcardBodyTypeAndNullBody() throws Exception {
|
||||||
|
|
||||||
MockServerWebExchange exchange = get("/path").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/path").build());
|
||||||
exchange.getAttributes().put(PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE, Collections.singleton(APPLICATION_JSON));
|
exchange.getAttributes().put(PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE, Collections.singleton(APPLICATION_JSON));
|
||||||
|
|
||||||
MethodParameter returnType = on(TestController.class).resolveReturnType(Mono.class, ResponseEntity.class);
|
MethodParameter returnType = on(TestController.class).resolveReturnType(Mono.class, ResponseEntity.class);
|
||||||
|
@ -345,7 +345,7 @@ public class ResponseEntityResultHandlerTests {
|
||||||
|
|
||||||
private void testHandle(Object returnValue, MethodParameter returnType) {
|
private void testHandle(Object returnValue, MethodParameter returnType) {
|
||||||
|
|
||||||
MockServerWebExchange exchange = get("/path").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/path").build());
|
||||||
HandlerResult result = handlerResult(returnValue, returnType);
|
HandlerResult result = handlerResult(returnValue, returnType);
|
||||||
this.resultHandler.handleResult(exchange, result).block(Duration.ofSeconds(5));
|
this.resultHandler.handleResult(exchange, result).block(Duration.ofSeconds(5));
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ import org.springframework.http.HttpMethod;
|
||||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||||
import org.springframework.http.server.reactive.ServerHttpResponse;
|
import org.springframework.http.server.reactive.ServerHttpResponse;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerWebExchange;
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.web.method.ResolvableMethod;
|
import org.springframework.web.method.ResolvableMethod;
|
||||||
import org.springframework.web.reactive.BindingContext;
|
import org.springframework.web.reactive.BindingContext;
|
||||||
import org.springframework.web.server.ServerWebExchange;
|
import org.springframework.web.server.ServerWebExchange;
|
||||||
|
@ -40,7 +40,6 @@ import org.springframework.web.util.UriComponentsBuilder;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertSame;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
|
@ -53,7 +52,8 @@ public class ServerWebExchangeArgumentResolverTests {
|
||||||
private final ServerWebExchangeArgumentResolver resolver =
|
private final ServerWebExchangeArgumentResolver resolver =
|
||||||
new ServerWebExchangeArgumentResolver(new ReactiveAdapterRegistry());
|
new ServerWebExchangeArgumentResolver(new ReactiveAdapterRegistry());
|
||||||
|
|
||||||
private final MockServerWebExchange exchange = MockServerHttpRequest.get("/path").toExchange();
|
private final MockServerWebExchange exchange = MockServerWebExchange.from(
|
||||||
|
MockServerHttpRequest.get("/path").build());
|
||||||
|
|
||||||
private ResolvableMethod testMethod = ResolvableMethod.on(getClass()).named("handle").build();
|
private ResolvableMethod testMethod = ResolvableMethod.on(getClass()).named("handle").build();
|
||||||
|
|
||||||
|
|
|
@ -30,11 +30,13 @@ import reactor.test.StepVerifier;
|
||||||
|
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerWebExchange;
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.tests.sample.beans.TestBean;
|
import org.springframework.tests.sample.beans.TestBean;
|
||||||
import org.springframework.web.server.ServerWebExchange;
|
import org.springframework.web.server.ServerWebExchange;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for {@link AbstractView}.
|
* Unit tests for {@link AbstractView}.
|
||||||
|
@ -47,7 +49,7 @@ public class AbstractViewTests {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
this.exchange = MockServerHttpRequest.get("/").toExchange();
|
this.exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
|
|
@ -34,7 +34,7 @@ import org.springframework.http.MediaType;
|
||||||
import org.springframework.http.codec.json.Jackson2JsonEncoder;
|
import org.springframework.http.codec.json.Jackson2JsonEncoder;
|
||||||
import org.springframework.http.codec.xml.Jaxb2XmlEncoder;
|
import org.springframework.http.codec.xml.Jaxb2XmlEncoder;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerWebExchange;
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.ui.ExtendedModelMap;
|
import org.springframework.ui.ExtendedModelMap;
|
||||||
import org.springframework.ui.ModelMap;
|
import org.springframework.ui.ModelMap;
|
||||||
|
|
||||||
|
@ -53,7 +53,8 @@ public class HttpMessageWriterViewTests {
|
||||||
|
|
||||||
private final ModelMap model = new ExtendedModelMap();
|
private final ModelMap model = new ExtendedModelMap();
|
||||||
|
|
||||||
private final MockServerWebExchange exchange = MockServerHttpRequest.get("/").toExchange();
|
private final MockServerWebExchange exchange = MockServerWebExchange.from(
|
||||||
|
MockServerHttpRequest.get("/").build());
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -27,7 +27,7 @@ import org.junit.Test;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerWebExchange;
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.web.reactive.HandlerMapping;
|
import org.springframework.web.reactive.HandlerMapping;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
@ -47,7 +47,8 @@ public class RedirectViewTests {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
this.exchange = MockServerHttpRequest.get("/context/path").contextPath("/context").toExchange();
|
this.exchange = MockServerWebExchange.from(
|
||||||
|
MockServerHttpRequest.get("/context/path").contextPath("/context").build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -129,7 +130,8 @@ public class RedirectViewTests {
|
||||||
public void propagateQueryParams() throws Exception {
|
public void propagateQueryParams() throws Exception {
|
||||||
RedirectView view = new RedirectView("http://url.somewhere.com?foo=bar#bazz");
|
RedirectView view = new RedirectView("http://url.somewhere.com?foo=bar#bazz");
|
||||||
view.setPropagateQuery(true);
|
view.setPropagateQuery(true);
|
||||||
this.exchange = MockServerHttpRequest.get("http://url.somewhere.com?a=b&c=d").toExchange();
|
MockServerHttpRequest request = MockServerHttpRequest.get("http://url.somewhere.com?a=b&c=d").build();
|
||||||
|
this.exchange = MockServerWebExchange.from(request);
|
||||||
view.render(new HashMap<>(), MediaType.TEXT_HTML, this.exchange).block();
|
view.render(new HashMap<>(), MediaType.TEXT_HTML, this.exchange).block();
|
||||||
assertEquals(HttpStatus.SEE_OTHER, this.exchange.getResponse().getStatusCode());
|
assertEquals(HttpStatus.SEE_OTHER, this.exchange.getResponse().getStatusCode());
|
||||||
assertEquals(URI.create("http://url.somewhere.com?foo=bar&a=b&c=d#bazz"),
|
assertEquals(URI.create("http://url.somewhere.com?foo=bar&a=b&c=d#bazz"),
|
||||||
|
|
|
@ -24,7 +24,7 @@ import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.context.support.GenericApplicationContext;
|
import org.springframework.context.support.GenericApplicationContext;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerWebExchange;
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
@ -34,8 +34,8 @@ import static org.junit.Assert.assertEquals;
|
||||||
*/
|
*/
|
||||||
public class RequestContextTests {
|
public class RequestContextTests {
|
||||||
|
|
||||||
private final MockServerWebExchange exchange = MockServerHttpRequest.get("/foo/path")
|
private final MockServerWebExchange exchange =
|
||||||
.contextPath("/foo").toExchange();
|
MockServerWebExchange.from(MockServerHttpRequest.get("/foo/path").contextPath("/foo").build());
|
||||||
|
|
||||||
private GenericApplicationContext applicationContext;
|
private GenericApplicationContext applicationContext;
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ import org.springframework.http.MediaType;
|
||||||
import org.springframework.http.server.reactive.ServerHttpResponse;
|
import org.springframework.http.server.reactive.ServerHttpResponse;
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerWebExchange;
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.ui.ConcurrentModel;
|
import org.springframework.ui.ConcurrentModel;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||||
|
@ -216,15 +216,15 @@ public class ViewResolutionResultHandlerTests {
|
||||||
HandlerResult result = new HandlerResult(new Object(), returnValue, returnType, this.bindingContext);
|
HandlerResult result = new HandlerResult(new Object(), returnValue, returnType, this.bindingContext);
|
||||||
ViewResolutionResultHandler handler = resultHandler(new TestViewResolver("account"));
|
ViewResolutionResultHandler handler = resultHandler(new TestViewResolver("account"));
|
||||||
|
|
||||||
MockServerWebExchange exchange = get("/account").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/account").build());
|
||||||
handler.handleResult(exchange, result).block(Duration.ofMillis(5000));
|
handler.handleResult(exchange, result).block(Duration.ofMillis(5000));
|
||||||
assertResponseBody(exchange, "account: {id=123}");
|
assertResponseBody(exchange, "account: {id=123}");
|
||||||
|
|
||||||
exchange = get("/account/").toExchange();
|
exchange = MockServerWebExchange.from(get("/account/").build());
|
||||||
handler.handleResult(exchange, result).block(Duration.ofMillis(5000));
|
handler.handleResult(exchange, result).block(Duration.ofMillis(5000));
|
||||||
assertResponseBody(exchange, "account: {id=123}");
|
assertResponseBody(exchange, "account: {id=123}");
|
||||||
|
|
||||||
exchange = get("/account.123").toExchange();
|
exchange = MockServerWebExchange.from(get("/account.123").build());
|
||||||
handler.handleResult(exchange, result).block(Duration.ofMillis(5000));
|
handler.handleResult(exchange, result).block(Duration.ofMillis(5000));
|
||||||
assertResponseBody(exchange, "account: {id=123}");
|
assertResponseBody(exchange, "account: {id=123}");
|
||||||
}
|
}
|
||||||
|
@ -235,7 +235,7 @@ public class ViewResolutionResultHandlerTests {
|
||||||
MethodParameter returnType = on(Handler.class).annotPresent(ModelAttribute.class).resolveReturnType(String.class);
|
MethodParameter returnType = on(Handler.class).annotPresent(ModelAttribute.class).resolveReturnType(String.class);
|
||||||
HandlerResult result = new HandlerResult(new Object(), returnValue, returnType, this.bindingContext);
|
HandlerResult result = new HandlerResult(new Object(), returnValue, returnType, this.bindingContext);
|
||||||
|
|
||||||
MockServerWebExchange exchange = get("/path").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/path").build());
|
||||||
Mono<Void> mono = resultHandler().handleResult(exchange, result);
|
Mono<Void> mono = resultHandler().handleResult(exchange, result);
|
||||||
|
|
||||||
StepVerifier.create(mono)
|
StepVerifier.create(mono)
|
||||||
|
@ -250,7 +250,7 @@ public class ViewResolutionResultHandlerTests {
|
||||||
MethodParameter returnType = on(Handler.class).resolveReturnType(TestBean.class);
|
MethodParameter returnType = on(Handler.class).resolveReturnType(TestBean.class);
|
||||||
HandlerResult handlerResult = new HandlerResult(new Object(), value, returnType, this.bindingContext);
|
HandlerResult handlerResult = new HandlerResult(new Object(), value, returnType, this.bindingContext);
|
||||||
|
|
||||||
MockServerWebExchange exchange = get("/account").accept(APPLICATION_JSON).toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/account").accept(APPLICATION_JSON).build());
|
||||||
|
|
||||||
TestView defaultView = new TestView("jsonView", APPLICATION_JSON);
|
TestView defaultView = new TestView("jsonView", APPLICATION_JSON);
|
||||||
|
|
||||||
|
@ -272,7 +272,7 @@ public class ViewResolutionResultHandlerTests {
|
||||||
MethodParameter returnType = on(Handler.class).resolveReturnType(TestBean.class);
|
MethodParameter returnType = on(Handler.class).resolveReturnType(TestBean.class);
|
||||||
HandlerResult handlerResult = new HandlerResult(new Object(), value, returnType, this.bindingContext);
|
HandlerResult handlerResult = new HandlerResult(new Object(), value, returnType, this.bindingContext);
|
||||||
|
|
||||||
MockServerWebExchange exchange = get("/account").accept(APPLICATION_JSON).toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/account").accept(APPLICATION_JSON).build());
|
||||||
|
|
||||||
ViewResolutionResultHandler resultHandler = resultHandler(new TestViewResolver("account"));
|
ViewResolutionResultHandler resultHandler = resultHandler(new TestViewResolver("account"));
|
||||||
Mono<Void> mono = resultHandler.handleResult(exchange, handlerResult);
|
Mono<Void> mono = resultHandler.handleResult(exchange, handlerResult);
|
||||||
|
@ -293,7 +293,7 @@ public class ViewResolutionResultHandlerTests {
|
||||||
viewResolver.setApplicationContext(new StaticApplicationContext());
|
viewResolver.setApplicationContext(new StaticApplicationContext());
|
||||||
ViewResolutionResultHandler resultHandler = resultHandler(viewResolver);
|
ViewResolutionResultHandler resultHandler = resultHandler(viewResolver);
|
||||||
|
|
||||||
MockServerWebExchange exchange = get("/account").accept(APPLICATION_JSON).toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(get("/account").accept(APPLICATION_JSON).build());
|
||||||
resultHandler.handleResult(exchange, handlerResult).block(Duration.ZERO);
|
resultHandler.handleResult(exchange, handlerResult).block(Duration.ZERO);
|
||||||
|
|
||||||
MockServerHttpResponse response = exchange.getResponse();
|
MockServerHttpResponse response = exchange.getResponse();
|
||||||
|
@ -321,7 +321,7 @@ public class ViewResolutionResultHandlerTests {
|
||||||
model.asMap().clear();
|
model.asMap().clear();
|
||||||
model.addAttribute("id", "123");
|
model.addAttribute("id", "123");
|
||||||
HandlerResult result = new HandlerResult(new Object(), returnValue, returnType, this.bindingContext);
|
HandlerResult result = new HandlerResult(new Object(), returnValue, returnType, this.bindingContext);
|
||||||
MockServerWebExchange exchange = get(path).toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(get(path).build());
|
||||||
resultHandler(resolvers).handleResult(exchange, result).block(Duration.ofSeconds(5));
|
resultHandler(resolvers).handleResult(exchange, result).block(Duration.ofSeconds(5));
|
||||||
assertResponseBody(exchange, responseBody);
|
assertResponseBody(exchange, responseBody);
|
||||||
return exchange;
|
return exchange;
|
||||||
|
|
|
@ -32,7 +32,7 @@ import org.springframework.context.ApplicationContextException;
|
||||||
import org.springframework.context.support.GenericApplicationContext;
|
import org.springframework.context.support.GenericApplicationContext;
|
||||||
import org.springframework.core.io.buffer.DataBuffer;
|
import org.springframework.core.io.buffer.DataBuffer;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerWebExchange;
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.ui.ExtendedModelMap;
|
import org.springframework.ui.ExtendedModelMap;
|
||||||
import org.springframework.ui.ModelMap;
|
import org.springframework.ui.ModelMap;
|
||||||
|
|
||||||
|
@ -47,7 +47,8 @@ public class FreeMarkerViewTests {
|
||||||
private static final String TEMPLATE_PATH = "classpath*:org/springframework/web/reactive/view/freemarker/";
|
private static final String TEMPLATE_PATH = "classpath*:org/springframework/web/reactive/view/freemarker/";
|
||||||
|
|
||||||
|
|
||||||
private final MockServerWebExchange exchange = MockServerHttpRequest.get("/path").toExchange();
|
private final MockServerWebExchange exchange =
|
||||||
|
MockServerWebExchange.from(MockServerHttpRequest.get("/path").build());
|
||||||
|
|
||||||
private GenericApplicationContext context;
|
private GenericApplicationContext context;
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerWebExchange;
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ public class JRubyScriptTemplateTests {
|
||||||
|
|
||||||
private MockServerHttpResponse renderViewWithModel(String viewUrl, Map<String, Object> model) throws Exception {
|
private MockServerHttpResponse renderViewWithModel(String viewUrl, Map<String, Object> model) throws Exception {
|
||||||
ScriptTemplateView view = createViewWithUrl(viewUrl);
|
ScriptTemplateView view = createViewWithUrl(viewUrl);
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("/").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||||
view.renderInternal(model, MediaType.TEXT_HTML, exchange).block();
|
view.renderInternal(model, MediaType.TEXT_HTML, exchange).block();
|
||||||
return exchange.getResponse();
|
return exchange.getResponse();
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerWebExchange;
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ public class JythonScriptTemplateTests {
|
||||||
|
|
||||||
private MockServerHttpResponse renderViewWithModel(String viewUrl, Map<String, Object> model) throws Exception {
|
private MockServerHttpResponse renderViewWithModel(String viewUrl, Map<String, Object> model) throws Exception {
|
||||||
ScriptTemplateView view = createViewWithUrl(viewUrl);
|
ScriptTemplateView view = createViewWithUrl(viewUrl);
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("/").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||||
view.renderInternal(model, MediaType.TEXT_HTML, exchange).block();
|
view.renderInternal(model, MediaType.TEXT_HTML, exchange).block();
|
||||||
return exchange.getResponse();
|
return exchange.getResponse();
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,9 +30,9 @@ import org.springframework.context.support.ResourceBundleMessageSource;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerWebExchange;
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for Kotlin script templates running on Kotlin JSR-223 support.
|
* Unit tests for Kotlin script templates running on Kotlin JSR-223 support.
|
||||||
|
@ -76,9 +76,12 @@ public class KotlinScriptTemplateTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private MockServerHttpResponse renderViewWithModel(String viewUrl, Map<String, Object> model, Locale locale, Class<?> configuration) throws Exception {
|
private MockServerHttpResponse renderViewWithModel(String viewUrl, Map<String, Object> model,
|
||||||
|
Locale locale, Class<?> configuration) throws Exception {
|
||||||
|
|
||||||
ScriptTemplateView view = createViewWithUrl(viewUrl, configuration);
|
ScriptTemplateView view = createViewWithUrl(viewUrl, configuration);
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("/").acceptLanguageAsLocales(locale).toExchange();
|
MockServerHttpRequest request = MockServerHttpRequest.get("/").acceptLanguageAsLocales(locale).build();
|
||||||
|
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||||
view.renderInternal(model, MediaType.TEXT_HTML, exchange).block();
|
view.renderInternal(model, MediaType.TEXT_HTML, exchange).block();
|
||||||
return exchange.getResponse();
|
return exchange.getResponse();
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse;
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse;
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerWebExchange;
|
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ public class NashornScriptTemplateTests {
|
||||||
|
|
||||||
private MockServerHttpResponse renderViewWithModel(String viewUrl, Map<String, Object> model, Class<?> configuration) throws Exception {
|
private MockServerHttpResponse renderViewWithModel(String viewUrl, Map<String, Object> model, Class<?> configuration) throws Exception {
|
||||||
ScriptTemplateView view = createViewWithUrl(viewUrl, configuration);
|
ScriptTemplateView view = createViewWithUrl(viewUrl, configuration);
|
||||||
MockServerWebExchange exchange = MockServerHttpRequest.get("/").toExchange();
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||||
view.renderInternal(model, MediaType.TEXT_HTML, exchange).block();
|
view.renderInternal(model, MediaType.TEXT_HTML, exchange).block();
|
||||||
return exchange.getResponse();
|
return exchange.getResponse();
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ import org.springframework.core.ReactiveAdapterRegistry
|
||||||
import org.springframework.core.annotation.SynthesizingMethodParameter
|
import org.springframework.core.annotation.SynthesizingMethodParameter
|
||||||
import org.springframework.format.support.DefaultFormattingConversionService
|
import org.springframework.format.support.DefaultFormattingConversionService
|
||||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest
|
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest
|
||||||
|
import org.springframework.mock.web.test.server.MockServerWebExchange
|
||||||
import org.springframework.util.ReflectionUtils
|
import org.springframework.util.ReflectionUtils
|
||||||
import org.springframework.web.bind.annotation.RequestParam
|
import org.springframework.web.bind.annotation.RequestParam
|
||||||
import org.springframework.web.bind.support.ConfigurableWebBindingInitializer
|
import org.springframework.web.bind.support.ConfigurableWebBindingInitializer
|
||||||
|
@ -64,56 +65,56 @@ class RequestParamMethodArgumentResolverKotlinTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun resolveNullableRequiredWithParameter() {
|
fun resolveNullableRequiredWithParameter() {
|
||||||
var exchange = MockServerHttpRequest.get("/path?name=123").toExchange()
|
var exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path?name=123").build())
|
||||||
var result = resolver.resolveArgument(nullableParamRequired, bindingContext, exchange)
|
var result = resolver.resolveArgument(nullableParamRequired, bindingContext, exchange)
|
||||||
StepVerifier.create(result).expectNext("123").expectComplete().verify()
|
StepVerifier.create(result).expectNext("123").expectComplete().verify()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun resolveNullableRequiredWithoutParameter() {
|
fun resolveNullableRequiredWithoutParameter() {
|
||||||
var exchange = MockServerHttpRequest.get("/").toExchange()
|
var exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build())
|
||||||
var result = resolver.resolveArgument(nullableParamRequired, bindingContext, exchange)
|
var result = resolver.resolveArgument(nullableParamRequired, bindingContext, exchange)
|
||||||
StepVerifier.create(result).expectComplete().verify()
|
StepVerifier.create(result).expectComplete().verify()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun resolveNullableNotRequiredWithParameter() {
|
fun resolveNullableNotRequiredWithParameter() {
|
||||||
var exchange = MockServerHttpRequest.get("/path?name=123").toExchange()
|
var exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path?name=123").build())
|
||||||
var result = resolver.resolveArgument(nullableParamNotRequired, bindingContext, exchange)
|
var result = resolver.resolveArgument(nullableParamNotRequired, bindingContext, exchange)
|
||||||
StepVerifier.create(result).expectNext("123").expectComplete().verify()
|
StepVerifier.create(result).expectNext("123").expectComplete().verify()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun resolveNullableNotRequiredWithoutParameter() {
|
fun resolveNullableNotRequiredWithoutParameter() {
|
||||||
var exchange = MockServerHttpRequest.get("/").toExchange()
|
var exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build())
|
||||||
var result = resolver.resolveArgument(nullableParamNotRequired, bindingContext, exchange)
|
var result = resolver.resolveArgument(nullableParamNotRequired, bindingContext, exchange)
|
||||||
StepVerifier.create(result).expectComplete().verify()
|
StepVerifier.create(result).expectComplete().verify()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun resolveNonNullableRequiredWithParameter() {
|
fun resolveNonNullableRequiredWithParameter() {
|
||||||
var exchange = MockServerHttpRequest.get("/path?name=123").toExchange()
|
var exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path?name=123").build())
|
||||||
var result = resolver.resolveArgument(nonNullableParamRequired, bindingContext, exchange)
|
var result = resolver.resolveArgument(nonNullableParamRequired, bindingContext, exchange)
|
||||||
StepVerifier.create(result).expectNext("123").expectComplete().verify()
|
StepVerifier.create(result).expectNext("123").expectComplete().verify()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun resolveNonNullableRequiredWithoutParameter() {
|
fun resolveNonNullableRequiredWithoutParameter() {
|
||||||
var exchange = MockServerHttpRequest.get("/").toExchange()
|
var exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build())
|
||||||
var result = resolver.resolveArgument(nonNullableParamRequired, bindingContext, exchange)
|
var result = resolver.resolveArgument(nonNullableParamRequired, bindingContext, exchange)
|
||||||
StepVerifier.create(result).expectError(ServerWebInputException::class.java).verify()
|
StepVerifier.create(result).expectError(ServerWebInputException::class.java).verify()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun resolveNonNullableNotRequiredWithParameter() {
|
fun resolveNonNullableNotRequiredWithParameter() {
|
||||||
var exchange = MockServerHttpRequest.get("/path?name=123").toExchange()
|
var exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path?name=123").build())
|
||||||
var result = resolver.resolveArgument(nonNullableParamNotRequired, bindingContext, exchange)
|
var result = resolver.resolveArgument(nonNullableParamNotRequired, bindingContext, exchange)
|
||||||
StepVerifier.create(result).expectNext("123").expectComplete().verify()
|
StepVerifier.create(result).expectNext("123").expectComplete().verify()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun resolveNonNullableNotRequiredWithoutParameter() {
|
fun resolveNonNullableNotRequiredWithoutParameter() {
|
||||||
var exchange = MockServerHttpRequest.get("/").toExchange()
|
var exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build())
|
||||||
var result = resolver.resolveArgument(nonNullableParamNotRequired, bindingContext, exchange)
|
var result = resolver.resolveArgument(nonNullableParamNotRequired, bindingContext, exchange)
|
||||||
StepVerifier.create(result).expectComplete().verify()
|
StepVerifier.create(result).expectComplete().verify()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue