From 537d6e01351189cc835ad1521e110d3ed2fb1885 Mon Sep 17 00:00:00 2001 From: Alan Zimmer <48699787+alzimmermsft@users.noreply.github.com> Date: Mon, 23 Sep 2024 16:18:52 -0400 Subject: [PATCH] Pass HttpClient into tests not using helper methods (#41990) Pass HttpClient into tests not using helper methods --- .../azure-resourcemanager-fabric/pom.xml | 2 +- .../search/documents/SearchClientBuilder.java | 3 +-- .../documents/SearchClientBuilderTests.java | 7 +++++++ ...SearchIndexingBufferedSenderUnitTests.java | 6 ++++++ .../SearchServiceSubClientTests.java | 4 ++++ .../indexes/IndexManagementTests.java | 12 ++++++----- .../indexes/IndexersManagementTests.java | 20 ++++++++++--------- .../documents/indexes/NonRestCallTests.java | 3 +++ .../SearchIndexClientBuilderTests.java | 18 ++++++++++++----- .../SearchIndexerClientBuilderTests.java | 20 +++++++++++++------ 10 files changed, 67 insertions(+), 28 deletions(-) diff --git a/sdk/fabric/azure-resourcemanager-fabric/pom.xml b/sdk/fabric/azure-resourcemanager-fabric/pom.xml index 7a77f7f6000d4..ce4f5692fb686 100644 --- a/sdk/fabric/azure-resourcemanager-fabric/pom.xml +++ b/sdk/fabric/azure-resourcemanager-fabric/pom.xml @@ -66,7 +66,7 @@ com.azure azure-core-test - 1.26.2 + 1.27.0-beta.1 test diff --git a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/SearchClientBuilder.java b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/SearchClientBuilder.java index dda9e3e24d770..c2ff43c386bd8 100644 --- a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/SearchClientBuilder.java +++ b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/SearchClientBuilder.java @@ -330,8 +330,7 @@ private HttpPipeline getHttpPipeline() { * Sets the service endpoint for the Azure AI Search instance. * * @param endpoint The URL of the Azure AI Search instance. - * @return The updated SearchClientBuilder object. - * @throws IllegalArgumentException If {@code endpoint} is null or it cannot be parsed into a valid URL. + * @return The updated SearchClientBuilder object.0ed into a valid URL. */ @Override public SearchClientBuilder endpoint(String endpoint) { diff --git a/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/SearchClientBuilderTests.java b/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/SearchClientBuilderTests.java index 5b9c5febcd4ae..14b5d91006603 100644 --- a/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/SearchClientBuilderTests.java +++ b/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/SearchClientBuilderTests.java @@ -47,6 +47,7 @@ public void buildSyncClientTest() { .credential(SEARCH_CREDENTIAL) .indexName(INDEX_NAME) .serviceVersion(API_VERSION) + .httpClient(request -> Mono.just(new MockHttpResponse(request, 200))) .buildClient(); assertNotNull(client); @@ -59,6 +60,7 @@ public void buildSyncClientUsingDefaultApiVersionTest() { .endpoint(SEARCH_ENDPOINT) .credential(SEARCH_CREDENTIAL) .indexName(INDEX_NAME) + .httpClient(request -> Mono.just(new MockHttpResponse(request, 200))) .buildClient(); assertNotNull(client); @@ -72,6 +74,7 @@ public void buildAsyncClientTest() { .credential(SEARCH_CREDENTIAL) .indexName(INDEX_NAME) .serviceVersion(API_VERSION) + .httpClient(request -> Mono.just(new MockHttpResponse(request, 200))) .buildAsyncClient(); assertNotNull(client); @@ -84,6 +87,7 @@ public void buildAsyncClientUsingDefaultApiVersionTest() { .endpoint(SEARCH_ENDPOINT) .credential(SEARCH_CREDENTIAL) .indexName(INDEX_NAME) + .httpClient(request -> Mono.just(new MockHttpResponse(request, 200))) .buildAsyncClient(); assertNotNull(client); @@ -96,6 +100,7 @@ public void whenBuildClientAndVerifyPropertiesThenSuccess() { .endpoint(SEARCH_ENDPOINT) .credential(SEARCH_CREDENTIAL) .indexName(INDEX_NAME) + .httpClient(request -> Mono.just(new MockHttpResponse(request, 200))) .buildClient(); assertEquals(SEARCH_ENDPOINT, client.getEndpoint()); @@ -105,6 +110,7 @@ public void whenBuildClientAndVerifyPropertiesThenSuccess() { .endpoint(SEARCH_ENDPOINT) .credential(SEARCH_CREDENTIAL) .indexName(INDEX_NAME) + .httpClient(request -> Mono.just(new MockHttpResponse(request, 200))) .buildAsyncClient(); assertEquals(SEARCH_ENDPOINT, asyncClient.getEndpoint()); @@ -214,6 +220,7 @@ public void bothRetryOptionsAndRetryPolicySet() { .serviceVersion(API_VERSION) .retryOptions(new RetryOptions(new ExponentialBackoffOptions())) .retryPolicy(new RetryPolicy()) + .httpClient(request -> Mono.just(new MockHttpResponse(request, 200))) .buildClient()); } } diff --git a/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/SearchIndexingBufferedSenderUnitTests.java b/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/SearchIndexingBufferedSenderUnitTests.java index 139477e519b0e..97650258d089b 100644 --- a/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/SearchIndexingBufferedSenderUnitTests.java +++ b/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/SearchIndexingBufferedSenderUnitTests.java @@ -923,6 +923,7 @@ public void batchSplitsUntilOneAndPartiallyFailsAsync() { public void operationsThrowAfterClientIsClosed( Consumer>> operation) { SearchIndexingBufferedSender> batchingClient = getSearchClientBuilder() + .httpClient(request -> Mono.just(new MockHttpResponse(request, 200))) .bufferedSender(HOTEL_DOCUMENT_TYPE) .documentKeyRetriever(HOTEL_ID_KEY_RETRIEVER) .autoFlush(false) @@ -968,6 +969,7 @@ static Stream>>> opera public void operationsThrowAfterClientIsClosedAsync( Function>, Mono> operation) { SearchIndexingBufferedAsyncSender> batchingClient = getSearchClientBuilder() + .httpClient(request -> Mono.just(new MockHttpResponse(request, 200))) .bufferedSender(HOTEL_DOCUMENT_TYPE) .documentKeyRetriever(HOTEL_ID_KEY_RETRIEVER) .autoFlush(false) @@ -999,6 +1001,7 @@ static Stream>, M @Test public void closingTwiceDoesNotThrow() { SearchIndexingBufferedSender> batchingClient = getSearchClientBuilder() + .httpClient(request -> Mono.just(new MockHttpResponse(request, 200))) .bufferedSender(HOTEL_DOCUMENT_TYPE) .documentKeyRetriever(HOTEL_ID_KEY_RETRIEVER) .autoFlush(false) @@ -1012,6 +1015,7 @@ public void closingTwiceDoesNotThrow() { @Test public void closingTwiceDoesNotThrowAsync() { SearchIndexingBufferedAsyncSender> batchingClient = getSearchClientBuilder() + .httpClient(request -> Mono.just(new MockHttpResponse(request, 200))) .bufferedSender(HOTEL_DOCUMENT_TYPE) .documentKeyRetriever(HOTEL_ID_KEY_RETRIEVER) .autoFlush(false) @@ -1453,6 +1457,7 @@ public void delayResetsAfterNo503sAsync() { public void emptyBatchIsNeverSent() { AtomicInteger requestCount = new AtomicInteger(); SearchIndexingBufferedSender> batchingClient = getSearchClientBuilder() + .httpClient(request -> Mono.just(new MockHttpResponse(request, 200))) .addPolicy((context, next) -> { requestCount.incrementAndGet(); return next.process(); @@ -1474,6 +1479,7 @@ public void emptyBatchIsNeverSent() { public void emptyBatchIsNeverSentAsync() { AtomicInteger requestCount = new AtomicInteger(); SearchIndexingBufferedAsyncSender> batchingClient = getSearchClientBuilder() + .httpClient(request -> Mono.just(new MockHttpResponse(request, 200))) .addPolicy((context, next) -> { requestCount.incrementAndGet(); return next.process(); diff --git a/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/SearchServiceSubClientTests.java b/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/SearchServiceSubClientTests.java index a45c5cdd456db..3a03d2aac7a8a 100644 --- a/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/SearchServiceSubClientTests.java +++ b/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/SearchServiceSubClientTests.java @@ -6,11 +6,13 @@ import com.azure.core.http.HttpPipeline; import com.azure.core.http.policy.FixedDelay; import com.azure.core.http.policy.RetryPolicy; +import com.azure.core.test.http.MockHttpResponse; import com.azure.search.documents.indexes.IndexesTestHelpers; import com.azure.search.documents.indexes.SearchIndexAsyncClient; import com.azure.search.documents.indexes.SearchIndexClient; import com.azure.search.documents.indexes.SearchIndexClientBuilder; import org.junit.jupiter.api.Test; +import reactor.core.publisher.Mono; import reactor.test.StepVerifier; import java.time.Duration; @@ -96,6 +98,7 @@ private SearchIndexClient getSearchIndexClient() { private SearchIndexClient getSearchIndexClient(RetryPolicy retryPolicy) { return new SearchIndexClientBuilder() + .httpClient(request -> Mono.just(new MockHttpResponse(request, 200))) .endpoint("https://test1.search.windows.net") .credential(new AzureKeyCredential("api-key")) .retryPolicy(retryPolicy) @@ -104,6 +107,7 @@ private SearchIndexClient getSearchIndexClient(RetryPolicy retryPolicy) { private SearchIndexAsyncClient getSearchIndexAsyncClient() { return new SearchIndexClientBuilder() + .httpClient(request -> Mono.just(new MockHttpResponse(request, 200))) .endpoint("https://test1.search.windows.net") .credential(new AzureKeyCredential("api-key")) .buildAsyncClient(); diff --git a/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/indexes/IndexManagementTests.java b/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/indexes/IndexManagementTests.java index ffbd738861eaf..e213d78475ffa 100644 --- a/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/indexes/IndexManagementTests.java +++ b/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/indexes/IndexManagementTests.java @@ -67,16 +67,18 @@ public class IndexManagementTests extends SearchTestBase { @BeforeAll public static void setupSharedResources() { + sharedSynonymMap = new SynonymMap("sharedhotelmotel").setSynonyms("hotel,motel"); + + if (TEST_MODE == TestMode.PLAYBACK) { + return; + } + sharedIndexClient = new SearchIndexClientBuilder() .endpoint(ENDPOINT) .credential(TestHelpers.getTestTokenCredential()) .buildClient(); - sharedSynonymMap = new SynonymMap("sharedhotelmotel").setSynonyms("hotel,motel"); - - if (TEST_MODE != TestMode.PLAYBACK) { - sharedSynonymMap = sharedIndexClient.createSynonymMap(sharedSynonymMap); - } + sharedSynonymMap = sharedIndexClient.createSynonymMap(sharedSynonymMap); } @AfterAll diff --git a/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/indexes/IndexersManagementTests.java b/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/indexes/IndexersManagementTests.java index 7172edb8f1216..b410564f9a17b 100644 --- a/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/indexes/IndexersManagementTests.java +++ b/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/indexes/IndexersManagementTests.java @@ -121,6 +121,14 @@ private void createAndValidateIndexerAsync(SearchIndexer indexer) { @BeforeAll public static void setupSharedResources() { + sharedSkillset = createSkillsetObject(); + sharedDatasource = createSharedDataSource(); + sharedIndex = createTestIndexForLiveDatasource(); + + if (TEST_MODE == TestMode.PLAYBACK) { + return; + } + sharedIndexerClient = new SearchIndexerClientBuilder() .endpoint(ENDPOINT) .credential(TestHelpers.getTestTokenCredential()) @@ -130,15 +138,9 @@ public static void setupSharedResources() { .credential(TestHelpers.getTestTokenCredential()) .buildClient(); - sharedSkillset = createSkillsetObject(); - sharedDatasource = createSharedDataSource(); - sharedIndex = createTestIndexForLiveDatasource(); - - if (TEST_MODE != TestMode.PLAYBACK) { - sharedSkillset = sharedIndexerClient.createSkillset(sharedSkillset); - sharedDatasource = sharedIndexerClient.createOrUpdateDataSourceConnection(sharedDatasource); - sharedIndex = sharedIndexClient.createIndex(sharedIndex); - } + sharedSkillset = sharedIndexerClient.createSkillset(sharedSkillset); + sharedDatasource = sharedIndexerClient.createOrUpdateDataSourceConnection(sharedDatasource); + sharedIndex = sharedIndexClient.createIndex(sharedIndex); } @AfterAll diff --git a/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/indexes/NonRestCallTests.java b/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/indexes/NonRestCallTests.java index 089bf8464bc7f..3e5b2d73cd74d 100644 --- a/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/indexes/NonRestCallTests.java +++ b/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/indexes/NonRestCallTests.java @@ -4,11 +4,13 @@ package com.azure.search.documents.indexes; import com.azure.core.credential.AzureKeyCredential; +import com.azure.core.test.http.MockHttpResponse; import org.junit.jupiter.api.parallel.Execution; import org.junit.jupiter.api.parallel.ExecutionMode; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; import org.reactivestreams.Publisher; +import reactor.core.publisher.Mono; import reactor.test.StepVerifier; import java.util.stream.Stream; @@ -26,6 +28,7 @@ public void apiCallReturnsError(Publisher apiCall) { static Stream> apiCallReturnsErrorSupplier() { SearchIndexerAsyncClient client = new SearchIndexerClientBuilder() + .httpClient(request -> Mono.just(new MockHttpResponse(request, 200))) .endpoint("https://fake.com") .credential(new AzureKeyCredential("fake")) .buildAsyncClient(); diff --git a/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/indexes/SearchIndexClientBuilderTests.java b/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/indexes/SearchIndexClientBuilderTests.java index b3c0cfc16f6eb..940261c6761c1 100644 --- a/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/indexes/SearchIndexClientBuilderTests.java +++ b/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/indexes/SearchIndexClientBuilderTests.java @@ -5,6 +5,7 @@ import com.azure.core.credential.AzureKeyCredential; import com.azure.core.exception.HttpResponseException; import com.azure.core.http.HttpClient; +import com.azure.core.http.HttpHeaderName; import com.azure.core.http.HttpHeaders; import com.azure.core.http.HttpMethod; import com.azure.core.http.HttpRequest; @@ -49,6 +50,7 @@ public class SearchIndexClientBuilderTests { @Test public void buildSyncClientTest() { SearchIndexClient client = new SearchIndexClientBuilder() + .httpClient(request -> Mono.just(new MockHttpResponse(request, 200))) .endpoint(searchEndpoint) .credential(searchApiKeyCredential) .serviceVersion(apiVersion) @@ -61,6 +63,7 @@ public void buildSyncClientTest() { @Test public void buildSyncClientUsingDefaultApiVersionTest() { SearchIndexClient client = new SearchIndexClientBuilder() + .httpClient(request -> Mono.just(new MockHttpResponse(request, 200))) .endpoint(searchEndpoint) .credential(searchApiKeyCredential) .buildClient(); @@ -72,6 +75,7 @@ public void buildSyncClientUsingDefaultApiVersionTest() { @Test public void buildAsyncClientTest() { SearchIndexAsyncClient client = new SearchIndexClientBuilder() + .httpClient(request -> Mono.just(new MockHttpResponse(request, 200))) .endpoint(searchEndpoint) .credential(searchApiKeyCredential) .serviceVersion(apiVersion) @@ -84,6 +88,7 @@ public void buildAsyncClientTest() { @Test public void buildAsyncClientUsingDefaultApiVersionTest() { SearchIndexAsyncClient client = new SearchIndexClientBuilder() + .httpClient(request -> Mono.just(new MockHttpResponse(request, 200))) .endpoint(searchEndpoint) .credential(searchApiKeyCredential) .buildAsyncClient(); @@ -95,6 +100,7 @@ public void buildAsyncClientUsingDefaultApiVersionTest() { @Test public void whenBuildClientAndVerifyPropertiesThenSuccess() { SearchIndexClient client = new SearchIndexClientBuilder() + .httpClient(request -> Mono.just(new MockHttpResponse(request, 200))) .endpoint(searchEndpoint) .credential(searchApiKeyCredential) .buildClient(); @@ -102,6 +108,7 @@ public void whenBuildClientAndVerifyPropertiesThenSuccess() { assertEquals(searchEndpoint, client.getEndpoint()); SearchIndexAsyncClient asyncClient = new SearchIndexClientBuilder() + .httpClient(request -> Mono.just(new MockHttpResponse(request, 200))) .endpoint(searchEndpoint) .credential(searchApiKeyCredential) .serviceVersion(apiVersion) @@ -141,7 +148,7 @@ public void serviceClientFreshDateOnRetry() throws MalformedURLException { public static HttpRequest request(String url) throws MalformedURLException { return new HttpRequest(HttpMethod.HEAD, - new URL(url), new HttpHeaders().set("Content-Length", "0"), + new URL(url), new HttpHeaders().set(HttpHeaderName.CONTENT_LENGTH, "0"), Flux.empty()); } @@ -151,11 +158,11 @@ public static final class FreshDateTestClient implements HttpClient { @Override public Mono send(HttpRequest request) { if (firstDate == null) { - firstDate = convertToDateObject(request.getHeaders().getValue("Date")); + firstDate = convertToDateObject(request.getHeaders().getValue(HttpHeaderName.DATE)); return Mono.error(new IOException("IOException!")); } - assert !firstDate.equals(convertToDateObject(request.getHeaders().getValue("Date"))); + assert !firstDate.equals(convertToDateObject(request.getHeaders().getValue(HttpHeaderName.DATE))); return Mono.just(new MockHttpResponse(request, 200)); } @@ -195,7 +202,7 @@ public void applicationIdFallsBackToLogOptions() { .httpLogOptions(new HttpLogOptions().setApplicationId("anOldApplication")) .retryPolicy(new RetryPolicy(new FixedDelay(3, Duration.ofMillis(1)))) .httpClient(httpRequest -> { - assertTrue(httpRequest.getHeaders().getValue("User-Agent").contains("anOldApplication")); + assertTrue(httpRequest.getHeaders().getValue(HttpHeaderName.USER_AGENT).contains("anOldApplication")); return Mono.just(new MockHttpResponse(httpRequest, 400)); }) .buildClient(); @@ -212,7 +219,7 @@ public void clientOptionHeadersAreAddedLast() { .setHeaders(Collections.singletonList(new Header("User-Agent", "custom")))) .retryPolicy(new RetryPolicy(new FixedDelay(3, Duration.ofMillis(1)))) .httpClient(httpRequest -> { - assertEquals("custom", httpRequest.getHeaders().getValue("User-Agent")); + assertEquals("custom", httpRequest.getHeaders().getValue(HttpHeaderName.USER_AGENT)); return Mono.just(new MockHttpResponse(httpRequest, 400)); }) .buildClient(); @@ -223,6 +230,7 @@ public void clientOptionHeadersAreAddedLast() { @Test public void bothRetryOptionsAndRetryPolicySet() { assertThrows(IllegalStateException.class, () -> new SearchIndexClientBuilder() + .httpClient(request -> Mono.just(new MockHttpResponse(request, 200))) .endpoint(searchEndpoint) .credential(searchApiKeyCredential) .serviceVersion(apiVersion) diff --git a/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/indexes/SearchIndexerClientBuilderTests.java b/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/indexes/SearchIndexerClientBuilderTests.java index 1552fbe5e00ba..722ca13d5d6f9 100644 --- a/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/indexes/SearchIndexerClientBuilderTests.java +++ b/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/indexes/SearchIndexerClientBuilderTests.java @@ -5,6 +5,7 @@ import com.azure.core.credential.AzureKeyCredential; import com.azure.core.exception.HttpResponseException; import com.azure.core.http.HttpClient; +import com.azure.core.http.HttpHeaderName; import com.azure.core.http.HttpHeaders; import com.azure.core.http.HttpMethod; import com.azure.core.http.HttpRequest; @@ -49,6 +50,7 @@ public class SearchIndexerClientBuilderTests { @Test public void buildSyncClientTest() { SearchIndexerClient client = new SearchIndexerClientBuilder() + .httpClient(request -> Mono.just(new MockHttpResponse(request, 200))) .endpoint(searchEndpoint) .credential(searchApiKeyCredential) .serviceVersion(apiVersion) @@ -61,6 +63,7 @@ public void buildSyncClientTest() { @Test public void buildSyncClientUsingDefaultApiVersionTest() { SearchIndexerClient client = new SearchIndexerClientBuilder() + .httpClient(request -> Mono.just(new MockHttpResponse(request, 200))) .endpoint(searchEndpoint) .credential(searchApiKeyCredential) .buildClient(); @@ -72,6 +75,7 @@ public void buildSyncClientUsingDefaultApiVersionTest() { @Test public void buildAsyncClientTest() { SearchIndexerAsyncClient client = new SearchIndexerClientBuilder() + .httpClient(request -> Mono.just(new MockHttpResponse(request, 200))) .endpoint(searchEndpoint) .credential(searchApiKeyCredential) .serviceVersion(apiVersion) @@ -84,6 +88,7 @@ public void buildAsyncClientTest() { @Test public void buildAsyncClientUsingDefaultApiVersionTest() { SearchIndexerAsyncClient client = new SearchIndexerClientBuilder() + .httpClient(request -> Mono.just(new MockHttpResponse(request, 200))) .endpoint(searchEndpoint) .credential(searchApiKeyCredential) .buildAsyncClient(); @@ -95,6 +100,7 @@ public void buildAsyncClientUsingDefaultApiVersionTest() { @Test public void whenBuildClientAndVerifyPropertiesThenSuccess() { SearchIndexerClient client = new SearchIndexerClientBuilder() + .httpClient(request -> Mono.just(new MockHttpResponse(request, 200))) .endpoint(searchEndpoint) .credential(searchApiKeyCredential) .buildClient(); @@ -102,6 +108,7 @@ public void whenBuildClientAndVerifyPropertiesThenSuccess() { assertEquals(searchEndpoint, client.getEndpoint()); SearchIndexerAsyncClient asyncClient = new SearchIndexerClientBuilder() + .httpClient(request -> Mono.just(new MockHttpResponse(request, 200))) .endpoint(searchEndpoint) .credential(searchApiKeyCredential) .serviceVersion(apiVersion) @@ -141,7 +148,7 @@ public void serviceClientFreshDateOnRetry() throws MalformedURLException { static HttpRequest request(String url) throws MalformedURLException { return new HttpRequest(HttpMethod.HEAD, - new URL(url), new HttpHeaders().set("Content-Length", "0"), + new URL(url), new HttpHeaders().set(HttpHeaderName.CONTENT_LENGTH, "0"), Flux.empty()); } @@ -151,11 +158,11 @@ static final class FreshDateTestClient implements HttpClient { @Override public Mono send(HttpRequest request) { if (firstDate == null) { - firstDate = convertToDateObject(request.getHeaders().getValue("Date")); + firstDate = convertToDateObject(request.getHeaders().getValue(HttpHeaderName.DATE)); return Mono.error(new IOException("IOException!")); } - assert !firstDate.equals(convertToDateObject(request.getHeaders().getValue("Date"))); + assert !firstDate.equals(convertToDateObject(request.getHeaders().getValue(HttpHeaderName.DATE))); return Mono.just(new MockHttpResponse(request, 200)); } @@ -178,7 +185,7 @@ public void clientOptionsIsPreferredOverLogOptions() { .clientOptions(new ClientOptions().setApplicationId("aNewApplication")) .retryPolicy(new RetryPolicy(new FixedDelay(3, Duration.ofMillis(1)))) .httpClient(httpRequest -> { - assertTrue(httpRequest.getHeaders().getValue("User-Agent").contains("aNewApplication")); + assertTrue(httpRequest.getHeaders().getValue(HttpHeaderName.USER_AGENT).contains("aNewApplication")); return Mono.just(new MockHttpResponse(httpRequest, 400)); }) .buildClient(); @@ -195,7 +202,7 @@ public void applicationIdFallsBackToLogOptions() { .httpLogOptions(new HttpLogOptions().setApplicationId("anOldApplication")) .retryPolicy(new RetryPolicy(new FixedDelay(3, Duration.ofMillis(1)))) .httpClient(httpRequest -> { - assertTrue(httpRequest.getHeaders().getValue("User-Agent").contains("anOldApplication")); + assertTrue(httpRequest.getHeaders().getValue(HttpHeaderName.USER_AGENT).contains("anOldApplication")); return Mono.just(new MockHttpResponse(httpRequest, 400)); }) .buildClient(); @@ -212,7 +219,7 @@ public void clientOptionHeadersAreAddedLast() { .setHeaders(Collections.singletonList(new Header("User-Agent", "custom")))) .retryPolicy(new RetryPolicy(new FixedDelay(3, Duration.ofMillis(1)))) .httpClient(httpRequest -> { - assertEquals("custom", httpRequest.getHeaders().getValue("User-Agent")); + assertEquals("custom", httpRequest.getHeaders().getValue(HttpHeaderName.USER_AGENT)); return Mono.just(new MockHttpResponse(httpRequest, 400)); }) .buildClient(); @@ -223,6 +230,7 @@ public void clientOptionHeadersAreAddedLast() { @Test public void bothRetryOptionsAndRetryPolicySet() { assertThrows(IllegalStateException.class, () -> new SearchIndexerClientBuilder() + .httpClient(request -> Mono.just(new MockHttpResponse(request, 200))) .endpoint(searchEndpoint) .credential(searchApiKeyCredential) .serviceVersion(apiVersion)