Deprecated ClientRequest.method in favor of ClientRequest.create
The former method clashed with the ClientRequest.method() getter.
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2017 the original author or authors.
|
* Copyright 2002-2018 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -33,7 +33,7 @@ import org.springframework.web.reactive.function.client.ExchangeFunction;
|
|||||||
import org.springframework.web.reactive.function.client.ExchangeFunctions;
|
import org.springframework.web.reactive.function.client.ExchangeFunctions;
|
||||||
|
|
||||||
import static java.time.Duration.ofMillis;
|
import static java.time.Duration.ofMillis;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for {@link WiretapConnector}.
|
* Unit tests for {@link WiretapConnector}.
|
||||||
@@ -44,12 +44,12 @@ import static org.junit.Assert.assertEquals;
|
|||||||
public class WebTestClientConnectorTests {
|
public class WebTestClientConnectorTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void captureAndClaim() throws Exception {
|
public void captureAndClaim() {
|
||||||
ClientHttpRequest request = new MockClientHttpRequest(HttpMethod.GET, "/test");
|
ClientHttpRequest request = new MockClientHttpRequest(HttpMethod.GET, "/test");
|
||||||
ClientHttpResponse response = new MockClientHttpResponse(HttpStatus.OK);
|
ClientHttpResponse response = new MockClientHttpResponse(HttpStatus.OK);
|
||||||
ClientHttpConnector connector = (method, uri, fn) -> fn.apply(request).then(Mono.just(response));
|
ClientHttpConnector connector = (method, uri, fn) -> fn.apply(request).then(Mono.just(response));
|
||||||
|
|
||||||
ClientRequest clientRequest = ClientRequest.method(HttpMethod.GET, URI.create("/test"))
|
ClientRequest clientRequest = ClientRequest.create(HttpMethod.GET, URI.create("/test"))
|
||||||
.header(WebTestClient.WEBTESTCLIENT_REQUEST_ID, "1").build();
|
.header(WebTestClient.WEBTESTCLIENT_REQUEST_ID, "1").build();
|
||||||
|
|
||||||
WiretapConnector wiretapConnector = new WiretapConnector(connector);
|
WiretapConnector wiretapConnector = new WiretapConnector(connector);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2017 the original author or authors.
|
* Copyright 2002-2018 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -111,11 +111,7 @@ public interface ClientRequest {
|
|||||||
*/
|
*/
|
||||||
static Builder from(ClientRequest other) {
|
static Builder from(ClientRequest other) {
|
||||||
Assert.notNull(other, "'other' must not be null");
|
Assert.notNull(other, "'other' must not be null");
|
||||||
return new DefaultClientRequestBuilder(other.method(), other.url())
|
return new DefaultClientRequestBuilder(other);
|
||||||
.headers(headers -> headers.addAll(other.headers()))
|
|
||||||
.cookies(cookies -> cookies.addAll(other.cookies()))
|
|
||||||
.attributes(attributes -> attributes.putAll(other.attributes()))
|
|
||||||
.body(other.body());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -123,11 +119,23 @@ public interface ClientRequest {
|
|||||||
* @param method the HTTP method (GET, POST, etc)
|
* @param method the HTTP method (GET, POST, etc)
|
||||||
* @param url the URL
|
* @param url the URL
|
||||||
* @return the created builder
|
* @return the created builder
|
||||||
|
* @deprecated in favor of {@link #create(HttpMethod, URI)}
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
static Builder method(HttpMethod method, URI url) {
|
static Builder method(HttpMethod method, URI url) {
|
||||||
return new DefaultClientRequestBuilder(method, url);
|
return new DefaultClientRequestBuilder(method, url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a request builder with the given method and url.
|
||||||
|
* @param method the HTTP method (GET, POST, etc)
|
||||||
|
* @param url the URL
|
||||||
|
* @return the created builder
|
||||||
|
*/
|
||||||
|
static Builder create(HttpMethod method, URI url) {
|
||||||
|
return new DefaultClientRequestBuilder(method, url);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines a builder for a request.
|
* Defines a builder for a request.
|
||||||
@@ -235,8 +243,8 @@ public interface ClientRequest {
|
|||||||
Builder attributes(Consumer<Map<String, Object>> attributesConsumer);
|
Builder attributes(Consumer<Map<String, Object>> attributesConsumer);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds the request entity with no body.
|
* Builds the request.
|
||||||
* @return the request entity
|
* @return the request
|
||||||
*/
|
*/
|
||||||
ClientRequest build();
|
ClientRequest build();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2017 the original author or authors.
|
* Copyright 2002-2018 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -67,6 +67,14 @@ class DefaultClientRequestBuilder implements ClientRequest.Builder {
|
|||||||
this.url = url;
|
this.url = url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DefaultClientRequestBuilder(ClientRequest other) {
|
||||||
|
this(other.method(), other.url());
|
||||||
|
headers(headers -> headers.addAll(other.headers()));
|
||||||
|
cookies(cookies -> cookies.addAll(other.cookies()));
|
||||||
|
attributes(attributes -> attributes.putAll(other.attributes()));
|
||||||
|
body(other.body());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ClientRequest.Builder method(HttpMethod method) {
|
public ClientRequest.Builder method(HttpMethod method) {
|
||||||
Assert.notNull(method, "'method' must not be null");
|
Assert.notNull(method, "'method' must not be null");
|
||||||
|
|||||||
@@ -324,7 +324,7 @@ class DefaultWebClient implements WebClient {
|
|||||||
|
|
||||||
private ClientRequest.Builder initRequestBuilder() {
|
private ClientRequest.Builder initRequestBuilder() {
|
||||||
URI uri = this.uri != null ? this.uri : uriBuilderFactory.expand("");
|
URI uri = this.uri != null ? this.uri : uriBuilderFactory.expand("");
|
||||||
return ClientRequest.method(this.httpMethod, uri)
|
return ClientRequest.create(this.httpMethod, uri)
|
||||||
.headers(headers -> headers.addAll(initHeaders()))
|
.headers(headers -> headers.addAll(initHeaders()))
|
||||||
.cookies(cookies -> cookies.addAll(initCookies()))
|
.cookies(cookies -> cookies.addAll(initCookies()))
|
||||||
.attributes(attributes -> attributes.putAll(this.attributes));
|
.attributes(attributes -> attributes.putAll(this.attributes));
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2017 the original author or authors.
|
* Copyright 2002-2018 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -50,7 +50,7 @@ public class DefaultClientRequestBuilderTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void from() throws Exception {
|
public void from() throws Exception {
|
||||||
ClientRequest other = ClientRequest.method(GET, URI.create("http://example.com"))
|
ClientRequest other = ClientRequest.create(GET, URI.create("http://example.com"))
|
||||||
.header("foo", "bar")
|
.header("foo", "bar")
|
||||||
.cookie("baz", "qux").build();
|
.cookie("baz", "qux").build();
|
||||||
ClientRequest result = ClientRequest.from(other)
|
ClientRequest result = ClientRequest.from(other)
|
||||||
@@ -68,7 +68,7 @@ public class DefaultClientRequestBuilderTests {
|
|||||||
@Test
|
@Test
|
||||||
public void method() throws Exception {
|
public void method() throws Exception {
|
||||||
URI url = new URI("http://example.com");
|
URI url = new URI("http://example.com");
|
||||||
ClientRequest.Builder builder = ClientRequest.method(DELETE, url);
|
ClientRequest.Builder builder = ClientRequest.create(DELETE, url);
|
||||||
assertEquals(DELETE, builder.build().method());
|
assertEquals(DELETE, builder.build().method());
|
||||||
|
|
||||||
builder.method(OPTIONS);
|
builder.method(OPTIONS);
|
||||||
@@ -79,7 +79,7 @@ public class DefaultClientRequestBuilderTests {
|
|||||||
public void url() throws Exception {
|
public void url() throws Exception {
|
||||||
URI url1 = new URI("http://example.com/foo");
|
URI url1 = new URI("http://example.com/foo");
|
||||||
URI url2 = new URI("http://example.com/bar");
|
URI url2 = new URI("http://example.com/bar");
|
||||||
ClientRequest.Builder builder = ClientRequest.method(DELETE, url1);
|
ClientRequest.Builder builder = ClientRequest.create(DELETE, url1);
|
||||||
assertEquals(url1, builder.build().url());
|
assertEquals(url1, builder.build().url());
|
||||||
|
|
||||||
builder.url(url2);
|
builder.url(url2);
|
||||||
@@ -87,15 +87,15 @@ public class DefaultClientRequestBuilderTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void cookie() throws Exception {
|
public void cookie() {
|
||||||
ClientRequest result = ClientRequest.method(GET, URI.create("http://example.com"))
|
ClientRequest result = ClientRequest.create(GET, URI.create("http://example.com"))
|
||||||
.cookie("foo", "bar").build();
|
.cookie("foo", "bar").build();
|
||||||
assertEquals("bar", result.cookies().getFirst("foo"));
|
assertEquals("bar", result.cookies().getFirst("foo"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void build() throws Exception {
|
public void build() {
|
||||||
ClientRequest result = ClientRequest.method(GET, URI.create("http://example.com"))
|
ClientRequest result = ClientRequest.create(GET, URI.create("http://example.com"))
|
||||||
.header("MyKey", "MyValue")
|
.header("MyKey", "MyValue")
|
||||||
.cookie("foo", "bar")
|
.cookie("foo", "bar")
|
||||||
.build();
|
.build();
|
||||||
@@ -111,7 +111,7 @@ public class DefaultClientRequestBuilderTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void bodyInserter() throws Exception {
|
public void bodyInserter() {
|
||||||
String body = "foo";
|
String body = "foo";
|
||||||
BodyInserter<String, ClientHttpRequest> inserter =
|
BodyInserter<String, ClientHttpRequest> inserter =
|
||||||
(response, strategies) -> {
|
(response, strategies) -> {
|
||||||
@@ -121,7 +121,7 @@ public class DefaultClientRequestBuilderTests {
|
|||||||
return response.writeWith(Mono.just(buffer));
|
return response.writeWith(Mono.just(buffer));
|
||||||
};
|
};
|
||||||
|
|
||||||
ClientRequest result = ClientRequest.method(POST, URI.create("http://example.com"))
|
ClientRequest result = ClientRequest.create(POST, URI.create("http://example.com"))
|
||||||
.body(inserter).build();
|
.body(inserter).build();
|
||||||
|
|
||||||
List<HttpMessageWriter<?>> messageWriters = new ArrayList<>();
|
List<HttpMessageWriter<?>> messageWriters = new ArrayList<>();
|
||||||
@@ -140,10 +140,10 @@ public class DefaultClientRequestBuilderTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void bodyClass() throws Exception {
|
public void bodyClass() {
|
||||||
String body = "foo";
|
String body = "foo";
|
||||||
Publisher<String> publisher = Mono.just(body);
|
Publisher<String> publisher = Mono.just(body);
|
||||||
ClientRequest result = ClientRequest.method(POST, URI.create("http://example.com"))
|
ClientRequest result = ClientRequest.create(POST, URI.create("http://example.com"))
|
||||||
.body(publisher, String.class).build();
|
.body(publisher, String.class).build();
|
||||||
|
|
||||||
List<HttpMessageWriter<?>> messageWriters = new ArrayList<>();
|
List<HttpMessageWriter<?>> messageWriters = new ArrayList<>();
|
||||||
@@ -162,11 +162,11 @@ public class DefaultClientRequestBuilderTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void bodyParameterizedTypeReference() throws Exception {
|
public void bodyParameterizedTypeReference() {
|
||||||
String body = "foo";
|
String body = "foo";
|
||||||
Publisher<String> publisher = Mono.just(body);
|
Publisher<String> publisher = Mono.just(body);
|
||||||
ParameterizedTypeReference<String> typeReference = new ParameterizedTypeReference<String>() {};
|
ParameterizedTypeReference<String> typeReference = new ParameterizedTypeReference<String>() {};
|
||||||
ClientRequest result = ClientRequest.method(POST, URI.create("http://example.com"))
|
ClientRequest result = ClientRequest.create(POST, URI.create("http://example.com"))
|
||||||
.body(publisher, typeReference).build();
|
.body(publisher, typeReference).build();
|
||||||
|
|
||||||
List<HttpMessageWriter<?>> messageWriters = new ArrayList<>();
|
List<HttpMessageWriter<?>> messageWriters = new ArrayList<>();
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2017 the original author or authors.
|
* Copyright 2002-2018 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -36,8 +36,8 @@ import static org.springframework.web.reactive.function.client.ExchangeFilterFun
|
|||||||
public class ExchangeFilterFunctionsTests {
|
public class ExchangeFilterFunctionsTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void andThen() throws Exception {
|
public void andThen() {
|
||||||
ClientRequest request = ClientRequest.method(GET, URI.create("http://example.com")).build();
|
ClientRequest request = ClientRequest.create(GET, URI.create("http://example.com")).build();
|
||||||
ClientResponse response = mock(ClientResponse.class);
|
ClientResponse response = mock(ClientResponse.class);
|
||||||
ExchangeFunction exchange = r -> Mono.just(response);
|
ExchangeFunction exchange = r -> Mono.just(response);
|
||||||
|
|
||||||
@@ -66,8 +66,8 @@ public class ExchangeFilterFunctionsTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void apply() throws Exception {
|
public void apply() {
|
||||||
ClientRequest request = ClientRequest.method(GET, URI.create("http://example.com")).build();
|
ClientRequest request = ClientRequest.create(GET, URI.create("http://example.com")).build();
|
||||||
ClientResponse response = mock(ClientResponse.class);
|
ClientResponse response = mock(ClientResponse.class);
|
||||||
ExchangeFunction exchange = r -> Mono.just(response);
|
ExchangeFunction exchange = r -> Mono.just(response);
|
||||||
|
|
||||||
@@ -85,8 +85,8 @@ public class ExchangeFilterFunctionsTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void basicAuthenticationUsernamePassword() throws Exception {
|
public void basicAuthenticationUsernamePassword() {
|
||||||
ClientRequest request = ClientRequest.method(GET, URI.create("http://example.com")).build();
|
ClientRequest request = ClientRequest.create(GET, URI.create("http://example.com")).build();
|
||||||
ClientResponse response = mock(ClientResponse.class);
|
ClientResponse response = mock(ClientResponse.class);
|
||||||
|
|
||||||
ExchangeFunction exchange = r -> {
|
ExchangeFunction exchange = r -> {
|
||||||
@@ -102,14 +102,14 @@ public class ExchangeFilterFunctionsTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void basicAuthenticationInvalidCharacters() throws Exception {
|
public void basicAuthenticationInvalidCharacters() {
|
||||||
|
|
||||||
ExchangeFilterFunctions.basicAuthentication("foo", "\ud83d\udca9");
|
ExchangeFilterFunctions.basicAuthentication("foo", "\ud83d\udca9");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void basicAuthenticationAttributes() throws Exception {
|
public void basicAuthenticationAttributes() {
|
||||||
ClientRequest request = ClientRequest.method(GET, URI.create("http://example.com"))
|
ClientRequest request = ClientRequest.create(GET, URI.create("http://example.com"))
|
||||||
.attributes(basicAuthenticationCredentials("foo", "bar"))
|
.attributes(basicAuthenticationCredentials("foo", "bar"))
|
||||||
.build();
|
.build();
|
||||||
ClientResponse response = mock(ClientResponse.class);
|
ClientResponse response = mock(ClientResponse.class);
|
||||||
@@ -127,8 +127,8 @@ public class ExchangeFilterFunctionsTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void basicAuthenticationAbsentAttributes() throws Exception {
|
public void basicAuthenticationAbsentAttributes() {
|
||||||
ClientRequest request = ClientRequest.method(GET, URI.create("http://example.com")).build();
|
ClientRequest request = ClientRequest.create(GET, URI.create("http://example.com")).build();
|
||||||
ClientResponse response = mock(ClientResponse.class);
|
ClientResponse response = mock(ClientResponse.class);
|
||||||
|
|
||||||
ExchangeFunction exchange = r -> {
|
ExchangeFunction exchange = r -> {
|
||||||
@@ -143,8 +143,8 @@ public class ExchangeFilterFunctionsTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void statusHandlerMatch() throws Exception {
|
public void statusHandlerMatch() {
|
||||||
ClientRequest request = ClientRequest.method(GET, URI.create("http://example.com")).build();
|
ClientRequest request = ClientRequest.create(GET, URI.create("http://example.com")).build();
|
||||||
ClientResponse response = mock(ClientResponse.class);
|
ClientResponse response = mock(ClientResponse.class);
|
||||||
when(response.statusCode()).thenReturn(HttpStatus.NOT_FOUND);
|
when(response.statusCode()).thenReturn(HttpStatus.NOT_FOUND);
|
||||||
|
|
||||||
@@ -161,8 +161,8 @@ public class ExchangeFilterFunctionsTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void statusHandlerNoMatch() throws Exception {
|
public void statusHandlerNoMatch() {
|
||||||
ClientRequest request = ClientRequest.method(GET, URI.create("http://example.com")).build();
|
ClientRequest request = ClientRequest.create(GET, URI.create("http://example.com")).build();
|
||||||
ClientResponse response = mock(ClientResponse.class);
|
ClientResponse response = mock(ClientResponse.class);
|
||||||
when(response.statusCode()).thenReturn(HttpStatus.NOT_FOUND);
|
when(response.statusCode()).thenReturn(HttpStatus.NOT_FOUND);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user