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:
@@ -38,6 +38,7 @@ import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.HttpRange;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.server.reactive.AbstractServerHttpRequest;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MimeType;
|
||||
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
|
||||
* an actual server.
|
||||
*
|
||||
* <p>Use the static builder methods in this class to create an instance possibly
|
||||
* further creating a {@link MockServerWebExchange} via {@link #toExchange()}.
|
||||
* an actual server. Use the static methods to obtain a builder.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 5.0
|
||||
@@ -59,15 +57,15 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
|
||||
|
||||
private final MultiValueMap<String, HttpCookie> cookies;
|
||||
|
||||
@Nullable
|
||||
private final InetSocketAddress remoteAddress;
|
||||
|
||||
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,
|
||||
InetSocketAddress remoteAddress,
|
||||
Publisher<? extends DataBuffer> body) {
|
||||
@Nullable InetSocketAddress remoteAddress, Publisher<? extends DataBuffer> body) {
|
||||
|
||||
super(uri, contextPath, headers);
|
||||
this.httpMethod = httpMethod;
|
||||
@@ -88,6 +86,7 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public InetSocketAddress getRemoteAddress() {
|
||||
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
|
||||
|
||||
/**
|
||||
@@ -311,11 +302,6 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
|
||||
*/
|
||||
MockServerHttpRequest build();
|
||||
|
||||
/**
|
||||
* Shortcut for:<br>
|
||||
* {@code build().toExchange()}
|
||||
*/
|
||||
MockServerWebExchange toExchange();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -369,12 +355,14 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
|
||||
|
||||
private final URI url;
|
||||
|
||||
@Nullable
|
||||
private String contextPath;
|
||||
|
||||
private final HttpHeaders headers = new HttpHeaders();
|
||||
|
||||
private final MultiValueMap<String, HttpCookie> cookies = new LinkedMultiValueMap<>();
|
||||
|
||||
@Nullable
|
||||
private InetSocketAddress remoteAddress;
|
||||
|
||||
|
||||
@@ -480,11 +468,6 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
|
||||
return body(Flux.empty());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MockServerWebExchange toExchange() {
|
||||
return build().toExchange();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MockServerHttpRequest body(String body) {
|
||||
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
|
||||
* 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.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.i18n.AcceptHeaderLocaleContextResolver;
|
||||
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
|
||||
* with {@link MockServerHttpRequest} and {@link MockServerHttpResponse}.
|
||||
*
|
||||
* <p>Typically used via {@link MockServerHttpRequest#toExchange()}.
|
||||
* <p>See static factory methods to create an instance.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 5.0
|
||||
*/
|
||||
public class MockServerWebExchange extends ServerWebExchangeDecorator {
|
||||
public final class MockServerWebExchange extends DefaultServerWebExchange {
|
||||
|
||||
|
||||
public MockServerWebExchange(MockServerHttpRequest request) {
|
||||
super(new DefaultServerWebExchange(
|
||||
request, new MockServerHttpResponse(), new DefaultWebSessionManager(),
|
||||
ServerCodecConfigurer.create(), new AcceptHeaderLocaleContextResolver()));
|
||||
private MockServerWebExchange(MockServerHttpRequest request) {
|
||||
super(request, new MockServerHttpResponse(), new DefaultWebSessionManager(),
|
||||
ServerCodecConfigurer.create(), new AcceptHeaderLocaleContextResolver());
|
||||
}
|
||||
|
||||
|
||||
@@ -47,4 +45,14 @@ public class MockServerWebExchange extends ServerWebExchangeDecorator {
|
||||
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.mock.http.client.reactive.test.MockClientHttpRequest;
|
||||
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.TestBean;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
@@ -181,7 +182,7 @@ public class WebExchangeDataBinderTests {
|
||||
public void testBindingWithQueryParams() throws Exception {
|
||||
String url = "/path?spouse=someValue&spouse.name=test";
|
||||
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());
|
||||
assertEquals("test", this.testBean.getSpouse().getName());
|
||||
@@ -223,11 +224,11 @@ public class WebExchangeDataBinderTests {
|
||||
forClassWithGenerics(MultiValueMap.class, String.class, String.class),
|
||||
MediaType.APPLICATION_FORM_URLENCODED, request, Collections.emptyMap()).block();
|
||||
|
||||
return MockServerHttpRequest
|
||||
.post("/")
|
||||
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
|
||||
.body(request.getBody())
|
||||
.toExchange();
|
||||
return MockServerWebExchange.from(
|
||||
MockServerHttpRequest
|
||||
.post("/")
|
||||
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
|
||||
.body(request.getBody()));
|
||||
}
|
||||
|
||||
private ServerWebExchange exchangeMultipart(MultiValueMap<String, ?> multipartData) {
|
||||
@@ -237,11 +238,10 @@ public class WebExchangeDataBinderTests {
|
||||
new MultipartHttpMessageWriter().write(Mono.just(multipartData), forClass(MultiValueMap.class),
|
||||
MediaType.MULTIPART_FORM_DATA, request, Collections.emptyMap()).block();
|
||||
|
||||
return MockServerHttpRequest
|
||||
return MockServerWebExchange.from(MockServerHttpRequest
|
||||
.post("/")
|
||||
.contentType(request.getHeaders().getContentType())
|
||||
.body(request.getBody())
|
||||
.toExchange();
|
||||
.body(request.getBody()));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
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.server.WebFilterChain;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
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}.
|
||||
@@ -50,19 +72,19 @@ public class CorsWebFilterTests {
|
||||
.header(ORIGIN, "http://domain2.com")
|
||||
.header("header2", "foo")
|
||||
.build();
|
||||
MockServerWebExchange exchange = new MockServerWebExchange(request);
|
||||
|
||||
WebFilterChain filterChain = (filterExchange) -> {
|
||||
try {
|
||||
assertEquals("http://domain2.com", filterExchange.getResponse().getHeaders().getFirst(ACCESS_CONTROL_ALLOW_ORIGIN));
|
||||
assertEquals("header3, header4", filterExchange.getResponse().getHeaders().getFirst(ACCESS_CONTROL_EXPOSE_HEADERS));
|
||||
HttpHeaders headers = filterExchange.getResponse().getHeaders();
|
||||
assertEquals("http://domain2.com", headers.getFirst(ACCESS_CONTROL_ALLOW_ORIGIN));
|
||||
assertEquals("header3, header4", headers.getFirst(ACCESS_CONTROL_EXPOSE_HEADERS));
|
||||
} catch (AssertionError ex) {
|
||||
return Mono.error(ex);
|
||||
}
|
||||
return Mono.empty();
|
||||
|
||||
};
|
||||
filter.filter(exchange, filterChain);
|
||||
filter.filter(MockServerWebExchange.from(request), filterChain);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -74,9 +96,10 @@ public class CorsWebFilterTests {
|
||||
.header(ORIGIN, "http://domain2.com")
|
||||
.header("header2", "foo")
|
||||
.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);
|
||||
|
||||
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_HEADERS, "header1, header2")
|
||||
.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);
|
||||
|
||||
assertEquals("http://domain2.com", exchange.getResponse().getHeaders().getFirst(ACCESS_CONTROL_ALLOW_ORIGIN));
|
||||
assertEquals("header1, header2", exchange.getResponse().getHeaders().getFirst(ACCESS_CONTROL_ALLOW_HEADERS));
|
||||
assertEquals("header3, header4", exchange.getResponse().getHeaders().getFirst(ACCESS_CONTROL_EXPOSE_HEADERS));
|
||||
assertEquals(123L, Long.parseLong(exchange.getResponse().getHeaders().getFirst(ACCESS_CONTROL_MAX_AGE)));
|
||||
HttpHeaders headers = exchange.getResponse().getHeaders();
|
||||
assertEquals("http://domain2.com", headers.getFirst(ACCESS_CONTROL_ALLOW_ORIGIN));
|
||||
assertEquals("header1, header2", headers.getFirst(ACCESS_CONTROL_ALLOW_HEADERS));
|
||||
assertEquals("header3, header4", headers.getFirst(ACCESS_CONTROL_EXPOSE_HEADERS));
|
||||
assertEquals(123L, Long.parseLong(headers.getFirst(ACCESS_CONTROL_MAX_AGE)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -113,9 +138,11 @@ public class CorsWebFilterTests {
|
||||
.header(ACCESS_CONTROL_REQUEST_METHOD, HttpMethod.DELETE.name())
|
||||
.header(ACCESS_CONTROL_REQUEST_HEADERS, "header1, header2")
|
||||
.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);
|
||||
|
||||
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.server.reactive.ServerHttpResponse;
|
||||
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.server.ServerWebExchange;
|
||||
|
||||
@@ -151,7 +152,8 @@ public class DefaultCorsProcessorTests {
|
||||
|
||||
@Test
|
||||
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.processor.process(this.conf, exchange);
|
||||
|
||||
@@ -161,7 +163,8 @@ public class DefaultCorsProcessorTests {
|
||||
|
||||
@Test
|
||||
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.processor.process(this.conf, exchange);
|
||||
|
||||
@@ -170,7 +173,8 @@ public class DefaultCorsProcessorTests {
|
||||
|
||||
@Test
|
||||
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.processor.process(this.conf, exchange);
|
||||
|
||||
@@ -181,7 +185,7 @@ public class DefaultCorsProcessorTests {
|
||||
|
||||
@Test
|
||||
public void preflightRequestTestWithOriginButWithoutOtherHeaders() throws Exception {
|
||||
ServerWebExchange exchange = preFlightRequest().toExchange();
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(preFlightRequest().build());
|
||||
this.processor.process(this.conf, exchange);
|
||||
|
||||
ServerHttpResponse response = exchange.getResponse();
|
||||
@@ -191,7 +195,8 @@ public class DefaultCorsProcessorTests {
|
||||
|
||||
@Test
|
||||
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);
|
||||
|
||||
ServerHttpResponse response = exchange.getResponse();
|
||||
@@ -201,10 +206,10 @@ public class DefaultCorsProcessorTests {
|
||||
|
||||
@Test
|
||||
public void preflightRequestWithRequestAndMethodHeaderButNoConfig() throws Exception {
|
||||
ServerWebExchange exchange = preFlightRequest()
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(preFlightRequest()
|
||||
.header(ACCESS_CONTROL_REQUEST_METHOD, "GET")
|
||||
.header(ACCESS_CONTROL_REQUEST_HEADERS, "Header1")
|
||||
.toExchange();
|
||||
.build());
|
||||
|
||||
this.processor.process(this.conf, exchange);
|
||||
|
||||
@@ -215,10 +220,10 @@ public class DefaultCorsProcessorTests {
|
||||
|
||||
@Test
|
||||
public void preflightRequestValidRequestAndConfig() throws Exception {
|
||||
ServerWebExchange exchange = preFlightRequest()
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(preFlightRequest()
|
||||
.header(ACCESS_CONTROL_REQUEST_METHOD, "GET")
|
||||
.header(ACCESS_CONTROL_REQUEST_HEADERS, "Header1")
|
||||
.toExchange();
|
||||
.build());
|
||||
|
||||
this.conf.addAllowedOrigin("*");
|
||||
this.conf.addAllowedMethod("GET");
|
||||
@@ -239,10 +244,10 @@ public class DefaultCorsProcessorTests {
|
||||
|
||||
@Test
|
||||
public void preflightRequestCredentials() throws Exception {
|
||||
ServerWebExchange exchange = preFlightRequest()
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(preFlightRequest()
|
||||
.header(ACCESS_CONTROL_REQUEST_METHOD, "GET")
|
||||
.header(ACCESS_CONTROL_REQUEST_HEADERS, "Header1")
|
||||
.toExchange();
|
||||
.build());
|
||||
|
||||
this.conf.addAllowedOrigin("http://domain1.com");
|
||||
this.conf.addAllowedOrigin("http://domain2.com");
|
||||
@@ -262,10 +267,10 @@ public class DefaultCorsProcessorTests {
|
||||
|
||||
@Test
|
||||
public void preflightRequestCredentialsWithOriginWildcard() throws Exception {
|
||||
ServerWebExchange exchange = preFlightRequest()
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(preFlightRequest()
|
||||
.header(ACCESS_CONTROL_REQUEST_METHOD, "GET")
|
||||
.header(ACCESS_CONTROL_REQUEST_HEADERS, "Header1")
|
||||
.toExchange();
|
||||
.build());
|
||||
|
||||
this.conf.addAllowedOrigin("http://domain1.com");
|
||||
this.conf.addAllowedOrigin("*");
|
||||
@@ -283,10 +288,10 @@ public class DefaultCorsProcessorTests {
|
||||
|
||||
@Test
|
||||
public void preflightRequestAllowedHeaders() throws Exception {
|
||||
ServerWebExchange exchange = preFlightRequest()
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(preFlightRequest()
|
||||
.header(ACCESS_CONTROL_REQUEST_METHOD, "GET")
|
||||
.header(ACCESS_CONTROL_REQUEST_HEADERS, "Header1, Header2")
|
||||
.toExchange();
|
||||
.build());
|
||||
|
||||
this.conf.addAllowedHeader("Header1");
|
||||
this.conf.addAllowedHeader("Header2");
|
||||
@@ -306,10 +311,10 @@ public class DefaultCorsProcessorTests {
|
||||
|
||||
@Test
|
||||
public void preflightRequestAllowsAllHeaders() throws Exception {
|
||||
ServerWebExchange exchange = preFlightRequest()
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(preFlightRequest()
|
||||
.header(ACCESS_CONTROL_REQUEST_METHOD, "GET")
|
||||
.header(ACCESS_CONTROL_REQUEST_HEADERS, "Header1, Header2")
|
||||
.toExchange();
|
||||
.build());
|
||||
|
||||
this.conf.addAllowedHeader("*");
|
||||
this.conf.addAllowedOrigin("http://domain2.com");
|
||||
@@ -327,10 +332,10 @@ public class DefaultCorsProcessorTests {
|
||||
|
||||
@Test
|
||||
public void preflightRequestWithEmptyHeaders() throws Exception {
|
||||
ServerWebExchange exchange = preFlightRequest()
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(preFlightRequest()
|
||||
.header(ACCESS_CONTROL_REQUEST_METHOD, "GET")
|
||||
.header(ACCESS_CONTROL_REQUEST_HEADERS, "")
|
||||
.toExchange();
|
||||
.build());
|
||||
|
||||
this.conf.addAllowedHeader("*");
|
||||
this.conf.addAllowedOrigin("http://domain2.com");
|
||||
@@ -345,7 +350,8 @@ public class DefaultCorsProcessorTests {
|
||||
|
||||
@Test
|
||||
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.processor.process(null, exchange);
|
||||
|
||||
@@ -356,7 +362,7 @@ public class DefaultCorsProcessorTests {
|
||||
|
||||
|
||||
private ServerWebExchange actualRequest() {
|
||||
return corsRequest(HttpMethod.GET).toExchange();
|
||||
return MockServerWebExchange.from(corsRequest(HttpMethod.GET).build());
|
||||
}
|
||||
|
||||
private MockServerHttpRequest.BaseBuilder<?> preFlightRequest() {
|
||||
|
||||
@@ -19,8 +19,8 @@ package org.springframework.web.cors.reactive;
|
||||
import org.junit.Test;
|
||||
|
||||
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.server.ServerWebExchange;
|
||||
import org.springframework.web.util.pattern.PathPatternParser;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -40,7 +40,7 @@ public class UrlBasedCorsConfigurationSourceTests {
|
||||
|
||||
@Test
|
||||
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));
|
||||
}
|
||||
|
||||
@@ -49,10 +49,10 @@ public class UrlBasedCorsConfigurationSourceTests {
|
||||
CorsConfiguration config = new CorsConfiguration();
|
||||
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));
|
||||
|
||||
exchange = MockServerHttpRequest.get("/bar/test.html").toExchange();
|
||||
exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/bar/test.html").build());
|
||||
assertEquals(config, this.configSource.getCorsConfiguration(exchange));
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ import reactor.core.publisher.Mono;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.lang.Nullable;
|
||||
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.WebFilterChain;
|
||||
|
||||
@@ -43,13 +43,13 @@ public class ForwardedHeaderFilterTests {
|
||||
|
||||
@Test
|
||||
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("X-Forwarded-Host", "example.com")
|
||||
.header("X-Forwarded-Port", "8080")
|
||||
.header("X-Forwarded-Proto", "http")
|
||||
.header("X-Forwarded-Prefix", "prefix")
|
||||
.toExchange();
|
||||
.build());
|
||||
|
||||
this.filter.setRemoveOnly(true);
|
||||
this.filter.filter(exchange, this.filterChain).block(Duration.ZERO);
|
||||
@@ -65,11 +65,11 @@ public class ForwardedHeaderFilterTests {
|
||||
|
||||
@Test
|
||||
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-Port", "443")
|
||||
.header("X-Forwarded-Proto", "https")
|
||||
.toExchange();
|
||||
.build());
|
||||
|
||||
this.filter.filter(exchange, this.filterChain).block(Duration.ZERO);
|
||||
|
||||
@@ -79,10 +79,10 @@ public class ForwardedHeaderFilterTests {
|
||||
|
||||
@Test
|
||||
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")
|
||||
|
||||
.toExchange();
|
||||
.build());
|
||||
|
||||
this.filter.filter(exchange, this.filterChain).block(Duration.ZERO);
|
||||
|
||||
@@ -92,9 +92,9 @@ public class ForwardedHeaderFilterTests {
|
||||
|
||||
@Test
|
||||
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")
|
||||
.toExchange();
|
||||
.build());
|
||||
|
||||
this.filter.filter(exchange, this.filterChain).block(Duration.ZERO);
|
||||
|
||||
@@ -104,9 +104,9 @@ public class ForwardedHeaderFilterTests {
|
||||
|
||||
@Test
|
||||
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/")
|
||||
.toExchange();
|
||||
.build());
|
||||
|
||||
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.MediaType;
|
||||
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.WebFilterChain;
|
||||
|
||||
@@ -84,10 +84,10 @@ public class HiddenHttpMethodFilterTests {
|
||||
@Test
|
||||
public void filterWithHttpPut() {
|
||||
|
||||
ServerWebExchange exchange = MockServerHttpRequest.put("/")
|
||||
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
||||
.body("_method=DELETE")
|
||||
.toExchange();
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(
|
||||
MockServerHttpRequest.put("/")
|
||||
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
||||
.body("_method=DELETE"));
|
||||
|
||||
this.filter.filter(exchange, this.filterChain).block(Duration.ZERO);
|
||||
assertEquals(HttpMethod.PUT, this.filterChain.getHttpMethod());
|
||||
@@ -96,10 +96,10 @@ public class HiddenHttpMethodFilterTests {
|
||||
|
||||
private Mono<Void> postForm(String body) {
|
||||
|
||||
MockServerWebExchange exchange = MockServerHttpRequest.post("/")
|
||||
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
||||
.body(body)
|
||||
.toExchange();
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(
|
||||
MockServerHttpRequest.post("/")
|
||||
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
||||
.body(body));
|
||||
|
||||
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.HttpStatus;
|
||||
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.assertFalse;
|
||||
@@ -79,7 +79,8 @@ public class DefaultServerWebExchangeCheckNotModifiedTests {
|
||||
|
||||
@Test
|
||||
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);
|
||||
|
||||
assertFalse(exchange.checkNotModified(this.currentDate));
|
||||
@@ -90,7 +91,7 @@ public class DefaultServerWebExchangeCheckNotModifiedTests {
|
||||
@Test // SPR-14559
|
||||
public void checkNotModifiedInvalidIfNoneMatchHeader() {
|
||||
String eTag = "\"etagvalue\"";
|
||||
MockServerWebExchange exchange = get("/").ifNoneMatch("missingquotes").toExchange();
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").ifNoneMatch("missingquotes").build());
|
||||
assertFalse(exchange.checkNotModified(eTag));
|
||||
assertNull(exchange.getResponse().getStatusCode());
|
||||
assertEquals(eTag, exchange.getResponse().getHeaders().getETag());
|
||||
@@ -98,7 +99,8 @@ public class DefaultServerWebExchangeCheckNotModifiedTests {
|
||||
|
||||
@Test
|
||||
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);
|
||||
|
||||
assertTrue(exchange.checkNotModified(currentDate));
|
||||
@@ -109,7 +111,8 @@ public class DefaultServerWebExchangeCheckNotModifiedTests {
|
||||
|
||||
@Test
|
||||
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));
|
||||
|
||||
@@ -120,7 +123,8 @@ public class DefaultServerWebExchangeCheckNotModifiedTests {
|
||||
@Test
|
||||
public void checkModifiedTimestamp() {
|
||||
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));
|
||||
|
||||
@@ -131,7 +135,7 @@ public class DefaultServerWebExchangeCheckNotModifiedTests {
|
||||
@Test
|
||||
public void checkNotModifiedETag() {
|
||||
String eTag = "\"Foo\"";
|
||||
MockServerWebExchange exchange = get("/").ifNoneMatch(eTag).toExchange();
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").ifNoneMatch(eTag).build());
|
||||
|
||||
assertTrue(exchange.checkNotModified(eTag));
|
||||
|
||||
@@ -142,7 +146,7 @@ public class DefaultServerWebExchangeCheckNotModifiedTests {
|
||||
@Test
|
||||
public void checkNotModifiedETagWithSeparatorChars() {
|
||||
String eTag = "\"Foo, Bar\"";
|
||||
MockServerWebExchange exchange = get("/").ifNoneMatch(eTag).toExchange();
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").ifNoneMatch(eTag).build());
|
||||
|
||||
assertTrue(exchange.checkNotModified(eTag));
|
||||
|
||||
@@ -155,7 +159,7 @@ public class DefaultServerWebExchangeCheckNotModifiedTests {
|
||||
public void checkModifiedETag() {
|
||||
String currentETag = "\"Foo\"";
|
||||
String oldEtag = "Bar";
|
||||
MockServerWebExchange exchange = get("/").ifNoneMatch(oldEtag).toExchange();
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").ifNoneMatch(oldEtag).build());
|
||||
|
||||
assertFalse(exchange.checkNotModified(currentETag));
|
||||
|
||||
@@ -167,7 +171,7 @@ public class DefaultServerWebExchangeCheckNotModifiedTests {
|
||||
public void checkNotModifiedUnpaddedETag() {
|
||||
String eTag = "Foo";
|
||||
String paddedEtag = String.format("\"%s\"", eTag);
|
||||
MockServerWebExchange exchange = get("/").ifNoneMatch(paddedEtag).toExchange();
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").ifNoneMatch(paddedEtag).build());
|
||||
|
||||
assertTrue(exchange.checkNotModified(eTag));
|
||||
|
||||
@@ -179,7 +183,7 @@ public class DefaultServerWebExchangeCheckNotModifiedTests {
|
||||
public void checkModifiedUnpaddedETag() {
|
||||
String currentETag = "Foo";
|
||||
String oldEtag = "Bar";
|
||||
MockServerWebExchange exchange = get("/").ifNoneMatch(oldEtag).toExchange();
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").ifNoneMatch(oldEtag).build());
|
||||
|
||||
assertFalse(exchange.checkNotModified(currentETag));
|
||||
|
||||
@@ -190,7 +194,7 @@ public class DefaultServerWebExchangeCheckNotModifiedTests {
|
||||
@Test
|
||||
public void checkNotModifiedWildcardIsIgnored() {
|
||||
String eTag = "\"Foo\"";
|
||||
MockServerWebExchange exchange = get("/").ifNoneMatch("*").toExchange();
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").ifNoneMatch("*").build());
|
||||
assertFalse(exchange.checkNotModified(eTag));
|
||||
|
||||
assertNull(exchange.getResponse().getStatusCode());
|
||||
@@ -201,7 +205,8 @@ public class DefaultServerWebExchangeCheckNotModifiedTests {
|
||||
public void checkNotModifiedETagAndTimestamp() {
|
||||
String eTag = "\"Foo\"";
|
||||
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));
|
||||
|
||||
@@ -215,10 +220,10 @@ public class DefaultServerWebExchangeCheckNotModifiedTests {
|
||||
public void checkNotModifiedETagAndModifiedTimestamp() {
|
||||
String eTag = "\"Foo\"";
|
||||
Instant oneMinuteAgo = currentDate.minusSeconds(60);
|
||||
MockServerWebExchange exchange = get("/")
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/")
|
||||
.ifNoneMatch(eTag)
|
||||
.ifModifiedSince(oneMinuteAgo.toEpochMilli())
|
||||
.toExchange();
|
||||
.build());
|
||||
|
||||
assertTrue(exchange.checkNotModified(eTag, currentDate));
|
||||
|
||||
@@ -232,7 +237,8 @@ public class DefaultServerWebExchangeCheckNotModifiedTests {
|
||||
String currentETag = "\"Foo\"";
|
||||
String oldEtag = "\"Bar\"";
|
||||
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));
|
||||
|
||||
@@ -245,7 +251,7 @@ public class DefaultServerWebExchangeCheckNotModifiedTests {
|
||||
public void checkNotModifiedETagWeakStrong() {
|
||||
String eTag = "\"Foo\"";
|
||||
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));
|
||||
|
||||
@@ -256,7 +262,8 @@ public class DefaultServerWebExchangeCheckNotModifiedTests {
|
||||
@Test
|
||||
public void checkNotModifiedETagStrongWeak() {
|
||||
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));
|
||||
|
||||
@@ -268,7 +275,7 @@ public class DefaultServerWebExchangeCheckNotModifiedTests {
|
||||
public void checkNotModifiedMultipleETags() {
|
||||
String eTag = "\"Bar\"";
|
||||
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));
|
||||
|
||||
@@ -280,7 +287,8 @@ public class DefaultServerWebExchangeCheckNotModifiedTests {
|
||||
public void checkNotModifiedTimestampWithLengthPart() throws Exception {
|
||||
long epochTime = dateFormat.parse(CURRENT_TIME).getTime();
|
||||
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)));
|
||||
|
||||
@@ -292,7 +300,8 @@ public class DefaultServerWebExchangeCheckNotModifiedTests {
|
||||
public void checkModifiedTimestampWithLengthPart() throws Exception {
|
||||
long epochTime = dateFormat.parse(CURRENT_TIME).getTime();
|
||||
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)));
|
||||
|
||||
@@ -304,7 +313,8 @@ public class DefaultServerWebExchangeCheckNotModifiedTests {
|
||||
public void checkNotModifiedTimestampConditionalPut() throws Exception {
|
||||
Instant oneMinuteAgo = currentDate.minusSeconds(60);
|
||||
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));
|
||||
assertNull(exchange.getResponse().getStatusCode());
|
||||
@@ -315,7 +325,8 @@ public class DefaultServerWebExchangeCheckNotModifiedTests {
|
||||
public void checkNotModifiedTimestampConditionalPutConflict() throws Exception {
|
||||
Instant oneMinuteAgo = currentDate.minusSeconds(60);
|
||||
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));
|
||||
assertEquals(412, exchange.getResponse().getStatusCode().value());
|
||||
|
||||
@@ -20,7 +20,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
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 static org.junit.Assert.*;
|
||||
@@ -32,10 +32,11 @@ public class ServerWebExchangeTests {
|
||||
|
||||
private ServerWebExchange exchange;
|
||||
|
||||
|
||||
@Before
|
||||
public void createExchange() {
|
||||
MockServerHttpRequest request = MockServerHttpRequest.get("http://example.com").build();
|
||||
this.exchange = new MockServerWebExchange(request);
|
||||
this.exchange = MockServerWebExchange.from(request);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -24,6 +24,7 @@ import reactor.test.StepVerifier;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
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.WebExceptionHandler;
|
||||
import org.springframework.web.server.WebHandler;
|
||||
@@ -38,10 +39,11 @@ import static org.junit.Assert.assertNull;
|
||||
*/
|
||||
public class ExceptionHandlingWebHandlerTests {
|
||||
|
||||
private final ServerWebExchange exchange = MockServerHttpRequest.get("http://localhost:8080").toExchange();
|
||||
|
||||
private final WebHandler targetHandler = new StubWebHandler(new IllegalStateException("boo"));
|
||||
|
||||
private final ServerWebExchange exchange = MockServerWebExchange.from(
|
||||
MockServerHttpRequest.get("http://localhost:8080").build());
|
||||
|
||||
|
||||
@Test
|
||||
public void handleErrorSignal() throws Exception {
|
||||
|
||||
@@ -28,6 +28,7 @@ import reactor.core.publisher.Mono;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||
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.WebExceptionHandler;
|
||||
import org.springframework.web.server.WebFilter;
|
||||
@@ -57,7 +58,7 @@ public class FilteringWebHandlerTests {
|
||||
StubWebHandler targetHandler = new StubWebHandler();
|
||||
|
||||
new FilteringWebHandler(targetHandler, Arrays.asList(filter1, filter2, filter3))
|
||||
.handle(MockServerHttpRequest.get("/").toExchange())
|
||||
.handle(MockServerWebExchange.from(MockServerHttpRequest.get("/").build()))
|
||||
.block(Duration.ZERO);
|
||||
|
||||
assertTrue(filter1.invoked());
|
||||
@@ -72,7 +73,7 @@ public class FilteringWebHandlerTests {
|
||||
StubWebHandler targetHandler = new StubWebHandler();
|
||||
|
||||
new FilteringWebHandler(targetHandler, Collections.emptyList())
|
||||
.handle(MockServerHttpRequest.get("/").toExchange())
|
||||
.handle(MockServerWebExchange.from(MockServerHttpRequest.get("/").build()))
|
||||
.block(Duration.ZERO);
|
||||
|
||||
assertTrue(targetHandler.invoked());
|
||||
@@ -87,7 +88,7 @@ public class FilteringWebHandlerTests {
|
||||
StubWebHandler targetHandler = new StubWebHandler();
|
||||
|
||||
new FilteringWebHandler(targetHandler, Arrays.asList(filter1, filter2, filter3))
|
||||
.handle(MockServerHttpRequest.get("/").toExchange())
|
||||
.handle(MockServerWebExchange.from(MockServerHttpRequest.get("/").build()))
|
||||
.block(Duration.ZERO);
|
||||
|
||||
assertTrue(filter1.invoked());
|
||||
@@ -103,7 +104,7 @@ public class FilteringWebHandlerTests {
|
||||
StubWebHandler targetHandler = new StubWebHandler();
|
||||
|
||||
new FilteringWebHandler(targetHandler, Collections.singletonList(filter))
|
||||
.handle(MockServerHttpRequest.get("/").toExchange())
|
||||
.handle(MockServerWebExchange.from(MockServerHttpRequest.get("/").build()))
|
||||
.block(Duration.ofSeconds(5));
|
||||
|
||||
assertTrue(filter.invoked());
|
||||
|
||||
@@ -24,7 +24,7 @@ import reactor.test.StepVerifier;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
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 static org.junit.Assert.assertEquals;
|
||||
@@ -39,7 +39,8 @@ public class ResponseStatusExceptionHandlerTests {
|
||||
|
||||
private final ResponseStatusExceptionHandler handler = new ResponseStatusExceptionHandler();
|
||||
|
||||
private final MockServerWebExchange exchange = MockServerHttpRequest.get("/").toExchange();
|
||||
private final MockServerWebExchange exchange = MockServerWebExchange.from(
|
||||
MockServerHttpRequest.get("/").build());
|
||||
|
||||
|
||||
@Test
|
||||
|
||||
@@ -23,7 +23,7 @@ import java.util.Locale;
|
||||
import org.junit.Test;
|
||||
|
||||
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 static java.util.Locale.*;
|
||||
@@ -62,34 +62,27 @@ public class AcceptHeaderLocaleContextResolverTests {
|
||||
this.resolver.setSupportedLocales(Arrays.asList(US, JAPAN));
|
||||
this.resolver.setDefaultLocale(JAPAN);
|
||||
|
||||
MockServerWebExchange exchange = new MockServerWebExchange(MockServerHttpRequest
|
||||
.get("/")
|
||||
.acceptLanguageAsLocales(KOREA)
|
||||
.build());
|
||||
MockServerHttpRequest request = MockServerHttpRequest.get("/").acceptLanguageAsLocales(KOREA).build();
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||
assertEquals(JAPAN, this.resolver.resolveLocaleContext(exchange).getLocale());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultLocale() throws Exception {
|
||||
this.resolver.setDefaultLocale(JAPANESE);
|
||||
MockServerWebExchange exchange = new MockServerWebExchange(MockServerHttpRequest
|
||||
.get("/")
|
||||
.build());
|
||||
MockServerHttpRequest request = MockServerHttpRequest.get("/").build();
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||
assertEquals(JAPANESE, this.resolver.resolveLocaleContext(exchange).getLocale());
|
||||
|
||||
exchange = new MockServerWebExchange(MockServerHttpRequest
|
||||
.get("/")
|
||||
.acceptLanguageAsLocales(US)
|
||||
.build());
|
||||
request = MockServerHttpRequest.get("/").acceptLanguageAsLocales(US).build();
|
||||
exchange = MockServerWebExchange.from(request);
|
||||
assertEquals(US, this.resolver.resolveLocaleContext(exchange).getLocale());
|
||||
}
|
||||
|
||||
|
||||
private ServerWebExchange exchange(Locale... locales) {
|
||||
return new MockServerWebExchange(MockServerHttpRequest
|
||||
.get("")
|
||||
.acceptLanguageAsLocales(locales)
|
||||
.build());
|
||||
MockServerHttpRequest request = MockServerHttpRequest.get("").acceptLanguageAsLocales(locales).build();
|
||||
return MockServerWebExchange.from(request);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.context.i18n.TimeZoneAwareLocaleContext;
|
||||
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 static java.util.Locale.CANADA;
|
||||
@@ -55,10 +55,8 @@ public class FixedLocaleContextResolverTests {
|
||||
}
|
||||
|
||||
private ServerWebExchange exchange(Locale... locales) {
|
||||
return new MockServerWebExchange(MockServerHttpRequest
|
||||
.get("")
|
||||
.acceptLanguageAsLocales(locales)
|
||||
.build());
|
||||
MockServerHttpRequest request = MockServerHttpRequest.get("").acceptLanguageAsLocales(locales).build();
|
||||
return MockServerWebExchange.from(request);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.web.server.session;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -40,7 +41,7 @@ public class HeaderWebSessionIdResolverTests {
|
||||
@Before
|
||||
public void setUp() {
|
||||
this.idResolver = new HeaderWebSessionIdResolver();
|
||||
this.exchange = MockServerHttpRequest.get("/path").toExchange();
|
||||
this.exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path").build());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -121,9 +122,9 @@ public class HeaderWebSessionIdResolverTests {
|
||||
@Test
|
||||
public void resolveSessionIdsWhenIdThenIdFound() {
|
||||
String id = "123";
|
||||
this.exchange = MockServerHttpRequest.get("/path")
|
||||
this.exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path")
|
||||
.header(HeaderWebSessionIdResolver.DEFAULT_HEADER_NAME, id)
|
||||
.toExchange();
|
||||
.build());
|
||||
|
||||
List<String> ids = this.idResolver.resolveSessionIds(this.exchange);
|
||||
|
||||
@@ -134,9 +135,10 @@ public class HeaderWebSessionIdResolverTests {
|
||||
public void resolveSessionIdsWhenMultipleIdsThenIdsFound() {
|
||||
String id1 = "123";
|
||||
String id2 = "abc";
|
||||
this.exchange = MockServerHttpRequest.get("/path")
|
||||
.header(HeaderWebSessionIdResolver.DEFAULT_HEADER_NAME, id1, id2)
|
||||
.toExchange();
|
||||
this.exchange = MockServerWebExchange.from(
|
||||
MockServerHttpRequest.get("/path")
|
||||
.header(HeaderWebSessionIdResolver.DEFAULT_HEADER_NAME, id1, id2)
|
||||
.build());
|
||||
|
||||
List<String> ids = this.idResolver.resolveSessionIds(this.exchange);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user