|
10 | 10 | import org.apache.http.HttpHost; |
11 | 11 | import org.apache.http.HttpRequest; |
12 | 12 | import org.apache.http.HttpRequestInterceptor; |
13 | | -import org.apache.http.message.BasicHeader; |
14 | 13 | import org.apache.http.message.BasicHttpRequest; |
15 | 14 | import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; |
16 | 15 | import org.elasticsearch.client.RestClient; |
17 | 16 | import org.elasticsearch.client.RestClientBuilder; |
18 | 17 | import org.hamcrest.Matchers; |
| 18 | +import org.mockito.Mockito; |
19 | 19 | import org.junit.jupiter.api.Test; |
20 | 20 |
|
21 | 21 | import java.io.IOException; |
|
24 | 24 | import java.util.Collection; |
25 | 25 | import java.util.Collections; |
26 | 26 | import java.util.List; |
27 | | -import java.util.Objects; |
28 | 27 |
|
29 | 28 | import co.elastic.logstash.filters.elasticintegration.ElasticsearchRestClientBuilder.ElasticApiConfig; |
30 | 29 |
|
|
33 | 32 |
|
34 | 33 | import static org.hamcrest.MatcherAssert.assertThat; |
35 | 34 | import static org.hamcrest.Matchers.containsString; |
36 | | -import static org.hamcrest.Matchers.equalTo; |
37 | 35 | import static org.hamcrest.Matchers.is; |
38 | 36 | import static org.hamcrest.Matchers.stringContainsInOrder; |
39 | 37 | import static org.junit.jupiter.api.Assertions.assertThrows; |
@@ -67,6 +65,35 @@ public void testForCloudIdFactory() { |
67 | 65 | } |
68 | 66 | } |
69 | 67 |
|
| 68 | + @Test |
| 69 | + public void testProxyConfigSetProxy() { |
| 70 | + ElasticsearchRestClientBuilder.ProxyConfig proxyConfig = new ElasticsearchRestClientBuilder.ProxyConfig(); |
| 71 | + proxyConfig.setProxy("https://proxy.mycorp.com:9043"); |
| 72 | + |
| 73 | + // Verify the proxy is configured in the HttpAsyncClientBuilder |
| 74 | + HttpAsyncClientBuilder httpClientBuilder = Mockito.mock(HttpAsyncClientBuilder.class); |
| 75 | + proxyConfig.configureHttpClient(httpClientBuilder); |
| 76 | + |
| 77 | + // Verify setProxy was called with the correct HttpHost |
| 78 | + ArgumentCaptor<HttpHost> proxyCaptor = ArgumentCaptor.forClass(HttpHost.class); |
| 79 | + verify(httpClientBuilder).setProxy(proxyCaptor.capture()); |
| 80 | + |
| 81 | + HttpHost capturedProxy = proxyCaptor.getValue(); |
| 82 | + assertThat(capturedProxy.getHostName(), is("proxy.mycorp.com")); |
| 83 | + assertThat(capturedProxy.getPort(), is(9043)); |
| 84 | + assertThat(capturedProxy.getSchemeName(), is("https")); |
| 85 | + } |
| 86 | + |
| 87 | + @Test |
| 88 | + public void testNoProxyConfigurationDoesNotSetProxy() { |
| 89 | + ElasticsearchRestClientBuilder.ProxyConfig proxyConfig = new ElasticsearchRestClientBuilder.ProxyConfig(); |
| 90 | + HttpAsyncClientBuilder httpClientBuilder = Mockito.mock(HttpAsyncClientBuilder.class); |
| 91 | + proxyConfig.configureHttpClient(httpClientBuilder); |
| 92 | + |
| 93 | + // Verify setProxy was never called |
| 94 | + verify(httpClientBuilder, never()).setProxy(any(HttpHost.class)); |
| 95 | + } |
| 96 | + |
70 | 97 | @Test |
71 | 98 | public void testForHostsFactorySingleURL() { |
72 | 99 | final Collection<URL> inputUrls = Collections.singleton(parseURL("https://169.0.0.254:9201/mypath")); |
|
0 commit comments