Shortcut factory method in MockServerWebExchange
MockServerWebExchange now has a second factory method that accepts a MockServerHttpRequest.BaseBuilder. Issue: SPR-16079
This commit is contained in:
@@ -55,4 +55,14 @@ public final class MockServerWebExchange extends DefaultServerWebExchange {
|
||||
return new MockServerWebExchange(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* A variant of {@link #from(MockServerHttpRequest)} that accepts a request
|
||||
* builder. Internally invokes the {@code build()} to build the request.
|
||||
* @param requestBuilder the builder for the request.
|
||||
* @return the exchange
|
||||
*/
|
||||
public static MockServerWebExchange from(MockServerHttpRequest.BaseBuilder<?> requestBuilder) {
|
||||
return new MockServerWebExchange(requestBuilder.build());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -55,4 +55,14 @@ public final class MockServerWebExchange extends DefaultServerWebExchange {
|
||||
return new MockServerWebExchange(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* A variant of {@link #from(MockServerHttpRequest)} that accepts a request
|
||||
* builder. Internally invokes the {@code build()} to build the request.
|
||||
* @param requestBuilder the builder for the request.
|
||||
* @return the exchange
|
||||
*/
|
||||
public static MockServerWebExchange from(MockServerHttpRequest.BaseBuilder<?> requestBuilder) {
|
||||
return new MockServerWebExchange(requestBuilder.build());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -181,8 +181,8 @@ public class WebExchangeDataBinderTests {
|
||||
@Test
|
||||
public void testBindingWithQueryParams() throws Exception {
|
||||
String url = "/path?spouse=someValue&spouse.name=test";
|
||||
MockServerHttpRequest request = MockServerHttpRequest.post(url).build();
|
||||
this.binder.bind(MockServerWebExchange.from(request)).block(Duration.ofSeconds(5));
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.post(url));
|
||||
this.binder.bind(exchange).block(Duration.ofSeconds(5));
|
||||
|
||||
assertNotNull(this.testBean.getSpouse());
|
||||
assertEquals("test", this.testBean.getSpouse().getName());
|
||||
|
||||
@@ -65,14 +65,6 @@ public class CorsWebFilterTests {
|
||||
|
||||
@Test
|
||||
public void validActualRequest() {
|
||||
|
||||
MockServerHttpRequest request = MockServerHttpRequest
|
||||
.get("http://domain1.com/test.html")
|
||||
.header(HOST, "domain1.com")
|
||||
.header(ORIGIN, "http://domain2.com")
|
||||
.header("header2", "foo")
|
||||
.build();
|
||||
|
||||
WebFilterChain filterChain = (filterExchange) -> {
|
||||
try {
|
||||
HttpHeaders headers = filterExchange.getResponse().getHeaders();
|
||||
@@ -84,19 +76,23 @@ public class CorsWebFilterTests {
|
||||
return Mono.empty();
|
||||
|
||||
};
|
||||
filter.filter(MockServerWebExchange.from(request), filterChain);
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(
|
||||
MockServerHttpRequest
|
||||
.get("http://domain1.com/test.html")
|
||||
.header(HOST, "domain1.com")
|
||||
.header(ORIGIN, "http://domain2.com")
|
||||
.header("header2", "foo"));
|
||||
this.filter.filter(exchange, filterChain);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invalidActualRequest() throws ServletException, IOException {
|
||||
|
||||
MockServerHttpRequest request = MockServerHttpRequest
|
||||
.delete("http://domain1.com/test.html")
|
||||
.header(HOST, "domain1.com")
|
||||
.header(ORIGIN, "http://domain2.com")
|
||||
.header("header2", "foo")
|
||||
.build();
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(
|
||||
MockServerHttpRequest
|
||||
.delete("http://domain1.com/test.html")
|
||||
.header(HOST, "domain1.com")
|
||||
.header(ORIGIN, "http://domain2.com")
|
||||
.header("header2", "foo"));
|
||||
|
||||
WebFilterChain filterChain = (filterExchange) -> Mono.error(
|
||||
new AssertionError("Invalid requests must not be forwarded to the filter chain"));
|
||||
@@ -108,14 +104,14 @@ public class CorsWebFilterTests {
|
||||
@Test
|
||||
public void validPreFlightRequest() throws ServletException, IOException {
|
||||
|
||||
MockServerHttpRequest request = MockServerHttpRequest
|
||||
.options("http://domain1.com/test.html")
|
||||
.header(HOST, "domain1.com")
|
||||
.header(ORIGIN, "http://domain2.com")
|
||||
.header(ACCESS_CONTROL_REQUEST_METHOD, HttpMethod.GET.name())
|
||||
.header(ACCESS_CONTROL_REQUEST_HEADERS, "header1, header2")
|
||||
.build();
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(
|
||||
MockServerHttpRequest
|
||||
.options("http://domain1.com/test.html")
|
||||
.header(HOST, "domain1.com")
|
||||
.header(ORIGIN, "http://domain2.com")
|
||||
.header(ACCESS_CONTROL_REQUEST_METHOD, HttpMethod.GET.name())
|
||||
.header(ACCESS_CONTROL_REQUEST_HEADERS, "header1, header2")
|
||||
);
|
||||
|
||||
WebFilterChain filterChain = (filterExchange) -> Mono.error(
|
||||
new AssertionError("Preflight requests must not be forwarded to the filter chain"));
|
||||
@@ -131,14 +127,13 @@ public class CorsWebFilterTests {
|
||||
@Test
|
||||
public void invalidPreFlightRequest() throws ServletException, IOException {
|
||||
|
||||
MockServerHttpRequest request = MockServerHttpRequest
|
||||
.options("http://domain1.com/test.html")
|
||||
.header(HOST, "domain1.com")
|
||||
.header(ORIGIN, "http://domain2.com")
|
||||
.header(ACCESS_CONTROL_REQUEST_METHOD, HttpMethod.DELETE.name())
|
||||
.header(ACCESS_CONTROL_REQUEST_HEADERS, "header1, header2")
|
||||
.build();
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(
|
||||
MockServerHttpRequest
|
||||
.options("http://domain1.com/test.html")
|
||||
.header(HOST, "domain1.com")
|
||||
.header(ORIGIN, "http://domain2.com")
|
||||
.header(ACCESS_CONTROL_REQUEST_METHOD, HttpMethod.DELETE.name())
|
||||
.header(ACCESS_CONTROL_REQUEST_HEADERS, "header1, header2"));
|
||||
|
||||
WebFilterChain filterChain = (filterExchange) -> Mono.error(
|
||||
new AssertionError("Preflight requests must not be forwarded to the filter chain"));
|
||||
|
||||
@@ -152,8 +152,8 @@ public class DefaultCorsProcessorTests {
|
||||
|
||||
@Test
|
||||
public void preflightRequestAllOriginsAllowed() throws Exception {
|
||||
MockServerHttpRequest request = preFlightRequest().header(ACCESS_CONTROL_REQUEST_METHOD, "GET").build();
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(
|
||||
preFlightRequest().header(ACCESS_CONTROL_REQUEST_METHOD, "GET"));
|
||||
this.conf.addAllowedOrigin("*");
|
||||
this.processor.process(this.conf, exchange);
|
||||
|
||||
@@ -163,8 +163,8 @@ public class DefaultCorsProcessorTests {
|
||||
|
||||
@Test
|
||||
public void preflightRequestWrongAllowedMethod() throws Exception {
|
||||
MockServerHttpRequest request = preFlightRequest().header(ACCESS_CONTROL_REQUEST_METHOD, "DELETE").build();
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(
|
||||
preFlightRequest().header(ACCESS_CONTROL_REQUEST_METHOD, "DELETE"));
|
||||
this.conf.addAllowedOrigin("*");
|
||||
this.processor.process(this.conf, exchange);
|
||||
|
||||
@@ -173,8 +173,8 @@ public class DefaultCorsProcessorTests {
|
||||
|
||||
@Test
|
||||
public void preflightRequestMatchedAllowedMethod() throws Exception {
|
||||
MockServerHttpRequest request = preFlightRequest().header(ACCESS_CONTROL_REQUEST_METHOD, "GET").build();
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(
|
||||
preFlightRequest().header(ACCESS_CONTROL_REQUEST_METHOD, "GET"));
|
||||
this.conf.addAllowedOrigin("*");
|
||||
this.processor.process(this.conf, exchange);
|
||||
|
||||
@@ -185,7 +185,7 @@ public class DefaultCorsProcessorTests {
|
||||
|
||||
@Test
|
||||
public void preflightRequestTestWithOriginButWithoutOtherHeaders() throws Exception {
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(preFlightRequest().build());
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(preFlightRequest());
|
||||
this.processor.process(this.conf, exchange);
|
||||
|
||||
ServerHttpResponse response = exchange.getResponse();
|
||||
@@ -195,8 +195,8 @@ public class DefaultCorsProcessorTests {
|
||||
|
||||
@Test
|
||||
public void preflightRequestWithoutRequestMethod() throws Exception {
|
||||
MockServerHttpRequest request = preFlightRequest().header(ACCESS_CONTROL_REQUEST_HEADERS, "Header1").build();
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(
|
||||
preFlightRequest().header(ACCESS_CONTROL_REQUEST_HEADERS, "Header1"));
|
||||
this.processor.process(this.conf, exchange);
|
||||
|
||||
ServerHttpResponse response = exchange.getResponse();
|
||||
@@ -208,8 +208,7 @@ public class DefaultCorsProcessorTests {
|
||||
public void preflightRequestWithRequestAndMethodHeaderButNoConfig() throws Exception {
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(preFlightRequest()
|
||||
.header(ACCESS_CONTROL_REQUEST_METHOD, "GET")
|
||||
.header(ACCESS_CONTROL_REQUEST_HEADERS, "Header1")
|
||||
.build());
|
||||
.header(ACCESS_CONTROL_REQUEST_HEADERS, "Header1"));
|
||||
|
||||
this.processor.process(this.conf, exchange);
|
||||
|
||||
@@ -222,8 +221,7 @@ public class DefaultCorsProcessorTests {
|
||||
public void preflightRequestValidRequestAndConfig() throws Exception {
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(preFlightRequest()
|
||||
.header(ACCESS_CONTROL_REQUEST_METHOD, "GET")
|
||||
.header(ACCESS_CONTROL_REQUEST_HEADERS, "Header1")
|
||||
.build());
|
||||
.header(ACCESS_CONTROL_REQUEST_HEADERS, "Header1"));
|
||||
|
||||
this.conf.addAllowedOrigin("*");
|
||||
this.conf.addAllowedMethod("GET");
|
||||
@@ -246,8 +244,7 @@ public class DefaultCorsProcessorTests {
|
||||
public void preflightRequestCredentials() throws Exception {
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(preFlightRequest()
|
||||
.header(ACCESS_CONTROL_REQUEST_METHOD, "GET")
|
||||
.header(ACCESS_CONTROL_REQUEST_HEADERS, "Header1")
|
||||
.build());
|
||||
.header(ACCESS_CONTROL_REQUEST_HEADERS, "Header1"));
|
||||
|
||||
this.conf.addAllowedOrigin("http://domain1.com");
|
||||
this.conf.addAllowedOrigin("http://domain2.com");
|
||||
@@ -269,8 +266,7 @@ public class DefaultCorsProcessorTests {
|
||||
public void preflightRequestCredentialsWithOriginWildcard() throws Exception {
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(preFlightRequest()
|
||||
.header(ACCESS_CONTROL_REQUEST_METHOD, "GET")
|
||||
.header(ACCESS_CONTROL_REQUEST_HEADERS, "Header1")
|
||||
.build());
|
||||
.header(ACCESS_CONTROL_REQUEST_HEADERS, "Header1"));
|
||||
|
||||
this.conf.addAllowedOrigin("http://domain1.com");
|
||||
this.conf.addAllowedOrigin("*");
|
||||
@@ -290,8 +286,7 @@ public class DefaultCorsProcessorTests {
|
||||
public void preflightRequestAllowedHeaders() throws Exception {
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(preFlightRequest()
|
||||
.header(ACCESS_CONTROL_REQUEST_METHOD, "GET")
|
||||
.header(ACCESS_CONTROL_REQUEST_HEADERS, "Header1, Header2")
|
||||
.build());
|
||||
.header(ACCESS_CONTROL_REQUEST_HEADERS, "Header1, Header2"));
|
||||
|
||||
this.conf.addAllowedHeader("Header1");
|
||||
this.conf.addAllowedHeader("Header2");
|
||||
@@ -313,8 +308,7 @@ public class DefaultCorsProcessorTests {
|
||||
public void preflightRequestAllowsAllHeaders() throws Exception {
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(preFlightRequest()
|
||||
.header(ACCESS_CONTROL_REQUEST_METHOD, "GET")
|
||||
.header(ACCESS_CONTROL_REQUEST_HEADERS, "Header1, Header2")
|
||||
.build());
|
||||
.header(ACCESS_CONTROL_REQUEST_HEADERS, "Header1, Header2"));
|
||||
|
||||
this.conf.addAllowedHeader("*");
|
||||
this.conf.addAllowedOrigin("http://domain2.com");
|
||||
@@ -334,8 +328,7 @@ public class DefaultCorsProcessorTests {
|
||||
public void preflightRequestWithEmptyHeaders() throws Exception {
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(preFlightRequest()
|
||||
.header(ACCESS_CONTROL_REQUEST_METHOD, "GET")
|
||||
.header(ACCESS_CONTROL_REQUEST_HEADERS, "")
|
||||
.build());
|
||||
.header(ACCESS_CONTROL_REQUEST_HEADERS, ""));
|
||||
|
||||
this.conf.addAllowedHeader("*");
|
||||
this.conf.addAllowedOrigin("http://domain2.com");
|
||||
@@ -350,8 +343,8 @@ public class DefaultCorsProcessorTests {
|
||||
|
||||
@Test
|
||||
public void preflightRequestWithNullConfig() throws Exception {
|
||||
MockServerHttpRequest request = preFlightRequest().header(ACCESS_CONTROL_REQUEST_METHOD, "GET").build();
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(
|
||||
preFlightRequest().header(ACCESS_CONTROL_REQUEST_METHOD, "GET"));
|
||||
this.conf.addAllowedOrigin("*");
|
||||
this.processor.process(null, exchange);
|
||||
|
||||
@@ -362,7 +355,7 @@ public class DefaultCorsProcessorTests {
|
||||
|
||||
|
||||
private ServerWebExchange actualRequest() {
|
||||
return MockServerWebExchange.from(corsRequest(HttpMethod.GET).build());
|
||||
return MockServerWebExchange.from(corsRequest(HttpMethod.GET));
|
||||
}
|
||||
|
||||
private MockServerHttpRequest.BaseBuilder<?> preFlightRequest() {
|
||||
|
||||
@@ -40,7 +40,7 @@ public class UrlBasedCorsConfigurationSourceTests {
|
||||
|
||||
@Test
|
||||
public void empty() {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/bar/test.html").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/bar/test.html"));
|
||||
assertNull(this.configSource.getCorsConfiguration(exchange));
|
||||
}
|
||||
|
||||
@@ -49,10 +49,10 @@ public class UrlBasedCorsConfigurationSourceTests {
|
||||
CorsConfiguration config = new CorsConfiguration();
|
||||
this.configSource.registerCorsConfiguration("/bar/**", config);
|
||||
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/foo/test.html").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/foo/test.html"));
|
||||
assertNull(this.configSource.getCorsConfiguration(exchange));
|
||||
|
||||
exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/bar/test.html").build());
|
||||
exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/bar/test.html"));
|
||||
assertEquals(config, this.configSource.getCorsConfiguration(exchange));
|
||||
}
|
||||
|
||||
|
||||
@@ -43,13 +43,13 @@ public class ForwardedHeaderFilterTests {
|
||||
|
||||
@Test
|
||||
public void removeOnly() {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(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")
|
||||
.build());
|
||||
.header("X-Forwarded-Prefix", "prefix"));
|
||||
|
||||
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 = MockServerWebExchange.from(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")
|
||||
.build());
|
||||
.header("X-Forwarded-Proto", "https"));
|
||||
|
||||
this.filter.filter(exchange, this.filterChain).block(Duration.ZERO);
|
||||
|
||||
@@ -79,10 +79,9 @@ public class ForwardedHeaderFilterTests {
|
||||
|
||||
@Test
|
||||
public void forwardedRequest() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("http://example.com/path")
|
||||
.header("Forwarded", "host=84.198.58.199;proto=https")
|
||||
|
||||
.build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest
|
||||
.get("http://example.com/path")
|
||||
.header("Forwarded", "host=84.198.58.199;proto=https"));
|
||||
|
||||
this.filter.filter(exchange, this.filterChain).block(Duration.ZERO);
|
||||
|
||||
@@ -92,9 +91,9 @@ public class ForwardedHeaderFilterTests {
|
||||
|
||||
@Test
|
||||
public void requestUriWithForwardedPrefix() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("http://example.com/path")
|
||||
.header("X-Forwarded-Prefix", "/prefix")
|
||||
.build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest
|
||||
.get("http://example.com/path")
|
||||
.header("X-Forwarded-Prefix", "/prefix"));
|
||||
|
||||
this.filter.filter(exchange, this.filterChain).block(Duration.ZERO);
|
||||
|
||||
@@ -104,9 +103,9 @@ public class ForwardedHeaderFilterTests {
|
||||
|
||||
@Test
|
||||
public void requestUriWithForwardedPrefixTrailingSlash() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("http://example.com/path")
|
||||
.header("X-Forwarded-Prefix", "/prefix/")
|
||||
.build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest
|
||||
.get("http://example.com/path")
|
||||
.header("X-Forwarded-Prefix", "/prefix/"));
|
||||
|
||||
this.filter.filter(exchange, this.filterChain).block(Duration.ZERO);
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@ public class DefaultServerWebExchangeCheckNotModifiedTests {
|
||||
@Test // SPR-14559
|
||||
public void checkNotModifiedInvalidIfNoneMatchHeader() {
|
||||
String eTag = "\"etagvalue\"";
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").ifNoneMatch("missingquotes").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").ifNoneMatch("missingquotes"));
|
||||
assertFalse(exchange.checkNotModified(eTag));
|
||||
assertNull(exchange.getResponse().getStatusCode());
|
||||
assertEquals(eTag, exchange.getResponse().getHeaders().getETag());
|
||||
@@ -135,7 +135,7 @@ public class DefaultServerWebExchangeCheckNotModifiedTests {
|
||||
@Test
|
||||
public void checkNotModifiedETag() {
|
||||
String eTag = "\"Foo\"";
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").ifNoneMatch(eTag).build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").ifNoneMatch(eTag));
|
||||
|
||||
assertTrue(exchange.checkNotModified(eTag));
|
||||
|
||||
@@ -146,7 +146,7 @@ public class DefaultServerWebExchangeCheckNotModifiedTests {
|
||||
@Test
|
||||
public void checkNotModifiedETagWithSeparatorChars() {
|
||||
String eTag = "\"Foo, Bar\"";
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").ifNoneMatch(eTag).build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").ifNoneMatch(eTag));
|
||||
|
||||
assertTrue(exchange.checkNotModified(eTag));
|
||||
|
||||
@@ -159,7 +159,7 @@ public class DefaultServerWebExchangeCheckNotModifiedTests {
|
||||
public void checkModifiedETag() {
|
||||
String currentETag = "\"Foo\"";
|
||||
String oldEtag = "Bar";
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").ifNoneMatch(oldEtag).build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").ifNoneMatch(oldEtag));
|
||||
|
||||
assertFalse(exchange.checkNotModified(currentETag));
|
||||
|
||||
@@ -171,7 +171,7 @@ public class DefaultServerWebExchangeCheckNotModifiedTests {
|
||||
public void checkNotModifiedUnpaddedETag() {
|
||||
String eTag = "Foo";
|
||||
String paddedEtag = String.format("\"%s\"", eTag);
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").ifNoneMatch(paddedEtag).build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").ifNoneMatch(paddedEtag));
|
||||
|
||||
assertTrue(exchange.checkNotModified(eTag));
|
||||
|
||||
@@ -183,7 +183,7 @@ public class DefaultServerWebExchangeCheckNotModifiedTests {
|
||||
public void checkModifiedUnpaddedETag() {
|
||||
String currentETag = "Foo";
|
||||
String oldEtag = "Bar";
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").ifNoneMatch(oldEtag).build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").ifNoneMatch(oldEtag));
|
||||
|
||||
assertFalse(exchange.checkNotModified(currentETag));
|
||||
|
||||
@@ -194,7 +194,7 @@ public class DefaultServerWebExchangeCheckNotModifiedTests {
|
||||
@Test
|
||||
public void checkNotModifiedWildcardIsIgnored() {
|
||||
String eTag = "\"Foo\"";
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").ifNoneMatch("*").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").ifNoneMatch("*"));
|
||||
assertFalse(exchange.checkNotModified(eTag));
|
||||
|
||||
assertNull(exchange.getResponse().getStatusCode());
|
||||
@@ -223,7 +223,7 @@ public class DefaultServerWebExchangeCheckNotModifiedTests {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/")
|
||||
.ifNoneMatch(eTag)
|
||||
.ifModifiedSince(oneMinuteAgo.toEpochMilli())
|
||||
.build());
|
||||
);
|
||||
|
||||
assertTrue(exchange.checkNotModified(eTag, currentDate));
|
||||
|
||||
@@ -251,7 +251,7 @@ public class DefaultServerWebExchangeCheckNotModifiedTests {
|
||||
public void checkNotModifiedETagWeakStrong() {
|
||||
String eTag = "\"Foo\"";
|
||||
String weakEtag = String.format("W/%s", eTag);
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").ifNoneMatch(eTag).build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").ifNoneMatch(eTag));
|
||||
|
||||
assertTrue(exchange.checkNotModified(weakEtag));
|
||||
|
||||
@@ -275,7 +275,7 @@ public class DefaultServerWebExchangeCheckNotModifiedTests {
|
||||
public void checkNotModifiedMultipleETags() {
|
||||
String eTag = "\"Bar\"";
|
||||
String multipleETags = String.format("\"Foo\", %s", eTag);
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").ifNoneMatch(multipleETags).build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").ifNoneMatch(multipleETags));
|
||||
|
||||
assertTrue(exchange.checkNotModified(eTag));
|
||||
|
||||
|
||||
@@ -35,8 +35,7 @@ public class ServerWebExchangeTests {
|
||||
|
||||
@Before
|
||||
public void createExchange() {
|
||||
MockServerHttpRequest request = MockServerHttpRequest.get("http://example.com").build();
|
||||
this.exchange = MockServerWebExchange.from(request);
|
||||
this.exchange = MockServerWebExchange.from(MockServerHttpRequest.get("http://example.com"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -41,8 +41,8 @@ public class ExceptionHandlingWebHandlerTests {
|
||||
|
||||
private final WebHandler targetHandler = new StubWebHandler(new IllegalStateException("boo"));
|
||||
|
||||
private final ServerWebExchange exchange = MockServerWebExchange.from(
|
||||
MockServerHttpRequest.get("http://localhost:8080").build());
|
||||
private final ServerWebExchange exchange =
|
||||
MockServerWebExchange.from(MockServerHttpRequest.get("http://localhost:8080"));
|
||||
|
||||
|
||||
@Test
|
||||
|
||||
@@ -58,7 +58,7 @@ public class FilteringWebHandlerTests {
|
||||
StubWebHandler targetHandler = new StubWebHandler();
|
||||
|
||||
new FilteringWebHandler(targetHandler, Arrays.asList(filter1, filter2, filter3))
|
||||
.handle(MockServerWebExchange.from(MockServerHttpRequest.get("/").build()))
|
||||
.handle(MockServerWebExchange.from(MockServerHttpRequest.get("/")))
|
||||
.block(Duration.ZERO);
|
||||
|
||||
assertTrue(filter1.invoked());
|
||||
@@ -73,7 +73,7 @@ public class FilteringWebHandlerTests {
|
||||
StubWebHandler targetHandler = new StubWebHandler();
|
||||
|
||||
new FilteringWebHandler(targetHandler, Collections.emptyList())
|
||||
.handle(MockServerWebExchange.from(MockServerHttpRequest.get("/").build()))
|
||||
.handle(MockServerWebExchange.from(MockServerHttpRequest.get("/")))
|
||||
.block(Duration.ZERO);
|
||||
|
||||
assertTrue(targetHandler.invoked());
|
||||
@@ -88,7 +88,7 @@ public class FilteringWebHandlerTests {
|
||||
StubWebHandler targetHandler = new StubWebHandler();
|
||||
|
||||
new FilteringWebHandler(targetHandler, Arrays.asList(filter1, filter2, filter3))
|
||||
.handle(MockServerWebExchange.from(MockServerHttpRequest.get("/").build()))
|
||||
.handle(MockServerWebExchange.from(MockServerHttpRequest.get("/")))
|
||||
.block(Duration.ZERO);
|
||||
|
||||
assertTrue(filter1.invoked());
|
||||
@@ -104,7 +104,7 @@ public class FilteringWebHandlerTests {
|
||||
StubWebHandler targetHandler = new StubWebHandler();
|
||||
|
||||
new FilteringWebHandler(targetHandler, Collections.singletonList(filter))
|
||||
.handle(MockServerWebExchange.from(MockServerHttpRequest.get("/").build()))
|
||||
.handle(MockServerWebExchange.from(MockServerHttpRequest.get("/")))
|
||||
.block(Duration.ofSeconds(5));
|
||||
|
||||
assertTrue(filter.invoked());
|
||||
|
||||
@@ -39,8 +39,7 @@ public class ResponseStatusExceptionHandlerTests {
|
||||
|
||||
private final ResponseStatusExceptionHandler handler = new ResponseStatusExceptionHandler();
|
||||
|
||||
private final MockServerWebExchange exchange = MockServerWebExchange.from(
|
||||
MockServerHttpRequest.get("/").build());
|
||||
private final MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||
|
||||
|
||||
@Test
|
||||
|
||||
@@ -81,8 +81,7 @@ public class AcceptHeaderLocaleContextResolverTests {
|
||||
|
||||
|
||||
private ServerWebExchange exchange(Locale... locales) {
|
||||
MockServerHttpRequest request = MockServerHttpRequest.get("").acceptLanguageAsLocales(locales).build();
|
||||
return MockServerWebExchange.from(request);
|
||||
return MockServerWebExchange.from(MockServerHttpRequest.get("").acceptLanguageAsLocales(locales));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -55,8 +55,7 @@ public class FixedLocaleContextResolverTests {
|
||||
}
|
||||
|
||||
private ServerWebExchange exchange(Locale... locales) {
|
||||
MockServerHttpRequest request = MockServerHttpRequest.get("").acceptLanguageAsLocales(locales).build();
|
||||
return MockServerWebExchange.from(request);
|
||||
return MockServerWebExchange.from(MockServerHttpRequest.get("").acceptLanguageAsLocales(locales));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ public class HeaderWebSessionIdResolverTests {
|
||||
@Before
|
||||
public void setUp() {
|
||||
this.idResolver = new HeaderWebSessionIdResolver();
|
||||
this.exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path").build());
|
||||
this.exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -123,8 +123,7 @@ public class HeaderWebSessionIdResolverTests {
|
||||
public void resolveSessionIdsWhenIdThenIdFound() {
|
||||
String id = "123";
|
||||
this.exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path")
|
||||
.header(HeaderWebSessionIdResolver.DEFAULT_HEADER_NAME, id)
|
||||
.build());
|
||||
.header(HeaderWebSessionIdResolver.DEFAULT_HEADER_NAME, id));
|
||||
|
||||
List<String> ids = this.idResolver.resolveSessionIds(this.exchange);
|
||||
|
||||
@@ -137,8 +136,7 @@ public class HeaderWebSessionIdResolverTests {
|
||||
String id2 = "abc";
|
||||
this.exchange = MockServerWebExchange.from(
|
||||
MockServerHttpRequest.get("/path")
|
||||
.header(HeaderWebSessionIdResolver.DEFAULT_HEADER_NAME, id1, id2)
|
||||
.build());
|
||||
.header(HeaderWebSessionIdResolver.DEFAULT_HEADER_NAME, id1, id2));
|
||||
|
||||
List<String> ids = this.idResolver.resolveSessionIds(this.exchange);
|
||||
|
||||
|
||||
@@ -82,8 +82,7 @@ public class DispatcherHandlerErrorTests {
|
||||
|
||||
@Test
|
||||
public void noHandler() throws Exception {
|
||||
MockServerHttpRequest request = MockServerHttpRequest.get("/does-not-exist").build();
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/does-not-exist"));
|
||||
Mono<Void> publisher = this.dispatcherHandler.handle(exchange);
|
||||
|
||||
StepVerifier.create(publisher)
|
||||
@@ -96,8 +95,7 @@ public class DispatcherHandlerErrorTests {
|
||||
|
||||
@Test
|
||||
public void controllerReturnsMonoError() throws Exception {
|
||||
MockServerHttpRequest request = MockServerHttpRequest.get("/error-signal").build();
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/error-signal"));
|
||||
Mono<Void> publisher = this.dispatcherHandler.handle(exchange);
|
||||
|
||||
StepVerifier.create(publisher)
|
||||
@@ -107,8 +105,7 @@ public class DispatcherHandlerErrorTests {
|
||||
|
||||
@Test
|
||||
public void controllerThrowsException() throws Exception {
|
||||
MockServerHttpRequest request = MockServerHttpRequest.get("/raise-exception").build();
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/raise-exception"));
|
||||
Mono<Void> publisher = this.dispatcherHandler.handle(exchange);
|
||||
|
||||
StepVerifier.create(publisher)
|
||||
@@ -118,8 +115,7 @@ public class DispatcherHandlerErrorTests {
|
||||
|
||||
@Test
|
||||
public void unknownReturnType() throws Exception {
|
||||
MockServerHttpRequest request = MockServerHttpRequest.get("/unknown-return-type").build();
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/unknown-return-type"));
|
||||
Mono<Void> publisher = this.dispatcherHandler.handle(exchange);
|
||||
|
||||
StepVerifier.create(publisher)
|
||||
@@ -156,8 +152,7 @@ public class DispatcherHandlerErrorTests {
|
||||
|
||||
@Test
|
||||
public void webExceptionHandler() throws Exception {
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(
|
||||
MockServerHttpRequest.get("/unknown-argument-type").build());
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/unknown-argument-type"));
|
||||
|
||||
List<WebExceptionHandler> handlers = Collections.singletonList(new ServerError500ExceptionHandler());
|
||||
WebHandler webHandler = new ExceptionHandlingWebHandler(this.dispatcherHandler, handlers);
|
||||
|
||||
@@ -67,7 +67,7 @@ public class DispatcherHandlerTests {
|
||||
|
||||
DispatcherHandler dispatcherHandler = new DispatcherHandler(context);
|
||||
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||
dispatcherHandler.handle(exchange).block(Duration.ofSeconds(0));
|
||||
assertEquals("1", exchange.getResponse().getBodyAsString().block(Duration.ofSeconds(5)));
|
||||
}
|
||||
|
||||
@@ -47,8 +47,8 @@ public class HeaderContentTypeResolverTests {
|
||||
@Test
|
||||
public void resolveMediaTypes() throws Exception {
|
||||
String header = "text/plain; q=0.5, text/html, text/x-dvi; q=0.8, text/x-c";
|
||||
MockServerHttpRequest request = MockServerHttpRequest.get("/").header("accept", header).build();
|
||||
List<MediaType> mediaTypes = this.resolver.resolveMediaTypes(MockServerWebExchange.from(request));
|
||||
List<MediaType> mediaTypes = this.resolver.resolveMediaTypes(
|
||||
MockServerWebExchange.from(MockServerHttpRequest.get("/").header("accept", header)));
|
||||
|
||||
assertEquals(4, mediaTypes.size());
|
||||
assertEquals("text/html", mediaTypes.get(0).toString());
|
||||
@@ -60,8 +60,8 @@ public class HeaderContentTypeResolverTests {
|
||||
@Test(expected = NotAcceptableStatusException.class)
|
||||
public void resolveMediaTypesParseError() throws Exception {
|
||||
String header = "textplain; q=0.5";
|
||||
MockServerHttpRequest request = MockServerHttpRequest.get("/").header("accept", header).build();
|
||||
this.resolver.resolveMediaTypes(MockServerWebExchange.from(request));
|
||||
this.resolver.resolveMediaTypes(
|
||||
MockServerWebExchange.from(MockServerHttpRequest.get("/").header("accept", header)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public class ParameterContentTypeResolverTests {
|
||||
@Test
|
||||
public void noKey() throws Exception {
|
||||
ParameterContentTypeResolver resolver = new ParameterContentTypeResolver(Collections.emptyMap());
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||
List<MediaType> mediaTypes = resolver.resolveMediaTypes(exchange);
|
||||
|
||||
assertEquals(0, mediaTypes.size());
|
||||
@@ -87,7 +87,7 @@ public class ParameterContentTypeResolverTests {
|
||||
}
|
||||
|
||||
private MockServerWebExchange createExchange(String format) {
|
||||
return MockServerWebExchange.from(MockServerHttpRequest.get("/path?format=" + format).build());
|
||||
return MockServerWebExchange.from(MockServerHttpRequest.get("/path?format=" + format));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -36,8 +36,8 @@ public class RequestedContentTypeResolverBuilderTests {
|
||||
public void defaultSettings() throws Exception {
|
||||
|
||||
RequestedContentTypeResolver resolver = new RequestedContentTypeResolverBuilder().build();
|
||||
MockServerHttpRequest request = MockServerHttpRequest.get("/flower").accept(MediaType.IMAGE_GIF).build();
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(
|
||||
MockServerHttpRequest.get("/flower").accept(MediaType.IMAGE_GIF));
|
||||
List<MediaType> mediaTypes = resolver.resolveMediaTypes(exchange);
|
||||
|
||||
assertEquals(Collections.singletonList(MediaType.IMAGE_GIF), mediaTypes);
|
||||
@@ -50,8 +50,7 @@ public class RequestedContentTypeResolverBuilderTests {
|
||||
builder.parameterResolver().mediaType("json", MediaType.APPLICATION_JSON);
|
||||
RequestedContentTypeResolver resolver = builder.build();
|
||||
|
||||
MockServerHttpRequest request = MockServerHttpRequest.get("/flower?format=json").build();
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/flower?format=json"));
|
||||
List<MediaType> mediaTypes = resolver.resolveMediaTypes(exchange);
|
||||
|
||||
assertEquals(Collections.singletonList(MediaType.APPLICATION_JSON), mediaTypes);
|
||||
@@ -64,8 +63,8 @@ public class RequestedContentTypeResolverBuilderTests {
|
||||
builder.parameterResolver().mediaType("json", MediaType.APPLICATION_JSON).parameterName("s");
|
||||
RequestedContentTypeResolver resolver = builder.build();
|
||||
|
||||
MockServerHttpRequest request = MockServerHttpRequest.get("/flower?s=json").build();
|
||||
List<MediaType> mediaTypes = resolver.resolveMediaTypes(MockServerWebExchange.from(request));
|
||||
List<MediaType> mediaTypes = resolver.resolveMediaTypes(
|
||||
MockServerWebExchange.from(MockServerHttpRequest.get("/flower?s=json")));
|
||||
|
||||
assertEquals(Collections.singletonList(MediaType.APPLICATION_JSON), mediaTypes);
|
||||
}
|
||||
@@ -77,8 +76,8 @@ public class RequestedContentTypeResolverBuilderTests {
|
||||
builder.fixedResolver(MediaType.APPLICATION_JSON);
|
||||
RequestedContentTypeResolver resolver = builder.build();
|
||||
|
||||
MockServerHttpRequest request = MockServerHttpRequest.get("/").accept(MediaType.ALL).build();
|
||||
List<MediaType> mediaTypes = resolver.resolveMediaTypes(MockServerWebExchange.from(request));
|
||||
List<MediaType> mediaTypes = resolver.resolveMediaTypes(
|
||||
MockServerWebExchange.from(MockServerHttpRequest.get("/").accept(MediaType.ALL)));
|
||||
|
||||
assertEquals(Collections.singletonList(MediaType.APPLICATION_JSON), mediaTypes);
|
||||
}
|
||||
@@ -90,11 +89,11 @@ public class RequestedContentTypeResolverBuilderTests {
|
||||
builder.resolver(new FixedContentTypeResolver(MediaType.APPLICATION_JSON));
|
||||
RequestedContentTypeResolver resolver = builder.build();
|
||||
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||
List<MediaType> mediaTypes = resolver.resolveMediaTypes(exchange);
|
||||
assertEquals(Collections.singletonList(MediaType.APPLICATION_JSON), mediaTypes);
|
||||
|
||||
exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").accept(MediaType.ALL).build());
|
||||
exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").accept(MediaType.ALL));
|
||||
mediaTypes = resolver.resolveMediaTypes(exchange);
|
||||
assertEquals(Collections.singletonList(MediaType.APPLICATION_JSON), mediaTypes);
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ public class ResourceHandlerRegistryTests {
|
||||
|
||||
@Test
|
||||
public void mapPathToLocation() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get(""));
|
||||
exchange.getAttributes().put(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE,
|
||||
PathContainer.parsePath("/testStylesheet.css"));
|
||||
|
||||
|
||||
@@ -105,7 +105,7 @@ public class WebFluxConfigurationSupportTests {
|
||||
RequestedContentTypeResolver resolver = context.getBean(name, RequestedContentTypeResolver.class);
|
||||
assertSame(resolver, mapping.getContentTypeResolver());
|
||||
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(get("/path").accept(MediaType.APPLICATION_JSON).build());
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(get("/path").accept(MediaType.APPLICATION_JSON));
|
||||
assertEquals(Collections.singletonList(MediaType.APPLICATION_JSON), resolver.resolveMediaTypes(exchange));
|
||||
}
|
||||
|
||||
|
||||
@@ -191,8 +191,7 @@ public class DefaultEntityResponseBuilderTests {
|
||||
|
||||
Mono<EntityResponse<Publisher<String>>> result = EntityResponse.fromPublisher(publisher, String.class).build();
|
||||
|
||||
MockServerHttpRequest request = MockServerHttpRequest.get("http://localhost").build();
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("http://localhost"));
|
||||
|
||||
ServerResponse.Context context = new ServerResponse.Context() {
|
||||
@Override
|
||||
|
||||
@@ -108,8 +108,7 @@ public class DefaultRenderingResponseTests {
|
||||
Map<String, Object> model = Collections.singletonMap("foo", "bar");
|
||||
Mono<RenderingResponse> result = RenderingResponse.create("view").modelAttributes(model).build();
|
||||
|
||||
MockServerHttpRequest build = MockServerHttpRequest.get("http://localhost").build();
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(build);
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("http://localhost"));
|
||||
ViewResolver viewResolver = mock(ViewResolver.class);
|
||||
View view = mock(View.class);
|
||||
when(viewResolver.resolveViewName("view", Locale.ENGLISH)).thenReturn(Mono.just(view));
|
||||
|
||||
@@ -64,15 +64,17 @@ public class DefaultServerRequestTests {
|
||||
|
||||
@Before
|
||||
public void createMocks() {
|
||||
this.messageReaders = Collections.<HttpMessageReader<?>>singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes(true)));
|
||||
this.messageReaders = Collections.singletonList(
|
||||
new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes(true)));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void method() throws Exception {
|
||||
HttpMethod method = HttpMethod.HEAD;
|
||||
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(method, "http://example.com").build();
|
||||
DefaultServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), messageReaders);
|
||||
DefaultServerRequest request = new DefaultServerRequest(
|
||||
MockServerWebExchange.from(MockServerHttpRequest.method(method, "http://example.com")),
|
||||
this.messageReaders);
|
||||
|
||||
assertEquals(method, request.method());
|
||||
}
|
||||
@@ -81,8 +83,9 @@ public class DefaultServerRequestTests {
|
||||
public void uri() throws Exception {
|
||||
URI uri = URI.create("https://example.com");
|
||||
|
||||
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.GET, uri).build();
|
||||
DefaultServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), messageReaders);
|
||||
DefaultServerRequest request = new DefaultServerRequest(
|
||||
MockServerWebExchange.from(MockServerHttpRequest.method(HttpMethod.GET, uri)),
|
||||
this.messageReaders);
|
||||
|
||||
assertEquals(uri, request.uri());
|
||||
}
|
||||
@@ -90,8 +93,9 @@ public class DefaultServerRequestTests {
|
||||
@Test
|
||||
public void uriBuilder() throws Exception {
|
||||
URI uri = new URI("http", "localhost", "/path", "a=1", null);
|
||||
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.GET, uri).build();
|
||||
DefaultServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), messageReaders);
|
||||
DefaultServerRequest request = new DefaultServerRequest(
|
||||
MockServerWebExchange.from(MockServerHttpRequest.method(HttpMethod.GET, uri)),
|
||||
this.messageReaders);
|
||||
|
||||
|
||||
URI result = request.uriBuilder().build();
|
||||
@@ -104,8 +108,8 @@ public class DefaultServerRequestTests {
|
||||
|
||||
@Test
|
||||
public void attribute() throws Exception {
|
||||
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.GET, "http://example.com").build();
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(mockRequest);
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(
|
||||
MockServerHttpRequest.method(HttpMethod.GET, "http://example.com"));
|
||||
exchange.getAttributes().put("foo", "bar");
|
||||
|
||||
DefaultServerRequest request = new DefaultServerRequest(exchange, messageReaders);
|
||||
@@ -115,32 +119,34 @@ public class DefaultServerRequestTests {
|
||||
|
||||
@Test
|
||||
public void queryParams() throws Exception {
|
||||
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.GET, "http://example.com?foo=bar").build();
|
||||
DefaultServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), messageReaders);
|
||||
DefaultServerRequest request = new DefaultServerRequest(
|
||||
MockServerWebExchange.from(MockServerHttpRequest.method(HttpMethod.GET, "http://example.com?foo=bar")),
|
||||
this.messageReaders);
|
||||
|
||||
assertEquals(Optional.of("bar"), request.queryParam("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptyQueryParam() throws Exception {
|
||||
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.GET, "http://example.com?foo").build();
|
||||
DefaultServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), messageReaders);
|
||||
DefaultServerRequest request = new DefaultServerRequest(
|
||||
MockServerWebExchange.from(MockServerHttpRequest.method(HttpMethod.GET, "http://example.com?foo")),
|
||||
this.messageReaders);
|
||||
|
||||
assertEquals(Optional.of(""), request.queryParam("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void absentQueryParam() throws Exception {
|
||||
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.GET, "http://example.com?foo").build();
|
||||
DefaultServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), messageReaders);
|
||||
DefaultServerRequest request = new DefaultServerRequest(
|
||||
MockServerWebExchange.from(MockServerHttpRequest.method(HttpMethod.GET, "http://example.com?foo")),
|
||||
this.messageReaders);
|
||||
|
||||
assertEquals(Optional.empty(), request.queryParam("bar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pathVariable() throws Exception {
|
||||
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.GET, "http://example.com").build();
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(mockRequest);
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("http://example.com"));
|
||||
Map<String, String> pathVariables = Collections.singletonMap("foo", "bar");
|
||||
exchange.getAttributes().put(RouterFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE, pathVariables);
|
||||
|
||||
@@ -152,8 +158,7 @@ public class DefaultServerRequestTests {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void pathVariableNotFound() throws Exception {
|
||||
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.GET, "http://example.com").build();
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(mockRequest);
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("http://example.com"));
|
||||
Map<String, String> pathVariables = Collections.singletonMap("foo", "bar");
|
||||
exchange.getAttributes().put(RouterFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE, pathVariables);
|
||||
|
||||
@@ -164,8 +169,7 @@ public class DefaultServerRequestTests {
|
||||
|
||||
@Test
|
||||
public void pathVariables() throws Exception {
|
||||
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.GET, "http://example.com").build();
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(mockRequest);
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("http://example.com"));
|
||||
Map<String, String> pathVariables = Collections.singletonMap("foo", "bar");
|
||||
exchange.getAttributes().put(RouterFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE, pathVariables);
|
||||
|
||||
@@ -191,9 +195,11 @@ public class DefaultServerRequestTests {
|
||||
List<HttpRange> range = Collections.singletonList(HttpRange.createByteRange(0, 42));
|
||||
httpHeaders.setRange(range);
|
||||
|
||||
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.GET, "http://example.com?foo=bar").
|
||||
headers(httpHeaders).build();
|
||||
DefaultServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), messageReaders);
|
||||
DefaultServerRequest request = new DefaultServerRequest(
|
||||
MockServerWebExchange.from(MockServerHttpRequest
|
||||
.method(HttpMethod.GET, "http://example.com?foo=bar")
|
||||
.headers(httpHeaders)),
|
||||
this.messageReaders);
|
||||
|
||||
ServerRequest.Headers headers = request.headers();
|
||||
assertEquals(accept, headers.accept());
|
||||
@@ -206,9 +212,8 @@ public class DefaultServerRequestTests {
|
||||
@Test
|
||||
public void cookies() {
|
||||
HttpCookie cookie = new HttpCookie("foo", "bar");
|
||||
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.GET, "http://example.com").
|
||||
cookie(cookie).build();
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(mockRequest);
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(
|
||||
MockServerHttpRequest.method(HttpMethod.GET, "http://example.com").cookie(cookie));
|
||||
|
||||
DefaultServerRequest request = new DefaultServerRequest(exchange, messageReaders);
|
||||
|
||||
@@ -229,8 +234,10 @@ public class DefaultServerRequestTests {
|
||||
HttpHeaders httpHeaders = new HttpHeaders();
|
||||
httpHeaders.setContentType(MediaType.TEXT_PLAIN);
|
||||
|
||||
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.GET, "http://example.com?foo=bar").
|
||||
headers(httpHeaders).body(body);
|
||||
MockServerHttpRequest mockRequest = MockServerHttpRequest
|
||||
.method(HttpMethod.GET, "http://example.com?foo=bar")
|
||||
.headers(httpHeaders)
|
||||
.body(body);
|
||||
DefaultServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), messageReaders);
|
||||
|
||||
Mono<String> resultMono = request.body(toMono(String.class));
|
||||
@@ -246,8 +253,10 @@ public class DefaultServerRequestTests {
|
||||
|
||||
HttpHeaders httpHeaders = new HttpHeaders();
|
||||
httpHeaders.setContentType(MediaType.TEXT_PLAIN);
|
||||
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.GET, "http://example.com?foo=bar").
|
||||
headers(httpHeaders).body(body);
|
||||
MockServerHttpRequest mockRequest = MockServerHttpRequest
|
||||
.method(HttpMethod.GET, "http://example.com?foo=bar")
|
||||
.headers(httpHeaders)
|
||||
.body(body);
|
||||
DefaultServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), messageReaders);
|
||||
|
||||
Mono<String> resultMono = request.bodyToMono(String.class);
|
||||
@@ -263,8 +272,10 @@ public class DefaultServerRequestTests {
|
||||
|
||||
HttpHeaders httpHeaders = new HttpHeaders();
|
||||
httpHeaders.setContentType(MediaType.TEXT_PLAIN);
|
||||
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.GET, "http://example.com?foo=bar").
|
||||
headers(httpHeaders).body(body);
|
||||
MockServerHttpRequest mockRequest = MockServerHttpRequest
|
||||
.method(HttpMethod.GET, "http://example.com?foo=bar")
|
||||
.headers(httpHeaders)
|
||||
.body(body);
|
||||
DefaultServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), messageReaders);
|
||||
|
||||
ParameterizedTypeReference<String> typeReference = new ParameterizedTypeReference<String>() {};
|
||||
@@ -281,8 +292,10 @@ public class DefaultServerRequestTests {
|
||||
|
||||
HttpHeaders httpHeaders = new HttpHeaders();
|
||||
httpHeaders.setContentType(MediaType.TEXT_PLAIN);
|
||||
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.GET, "http://example.com?foo=bar").
|
||||
headers(httpHeaders).body(body);
|
||||
MockServerHttpRequest mockRequest = MockServerHttpRequest
|
||||
.method(HttpMethod.GET, "http://example.com?foo=bar")
|
||||
.headers(httpHeaders)
|
||||
.body(body);
|
||||
DefaultServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), messageReaders);
|
||||
|
||||
Flux<String> resultFlux = request.bodyToFlux(String.class);
|
||||
@@ -298,8 +311,10 @@ public class DefaultServerRequestTests {
|
||||
|
||||
HttpHeaders httpHeaders = new HttpHeaders();
|
||||
httpHeaders.setContentType(MediaType.TEXT_PLAIN);
|
||||
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.GET, "http://example.com?foo=bar").
|
||||
headers(httpHeaders).body(body);
|
||||
MockServerHttpRequest mockRequest = MockServerHttpRequest
|
||||
.method(HttpMethod.GET, "http://example.com?foo=bar")
|
||||
.headers(httpHeaders)
|
||||
.body(body);
|
||||
DefaultServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), messageReaders);
|
||||
|
||||
ParameterizedTypeReference<String> typeReference = new ParameterizedTypeReference<String>() {};
|
||||
@@ -316,8 +331,10 @@ public class DefaultServerRequestTests {
|
||||
|
||||
HttpHeaders httpHeaders = new HttpHeaders();
|
||||
httpHeaders.setContentType(MediaType.TEXT_PLAIN);
|
||||
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.GET, "http://example.com?foo=bar").
|
||||
headers(httpHeaders).body(body);
|
||||
MockServerHttpRequest mockRequest = MockServerHttpRequest
|
||||
.method(HttpMethod.GET, "http://example.com?foo=bar")
|
||||
.headers(httpHeaders)
|
||||
.body(body);
|
||||
this.messageReaders = Collections.emptyList();
|
||||
DefaultServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), messageReaders);
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ public class ResourceHandlerFunctionTests {
|
||||
|
||||
@Test
|
||||
public void get() throws IOException {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("http://localhost").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("http://localhost"));
|
||||
MockServerHttpResponse mockResponse = exchange.getResponse();
|
||||
|
||||
ServerRequest request = new DefaultServerRequest(exchange, HandlerStrategies.withDefaults().messageReaders());
|
||||
@@ -109,7 +109,7 @@ public class ResourceHandlerFunctionTests {
|
||||
|
||||
@Test
|
||||
public void head() throws IOException {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.head("http://localhost").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.head("http://localhost"));
|
||||
MockServerHttpResponse mockResponse = exchange.getResponse();
|
||||
|
||||
ServerRequest request = new DefaultServerRequest(exchange, HandlerStrategies.withDefaults().messageReaders());
|
||||
@@ -134,7 +134,7 @@ public class ResourceHandlerFunctionTests {
|
||||
|
||||
@Test
|
||||
public void options() {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.options("http://localhost").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.options("http://localhost"));
|
||||
MockServerHttpResponse mockResponse = exchange.getResponse();
|
||||
|
||||
ServerRequest request = new DefaultServerRequest(exchange, HandlerStrategies.withDefaults().messageReaders());
|
||||
|
||||
@@ -54,7 +54,7 @@ public class RouterFunctionMappingTests {
|
||||
@Before
|
||||
public void setUp() {
|
||||
this.messageReaders = Collections.singletonList(new DecoderHttpMessageReader<>(new ByteBufferDecoder()));
|
||||
this.exchange = MockServerWebExchange.from(MockServerHttpRequest.get("http://example.com/match").build());
|
||||
this.exchange = MockServerWebExchange.from(MockServerHttpRequest.get("http://example.com/match"));
|
||||
codecConfigurer = ServerCodecConfigurer.create();
|
||||
|
||||
}
|
||||
|
||||
@@ -136,8 +136,7 @@ public class CorsUrlHandlerMappingTests {
|
||||
return MockServerWebExchange.from(MockServerHttpRequest
|
||||
.method(method, "http://localhost" + path)
|
||||
.header("Origin", origin)
|
||||
.header(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET")
|
||||
.build());
|
||||
.header(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ public class CachingResourceResolverTests {
|
||||
public void resolveResourceInternal() {
|
||||
String file = "bar.css";
|
||||
Resource expected = new ClassPathResource("test/" + file, getClass());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get(""));
|
||||
Resource actual = this.chain.resolveResource(exchange, file, this.locations).block(TIMEOUT);
|
||||
|
||||
assertEquals(expected, actual);
|
||||
@@ -84,7 +84,7 @@ public class CachingResourceResolverTests {
|
||||
this.cache.put(CachingResourceResolver.RESOLVED_RESOURCE_CACHE_KEY_PREFIX + "bar.css", expected);
|
||||
|
||||
String file = "bar.css";
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get(""));
|
||||
Resource actual = this.chain.resolveResource(exchange, file, this.locations).block(TIMEOUT);
|
||||
|
||||
assertSame(expected, actual);
|
||||
@@ -92,7 +92,7 @@ public class CachingResourceResolverTests {
|
||||
|
||||
@Test
|
||||
public void resolveResourceInternalNoMatch() {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get(""));
|
||||
assertNull(this.chain.resolveResource(exchange, "invalid.css", this.locations).block(TIMEOUT));
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ public class CachingResourceResolverTests {
|
||||
public void resolveResourceAcceptEncodingInCacheKey() {
|
||||
String file = "bar.css";
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get(file)
|
||||
.header("Accept-Encoding", "gzip").build());
|
||||
.header("Accept-Encoding", "gzip"));
|
||||
|
||||
Resource expected = this.chain.resolveResource(exchange, file, this.locations).block(TIMEOUT);
|
||||
String cacheKey = CachingResourceResolver.RESOLVED_RESOURCE_CACHE_KEY_PREFIX + file + "+encoding=gzip";
|
||||
@@ -133,7 +133,7 @@ public class CachingResourceResolverTests {
|
||||
@Test
|
||||
public void resolveResourceNoAcceptEncodingInCacheKey() {
|
||||
String file = "bar.css";
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get(file).build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get(file));
|
||||
|
||||
Resource expected = this.chain.resolveResource(exchange, file, this.locations).block(TIMEOUT);
|
||||
String cacheKey = CachingResourceResolver.RESOLVED_RESOURCE_CACHE_KEY_PREFIX + file;
|
||||
@@ -149,11 +149,10 @@ public class CachingResourceResolverTests {
|
||||
this.cache.put(CachingResourceResolver.RESOLVED_RESOURCE_CACHE_KEY_PREFIX + "bar.css+encoding=gzip", gzResource);
|
||||
|
||||
String file = "bar.css";
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get(file).build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get(file));
|
||||
assertSame(resource, this.chain.resolveResource(exchange, file, this.locations).block(TIMEOUT));
|
||||
|
||||
MockServerHttpRequest request = MockServerHttpRequest.get(file).header("Accept-Encoding", "gzip").build();
|
||||
exchange = MockServerWebExchange.from(request);
|
||||
exchange = MockServerWebExchange.from(MockServerHttpRequest.get(file).header("Accept-Encoding", "gzip"));
|
||||
assertSame(gzResource, this.chain.resolveResource(exchange, file, this.locations).block(TIMEOUT));
|
||||
}
|
||||
|
||||
|
||||
@@ -76,8 +76,7 @@ public class CssLinkResourceTransformerTests {
|
||||
|
||||
@Test
|
||||
public void transform() throws Exception {
|
||||
MockServerHttpRequest request = MockServerHttpRequest.get("/static/main.css").build();
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/static/main.css"));
|
||||
Resource css = new ClassPathResource("test/main.css", getClass());
|
||||
|
||||
String expected = "\n" +
|
||||
@@ -99,7 +98,7 @@ public class CssLinkResourceTransformerTests {
|
||||
|
||||
@Test
|
||||
public void transformNoLinks() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/static/foo.css").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/static/foo.css"));
|
||||
Resource expected = new ClassPathResource("test/foo.css", getClass());
|
||||
StepVerifier.create(this.transformerChain.transform(exchange, expected))
|
||||
.consumeNextWith(resource -> assertSame(expected, resource))
|
||||
@@ -108,7 +107,7 @@ public class CssLinkResourceTransformerTests {
|
||||
|
||||
@Test
|
||||
public void transformExtLinksNotAllowed() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/static/external.css").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/static/external.css"));
|
||||
ResourceResolverChain resolverChain = Mockito.mock(DefaultResourceResolverChain.class);
|
||||
ResourceTransformerChain transformerChain = new DefaultResourceTransformerChain(resolverChain,
|
||||
Collections.singletonList(new CssLinkResourceTransformer()));
|
||||
@@ -134,7 +133,7 @@ public class CssLinkResourceTransformerTests {
|
||||
|
||||
@Test
|
||||
public void transformWithNonCssResource() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/static/images/image.png").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/static/images/image.png"));
|
||||
Resource expected = new ClassPathResource("test/images/image.png", getClass());
|
||||
StepVerifier.create(this.transformerChain.transform(exchange, expected))
|
||||
.expectNext(expected)
|
||||
@@ -143,7 +142,7 @@ public class CssLinkResourceTransformerTests {
|
||||
|
||||
@Test
|
||||
public void transformWithGzippedResource() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/static/main.css").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/static/main.css"));
|
||||
Resource original = new ClassPathResource("test/main.css", getClass());
|
||||
createTempCopy("main.css", "main.css.gz");
|
||||
GzipResourceResolver.GzippedResource expected = new GzipResourceResolver.GzippedResource(original);
|
||||
|
||||
@@ -105,7 +105,7 @@ public class GzipResourceResolverTests {
|
||||
@Test
|
||||
public void resolveGzippedFile() throws IOException {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("")
|
||||
.header("Accept-Encoding", "gzip").build());
|
||||
.header("Accept-Encoding", "gzip"));
|
||||
|
||||
String file = "js/foo.js";
|
||||
Resource resolved = this.resolver.resolveResource(exchange, file, this.locations).block(TIMEOUT);
|
||||
@@ -121,7 +121,7 @@ public class GzipResourceResolverTests {
|
||||
@Test
|
||||
public void resolveFingerprintedGzippedFile() throws IOException {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("")
|
||||
.header("Accept-Encoding", "gzip").build());
|
||||
.header("Accept-Encoding", "gzip"));
|
||||
|
||||
String file = "foo-e36d2e05253c6c7085a91522ce43a0b4.css";
|
||||
Resource resolved = this.resolver.resolveResource(exchange, file, this.locations).block(TIMEOUT);
|
||||
@@ -137,7 +137,7 @@ public class GzipResourceResolverTests {
|
||||
@Test
|
||||
public void resolveFromCacheWithEncodingVariants() throws IOException {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("")
|
||||
.header("Accept-Encoding", "gzip").build());
|
||||
.header("Accept-Encoding", "gzip"));
|
||||
|
||||
String file = "js/foo.js";
|
||||
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
|
||||
|
||||
exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/js/foo.js").build());
|
||||
exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/js/foo.js"));
|
||||
resolved = this.resolver.resolveResource(exchange, file, this.locations).block(TIMEOUT);
|
||||
|
||||
Resource resource = new ClassPathResource("test/"+file, getClass());
|
||||
|
||||
@@ -71,8 +71,7 @@ public class ResourceTransformerSupportTests {
|
||||
|
||||
@Test
|
||||
public void resolveUrlPath() throws Exception {
|
||||
MockServerHttpRequest request = MockServerHttpRequest.get("/resources/main.css").build();
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/resources/main.css"));
|
||||
String resourcePath = "/resources/bar.css";
|
||||
Resource css = new ClassPathResource("test/main.css", getClass());
|
||||
String actual = this.transformer.resolveUrlPath(
|
||||
@@ -85,7 +84,7 @@ public class ResourceTransformerSupportTests {
|
||||
@Test
|
||||
public void resolveUrlPathWithRelativePath() throws Exception {
|
||||
Resource css = new ClassPathResource("test/main.css", getClass());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get(""));
|
||||
String actual = this.transformer.resolveUrlPath(
|
||||
"bar.css", exchange, css, this.transformerChain).block(Duration.ofSeconds(5));
|
||||
|
||||
@@ -95,7 +94,7 @@ public class ResourceTransformerSupportTests {
|
||||
@Test
|
||||
public void resolveUrlPathWithRelativePathInParentDirectory() throws Exception {
|
||||
Resource imagePng = new ClassPathResource("test/images/image.png", getClass());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get(""));
|
||||
String actual = this.transformer.resolveUrlPath(
|
||||
"../bar.css", exchange, imagePng, this.transformerChain).block(Duration.ofSeconds(5));
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ public class ResourceUrlProviderTests {
|
||||
|
||||
@Test
|
||||
public void getStaticResourceUrl() {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||
String uriString = "/resources/foo.css";
|
||||
String actual = this.urlProvider.getForUriString(uriString, exchange).block(Duration.ofSeconds(5));
|
||||
assertEquals(uriString, actual);
|
||||
@@ -80,7 +80,7 @@ public class ResourceUrlProviderTests {
|
||||
|
||||
@Test // SPR-13374
|
||||
public void getStaticResourceUrlRequestWithQueryOrHash() {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||
|
||||
String url = "/resources/foo.css?foo=bar&url=http://example.org";
|
||||
String resolvedUrl = this.urlProvider.getForUriString(url, exchange).block(Duration.ofSeconds(5));
|
||||
@@ -103,7 +103,7 @@ public class ResourceUrlProviderTests {
|
||||
resolvers.add(new PathResourceResolver());
|
||||
this.handler.setResourceResolvers(resolvers);
|
||||
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||
String path = "/resources/foo.css";
|
||||
String url = this.urlProvider.getForUriString(path, exchange).block(Duration.ofSeconds(5));
|
||||
assertEquals("/resources/foo-e36d2e05253c6c7085a91522ce43a0b4.css", url);
|
||||
@@ -126,7 +126,7 @@ public class ResourceUrlProviderTests {
|
||||
this.handlerMap.put("/resources/*.css", otherHandler);
|
||||
this.urlProvider.registerHandlers(this.handlerMap);
|
||||
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||
String path = "/resources/foo.css";
|
||||
String url = this.urlProvider.getForUriString(path, exchange).block(Duration.ofSeconds(5));
|
||||
assertEquals("/resources/foo-e36d2e05253c6c7085a91522ce43a0b4.css", url);
|
||||
|
||||
@@ -93,7 +93,7 @@ public class ResourceWebHandlerTests {
|
||||
|
||||
@Test
|
||||
public void getResource() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get(""));
|
||||
setPathWithinHandlerMapping(exchange, "foo.css");
|
||||
this.handler.handle(exchange).block(TIMEOUT);
|
||||
|
||||
@@ -110,7 +110,7 @@ public class ResourceWebHandlerTests {
|
||||
|
||||
@Test
|
||||
public void getResourceHttpHeader() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.head("").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.head(""));
|
||||
setPathWithinHandlerMapping(exchange, "foo.css");
|
||||
this.handler.handle(exchange).block(TIMEOUT);
|
||||
|
||||
@@ -131,7 +131,7 @@ public class ResourceWebHandlerTests {
|
||||
|
||||
@Test
|
||||
public void getResourceHttpOptions() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.options("").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.options(""));
|
||||
setPathWithinHandlerMapping(exchange, "foo.css");
|
||||
this.handler.handle(exchange).block(TIMEOUT);
|
||||
|
||||
@@ -141,7 +141,7 @@ public class ResourceWebHandlerTests {
|
||||
|
||||
@Test
|
||||
public void getResourceNoCache() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get(""));
|
||||
setPathWithinHandlerMapping(exchange, "foo.css");
|
||||
this.handler.setCacheControl(CacheControl.noStore());
|
||||
this.handler.handle(exchange).block(TIMEOUT);
|
||||
@@ -161,7 +161,7 @@ public class ResourceWebHandlerTests {
|
||||
this.handler.setResourceResolvers(Arrays.asList(versionResolver, new PathResourceResolver()));
|
||||
this.handler.afterPropertiesSet();
|
||||
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get(""));
|
||||
setPathWithinHandlerMapping(exchange, "versionString/foo.css");
|
||||
this.handler.handle(exchange).block(TIMEOUT);
|
||||
|
||||
@@ -172,7 +172,7 @@ public class ResourceWebHandlerTests {
|
||||
|
||||
@Test
|
||||
public void getResourceWithHtmlMediaType() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get(""));
|
||||
setPathWithinHandlerMapping(exchange, "foo.html");
|
||||
this.handler.handle(exchange).block(TIMEOUT);
|
||||
|
||||
@@ -187,7 +187,7 @@ public class ResourceWebHandlerTests {
|
||||
|
||||
@Test
|
||||
public void getResourceFromAlternatePath() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get(""));
|
||||
setPathWithinHandlerMapping(exchange, "baz.css");
|
||||
this.handler.handle(exchange).block(TIMEOUT);
|
||||
|
||||
@@ -204,7 +204,7 @@ public class ResourceWebHandlerTests {
|
||||
|
||||
@Test
|
||||
public void getResourceFromSubDirectory() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get(""));
|
||||
setPathWithinHandlerMapping(exchange, "js/foo.js");
|
||||
this.handler.handle(exchange).block(TIMEOUT);
|
||||
|
||||
@@ -215,7 +215,7 @@ public class ResourceWebHandlerTests {
|
||||
|
||||
@Test
|
||||
public void getResourceFromSubDirectoryOfAlternatePath() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get(""));
|
||||
setPathWithinHandlerMapping(exchange, "js/baz.js");
|
||||
this.handler.handle(exchange).block(TIMEOUT);
|
||||
|
||||
@@ -232,7 +232,7 @@ public class ResourceWebHandlerTests {
|
||||
handler.afterPropertiesSet();
|
||||
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("")
|
||||
.header("Accept", "application/json,text/plain,*/*").build());
|
||||
.header("Accept", "application/json,text/plain,*/*"));
|
||||
setPathWithinHandlerMapping(exchange, "foo.html");
|
||||
handler.handle(exchange).block(TIMEOUT);
|
||||
|
||||
@@ -273,8 +273,7 @@ public class ResourceWebHandlerTests {
|
||||
}
|
||||
|
||||
private void testInvalidPath(HttpMethod httpMethod, String requestPath, Resource location) throws Exception {
|
||||
MockServerHttpRequest request = MockServerHttpRequest.method(httpMethod, "").build();
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.method(httpMethod, ""));
|
||||
setPathWithinHandlerMapping(exchange, requestPath);
|
||||
StepVerifier.create(this.handler.handle(exchange))
|
||||
.expectErrorSatisfies(err -> {
|
||||
@@ -347,7 +346,7 @@ public class ResourceWebHandlerTests {
|
||||
@Test
|
||||
public void notModified() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("")
|
||||
.ifModifiedSince(resourceLastModified("test/foo.css")).build());
|
||||
.ifModifiedSince(resourceLastModified("test/foo.css")));
|
||||
setPathWithinHandlerMapping(exchange, "foo.css");
|
||||
this.handler.handle(exchange).block(TIMEOUT);
|
||||
assertEquals(HttpStatus.NOT_MODIFIED, exchange.getResponse().getStatusCode());
|
||||
@@ -367,7 +366,7 @@ public class ResourceWebHandlerTests {
|
||||
|
||||
@Test
|
||||
public void directory() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get(""));
|
||||
setPathWithinHandlerMapping(exchange, "js/");
|
||||
StepVerifier.create(this.handler.handle(exchange))
|
||||
.expectErrorSatisfies(err -> {
|
||||
@@ -378,7 +377,7 @@ public class ResourceWebHandlerTests {
|
||||
|
||||
@Test
|
||||
public void directoryInJarFile() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get(""));
|
||||
setPathWithinHandlerMapping(exchange, "underscorejs/");
|
||||
this.handler.handle(exchange).block(TIMEOUT);
|
||||
|
||||
@@ -388,7 +387,7 @@ public class ResourceWebHandlerTests {
|
||||
|
||||
@Test
|
||||
public void missingResourcePath() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get(""));
|
||||
setPathWithinHandlerMapping(exchange, "");
|
||||
StepVerifier.create(this.handler.handle(exchange))
|
||||
.expectErrorSatisfies(err -> {
|
||||
@@ -399,13 +398,13 @@ public class ResourceWebHandlerTests {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void noPathWithinHandlerMappingAttribute() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get(""));
|
||||
this.handler.handle(exchange).block(TIMEOUT);
|
||||
}
|
||||
|
||||
@Test(expected = MethodNotAllowedException.class)
|
||||
public void unsupportedHttpMethod() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.post("").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.post(""));
|
||||
setPathWithinHandlerMapping(exchange, "foo.css");
|
||||
this.handler.handle(exchange).block(TIMEOUT);
|
||||
}
|
||||
@@ -569,7 +568,7 @@ public class ResourceWebHandlerTests {
|
||||
|
||||
@Test // SPR-14005
|
||||
public void doOverwriteExistingCacheControlHeaders() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get(""));
|
||||
exchange.getResponse().getHeaders().setCacheControl(CacheControl.noStore().getHeaderValue());
|
||||
setPathWithinHandlerMapping(exchange, "foo.css");
|
||||
this.handler.handle(exchange).block(TIMEOUT);
|
||||
|
||||
@@ -64,7 +64,7 @@ public class WebJarsResourceResolverTests {
|
||||
this.locations = singletonList(new ClassPathResource("/META-INF/resources/webjars"));
|
||||
this.resolver = new WebJarsResourceResolver();
|
||||
this.chain = mock(ResourceResolverChain.class);
|
||||
this.exchange = MockServerWebExchange.from(MockServerHttpRequest.get("").build());
|
||||
this.exchange = MockServerWebExchange.from(MockServerHttpRequest.get(""));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ public class HandlerResultHandlerTests {
|
||||
public void usesContentTypeResolver() throws Exception {
|
||||
TestResultHandler resultHandler = new TestResultHandler(new FixedContentTypeResolver(IMAGE_GIF));
|
||||
List<MediaType> mediaTypes = Arrays.asList(IMAGE_JPEG, IMAGE_GIF, IMAGE_PNG);
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path"));
|
||||
MediaType actual = resultHandler.selectMediaType(exchange, () -> mediaTypes);
|
||||
|
||||
assertEquals(IMAGE_GIF, actual);
|
||||
@@ -62,7 +62,7 @@ public class HandlerResultHandlerTests {
|
||||
|
||||
@Test
|
||||
public void producibleMediaTypesRequestAttribute() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path"));
|
||||
exchange.getAttributes().put(HandlerMapping.PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE, Collections.singleton(IMAGE_GIF));
|
||||
|
||||
List<MediaType> mediaTypes = Arrays.asList(IMAGE_JPEG, IMAGE_GIF, IMAGE_PNG);
|
||||
@@ -74,8 +74,7 @@ public class HandlerResultHandlerTests {
|
||||
@Test // SPR-9160
|
||||
public void sortsByQuality() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path")
|
||||
.header("Accept", "text/plain; q=0.5, application/json")
|
||||
.build());
|
||||
.header("Accept", "text/plain; q=0.5, application/json"));
|
||||
|
||||
List<MediaType> mediaTypes = Arrays.asList(TEXT_PLAIN, APPLICATION_JSON_UTF8);
|
||||
MediaType actual = this.resultHandler.selectMediaType(exchange, () -> mediaTypes);
|
||||
@@ -87,7 +86,7 @@ public class HandlerResultHandlerTests {
|
||||
public void charsetFromAcceptHeader() throws Exception {
|
||||
MediaType text8859 = MediaType.parseMediaType("text/plain;charset=ISO-8859-1");
|
||||
MediaType textUtf8 = MediaType.parseMediaType("text/plain;charset=UTF-8");
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path").accept(text8859).build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path").accept(text8859));
|
||||
MediaType actual = this.resultHandler.selectMediaType(exchange, () -> Collections.singletonList(textUtf8));
|
||||
|
||||
assertEquals(text8859, actual);
|
||||
@@ -96,7 +95,7 @@ public class HandlerResultHandlerTests {
|
||||
@Test // SPR-12894
|
||||
public void noConcreteMediaType() throws Exception {
|
||||
List<MediaType> producible = Collections.singletonList(ALL);
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path"));
|
||||
MediaType actual = this.resultHandler.selectMediaType(exchange, () -> producible);
|
||||
|
||||
assertEquals(APPLICATION_OCTET_STREAM, actual);
|
||||
|
||||
@@ -98,20 +98,20 @@ public class CompositeRequestConditionTests {
|
||||
@Test
|
||||
public void noMatch() {
|
||||
CompositeRequestCondition cond = new CompositeRequestCondition(this.param1);
|
||||
assertNull(cond.getMatchingCondition(MockServerWebExchange.from(MockServerHttpRequest.get("/").build())));
|
||||
assertNull(cond.getMatchingCondition(MockServerWebExchange.from(MockServerHttpRequest.get("/"))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchEmpty() {
|
||||
CompositeRequestCondition empty = new CompositeRequestCondition();
|
||||
assertSame(empty, empty.getMatchingCondition(MockServerWebExchange.from(MockServerHttpRequest.get("/").build())));
|
||||
assertSame(empty, empty.getMatchingCondition(MockServerWebExchange.from(MockServerHttpRequest.get("/"))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compare() {
|
||||
CompositeRequestCondition cond1 = new CompositeRequestCondition(this.param1);
|
||||
CompositeRequestCondition cond3 = new CompositeRequestCondition(this.param3);
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||
|
||||
assertEquals(1, cond1.compareTo(cond3, exchange));
|
||||
assertEquals(-1, cond3.compareTo(cond1, exchange));
|
||||
@@ -121,7 +121,7 @@ public class CompositeRequestConditionTests {
|
||||
public void compareEmpty() {
|
||||
CompositeRequestCondition empty = new CompositeRequestCondition();
|
||||
CompositeRequestCondition notEmpty = new CompositeRequestCondition(this.param1);
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||
|
||||
assertEquals(0, empty.compareTo(empty, exchange));
|
||||
assertEquals(-1, notEmpty.compareTo(empty, exchange));
|
||||
@@ -132,7 +132,7 @@ public class CompositeRequestConditionTests {
|
||||
public void compareDifferentLength() {
|
||||
CompositeRequestCondition cond1 = new CompositeRequestCondition(this.param1);
|
||||
CompositeRequestCondition cond2 = new CompositeRequestCondition(this.param1, this.header1);
|
||||
cond1.compareTo(cond2, MockServerWebExchange.from(MockServerHttpRequest.get("/").build()));
|
||||
cond1.compareTo(cond2, MockServerWebExchange.from(MockServerHttpRequest.get("/")));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ public class ConsumesRequestConditionTests {
|
||||
|
||||
@Test
|
||||
public void compareToSingle() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||
|
||||
ConsumesRequestCondition condition1 = new ConsumesRequestCondition("text/plain");
|
||||
ConsumesRequestCondition condition2 = new ConsumesRequestCondition("text/*");
|
||||
@@ -115,7 +115,7 @@ public class ConsumesRequestConditionTests {
|
||||
|
||||
@Test
|
||||
public void compareToMultiple() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||
|
||||
ConsumesRequestCondition condition1 = new ConsumesRequestCondition("*/*", "text/plain");
|
||||
ConsumesRequestCondition condition2 = new ConsumesRequestCondition("text/*", "text/plain;q=0.7");
|
||||
@@ -189,7 +189,7 @@ public class ConsumesRequestConditionTests {
|
||||
|
||||
private MockServerWebExchange postExchange(String contentType) {
|
||||
return MockServerWebExchange.from(
|
||||
MockServerHttpRequest.post("/").header(HttpHeaders.CONTENT_TYPE, contentType).build());
|
||||
MockServerHttpRequest.post("/").header(HttpHeaders.CONTENT_TYPE, contentType));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public class HeadersRequestConditionTests {
|
||||
|
||||
@Test
|
||||
public void headerPresent() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("Accept", "").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("Accept", ""));
|
||||
HeadersRequestCondition condition = new HeadersRequestCondition("accept");
|
||||
|
||||
assertNotNull(condition.getMatchingCondition(exchange));
|
||||
@@ -55,7 +55,7 @@ public class HeadersRequestConditionTests {
|
||||
|
||||
@Test
|
||||
public void headerPresentNoMatch() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("bar", "").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("bar", ""));
|
||||
HeadersRequestCondition condition = new HeadersRequestCondition("foo");
|
||||
|
||||
assertNull(condition.getMatchingCondition(exchange));
|
||||
@@ -63,7 +63,7 @@ public class HeadersRequestConditionTests {
|
||||
|
||||
@Test
|
||||
public void headerNotPresent() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||
HeadersRequestCondition condition = new HeadersRequestCondition("!accept");
|
||||
|
||||
assertNotNull(condition.getMatchingCondition(exchange));
|
||||
@@ -71,7 +71,7 @@ public class HeadersRequestConditionTests {
|
||||
|
||||
@Test
|
||||
public void headerValueMatch() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("foo", "bar").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("foo", "bar"));
|
||||
HeadersRequestCondition condition = new HeadersRequestCondition("foo=bar");
|
||||
|
||||
assertNotNull(condition.getMatchingCondition(exchange));
|
||||
@@ -79,7 +79,7 @@ public class HeadersRequestConditionTests {
|
||||
|
||||
@Test
|
||||
public void headerValueNoMatch() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("foo", "bazz").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("foo", "bazz"));
|
||||
HeadersRequestCondition condition = new HeadersRequestCondition("foo=bar");
|
||||
|
||||
assertNull(condition.getMatchingCondition(exchange));
|
||||
@@ -87,7 +87,7 @@ public class HeadersRequestConditionTests {
|
||||
|
||||
@Test
|
||||
public void headerCaseSensitiveValueMatch() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("foo", "bar").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("foo", "bar"));
|
||||
HeadersRequestCondition condition = new HeadersRequestCondition("foo=Bar");
|
||||
|
||||
assertNull(condition.getMatchingCondition(exchange));
|
||||
@@ -95,7 +95,7 @@ public class HeadersRequestConditionTests {
|
||||
|
||||
@Test
|
||||
public void headerValueMatchNegated() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("foo", "baz").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("foo", "baz"));
|
||||
HeadersRequestCondition condition = new HeadersRequestCondition("foo!=bar");
|
||||
|
||||
assertNotNull(condition.getMatchingCondition(exchange));
|
||||
@@ -103,7 +103,7 @@ public class HeadersRequestConditionTests {
|
||||
|
||||
@Test
|
||||
public void headerValueNoMatchNegated() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("foo", "bar").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("foo", "bar"));
|
||||
HeadersRequestCondition condition = new HeadersRequestCondition("foo!=bar");
|
||||
|
||||
assertNull(condition.getMatchingCondition(exchange));
|
||||
@@ -111,7 +111,7 @@ public class HeadersRequestConditionTests {
|
||||
|
||||
@Test
|
||||
public void compareTo() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||
|
||||
HeadersRequestCondition condition1 = new HeadersRequestCondition("foo", "bar", "baz");
|
||||
HeadersRequestCondition condition2 = new HeadersRequestCondition("foo", "bar");
|
||||
@@ -136,7 +136,7 @@ public class HeadersRequestConditionTests {
|
||||
|
||||
@Test
|
||||
public void getMatchingCondition() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("foo", "bar").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("foo", "bar"));
|
||||
HeadersRequestCondition condition = new HeadersRequestCondition("foo");
|
||||
|
||||
HeadersRequestCondition result = condition.getMatchingCondition(exchange);
|
||||
|
||||
@@ -48,42 +48,42 @@ public class ParamsRequestConditionTests {
|
||||
@Test
|
||||
public void paramPresent() throws Exception {
|
||||
ParamsRequestCondition condition = new ParamsRequestCondition("foo");
|
||||
assertNotNull(condition.getMatchingCondition(MockServerWebExchange.from(get("/path?foo=").build())));
|
||||
assertNotNull(condition.getMatchingCondition(MockServerWebExchange.from(get("/path?foo="))));
|
||||
}
|
||||
|
||||
@Test // SPR-15831
|
||||
public void paramPresentNullValue() throws Exception {
|
||||
ParamsRequestCondition condition = new ParamsRequestCondition("foo");
|
||||
assertNotNull(condition.getMatchingCondition(MockServerWebExchange.from(get("/path?foo").build())));
|
||||
assertNotNull(condition.getMatchingCondition(MockServerWebExchange.from(get("/path?foo"))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void paramPresentNoMatch() throws Exception {
|
||||
ParamsRequestCondition condition = new ParamsRequestCondition("foo");
|
||||
assertNull(condition.getMatchingCondition(MockServerWebExchange.from(get("/path?bar=").build())));
|
||||
assertNull(condition.getMatchingCondition(MockServerWebExchange.from(get("/path?bar="))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void paramNotPresent() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/"));
|
||||
assertNotNull(new ParamsRequestCondition("!foo").getMatchingCondition(exchange));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void paramValueMatch() throws Exception {
|
||||
ParamsRequestCondition condition = new ParamsRequestCondition("foo=bar");
|
||||
assertNotNull(condition.getMatchingCondition(MockServerWebExchange.from(get("/path?foo=bar").build())));
|
||||
assertNotNull(condition.getMatchingCondition(MockServerWebExchange.from(get("/path?foo=bar"))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void paramValueNoMatch() throws Exception {
|
||||
ParamsRequestCondition condition = new ParamsRequestCondition("foo=bar");
|
||||
assertNull(condition.getMatchingCondition(MockServerWebExchange.from(get("/path?foo=bazz").build())));
|
||||
assertNull(condition.getMatchingCondition(MockServerWebExchange.from(get("/path?foo=bazz"))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compareTo() throws Exception {
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(get("/").build());
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(get("/"));
|
||||
|
||||
ParamsRequestCondition condition1 = new ParamsRequestCondition("foo", "bar", "baz");
|
||||
ParamsRequestCondition condition2 = new ParamsRequestCondition("foo", "bar");
|
||||
|
||||
@@ -80,7 +80,7 @@ public class PatternsRequestConditionTests {
|
||||
@Test
|
||||
public void matchDirectPath() throws Exception {
|
||||
PatternsRequestCondition condition = createPatternsCondition("/foo");
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/foo").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/foo"));
|
||||
PatternsRequestCondition match = condition.getMatchingCondition(exchange);
|
||||
|
||||
assertNotNull(match);
|
||||
@@ -89,7 +89,7 @@ public class PatternsRequestConditionTests {
|
||||
@Test
|
||||
public void matchPattern() throws Exception {
|
||||
PatternsRequestCondition condition = createPatternsCondition("/foo/*");
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/foo/bar").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/foo/bar"));
|
||||
PatternsRequestCondition match = condition.getMatchingCondition(exchange);
|
||||
|
||||
assertNotNull(match);
|
||||
@@ -98,7 +98,7 @@ public class PatternsRequestConditionTests {
|
||||
@Test
|
||||
public void matchSortPatterns() throws Exception {
|
||||
PatternsRequestCondition condition = createPatternsCondition("/*/*", "/foo/bar", "/foo/*");
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/foo/bar").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/foo/bar"));
|
||||
PatternsRequestCondition match = condition.getMatchingCondition(exchange);
|
||||
PatternsRequestCondition expected = createPatternsCondition("/foo/bar", "/foo/*", "/*/*");
|
||||
|
||||
@@ -107,7 +107,7 @@ public class PatternsRequestConditionTests {
|
||||
|
||||
@Test
|
||||
public void matchTrailingSlash() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/foo/").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/foo/"));
|
||||
|
||||
PatternsRequestCondition condition = createPatternsCondition("/foo");
|
||||
PatternsRequestCondition match = condition.getMatchingCondition(exchange);
|
||||
@@ -126,7 +126,7 @@ public class PatternsRequestConditionTests {
|
||||
PathPatternParser parser = new PathPatternParser();
|
||||
parser.setMatchOptionalTrailingSeparator(false);
|
||||
condition = new PatternsRequestCondition(parser.parse("/foo"));
|
||||
match = condition.getMatchingCondition(MockServerWebExchange.from(get("/foo/").build()));
|
||||
match = condition.getMatchingCondition(MockServerWebExchange.from(get("/foo/")));
|
||||
|
||||
assertNull(match);
|
||||
}
|
||||
@@ -134,7 +134,7 @@ public class PatternsRequestConditionTests {
|
||||
@Test
|
||||
public void matchPatternContainsExtension() throws Exception {
|
||||
PatternsRequestCondition condition = createPatternsCondition("/foo.jpg");
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/foo.html").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/foo.html"));
|
||||
PatternsRequestCondition match = condition.getMatchingCondition(exchange);
|
||||
|
||||
assertNull(match);
|
||||
@@ -145,7 +145,7 @@ public class PatternsRequestConditionTests {
|
||||
PatternsRequestCondition c1 = createPatternsCondition("/foo*");
|
||||
PatternsRequestCondition c2 = createPatternsCondition("/foo*");
|
||||
|
||||
assertEquals(0, c1.compareTo(c2, MockServerWebExchange.from(get("/foo").build())));
|
||||
assertEquals(0, c1.compareTo(c2, MockServerWebExchange.from(get("/foo"))));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -159,7 +159,7 @@ public class PatternsRequestConditionTests {
|
||||
|
||||
@Test
|
||||
public void comparePatternSpecificity() throws Exception {
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(get("/foo").build());
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(get("/foo"));
|
||||
|
||||
PatternsRequestCondition c1 = createPatternsCondition("/fo*");
|
||||
PatternsRequestCondition c2 = createPatternsCondition("/foo");
|
||||
@@ -174,7 +174,7 @@ public class PatternsRequestConditionTests {
|
||||
|
||||
@Test
|
||||
public void compareNumberOfMatchingPatterns() throws Exception {
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(get("/foo.html").build());
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(get("/foo.html"));
|
||||
|
||||
PatternsRequestCondition c1 = createPatternsCondition("/foo.*", "/foo.jpeg");
|
||||
PatternsRequestCondition c2 = createPatternsCondition("/foo.*", "/foo.html");
|
||||
|
||||
@@ -41,7 +41,7 @@ public class ProducesRequestConditionTests {
|
||||
|
||||
@Test
|
||||
public void match() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("Accept", "text/plain").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("Accept", "text/plain"));
|
||||
ProducesRequestCondition condition = new ProducesRequestCondition("text/plain");
|
||||
|
||||
assertNotNull(condition.getMatchingCondition(exchange));
|
||||
@@ -49,7 +49,7 @@ public class ProducesRequestConditionTests {
|
||||
|
||||
@Test
|
||||
public void matchNegated() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("Accept", "text/plain").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("Accept", "text/plain"));
|
||||
ProducesRequestCondition condition = new ProducesRequestCondition("!text/plain");
|
||||
|
||||
assertNull(condition.getMatchingCondition(exchange));
|
||||
@@ -63,7 +63,7 @@ public class ProducesRequestConditionTests {
|
||||
|
||||
@Test
|
||||
public void matchWildcard() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("Accept", "text/plain").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("Accept", "text/plain"));
|
||||
ProducesRequestCondition condition = new ProducesRequestCondition("text/*");
|
||||
|
||||
assertNotNull(condition.getMatchingCondition(exchange));
|
||||
@@ -71,7 +71,7 @@ public class ProducesRequestConditionTests {
|
||||
|
||||
@Test
|
||||
public void matchMultiple() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("Accept", "text/plain").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("Accept", "text/plain"));
|
||||
ProducesRequestCondition condition = new ProducesRequestCondition("text/plain", "application/xml");
|
||||
|
||||
assertNotNull(condition.getMatchingCondition(exchange));
|
||||
@@ -79,7 +79,7 @@ public class ProducesRequestConditionTests {
|
||||
|
||||
@Test
|
||||
public void matchSingle() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("Accept", "application/xml").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("Accept", "application/xml"));
|
||||
ProducesRequestCondition condition = new ProducesRequestCondition("text/plain");
|
||||
|
||||
assertNull(condition.getMatchingCondition(exchange));
|
||||
@@ -87,7 +87,7 @@ public class ProducesRequestConditionTests {
|
||||
|
||||
@Test
|
||||
public void matchParseError() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("Accept", "bogus").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("Accept", "bogus"));
|
||||
ProducesRequestCondition condition = new ProducesRequestCondition("text/plain");
|
||||
|
||||
assertNull(condition.getMatchingCondition(exchange));
|
||||
@@ -95,7 +95,7 @@ public class ProducesRequestConditionTests {
|
||||
|
||||
@Test
|
||||
public void matchParseErrorWithNegation() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("Accept", "bogus").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("Accept", "bogus"));
|
||||
ProducesRequestCondition condition = new ProducesRequestCondition("!text/plain");
|
||||
|
||||
assertNull(condition.getMatchingCondition(exchange));
|
||||
@@ -107,7 +107,7 @@ public class ProducesRequestConditionTests {
|
||||
ProducesRequestCondition xml = new ProducesRequestCondition("application/xml");
|
||||
ProducesRequestCondition none = new ProducesRequestCondition();
|
||||
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("Accept", "application/xml, text/html").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("Accept", "application/xml, text/html"));
|
||||
|
||||
assertTrue(html.compareTo(xml, exchange) > 0);
|
||||
assertTrue(xml.compareTo(html, exchange) < 0);
|
||||
@@ -117,20 +117,20 @@ public class ProducesRequestConditionTests {
|
||||
assertTrue(none.compareTo(html, exchange) > 0);
|
||||
|
||||
exchange = MockServerWebExchange.from(
|
||||
MockServerHttpRequest.get("/").header("Accept", "application/xml, text/*").build());
|
||||
MockServerHttpRequest.get("/").header("Accept", "application/xml, text/*"));
|
||||
|
||||
assertTrue(html.compareTo(xml, exchange) > 0);
|
||||
assertTrue(xml.compareTo(html, exchange) < 0);
|
||||
|
||||
exchange = MockServerWebExchange.from(
|
||||
MockServerHttpRequest.get("/").header("Accept", "application/pdf").build());
|
||||
MockServerHttpRequest.get("/").header("Accept", "application/pdf"));
|
||||
|
||||
assertTrue(html.compareTo(xml, exchange) == 0);
|
||||
assertTrue(xml.compareTo(html, exchange) == 0);
|
||||
|
||||
// See SPR-7000
|
||||
exchange = MockServerWebExchange.from(
|
||||
MockServerHttpRequest.get("/").header("Accept", "text/html;q=0.9,application/xml").build());
|
||||
MockServerHttpRequest.get("/").header("Accept", "text/html;q=0.9,application/xml"));
|
||||
|
||||
assertTrue(html.compareTo(xml, exchange) > 0);
|
||||
assertTrue(xml.compareTo(html, exchange) < 0);
|
||||
@@ -138,7 +138,7 @@ public class ProducesRequestConditionTests {
|
||||
|
||||
@Test
|
||||
public void compareToWithSingleExpression() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("Accept", "text/plain").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("Accept", "text/plain"));
|
||||
|
||||
ProducesRequestCondition condition1 = new ProducesRequestCondition("text/plain");
|
||||
ProducesRequestCondition condition2 = new ProducesRequestCondition("text/*");
|
||||
@@ -155,7 +155,7 @@ public class ProducesRequestConditionTests {
|
||||
ProducesRequestCondition condition1 = new ProducesRequestCondition("*/*", "text/plain");
|
||||
ProducesRequestCondition condition2 = new ProducesRequestCondition("text/*", "text/plain;q=0.7");
|
||||
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("Accept", "text/plain").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("Accept", "text/plain"));
|
||||
|
||||
int result = condition1.compareTo(condition2, exchange);
|
||||
assertTrue("Invalid comparison result: " + result, result < 0);
|
||||
@@ -170,7 +170,7 @@ public class ProducesRequestConditionTests {
|
||||
ProducesRequestCondition condition2 = new ProducesRequestCondition("application/*", "application/xml");
|
||||
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(
|
||||
get("/").header("Accept", "text/plain", "application/xml").build());
|
||||
get("/").header("Accept", "text/plain", "application/xml"));
|
||||
|
||||
int result = condition1.compareTo(condition2, exchange);
|
||||
assertTrue("Invalid comparison result: " + result, result < 0);
|
||||
@@ -179,7 +179,7 @@ public class ProducesRequestConditionTests {
|
||||
assertTrue("Invalid comparison result: " + result, result > 0);
|
||||
|
||||
exchange = MockServerWebExchange.from(
|
||||
MockServerHttpRequest.get("/").header("Accept", "application/xml", "text/plain").build());
|
||||
MockServerHttpRequest.get("/").header("Accept", "application/xml", "text/plain"));
|
||||
|
||||
result = condition1.compareTo(condition2, exchange);
|
||||
assertTrue("Invalid comparison result: " + result, result > 0);
|
||||
@@ -192,7 +192,7 @@ public class ProducesRequestConditionTests {
|
||||
|
||||
@Test
|
||||
public void compareToMediaTypeAll() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||
|
||||
ProducesRequestCondition condition1 = new ProducesRequestCondition();
|
||||
ProducesRequestCondition condition2 = new ProducesRequestCondition("application/json");
|
||||
@@ -209,7 +209,7 @@ public class ProducesRequestConditionTests {
|
||||
assertTrue(condition2.compareTo(condition1, exchange) > 0);
|
||||
|
||||
exchange = MockServerWebExchange.from(
|
||||
MockServerHttpRequest.get("/").header("Accept", "*/*").build());
|
||||
MockServerHttpRequest.get("/").header("Accept", "*/*"));
|
||||
|
||||
condition1 = new ProducesRequestCondition();
|
||||
condition2 = new ProducesRequestCondition("application/json");
|
||||
@@ -228,7 +228,7 @@ public class ProducesRequestConditionTests {
|
||||
|
||||
@Test
|
||||
public void compareToMediaTypeAllWithParameter() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("Accept", "*/*;q=0.9").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("Accept", "*/*;q=0.9"));
|
||||
|
||||
ProducesRequestCondition condition1 = new ProducesRequestCondition();
|
||||
ProducesRequestCondition condition2 = new ProducesRequestCondition("application/json");
|
||||
@@ -239,7 +239,7 @@ public class ProducesRequestConditionTests {
|
||||
|
||||
@Test
|
||||
public void compareToEqualMatch() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("Accept", "text/*").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("Accept", "text/*"));
|
||||
|
||||
ProducesRequestCondition condition1 = new ProducesRequestCondition("text/plain");
|
||||
ProducesRequestCondition condition2 = new ProducesRequestCondition("text/xhtml");
|
||||
@@ -280,7 +280,7 @@ public class ProducesRequestConditionTests {
|
||||
|
||||
@Test
|
||||
public void getMatchingCondition() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("Accept", "text/plain").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("Accept", "text/plain"));
|
||||
|
||||
ProducesRequestCondition condition = new ProducesRequestCondition("text/plain", "application/xml");
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ import static org.junit.Assert.assertSame;
|
||||
*/
|
||||
public class RequestConditionHolderTests {
|
||||
|
||||
private final MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||
private final MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||
|
||||
|
||||
@Test
|
||||
|
||||
@@ -87,7 +87,7 @@ public class RequestMappingInfoTests {
|
||||
|
||||
@Test
|
||||
public void matchPatternsCondition() {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/foo").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/foo"));
|
||||
|
||||
RequestMappingInfo info = paths("/foo*", "/bar").build();
|
||||
RequestMappingInfo expected = paths("/foo*").build();
|
||||
@@ -102,8 +102,7 @@ public class RequestMappingInfoTests {
|
||||
|
||||
@Test
|
||||
public void matchParamsCondition() {
|
||||
MockServerHttpRequest request = MockServerHttpRequest.get("/foo?foo=bar").build();
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/foo?foo=bar"));
|
||||
|
||||
RequestMappingInfo info = paths("/foo").params("foo=bar").build();
|
||||
RequestMappingInfo match = info.getMatchingCondition(exchange);
|
||||
@@ -166,8 +165,7 @@ public class RequestMappingInfoTests {
|
||||
|
||||
@Test
|
||||
public void matchCustomCondition() {
|
||||
MockServerHttpRequest request = MockServerHttpRequest.get("/foo?foo=bar").build();
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/foo?foo=bar"));
|
||||
|
||||
RequestMappingInfo info = paths("/foo").params("foo=bar").build();
|
||||
RequestMappingInfo match = info.getMatchingCondition(exchange);
|
||||
@@ -188,7 +186,7 @@ public class RequestMappingInfoTests {
|
||||
RequestMappingInfo oneMethod = paths().methods(RequestMethod.GET).build();
|
||||
RequestMappingInfo oneMethodOneParam = paths().methods(RequestMethod.GET).params("foo").build();
|
||||
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/foo").build());
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/foo"));
|
||||
Comparator<RequestMappingInfo> comparator = (info, otherInfo) -> info.compareTo(otherInfo, exchange);
|
||||
|
||||
List<RequestMappingInfo> list = asList(none, oneMethod, oneMethodOneParam);
|
||||
@@ -287,7 +285,7 @@ public class RequestMappingInfoTests {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.options("/foo")
|
||||
.header("Origin", "http://domain.com")
|
||||
.header(HttpHeaders.ACCESS_CONTROL_REQUEST_HEADERS, "POST")
|
||||
.build());
|
||||
);
|
||||
|
||||
RequestMappingInfo info = paths("/foo").methods(RequestMethod.POST).build();
|
||||
RequestMappingInfo match = info.getMatchingCondition(exchange);
|
||||
|
||||
@@ -139,7 +139,7 @@ public class RequestMethodsRequestConditionTests {
|
||||
}
|
||||
|
||||
private ServerWebExchange getExchange(String method) throws URISyntaxException {
|
||||
return MockServerWebExchange.from(MockServerHttpRequest.method(HttpMethod.valueOf(method), "/").build());
|
||||
return MockServerWebExchange.from(MockServerHttpRequest.method(HttpMethod.valueOf(method), "/"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ public class HandlerMethodMappingTests {
|
||||
public void directMatch() throws Exception {
|
||||
String key = "foo";
|
||||
this.mapping.registerMapping(key, this.handler, this.method1);
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get(key).build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get(key));
|
||||
Mono<Object> result = this.mapping.getHandler(exchange);
|
||||
|
||||
assertEquals(this.method1, ((HandlerMethod) result.block()).getMethod());
|
||||
@@ -86,7 +86,7 @@ public class HandlerMethodMappingTests {
|
||||
this.mapping.registerMapping("/fo*", this.handler, this.method1);
|
||||
this.mapping.registerMapping("/f*", this.handler, this.method2);
|
||||
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/foo").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/foo"));
|
||||
Mono<Object> result = this.mapping.getHandler(exchange);
|
||||
assertEquals(this.method1, ((HandlerMethod) result.block()).getMethod());
|
||||
}
|
||||
@@ -95,7 +95,7 @@ public class HandlerMethodMappingTests {
|
||||
public void ambiguousMatch() throws Exception {
|
||||
this.mapping.registerMapping("/f?o", this.handler, this.method1);
|
||||
this.mapping.registerMapping("/fo?", this.handler, this.method2);
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/foo").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/foo"));
|
||||
Mono<Object> result = this.mapping.getHandler(exchange);
|
||||
|
||||
StepVerifier.create(result).expectError(IllegalStateException.class).verify();
|
||||
@@ -128,12 +128,12 @@ public class HandlerMethodMappingTests {
|
||||
public void unregisterMapping() throws Exception {
|
||||
String key = "foo";
|
||||
this.mapping.registerMapping(key, this.handler, this.method1);
|
||||
Mono<Object> result = this.mapping.getHandler(MockServerWebExchange.from(MockServerHttpRequest.get(key).build()));
|
||||
Mono<Object> result = this.mapping.getHandler(MockServerWebExchange.from(MockServerHttpRequest.get(key)));
|
||||
|
||||
assertNotNull(result.block());
|
||||
|
||||
this.mapping.unregisterMapping(key);
|
||||
result = this.mapping.getHandler(MockServerWebExchange.from(MockServerHttpRequest.get(key).build()));
|
||||
result = this.mapping.getHandler(MockServerWebExchange.from(MockServerHttpRequest.get(key)));
|
||||
|
||||
assertNull(result.block());
|
||||
assertThat(this.mapping.getMappingRegistry().getMappings().keySet(), Matchers.not(Matchers.contains(key)));
|
||||
|
||||
@@ -46,7 +46,7 @@ import static org.springframework.web.method.ResolvableMethod.*;
|
||||
public class InvocableHandlerMethodTests {
|
||||
|
||||
private final MockServerWebExchange exchange =
|
||||
MockServerWebExchange.from(MockServerHttpRequest.get("http://localhost:8080/path").build());
|
||||
MockServerWebExchange.from(MockServerHttpRequest.get("http://localhost:8080/path"));
|
||||
|
||||
|
||||
@Test
|
||||
|
||||
@@ -98,7 +98,7 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||
@Test
|
||||
public void getHandlerDirectMatch() throws Exception {
|
||||
Method expected = on(TestController.class).annot(getMapping("/foo").params()).resolveMethod();
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(get("/foo").build());
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(get("/foo"));
|
||||
HandlerMethod hm = (HandlerMethod) this.handlerMapping.getHandler(exchange).block();
|
||||
|
||||
assertEquals(expected, hm.getMethod());
|
||||
@@ -107,7 +107,7 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||
@Test
|
||||
public void getHandlerGlobMatch() throws Exception {
|
||||
Method expected = on(TestController.class).annot(requestMapping("/ba*").method(GET, HEAD)).resolveMethod();
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(get("/bar").build());
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(get("/bar"));
|
||||
HandlerMethod hm = (HandlerMethod) this.handlerMapping.getHandler(exchange).block();
|
||||
|
||||
assertEquals(expected, hm.getMethod());
|
||||
@@ -116,11 +116,11 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||
@Test
|
||||
public void getHandlerEmptyPathMatch() throws Exception {
|
||||
Method expected = on(TestController.class).annot(requestMapping("")).resolveMethod();
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(get("").build());
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(get(""));
|
||||
HandlerMethod hm = (HandlerMethod) this.handlerMapping.getHandler(exchange).block();
|
||||
assertEquals(expected, hm.getMethod());
|
||||
|
||||
exchange = MockServerWebExchange.from(get("/").build());
|
||||
exchange = MockServerWebExchange.from(get("/"));
|
||||
hm = (HandlerMethod) this.handlerMapping.getHandler(exchange).block();
|
||||
assertEquals(expected, hm.getMethod());
|
||||
}
|
||||
@@ -128,7 +128,7 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||
@Test
|
||||
public void getHandlerBestMatch() throws Exception {
|
||||
Method expected = on(TestController.class).annot(getMapping("/foo").params("p")).resolveMethod();
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(get("/foo?p=anything").build());
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(get("/foo?p=anything"));
|
||||
HandlerMethod hm = (HandlerMethod) this.handlerMapping.getHandler(exchange).block();
|
||||
|
||||
assertEquals(expected, hm.getMethod());
|
||||
@@ -136,7 +136,7 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||
|
||||
@Test
|
||||
public void getHandlerRequestMethodNotAllowed() throws Exception {
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(post("/bar").build());
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(post("/bar"));
|
||||
Mono<Object> mono = this.handlerMapping.getHandler(exchange);
|
||||
|
||||
assertError(mono, MethodNotAllowedException.class,
|
||||
@@ -145,7 +145,7 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||
|
||||
@Test // SPR-9603
|
||||
public void getHandlerRequestMethodMatchFalsePositive() throws Exception {
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(get("/users").accept(MediaType.APPLICATION_XML).build());
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(get("/users").accept(MediaType.APPLICATION_XML));
|
||||
this.handlerMapping.registerHandler(new UserController());
|
||||
Mono<Object> mono = this.handlerMapping.getHandler(exchange);
|
||||
|
||||
@@ -180,7 +180,7 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||
|
||||
@Test // SPR-12854
|
||||
public void getHandlerTestRequestParamMismatch() throws Exception {
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(get("/params").build());
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(get("/params"));
|
||||
Mono<Object> mono = this.handlerMapping.getHandler(exchange);
|
||||
assertError(mono, ServerWebInputException.class, ex -> {
|
||||
assertThat(ex.getReason(), containsString("[foo=bar]"));
|
||||
@@ -198,13 +198,13 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||
|
||||
@Test
|
||||
public void getHandlerProducibleMediaTypesAttribute() throws Exception {
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(get("/content").accept(MediaType.APPLICATION_XML).build());
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(get("/content").accept(MediaType.APPLICATION_XML));
|
||||
this.handlerMapping.getHandler(exchange).block();
|
||||
|
||||
String name = HandlerMapping.PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE;
|
||||
assertEquals(Collections.singleton(MediaType.APPLICATION_XML), exchange.getAttributes().get(name));
|
||||
|
||||
exchange = MockServerWebExchange.from(get("/content").accept(MediaType.APPLICATION_JSON).build());
|
||||
exchange = MockServerWebExchange.from(get("/content").accept(MediaType.APPLICATION_JSON));
|
||||
this.handlerMapping.getHandler(exchange).block();
|
||||
|
||||
assertNull("Negated expression shouldn't be listed as producible type",
|
||||
@@ -214,7 +214,7 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void handleMatchUriTemplateVariables() throws Exception {
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(get("/1/2").build());
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(get("/1/2"));
|
||||
|
||||
RequestMappingInfo key = paths("/{path1}/{path2}").build();
|
||||
this.handlerMapping.handleMatch(key, handlerMethod, exchange);
|
||||
@@ -231,7 +231,7 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||
public void handleMatchUriTemplateVariablesDecode() throws Exception {
|
||||
RequestMappingInfo key = paths("/{group}/{identifier}").build();
|
||||
URI url = URI.create("/group/a%2Fb");
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(method(HttpMethod.GET, url).build());
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(method(HttpMethod.GET, url));
|
||||
|
||||
this.handlerMapping.handleMatch(key, handlerMethod, exchange);
|
||||
|
||||
@@ -247,7 +247,7 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||
@Test
|
||||
public void handleMatchBestMatchingPatternAttribute() throws Exception {
|
||||
RequestMappingInfo key = paths("/{path1}/2", "/**").build();
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(get("/1/2").build());
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(get("/1/2"));
|
||||
this.handlerMapping.handleMatch(key, handlerMethod, exchange);
|
||||
|
||||
PathPattern bestMatch = (PathPattern) exchange.getAttributes().get(BEST_MATCHING_PATTERN_ATTRIBUTE);
|
||||
@@ -260,7 +260,7 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||
@Test
|
||||
public void handleMatchBestMatchingPatternAttributeNoPatternsDefined() throws Exception {
|
||||
RequestMappingInfo key = paths().build();
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(get("/1/2").build());
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(get("/1/2"));
|
||||
this.handlerMapping.handleMatch(key, handlerMethod, exchange);
|
||||
|
||||
PathPattern bestMatch = (PathPattern) exchange.getAttributes().get(BEST_MATCHING_PATTERN_ATTRIBUTE);
|
||||
@@ -272,7 +272,7 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||
MultiValueMap<String, String> matrixVariables;
|
||||
Map<String, String> uriVariables;
|
||||
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(get("/cars;colors=red,blue,green;year=2012").build());
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(get("/cars;colors=red,blue,green;year=2012"));
|
||||
handleMatch(exchange, "/{cars}");
|
||||
|
||||
matrixVariables = getMatrixVariables(exchange, "cars");
|
||||
@@ -321,7 +321,7 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||
}
|
||||
|
||||
private void testHttpOptions(String requestURI, Set<HttpMethod> allowedMethods) throws Exception {
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.options(requestURI).build());
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.options(requestURI));
|
||||
HandlerMethod handlerMethod = (HandlerMethod) this.handlerMapping.getHandler(exchange).block();
|
||||
|
||||
BindingContext bindingContext = new BindingContext();
|
||||
@@ -338,7 +338,7 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||
}
|
||||
|
||||
private void testMediaTypeNotAcceptable(String url) throws Exception {
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(get(url).accept(MediaType.APPLICATION_JSON).build());
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(get(url).accept(MediaType.APPLICATION_JSON));
|
||||
Mono<Object> mono = this.handlerMapping.getHandler(exchange);
|
||||
|
||||
assertError(mono, NotAcceptableStatusException.class, ex ->
|
||||
|
||||
@@ -54,7 +54,7 @@ import static org.mockito.Mockito.mock;
|
||||
public class ControllerAdviceTests {
|
||||
|
||||
private final MockServerWebExchange exchange =
|
||||
MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||
MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||
|
||||
|
||||
@Test
|
||||
|
||||
@@ -97,7 +97,7 @@ public class CookieValueMethodArgumentResolverTests {
|
||||
@Test
|
||||
public void resolveCookieArgument() {
|
||||
HttpCookie expected = new HttpCookie("name", "foo");
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").cookie(expected).build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").cookie(expected));
|
||||
|
||||
Mono<Object> mono = this.resolver.resolveArgument(
|
||||
this.cookieParameter, this.bindingContext, exchange);
|
||||
@@ -108,7 +108,7 @@ public class CookieValueMethodArgumentResolverTests {
|
||||
@Test
|
||||
public void resolveCookieStringArgument() {
|
||||
HttpCookie cookie = new HttpCookie("name", "foo");
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").cookie(cookie).build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").cookie(cookie));
|
||||
|
||||
Mono<Object> mono = this.resolver.resolveArgument(
|
||||
this.cookieStringParameter, this.bindingContext, exchange);
|
||||
@@ -118,7 +118,7 @@ public class CookieValueMethodArgumentResolverTests {
|
||||
|
||||
@Test
|
||||
public void resolveCookieDefaultValue() {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||
Object result = this.resolver.resolveArgument(this.cookieStringParameter, this.bindingContext, exchange).block();
|
||||
|
||||
assertTrue(result instanceof String);
|
||||
@@ -127,7 +127,7 @@ public class CookieValueMethodArgumentResolverTests {
|
||||
|
||||
@Test
|
||||
public void notFound() {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||
Mono<Object> mono = resolver.resolveArgument(this.cookieParameter, this.bindingContext, exchange);
|
||||
StepVerifier.create(mono)
|
||||
.expectNextCount(0)
|
||||
|
||||
@@ -53,7 +53,7 @@ public class ErrorsArgumentResolverTests {
|
||||
|
||||
private BindingResult bindingResult;
|
||||
|
||||
private MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.post("/path").build());
|
||||
private MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.post("/path"));
|
||||
|
||||
private final ResolvableMethod testMethod = ResolvableMethod.on(getClass()).named("handle").build();
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ public class ExpressionValueMethodArgumentResolverTests {
|
||||
|
||||
private ExpressionValueMethodArgumentResolver resolver;
|
||||
|
||||
private final MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||
private final MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||
|
||||
private MethodParameter paramSystemProperty;
|
||||
private MethodParameter paramNotSupported;
|
||||
|
||||
@@ -328,7 +328,7 @@ public class HttpEntityArgumentResolverTests {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T> HttpEntity<T> resolveValueWithEmptyBody(ResolvableType type) {
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(post("/path").build());
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(post("/path"));
|
||||
MethodParameter param = this.testMethod.arg(type);
|
||||
Mono<Object> result = this.resolver.resolveArgument(param, new BindingContext(), exchange);
|
||||
HttpEntity<String> httpEntity = (HttpEntity<String>) result.block(Duration.ofSeconds(5));
|
||||
|
||||
@@ -55,7 +55,7 @@ public class InitBinderBindingContextTests {
|
||||
|
||||
@Test
|
||||
public void createBinder() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||
BindingContext context = createBindingContext("initBinder", WebDataBinder.class);
|
||||
WebDataBinder dataBinder = context.createDataBinder(exchange, null, null);
|
||||
|
||||
@@ -68,7 +68,7 @@ public class InitBinderBindingContextTests {
|
||||
ConversionService conversionService = new DefaultFormattingConversionService();
|
||||
bindingInitializer.setConversionService(conversionService);
|
||||
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||
BindingContext context = createBindingContext("initBinder", WebDataBinder.class);
|
||||
WebDataBinder dataBinder = context.createDataBinder(exchange, null, null);
|
||||
|
||||
@@ -77,7 +77,7 @@ public class InitBinderBindingContextTests {
|
||||
|
||||
@Test
|
||||
public void createBinderWithAttrName() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||
BindingContext context = createBindingContext("initBinderWithAttributeName", WebDataBinder.class);
|
||||
WebDataBinder dataBinder = context.createDataBinder(exchange, null, "foo");
|
||||
|
||||
@@ -87,7 +87,7 @@ public class InitBinderBindingContextTests {
|
||||
|
||||
@Test
|
||||
public void createBinderWithAttrNameNoMatch() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||
BindingContext context = createBindingContext("initBinderWithAttributeName", WebDataBinder.class);
|
||||
WebDataBinder dataBinder = context.createDataBinder(exchange, null, "invalidName");
|
||||
|
||||
@@ -96,7 +96,7 @@ public class InitBinderBindingContextTests {
|
||||
|
||||
@Test
|
||||
public void createBinderNullAttrName() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||
BindingContext context = createBindingContext("initBinderWithAttributeName", WebDataBinder.class);
|
||||
WebDataBinder dataBinder = context.createDataBinder(exchange, null, null);
|
||||
|
||||
@@ -105,7 +105,7 @@ public class InitBinderBindingContextTests {
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void returnValueNotExpected() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||
BindingContext context = createBindingContext("initBinderReturnValue", WebDataBinder.class);
|
||||
context.createDataBinder(exchange, null, "invalidName");
|
||||
}
|
||||
|
||||
@@ -69,8 +69,7 @@ public class MessageWriterResultHandlerTests {
|
||||
|
||||
private final AbstractMessageWriterResultHandler resultHandler = initResultHandler();
|
||||
|
||||
private final MockServerWebExchange exchange = MockServerWebExchange.from(
|
||||
MockServerHttpRequest.get("/path").build());
|
||||
private final MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path"));
|
||||
|
||||
|
||||
private AbstractMessageWriterResultHandler initResultHandler(HttpMessageWriter<?>... writers) {
|
||||
|
||||
@@ -67,8 +67,7 @@ public class ModelInitializerTests {
|
||||
|
||||
private ModelInitializer modelInitializer;
|
||||
|
||||
private final ServerWebExchange exchange = MockServerWebExchange.from(
|
||||
MockServerHttpRequest.get("/path").build());
|
||||
private final ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path"));
|
||||
|
||||
|
||||
@Before
|
||||
|
||||
@@ -48,8 +48,7 @@ public class PathVariableMapMethodArgumentResolverTests {
|
||||
|
||||
private PathVariableMapMethodArgumentResolver resolver;
|
||||
|
||||
private final MockServerWebExchange exchange= MockServerWebExchange.from(
|
||||
MockServerHttpRequest.get("/").build());
|
||||
private final MockServerWebExchange exchange= MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||
|
||||
private MethodParameter paramMap;
|
||||
private MethodParameter paramNamedMap;
|
||||
|
||||
@@ -54,8 +54,7 @@ public class PathVariableMethodArgumentResolverTests {
|
||||
|
||||
private PathVariableMethodArgumentResolver resolver;
|
||||
|
||||
private final MockServerWebExchange exchange= MockServerWebExchange.from(
|
||||
MockServerHttpRequest.get("/").build());
|
||||
private final MockServerWebExchange exchange= MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||
|
||||
private MethodParameter paramNamedString;
|
||||
private MethodParameter paramString;
|
||||
|
||||
@@ -57,7 +57,7 @@ public class PrincipalArgumentResolverTests {
|
||||
|
||||
BindingContext context = new BindingContext();
|
||||
Principal user = () -> "Joe";
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build())
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"))
|
||||
.mutate().principal(Mono.just(user)).build();
|
||||
|
||||
MethodParameter param = this.testMethod.arg(Principal.class);
|
||||
|
||||
@@ -56,8 +56,7 @@ public class RequestAttributeMethodArgumentResolverTests {
|
||||
|
||||
private RequestAttributeMethodArgumentResolver resolver;
|
||||
|
||||
private final MockServerWebExchange exchange = MockServerWebExchange.from(
|
||||
MockServerHttpRequest.get("/").build());
|
||||
private final MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||
|
||||
private Method handleMethod;
|
||||
|
||||
|
||||
@@ -238,7 +238,7 @@ public class RequestBodyArgumentResolverTests {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T> T resolveValueWithEmptyBody(MethodParameter param) {
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.post("/path").build());
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.post("/path"));
|
||||
Mono<Object> result = this.resolver.resolveArgument(param, new BindingContext(), exchange);
|
||||
Object value = result.block(Duration.ofSeconds(5));
|
||||
|
||||
|
||||
@@ -112,7 +112,7 @@ public class RequestHeaderMethodArgumentResolverTests {
|
||||
@Test
|
||||
public void resolveStringArgument() throws Exception {
|
||||
String expected = "foo";
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("name", expected).build());
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").header("name", expected));
|
||||
|
||||
Mono<Object> mono = this.resolver.resolveArgument(
|
||||
this.paramNamedDefaultValueStringHeader, this.bindingContext, exchange);
|
||||
@@ -137,7 +137,7 @@ public class RequestHeaderMethodArgumentResolverTests {
|
||||
|
||||
@Test
|
||||
public void resolveDefaultValue() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||
Mono<Object> mono = this.resolver.resolveArgument(
|
||||
this.paramNamedDefaultValueStringHeader, this.bindingContext, exchange);
|
||||
|
||||
@@ -152,7 +152,7 @@ public class RequestHeaderMethodArgumentResolverTests {
|
||||
try {
|
||||
Mono<Object> mono = this.resolver.resolveArgument(
|
||||
this.paramSystemProperty, this.bindingContext,
|
||||
MockServerWebExchange.from(MockServerHttpRequest.get("/").build()));
|
||||
MockServerWebExchange.from(MockServerHttpRequest.get("/")));
|
||||
|
||||
Object result = mono.block();
|
||||
assertTrue(result instanceof String);
|
||||
@@ -207,7 +207,7 @@ public class RequestHeaderMethodArgumentResolverTests {
|
||||
public void notFound() throws Exception {
|
||||
Mono<Object> mono = resolver.resolveArgument(
|
||||
this.paramNamedValueStringArray, this.bindingContext,
|
||||
MockServerWebExchange.from(MockServerHttpRequest.get("/").build()));
|
||||
MockServerWebExchange.from(MockServerHttpRequest.get("/")));
|
||||
|
||||
StepVerifier.create(mono)
|
||||
.expectNextCount(0)
|
||||
|
||||
@@ -80,8 +80,7 @@ public class RequestParamMapMethodArgumentResolverTests {
|
||||
@Test
|
||||
public void resolveMapArgumentWithQueryString() throws Exception {
|
||||
MethodParameter param = this.testMethod.annot(requestParam().name("")).arg(Map.class);
|
||||
MockServerHttpRequest request = MockServerHttpRequest.get("/path?foo=bar").build();
|
||||
Object result= resolve(param, MockServerWebExchange.from(request));
|
||||
Object result= resolve(param, MockServerWebExchange.from(MockServerHttpRequest.get("/path?foo=bar")));
|
||||
assertTrue(result instanceof Map);
|
||||
assertEquals(Collections.singletonMap("foo", "bar"), result);
|
||||
}
|
||||
@@ -89,8 +88,7 @@ public class RequestParamMapMethodArgumentResolverTests {
|
||||
@Test
|
||||
public void resolveMultiValueMapArgument() throws Exception {
|
||||
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(MultiValueMap.class);
|
||||
MockServerHttpRequest request = MockServerHttpRequest.get("/path?foo=bar&foo=baz").build();
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(request);
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path?foo=bar&foo=baz"));
|
||||
Object result= resolve(param, exchange);
|
||||
|
||||
assertTrue(result instanceof MultiValueMap);
|
||||
|
||||
@@ -135,7 +135,7 @@ public class RequestParamMethodArgumentResolverTests {
|
||||
@Test
|
||||
public void resolveWithQueryString() throws Exception {
|
||||
MethodParameter param = this.testMethod.annot(requestParam().notRequired("bar")).arg(String.class);
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path?name=foo").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path?name=foo"));
|
||||
assertEquals("foo", resolve(param, exchange));
|
||||
}
|
||||
|
||||
@@ -151,13 +151,13 @@ public class RequestParamMethodArgumentResolverTests {
|
||||
@Test
|
||||
public void resolveDefaultValue() throws Exception {
|
||||
MethodParameter param = this.testMethod.annot(requestParam().notRequired("bar")).arg(String.class);
|
||||
assertEquals("bar", resolve(param, MockServerWebExchange.from(MockServerHttpRequest.get("/").build())));
|
||||
assertEquals("bar", resolve(param, MockServerWebExchange.from(MockServerHttpRequest.get("/"))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void missingRequestParam() throws Exception {
|
||||
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(String[].class);
|
||||
Mono<Object> mono = this.resolver.resolveArgument(param, this.bindContext, exchange);
|
||||
|
||||
@@ -179,12 +179,12 @@ public class RequestParamMethodArgumentResolverTests {
|
||||
@Test // SPR-8561
|
||||
public void resolveSimpleTypeParamToNull() throws Exception {
|
||||
MethodParameter param = this.testMethod.annotNotPresent(RequestParam.class).arg(String.class);
|
||||
assertNull(resolve(param, MockServerWebExchange.from(MockServerHttpRequest.get("/").build())));
|
||||
assertNull(resolve(param, MockServerWebExchange.from(MockServerHttpRequest.get("/"))));
|
||||
}
|
||||
|
||||
@Test // SPR-10180
|
||||
public void resolveEmptyValueToDefault() throws Exception {
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path?name=").build());
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path?name="));
|
||||
MethodParameter param = this.testMethod.annot(requestParam().notRequired("bar")).arg(String.class);
|
||||
Object result = resolve(param, exchange);
|
||||
assertEquals("bar", result);
|
||||
@@ -200,18 +200,18 @@ public class RequestParamMethodArgumentResolverTests {
|
||||
@Test
|
||||
public void resolveEmptyValueRequiredWithoutDefault() throws Exception {
|
||||
MethodParameter param = this.testMethod.annot(requestParam()).arg(String.class);
|
||||
MockServerHttpRequest request = MockServerHttpRequest.get("/path?name=").build();
|
||||
assertEquals("", resolve(param, MockServerWebExchange.from(request)));
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path?name="));
|
||||
assertEquals("", resolve(param, exchange));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveOptionalParamValue() throws Exception {
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||
MethodParameter param = this.testMethod.arg(forClassWithGenerics(Optional.class, Integer.class));
|
||||
Object result = resolve(param, exchange);
|
||||
assertEquals(Optional.empty(), result);
|
||||
|
||||
exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path?name=123").build());
|
||||
exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path?name=123"));
|
||||
result = resolve(param, exchange);
|
||||
|
||||
assertEquals(Optional.class, result.getClass());
|
||||
|
||||
@@ -159,7 +159,7 @@ public class ResponseEntityResultHandlerTests {
|
||||
ResponseEntity<Void> value = ResponseEntity.noContent().build();
|
||||
MethodParameter returnType = on(TestController.class).resolveReturnType(entity(Void.class));
|
||||
HandlerResult result = handlerResult(value, returnType);
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/path").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/path"));
|
||||
this.resultHandler.handleResult(exchange, result).block(Duration.ofSeconds(5));
|
||||
|
||||
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)));
|
||||
MethodParameter returnType = on(TestController.class).resolveReturnType(entity(Void.class));
|
||||
HandlerResult result = handlerResult(headers, returnType);
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/path").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/path"));
|
||||
this.resultHandler.handleResult(exchange, result).block(Duration.ofSeconds(5));
|
||||
|
||||
assertEquals(HttpStatus.OK, exchange.getResponse().getStatusCode());
|
||||
@@ -188,7 +188,7 @@ public class ResponseEntityResultHandlerTests {
|
||||
ResponseEntity<Void> value = ResponseEntity.created(location).build();
|
||||
MethodParameter returnType = on(TestController.class).resolveReturnType(entity(Void.class));
|
||||
HandlerResult result = handlerResult(value, returnType);
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/path").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/path"));
|
||||
this.resultHandler.handleResult(exchange, result).block(Duration.ofSeconds(5));
|
||||
|
||||
assertEquals(HttpStatus.CREATED, exchange.getResponse().getStatusCode());
|
||||
@@ -202,7 +202,7 @@ public class ResponseEntityResultHandlerTests {
|
||||
Object returnValue = Mono.just(notFound().build());
|
||||
MethodParameter type = on(TestController.class).resolveReturnType(Mono.class, entity(String.class));
|
||||
HandlerResult result = handlerResult(returnValue, type);
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/path").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/path"));
|
||||
this.resultHandler.handleResult(exchange, result).block(Duration.ofSeconds(5));
|
||||
|
||||
assertEquals(HttpStatus.NOT_FOUND, exchange.getResponse().getStatusCode());
|
||||
@@ -235,7 +235,7 @@ public class ResponseEntityResultHandlerTests {
|
||||
public void handleReturnValueLastModified() throws Exception {
|
||||
Instant currentTime = Instant.now().truncatedTo(ChronoUnit.SECONDS);
|
||||
Instant oneMinAgo = currentTime.minusSeconds(60);
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/path").ifModifiedSince(currentTime.toEpochMilli()).build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/path").ifModifiedSince(currentTime.toEpochMilli()));
|
||||
|
||||
ResponseEntity<String> entity = ok().lastModified(oneMinAgo.toEpochMilli()).body("body");
|
||||
MethodParameter returnType = on(TestController.class).resolveReturnType(entity(String.class));
|
||||
@@ -248,7 +248,7 @@ public class ResponseEntityResultHandlerTests {
|
||||
@Test
|
||||
public void handleReturnValueEtag() throws Exception {
|
||||
String etagValue = "\"deadb33f8badf00d\"";
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/path").ifNoneMatch(etagValue).build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/path").ifNoneMatch(etagValue));
|
||||
|
||||
ResponseEntity<String> entity = ok().eTag(etagValue).body("body");
|
||||
MethodParameter returnType = on(TestController.class).resolveReturnType(entity(String.class));
|
||||
@@ -260,7 +260,7 @@ public class ResponseEntityResultHandlerTests {
|
||||
|
||||
@Test // SPR-14559
|
||||
public void handleReturnValueEtagInvalidIfNoneMatch() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/path").ifNoneMatch("unquoted").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/path").ifNoneMatch("unquoted"));
|
||||
|
||||
ResponseEntity<String> entity = ok().eTag("\"deadb33f8badf00d\"").body("body");
|
||||
MethodParameter returnType = on(TestController.class).resolveReturnType(entity(String.class));
|
||||
@@ -281,7 +281,7 @@ public class ResponseEntityResultHandlerTests {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/path")
|
||||
.ifNoneMatch(eTag)
|
||||
.ifModifiedSince(currentTime.toEpochMilli())
|
||||
.build());
|
||||
);
|
||||
|
||||
ResponseEntity<String> entity = ok().eTag(eTag).lastModified(oneMinAgo.toEpochMilli()).body("body");
|
||||
MethodParameter returnType = on(TestController.class).resolveReturnType(entity(String.class));
|
||||
@@ -302,7 +302,7 @@ public class ResponseEntityResultHandlerTests {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/path")
|
||||
.ifNoneMatch(etag)
|
||||
.ifModifiedSince(currentTime.toEpochMilli())
|
||||
.build());
|
||||
);
|
||||
|
||||
ResponseEntity<String> entity = ok().eTag(newEtag).lastModified(oneMinAgo.toEpochMilli()).body("body");
|
||||
MethodParameter returnType = on(TestController.class).resolveReturnType(entity(String.class));
|
||||
@@ -315,7 +315,7 @@ public class ResponseEntityResultHandlerTests {
|
||||
@Test // SPR-14877
|
||||
public void handleMonoWithWildcardBodyType() throws Exception {
|
||||
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/path").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/path"));
|
||||
exchange.getAttributes().put(PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE, Collections.singleton(APPLICATION_JSON));
|
||||
|
||||
MethodParameter type = on(TestController.class).resolveReturnType(Mono.class, ResponseEntity.class);
|
||||
@@ -330,7 +330,7 @@ public class ResponseEntityResultHandlerTests {
|
||||
@Test // SPR-14877
|
||||
public void handleMonoWithWildcardBodyTypeAndNullBody() throws Exception {
|
||||
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/path").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/path"));
|
||||
exchange.getAttributes().put(PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE, Collections.singleton(APPLICATION_JSON));
|
||||
|
||||
MethodParameter returnType = on(TestController.class).resolveReturnType(Mono.class, ResponseEntity.class);
|
||||
@@ -345,7 +345,7 @@ public class ResponseEntityResultHandlerTests {
|
||||
|
||||
private void testHandle(Object returnValue, MethodParameter returnType) {
|
||||
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/path").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/path"));
|
||||
HandlerResult result = handlerResult(returnValue, returnType);
|
||||
this.resultHandler.handleResult(exchange, result).block(Duration.ofSeconds(5));
|
||||
|
||||
|
||||
@@ -52,8 +52,7 @@ public class ServerWebExchangeArgumentResolverTests {
|
||||
private final ServerWebExchangeArgumentResolver resolver =
|
||||
new ServerWebExchangeArgumentResolver(new ReactiveAdapterRegistry());
|
||||
|
||||
private final MockServerWebExchange exchange = MockServerWebExchange.from(
|
||||
MockServerHttpRequest.get("/path").build());
|
||||
private final MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path"));
|
||||
|
||||
private ResolvableMethod testMethod = ResolvableMethod.on(getClass()).named("handle").build();
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ public class AbstractViewTests {
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
this.exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||
this.exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@@ -53,8 +53,7 @@ public class HttpMessageWriterViewTests {
|
||||
|
||||
private final ModelMap model = new ExtendedModelMap();
|
||||
|
||||
private final MockServerWebExchange exchange = MockServerWebExchange.from(
|
||||
MockServerHttpRequest.get("/").build());
|
||||
private final MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||
|
||||
|
||||
@Test
|
||||
|
||||
@@ -47,8 +47,7 @@ public class RedirectViewTests {
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
this.exchange = MockServerWebExchange.from(
|
||||
MockServerHttpRequest.get("/context/path").contextPath("/context").build());
|
||||
this.exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/context/path").contextPath("/context"));
|
||||
}
|
||||
|
||||
|
||||
@@ -130,8 +129,7 @@ public class RedirectViewTests {
|
||||
public void propagateQueryParams() throws Exception {
|
||||
RedirectView view = new RedirectView("http://url.somewhere.com?foo=bar#bazz");
|
||||
view.setPropagateQuery(true);
|
||||
MockServerHttpRequest request = MockServerHttpRequest.get("http://url.somewhere.com?a=b&c=d").build();
|
||||
this.exchange = MockServerWebExchange.from(request);
|
||||
this.exchange = MockServerWebExchange.from(MockServerHttpRequest.get("http://url.somewhere.com?a=b&c=d"));
|
||||
view.render(new HashMap<>(), MediaType.TEXT_HTML, this.exchange).block();
|
||||
assertEquals(HttpStatus.SEE_OTHER, this.exchange.getResponse().getStatusCode());
|
||||
assertEquals(URI.create("http://url.somewhere.com?foo=bar&a=b&c=d#bazz"),
|
||||
|
||||
@@ -35,7 +35,7 @@ import static org.junit.Assert.assertEquals;
|
||||
public class RequestContextTests {
|
||||
|
||||
private final MockServerWebExchange exchange =
|
||||
MockServerWebExchange.from(MockServerHttpRequest.get("/foo/path").contextPath("/foo").build());
|
||||
MockServerWebExchange.from(MockServerHttpRequest.get("/foo/path").contextPath("/foo"));
|
||||
|
||||
private GenericApplicationContext applicationContext;
|
||||
|
||||
|
||||
@@ -216,15 +216,15 @@ public class ViewResolutionResultHandlerTests {
|
||||
HandlerResult result = new HandlerResult(new Object(), returnValue, returnType, this.bindingContext);
|
||||
ViewResolutionResultHandler handler = resultHandler(new TestViewResolver("account"));
|
||||
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/account").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/account"));
|
||||
handler.handleResult(exchange, result).block(Duration.ofMillis(5000));
|
||||
assertResponseBody(exchange, "account: {id=123}");
|
||||
|
||||
exchange = MockServerWebExchange.from(get("/account/").build());
|
||||
exchange = MockServerWebExchange.from(get("/account/"));
|
||||
handler.handleResult(exchange, result).block(Duration.ofMillis(5000));
|
||||
assertResponseBody(exchange, "account: {id=123}");
|
||||
|
||||
exchange = MockServerWebExchange.from(get("/account.123").build());
|
||||
exchange = MockServerWebExchange.from(get("/account.123"));
|
||||
handler.handleResult(exchange, result).block(Duration.ofMillis(5000));
|
||||
assertResponseBody(exchange, "account: {id=123}");
|
||||
}
|
||||
@@ -235,7 +235,7 @@ public class ViewResolutionResultHandlerTests {
|
||||
MethodParameter returnType = on(Handler.class).annotPresent(ModelAttribute.class).resolveReturnType(String.class);
|
||||
HandlerResult result = new HandlerResult(new Object(), returnValue, returnType, this.bindingContext);
|
||||
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/path").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/path"));
|
||||
Mono<Void> mono = resultHandler().handleResult(exchange, result);
|
||||
|
||||
StepVerifier.create(mono)
|
||||
@@ -250,7 +250,7 @@ public class ViewResolutionResultHandlerTests {
|
||||
MethodParameter returnType = on(Handler.class).resolveReturnType(TestBean.class);
|
||||
HandlerResult handlerResult = new HandlerResult(new Object(), value, returnType, this.bindingContext);
|
||||
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/account").accept(APPLICATION_JSON).build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/account").accept(APPLICATION_JSON));
|
||||
|
||||
TestView defaultView = new TestView("jsonView", APPLICATION_JSON);
|
||||
|
||||
@@ -272,7 +272,7 @@ public class ViewResolutionResultHandlerTests {
|
||||
MethodParameter returnType = on(Handler.class).resolveReturnType(TestBean.class);
|
||||
HandlerResult handlerResult = new HandlerResult(new Object(), value, returnType, this.bindingContext);
|
||||
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/account").accept(APPLICATION_JSON).build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/account").accept(APPLICATION_JSON));
|
||||
|
||||
ViewResolutionResultHandler resultHandler = resultHandler(new TestViewResolver("account"));
|
||||
Mono<Void> mono = resultHandler.handleResult(exchange, handlerResult);
|
||||
@@ -293,7 +293,7 @@ public class ViewResolutionResultHandlerTests {
|
||||
viewResolver.setApplicationContext(new StaticApplicationContext());
|
||||
ViewResolutionResultHandler resultHandler = resultHandler(viewResolver);
|
||||
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/account").accept(APPLICATION_JSON).build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get("/account").accept(APPLICATION_JSON));
|
||||
resultHandler.handleResult(exchange, handlerResult).block(Duration.ZERO);
|
||||
|
||||
MockServerHttpResponse response = exchange.getResponse();
|
||||
@@ -321,7 +321,7 @@ public class ViewResolutionResultHandlerTests {
|
||||
model.asMap().clear();
|
||||
model.addAttribute("id", "123");
|
||||
HandlerResult result = new HandlerResult(new Object(), returnValue, returnType, this.bindingContext);
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get(path).build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(get(path));
|
||||
resultHandler(resolvers).handleResult(exchange, result).block(Duration.ofSeconds(5));
|
||||
assertResponseBody(exchange, responseBody);
|
||||
return exchange;
|
||||
|
||||
@@ -48,7 +48,7 @@ public class FreeMarkerViewTests {
|
||||
|
||||
|
||||
private final MockServerWebExchange exchange =
|
||||
MockServerWebExchange.from(MockServerHttpRequest.get("/path").build());
|
||||
MockServerWebExchange.from(MockServerHttpRequest.get("/path"));
|
||||
|
||||
private GenericApplicationContext context;
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ public class JRubyScriptTemplateTests {
|
||||
|
||||
private MockServerHttpResponse renderViewWithModel(String viewUrl, Map<String, Object> model) throws Exception {
|
||||
ScriptTemplateView view = createViewWithUrl(viewUrl);
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||
view.renderInternal(model, MediaType.TEXT_HTML, exchange).block();
|
||||
return exchange.getResponse();
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ public class JythonScriptTemplateTests {
|
||||
|
||||
private MockServerHttpResponse renderViewWithModel(String viewUrl, Map<String, Object> model) throws Exception {
|
||||
ScriptTemplateView view = createViewWithUrl(viewUrl);
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||
view.renderInternal(model, MediaType.TEXT_HTML, exchange).block();
|
||||
return exchange.getResponse();
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ public class NashornScriptTemplateTests {
|
||||
|
||||
private MockServerHttpResponse renderViewWithModel(String viewUrl, Map<String, Object> model, Class<?> configuration) throws Exception {
|
||||
ScriptTemplateView view = createViewWithUrl(viewUrl, configuration);
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||
view.renderInternal(model, MediaType.TEXT_HTML, exchange).block();
|
||||
return exchange.getResponse();
|
||||
}
|
||||
|
||||
@@ -65,56 +65,56 @@ class RequestParamMethodArgumentResolverKotlinTests {
|
||||
|
||||
@Test
|
||||
fun resolveNullableRequiredWithParameter() {
|
||||
var exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path?name=123").build())
|
||||
var exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path?name=123"))
|
||||
var result = resolver.resolveArgument(nullableParamRequired, bindingContext, exchange)
|
||||
StepVerifier.create(result).expectNext("123").expectComplete().verify()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun resolveNullableRequiredWithoutParameter() {
|
||||
var exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build())
|
||||
var exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"))
|
||||
var result = resolver.resolveArgument(nullableParamRequired, bindingContext, exchange)
|
||||
StepVerifier.create(result).expectComplete().verify()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun resolveNullableNotRequiredWithParameter() {
|
||||
var exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path?name=123").build())
|
||||
var exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path?name=123"))
|
||||
var result = resolver.resolveArgument(nullableParamNotRequired, bindingContext, exchange)
|
||||
StepVerifier.create(result).expectNext("123").expectComplete().verify()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun resolveNullableNotRequiredWithoutParameter() {
|
||||
var exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build())
|
||||
var exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"))
|
||||
var result = resolver.resolveArgument(nullableParamNotRequired, bindingContext, exchange)
|
||||
StepVerifier.create(result).expectComplete().verify()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun resolveNonNullableRequiredWithParameter() {
|
||||
var exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path?name=123").build())
|
||||
var exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path?name=123"))
|
||||
var result = resolver.resolveArgument(nonNullableParamRequired, bindingContext, exchange)
|
||||
StepVerifier.create(result).expectNext("123").expectComplete().verify()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun resolveNonNullableRequiredWithoutParameter() {
|
||||
var exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build())
|
||||
var exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"))
|
||||
var result = resolver.resolveArgument(nonNullableParamRequired, bindingContext, exchange)
|
||||
StepVerifier.create(result).expectError(ServerWebInputException::class.java).verify()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun resolveNonNullableNotRequiredWithParameter() {
|
||||
var exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path?name=123").build())
|
||||
var exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path?name=123"))
|
||||
var result = resolver.resolveArgument(nonNullableParamNotRequired, bindingContext, exchange)
|
||||
StepVerifier.create(result).expectNext("123").expectComplete().verify()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun resolveNonNullableNotRequiredWithoutParameter() {
|
||||
var exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build())
|
||||
var exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"))
|
||||
var result = resolver.resolveArgument(nonNullableParamNotRequired, bindingContext, exchange)
|
||||
StepVerifier.create(result).expectComplete().verify()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user