diff --git a/sdk/core/azure-core-test/src/main/java/com/azure/core/test/TestProxyTestBase.java b/sdk/core/azure-core-test/src/main/java/com/azure/core/test/TestProxyTestBase.java index 0c78e22dd7cbc..fb50829f68730 100644 --- a/sdk/core/azure-core-test/src/main/java/com/azure/core/test/TestProxyTestBase.java +++ b/sdk/core/azure-core-test/src/main/java/com/azure/core/test/TestProxyTestBase.java @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + package com.azure.core.test; /** diff --git a/sdk/core/azure-core-test/src/main/java/com/azure/core/test/http/TestProxyPlaybackClient.java b/sdk/core/azure-core-test/src/main/java/com/azure/core/test/http/TestProxyPlaybackClient.java index 101d42490a3d4..a5010833d4989 100644 --- a/sdk/core/azure-core-test/src/main/java/com/azure/core/test/http/TestProxyPlaybackClient.java +++ b/sdk/core/azure-core-test/src/main/java/com/azure/core/test/http/TestProxyPlaybackClient.java @@ -41,6 +41,11 @@ public class TestProxyPlaybackClient implements HttpClient { private static final List DEFAULT_SANITIZERS = loadSanitizers(); private final List sanitizers = new ArrayList<>(); + /** + * Create an instance of {@link TestProxyPlaybackClient} with a list of custom sanitizers. + * + * @param customSanitizers the list of custom sanitizers to be added to {@link TestProxyPlaybackClient} + */ public TestProxyPlaybackClient(List customSanitizers) { this.sanitizers.addAll(DEFAULT_SANITIZERS); this.sanitizers.addAll(customSanitizers == null ? Collections.emptyList() : customSanitizers); diff --git a/sdk/core/azure-core-test/src/main/java/com/azure/core/test/http/TestProxyTestServer.java b/sdk/core/azure-core-test/src/main/java/com/azure/core/test/http/TestProxyTestServer.java index dde689e03b91a..ac542d83b9e71 100644 --- a/sdk/core/azure-core-test/src/main/java/com/azure/core/test/http/TestProxyTestServer.java +++ b/sdk/core/azure-core-test/src/main/java/com/azure/core/test/http/TestProxyTestServer.java @@ -40,12 +40,12 @@ public TestProxyTestServer() { res.addHeader(requestHeader.getKey(), requestHeader.getValue()); } return res.status(HttpResponseStatus.OK) - .addHeader("Content-Type","application/json") + .addHeader("Content-Type", "application/json") .sendString(Mono.just(TEST_JSON_RESPONSE_BODY)); }) .get("/fr/path/2", (req, res) -> res.status(HttpResponseStatus.OK) - .addHeader("Content-Type","application/json") + .addHeader("Content-Type", "application/json") .sendString(Mono.just(TEST_XML_RESPONSE_BODY)))) .bindNow(); } diff --git a/sdk/core/azure-core-test/src/main/java/com/azure/core/test/models/TestProxySanitizer.java b/sdk/core/azure-core-test/src/main/java/com/azure/core/test/models/TestProxySanitizer.java index c2e909808e586..a709974b95d1b 100644 --- a/sdk/core/azure-core-test/src/main/java/com/azure/core/test/models/TestProxySanitizer.java +++ b/sdk/core/azure-core-test/src/main/java/com/azure/core/test/models/TestProxySanitizer.java @@ -60,8 +60,8 @@ public String getGroupForReplace() { /** * Set the group for replace. * - * @param groupForReplace th value to set - * @return + * @param groupForReplace The name of the group to replace. + * @return the {@link TestProxySanitizer} itself. */ public TestProxySanitizer setGroupForReplace(String groupForReplace) { this.groupForReplace = groupForReplace; diff --git a/sdk/core/azure-core-test/src/main/java/com/azure/core/test/models/TestProxySanitizerType.java b/sdk/core/azure-core-test/src/main/java/com/azure/core/test/models/TestProxySanitizerType.java index 0b53ff642a458..cf13c434c6054 100644 --- a/sdk/core/azure-core-test/src/main/java/com/azure/core/test/models/TestProxySanitizerType.java +++ b/sdk/core/azure-core-test/src/main/java/com/azure/core/test/models/TestProxySanitizerType.java @@ -22,9 +22,17 @@ public enum TestProxySanitizerType { */ HEADER("HeaderRegexSanitizer"); - public final String name; + private final String name; TestProxySanitizerType(String name) { this.name = name; } + + /** + * Gets the name value of the enum. + * @return the name value of the enum. + */ + public String getName() { + return name; + } } diff --git a/sdk/core/azure-core-test/src/main/java/com/azure/core/test/policy/TestProxyRecordPolicy.java b/sdk/core/azure-core-test/src/main/java/com/azure/core/test/policy/TestProxyRecordPolicy.java index dd329879e5eeb..66472803ff00a 100644 --- a/sdk/core/azure-core-test/src/main/java/com/azure/core/test/policy/TestProxyRecordPolicy.java +++ b/sdk/core/azure-core-test/src/main/java/com/azure/core/test/policy/TestProxyRecordPolicy.java @@ -42,6 +42,11 @@ public class TestProxyRecordPolicy implements HttpPipelinePolicy { private final List sanitizers = new ArrayList<>(); private static final List DEFAULT_SANITIZERS = loadSanitizers(); + /** + * Create an instance of {@link TestProxyRecordPolicy} with a list of custom sanitizers. + * + * @param customSanitizers the list of custom sanitizers to be added to {@link TestProxyRecordPolicy} + */ public TestProxyRecordPolicy(List customSanitizers) { this.sanitizers.addAll(DEFAULT_SANITIZERS); this.sanitizers.addAll(customSanitizers == null ? Collections.emptyList() : customSanitizers); diff --git a/sdk/core/azure-core-test/src/main/java/com/azure/core/test/utils/HttpURLConnectionHttpClient.java b/sdk/core/azure-core-test/src/main/java/com/azure/core/test/utils/HttpURLConnectionHttpClient.java index 38e9e94aacc9c..53b5a403fd32f 100644 --- a/sdk/core/azure-core-test/src/main/java/com/azure/core/test/utils/HttpURLConnectionHttpClient.java +++ b/sdk/core/azure-core-test/src/main/java/com/azure/core/test/utils/HttpURLConnectionHttpClient.java @@ -22,6 +22,9 @@ import java.util.List; import java.util.Map; +/** + * A {@link HttpClient} that uses the JDK {@link HttpURLConnection}. + */ public class HttpURLConnectionHttpClient implements HttpClient { @Override @@ -40,7 +43,7 @@ public HttpResponse sendSync(HttpRequest request, Context context) { } catch (IOException e) { throw new RuntimeException(e); } finally { - if (connection != null ) { + if (connection != null) { connection.disconnect(); } } @@ -60,7 +63,7 @@ public Mono send(HttpRequest request) { } catch (IOException e) { throw new RuntimeException(e); } finally { - if (connection != null ) { + if (connection != null) { connection.disconnect(); } } diff --git a/sdk/core/azure-core-test/src/main/java/com/azure/core/test/utils/TestProxyDownloader.java b/sdk/core/azure-core-test/src/main/java/com/azure/core/test/utils/TestProxyDownloader.java index 9c3a7cf9595d7..08cc3a08a8afa 100644 --- a/sdk/core/azure-core-test/src/main/java/com/azure/core/test/utils/TestProxyDownloader.java +++ b/sdk/core/azure-core-test/src/main/java/com/azure/core/test/utils/TestProxyDownloader.java @@ -6,9 +6,7 @@ import com.azure.core.util.logging.ClientLogger; import com.azure.core.util.logging.LogLevel; import org.apache.commons.compress.archivers.ArchiveEntry; -import org.apache.commons.compress.archivers.ArchiveException; import org.apache.commons.compress.archivers.ArchiveInputStream; -import org.apache.commons.compress.archivers.ArchiveStreamFactory; import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream; import org.apache.commons.compress.utils.IOUtils; diff --git a/sdk/core/azure-core-test/src/main/java/com/azure/core/test/utils/TestProxyUtils.java b/sdk/core/azure-core-test/src/main/java/com/azure/core/test/utils/TestProxyUtils.java index 4ac548ab87bcd..ba57ace03c461 100644 --- a/sdk/core/azure-core-test/src/main/java/com/azure/core/test/utils/TestProxyUtils.java +++ b/sdk/core/azure-core-test/src/main/java/com/azure/core/test/utils/TestProxyUtils.java @@ -85,6 +85,10 @@ public static void changeHeaders(HttpRequest request, String xRecordingId, Strin } } + /** + * Registers the default set of sanitizers for sanitizing request and responses + * @return the list of default sanitizers to be added. + */ public static List loadSanitizers() { List sanitizers = new ArrayList<>(); sanitizers.addAll(addDefaultRegexSanitizers()); @@ -94,23 +98,30 @@ public static List loadSanitizers() { return sanitizers; } - public static String createUrlRegexRequestBody(String regexValue, String redactedValue) { + private static String createUrlRegexRequestBody(String regexValue, String redactedValue) { return String.format("{\"value\":\"%s\",\"regex\":\"%s\"}", redactedValue, regexValue); } - public static String createBodyJsonKeyRequestBody(String regexValue, String redactedValue) { + private static String createBodyJsonKeyRequestBody(String regexValue, String redactedValue) { return String.format("{\"value\":\"%s\",\"jsonPath\":\"%s\"}", redactedValue, regexValue); } - public static String createBodyRegexRequestBody(String regexValue, String redactedValue, String groupForReplace) { + private static String createBodyRegexRequestBody(String regexValue, String redactedValue, String groupForReplace) { return String.format("{\"value\":\"%s\",\"regex\":\"%s\",\"groupForReplace\":\"%s\"}", redactedValue, regexValue, groupForReplace); } - public static String createHeaderRegexRequestBody(String regexValue, String redactedValue) { + private static String createHeaderRegexRequestBody(String regexValue, String redactedValue) { return String.format("{\"value\":\"%s\",\"key\":\"%s\"}", redactedValue, regexValue); } + /** + * Creates a list of sanitizer requests to be sent to the test proxy server. + * + * @param sanitizers the list of sanitizers to be added + * @return the list of sanitizer {@link HttpRequest requests} to be sent. + * @throws RuntimeException if {@link TestProxySanitizerType} is not supported. + */ public static List getSanitizerRequests(List sanitizers) { return sanitizers.stream().map(testProxySanitizer -> { String requestBody; @@ -119,22 +130,22 @@ public static List getSanitizerRequests(List sa case URL: requestBody = createUrlRegexRequestBody(testProxySanitizer.getRegex(), testProxySanitizer.getRedactedValue()); - sanitizerType = TestProxySanitizerType.URL.name; + sanitizerType = TestProxySanitizerType.URL.getName(); break; case BODY_REGEX: requestBody = createBodyRegexRequestBody(testProxySanitizer.getRegex(), testProxySanitizer.getRedactedValue(), testProxySanitizer.getGroupForReplace()); - sanitizerType = TestProxySanitizerType.BODY_REGEX.name; + sanitizerType = TestProxySanitizerType.BODY_REGEX.getName(); break; case BODY: requestBody = createBodyJsonKeyRequestBody(testProxySanitizer.getRegex(), testProxySanitizer.getRedactedValue()); - sanitizerType = TestProxySanitizerType.BODY.name; + sanitizerType = TestProxySanitizerType.BODY.getName(); break; case HEADER: requestBody = createHeaderRegexRequestBody(testProxySanitizer.getRegex(), testProxySanitizer.getRedactedValue()); - sanitizerType = TestProxySanitizerType.HEADER.name; + sanitizerType = TestProxySanitizerType.HEADER.getName(); break; default: throw new RuntimeException(String.format("Sanitizer type {%s} not supported", testProxySanitizer.getType()));