DATAES-719 - Add customization hook for reactive WebClient.
Original PR: #363
This commit is contained in:
committed by
GitHub
parent
6dfeee3ba9
commit
f7a14c1135
@@ -20,12 +20,14 @@ import static org.mockito.Mockito.*;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.time.Duration;
|
||||
import java.util.function.Function;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
|
||||
import org.apache.http.conn.ssl.NoopHostnameVerifier;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ClientConfiguration}.
|
||||
@@ -143,6 +145,26 @@ public class ClientConfigurationUnitTests {
|
||||
assertThat(clientConfiguration.getHostNameVerifier()).contains(NoopHostnameVerifier.INSTANCE);
|
||||
}
|
||||
|
||||
@Test // DATAES-719
|
||||
void shouldHaveDefaultWebClientConfigurer() {
|
||||
ClientConfiguration clientConfiguration = ClientConfiguration.builder() //
|
||||
.connectedTo("foo", "bar") //
|
||||
.build();
|
||||
|
||||
assertThat(clientConfiguration.getWebClientConfigurer()).isEqualTo(Function.identity());
|
||||
}
|
||||
|
||||
@Test // DATAES-719
|
||||
void shouldUseConfiguredWebClientConfigurer() {
|
||||
Function<WebClient, WebClient> webClientConfigurer = webClient -> webClient;
|
||||
ClientConfiguration clientConfiguration = ClientConfiguration.builder() //
|
||||
.connectedTo("foo", "bar") //
|
||||
.withWebClientConfigurer(webClientConfigurer) //
|
||||
.build();
|
||||
|
||||
assertThat(clientConfiguration.getWebClientConfigurer()).isEqualTo(webClientConfigurer);
|
||||
}
|
||||
|
||||
private static String buildBasicAuth(String username, String password) {
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
|
||||
@@ -18,12 +18,15 @@ package org.springframework.data.elasticsearch.client.reactive;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
* @author Peter-Josef Meisch
|
||||
*/
|
||||
public class DefaultWebClientProviderUnitTests {
|
||||
|
||||
@@ -40,4 +43,18 @@ public class DefaultWebClientProviderUnitTests {
|
||||
assertThat(shouldBeCachedInstanceOfClient1).isSameAs(client1);
|
||||
assertThat(notClient1ButAnotherInstance).isNotSameAs(client1);
|
||||
}
|
||||
|
||||
@Test // DATAES-719
|
||||
void shouldCallWebClientConfigurer() {
|
||||
AtomicReference<Boolean> configurerCalled = new AtomicReference<>(false);
|
||||
Function<WebClient, WebClient> configurer = webClient -> {
|
||||
configurerCalled.set(true);
|
||||
return webClient;
|
||||
};
|
||||
WebClientProvider provider = new DefaultWebClientProvider("http", null).withWebClientConfigurer(configurer);
|
||||
|
||||
provider.get(InetSocketAddress.createUnresolved("localhost", 9200));
|
||||
|
||||
assertThat(configurerCalled).hasValue(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,6 +61,7 @@ import org.springframework.web.util.UriBuilder;
|
||||
* @author Christoph Strobl
|
||||
* @author Huw Ayling-Miller
|
||||
* @author Henrique Amaral
|
||||
* @author Peter-Josef Meisch
|
||||
*/
|
||||
public class ReactiveMockClientTestsUtils {
|
||||
|
||||
@@ -276,6 +277,11 @@ public class ReactiveMockClientTestsUtils {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public WebClientProvider withWebClientConfigurer(Function<WebClient, WebClient> webClientConfigurer) {
|
||||
throw new UnsupportedOperationException("not implemented");
|
||||
}
|
||||
|
||||
public Send when(String host) {
|
||||
InetSocketAddress inetSocketAddress = getInetSocketAddress(host);
|
||||
return new CallbackImpl(get(host), headersUriSpecMap.get(inetSocketAddress),
|
||||
|
||||
Reference in New Issue
Block a user