Remove parameterisation from ClientRequest
This commit removes the parameterisation from ClientRequest, similarly to ServerResponse. Dropping the parameterisation facilitates a ClientRequest.from method that also copies the body of the target request. SPR-15234 Work in Progress
This commit is contained in:
@@ -37,7 +37,6 @@ import org.springframework.web.reactive.function.BodyInserter;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.http.HttpMethod.DELETE;
|
||||
@@ -51,10 +50,10 @@ public class DefaultClientRequestBuilderTests {
|
||||
|
||||
@Test
|
||||
public void from() throws Exception {
|
||||
ClientRequest<Void> other = ClientRequest.method(GET, URI.create("http://example.com"))
|
||||
ClientRequest other = ClientRequest.method(GET, URI.create("http://example.com"))
|
||||
.header("foo", "bar")
|
||||
.cookie("baz", "qux").build();
|
||||
ClientRequest<Void> result = ClientRequest.from(other).build();
|
||||
ClientRequest result = ClientRequest.from(other).build();
|
||||
assertEquals(new URI("http://example.com"), result.url());
|
||||
assertEquals(GET, result.method());
|
||||
assertEquals("bar", result.headers().getFirst("foo"));
|
||||
@@ -64,21 +63,21 @@ public class DefaultClientRequestBuilderTests {
|
||||
@Test
|
||||
public void method() throws Exception {
|
||||
URI url = new URI("http://example.com");
|
||||
ClientRequest<Void> result = ClientRequest.method(DELETE, url).build();
|
||||
ClientRequest result = ClientRequest.method(DELETE, url).build();
|
||||
assertEquals(url, result.url());
|
||||
assertEquals(DELETE, result.method());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cookie() throws Exception {
|
||||
ClientRequest<Void> result = ClientRequest.method(GET, URI.create("http://example.com"))
|
||||
ClientRequest result = ClientRequest.method(GET, URI.create("http://example.com"))
|
||||
.cookie("foo", "bar").build();
|
||||
assertEquals("bar", result.cookies().getFirst("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void build() throws Exception {
|
||||
ClientRequest<Void> result = ClientRequest.method(GET, URI.create("http://example.com"))
|
||||
ClientRequest result = ClientRequest.method(GET, URI.create("http://example.com"))
|
||||
.header("MyKey", "MyValue")
|
||||
.cookie("foo", "bar")
|
||||
.build();
|
||||
@@ -105,8 +104,8 @@ public class DefaultClientRequestBuilderTests {
|
||||
return response.writeWith(Mono.just(buffer));
|
||||
};
|
||||
|
||||
ClientRequest<String> result = ClientRequest.method(POST, URI.create("http://example.com"))
|
||||
.body(inserter);
|
||||
ClientRequest result = ClientRequest.method(POST, URI.create("http://example.com"))
|
||||
.body(inserter).build();
|
||||
|
||||
List<HttpMessageWriter<?>> messageWriters = new ArrayList<>();
|
||||
messageWriters.add(new EncoderHttpMessageWriter<>(new CharSequenceEncoder()));
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.reactive.function.client;
|
||||
|
||||
import java.util.Collections;
|
||||
@@ -42,7 +43,7 @@ public class DefaultWebClientTests {
|
||||
private ExchangeFunction exchangeFunction;
|
||||
|
||||
@Captor
|
||||
private ArgumentCaptor<ClientRequest<?>> captor;
|
||||
private ArgumentCaptor<ClientRequest> captor;
|
||||
|
||||
|
||||
@Before
|
||||
@@ -58,7 +59,7 @@ public class DefaultWebClientTests {
|
||||
WebClient client = builder().build();
|
||||
client.get().uri("/path").exchange();
|
||||
|
||||
ClientRequest<?> request = verifyExchange();
|
||||
ClientRequest request = verifyExchange();
|
||||
assertEquals("/base/path", request.url().toString());
|
||||
assertEquals(new HttpHeaders(), request.headers());
|
||||
assertEquals(Collections.emptyMap(), request.cookies());
|
||||
@@ -69,7 +70,7 @@ public class DefaultWebClientTests {
|
||||
WebClient client = builder().build();
|
||||
client.get().uri(builder -> builder.path("/path").queryParam("q", "12").build()).exchange();
|
||||
|
||||
ClientRequest<?> request = verifyExchange();
|
||||
ClientRequest request = verifyExchange();
|
||||
assertEquals("/base/path?q=12", request.url().toString());
|
||||
verifyNoMoreInteractions(this.exchangeFunction);
|
||||
}
|
||||
@@ -79,7 +80,7 @@ public class DefaultWebClientTests {
|
||||
WebClient client = builder().build();
|
||||
client.get().uri(builder -> builder.replacePath("/path").build()).exchange();
|
||||
|
||||
ClientRequest<?> request = verifyExchange();
|
||||
ClientRequest request = verifyExchange();
|
||||
assertEquals("/path", request.url().toString());
|
||||
verifyNoMoreInteractions(this.exchangeFunction);
|
||||
}
|
||||
@@ -89,7 +90,7 @@ public class DefaultWebClientTests {
|
||||
WebClient client = builder().build();
|
||||
client.get().uri("/path").accept(MediaType.APPLICATION_JSON).cookie("id", "123").exchange();
|
||||
|
||||
ClientRequest<?> request = verifyExchange();
|
||||
ClientRequest request = verifyExchange();
|
||||
assertEquals("application/json", request.headers().getFirst("Accept"));
|
||||
assertEquals("123", request.cookies().getFirst("id"));
|
||||
verifyNoMoreInteractions(this.exchangeFunction);
|
||||
@@ -100,7 +101,7 @@ public class DefaultWebClientTests {
|
||||
WebClient client = builder().defaultHeader("Accept", "application/json").defaultCookie("id", "123").build();
|
||||
client.get().uri("/path").exchange();
|
||||
|
||||
ClientRequest<?> request = verifyExchange();
|
||||
ClientRequest request = verifyExchange();
|
||||
assertEquals("application/json", request.headers().getFirst("Accept"));
|
||||
assertEquals("123", request.cookies().getFirst("id"));
|
||||
verifyNoMoreInteractions(this.exchangeFunction);
|
||||
@@ -111,7 +112,7 @@ public class DefaultWebClientTests {
|
||||
WebClient client = builder().defaultHeader("Accept", "application/json").defaultCookie("id", "123").build();
|
||||
client.get().uri("/path").header("Accept", "application/xml").cookie("id", "456").exchange();
|
||||
|
||||
ClientRequest<?> request = verifyExchange();
|
||||
ClientRequest request = verifyExchange();
|
||||
assertEquals("application/xml", request.headers().getFirst("Accept"));
|
||||
assertEquals("456", request.cookies().getFirst("id"));
|
||||
verifyNoMoreInteractions(this.exchangeFunction);
|
||||
@@ -122,8 +123,8 @@ public class DefaultWebClientTests {
|
||||
return WebClient.builder().baseUrl("/base").exchangeFunction(this.exchangeFunction);
|
||||
}
|
||||
|
||||
private ClientRequest<?> verifyExchange() {
|
||||
ClientRequest<?> request = this.captor.getValue();
|
||||
private ClientRequest verifyExchange() {
|
||||
ClientRequest request = this.captor.getValue();
|
||||
Mockito.verify(this.exchangeFunction).exchange(request);
|
||||
verifyNoMoreInteractions(this.exchangeFunction);
|
||||
return request;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -22,7 +22,6 @@ import org.junit.Test;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
@@ -37,7 +36,7 @@ public class ExchangeFilterFunctionsTests {
|
||||
|
||||
@Test
|
||||
public void andThen() throws Exception {
|
||||
ClientRequest<Void> request = ClientRequest.method(GET, URI.create("http://example.com")).build();
|
||||
ClientRequest request = ClientRequest.method(GET, URI.create("http://example.com")).build();
|
||||
ClientResponse response = mock(ClientResponse.class);
|
||||
ExchangeFunction exchange = r -> Mono.just(response);
|
||||
|
||||
@@ -67,7 +66,7 @@ public class ExchangeFilterFunctionsTests {
|
||||
|
||||
@Test
|
||||
public void apply() throws Exception {
|
||||
ClientRequest<Void> request = ClientRequest.method(GET, URI.create("http://example.com")).build();
|
||||
ClientRequest request = ClientRequest.method(GET, URI.create("http://example.com")).build();
|
||||
ClientResponse response = mock(ClientResponse.class);
|
||||
ExchangeFunction exchange = r -> Mono.just(response);
|
||||
|
||||
@@ -86,7 +85,7 @@ public class ExchangeFilterFunctionsTests {
|
||||
|
||||
@Test
|
||||
public void basicAuthentication() throws Exception {
|
||||
ClientRequest<Void> request = ClientRequest.method(GET, URI.create("http://example.com")).build();
|
||||
ClientRequest request = ClientRequest.method(GET, URI.create("http://example.com")).build();
|
||||
ClientResponse response = mock(ClientResponse.class);
|
||||
|
||||
ExchangeFunction exchange = r -> {
|
||||
|
||||
@@ -252,7 +252,7 @@ public class WebClientIntegrationTests {
|
||||
|
||||
WebClient filteredClient = this.webClient.filter(
|
||||
(request, next) -> {
|
||||
ClientRequest<?> filteredRequest = ClientRequest.from(request).header("foo", "bar").build();
|
||||
ClientRequest filteredRequest = ClientRequest.from(request).header("foo", "bar").build();
|
||||
return next.exchange(filteredRequest);
|
||||
});
|
||||
|
||||
@@ -278,7 +278,7 @@ public class WebClientIntegrationTests {
|
||||
|
||||
WebClient filteredClient = this.webClient.filter(
|
||||
(request, next) -> {
|
||||
ClientRequest<?> filteredRequest = ClientRequest.from(request).header("foo", "bar").build();
|
||||
ClientRequest filteredRequest = ClientRequest.from(request).header("foo", "bar").build();
|
||||
return next.exchange(filteredRequest);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user