Skip to content

Commit

Permalink
add matcher and LIVE mode changes
Browse files Browse the repository at this point in the history
  • Loading branch information
samvaity committed Mar 10, 2023
1 parent e6b16b2 commit 5a66a9b
Show file tree
Hide file tree
Showing 8 changed files with 465 additions and 415 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.azure.core.credential.TokenCredential;
import com.azure.core.http.HttpClient;
import com.azure.core.test.TestProxyTestBase;
import com.azure.core.test.models.CustomMatcher;
import com.azure.core.util.Configuration;
import com.azure.data.appconfiguration.implementation.ConfigurationClientCredentials;
import com.azure.data.appconfiguration.models.ConfigurationSetting;
Expand All @@ -15,6 +16,7 @@

import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;

import static com.azure.data.appconfiguration.ConfigurationClientTestBase.FAKE_CONNECTION_STRING;
import static com.azure.data.appconfiguration.TestHelper.DISPLAY_NAME_WITH_ARGUMENTS;
Expand All @@ -26,29 +28,36 @@ public class AadCredentialTest extends TestProxyTestBase {
private static ConfigurationClient client;
private static final String AZURE_APPCONFIG_CONNECTION_STRING = "AZURE_APPCONFIG_CONNECTION_STRING";
static String connectionString;
static TokenCredential tokenCredential = new DefaultAzureCredentialBuilder().build();;
static TokenCredential tokenCredential;

private void setup(HttpClient httpClient, ConfigurationServiceVersion serviceVersion)
throws InvalidKeyException, NoSuchAlgorithmException {
if (interceptorManager.isPlaybackMode()) {
connectionString = FAKE_CONNECTION_STRING;
String endpoint = new ConfigurationClientCredentials(connectionString).getBaseUri();
// In playback mode use connection string because CI environment doesn't set up to support AAD
client = new ConfigurationClientBuilder()
.credential(tokenCredential)
.connectionString(connectionString)
.endpoint(endpoint)
.httpClient(interceptorManager.getPlaybackClient())
.buildClient();
// since running in playback mode won't have the token credential, so skipping matching it.
interceptorManager.addMatchers(Arrays.asList(new CustomMatcher().setExcludedHeaders(Arrays.asList("x-ms-content-sha256"))));
} else {
connectionString = Configuration.getGlobalConfiguration().get(AZURE_APPCONFIG_CONNECTION_STRING);
tokenCredential = new DefaultAzureCredentialBuilder().build();

String endpoint = new ConfigurationClientCredentials(connectionString).getBaseUri();
client = new ConfigurationClientBuilder()
ConfigurationClientBuilder builder = new ConfigurationClientBuilder()
.httpClient(httpClient)
.credential(tokenCredential)
.endpoint(endpoint)
.addPolicy(interceptorManager.getRecordPolicy()) // Record
.serviceVersion(serviceVersion)
.buildClient();
.serviceVersion(serviceVersion);

if (interceptorManager.isRecordMode()) {
builder.addPolicy(interceptorManager.getRecordPolicy()); // Record
}
client = builder.buildClient();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import com.azure.core.http.policy.RetryPolicy;
import com.azure.core.http.rest.PagedFlux;
import com.azure.core.http.rest.Response;
import com.azure.core.test.TestMode;
import com.azure.core.test.http.AssertingHttpClientBuilder;
import com.azure.core.util.logging.ClientLogger;
import com.azure.data.appconfiguration.models.ConfigurationSetting;
Expand Down Expand Up @@ -80,7 +79,7 @@ private ConfigurationAsyncClient getConfigurationAsyncClient(HttpClient httpClie
.httpClient(buildAsyncAssertingClient(interceptorManager.isPlaybackMode() ? interceptorManager.getPlaybackClient() : httpClient))
.serviceVersion(serviceVersion)
.httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS));
if (getTestMode() != TestMode.PLAYBACK) {
if (interceptorManager.isRecordMode()) {
builder
.addPolicy(interceptorManager.getRecordPolicy())
.addPolicy(new RetryPolicy());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@

import com.azure.core.exception.HttpResponseException;
import com.azure.core.http.HttpClient;
import com.azure.core.http.HttpPipelineBuilder;
import com.azure.core.http.policy.ExponentialBackoffOptions;
import com.azure.core.http.policy.FixedDelay;
import com.azure.core.http.policy.HttpLogDetailLevel;
import com.azure.core.http.policy.HttpLogOptions;
import com.azure.core.http.policy.RetryOptions;
import com.azure.core.http.policy.RetryPolicy;
import com.azure.core.http.policy.TimeoutPolicy;
import com.azure.core.test.TestBase;
import com.azure.core.test.TestProxyTestBase;
import com.azure.core.test.annotation.DoNotRecord;
import com.azure.core.test.http.MockHttpResponse;
import com.azure.core.util.ClientOptions;
Expand All @@ -39,7 +38,7 @@
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class ConfigurationClientBuilderTest extends TestBase {
public class ConfigurationClientBuilderTest extends TestProxyTestBase {
private static final String AZURE_APPCONFIG_CONNECTION_STRING = "AZURE_APPCONFIG_CONNECTION_STRING";
private static final String DEFAULT_DOMAIN_NAME = ".azconfig.io";
private static final String NAMESPACE_NAME = "dummyNamespaceName";
Expand Down Expand Up @@ -158,7 +157,7 @@ public void nullServiceVersion(HttpClient httpClient) {
.serviceVersion(null)
.httpClient(interceptorManager.isPlaybackMode() ? interceptorManager.getPlaybackClient() : httpClient);

if (!interceptorManager.isPlaybackMode()) {
if (interceptorManager.isRecordMode()) {
clientBuilder.addPolicy(interceptorManager.getRecordPolicy());
}

Expand All @@ -179,19 +178,14 @@ public void defaultPipeline() {
.connectionString(connectionString)
.retryPolicy(new RetryPolicy())
.configuration(Configuration.getGlobalConfiguration())
.httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS))
.pipeline(new HttpPipelineBuilder().build());
.httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS));

if (!interceptorManager.isPlaybackMode()) {
if (interceptorManager.isRecordMode()) {
clientBuilder.addPolicy(interceptorManager.getRecordPolicy());

assertThrows(HttpResponseException.class,
() -> clientBuilder.buildClient().setConfigurationSetting(key, null, value));
}
HttpClient defaultHttpClient = interceptorManager.isPlaybackMode() ? interceptorManager.getPlaybackClient()
: HttpClient.createDefault();

clientBuilder.pipeline(null).httpClient(defaultHttpClient);
if (interceptorManager.isPlaybackMode()) {
clientBuilder.httpClient(interceptorManager.getPlaybackClient());
}

ConfigurationSetting addedSetting = clientBuilder.buildClient().setConfigurationSetting(key, null, value);
assertEquals(addedSetting.getKey(), key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ private ConfigurationClient getConfigurationClient(HttpClient httpClient,
return clientSetup(credentials -> {
ConfigurationClientBuilder builder = new ConfigurationClientBuilder()
.connectionString(connectionString)
.httpClient(buildSyncAssertingClient(getTestMode() == TestMode.PLAYBACK ? interceptorManager.getPlaybackClient() : httpClient))
.httpClient(buildSyncAssertingClient(interceptorManager.isPlaybackMode() ? interceptorManager.getPlaybackClient() : httpClient))
.serviceVersion(serviceVersion)
.httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS));
if (getTestMode() != TestMode.PLAYBACK) {
if (interceptorManager.isRecordMode()) {
builder
.addPolicy(interceptorManager.getRecordPolicy())
.addPolicy(new RetryPolicy());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
"Authorization": "Sanitized",
"Content-Length": "92",
"Content-Type": "application/json",
"Date": "Thu, 09 Mar 2023 22:16:58 GMT",
"Date": "Fri, 10 Mar 2023 19:16:05 GMT",
"Sync-Token": "",
"User-Agent": "azsdk-java-azure-data-appconfiguration/1.5.0-beta.1 (17.0.1; Windows 11; 10.0)",
"x-ms-client-request-id": "41194a2f-cb47-4644-be88-feb842864f29",
"User-Agent": "azsdk-java-azure-data-appconfiguration/1.5.0-beta.1 (11.0.9; Windows 10; 10.0)",
"x-ms-client-request-id": "42c45a6e-eb5e-4089-b525-5b8886fb3978",
"x-ms-return-client-request-id": "true"
},
"RequestBody": {
Expand All @@ -29,26 +29,26 @@
"Access-Control-Expose-Headers": "DNT, X-CustomHeader, Keep-Alive, User-Agent, X-Requested-With, If-Modified-Since, Cache-Control, Content-Type, Authorization, x-ms-client-request-id, x-ms-useragent, x-ms-content-sha256, x-ms-date, host, Accept, Accept-Datetime, Date, If-Match, If-None-Match, Sync-Token, x-ms-return-client-request-id, ETag, Last-Modified, Link, Memento-Datetime, retry-after-ms, x-ms-request-id, x-ms-client-session-id, x-ms-effective-locale, WWW-Authenticate, traceparent, tracestate",
"Connection": "keep-alive",
"Content-Type": "application/vnd.microsoft.appconfig.kv\u002Bjson; charset=utf-8",
"Date": "Thu, 09 Mar 2023 22:17:01 GMT",
"ETag": "\u00226bpTn97p9iW_hkcD9P8XUzTjvaowJYumF-bHTQC66j8\u0022",
"Last-Modified": "Thu, 09 Mar 2023 22:17:01 GMT",
"Date": "Fri, 10 Mar 2023 19:16:07 GMT",
"ETag": "\u0022ji0xtIpxOdKiq49RHo8Lzvlp_trw1VjKFEPXFFZRTYY\u0022",
"Last-Modified": "Fri, 10 Mar 2023 19:16:07 GMT",
"Server": "openresty/1.21.4.1",
"Strict-Transport-Security": "max-age=15724800; includeSubDomains",
"Sync-Token": "zAJw6V16=MjoyMCM0MjI4NTY0;sn=4228564",
"Sync-Token": "zAJw6V16=MjoyMCM0MjI5NjM1;sn=4229635",
"Transfer-Encoding": "chunked",
"x-ms-client-request-id": "41194a2f-cb47-4644-be88-feb842864f29",
"x-ms-correlation-request-id": "47860f36-754d-48a8-9083-1f12e2c8af9e",
"x-ms-request-id": "47860f36-754d-48a8-9083-1f12e2c8af9e"
"x-ms-client-request-id": "42c45a6e-eb5e-4089-b525-5b8886fb3978",
"x-ms-correlation-request-id": "96e6adb3-26ef-453b-bb88-850bc9295a65",
"x-ms-request-id": "96e6adb3-26ef-453b-bb88-850bc9295a65"
},
"ResponseBody": {
"etag": "6bpTn97p9iW_hkcD9P8XUzTjvaowJYumF-bHTQC66j8",
"etag": "ji0xtIpxOdKiq49RHo8Lzvlp_trw1VjKFEPXFFZRTYY",
"key": "newKey",
"label": null,
"content_type": null,
"value": "newValue",
"tags": {},
"locked": false,
"last_modified": "2023-03-09T22:17:01\u002B00:00"
"last_modified": "2023-03-10T19:16:07\u002B00:00"
}
}
],
Expand Down
Loading

0 comments on commit 5a66a9b

Please sign in to comment.